3 lines
No EOL
14 KiB
JavaScript
3 lines
No EOL
14 KiB
JavaScript
import{I as e,L as t,M as n,R as r,U as i,X as a,Y as o,_ as s,d as c,f as l,g as u,i as d,p as f,q as p,t as m,u as h}from"./_plugin-vue_export-helper.By3-ojQa.js";import{s as g}from"./runtime-dom.esm-bundler.DzcUlaDE.js";import{t as _}from"./lodash.daI9UflD.js";import{O as v}from"./oauth.C4JLKGAu.js";import{kn as y}from"./free-solid-svg-icons.vn_kySUQ.js";import{t as b}from"./languages.q6q0orhR.js";import{t as x}from"./unicode_domain_indicator.BnLqD48H.js";import{t as S}from"./popover.94nM-RDc.js";import{t as C}from"./emoji_picker.Ccx2u99H.js";import{r as w}from"./free-regular-svg-icons.BGRGA4e_.js";var T=_(),E={props:{ariaLive:{type:String,default:`assertive`}},data(){return{currentText:``}},methods:{announce(e){this.currentText=e,setTimeout(()=>{this.currentText=``},1e3)}}},D=[`aria-live`];function O(e,t,r,i,o,s){return n(),f(`div`,{class:`visible-for-screenreader-only`,"aria-live":e.ariaLive},a(e.currentText),9,D)}var k=m(E,[[`render`,O]]),A=(e,t,n)=>e.slice(0,t.start)+n+e.slice(t.end),j=(e,t)=>(0,T.find)(M(N(e)),({start:e,end:n})=>e<=t&&n>t),M=e=>(0,T.reduce)(e,(e,t)=>{let n={word:t,start:0,end:t.length};if(e.length>0){let t=e.pop();n.start+=t.end,n.end+=t.end,e.push(t)}return e.push(n),e},[]),N=e=>{let t=[],n=``;for(let r=0;r<e.length;r++){let i=e[r];if(!n){n=i;continue}if(!!i.trim()!=!!n.trim()){t.push(n),n=i;continue}n+=i}return n&&t.push(n),t},P={wordAtPosition:j,addPositionToWords:M,splitByWhitespaceBoundary:N,replaceWord:A},F=(e,t,{top:n=0,left:r=0}={},i=!0)=>{let a={top:n+e.offsetTop,left:r+e.offsetLeft};if(!i&&e!==window){let{topPadding:t,leftPadding:n}=I(e);a.top+=i?0:t,a.left+=i?0:n}if(e.offsetParent&&window.getComputedStyle(e.offsetParent).position!==`sticky`&&(t===window||t.contains(e.offsetParent)||t===e.offsetParent))return F(e.offsetParent,t,a,!1);if(t!==window){let{topPadding:e,leftPadding:n}=I(t);a.top+=e,a.left+=n}return a},I=e=>{let t=window.getComputedStyle(e)[`padding-top`],n=Number(t.substring(0,t.length-2)),r=window.getComputedStyle(e)[`padding-left`];return{topPadding:n,leftPadding:Number(r.substring(0,r.length-2))}},L=()=>`${Math.random()}`.replace(`.`,`-`);y.add(w);var R={emits:[`update:modelValue`,`shown`],props:{suggest:{required:!0,type:Function},modelValue:{required:!0,type:String},enableEmojiPicker:{required:!1,type:Boolean,default:!1},hideEmojiButton:{required:!1,type:Boolean,default:!1},enableStickerPicker:{required:!1,type:Boolean,default:!1},placement:{required:!1,type:String,default:`auto`},newlineOnCtrlEnter:{required:!1,type:Boolean,default:!1}},data(){return{randomSeed:L(),input:void 0,caretEl:void 0,highlighted:-1,caret:0,focused:!1,blurTimeout:null,temporarilyHideSuggestions:!1,disableClickOutside:!1,suggestions:[],overlayStyle:{},pickerShown:!1}},components:{Popover:S,EmojiPicker:C,UnicodeDomainIndicator:x,ScreenReaderNotice:k},computed:{padEmoji(){return v().mergedConfig.padEmoji},defaultCandidateIndex(){return v().mergedConfig.autocompleteSelect?0:-1},preText(){return this.modelValue.slice(0,this.caret)},postText(){return this.modelValue.slice(this.caret)},showSuggestions(){return this.focused&&this.suggestions&&this.suggestions.length>0&&!this.pickerShown&&!this.temporarilyHideSuggestions},textAtCaret(){return this.wordAtCaret?.word},wordAtCaret(){if(this.modelValue&&this.caret)return P.wordAtPosition(this.modelValue,this.caret-1)||{}},languages(){return b(v().mergedConfig.interfaceLanguage)},maybeLocalizedEmojiNamesAndKeywords(){return e=>{let t=[e.displayText],n=[];return e.displayTextI18n&&t.push(this.$t(e.displayTextI18n.key,e.displayTextI18n.args)),e.annotations&&this.languages.forEach(r=>{t.push(e.annotations[r]?.name),n.push(...e.annotations[r]?.keywords||[])}),{names:t.filter(e=>e),keywords:n.filter(e=>e)}}},maybeLocalizedEmojiName(){return e=>{if(!e.annotations)return e.displayText;if(e.displayTextI18n)return this.$t(e.displayTextI18n.key,e.displayTextI18n.args);for(let t of this.languages)if(e.annotations[t]?.name)return e.annotations[t].name;return e.displayText}},suggestionListId(){return`suggestions-${this.randomSeed}`},suggestionItemId(){return e=>`suggestion-item-${e}-${this.randomSeed}`}},mounted(){let{root:e,hiddenOverlayCaret:t,suggestorPopover:n}=this.$refs,r=e.querySelector(`.emoji-input > input`)||e.querySelector(`.emoji-input > textarea`);if(!r)return;this.input=r,this.caretEl=t,n.setAnchorEl?(n.setAnchorEl(this.caretEl),this.$refs.picker.setAnchorEl(this.caretEl)):console.warn(`setAnchorEl not found, are we in a unit test?`);let i=getComputedStyle(this.input);this.overlayStyle.padding=i.padding,this.overlayStyle.border=i.border,this.overlayStyle.margin=i.margin,this.overlayStyle.lineHeight=i.lineHeight,this.overlayStyle.fontFamily=i.fontFamily,this.overlayStyle.fontSize=i.fontSize,this.overlayStyle.wordWrap=i.wordWrap,this.overlayStyle.whiteSpace=i.whiteSpace,r.addEventListener(`blur`,this.onBlur),r.addEventListener(`focus`,this.onFocus),r.addEventListener(`paste`,this.onPaste),r.addEventListener(`keyup`,this.onKeyUp),r.addEventListener(`keydown`,this.onKeyDown),r.addEventListener(`click`,this.onClickInput),r.addEventListener(`transitionend`,this.onTransition),r.addEventListener(`input`,this.onInput),r.addEventListener(`scroll`,this.onInputScroll)},unmounted(){let{input:e}=this;e&&(e.removeEventListener(`blur`,this.onBlur),e.removeEventListener(`focus`,this.onFocus),e.removeEventListener(`paste`,this.onPaste),e.removeEventListener(`keyup`,this.onKeyUp),e.removeEventListener(`keydown`,this.onKeyDown),e.removeEventListener(`click`,this.onClickInput),e.removeEventListener(`transitionend`,this.onTransition),e.removeEventListener(`input`,this.onInput),e.removeEventListener(`scroll`,this.onInputScroll))},watch:{showSuggestions:function(e){this.$emit(`shown`,e),e?this.$refs.suggestorPopover.showPopover():this.$refs.suggestorPopover.hidePopover()},textAtCaret:async function(e){if(e===void 0)return;if(e===e.charAt(0)){this.suggestions=[];return}let t=await this.suggest(e,this.maybeLocalizedEmojiNamesAndKeywords);if(this.textAtCaret!==e||t.length<=0){this.suggestions=[];return}this.suggestions=(0,T.take)(t,5).map(({imageUrl:e,...t})=>({...t,img:e||``})),this.highlighted=this.defaultCandidateIndex,this.$refs.screenReaderNotice.announce(this.$t(`tool_tip.autocomplete_available`,{number:this.suggestions.length},this.suggestions.length))}},methods:{onInputScroll(e){this.$refs.hiddenOverlay.scrollTo({top:this.input.scrollTop,left:this.input.scrollLeft}),this.setCaret(e)},triggerShowPicker(){this.$nextTick(()=>{this.$refs.picker.showPicker(),this.scrollIntoView()}),this.disableClickOutside=!0,setTimeout(()=>{this.disableClickOutside=!1},0)},togglePicker(){this.input.focus(),this.pickerShown?this.$refs.picker.hidePicker():(this.scrollIntoView(),this.$refs.picker.showPicker())},replace(e){let t=P.replaceWord(this.modelValue,this.wordAtCaret,e);this.$emit(`update:modelValue`,t),this.caret=0},insert({insertion:e,keepOpen:t,surroundingSpace:n=!0}){let r=this.modelValue.substring(0,this.caret)||``,i=this.modelValue.substring(this.caret)||``,a=/\s/,o=n&&!a.exec(r.slice(-1))&&r.length&&this.padEmoji>0?` `:``,s=n&&!a.exec(i[0])&&this.padEmoji?` `:``,c=[r,o,e,s,i].join(``);this.$emit(`update:modelValue`,c);let l=this.caret+(e+s+o).length;t||this.input.focus(),this.$nextTick(function(){this.input.setSelectionRange(l,l),this.caret=l})},replaceText(e,t){let n=this.suggestions.length||0;if(this.textAtCaret.length!==1&&(n>0||t)){let n=(t||this.suggestions[this.highlighted]).replacement,r=P.replaceWord(this.modelValue,this.wordAtCaret,n);this.$emit(`update:modelValue`,r),this.highlighted=0;let i=this.wordAtCaret.start+n.length;this.$nextTick(function(){this.input.focus(),this.input.setSelectionRange(i,i),this.caret=i}),e.preventDefault()}},cycleBackward(e){let t=this.suggestions.length||0;--this.highlighted,this.highlighted===-1?this.input.focus():this.highlighted<-1&&(this.highlighted=t-1),t>0&&e.preventDefault()},cycleForward(e){let t=this.suggestions.length||0;this.highlighted+=1,this.highlighted>=t&&(this.highlighted=-1,this.input.focus()),t>0&&e.preventDefault()},scrollIntoView(){let e=this.$refs.picker.$el,t=this.$el.closest(`.sidebar-scroller`)||this.$el.closest(`.post-form-modal-view`)||window,n=t===window?t.scrollY:t.scrollTop,r=n+(t===window?t.innerHeight:t.offsetHeight),i=e.offsetHeight+F(e,t).top,a=n+Math.max(0,i-r);t===window?t.scroll(0,a):t.scrollTop=a,this.$nextTick(()=>{let{offsetHeight:e}=this.input,{picker:t}=this.$refs;t.$el.getBoundingClientRect().bottom>window.innerHeight&&(t.$el.style.top=`auto`,t.$el.style.bottom=e+`px`)})},onPickerShown(){this.pickerShown=!0},onPickerClosed(){this.pickerShown=!1},onBlur(e){this.blurTimeout=setTimeout(()=>{this.focused=!1,this.setCaret(e)},200)},onClick(e,t){this.replaceText(e,t)},onFocus(e){this.blurTimeout&&=(clearTimeout(this.blurTimeout),null),this.focused=!0,this.setCaret(e),this.temporarilyHideSuggestions=!1},onKeyUp(e){let{key:t}=e;this.setCaret(e),t===`Escape`?this.temporarilyHideSuggestions=!0:this.temporarilyHideSuggestions=!1},onPaste(e){this.setCaret(e)},onKeyDown(e){let{ctrlKey:t,shiftKey:n,key:r}=e;this.newlineOnCtrlEnter&&t&&r===`Enter`&&(this.insert({insertion:`
|
|
`,surroundingSpace:!1}),e.stopPropagation(),e.preventDefault(),this.$nextTick(()=>{this.input.blur(),this.input.focus()})),this.temporarilyHideSuggestions||(r===`Tab`&&(n?this.cycleBackward(e):this.cycleForward(e)),r===`ArrowUp`?this.cycleBackward(e):r===`ArrowDown`&&this.cycleForward(e),r===`Enter`&&(t||this.replaceText(e))),r===`Escape`&&(this.temporarilyHideSuggestions||this.input.focus())},onInput(e){this.setCaret(e),this.$emit(`update:modelValue`,e.target.value)},onStickerUploaded(e){this.$emit(`sticker-uploaded`,e)},onStickerUploadFailed(e){this.$emit(`sticker-upload-Failed`,e)},setCaret({target:{selectionStart:e}}){this.caret=e,this.$nextTick(()=>{this.$refs.suggestorPopover?.updateStyles()})},autoCompleteItemLabel(e){return e.user?e.displayText+` `+e.detailText:this.maybeLocalizedEmojiName(e)}}},z={ref:`hiddenOverlayCaret`,class:`caret`},B=[`title`],V=[`id`],H=[`id`,`aria-label`,`aria-selected`,`onClick`],U={class:`image`},W=[`src`],G={key:1},K={class:`label`},q={key:0,class:`displayText`},J={key:1,class:`displayText`},Y={class:`detailText`};function X(m,_,v,y,b,x){let S=r(`screen-reader-notice`),C=r(`FAIcon`),w=r(`EmojiPicker`),T=r(`UnicodeDomainIndicator`),E=r(`Popover`);return n(),f(`div`,{ref:`root`,class:p([`input emoji-input`,{"-with-picker":!m.hideEmojiButton,"-textarea":m.input?.tagName===`TEXTAREA`}])},[t(m.$slots,`default`,{id:`textbox-`+m.randomSeed,ariaOwns:m.suggestionListId,ariaAutocomplete:`both`,ariaExpanded:m.showSuggestions,ariaActivedescendant:!m.showSuggestions||m.highlighted===-1?``:m.suggestionItemId(m.highlighted)}),h(`div`,{ref:`hiddenOverlay`,class:`hidden-overlay`,style:o(m.overlayStyle),"aria-hidden":!0},[h(`span`,null,a(m.preText),1),h(`span`,z,`x`,512),h(`span`,null,a(m.postText),1)],4),s(S,{ref:`screenReaderNotice`,"aria-live":`assertive`},null,512),m.enableEmojiPicker?(n(),f(d,{key:0},[m.hideEmojiButton?l(``,!0):(n(),f(`button`,{key:0,class:`button-unstyled emoji-picker-icon`,type:`button`,title:m.$t(`emoji.add_emoji`),onClick:_[0]||=g((...e)=>m.togglePicker&&m.togglePicker(...e),[`prevent`])},[s(C,{icon:[`far`,`face-smile-beam`]})],8,B)),m.enableEmojiPicker?(n(),c(w,{key:1,ref:`picker`,"enable-sticker-picker":m.enableStickerPicker,class:`emoji-picker-panel`,onEmoji:m.insert,onStickerUploaded:m.onStickerUploaded,onStickerUploadFailed:m.onStickerUploadFailed,onShow:m.onPickerShown,onClose:m.onPickerClosed},null,8,[`enable-sticker-picker`,`onEmoji`,`onStickerUploaded`,`onStickerUploadFailed`,`onShow`,`onClose`])):l(``,!0)],64)):l(``,!0),s(E,{ref:`suggestorPopover`,class:`autocomplete-panel`,placement:`bottom`,"hide-trigger":!0},{content:i(()=>[h(`div`,{id:m.suggestionListId,ref:`panel-body`,class:`autocomplete-panel-body`,role:`listbox`},[(n(!0),f(d,null,e(m.suggestions,(e,t)=>(n(),f(`div`,{id:m.suggestionItemId(t),key:t,class:p([`menu-item autocomplete-item`,{"-active":t===m.highlighted}]),role:`option`,"aria-label":m.autoCompleteItemLabel(e),"aria-selected":t===m.highlighted,onClick:g(t=>m.onClick(t,e),[`stop`,`prevent`])},[h(`span`,U,[e.img?(n(),f(`img`,{key:0,src:e.img},null,8,W)):(n(),f(`span`,G,a(e.replacement),1))]),h(`div`,K,[e.user?(n(),f(`span`,q,[u(a(e.displayText),1),s(T,{user:e.user,at:!1},null,8,[`user`])])):l(``,!0),e.user?l(``,!0):(n(),f(`span`,J,a(m.maybeLocalizedEmojiName(e)),1)),h(`span`,Y,a(e.detailText),1)])],10,H))),128))],8,V)]),_:1},512)],2)}var Z=m(R,[[`render`,X]]),Q=e=>{let t=$(e.emoji),n=e.store&&ee(e.store);return(r,i)=>{let a=r[0];return a===`:`&&e.emoji?t(r,i):a===`@`&&n?n(r):[]}},$=e=>(t,n)=>{let r=t.toLowerCase().substring(1);return e.map(e=>({...e,...n(e)})).filter(e=>e.names.concat(e.keywords).filter(e=>e.toLowerCase().includes(r)).length).map(e=>{let t=0;return t+=Math.max(...e.names.map(e=>e.toLowerCase()===r?200:0),0),t+=e.imageUrl?100:0,t+=Math.max(...e.names.map(e=>e.toLowerCase().startsWith(r)?10:0),0),t-=e.displayText.length,e.score=t,e}).sort((e,t)=>{let n=e.displayText>t.displayText?.5:-.5;return t.score-e.score+n})},ee=({dispatch:e,state:t})=>{let n=[],r=``,i=null,a=null,o=t=>e(`searchUsers`,{query:t}),s=e=>(a&&a(),new Promise((t,n)=>{i=setTimeout(()=>{o(e).then(t).catch(n)},300),a=()=>{clearTimeout(i),t([])}}));return async e=>{let i=e.toLowerCase().substr(1);return r===i?n:(n=[],r=i,i.includes(`@`)||await s(i),n=t.users.users.filter(e=>e.screen_name&&e.name&&(e.screen_name.toLowerCase().startsWith(i)||e.name.toLowerCase().startsWith(i))).slice(0,20).sort((e,t)=>{let n=0,r=0;n+=e.screen_name.toLowerCase().startsWith(i)?2:0,r+=t.screen_name.toLowerCase().startsWith(i)?2:0,n+=+!!e.name.toLowerCase().startsWith(i),r+=+!!t.name.toLowerCase().startsWith(i);let a=(r-n)*10,o=e.last_status_at<t.last_status_at?100:-100,s=e.name>t.name?1:-1,c=e.screen_name>t.screen_name?1:-1;return a+s+c+o}).map(e=>({user:e,displayText:e.screen_name_ui,detailText:e.name,imageUrl:e.profile_image_url_original,replacement:`@`+e.screen_name+` `}))||[],n)}},te=e=>Object.keys(e).reduce((t,n)=>(t[(0,T.kebabCase)(n)]=e[n],t),{});export{F as a,L as i,Q as n,Z as r,te as t};
|
|
//# sourceMappingURL=attributes_helper.service.Ku0p8pb2.js.map
|