UNPKG

ant-design-x-vue

Version:

Craft AI-driven interfaces effortlessly

2 lines (1 loc) 3.96 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),O=require("../attachments/Attachments2.js");require("../x-provider/index.js");const M=require("../_util/hooks/use-x-component-config.js"),W=require("./style/index.js"),k=require("../_util/hooks/use-state.js"),D=require("ant-design-vue"),T=require("./useActive.js"),$=require("../x-provider/hooks/use-x-provider-context.js");function I(e){return t.getCurrentScope()?(t.onScopeDispose(e),!0):!1}const P=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;function z(e){return Array.isArray(e)?e:[e]}function F(e){return t.getCurrentInstance()}function L(e,o=!0,u){F()?t.onMounted(e,u):o?e():t.nextTick(e)}const q=P?window:void 0;function m(e){var o;const u=t.toValue(e);return(o=u==null?void 0:u.$el)!=null?o:u}function G(){const e=t.shallowRef(!1),o=t.getCurrentInstance();return o&&t.onMounted(()=>{e.value=!0},o),e}function X(e){const o=G();return t.computed(()=>(o.value,!!e()))}function E(e,o,u={}){const{window:d=q,...a}=u;let r;const l=X(()=>d&&"ResizeObserver"in d),i=()=>{r&&(r.disconnect(),r=void 0)},w=t.computed(()=>{const n=t.toValue(e);return Array.isArray(n)?n.map(c=>m(c)):[m(n)]}),g=t.watch(w,n=>{if(i(),l.value&&d){r=new ResizeObserver(o);for(const c of n)c&&r.observe(c,a)}},{immediate:!0,flush:"post"}),h=()=>{i(),g()};return I(h),{isSupported:l,stop:h}}function H(e,o={width:0,height:0},u={}){const{window:d=q,box:a="content-box"}=u,r=t.computed(()=>{var n,c;return(c=(n=m(e))==null?void 0:n.namespaceURI)==null?void 0:c.includes("svg")}),l=t.shallowRef(o.width),i=t.shallowRef(o.height),{stop:w}=E(e,([n])=>{const c=a==="border-box"?n.borderBoxSize:a==="content-box"?n.contentBoxSize:n.devicePixelContentBoxSize;if(d&&r.value){const f=m(e);if(f){const v=f.getBoundingClientRect();l.value=v.width,i.value=v.height}}else if(c){const f=z(c);l.value=f.reduce((v,{inlineSize:C})=>v+C,0),i.value=f.reduce((v,{blockSize:C})=>v+C,0)}else l.value=n.contentRect.width,i.value=n.contentRect.height},u);L(()=>{const n=m(e);n&&(l.value="offsetWidth"in n?n.offsetWidth:o.width,i.value="offsetHeight"in n?n.offsetHeight:o.height)});const g=t.watch(()=>m(e),n=>{l.value=n?o.width:0,i.value=n?o.height:0});function h(){w(),g()}return{width:l,height:i,stop:h}}const j=t.defineComponent({name:"AXSuggestion",__name:"Suggestion",props:t.mergeDefaults({prefixCls:null,className:null,rootClassName:null,style:null,children:{type:Function},open:{type:Boolean},onOpenChange:{type:Function},items:{type:Function},onSelect:{type:Function},block:{type:Boolean},styles:null,classNames:null},{open:!1}),setup(e){t.toRef(e,"prefixCls");const o=t.useSlots(),{direction:u,getPrefixCls:d}=$.default(),a=t.computed(()=>d("suggestion",e.prefixCls));`${a.value}`;const r=t.computed(()=>u.value==="rtl"),l=M.default("suggestion"),i=t.ref(),[w,g,h]=W.default(a),{width:n}=H(i),c=t.computed(()=>{if(e.block&&n.value)return{width:`${n.value}px`}}),[f,v]=k.default(e.open),[C,A]=k.default(),p=s=>{var N;v(s),(N=e.onOpenChange)==null||N.call(e,s)},b=s=>{s===!1?p(!1):(A(s),p(!0))},y=()=>{p(!1)},S=t.computed(()=>typeof e.items=="function"?e.items(C.value):e.items),x=s=>{e.onSelect&&e.onSelect(s[s.length-1]),p(!1)},[V,R]=T.default(S,f,r,x,y),B=t.computed(()=>{var s;return o.default?o.default({onTrigger:b,onKeyDown:R}):(s=e.children)==null?void 0:s.call(e,{onTrigger:b,onKeyDown:R})});return()=>w(t.createVNode(D.Cascader,{options:S.value,open:f.value,value:V.value,placement:r.value?"topRight":"topLeft",onDropdownVisibleChange:s=>{s||y()},popupClassName:O.classnames(e.rootClassName,a.value,g.value,h,{[`${a.value}-block`]:e.block}),onChange:x,dropdownStyle:c.value},{default:()=>t.createVNode("div",{ref:i,class:O.classnames(a.value,l.value.className,e.rootClassName,e.className,`${a.value}-wrapper`,g.value,h),style:{...l.value.style,...e.style}},[B.value])}))}});exports.default=j;