New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@xiaohaih/condition-core

Package Overview
Dependencies
Maintainers
0
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xiaohaih/condition-core - npm Package Compare versions

Comparing version 0.5.3 to 0.5.6

6

CHANGELOG.md
# @xiaohaih/condition-core
## 0.5.6
### Patch Changes
- 修复存在依赖项时, 在 getOptions 中无法主动改变值
## 0.5.3

@@ -4,0 +10,0 @@

12

dist/index.cjs.js

@@ -410,2 +410,7 @@ 'use strict';

}));
/** 是否允许依赖变动时, 重置值(外部通过 search, change 主动改变值时, 内部应取消重置) */
const {
flag: allowDependChangeValue,
updateFlag: updateAllowDependChangeValue
} = useDisableInCurrentCycle(true);
// 存在依赖项

@@ -418,6 +423,7 @@ unwatchs.push(vueDemi.watch([() => props.depend, () => props.dependFields, () => props.dependFields && [].concat(props.dependFields).map(k => get(props.query, k))], ([_depend, _dependFields], [__depend, __dependFields]) => {

// 防止表单类监测值发生改变时触发校验
if (isEmptyValue(checked.value)) return;
// 或内部不允许重置时直接返回
if (isEmptyValue(checked.value) || !allowDependChangeValue.value) return;
change(props.multiple ? [] : '');
}, props.dependWatchOption));
// 存在依赖项
// 存在选项变动依赖项时
unwatchs.push(vueDemi.watch([() => props.optionsDepend, () => wrapper && (props.optionsDependFields || props.dependFields) && [].concat(props.optionsDependFields || props.dependFields).map(k => wrapper.options[k])], ([_depend], [__depend]) => {

@@ -448,2 +454,3 @@ // 是否启用依赖, 相同时启用才走后续逻辑, 不同时直接走后续逻辑

isInitial && (initialValue.value = value);
updateAllowDependChangeValue();
change(value);

@@ -454,2 +461,3 @@ return this;

isInitial && (initialValue.value = value);
updateAllowDependChangeValue();
updateCheckedValue(value);

@@ -456,0 +464,0 @@ wrapper?.search();

2

dist/index.cjs.min.js

@@ -1,2 +0,2 @@

"use strict";var e=require("vue-demi");const t="2.7"===e.version.slice(0,3),n="condition-wrapper";function r(e){return e}function i(e){return e}const a={realtime:{type:Boolean,default:void 0},searchAtDatumChanged:{type:Boolean,default:void 0},backfill:{type:Object},toast:{type:Function,default:void 0},emptyValues:{type:Array,default:()=>["",null,void 0]},emptyValue:{type:Function,default:void 0}};function u(e,t){return"number"==typeof e?e:e||t}function l(e,t){return o(e)&&o(t)||p(e,t)}function o(e){return void 0===e||""===e||null===e}function p(e,t){if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const n=Reflect.ownKeys(e),r=Reflect.ownKeys(t);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r++){if(!Reflect.has(t,n[r]))return!1;if(!p(e[n[r]],t[n[r]]))return!1}return!0}function s(e){return null==e||"object"!=typeof e&&"function"!=typeof e}function d(e,t){if(s(e))return e;if("function"==typeof e)return e.bind({});const n=new e.constructor;return Object.getOwnPropertyNames(e).forEach((r=>{n[r]=t?d(e[r]):e[r]})),n}function c(e,t,n="children"){for(const r of e){if(t(r))return[r];if(r[n]?.length){const e=c(r[n],t);if(e.length)return e.unshift(r),e}}return[]}function f(e,t,n){const r=t.split(/[\.\[\]]/g);let i=e;for(const e of r){if(null===i)return n;if(void 0===i)return n;const t=e.replace(/['"]/g,"");""!==t.trim()&&(i=i[t])}return void 0===i?n:i}function y(t){const n=e.ref();return e.computed({set(e){n.value=e},get:()=>void 0===n.value?void 0!==t.defaultValue?"function"==typeof t.defaultValue?t.defaultValue(t.query,t.backfill):t.defaultValue:void 0:n.value})}function v(t,n){const r=e.ref("boolean"==typeof t.disabled&&t.disabled),i=e.ref("boolean"==typeof t.hide&&t.hide),a=()=>({query:t.query,backfill:t.backfill,option:n}),u=()=>{if("function"==typeof t.hide){i.value!==t.hide(a())&&(i.value=t.hide(a()))}else if("function"==typeof t.disabled){r.value!==t.disabled(a())&&(r.value=t.disabled(a()))}};let l=[e.watch((()=>t.query),u,{immediate:!0,deep:!0}),e.watch((()=>[t.disabled,t.hide]),((e,t)=>{e[0]!==t[0]&&(r.value="boolean"==typeof e[0]&&e[0],e[0]),e[1]!==t[1]&&(i.value="boolean"==typeof e[1]&&e[1],e[1]),u()}))];return e.onBeforeUnmount((()=>(l.forEach((e=>e())),l=[]))),{insetDisabled:r,insetHide:i}}function h(t=!0){const n=e.ref(t);return{flag:n,updateFlag:()=>{n.value=!t,e.nextTick((()=>{n.value=t}))}}}const g={field:{type:String,required:!0},multiple:{type:Boolean,default:void 0},query:{type:Object,required:!0},backfill:{type:Object},disabled:{type:[Boolean,Function]},hide:{type:[Boolean,Function]},depend:{type:Boolean},dependFields:{type:[String,Array]},dependWatchOption:{type:[Object]},optionsDepend:{type:Boolean},optionsDependFields:{type:[String,Array]},resetToInitialValue:{type:[Boolean]},emptyValue:{type:[String,Number,Boolean,null,void 0],default:void 0},validator:{type:[Function]},customGetQuery:{type:Function},defaultValue:{type:[String,Number,Array,Function]}},m={...g,fields:{type:[Array]},backfillToValue:{type:Function,default:e=>e},options:{type:Array,default:()=>[]},getOptions:{type:Function}};const b={...g,fields:{type:[Array]},valueKey:{type:String,required:!0},childrenKey:{type:String},emitPath:{type:[Boolean],default:!1},options:{type:Array,default:()=>[]},getOptions:{type:Function}};exports.IS_COMPOSITION_VERSION=t,exports.clone=d,exports.commonProps=g,exports.defineCommonMethod=i,exports.defineProvideValue=r,exports.emptyToValue=u,exports.get=f,exports.getChained=c,exports.getNode=function(t,...n){return t?"function"==typeof t?t(...n):"string"==typeof t?t:e.markRaw(t):null},exports.isEmptyValue=o,exports.isEqual=p,exports.isEqualExcludeEmptyValue=l,exports.isPrimitive=s,exports.plainProps=m,exports.provideKey=n,exports.treeProps=b,exports.usePlain=function(t){const r=[],i=e.inject(n),a=y(t),p=t.query&&(t.fields?.length?t.fields.map((e=>t.query[e])).filter(Boolean):t.query[t.field]),s=e.shallowRef(p||(void 0!==t.defaultValue?d(a.value):void 0)),c=e.ref([]),h=e.computed((()=>c.value.length?c.value:t.options));r.push(e.watch(h,(e=>i&&(i.options[t.field]=e)),{immediate:!0}));const g=()=>{if(t.customGetQuery)return t.customGetQuery(s.value,u,t);const e=d(s.value);return t.multiple&&t.fields?t.fields.reduce(((n,r,i)=>(n[r]=u(e?.[i],t.emptyValue),n)),{}):{[t.field]:u(e,t.emptyValue)}},m={reset(){const{multiple:e}=t;s.value=t.resetToInitialValue&&a.value?.slice()||(e?[]:"")},updateWrapperQuery(){i&&Object.entries(g()).forEach((([e,n])=>i.updateQueryValue(e,n,t.field)))},get validator(){return t.validator},getQuery:g};i?.register(m);const{insetDisabled:b,insetHide:V}=v(t,m);function w(n){t.getOptions?.((e=>{const t=s.value;s.value=void 0,c.value=e||[],s.value=t}),t.query||{},{trigger:n,options:e.toRaw(i?.options)||{},changeDefaultValue(e){return a.value=e,this},change(e,t){return t&&(a.value=e),O(e),this},search(e,t){return t&&(a.value=e),F(e),i?.search(),this}})}function F(e){e!==s.value&&(s.value=e,m.updateWrapperQuery())}function O(e){F(e),i?.insetSearch()}return!p&&t.defaultValue&&m.updateWrapperQuery(),e.onBeforeUnmount((()=>r.forEach((e=>e())))),r.push(e.watch((()=>t.field),((e,t)=>{e!==t&&i?.removeUnreferencedField(t),m.updateWrapperQuery()}))),r.push(e.watch([()=>t.fields||t.field,()=>t.fields?t.fields.map((e=>t.query[e])).filter(Boolean):t.query[t.field]],(([e,n],[r])=>{const i=t.backfillToValue(n,e,t.query);s.value===i||e.toString()!==r.toString()||l(i,s.value)||s.value!==i&&(s.value=i)}))),r.push(e.watch([()=>t.depend,()=>t.dependFields,()=>t.dependFields&&[].concat(t.dependFields).map((e=>f(t.query,e)))],(([e,n],[r,i])=>{(e!==r||e)&&(w("depend"),o(s.value)||O(t.multiple?[]:""))}),t.dependWatchOption)),r.push(e.watch([()=>t.optionsDepend,()=>i&&(t.optionsDependFields||t.dependFields)&&[].concat(t.optionsDependFields||t.dependFields).map((e=>i.options[e]))],(([e],[t])=>{(e!==t||e)&&w("depend")}))),r.push(e.watch((()=>t.getOptions),w.bind(null,"initial"))),e.nextTick(w.bind(null,"initial")),{wrapper:i,option:m,checked:s,getQuery:g,insetDisabled:b,insetHide:V,finalOption:h,updateCheckedValue:F,change:O,reset:m.reset}},exports.useTree=function(t){const r=e.inject(n),i=y(t),a=e.ref(),p=e.ref([]),s=e.computed((()=>p.value.length?p.value:t.options)),f=e.computed((()=>t.fields?t.fields.reduce(((e,n)=>(e[n]=t.emptyValue,e)),{}):{[t.field]:t.emptyValue})),g=()=>{if(!Q.value&&!i.value)return{};let e=d(a.value);const{...n}=f.value;return t.customGetQuery?t.customGetQuery(e,u,t):e?(t.emitPath||(e=t.multiple?e.map((e=>e?.slice(-1)[0])):e.slice(-1)[0]),Array.isArray(e)?t.fields?e.forEach(((e,r)=>{n[t.fields[r]]=u(e,t.emptyValue)})):n[t.field]=e:n[t.fields?.[0]||t.field]=u(e,t.emptyValue),n):n},{flag:m,updateFlag:b}=h(),{flag:V,updateFlag:w}=h(),F={reset(){return b(),w(),a.value=t.resetToInitialValue&&i.value?.slice()||[],this},get validator(){return t.validator},updateWrapperQuery(){b(),r&&Object.entries(g()).forEach((([e,n])=>r.updateQueryValue(e,n,t.field)))},getQuery:g};r?.register(F);const{insetDisabled:O,insetHide:q}=v(t,F),x=[];e.onBeforeUnmount((()=>x.forEach((e=>e()))));const Q=e.ref("function"!=typeof t.getOptions||!!t.fields?.length);function k(n){t.getOptions?.((e=>{p.value=e||[],Q.value=!0}),t.query||{},{trigger:n,options:e.toRaw(r?.options)||{},changeDefaultValue(e){return i.value=e,this},change(e,t){return t&&(i.value=e),B(e),this},search(e,t){return t&&(i.value=e),S(e),r?.search(),this}})}function S(e){l(a.value,e)||(a.value=e,F.updateWrapperQuery())}function B(e){S(e),r?.insetSearch()}function E(e){if(o(e))return[];const{valueKey:n,childrenKey:r}=t;return c(s.value,(t=>t[n]===e)).map((e=>e[n]),r).filter(Boolean)}return e.watch(Q,(e=>e&&function(){const{backfill:e,field:n,fields:r}=t;if(e)if(r){const t=r.reduce(((t,n)=>(e[n]&&t.push(e[n]),t)),[]);if(t.length)return a.value=t,void F.updateWrapperQuery()}else if(e[n])return a.value=E(e[n]),void F.updateWrapperQuery();i.value?.length&&(a.value="string"==typeof i.value?E(i.value):i.value.slice(),"string"==typeof i.value&&(i.value=d(a.value)),F.updateWrapperQuery())}()),{immediate:!0}),x.push(e.watch((()=>t.fields||[t.field]),((e,t)=>{e.toString()!==t.toString()&&r&&t.forEach((t=>e.includes(t)||r.removeUnreferencedField(t))),F.updateWrapperQuery()}))),x.push(e.watch([()=>t.fields?.toString()||t.field,()=>t.fields?.map((e=>t.query[e])).filter(Boolean)||t.query[t.field]],(([e,t],[n,r])=>{m.value&&e===n&&l(t,r)}))),x.push(e.watch((()=>t.fields?.length?t.fields.reduce(((e,n)=>(t.backfill?.[n]&&e.push(t.backfill[n]),e)),[]):t.backfill?.[t.field]),((e,t)=>{Q.value&&(l(e,t)||w())}))),x.push(e.watch([()=>t.depend,()=>t.dependFields,()=>t.dependFields&&[].concat(t.dependFields).map((e=>t.query?.[e]))],(([e,t],[n,r])=>{m.value&&(e!==n||e)&&(k("depend"),o(a.value)||B(void 0))}))),x.push(e.watch((()=>t.getOptions),k.bind(null,"initial"),{immediate:!0})),{wrapper:r,option:F,checked:a,getQuery:g,finalOption:s,insetDisabled:O,insetHide:q,change:B,reset:F.reset}},exports.useWrapper=function(r,i){const a=[];e.onBeforeUnmount((()=>a.splice(0)));const u=e.computed((()=>r.emptyValue?.()));let l=!1,o=[];const p=e.reactive({}),s={realtime:e.toRef(r,"realtime",!1),queryChangedInWrapper:e.ref(!1),register(n){a.push(n);const i=()=>{l=!0,n.reset(),n.updateWrapperQuery();const t=a.indexOf(n);-1!==t&&a.splice(t,1),r.searchAtDatumChanged&&f(),l=!1,o.forEach((t=>{e.del(d.value,t)})),o=[]},u=e.getCurrentInstance();return u&&e.onBeforeUnmount(i,t?u.proxy:u),i},updateQueryValue(t,n,a){r.emptyValues.includes(n)&&n!==u.value&&(n=u.value),l&&o.push(t),e.set(d.value,t,n),i?.fieldChange?.({field:t,value:n,query:d.value,nativeField:a})},insetSearch(){r.realtime&&f()},search:f,removeUnreferencedField(t){let n=0;a.some((e=>(e.getQuery().hasOwnProperty(t)&&(n+=1),n))),n||e.del(d.value,t)},options:p};e.provide(n,s);const d=e.ref({...r.backfill}),c=()=>({...d.value});async function f(){const e=await y();e?r.toast?.(e):i?.search?.(c())}async function y(){return(await Promise.all(a.map((e=>e.validator?.(d.value))))).find((e=>e&&"string"==typeof e))}return e.watch((()=>r.backfill),(t=>{s.queryChangedInWrapper.value=!0,Object.keys(d.value).forEach((e=>{t?.hasOwnProperty(e)||delete d.value[e]})),t&&Object.assign(d.value,t),e.nextTick((()=>{s.queryChangedInWrapper.value=!1}))}),{deep:!0}),{child:a,wrapperInstance:s,query:d,getQuery:c,search:f,reset:function(){a.forEach((e=>{e.reset(),e.updateWrapperQuery()})),i?.reset?.(c())},validate:y}},exports.wrapperProps=a;
"use strict";var e=require("vue-demi");const t="2.7"===e.version.slice(0,3),n="condition-wrapper";function r(e){return e}function i(e){return e}const a={realtime:{type:Boolean,default:void 0},searchAtDatumChanged:{type:Boolean,default:void 0},backfill:{type:Object},toast:{type:Function,default:void 0},emptyValues:{type:Array,default:()=>["",null,void 0]},emptyValue:{type:Function,default:void 0}};function u(e,t){return"number"==typeof e?e:e||t}function l(e,t){return o(e)&&o(t)||p(e,t)}function o(e){return void 0===e||""===e||null===e}function p(e,t){if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const n=Reflect.ownKeys(e),r=Reflect.ownKeys(t);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r++){if(!Reflect.has(t,n[r]))return!1;if(!p(e[n[r]],t[n[r]]))return!1}return!0}function s(e){return null==e||"object"!=typeof e&&"function"!=typeof e}function d(e,t){if(s(e))return e;if("function"==typeof e)return e.bind({});const n=new e.constructor;return Object.getOwnPropertyNames(e).forEach((r=>{n[r]=t?d(e[r]):e[r]})),n}function c(e,t,n="children"){for(const r of e){if(t(r))return[r];if(r[n]?.length){const e=c(r[n],t);if(e.length)return e.unshift(r),e}}return[]}function f(e,t,n){const r=t.split(/[\.\[\]]/g);let i=e;for(const e of r){if(null===i)return n;if(void 0===i)return n;const t=e.replace(/['"]/g,"");""!==t.trim()&&(i=i[t])}return void 0===i?n:i}function y(t){const n=e.ref();return e.computed({set(e){n.value=e},get:()=>void 0===n.value?void 0!==t.defaultValue?"function"==typeof t.defaultValue?t.defaultValue(t.query,t.backfill):t.defaultValue:void 0:n.value})}function v(t,n){const r=e.ref("boolean"==typeof t.disabled&&t.disabled),i=e.ref("boolean"==typeof t.hide&&t.hide),a=()=>({query:t.query,backfill:t.backfill,option:n}),u=()=>{if("function"==typeof t.hide){i.value!==t.hide(a())&&(i.value=t.hide(a()))}else if("function"==typeof t.disabled){r.value!==t.disabled(a())&&(r.value=t.disabled(a()))}};let l=[e.watch((()=>t.query),u,{immediate:!0,deep:!0}),e.watch((()=>[t.disabled,t.hide]),((e,t)=>{e[0]!==t[0]&&(r.value="boolean"==typeof e[0]&&e[0],e[0]),e[1]!==t[1]&&(i.value="boolean"==typeof e[1]&&e[1],e[1]),u()}))];return e.onBeforeUnmount((()=>(l.forEach((e=>e())),l=[]))),{insetDisabled:r,insetHide:i}}function h(t=!0){const n=e.ref(t);return{flag:n,updateFlag:()=>{n.value=!t,e.nextTick((()=>{n.value=t}))}}}const g={field:{type:String,required:!0},multiple:{type:Boolean,default:void 0},query:{type:Object,required:!0},backfill:{type:Object},disabled:{type:[Boolean,Function]},hide:{type:[Boolean,Function]},depend:{type:Boolean},dependFields:{type:[String,Array]},dependWatchOption:{type:[Object]},optionsDepend:{type:Boolean},optionsDependFields:{type:[String,Array]},resetToInitialValue:{type:[Boolean]},emptyValue:{type:[String,Number,Boolean,null,void 0],default:void 0},validator:{type:[Function]},customGetQuery:{type:Function},defaultValue:{type:[String,Number,Array,Function]}},m={...g,fields:{type:[Array]},backfillToValue:{type:Function,default:e=>e},options:{type:Array,default:()=>[]},getOptions:{type:Function}};const b={...g,fields:{type:[Array]},valueKey:{type:String,required:!0},childrenKey:{type:String},emitPath:{type:[Boolean],default:!1},options:{type:Array,default:()=>[]},getOptions:{type:Function}};exports.IS_COMPOSITION_VERSION=t,exports.clone=d,exports.commonProps=g,exports.defineCommonMethod=i,exports.defineProvideValue=r,exports.emptyToValue=u,exports.get=f,exports.getChained=c,exports.getNode=function(t,...n){return t?"function"==typeof t?t(...n):"string"==typeof t?t:e.markRaw(t):null},exports.isEmptyValue=o,exports.isEqual=p,exports.isEqualExcludeEmptyValue=l,exports.isPrimitive=s,exports.plainProps=m,exports.provideKey=n,exports.treeProps=b,exports.usePlain=function(t){const r=[],i=e.inject(n),a=y(t),p=t.query&&(t.fields?.length?t.fields.map((e=>t.query[e])).filter(Boolean):t.query[t.field]),s=e.shallowRef(p||(void 0!==t.defaultValue?d(a.value):void 0)),c=e.ref([]),g=e.computed((()=>c.value.length?c.value:t.options));r.push(e.watch(g,(e=>i&&(i.options[t.field]=e)),{immediate:!0}));const m=()=>{if(t.customGetQuery)return t.customGetQuery(s.value,u,t);const e=d(s.value);return t.multiple&&t.fields?t.fields.reduce(((n,r,i)=>(n[r]=u(e?.[i],t.emptyValue),n)),{}):{[t.field]:u(e,t.emptyValue)}},b={reset(){const{multiple:e}=t;s.value=t.resetToInitialValue&&a.value?.slice()||(e?[]:"")},updateWrapperQuery(){i&&Object.entries(m()).forEach((([e,n])=>i.updateQueryValue(e,n,t.field)))},get validator(){return t.validator},getQuery:m};i?.register(b);const{insetDisabled:V,insetHide:w}=v(t,b);!p&&t.defaultValue&&b.updateWrapperQuery(),e.onBeforeUnmount((()=>r.forEach((e=>e())))),r.push(e.watch((()=>t.field),((e,t)=>{e!==t&&i?.removeUnreferencedField(t),b.updateWrapperQuery()}))),r.push(e.watch([()=>t.fields||t.field,()=>t.fields?t.fields.map((e=>t.query[e])).filter(Boolean):t.query[t.field]],(([e,n],[r])=>{const i=t.backfillToValue(n,e,t.query);s.value===i||e.toString()!==r.toString()||l(i,s.value)||s.value!==i&&(s.value=i)})));const{flag:F,updateFlag:O}=h(!0);function q(n){t.getOptions?.((e=>{const t=s.value;s.value=void 0,c.value=e||[],s.value=t}),t.query||{},{trigger:n,options:e.toRaw(i?.options)||{},changeDefaultValue(e){return a.value=e,this},change(e,t){return t&&(a.value=e),O(),Q(e),this},search(e,t){return t&&(a.value=e),O(),x(e),i?.search(),this}})}function x(e){e!==s.value&&(s.value=e,b.updateWrapperQuery())}function Q(e){x(e),i?.insetSearch()}return r.push(e.watch([()=>t.depend,()=>t.dependFields,()=>t.dependFields&&[].concat(t.dependFields).map((e=>f(t.query,e)))],(([e,n],[r,i])=>{(e!==r||e)&&(q("depend"),!o(s.value)&&F.value&&Q(t.multiple?[]:""))}),t.dependWatchOption)),r.push(e.watch([()=>t.optionsDepend,()=>i&&(t.optionsDependFields||t.dependFields)&&[].concat(t.optionsDependFields||t.dependFields).map((e=>i.options[e]))],(([e],[t])=>{(e!==t||e)&&q("depend")}))),r.push(e.watch((()=>t.getOptions),q.bind(null,"initial"))),e.nextTick(q.bind(null,"initial")),{wrapper:i,option:b,checked:s,getQuery:m,insetDisabled:V,insetHide:w,finalOption:g,updateCheckedValue:x,change:Q,reset:b.reset}},exports.useTree=function(t){const r=e.inject(n),i=y(t),a=e.ref(),p=e.ref([]),s=e.computed((()=>p.value.length?p.value:t.options)),f=e.computed((()=>t.fields?t.fields.reduce(((e,n)=>(e[n]=t.emptyValue,e)),{}):{[t.field]:t.emptyValue})),g=()=>{if(!Q.value&&!i.value)return{};let e=d(a.value);const{...n}=f.value;return t.customGetQuery?t.customGetQuery(e,u,t):e?(t.emitPath||(e=t.multiple?e.map((e=>e?.slice(-1)[0])):e.slice(-1)[0]),Array.isArray(e)?t.fields?e.forEach(((e,r)=>{n[t.fields[r]]=u(e,t.emptyValue)})):n[t.field]=e:n[t.fields?.[0]||t.field]=u(e,t.emptyValue),n):n},{flag:m,updateFlag:b}=h(),{flag:V,updateFlag:w}=h(),F={reset(){return b(),w(),a.value=t.resetToInitialValue&&i.value?.slice()||[],this},get validator(){return t.validator},updateWrapperQuery(){b(),r&&Object.entries(g()).forEach((([e,n])=>r.updateQueryValue(e,n,t.field)))},getQuery:g};r?.register(F);const{insetDisabled:O,insetHide:q}=v(t,F),x=[];e.onBeforeUnmount((()=>x.forEach((e=>e()))));const Q=e.ref("function"!=typeof t.getOptions||!!t.fields?.length);function k(n){t.getOptions?.((e=>{p.value=e||[],Q.value=!0}),t.query||{},{trigger:n,options:e.toRaw(r?.options)||{},changeDefaultValue(e){return i.value=e,this},change(e,t){return t&&(i.value=e),B(e),this},search(e,t){return t&&(i.value=e),S(e),r?.search(),this}})}function S(e){l(a.value,e)||(a.value=e,F.updateWrapperQuery())}function B(e){S(e),r?.insetSearch()}function E(e){if(o(e))return[];const{valueKey:n,childrenKey:r}=t;return c(s.value,(t=>t[n]===e)).map((e=>e[n]),r).filter(Boolean)}return e.watch(Q,(e=>e&&function(){const{backfill:e,field:n,fields:r}=t;if(e)if(r){const t=r.reduce(((t,n)=>(e[n]&&t.push(e[n]),t)),[]);if(t.length)return a.value=t,void F.updateWrapperQuery()}else if(e[n])return a.value=E(e[n]),void F.updateWrapperQuery();i.value?.length&&(a.value="string"==typeof i.value?E(i.value):i.value.slice(),"string"==typeof i.value&&(i.value=d(a.value)),F.updateWrapperQuery())}()),{immediate:!0}),x.push(e.watch((()=>t.fields||[t.field]),((e,t)=>{e.toString()!==t.toString()&&r&&t.forEach((t=>e.includes(t)||r.removeUnreferencedField(t))),F.updateWrapperQuery()}))),x.push(e.watch([()=>t.fields?.toString()||t.field,()=>t.fields?.map((e=>t.query[e])).filter(Boolean)||t.query[t.field]],(([e,t],[n,r])=>{m.value&&e===n&&l(t,r)}))),x.push(e.watch((()=>t.fields?.length?t.fields.reduce(((e,n)=>(t.backfill?.[n]&&e.push(t.backfill[n]),e)),[]):t.backfill?.[t.field]),((e,t)=>{Q.value&&(l(e,t)||w())}))),x.push(e.watch([()=>t.depend,()=>t.dependFields,()=>t.dependFields&&[].concat(t.dependFields).map((e=>t.query?.[e]))],(([e,t],[n,r])=>{m.value&&(e!==n||e)&&(k("depend"),o(a.value)||B(void 0))}))),x.push(e.watch((()=>t.getOptions),k.bind(null,"initial"),{immediate:!0})),{wrapper:r,option:F,checked:a,getQuery:g,finalOption:s,insetDisabled:O,insetHide:q,change:B,reset:F.reset}},exports.useWrapper=function(r,i){const a=[];e.onBeforeUnmount((()=>a.splice(0)));const u=e.computed((()=>r.emptyValue?.()));let l=!1,o=[];const p=e.reactive({}),s={realtime:e.toRef(r,"realtime",!1),queryChangedInWrapper:e.ref(!1),register(n){a.push(n);const i=()=>{l=!0,n.reset(),n.updateWrapperQuery();const t=a.indexOf(n);-1!==t&&a.splice(t,1),r.searchAtDatumChanged&&f(),l=!1,o.forEach((t=>{e.del(d.value,t)})),o=[]},u=e.getCurrentInstance();return u&&e.onBeforeUnmount(i,t?u.proxy:u),i},updateQueryValue(t,n,a){r.emptyValues.includes(n)&&n!==u.value&&(n=u.value),l&&o.push(t),e.set(d.value,t,n),i?.fieldChange?.({field:t,value:n,query:d.value,nativeField:a})},insetSearch(){r.realtime&&f()},search:f,removeUnreferencedField(t){let n=0;a.some((e=>(e.getQuery().hasOwnProperty(t)&&(n+=1),n))),n||e.del(d.value,t)},options:p};e.provide(n,s);const d=e.ref({...r.backfill}),c=()=>({...d.value});async function f(){const e=await y();e?r.toast?.(e):i?.search?.(c())}async function y(){return(await Promise.all(a.map((e=>e.validator?.(d.value))))).find((e=>e&&"string"==typeof e))}return e.watch((()=>r.backfill),(t=>{s.queryChangedInWrapper.value=!0,Object.keys(d.value).forEach((e=>{t?.hasOwnProperty(e)||delete d.value[e]})),t&&Object.assign(d.value,t),e.nextTick((()=>{s.queryChangedInWrapper.value=!1}))}),{deep:!0}),{child:a,wrapperInstance:s,query:d,getQuery:c,search:f,reset:function(){a.forEach((e=>{e.reset(),e.updateWrapperQuery()})),i?.reset?.(c())},validate:y}},exports.wrapperProps=a;
//# sourceMappingURL=index.cjs.min.js.map

@@ -408,2 +408,7 @@ import { version, onBeforeUnmount, computed, reactive, toRef, ref, getCurrentInstance, set, del, provide, watch, nextTick, markRaw, inject, shallowRef, toRaw } from 'vue-demi';

}));
/** 是否允许依赖变动时, 重置值(外部通过 search, change 主动改变值时, 内部应取消重置) */
const {
flag: allowDependChangeValue,
updateFlag: updateAllowDependChangeValue
} = useDisableInCurrentCycle(true);
// 存在依赖项

@@ -416,6 +421,7 @@ unwatchs.push(watch([() => props.depend, () => props.dependFields, () => props.dependFields && [].concat(props.dependFields).map(k => get(props.query, k))], ([_depend, _dependFields], [__depend, __dependFields]) => {

// 防止表单类监测值发生改变时触发校验
if (isEmptyValue(checked.value)) return;
// 或内部不允许重置时直接返回
if (isEmptyValue(checked.value) || !allowDependChangeValue.value) return;
change(props.multiple ? [] : '');
}, props.dependWatchOption));
// 存在依赖项
// 存在选项变动依赖项时
unwatchs.push(watch([() => props.optionsDepend, () => wrapper && (props.optionsDependFields || props.dependFields) && [].concat(props.optionsDependFields || props.dependFields).map(k => wrapper.options[k])], ([_depend], [__depend]) => {

@@ -446,2 +452,3 @@ // 是否启用依赖, 相同时启用才走后续逻辑, 不同时直接走后续逻辑

isInitial && (initialValue.value = value);
updateAllowDependChangeValue();
change(value);

@@ -452,2 +459,3 @@ return this;

isInitial && (initialValue.value = value);
updateAllowDependChangeValue();
updateCheckedValue(value);

@@ -454,0 +462,0 @@ wrapper?.search();

@@ -1,2 +0,2 @@

import{version as e,onBeforeUnmount as t,computed as n,reactive as i,toRef as l,ref as u,getCurrentInstance as a,set as r,del as o,provide as d,watch as p,nextTick as s,markRaw as f,inject as c,shallowRef as y,toRaw as v}from"vue-demi";const h="2.7"===e.slice(0,3),g="condition-wrapper";function m(e){return e}function b(e){return e}function F(e,f){const c=[];t((()=>c.splice(0)));const y=n((()=>e.emptyValue?.()));let v=!1,m=[];const b=i({}),F={realtime:l(e,"realtime",!1),queryChangedInWrapper:u(!1),register(n){c.push(n);const i=()=>{v=!0,n.reset(),n.updateWrapperQuery();const t=c.indexOf(n);-1!==t&&c.splice(t,1),e.searchAtDatumChanged&&q(),v=!1,m.forEach((e=>{o(V.value,e)})),m=[]},l=a();return l&&t(i,h?l.proxy:l),i},updateQueryValue(t,n,i){e.emptyValues.includes(n)&&n!==y.value&&(n=y.value),v&&m.push(t),r(V.value,t,n),f?.fieldChange?.({field:t,value:n,query:V.value,nativeField:i})},insetSearch(){e.realtime&&q()},search:q,removeUnreferencedField(e){let t=0;c.some((n=>(n.getQuery().hasOwnProperty(e)&&(t+=1),t))),t||o(V.value,e)},options:b};d(g,F);const V=u({...e.backfill}),Q=()=>({...V.value});async function q(){const t=await O();t?e.toast?.(t):f?.search?.(Q())}async function O(){return(await Promise.all(c.map((e=>e.validator?.(V.value))))).find((e=>e&&"string"==typeof e))}return p((()=>e.backfill),(e=>{F.queryChangedInWrapper.value=!0,Object.keys(V.value).forEach((t=>{e?.hasOwnProperty(t)||delete V.value[t]})),e&&Object.assign(V.value,e),s((()=>{F.queryChangedInWrapper.value=!1}))}),{deep:!0}),{child:c,wrapperInstance:F,query:V,getQuery:Q,search:q,reset:function(){c.forEach((e=>{e.reset(),e.updateWrapperQuery()})),f?.reset?.(Q())},validate:O}}const V={realtime:{type:Boolean,default:void 0},searchAtDatumChanged:{type:Boolean,default:void 0},backfill:{type:Object},toast:{type:Function,default:void 0},emptyValues:{type:Array,default:()=>["",null,void 0]},emptyValue:{type:Function,default:void 0}};function Q(e,t){return"number"==typeof e?e:e||t}function q(e,t){return O(e)&&O(t)||k(e,t)}function O(e){return void 0===e||""===e||null===e}function k(e,t){if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const n=Reflect.ownKeys(e),i=Reflect.ownKeys(t);if(n.length!==i.length)return!1;for(let i=0;i<n.length;i++){if(!Reflect.has(t,n[i]))return!1;if(!k(e[n[i]],t[n[i]]))return!1}return!0}function S(e){return null==e||"object"!=typeof e&&"function"!=typeof e}function W(e,t){if(S(e))return e;if("function"==typeof e)return e.bind({});const n=new e.constructor;return Object.getOwnPropertyNames(e).forEach((i=>{n[i]=t?W(e[i]):e[i]})),n}function D(e,t,n="children"){for(const i of e){if(t(i))return[i];if(i[n]?.length){const e=D(i[n],t);if(e.length)return e.unshift(i),e}}return[]}function B(e,...t){return e?"function"==typeof e?e(...t):"string"==typeof e?e:f(e):null}function j(e,t,n){const i=t.split(/[\.\[\]]/g);let l=e;for(const e of i){if(null===l)return n;if(void 0===l)return n;const t=e.replace(/['"]/g,"");""!==t.trim()&&(l=l[t])}return void 0===l?n:l}function E(e){const t=u();return n({set(e){t.value=e},get:()=>void 0===t.value?void 0!==e.defaultValue?"function"==typeof e.defaultValue?e.defaultValue(e.query,e.backfill):e.defaultValue:void 0:t.value})}function w(e,n){const i=u("boolean"==typeof e.disabled&&e.disabled),l=u("boolean"==typeof e.hide&&e.hide),a=()=>({query:e.query,backfill:e.backfill,option:n}),r=()=>{if("function"==typeof e.hide){l.value!==e.hide(a())&&(l.value=e.hide(a()))}else if("function"==typeof e.disabled){i.value!==e.disabled(a())&&(i.value=e.disabled(a()))}};let o=[p((()=>e.query),r,{immediate:!0,deep:!0}),p((()=>[e.disabled,e.hide]),((e,t)=>{e[0]!==t[0]&&(i.value="boolean"==typeof e[0]&&e[0],e[0]),e[1]!==t[1]&&(l.value="boolean"==typeof e[1]&&e[1],e[1]),r()}))];return t((()=>(o.forEach((e=>e())),o=[]))),{insetDisabled:i,insetHide:l}}function A(e=!0){const t=u(e);return{flag:t,updateFlag:()=>{t.value=!e,s((()=>{t.value=e}))}}}function C(e){const i=[],l=c(g),a=E(e),r=e.query&&(e.fields?.length?e.fields.map((t=>e.query[t])).filter(Boolean):e.query[e.field]),o=y(r||(void 0!==e.defaultValue?W(a.value):void 0)),d=u([]),f=n((()=>d.value.length?d.value:e.options));i.push(p(f,(t=>l&&(l.options[e.field]=t)),{immediate:!0}));const h=()=>{if(e.customGetQuery)return e.customGetQuery(o.value,Q,e);const t=W(o.value);return e.multiple&&e.fields?e.fields.reduce(((n,i,l)=>(n[i]=Q(t?.[l],e.emptyValue),n)),{}):{[e.field]:Q(t,e.emptyValue)}},m={reset(){const{multiple:t}=e;o.value=e.resetToInitialValue&&a.value?.slice()||(t?[]:"")},updateWrapperQuery(){l&&Object.entries(h()).forEach((([t,n])=>l.updateQueryValue(t,n,e.field)))},get validator(){return e.validator},getQuery:h};l?.register(m);const{insetDisabled:b,insetHide:F}=w(e,m);function V(t){e.getOptions?.((e=>{const t=o.value;o.value=void 0,d.value=e||[],o.value=t}),e.query||{},{trigger:t,options:v(l?.options)||{},changeDefaultValue(e){return a.value=e,this},change(e,t){return t&&(a.value=e),S(e),this},search(e,t){return t&&(a.value=e),k(e),l?.search(),this}})}function k(e){e!==o.value&&(o.value=e,m.updateWrapperQuery())}function S(e){k(e),l?.insetSearch()}return!r&&e.defaultValue&&m.updateWrapperQuery(),t((()=>i.forEach((e=>e())))),i.push(p((()=>e.field),((e,t)=>{e!==t&&l?.removeUnreferencedField(t),m.updateWrapperQuery()}))),i.push(p([()=>e.fields||e.field,()=>e.fields?e.fields.map((t=>e.query[t])).filter(Boolean):e.query[e.field]],(([t,n],[i])=>{const l=e.backfillToValue(n,t,e.query);o.value===l||t.toString()!==i.toString()||q(l,o.value)||o.value!==l&&(o.value=l)}))),i.push(p([()=>e.depend,()=>e.dependFields,()=>e.dependFields&&[].concat(e.dependFields).map((t=>j(e.query,t)))],(([t,n],[i,l])=>{(t!==i||t)&&(V("depend"),O(o.value)||S(e.multiple?[]:""))}),e.dependWatchOption)),i.push(p([()=>e.optionsDepend,()=>l&&(e.optionsDependFields||e.dependFields)&&[].concat(e.optionsDependFields||e.dependFields).map((e=>l.options[e]))],(([e],[t])=>{(e!==t||e)&&V("depend")}))),i.push(p((()=>e.getOptions),V.bind(null,"initial"))),s(V.bind(null,"initial")),{wrapper:l,option:m,checked:o,getQuery:h,insetDisabled:b,insetHide:F,finalOption:f,updateCheckedValue:k,change:S,reset:m.reset}}const I={field:{type:String,required:!0},multiple:{type:Boolean,default:void 0},query:{type:Object,required:!0},backfill:{type:Object},disabled:{type:[Boolean,Function]},hide:{type:[Boolean,Function]},depend:{type:Boolean},dependFields:{type:[String,Array]},dependWatchOption:{type:[Object]},optionsDepend:{type:Boolean},optionsDependFields:{type:[String,Array]},resetToInitialValue:{type:[Boolean]},emptyValue:{type:[String,Number,Boolean,null,void 0],default:void 0},validator:{type:[Function]},customGetQuery:{type:Function},defaultValue:{type:[String,Number,Array,Function]}},T={...I,fields:{type:[Array]},backfillToValue:{type:Function,default:e=>e},options:{type:Array,default:()=>[]},getOptions:{type:Function}};function K(e){const i=c(g),l=E(e),a=u(),r=u([]),o=n((()=>r.value.length?r.value:e.options)),d=n((()=>e.fields?e.fields.reduce(((t,n)=>(t[n]=e.emptyValue,t)),{}):{[e.field]:e.emptyValue})),s=()=>{if(!S.value&&!l.value)return{};let t=W(a.value);const{...n}=d.value;return e.customGetQuery?e.customGetQuery(t,Q,e):t?(e.emitPath||(t=e.multiple?t.map((e=>e?.slice(-1)[0])):t.slice(-1)[0]),Array.isArray(t)?e.fields?t.forEach(((t,i)=>{n[e.fields[i]]=Q(t,e.emptyValue)})):n[e.field]=t:n[e.fields?.[0]||e.field]=Q(t,e.emptyValue),n):n},{flag:f,updateFlag:y}=A(),{flag:h,updateFlag:m}=A(),b={reset(){return y(),m(),a.value=e.resetToInitialValue&&l.value?.slice()||[],this},get validator(){return e.validator},updateWrapperQuery(){y(),i&&Object.entries(s()).forEach((([t,n])=>i.updateQueryValue(t,n,e.field)))},getQuery:s};i?.register(b);const{insetDisabled:F,insetHide:V}=w(e,b),k=[];t((()=>k.forEach((e=>e()))));const S=u("function"!=typeof e.getOptions||!!e.fields?.length);function B(t){e.getOptions?.((e=>{r.value=e||[],S.value=!0}),e.query||{},{trigger:t,options:v(i?.options)||{},changeDefaultValue(e){return l.value=e,this},change(e,t){return t&&(l.value=e),C(e),this},search(e,t){return t&&(l.value=e),j(e),i?.search(),this}})}function j(e){q(a.value,e)||(a.value=e,b.updateWrapperQuery())}function C(e){j(e),i?.insetSearch()}function I(t){if(O(t))return[];const{valueKey:n,childrenKey:i}=e;return D(o.value,(e=>e[n]===t)).map((e=>e[n]),i).filter(Boolean)}return p(S,(t=>t&&function(){const{backfill:t,field:n,fields:i}=e;if(t)if(i){const e=i.reduce(((e,n)=>(t[n]&&e.push(t[n]),e)),[]);if(e.length)return a.value=e,void b.updateWrapperQuery()}else if(t[n])return a.value=I(t[n]),void b.updateWrapperQuery();l.value?.length&&(a.value="string"==typeof l.value?I(l.value):l.value.slice(),"string"==typeof l.value&&(l.value=W(a.value)),b.updateWrapperQuery())}()),{immediate:!0}),k.push(p((()=>e.fields||[e.field]),((e,t)=>{e.toString()!==t.toString()&&i&&t.forEach((t=>e.includes(t)||i.removeUnreferencedField(t))),b.updateWrapperQuery()}))),k.push(p([()=>e.fields?.toString()||e.field,()=>e.fields?.map((t=>e.query[t])).filter(Boolean)||e.query[e.field]],(([e,t],[n,i])=>{f.value&&e===n&&q(t,i)}))),k.push(p((()=>e.fields?.length?e.fields.reduce(((t,n)=>(e.backfill?.[n]&&t.push(e.backfill[n]),t)),[]):e.backfill?.[e.field]),((e,t)=>{S.value&&(q(e,t)||m())}))),k.push(p([()=>e.depend,()=>e.dependFields,()=>e.dependFields&&[].concat(e.dependFields).map((t=>e.query?.[t]))],(([e,t],[n,i])=>{f.value&&(e!==n||e)&&(B("depend"),O(a.value)||C(void 0))}))),k.push(p((()=>e.getOptions),B.bind(null,"initial"),{immediate:!0})),{wrapper:i,option:b,checked:a,getQuery:s,finalOption:o,insetDisabled:F,insetHide:V,change:C,reset:b.reset}}const P={...I,fields:{type:[Array]},valueKey:{type:String,required:!0},childrenKey:{type:String},emitPath:{type:[Boolean],default:!1},options:{type:Array,default:()=>[]},getOptions:{type:Function}};export{h as IS_COMPOSITION_VERSION,W as clone,I as commonProps,b as defineCommonMethod,m as defineProvideValue,Q as emptyToValue,j as get,D as getChained,B as getNode,O as isEmptyValue,k as isEqual,q as isEqualExcludeEmptyValue,S as isPrimitive,T as plainProps,g as provideKey,P as treeProps,C as usePlain,K as useTree,F as useWrapper,V as wrapperProps};
import{version as e,onBeforeUnmount as t,computed as n,reactive as i,toRef as l,ref as u,getCurrentInstance as a,set as r,del as o,provide as d,watch as p,nextTick as s,markRaw as f,inject as c,shallowRef as y,toRaw as v}from"vue-demi";const h="2.7"===e.slice(0,3),g="condition-wrapper";function m(e){return e}function b(e){return e}function F(e,f){const c=[];t((()=>c.splice(0)));const y=n((()=>e.emptyValue?.()));let v=!1,m=[];const b=i({}),F={realtime:l(e,"realtime",!1),queryChangedInWrapper:u(!1),register(n){c.push(n);const i=()=>{v=!0,n.reset(),n.updateWrapperQuery();const t=c.indexOf(n);-1!==t&&c.splice(t,1),e.searchAtDatumChanged&&q(),v=!1,m.forEach((e=>{o(V.value,e)})),m=[]},l=a();return l&&t(i,h?l.proxy:l),i},updateQueryValue(t,n,i){e.emptyValues.includes(n)&&n!==y.value&&(n=y.value),v&&m.push(t),r(V.value,t,n),f?.fieldChange?.({field:t,value:n,query:V.value,nativeField:i})},insetSearch(){e.realtime&&q()},search:q,removeUnreferencedField(e){let t=0;c.some((n=>(n.getQuery().hasOwnProperty(e)&&(t+=1),t))),t||o(V.value,e)},options:b};d(g,F);const V=u({...e.backfill}),Q=()=>({...V.value});async function q(){const t=await O();t?e.toast?.(t):f?.search?.(Q())}async function O(){return(await Promise.all(c.map((e=>e.validator?.(V.value))))).find((e=>e&&"string"==typeof e))}return p((()=>e.backfill),(e=>{F.queryChangedInWrapper.value=!0,Object.keys(V.value).forEach((t=>{e?.hasOwnProperty(t)||delete V.value[t]})),e&&Object.assign(V.value,e),s((()=>{F.queryChangedInWrapper.value=!1}))}),{deep:!0}),{child:c,wrapperInstance:F,query:V,getQuery:Q,search:q,reset:function(){c.forEach((e=>{e.reset(),e.updateWrapperQuery()})),f?.reset?.(Q())},validate:O}}const V={realtime:{type:Boolean,default:void 0},searchAtDatumChanged:{type:Boolean,default:void 0},backfill:{type:Object},toast:{type:Function,default:void 0},emptyValues:{type:Array,default:()=>["",null,void 0]},emptyValue:{type:Function,default:void 0}};function Q(e,t){return"number"==typeof e?e:e||t}function q(e,t){return O(e)&&O(t)||k(e,t)}function O(e){return void 0===e||""===e||null===e}function k(e,t){if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const n=Reflect.ownKeys(e),i=Reflect.ownKeys(t);if(n.length!==i.length)return!1;for(let i=0;i<n.length;i++){if(!Reflect.has(t,n[i]))return!1;if(!k(e[n[i]],t[n[i]]))return!1}return!0}function S(e){return null==e||"object"!=typeof e&&"function"!=typeof e}function W(e,t){if(S(e))return e;if("function"==typeof e)return e.bind({});const n=new e.constructor;return Object.getOwnPropertyNames(e).forEach((i=>{n[i]=t?W(e[i]):e[i]})),n}function D(e,t,n="children"){for(const i of e){if(t(i))return[i];if(i[n]?.length){const e=D(i[n],t);if(e.length)return e.unshift(i),e}}return[]}function B(e,...t){return e?"function"==typeof e?e(...t):"string"==typeof e?e:f(e):null}function j(e,t,n){const i=t.split(/[\.\[\]]/g);let l=e;for(const e of i){if(null===l)return n;if(void 0===l)return n;const t=e.replace(/['"]/g,"");""!==t.trim()&&(l=l[t])}return void 0===l?n:l}function E(e){const t=u();return n({set(e){t.value=e},get:()=>void 0===t.value?void 0!==e.defaultValue?"function"==typeof e.defaultValue?e.defaultValue(e.query,e.backfill):e.defaultValue:void 0:t.value})}function w(e,n){const i=u("boolean"==typeof e.disabled&&e.disabled),l=u("boolean"==typeof e.hide&&e.hide),a=()=>({query:e.query,backfill:e.backfill,option:n}),r=()=>{if("function"==typeof e.hide){l.value!==e.hide(a())&&(l.value=e.hide(a()))}else if("function"==typeof e.disabled){i.value!==e.disabled(a())&&(i.value=e.disabled(a()))}};let o=[p((()=>e.query),r,{immediate:!0,deep:!0}),p((()=>[e.disabled,e.hide]),((e,t)=>{e[0]!==t[0]&&(i.value="boolean"==typeof e[0]&&e[0],e[0]),e[1]!==t[1]&&(l.value="boolean"==typeof e[1]&&e[1],e[1]),r()}))];return t((()=>(o.forEach((e=>e())),o=[]))),{insetDisabled:i,insetHide:l}}function A(e=!0){const t=u(e);return{flag:t,updateFlag:()=>{t.value=!e,s((()=>{t.value=e}))}}}function C(e){const i=[],l=c(g),a=E(e),r=e.query&&(e.fields?.length?e.fields.map((t=>e.query[t])).filter(Boolean):e.query[e.field]),o=y(r||(void 0!==e.defaultValue?W(a.value):void 0)),d=u([]),f=n((()=>d.value.length?d.value:e.options));i.push(p(f,(t=>l&&(l.options[e.field]=t)),{immediate:!0}));const h=()=>{if(e.customGetQuery)return e.customGetQuery(o.value,Q,e);const t=W(o.value);return e.multiple&&e.fields?e.fields.reduce(((n,i,l)=>(n[i]=Q(t?.[l],e.emptyValue),n)),{}):{[e.field]:Q(t,e.emptyValue)}},m={reset(){const{multiple:t}=e;o.value=e.resetToInitialValue&&a.value?.slice()||(t?[]:"")},updateWrapperQuery(){l&&Object.entries(h()).forEach((([t,n])=>l.updateQueryValue(t,n,e.field)))},get validator(){return e.validator},getQuery:h};l?.register(m);const{insetDisabled:b,insetHide:F}=w(e,m);!r&&e.defaultValue&&m.updateWrapperQuery(),t((()=>i.forEach((e=>e())))),i.push(p((()=>e.field),((e,t)=>{e!==t&&l?.removeUnreferencedField(t),m.updateWrapperQuery()}))),i.push(p([()=>e.fields||e.field,()=>e.fields?e.fields.map((t=>e.query[t])).filter(Boolean):e.query[e.field]],(([t,n],[i])=>{const l=e.backfillToValue(n,t,e.query);o.value===l||t.toString()!==i.toString()||q(l,o.value)||o.value!==l&&(o.value=l)})));const{flag:V,updateFlag:k}=A(!0);function S(t){e.getOptions?.((e=>{const t=o.value;o.value=void 0,d.value=e||[],o.value=t}),e.query||{},{trigger:t,options:v(l?.options)||{},changeDefaultValue(e){return a.value=e,this},change(e,t){return t&&(a.value=e),k(),B(e),this},search(e,t){return t&&(a.value=e),k(),D(e),l?.search(),this}})}function D(e){e!==o.value&&(o.value=e,m.updateWrapperQuery())}function B(e){D(e),l?.insetSearch()}return i.push(p([()=>e.depend,()=>e.dependFields,()=>e.dependFields&&[].concat(e.dependFields).map((t=>j(e.query,t)))],(([t,n],[i,l])=>{(t!==i||t)&&(S("depend"),!O(o.value)&&V.value&&B(e.multiple?[]:""))}),e.dependWatchOption)),i.push(p([()=>e.optionsDepend,()=>l&&(e.optionsDependFields||e.dependFields)&&[].concat(e.optionsDependFields||e.dependFields).map((e=>l.options[e]))],(([e],[t])=>{(e!==t||e)&&S("depend")}))),i.push(p((()=>e.getOptions),S.bind(null,"initial"))),s(S.bind(null,"initial")),{wrapper:l,option:m,checked:o,getQuery:h,insetDisabled:b,insetHide:F,finalOption:f,updateCheckedValue:D,change:B,reset:m.reset}}const I={field:{type:String,required:!0},multiple:{type:Boolean,default:void 0},query:{type:Object,required:!0},backfill:{type:Object},disabled:{type:[Boolean,Function]},hide:{type:[Boolean,Function]},depend:{type:Boolean},dependFields:{type:[String,Array]},dependWatchOption:{type:[Object]},optionsDepend:{type:Boolean},optionsDependFields:{type:[String,Array]},resetToInitialValue:{type:[Boolean]},emptyValue:{type:[String,Number,Boolean,null,void 0],default:void 0},validator:{type:[Function]},customGetQuery:{type:Function},defaultValue:{type:[String,Number,Array,Function]}},T={...I,fields:{type:[Array]},backfillToValue:{type:Function,default:e=>e},options:{type:Array,default:()=>[]},getOptions:{type:Function}};function K(e){const i=c(g),l=E(e),a=u(),r=u([]),o=n((()=>r.value.length?r.value:e.options)),d=n((()=>e.fields?e.fields.reduce(((t,n)=>(t[n]=e.emptyValue,t)),{}):{[e.field]:e.emptyValue})),s=()=>{if(!S.value&&!l.value)return{};let t=W(a.value);const{...n}=d.value;return e.customGetQuery?e.customGetQuery(t,Q,e):t?(e.emitPath||(t=e.multiple?t.map((e=>e?.slice(-1)[0])):t.slice(-1)[0]),Array.isArray(t)?e.fields?t.forEach(((t,i)=>{n[e.fields[i]]=Q(t,e.emptyValue)})):n[e.field]=t:n[e.fields?.[0]||e.field]=Q(t,e.emptyValue),n):n},{flag:f,updateFlag:y}=A(),{flag:h,updateFlag:m}=A(),b={reset(){return y(),m(),a.value=e.resetToInitialValue&&l.value?.slice()||[],this},get validator(){return e.validator},updateWrapperQuery(){y(),i&&Object.entries(s()).forEach((([t,n])=>i.updateQueryValue(t,n,e.field)))},getQuery:s};i?.register(b);const{insetDisabled:F,insetHide:V}=w(e,b),k=[];t((()=>k.forEach((e=>e()))));const S=u("function"!=typeof e.getOptions||!!e.fields?.length);function B(t){e.getOptions?.((e=>{r.value=e||[],S.value=!0}),e.query||{},{trigger:t,options:v(i?.options)||{},changeDefaultValue(e){return l.value=e,this},change(e,t){return t&&(l.value=e),C(e),this},search(e,t){return t&&(l.value=e),j(e),i?.search(),this}})}function j(e){q(a.value,e)||(a.value=e,b.updateWrapperQuery())}function C(e){j(e),i?.insetSearch()}function I(t){if(O(t))return[];const{valueKey:n,childrenKey:i}=e;return D(o.value,(e=>e[n]===t)).map((e=>e[n]),i).filter(Boolean)}return p(S,(t=>t&&function(){const{backfill:t,field:n,fields:i}=e;if(t)if(i){const e=i.reduce(((e,n)=>(t[n]&&e.push(t[n]),e)),[]);if(e.length)return a.value=e,void b.updateWrapperQuery()}else if(t[n])return a.value=I(t[n]),void b.updateWrapperQuery();l.value?.length&&(a.value="string"==typeof l.value?I(l.value):l.value.slice(),"string"==typeof l.value&&(l.value=W(a.value)),b.updateWrapperQuery())}()),{immediate:!0}),k.push(p((()=>e.fields||[e.field]),((e,t)=>{e.toString()!==t.toString()&&i&&t.forEach((t=>e.includes(t)||i.removeUnreferencedField(t))),b.updateWrapperQuery()}))),k.push(p([()=>e.fields?.toString()||e.field,()=>e.fields?.map((t=>e.query[t])).filter(Boolean)||e.query[e.field]],(([e,t],[n,i])=>{f.value&&e===n&&q(t,i)}))),k.push(p((()=>e.fields?.length?e.fields.reduce(((t,n)=>(e.backfill?.[n]&&t.push(e.backfill[n]),t)),[]):e.backfill?.[e.field]),((e,t)=>{S.value&&(q(e,t)||m())}))),k.push(p([()=>e.depend,()=>e.dependFields,()=>e.dependFields&&[].concat(e.dependFields).map((t=>e.query?.[t]))],(([e,t],[n,i])=>{f.value&&(e!==n||e)&&(B("depend"),O(a.value)||C(void 0))}))),k.push(p((()=>e.getOptions),B.bind(null,"initial"),{immediate:!0})),{wrapper:i,option:b,checked:a,getQuery:s,finalOption:o,insetDisabled:F,insetHide:V,change:C,reset:b.reset}}const P={...I,fields:{type:[Array]},valueKey:{type:String,required:!0},childrenKey:{type:String},emitPath:{type:[Boolean],default:!1},options:{type:Array,default:()=>[]},getOptions:{type:Function}};export{h as IS_COMPOSITION_VERSION,W as clone,I as commonProps,b as defineCommonMethod,m as defineProvideValue,Q as emptyToValue,j as get,D as getChained,B as getNode,O as isEmptyValue,k as isEqual,q as isEqualExcludeEmptyValue,S as isPrimitive,T as plainProps,g as provideKey,P as treeProps,C as usePlain,K as useTree,F as useWrapper,V as wrapperProps};
//# sourceMappingURL=index.esm.min.js.map

@@ -528,2 +528,7 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {

}));
/** 是否允许依赖变动时, 重置值(外部通过 search, change 主动改变值时, 内部应取消重置) */
const {
flag: allowDependChangeValue,
updateFlag: updateAllowDependChangeValue
} = useDisableInCurrentCycle(true);
// 存在依赖项

@@ -536,6 +541,7 @@ unwatchs.push(vueDemi.watch([() => props.depend, () => props.dependFields, () => props.dependFields && [].concat(props.dependFields).map(k => get(props.query, k))], ([_depend, _dependFields], [__depend, __dependFields]) => {

// 防止表单类监测值发生改变时触发校验
if (isEmptyValue(checked.value)) return;
// 或内部不允许重置时直接返回
if (isEmptyValue(checked.value) || !allowDependChangeValue.value) return;
change(props.multiple ? [] : '');
}, props.dependWatchOption));
// 存在依赖项
// 存在选项变动依赖项时
unwatchs.push(vueDemi.watch([() => props.optionsDepend, () => wrapper && (props.optionsDependFields || props.dependFields) && [].concat(props.optionsDependFields || props.dependFields).map(k => wrapper.options[k])], ([_depend], [__depend]) => {

@@ -566,2 +572,3 @@ // 是否启用依赖, 相同时启用才走后续逻辑, 不同时直接走后续逻辑

isInitial && (initialValue.value = value);
updateAllowDependChangeValue();
change(value);

@@ -572,2 +579,3 @@ return this;

isInitial && (initialValue.value = value);
updateAllowDependChangeValue();
updateCheckedValue(value);

@@ -574,0 +582,0 @@ wrapper?.search();

@@ -1,2 +0,2 @@

var VueDemi=function(e,t,n){if(e.install)return e;if(!t)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),e;if("2.7."===t.version.slice(0,4)){for(var i in t)e[i]=t[i];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=t,e.Vue2=t,e.version=t.version,e.warn=t.util.warn,e.hasInjectionContext=()=>!!e.getCurrentInstance(),e.createApp=function(e,n){var i,u={},r={config:t.config,use:t.use.bind(t),mixin:t.mixin.bind(t),component:t.component.bind(t),provide:function(e,t){return u[e]=t,this},directive:function(e,n){return n?(t.directive(e,n),r):t.directive(e)},mount:function(r,o){return i||((i=new t(Object.assign({propsData:n},e,{provide:Object.assign(u,e.provide)}))).$mount(r,o),i)},unmount:function(){i&&(i.$destroy(),i=void 0)}};return r}}else if("2."===t.version.slice(0,2))if(n){for(var i in n)e[i]=n[i];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=t,e.Vue2=t,e.version=t.version,e.hasInjectionContext=()=>!!e.getCurrentInstance()}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if("3."===t.version.slice(0,2)){for(var i in t)e[i]=t[i];e.isVue2=!1,e.isVue3=!0,e.install=function(){},e.Vue=t,e.Vue2=void 0,e.version=t.version,e.set=function(e,t,n){return Array.isArray(e)?(e.length=Math.max(e.length,t),e.splice(t,1,n),n):(e[t]=n,n)},e.del=function(e,t){Array.isArray(e)?e.splice(t,1):delete e[t]}}else console.error("[vue-demi] Vue version "+t.version+" is unsupported.");return e}(this.VueDemi=this.VueDemi||(void 0!==VueDemi?VueDemi:{}),this.Vue||("undefined"!=typeof Vue?Vue:void 0),this.VueCompositionAPI||("undefined"!=typeof VueCompositionAPI?VueCompositionAPI:void 0));!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue-demi")):"function"==typeof define&&define.amd?define(["exports","vue-demi"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CoreCondition={},e.VueDemi)}(this,(function(e,t){"use strict";const n="2.7"===t.version.slice(0,3),i="condition-wrapper";function u(e){return e}function r(e){return e}const o={realtime:{type:Boolean,default:void 0},searchAtDatumChanged:{type:Boolean,default:void 0},backfill:{type:Object},toast:{type:Function,default:void 0},emptyValues:{type:Array,default:()=>["",null,void 0]},emptyValue:{type:Function,default:void 0}};function a(e,t){return"number"==typeof e?e:e||t}function l(e,t){return s(e)&&s(t)||d(e,t)}function s(e){return void 0===e||""===e||null===e}function d(e,t){if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const n=Reflect.ownKeys(e),i=Reflect.ownKeys(t);if(n.length!==i.length)return!1;for(let i=0;i<n.length;i++){if(!Reflect.has(t,n[i]))return!1;if(!d(e[n[i]],t[n[i]]))return!1}return!0}function p(e){return null==e||"object"!=typeof e&&"function"!=typeof e}function c(e,t){if(p(e))return e;if("function"==typeof e)return e.bind({});const n=new e.constructor;return Object.getOwnPropertyNames(e).forEach((i=>{n[i]=t?c(e[i]):e[i]})),n}function f(e,t,n="children"){for(const i of e){if(t(i))return[i];if(i[n]?.length){const e=f(i[n],t);if(e.length)return e.unshift(i),e}}return[]}function v(e,t,n){const i=t.split(/[\.\[\]]/g);let u=e;for(const e of i){if(null===u)return n;if(void 0===u)return n;const t=e.replace(/['"]/g,"");""!==t.trim()&&(u=u[t])}return void 0===u?n:u}function y(e){const n=t.ref();return t.computed({set(e){n.value=e},get:()=>void 0===n.value?void 0!==e.defaultValue?"function"==typeof e.defaultValue?e.defaultValue(e.query,e.backfill):e.defaultValue:void 0:n.value})}function h(e,n){const i=t.ref("boolean"==typeof e.disabled&&e.disabled),u=t.ref("boolean"==typeof e.hide&&e.hide),r=()=>({query:e.query,backfill:e.backfill,option:n}),o=()=>{if("function"==typeof e.hide){u.value!==e.hide(r())&&(u.value=e.hide(r()))}else if("function"==typeof e.disabled){i.value!==e.disabled(r())&&(i.value=e.disabled(r()))}};let a=[t.watch((()=>e.query),o,{immediate:!0,deep:!0}),t.watch((()=>[e.disabled,e.hide]),((e,t)=>{e[0]!==t[0]&&(i.value="boolean"==typeof e[0]&&e[0],e[0]),e[1]!==t[1]&&(u.value="boolean"==typeof e[1]&&e[1],e[1]),o()}))];return t.onBeforeUnmount((()=>(a.forEach((e=>e())),a=[]))),{insetDisabled:i,insetHide:u}}function m(e=!0){const n=t.ref(e);return{flag:n,updateFlag:()=>{n.value=!e,t.nextTick((()=>{n.value=e}))}}}const g={field:{type:String,required:!0},multiple:{type:Boolean,default:void 0},query:{type:Object,required:!0},backfill:{type:Object},disabled:{type:[Boolean,Function]},hide:{type:[Boolean,Function]},depend:{type:Boolean},dependFields:{type:[String,Array]},dependWatchOption:{type:[Object]},optionsDepend:{type:Boolean},optionsDependFields:{type:[String,Array]},resetToInitialValue:{type:[Boolean]},emptyValue:{type:[String,Number,Boolean,null,void 0],default:void 0},validator:{type:[Function]},customGetQuery:{type:Function},defaultValue:{type:[String,Number,Array,Function]}},b={...g,fields:{type:[Array]},backfillToValue:{type:Function,default:e=>e},options:{type:Array,default:()=>[]},getOptions:{type:Function}};const V={...g,fields:{type:[Array]},valueKey:{type:String,required:!0},childrenKey:{type:String},emitPath:{type:[Boolean],default:!1},options:{type:Array,default:()=>[]},getOptions:{type:Function}};e.IS_COMPOSITION_VERSION=n,e.clone=c,e.commonProps=g,e.defineCommonMethod=r,e.defineProvideValue=u,e.emptyToValue=a,e.get=v,e.getChained=f,e.getNode=function(e,...n){return e?"function"==typeof e?e(...n):"string"==typeof e?e:t.markRaw(e):null},e.isEmptyValue=s,e.isEqual=d,e.isEqualExcludeEmptyValue=l,e.isPrimitive=p,e.plainProps=b,e.provideKey=i,e.treeProps=V,e.usePlain=function(e){const n=[],u=t.inject(i),r=y(e),o=e.query&&(e.fields?.length?e.fields.map((t=>e.query[t])).filter(Boolean):e.query[e.field]),d=t.shallowRef(o||(void 0!==e.defaultValue?c(r.value):void 0)),p=t.ref([]),f=t.computed((()=>p.value.length?p.value:e.options));n.push(t.watch(f,(t=>u&&(u.options[e.field]=t)),{immediate:!0}));const m=()=>{if(e.customGetQuery)return e.customGetQuery(d.value,a,e);const t=c(d.value);return e.multiple&&e.fields?e.fields.reduce(((n,i,u)=>(n[i]=a(t?.[u],e.emptyValue),n)),{}):{[e.field]:a(t,e.emptyValue)}},g={reset(){const{multiple:t}=e;d.value=e.resetToInitialValue&&r.value?.slice()||(t?[]:"")},updateWrapperQuery(){u&&Object.entries(m()).forEach((([t,n])=>u.updateQueryValue(t,n,e.field)))},get validator(){return e.validator},getQuery:m};u?.register(g);const{insetDisabled:b,insetHide:V}=h(e,g);function w(n){e.getOptions?.((e=>{const t=d.value;d.value=void 0,p.value=e||[],d.value=t}),e.query||{},{trigger:n,options:t.toRaw(u?.options)||{},changeDefaultValue(e){return r.value=e,this},change(e,t){return t&&(r.value=e),F(e),this},search(e,t){return t&&(r.value=e),O(e),u?.search(),this}})}function O(e){e!==d.value&&(d.value=e,g.updateWrapperQuery())}function F(e){O(e),u?.insetSearch()}return!o&&e.defaultValue&&g.updateWrapperQuery(),t.onBeforeUnmount((()=>n.forEach((e=>e())))),n.push(t.watch((()=>e.field),((e,t)=>{e!==t&&u?.removeUnreferencedField(t),g.updateWrapperQuery()}))),n.push(t.watch([()=>e.fields||e.field,()=>e.fields?e.fields.map((t=>e.query[t])).filter(Boolean):e.query[e.field]],(([t,n],[i])=>{const u=e.backfillToValue(n,t,e.query);d.value===u||t.toString()!==i.toString()||l(u,d.value)||d.value!==u&&(d.value=u)}))),n.push(t.watch([()=>e.depend,()=>e.dependFields,()=>e.dependFields&&[].concat(e.dependFields).map((t=>v(e.query,t)))],(([t,n],[i,u])=>{(t!==i||t)&&(w("depend"),s(d.value)||F(e.multiple?[]:""))}),e.dependWatchOption)),n.push(t.watch([()=>e.optionsDepend,()=>u&&(e.optionsDependFields||e.dependFields)&&[].concat(e.optionsDependFields||e.dependFields).map((e=>u.options[e]))],(([e],[t])=>{(e!==t||e)&&w("depend")}))),n.push(t.watch((()=>e.getOptions),w.bind(null,"initial"))),t.nextTick(w.bind(null,"initial")),{wrapper:u,option:g,checked:d,getQuery:m,insetDisabled:b,insetHide:V,finalOption:f,updateCheckedValue:O,change:F,reset:g.reset}},e.useTree=function(e){const n=t.inject(i),u=y(e),r=t.ref(),o=t.ref([]),d=t.computed((()=>o.value.length?o.value:e.options)),p=t.computed((()=>e.fields?e.fields.reduce(((t,n)=>(t[n]=e.emptyValue,t)),{}):{[e.field]:e.emptyValue})),v=()=>{if(!D.value&&!u.value)return{};let t=c(r.value);const{...n}=p.value;return e.customGetQuery?e.customGetQuery(t,a,e):t?(e.emitPath||(t=e.multiple?t.map((e=>e?.slice(-1)[0])):t.slice(-1)[0]),Array.isArray(t)?e.fields?t.forEach(((t,i)=>{n[e.fields[i]]=a(t,e.emptyValue)})):n[e.field]=t:n[e.fields?.[0]||e.field]=a(t,e.emptyValue),n):n},{flag:g,updateFlag:b}=m(),{flag:V,updateFlag:w}=m(),O={reset(){return b(),w(),r.value=e.resetToInitialValue&&u.value?.slice()||[],this},get validator(){return e.validator},updateWrapperQuery(){b(),n&&Object.entries(v()).forEach((([t,i])=>n.updateQueryValue(t,i,e.field)))},getQuery:v};n?.register(O);const{insetDisabled:F,insetHide:q}=h(e,O),Q=[];t.onBeforeUnmount((()=>Q.forEach((e=>e()))));const D=t.ref("function"!=typeof e.getOptions||!!e.fields?.length);function k(i){e.getOptions?.((e=>{o.value=e||[],D.value=!0}),e.query||{},{trigger:i,options:t.toRaw(n?.options)||{},changeDefaultValue(e){return u.value=e,this},change(e,t){return t&&(u.value=e),C(e),this},search(e,t){return t&&(u.value=e),A(e),n?.search(),this}})}function A(e){l(r.value,e)||(r.value=e,O.updateWrapperQuery())}function C(e){A(e),n?.insetSearch()}function j(t){if(s(t))return[];const{valueKey:n,childrenKey:i}=e;return f(d.value,(e=>e[n]===t)).map((e=>e[n]),i).filter(Boolean)}return t.watch(D,(t=>t&&function(){const{backfill:t,field:n,fields:i}=e;if(t)if(i){const e=i.reduce(((e,n)=>(t[n]&&e.push(t[n]),e)),[]);if(e.length)return r.value=e,void O.updateWrapperQuery()}else if(t[n])return r.value=j(t[n]),void O.updateWrapperQuery();u.value?.length&&(r.value="string"==typeof u.value?j(u.value):u.value.slice(),"string"==typeof u.value&&(u.value=c(r.value)),O.updateWrapperQuery())}()),{immediate:!0}),Q.push(t.watch((()=>e.fields||[e.field]),((e,t)=>{e.toString()!==t.toString()&&n&&t.forEach((t=>e.includes(t)||n.removeUnreferencedField(t))),O.updateWrapperQuery()}))),Q.push(t.watch([()=>e.fields?.toString()||e.field,()=>e.fields?.map((t=>e.query[t])).filter(Boolean)||e.query[e.field]],(([e,t],[n,i])=>{g.value&&e===n&&l(t,i)}))),Q.push(t.watch((()=>e.fields?.length?e.fields.reduce(((t,n)=>(e.backfill?.[n]&&t.push(e.backfill[n]),t)),[]):e.backfill?.[e.field]),((e,t)=>{D.value&&(l(e,t)||w())}))),Q.push(t.watch([()=>e.depend,()=>e.dependFields,()=>e.dependFields&&[].concat(e.dependFields).map((t=>e.query?.[t]))],(([e,t],[n,i])=>{g.value&&(e!==n||e)&&(k("depend"),s(r.value)||C(void 0))}))),Q.push(t.watch((()=>e.getOptions),k.bind(null,"initial"),{immediate:!0})),{wrapper:n,option:O,checked:r,getQuery:v,finalOption:d,insetDisabled:F,insetHide:q,change:C,reset:O.reset}},e.useWrapper=function(e,u){const r=[];t.onBeforeUnmount((()=>r.splice(0)));const o=t.computed((()=>e.emptyValue?.()));let a=!1,l=[];const s=t.reactive({}),d={realtime:t.toRef(e,"realtime",!1),queryChangedInWrapper:t.ref(!1),register(i){r.push(i);const u=()=>{a=!0,i.reset(),i.updateWrapperQuery();const n=r.indexOf(i);-1!==n&&r.splice(n,1),e.searchAtDatumChanged&&f(),a=!1,l.forEach((e=>{t.del(p.value,e)})),l=[]},o=t.getCurrentInstance();return o&&t.onBeforeUnmount(u,n?o.proxy:o),u},updateQueryValue(n,i,r){e.emptyValues.includes(i)&&i!==o.value&&(i=o.value),a&&l.push(n),t.set(p.value,n,i),u?.fieldChange?.({field:n,value:i,query:p.value,nativeField:r})},insetSearch(){e.realtime&&f()},search:f,removeUnreferencedField(e){let n=0;r.some((t=>(t.getQuery().hasOwnProperty(e)&&(n+=1),n))),n||t.del(p.value,e)},options:s};t.provide(i,d);const p=t.ref({...e.backfill}),c=()=>({...p.value});async function f(){const t=await v();t?e.toast?.(t):u?.search?.(c())}async function v(){return(await Promise.all(r.map((e=>e.validator?.(p.value))))).find((e=>e&&"string"==typeof e))}return t.watch((()=>e.backfill),(e=>{d.queryChangedInWrapper.value=!0,Object.keys(p.value).forEach((t=>{e?.hasOwnProperty(t)||delete p.value[t]})),e&&Object.assign(p.value,e),t.nextTick((()=>{d.queryChangedInWrapper.value=!1}))}),{deep:!0}),{child:r,wrapperInstance:d,query:p,getQuery:c,search:f,reset:function(){r.forEach((e=>{e.reset(),e.updateWrapperQuery()})),u?.reset?.(c())},validate:v}},e.wrapperProps=o}));
var VueDemi=function(e,t,n){if(e.install)return e;if(!t)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),e;if("2.7."===t.version.slice(0,4)){for(var i in t)e[i]=t[i];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=t,e.Vue2=t,e.version=t.version,e.warn=t.util.warn,e.hasInjectionContext=()=>!!e.getCurrentInstance(),e.createApp=function(e,n){var i,u={},r={config:t.config,use:t.use.bind(t),mixin:t.mixin.bind(t),component:t.component.bind(t),provide:function(e,t){return u[e]=t,this},directive:function(e,n){return n?(t.directive(e,n),r):t.directive(e)},mount:function(r,o){return i||((i=new t(Object.assign({propsData:n},e,{provide:Object.assign(u,e.provide)}))).$mount(r,o),i)},unmount:function(){i&&(i.$destroy(),i=void 0)}};return r}}else if("2."===t.version.slice(0,2))if(n){for(var i in n)e[i]=n[i];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=t,e.Vue2=t,e.version=t.version,e.hasInjectionContext=()=>!!e.getCurrentInstance()}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if("3."===t.version.slice(0,2)){for(var i in t)e[i]=t[i];e.isVue2=!1,e.isVue3=!0,e.install=function(){},e.Vue=t,e.Vue2=void 0,e.version=t.version,e.set=function(e,t,n){return Array.isArray(e)?(e.length=Math.max(e.length,t),e.splice(t,1,n),n):(e[t]=n,n)},e.del=function(e,t){Array.isArray(e)?e.splice(t,1):delete e[t]}}else console.error("[vue-demi] Vue version "+t.version+" is unsupported.");return e}(this.VueDemi=this.VueDemi||(void 0!==VueDemi?VueDemi:{}),this.Vue||("undefined"!=typeof Vue?Vue:void 0),this.VueCompositionAPI||("undefined"!=typeof VueCompositionAPI?VueCompositionAPI:void 0));!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue-demi")):"function"==typeof define&&define.amd?define(["exports","vue-demi"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CoreCondition={},e.VueDemi)}(this,(function(e,t){"use strict";const n="2.7"===t.version.slice(0,3),i="condition-wrapper";function u(e){return e}function r(e){return e}const o={realtime:{type:Boolean,default:void 0},searchAtDatumChanged:{type:Boolean,default:void 0},backfill:{type:Object},toast:{type:Function,default:void 0},emptyValues:{type:Array,default:()=>["",null,void 0]},emptyValue:{type:Function,default:void 0}};function a(e,t){return"number"==typeof e?e:e||t}function l(e,t){return s(e)&&s(t)||d(e,t)}function s(e){return void 0===e||""===e||null===e}function d(e,t){if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp&&t instanceof RegExp)return e.toString()===t.toString();if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const n=Reflect.ownKeys(e),i=Reflect.ownKeys(t);if(n.length!==i.length)return!1;for(let i=0;i<n.length;i++){if(!Reflect.has(t,n[i]))return!1;if(!d(e[n[i]],t[n[i]]))return!1}return!0}function p(e){return null==e||"object"!=typeof e&&"function"!=typeof e}function c(e,t){if(p(e))return e;if("function"==typeof e)return e.bind({});const n=new e.constructor;return Object.getOwnPropertyNames(e).forEach((i=>{n[i]=t?c(e[i]):e[i]})),n}function f(e,t,n="children"){for(const i of e){if(t(i))return[i];if(i[n]?.length){const e=f(i[n],t);if(e.length)return e.unshift(i),e}}return[]}function v(e,t,n){const i=t.split(/[\.\[\]]/g);let u=e;for(const e of i){if(null===u)return n;if(void 0===u)return n;const t=e.replace(/['"]/g,"");""!==t.trim()&&(u=u[t])}return void 0===u?n:u}function y(e){const n=t.ref();return t.computed({set(e){n.value=e},get:()=>void 0===n.value?void 0!==e.defaultValue?"function"==typeof e.defaultValue?e.defaultValue(e.query,e.backfill):e.defaultValue:void 0:n.value})}function h(e,n){const i=t.ref("boolean"==typeof e.disabled&&e.disabled),u=t.ref("boolean"==typeof e.hide&&e.hide),r=()=>({query:e.query,backfill:e.backfill,option:n}),o=()=>{if("function"==typeof e.hide){u.value!==e.hide(r())&&(u.value=e.hide(r()))}else if("function"==typeof e.disabled){i.value!==e.disabled(r())&&(i.value=e.disabled(r()))}};let a=[t.watch((()=>e.query),o,{immediate:!0,deep:!0}),t.watch((()=>[e.disabled,e.hide]),((e,t)=>{e[0]!==t[0]&&(i.value="boolean"==typeof e[0]&&e[0],e[0]),e[1]!==t[1]&&(u.value="boolean"==typeof e[1]&&e[1],e[1]),o()}))];return t.onBeforeUnmount((()=>(a.forEach((e=>e())),a=[]))),{insetDisabled:i,insetHide:u}}function m(e=!0){const n=t.ref(e);return{flag:n,updateFlag:()=>{n.value=!e,t.nextTick((()=>{n.value=e}))}}}const g={field:{type:String,required:!0},multiple:{type:Boolean,default:void 0},query:{type:Object,required:!0},backfill:{type:Object},disabled:{type:[Boolean,Function]},hide:{type:[Boolean,Function]},depend:{type:Boolean},dependFields:{type:[String,Array]},dependWatchOption:{type:[Object]},optionsDepend:{type:Boolean},optionsDependFields:{type:[String,Array]},resetToInitialValue:{type:[Boolean]},emptyValue:{type:[String,Number,Boolean,null,void 0],default:void 0},validator:{type:[Function]},customGetQuery:{type:Function},defaultValue:{type:[String,Number,Array,Function]}},b={...g,fields:{type:[Array]},backfillToValue:{type:Function,default:e=>e},options:{type:Array,default:()=>[]},getOptions:{type:Function}};const V={...g,fields:{type:[Array]},valueKey:{type:String,required:!0},childrenKey:{type:String},emitPath:{type:[Boolean],default:!1},options:{type:Array,default:()=>[]},getOptions:{type:Function}};e.IS_COMPOSITION_VERSION=n,e.clone=c,e.commonProps=g,e.defineCommonMethod=r,e.defineProvideValue=u,e.emptyToValue=a,e.get=v,e.getChained=f,e.getNode=function(e,...n){return e?"function"==typeof e?e(...n):"string"==typeof e?e:t.markRaw(e):null},e.isEmptyValue=s,e.isEqual=d,e.isEqualExcludeEmptyValue=l,e.isPrimitive=p,e.plainProps=b,e.provideKey=i,e.treeProps=V,e.usePlain=function(e){const n=[],u=t.inject(i),r=y(e),o=e.query&&(e.fields?.length?e.fields.map((t=>e.query[t])).filter(Boolean):e.query[e.field]),d=t.shallowRef(o||(void 0!==e.defaultValue?c(r.value):void 0)),p=t.ref([]),f=t.computed((()=>p.value.length?p.value:e.options));n.push(t.watch(f,(t=>u&&(u.options[e.field]=t)),{immediate:!0}));const g=()=>{if(e.customGetQuery)return e.customGetQuery(d.value,a,e);const t=c(d.value);return e.multiple&&e.fields?e.fields.reduce(((n,i,u)=>(n[i]=a(t?.[u],e.emptyValue),n)),{}):{[e.field]:a(t,e.emptyValue)}},b={reset(){const{multiple:t}=e;d.value=e.resetToInitialValue&&r.value?.slice()||(t?[]:"")},updateWrapperQuery(){u&&Object.entries(g()).forEach((([t,n])=>u.updateQueryValue(t,n,e.field)))},get validator(){return e.validator},getQuery:g};u?.register(b);const{insetDisabled:V,insetHide:w}=h(e,b);!o&&e.defaultValue&&b.updateWrapperQuery(),t.onBeforeUnmount((()=>n.forEach((e=>e())))),n.push(t.watch((()=>e.field),((e,t)=>{e!==t&&u?.removeUnreferencedField(t),b.updateWrapperQuery()}))),n.push(t.watch([()=>e.fields||e.field,()=>e.fields?e.fields.map((t=>e.query[t])).filter(Boolean):e.query[e.field]],(([t,n],[i])=>{const u=e.backfillToValue(n,t,e.query);d.value===u||t.toString()!==i.toString()||l(u,d.value)||d.value!==u&&(d.value=u)})));const{flag:O,updateFlag:F}=m(!0);function q(n){e.getOptions?.((e=>{const t=d.value;d.value=void 0,p.value=e||[],d.value=t}),e.query||{},{trigger:n,options:t.toRaw(u?.options)||{},changeDefaultValue(e){return r.value=e,this},change(e,t){return t&&(r.value=e),F(),D(e),this},search(e,t){return t&&(r.value=e),F(),Q(e),u?.search(),this}})}function Q(e){e!==d.value&&(d.value=e,b.updateWrapperQuery())}function D(e){Q(e),u?.insetSearch()}return n.push(t.watch([()=>e.depend,()=>e.dependFields,()=>e.dependFields&&[].concat(e.dependFields).map((t=>v(e.query,t)))],(([t,n],[i,u])=>{(t!==i||t)&&(q("depend"),!s(d.value)&&O.value&&D(e.multiple?[]:""))}),e.dependWatchOption)),n.push(t.watch([()=>e.optionsDepend,()=>u&&(e.optionsDependFields||e.dependFields)&&[].concat(e.optionsDependFields||e.dependFields).map((e=>u.options[e]))],(([e],[t])=>{(e!==t||e)&&q("depend")}))),n.push(t.watch((()=>e.getOptions),q.bind(null,"initial"))),t.nextTick(q.bind(null,"initial")),{wrapper:u,option:b,checked:d,getQuery:g,insetDisabled:V,insetHide:w,finalOption:f,updateCheckedValue:Q,change:D,reset:b.reset}},e.useTree=function(e){const n=t.inject(i),u=y(e),r=t.ref(),o=t.ref([]),d=t.computed((()=>o.value.length?o.value:e.options)),p=t.computed((()=>e.fields?e.fields.reduce(((t,n)=>(t[n]=e.emptyValue,t)),{}):{[e.field]:e.emptyValue})),v=()=>{if(!D.value&&!u.value)return{};let t=c(r.value);const{...n}=p.value;return e.customGetQuery?e.customGetQuery(t,a,e):t?(e.emitPath||(t=e.multiple?t.map((e=>e?.slice(-1)[0])):t.slice(-1)[0]),Array.isArray(t)?e.fields?t.forEach(((t,i)=>{n[e.fields[i]]=a(t,e.emptyValue)})):n[e.field]=t:n[e.fields?.[0]||e.field]=a(t,e.emptyValue),n):n},{flag:g,updateFlag:b}=m(),{flag:V,updateFlag:w}=m(),O={reset(){return b(),w(),r.value=e.resetToInitialValue&&u.value?.slice()||[],this},get validator(){return e.validator},updateWrapperQuery(){b(),n&&Object.entries(v()).forEach((([t,i])=>n.updateQueryValue(t,i,e.field)))},getQuery:v};n?.register(O);const{insetDisabled:F,insetHide:q}=h(e,O),Q=[];t.onBeforeUnmount((()=>Q.forEach((e=>e()))));const D=t.ref("function"!=typeof e.getOptions||!!e.fields?.length);function k(i){e.getOptions?.((e=>{o.value=e||[],D.value=!0}),e.query||{},{trigger:i,options:t.toRaw(n?.options)||{},changeDefaultValue(e){return u.value=e,this},change(e,t){return t&&(u.value=e),C(e),this},search(e,t){return t&&(u.value=e),A(e),n?.search(),this}})}function A(e){l(r.value,e)||(r.value=e,O.updateWrapperQuery())}function C(e){A(e),n?.insetSearch()}function j(t){if(s(t))return[];const{valueKey:n,childrenKey:i}=e;return f(d.value,(e=>e[n]===t)).map((e=>e[n]),i).filter(Boolean)}return t.watch(D,(t=>t&&function(){const{backfill:t,field:n,fields:i}=e;if(t)if(i){const e=i.reduce(((e,n)=>(t[n]&&e.push(t[n]),e)),[]);if(e.length)return r.value=e,void O.updateWrapperQuery()}else if(t[n])return r.value=j(t[n]),void O.updateWrapperQuery();u.value?.length&&(r.value="string"==typeof u.value?j(u.value):u.value.slice(),"string"==typeof u.value&&(u.value=c(r.value)),O.updateWrapperQuery())}()),{immediate:!0}),Q.push(t.watch((()=>e.fields||[e.field]),((e,t)=>{e.toString()!==t.toString()&&n&&t.forEach((t=>e.includes(t)||n.removeUnreferencedField(t))),O.updateWrapperQuery()}))),Q.push(t.watch([()=>e.fields?.toString()||e.field,()=>e.fields?.map((t=>e.query[t])).filter(Boolean)||e.query[e.field]],(([e,t],[n,i])=>{g.value&&e===n&&l(t,i)}))),Q.push(t.watch((()=>e.fields?.length?e.fields.reduce(((t,n)=>(e.backfill?.[n]&&t.push(e.backfill[n]),t)),[]):e.backfill?.[e.field]),((e,t)=>{D.value&&(l(e,t)||w())}))),Q.push(t.watch([()=>e.depend,()=>e.dependFields,()=>e.dependFields&&[].concat(e.dependFields).map((t=>e.query?.[t]))],(([e,t],[n,i])=>{g.value&&(e!==n||e)&&(k("depend"),s(r.value)||C(void 0))}))),Q.push(t.watch((()=>e.getOptions),k.bind(null,"initial"),{immediate:!0})),{wrapper:n,option:O,checked:r,getQuery:v,finalOption:d,insetDisabled:F,insetHide:q,change:C,reset:O.reset}},e.useWrapper=function(e,u){const r=[];t.onBeforeUnmount((()=>r.splice(0)));const o=t.computed((()=>e.emptyValue?.()));let a=!1,l=[];const s=t.reactive({}),d={realtime:t.toRef(e,"realtime",!1),queryChangedInWrapper:t.ref(!1),register(i){r.push(i);const u=()=>{a=!0,i.reset(),i.updateWrapperQuery();const n=r.indexOf(i);-1!==n&&r.splice(n,1),e.searchAtDatumChanged&&f(),a=!1,l.forEach((e=>{t.del(p.value,e)})),l=[]},o=t.getCurrentInstance();return o&&t.onBeforeUnmount(u,n?o.proxy:o),u},updateQueryValue(n,i,r){e.emptyValues.includes(i)&&i!==o.value&&(i=o.value),a&&l.push(n),t.set(p.value,n,i),u?.fieldChange?.({field:n,value:i,query:p.value,nativeField:r})},insetSearch(){e.realtime&&f()},search:f,removeUnreferencedField(e){let n=0;r.some((t=>(t.getQuery().hasOwnProperty(e)&&(n+=1),n))),n||t.del(p.value,e)},options:s};t.provide(i,d);const p=t.ref({...e.backfill}),c=()=>({...p.value});async function f(){const t=await v();t?e.toast?.(t):u?.search?.(c())}async function v(){return(await Promise.all(r.map((e=>e.validator?.(p.value))))).find((e=>e&&"string"==typeof e))}return t.watch((()=>e.backfill),(e=>{d.queryChangedInWrapper.value=!0,Object.keys(p.value).forEach((t=>{e?.hasOwnProperty(t)||delete p.value[t]})),e&&Object.assign(p.value,e),t.nextTick((()=>{d.queryChangedInWrapper.value=!1}))}),{deep:!0}),{child:r,wrapperInstance:d,query:p,getQuery:c,search:f,reset:function(){r.forEach((e=>{e.reset(),e.updateWrapperQuery()})),u?.reset?.(c())},validate:v}},e.wrapperProps=o}));
//# sourceMappingURL=index.umd.min.js.map

@@ -0,0 +0,0 @@ export * from './use/index';

@@ -0,0 +0,0 @@ // 不能直接用 vue-demi 的 ExtractPropTypes, 编译后项目会找不到该类型

{
"name": "@xiaohaih/condition-core",
"version": "0.5.3",
"version": "0.5.6",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.cjs.js",

@@ -0,0 +0,0 @@ import { ref, watch, onBeforeUnmount, ExtractPropTypes, nextTick, computed } from 'vue-demi';

@@ -0,0 +0,0 @@ import { version, type Ref } from 'vue-demi';

@@ -0,0 +0,0 @@ export * from './wrapper/index';

@@ -115,2 +115,4 @@ import {

/** 是否允许依赖变动时, 重置值(外部通过 search, change 主动改变值时, 内部应取消重置) */
const { flag: allowDependChangeValue, updateFlag: updateAllowDependChangeValue } = useDisableInCurrentCycle(true);
// 存在依赖项

@@ -130,3 +132,4 @@ unwatchs.push(

// 防止表单类监测值发生改变时触发校验
if (isEmptyValue(checked.value)) return;
// 或内部不允许重置时直接返回
if (isEmptyValue(checked.value) || !allowDependChangeValue.value) return;
change(props.multiple ? [] : '');

@@ -138,3 +141,3 @@ },

// 存在依赖项
// 存在选项变动依赖项时
unwatchs.push(

@@ -184,2 +187,3 @@ watch(

isInitial && (initialValue.value = value);
updateAllowDependChangeValue();
change(value);

@@ -190,2 +194,3 @@ return this;

isInitial && (initialValue.value = value);
updateAllowDependChangeValue();
updateCheckedValue(value);

@@ -192,0 +197,0 @@ wrapper?.search();

@@ -0,0 +0,0 @@ import { PropType } from 'vue-demi';

@@ -0,0 +0,0 @@ ### `plain` 组件(普通数据结构组件)

@@ -0,0 +0,0 @@ import { type PropType, type WatchOptions } from 'vue-demi';

@@ -0,0 +0,0 @@ import { computed, ExtractPropTypes, inject, onBeforeUnmount, PropType, ref, watch, nextTick, toRaw } from 'vue-demi';

@@ -0,0 +0,0 @@ import { PropType } from 'vue-demi';

@@ -0,0 +0,0 @@ ### `tree` 组件(数据结构为树形时使用)

@@ -0,0 +0,0 @@ import {

@@ -0,0 +0,0 @@ import { PropType } from 'vue-demi';

@@ -0,0 +0,0 @@ ### `wrapper` 组件(容器组件)

@@ -0,0 +0,0 @@ import { markRaw, VNode } from 'vue-demi';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc