UNPKG

ant-design-x-vue

Version:

Craft AI-driven interfaces effortlessly

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