diff options
Diffstat (limited to 'resources/lib/codex/modules/CdxMenu.cjs')
-rw-r--r-- | resources/lib/codex/modules/CdxMenu.cjs | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/resources/lib/codex/modules/CdxMenu.cjs b/resources/lib/codex/modules/CdxMenu.cjs new file mode 100644 index 000000000000..10fcb8ac6301 --- /dev/null +++ b/resources/lib/codex/modules/CdxMenu.cjs @@ -0,0 +1 @@ +"use strict";var X=Object.defineProperty,Y=Object.defineProperties;var Z=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var H=(e,a,u)=>a in e?X(e,a,{enumerable:!0,configurable:!0,writable:!0,value:u}):e[a]=u,P=(e,a)=>{for(var u in a||(a={}))ee.call(a,u)&&H(e,u,a[u]);if(_)for(var u of _(a))te.call(a,u)&&H(e,u,a[u]);return e},A=(e,a)=>Y(e,Z(a));var q=(e,a,u)=>new Promise((B,d)=>{var x=i=>{try{f(u.next(i))}catch(b){d(b)}},r=i=>{try{f(u.throw(i))}catch(b){d(b)}},f=i=>i.done?B(i.value):Promise.resolve(i.value).then(x,r);f((u=u.apply(e,a)).next())});const l=require("vue"),le=require("./CdxMenuItem.cjs"),ne=require("./CdxProgressBar.cjs"),ae=require("./useGeneratedId.cjs"),ie=require("./useIntersectionObserver.cjs"),ue=require("./useSplitAttributes.cjs"),re=require("./_plugin-vue_export-helper.js");require("./Icon.js");require("./useComputedDirection.cjs");require("./useComputedLanguage.cjs");require("./constants.js");require("./CdxThumbnail.cjs");require("./CdxSearchResultTitle.cjs");require("./useWarnOnce.cjs");const oe=l.defineComponent({name:"CdxMenu",components:{CdxMenuItem:le,CdxProgressBar:ne},inheritAttrs:!1,props:{menuItems:{type:Array,required:!0},footer:{type:Object,default:null},selected:{type:[String,Number,null],required:!0},expanded:{type:Boolean,required:!0},showPending:{type:Boolean,default:!1},visibleItemLimit:{type:Number,default:null},showThumbnail:{type:Boolean,default:!1},boldLabel:{type:Boolean,default:!1},hideDescriptionOverflow:{type:Boolean,default:!1},searchQuery:{type:String,default:""},showNoResultsSlot:{type:Boolean,default:null}},emits:["update:selected","update:expanded","menu-item-click","menu-item-keyboard-navigation","load-more"],expose:["isExpanded","clearActive","getHighlightedMenuItem","getHighlightedViaKeyboard","delegateKeyNavigation"],setup(e,{emit:a,slots:u,attrs:B}){const d=l.computed(()=>(e.footer&&e.menuItems?[...e.menuItems,e.footer]:e.menuItems).map(n=>A(P({},n),{id:ae("menu-item")}))),x=l.computed(()=>u["no-results"]?e.showNoResultsSlot!==null?e.showNoResultsSlot:d.value.length===0:!1),r=l.ref(null),f=l.ref(!1),i=l.ref(null),b="additions removals";let c="",m=null;function v(){c="",m!==null&&(clearTimeout(m),m=null)}function k(){m!==null&&clearTimeout(m),m=setTimeout(v,1500)}function C(){var t;return(t=d.value.find(n=>n.value===e.selected))!=null?t:null}function g(t,n){var o;if(!(n&&n.disabled))switch(t){case"selected":a("update:selected",(o=n==null?void 0:n.value)!=null?o:null),a("update:expanded",!1),i.value=null;break;case"highlighted":r.value=n!=null?n:null,f.value=!1;break;case"highlightedViaKeyboard":r.value=n!=null?n:null,f.value=!0;break;case"active":i.value=n!=null?n:null;break}}const y=l.computed(()=>{if(r.value!==null)return d.value.findIndex(t=>t.value===r.value.value)});function T(t){t&&(g("highlightedViaKeyboard",t),a("menu-item-keyboard-navigation",t))}function N(t){var s;const n=M=>{for(let h=M-1;h>=0;h--)if(!d.value[h].disabled)return d.value[h]};t=t!=null?t:d.value.length;const o=(s=n(t))!=null?s:n(d.value.length);T(o)}function E(t){var s;const n=M=>d.value.find((h,V)=>!h.disabled&&V>M);t=t!=null?t:-1;const o=(s=n(t))!=null?s:n(-1);T(o)}function D(t){if(t.key==="Clear")return v(),!0;if(t.key==="Backspace")return c=c.slice(0,-1),k(),!0;if(t.key.length===1&&!t.metaKey&&!t.ctrlKey&&!t.altKey){if(e.expanded||a("update:expanded",!0),t.key===" "&&c.length<1)return!1;c+=t.key.toLowerCase();const n=c.length>1&&c.split("").every(h=>h===c[0]);let o=d.value,s=c;n&&y.value!==void 0&&(o=o.slice(y.value+1).concat(o.slice(0,y.value)),s=c[0]);const M=o.find(h=>{var V;return!h.disabled&&String((V=h.label)!=null?V:h.value).toLowerCase().startsWith(s)});return M&&(g("highlightedViaKeyboard",M),w()),k(),!0}return!1}function F(t,{prevent:n=!0,characterNavigation:o=!1}={}){if(o){if(D(t))return t.preventDefault(),!0;v()}function s(){n&&(t.preventDefault(),t.stopPropagation())}switch(t.key){case"Enter":case" ":return s(),e.expanded?(r.value&&f.value&&a("update:selected",r.value.value),a("update:expanded",!1)):a("update:expanded",!0),!0;case"Tab":return e.expanded&&(r.value&&f.value&&a("update:selected",r.value.value),a("update:expanded",!1)),!0;case"ArrowUp":return s(),e.expanded?(r.value===null&&g("highlightedViaKeyboard",C()),N(y.value)):a("update:expanded",!0),w(),!0;case"ArrowDown":return s(),e.expanded?(r.value===null&&g("highlightedViaKeyboard",C()),E(y.value)):a("update:expanded",!0),w(),!0;case"Home":return s(),e.expanded?(r.value===null&&g("highlightedViaKeyboard",C()),E()):a("update:expanded",!0),w(),!0;case"End":return s(),e.expanded?(r.value===null&&g("highlightedViaKeyboard",C()),N()):a("update:expanded",!0),w(),!0;case"Escape":return s(),a("update:expanded",!1),!0;default:return!1}}function L(){g("active",null)}const p=[],$=l.ref(void 0),I=ie($,{threshold:.8});l.watch(I,t=>{t&&a("load-more")});function O(t,n){if(t){p[n]=t.$el;const o=e.visibleItemLimit;if(!o||e.menuItems.length<o)return;const s=Math.min(o,Math.max(2,Math.floor(.2*e.menuItems.length)));n===e.menuItems.length-s&&($.value=t.$el)}}function w(){if(!e.visibleItemLimit||e.visibleItemLimit>e.menuItems.length||y.value===void 0)return;const t=y.value>=0?y.value:0;p[t].scrollIntoView({behavior:"smooth",block:"nearest"})}const S=l.ref(null),K=l.ref(null);function R(){return q(this,null,function*(){yield l.nextTick(),z(),U(),yield l.nextTick(),w()})}function z(){if(e.footer){const t=p[p.length-1];K.value=t.scrollHeight}else K.value=null}function U(){if(!e.visibleItemLimit||p.length<=e.visibleItemLimit){S.value=null;return}const t=p[0].getBoundingClientRect().top,n=p[e.visibleItemLimit].getBoundingClientRect().top;S.value=n-t+2}l.onMounted(()=>{document.addEventListener("mouseup",L)}),l.onUnmounted(()=>{document.removeEventListener("mouseup",L)}),l.watch(l.toRef(e,"expanded"),t=>q(this,null,function*(){if(t){const n=C();n&&!r.value&&g("highlighted",n),yield R()}else g("highlighted",null)})),l.watch(l.toRef(e,"menuItems"),t=>q(this,null,function*(){t.length<p.length&&(p.length=t.length),e.expanded&&(yield R())}),{deep:!0});const W=l.computed(()=>({"max-height":S.value?"".concat(S.value,"px"):void 0,"margin-bottom":K.value?"".concat(K.value,"px"):void 0})),Q=l.computed(()=>({"cdx-menu--has-footer":!!e.footer})),{rootClasses:j,rootStyle:G,otherAttrs:J}=ue(B,Q);return{listBoxStyle:W,rootClasses:j,rootStyle:G,otherAttrs:J,assignTemplateRef:O,computedMenuItems:d,computedShowNoResultsSlot:x,highlightedMenuItem:r,highlightedViaKeyboard:f,activeMenuItem:i,handleMenuItemChange:g,handleKeyNavigation:F,ariaRelevant:b}},methods:{isExpanded(){return this.expanded},getHighlightedMenuItem(){return this.expanded?this.highlightedMenuItem:null},getHighlightedViaKeyboard(){return this.highlightedViaKeyboard},clearActive(){this.handleMenuItemChange("active",null)},delegateKeyNavigation(e,{prevent:a=!0,characterNavigation:u=!1}={}){return this.handleKeyNavigation(e,{prevent:a,characterNavigation:u})}}});const se=["aria-live","aria-relevant"],de={key:0,class:"cdx-menu__pending cdx-menu-item"},ce={key:1,class:"cdx-menu__no-results cdx-menu-item"};function he(e,a,u,B,d,x){const r=l.resolveComponent("cdx-menu-item"),f=l.resolveComponent("cdx-progress-bar");return l.withDirectives((l.openBlock(),l.createElementBlock("div",{class:l.normalizeClass(["cdx-menu",e.rootClasses]),style:l.normalizeStyle(e.rootStyle)},[l.createElementVNode("ul",l.mergeProps({class:"cdx-menu__listbox",role:"listbox",style:e.listBoxStyle,"aria-live":e.showPending?"polite":void 0,"aria-relevant":e.showPending?e.ariaRelevant:void 0},e.otherAttrs),[e.showPending&&e.computedMenuItems.length===0&&e.$slots.pending?(l.openBlock(),l.createElementBlock("li",de,[l.renderSlot(e.$slots,"pending")])):l.createCommentVNode("",!0),e.computedShowNoResultsSlot?(l.openBlock(),l.createElementBlock("li",ce,[l.renderSlot(e.$slots,"no-results")])):l.createCommentVNode("",!0),(l.openBlock(!0),l.createElementBlock(l.Fragment,null,l.renderList(e.computedMenuItems,(i,b)=>{var c,m;return l.openBlock(),l.createBlock(r,l.mergeProps({key:i.value,ref_for:!0,ref:v=>e.assignTemplateRef(v,b)},i,{selected:i.value===e.selected,active:i.value===((c=e.activeMenuItem)==null?void 0:c.value),highlighted:i.value===((m=e.highlightedMenuItem)==null?void 0:m.value),"show-thumbnail":e.showThumbnail,"bold-label":e.boldLabel,"hide-description-overflow":e.hideDescriptionOverflow,"search-query":e.searchQuery,onChange:(v,k)=>e.handleMenuItemChange(v,k?i:null),onClick:v=>e.$emit("menu-item-click",i)}),{default:l.withCtx(()=>{var v,k;return[l.renderSlot(e.$slots,"default",{menuItem:i,active:i.value===((v=e.activeMenuItem)==null?void 0:v.value)&&i.value===((k=e.highlightedMenuItem)==null?void 0:k.value)})]}),_:2},1040,["selected","active","highlighted","show-thumbnail","bold-label","hide-description-overflow","search-query","onChange","onClick"])}),128)),e.showPending?(l.openBlock(),l.createBlock(f,{key:2,class:"cdx-menu__progress-bar",inline:!0})):l.createCommentVNode("",!0)],16,se)],6)),[[l.vShow,e.expanded]])}const fe=re._export_sfc(oe,[["render",he]]);module.exports=fe; |