Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xiaohaih/condition-core

Package Overview
Dependencies
Maintainers
1
Versions
43
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.3.1 to 0.3.2

6

CHANGELOG.md
# @xiaohaih/condition-core
## 0.3.2
### Patch Changes
- 增加新的条件项(element-plus 表单支持的组件)(element-ui 的新组件还存在一些 bug)
## 0.3.1

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

22

dist/index.cjs.js

@@ -154,2 +154,9 @@ 'use strict';

/**
* 对值进行浅拷贝
* @param {*} val
*/
function shallowDeep(val) {
return Array.isArray(val) ? [...val] : val;
}
/**
* 获取指定层级的父级(包括自身)

@@ -178,2 +185,3 @@ * @param {Record<string, any>[]} data 数据源

function getNode(node, ...args) {
if (!node) return;
return typeof node === 'function' ? node(...args) : typeof node === 'string' ? node : vueDemi.markRaw(node);

@@ -276,5 +284,5 @@ }

/** 当前选中值 */
const checked = vueDemi.ref(initialBackfillValue || (props.defaultValue !== undefined ? initialValue.value : props.multiple ? [] : ''
const checked = vueDemi.ref(initialBackfillValue ||
// 防止数组引用导致默认值发生改变
).slice());
shallowDeep(props.defaultValue !== undefined ? initialValue.value : props.multiple ? [] : ''));
/** 远程获取的数据源 */

@@ -287,3 +295,3 @@ const remoteOption = vueDemi.ref([]);

return props.multiple && props.fields ? props.fields.reduce((p, k, i) => (p[k] = emptyToValue(checked.value?.[i], props.emptyValue), p), {}) : {
[props.field]: emptyToValue(checked.value, props.emptyValue)
[props.field]: emptyToValue(shallowDeep(vueDemi.toRaw(checked.value)), props.emptyValue)
};

@@ -343,3 +351,3 @@ };

if (!realtimeFlag.value) return;
checked.value = _val;
updateCheckedValue(_val);
}));

@@ -457,3 +465,4 @@ // 回填值发生变化时触发更新

emptyValue: {
type: [String, Number, null, undefined]
type: [String, Number, Boolean, null, undefined],
default: undefined
},

@@ -470,3 +479,3 @@ /** 校验函数, 返回字符串不通过, 会触发提示 - 提交时触发 */

defaultValue: {
type: [String, Array, Function]
type: [String, Number, Array, Function]
}

@@ -746,2 +755,3 @@ };

exports.provideKey = provideKey;
exports.shallowDeep = shallowDeep;
exports.treeProps = treeProps;

@@ -748,0 +758,0 @@ exports.usePlain = usePlain;

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

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

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

import { version, onBeforeUnmount, ref, getCurrentInstance, set, del, provide, markRaw, computed, watch, nextTick, inject } from 'vue-demi';
import { version, onBeforeUnmount, ref, getCurrentInstance, set, del, provide, markRaw, computed, watch, nextTick, inject, toRaw } from 'vue-demi';

@@ -152,2 +152,9 @@ /** 判断是否是 2.7.* 版本, 监听生命周期需对该版本做处理 */

/**
* 对值进行浅拷贝
* @param {*} val
*/
function shallowDeep(val) {
return Array.isArray(val) ? [...val] : val;
}
/**
* 获取指定层级的父级(包括自身)

@@ -176,2 +183,3 @@ * @param {Record<string, any>[]} data 数据源

function getNode(node, ...args) {
if (!node) return;
return typeof node === 'function' ? node(...args) : typeof node === 'string' ? node : markRaw(node);

@@ -274,5 +282,5 @@ }

/** 当前选中值 */
const checked = ref(initialBackfillValue || (props.defaultValue !== undefined ? initialValue.value : props.multiple ? [] : ''
const checked = ref(initialBackfillValue ||
// 防止数组引用导致默认值发生改变
).slice());
shallowDeep(props.defaultValue !== undefined ? initialValue.value : props.multiple ? [] : ''));
/** 远程获取的数据源 */

@@ -285,3 +293,3 @@ const remoteOption = ref([]);

return props.multiple && props.fields ? props.fields.reduce((p, k, i) => (p[k] = emptyToValue(checked.value?.[i], props.emptyValue), p), {}) : {
[props.field]: emptyToValue(checked.value, props.emptyValue)
[props.field]: emptyToValue(shallowDeep(toRaw(checked.value)), props.emptyValue)
};

@@ -341,3 +349,3 @@ };

if (!realtimeFlag.value) return;
checked.value = _val;
updateCheckedValue(_val);
}));

@@ -455,3 +463,4 @@ // 回填值发生变化时触发更新

emptyValue: {
type: [String, Number, null, undefined]
type: [String, Number, Boolean, null, undefined],
default: undefined
},

@@ -468,3 +477,3 @@ /** 校验函数, 返回字符串不通过, 会触发提示 - 提交时触发 */

defaultValue: {
type: [String, Array, Function]
type: [String, Number, Array, Function]
}

@@ -735,3 +744,3 @@ };

export { IS_COMPOSITION_VERSION, commonProps, defineCommonMethod, defineProvideValue, emptyToValue, getChained, getNode, plainProps, provideKey, treeProps, usePlain, useTree, useWrapper, wrapperProps };
export { IS_COMPOSITION_VERSION, commonProps, defineCommonMethod, defineProvideValue, emptyToValue, getChained, getNode, plainProps, provideKey, shallowDeep, treeProps, usePlain, useTree, useWrapper, wrapperProps };
//# sourceMappingURL=index.esm.js.map

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

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

@@ -272,2 +272,9 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {

/**
* 对值进行浅拷贝
* @param {*} val
*/
function shallowDeep(val) {
return Array.isArray(val) ? [...val] : val;
}
/**
* 获取指定层级的父级(包括自身)

@@ -296,2 +303,3 @@ * @param {Record<string, any>[]} data 数据源

function getNode(node, ...args) {
if (!node) return;
return typeof node === 'function' ? node(...args) : typeof node === 'string' ? node : vueDemi.markRaw(node);

@@ -394,5 +402,5 @@ }

/** 当前选中值 */
const checked = vueDemi.ref(initialBackfillValue || (props.defaultValue !== undefined ? initialValue.value : props.multiple ? [] : ''
const checked = vueDemi.ref(initialBackfillValue ||
// 防止数组引用导致默认值发生改变
).slice());
shallowDeep(props.defaultValue !== undefined ? initialValue.value : props.multiple ? [] : ''));
/** 远程获取的数据源 */

@@ -405,3 +413,3 @@ const remoteOption = vueDemi.ref([]);

return props.multiple && props.fields ? props.fields.reduce((p, k, i) => (p[k] = emptyToValue(checked.value?.[i], props.emptyValue), p), {}) : {
[props.field]: emptyToValue(checked.value, props.emptyValue)
[props.field]: emptyToValue(shallowDeep(vueDemi.toRaw(checked.value)), props.emptyValue)
};

@@ -461,3 +469,3 @@ };

if (!realtimeFlag.value) return;
checked.value = _val;
updateCheckedValue(_val);
}));

@@ -575,3 +583,4 @@ // 回填值发生变化时触发更新

emptyValue: {
type: [String, Number, null, undefined]
type: [String, Number, Boolean, null, undefined],
default: undefined
},

@@ -588,3 +597,3 @@ /** 校验函数, 返回字符串不通过, 会触发提示 - 提交时触发 */

defaultValue: {
type: [String, Array, Function]
type: [String, Number, Array, Function]
}

@@ -864,2 +873,3 @@ };

exports.provideKey = provideKey;
exports.shallowDeep = shallowDeep;
exports.treeProps = treeProps;

@@ -866,0 +876,0 @@ exports.usePlain = usePlain;

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

var VueDemi=function(e,t,i){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 n in t)e[n]=t[n];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,i){var n,r={},u={config:t.config,use:t.use.bind(t),mixin:t.mixin.bind(t),component:t.component.bind(t),provide:function(e,t){return r[e]=t,this},directive:function(e,i){return i?(t.directive(e,i),u):t.directive(e)},mount:function(u,a){return n||((n=new t(Object.assign({propsData:i},e,{provide:Object.assign(r,e.provide)}))).$mount(u,a),n)},unmount:function(){n&&(n.$destroy(),n=void 0)}};return u}}else if("2."===t.version.slice(0,2))if(i){for(var n in i)e[n]=i[n];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 n in t)e[n]=t[n];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,i){return Array.isArray(e)?(e.length=Math.max(e.length,t),e.splice(t,1,i),i):(e[t]=i,i)},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 i="2.7"===t.version.slice(0,3),n="condition-wrapper";function r(e){return e}function u(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}};function l(e,t){return Array.isArray(e)?e.filter(Boolean).length?e:t:"number"==typeof e?e:e||t}function o(e,t,i="children"){for(const n of e){if(t(n))return[n];if(n[i]?.length){const e=o(n[i],t);if(e.length)return e.unshift(n),e}}return[]}function s(e){const i=t.ref();return t.computed({set(e){i.value=e},get:()=>void 0===i.value?void 0!==e.defaultValue?"function"==typeof e.defaultValue?e.defaultValue(e.query,e.backfill):e.defaultValue:void 0:i.value})}function d(e,i){const n=t.ref("boolean"==typeof e.disabled&&e.disabled),r=t.ref("boolean"==typeof e.hide&&e.hide),u=()=>({query:e.query,backfill:e.backfill,option:i}),a=()=>{if("function"==typeof e.hide){r.value!==e.hide(u())&&(r.value=e.hide(u()))}else if("function"==typeof e.disabled){n.value!==e.disabled(u())&&(n.value=e.disabled(u()))}};let l=[t.watch((()=>e.query),a,{immediate:!0,deep:!0}),t.watch((()=>[e.disabled,e.hide]),((e,t)=>{e[0]!==t[0]&&(n.value="boolean"==typeof e[0]&&e[0],e[0]),e[1]!==t[1]&&(r.value="boolean"==typeof e[1]&&e[1],e[1]),a()}))];return t.onBeforeUnmount((()=>(l.forEach((e=>e())),l=[]))),{insetDisabled:n,insetHide:r}}function c(e=!0){const i=t.ref(e);return{flag:i,updateFlag:()=>{i.value=!e,t.nextTick((()=>{i.value=e}))}}}function f(e){return e?.toString()??""}const p={field:{type:String,required:!0},query:{type:Object,required:!0},backfill:{type:Object},disabled:{type:[Boolean,Function]},hide:{type:[Boolean,Function]},depend:{type:Boolean},dependFields:{type:[String,Array]},resetToInitialValue:{type:[Boolean]},emptyValue:{type:[String,Number,null,void 0]},validator:{type:[Function]},customGetQuery:{type:Function},defaultValue:{type:[String,Array,Function]}},v={...p,fields:{type:[Array]},backfillToValue:{type:Function,default:e=>e},multiple:{type:Boolean,default:void 0},options:{type:Array,default:()=>[]},getOptions:{type:Function}};function y(e){return e?.toString()??""}const h={...p,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=i,e.commonProps=p,e.defineCommonMethod=u,e.defineProvideValue=r,e.emptyToValue=l,e.getChained=o,e.getNode=function(e,...i){return"function"==typeof e?e(...i):"string"==typeof e?e:t.markRaw(e)},e.plainProps=v,e.provideKey=n,e.treeProps=h,e.usePlain=function(e){const i=t.inject(n),r=s(e),u=e.backfill&&(e.fields?.length?e.fields.map((t=>e.backfill[t])).filter(Boolean):e.backfill[e.field]),a=t.ref(u||(void 0!==e.defaultValue?r.value:e.multiple?[]:"").slice()),o=t.ref([]),p=t.computed((()=>o.value.length?o.value:e.options)),v=()=>e.customGetQuery?e.customGetQuery(a.value,l,e):e.multiple&&e.fields?e.fields.reduce(((t,i,n)=>(t[i]=l(a.value?.[n],e.emptyValue),t)),{}):{[e.field]:l(a.value,e.emptyValue)},{flag:y,updateFlag:h}=c(),{flag:g,updateFlag:m}=c(),b={reset(){const{multiple:t}=e;h(),m(),a.value=e.resetToInitialValue&&r.value?.slice()||(t?[]:"")},updateWrapperQuery(){h(),i&&Object.entries(v()).forEach((([e,t])=>i.updateQueryValue(e,t)))},get validator(){return e.validator},getQuery:v};i?.register(b);const{insetDisabled:V,insetHide:Q}=d(e,b);!u&&e.defaultValue&&b.updateWrapperQuery();const S=[];function k(t){e.getOptions?.((e=>{const t=a.value;a.value=void 0,o.value=e||[],a.value=t}),e.query||{},{trigger:t,change:(e,t)=>{t&&(r.value=e),F(e)},search:(e,t)=>{t&&(r.value=e),w(e),i?.search()}})}function w(e){e!==a.value&&(a.value=e,b.updateWrapperQuery())}function F(e){w(e),i?.insetSearch()}return t.onBeforeUnmount((()=>S.forEach((e=>e())))),S.push(t.watch((()=>e.field),((e,t)=>{e!==t&&i?.removeUnreferencedField(t),b.updateWrapperQuery()}))),S.push(t.watch((()=>[e.fields||e.field,e.fields?e.fields.map((t=>e.query[t])).filter(Boolean):e.query[e.field]]),(([t,i],[n])=>{const r=e.backfillToValue(i,t,e.query);t.toString()===n.toString()&&f(r)!==f(a.value)&&y.value&&(a.value=r)}))),S.push(t.watch((()=>[e.fields||e.field,e.fields?e.fields.map((t=>e.backfill?.[t])).filter(Boolean):e.backfill?.[e.field]]),(([t,i],[n])=>{const r=e.backfillToValue(i,t,e.backfill);t.toString()===n.toString()&&f(r)!==f(a.value)&&(m(),w(r))}))),S.push(t.watch((()=>[e.depend,e.dependFields,e.dependFields&&[].concat(e.dependFields).map((t=>e.query?.[t])).join(",")||""]),(([t,i,n],[r,u,l])=>{g.value&&n!==l&&(k("depend"),t===r&&i?.toString()===u?.toString()&&void 0!==a.value&&""!==a.value.toString()&&w(e.multiple?[]:""))}))),S.push(t.watch((()=>e.getOptions),k.bind(null,"initial"),{immediate:!0})),{wrapper:i,option:b,checked:a,getQuery:v,insetDisabled:V,insetHide:Q,finalOption:p,updateCheckedValue:w,change:F,reset:b.reset}},e.useTree=function(e){const i=t.inject(n),r=s(e),u=t.ref([]),a=t.ref([]),f=t.computed((()=>a.value.length?a.value:e.options)),p=()=>k.value||r.value?e.customGetQuery?e.customGetQuery(u.value,l,e):e.fields?.length?e.fields.reduce(((t,i,n)=>Object.assign(t,{[i]:l(u.value[n],e.emptyValue)})),{}):{[e.field]:l(e.emitPath?[...u.value]:u.value.slice(-1)[0],e.emptyValue)}:{},{flag:v,updateFlag:h}=c(),{flag:g,updateFlag:m}=c(),b={reset(){return h(),m(),u.value=e.resetToInitialValue&&r.value?.slice()||[],this},get validator(){return e.validator},updateWrapperQuery(){h(),i&&Object.entries(p()).forEach((([e,t])=>i.updateQueryValue(e,t)))},getQuery:p};i?.register(b);const{insetDisabled:V,insetHide:Q}=d(e,b),S=[];t.onBeforeUnmount((()=>S.forEach((e=>e()))));const k=t.ref("function"!=typeof e.getOptions||!!e.fields?.length);function w(t){e.getOptions?.((e=>{a.value=e||[],k.value=!0}),e.query||{},{trigger:t,change:(e,t)=>{t&&(r.value=e),A(e)},search:(e,t)=>{t&&(r.value=e),F(e),i?.search()}})}function F(e){const t=Array.isArray(e)?e:O(e);t.join("")!==u.value.join("")&&(u.value=t,b.updateWrapperQuery())}function A(e){F(e||[]),i?.insetSearch()}function O(t){if(!t&&0!==t)return[];const{valueKey:i,childrenKey:n}=e;return o(f.value,(e=>e[i]===t)).map((e=>e[i]),n).filter(Boolean)}return t.watch(k,(t=>t&&function(){const{backfill:t,field:i,fields:n}=e;if(t)if(n){const e=n.reduce(((e,i)=>(t[i]&&e.push(t[i]),e)),[]);if(e.length)return u.value=e,void b.updateWrapperQuery()}else if(t[i])return u.value=O(t[i]),void b.updateWrapperQuery();r.value?.length&&(u.value="string"==typeof r.value?O(r.value):r.value.slice(),"string"==typeof r.value&&(r.value=u.value.slice()),b.updateWrapperQuery())}()),{immediate:!0}),S.push(t.watch((()=>e.fields||[e.field]),((e,t)=>{e.toString()!==t.toString()&&i&&t.forEach((t=>e.includes(t)||i.removeUnreferencedField(t))),b.updateWrapperQuery()}))),S.push(t.watch((()=>[e.fields?.toString()||e.field,e.fields?.map((t=>e.query[t])).filter(Boolean)||e.query[e.field]]),(([e,t],[i,n])=>{e===i&&y(t)!==y(n)&&v.value&&(u.value="string"==typeof t?O(t):t)}))),S.push(t.watch((()=>e.fields?.length?e.fields.reduce(((t,i)=>(e.backfill?.[i]&&t.push(e.backfill[i]),t)),[]):e.backfill?.[e.field]),((e,t)=>{if(k.value&&y(e)!==y(t))if(m(),Array.isArray(e))F(e);else{if(!e&&0!==e)return void(u.value.length&&(u.value=[]));F(O(e))}}))),S.push(t.watch((()=>[e.depend,e.dependFields,e.dependFields&&[].concat(e.dependFields).map((t=>e.query?.[t])).join(",")||""]),(([e,t,i],[n,r,a])=>{g.value&&i!==a&&(w("depend"),e===n&&t?.toString()===r?.toString()&&u.value.length&&F("string"==typeof u.value?"":[]))}))),S.push(t.watch((()=>e.getOptions),w.bind(null,"initial"),{immediate:!0})),{wrapper:i,option:b,checked:u,getQuery:p,finalOption:f,insetDisabled:V,insetHide:Q,change:A,reset:b.reset}},e.useWrapper=function(e,r){const u=[];t.onBeforeUnmount((()=>u.splice(0)));const a={};let l=!1,o=[];const s={realtime:t.ref(e.realtime),register(n){u.push(n);const r=()=>{l=!0,n.reset(),n.updateWrapperQuery();const i=u.indexOf(n);-1!==i&&u.splice(i,1),e.searchAtDatumChanged&&f(),l=!1,o.forEach((e=>{t.del(d.value,e),delete a[e]})),o=[]},s=t.getCurrentInstance();return s&&t.onBeforeUnmount(r,i?s.proxy:s),r},updateQueryValue(e,i){l&&o.push(e),t.set(d.value,e,i),a[e]=i},insetSearch(){e.realtime&&f()},search:f,removeUnreferencedField(e){let i=0;u.some((t=>(t.getQuery().hasOwnProperty(e)&&(i+=1),i))),i||(t.del(d.value,e),delete a[e])}};t.provide(n,s);const d=t.ref({...e.backfill}),c=()=>({...d.value,...e.backfill,...a});async function f(){const t=await p();t?e.toast?.(t):r?.search?.(c())}async function p(){return(await Promise.all(u.map((e=>e.validator?.(d.value))))).find((e=>e&&"string"==typeof e))}return{child:u,wrapperInstance:s,query:d,getQuery:c,search:f,reset:function(){u.forEach((e=>{e.reset(),e.updateWrapperQuery()})),r?.reset?.(c())},validate:p}},e.wrapperProps=a}));
var VueDemi=function(e,t,i){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 n in t)e[n]=t[n];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,i){var n,r={},u={config:t.config,use:t.use.bind(t),mixin:t.mixin.bind(t),component:t.component.bind(t),provide:function(e,t){return r[e]=t,this},directive:function(e,i){return i?(t.directive(e,i),u):t.directive(e)},mount:function(u,a){return n||((n=new t(Object.assign({propsData:i},e,{provide:Object.assign(r,e.provide)}))).$mount(u,a),n)},unmount:function(){n&&(n.$destroy(),n=void 0)}};return u}}else if("2."===t.version.slice(0,2))if(i){for(var n in i)e[n]=i[n];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 n in t)e[n]=t[n];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,i){return Array.isArray(e)?(e.length=Math.max(e.length,t),e.splice(t,1,i),i):(e[t]=i,i)},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 i="2.7"===t.version.slice(0,3),n="condition-wrapper";function r(e){return e}function u(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}};function l(e,t){return Array.isArray(e)?e.filter(Boolean).length?e:t:"number"==typeof e?e:e||t}function o(e){return Array.isArray(e)?[...e]:e}function s(e,t,i="children"){for(const n of e){if(t(n))return[n];if(n[i]?.length){const e=s(n[i],t);if(e.length)return e.unshift(n),e}}return[]}function d(e){const i=t.ref();return t.computed({set(e){i.value=e},get:()=>void 0===i.value?void 0!==e.defaultValue?"function"==typeof e.defaultValue?e.defaultValue(e.query,e.backfill):e.defaultValue:void 0:i.value})}function f(e,i){const n=t.ref("boolean"==typeof e.disabled&&e.disabled),r=t.ref("boolean"==typeof e.hide&&e.hide),u=()=>({query:e.query,backfill:e.backfill,option:i}),a=()=>{if("function"==typeof e.hide){r.value!==e.hide(u())&&(r.value=e.hide(u()))}else if("function"==typeof e.disabled){n.value!==e.disabled(u())&&(n.value=e.disabled(u()))}};let l=[t.watch((()=>e.query),a,{immediate:!0,deep:!0}),t.watch((()=>[e.disabled,e.hide]),((e,t)=>{e[0]!==t[0]&&(n.value="boolean"==typeof e[0]&&e[0],e[0]),e[1]!==t[1]&&(r.value="boolean"==typeof e[1]&&e[1],e[1]),a()}))];return t.onBeforeUnmount((()=>(l.forEach((e=>e())),l=[]))),{insetDisabled:n,insetHide:r}}function c(e=!0){const i=t.ref(e);return{flag:i,updateFlag:()=>{i.value=!e,t.nextTick((()=>{i.value=e}))}}}function p(e){return e?.toString()??""}const v={field:{type:String,required:!0},query:{type:Object,required:!0},backfill:{type:Object},disabled:{type:[Boolean,Function]},hide:{type:[Boolean,Function]},depend:{type:Boolean},dependFields:{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]}},y={...v,fields:{type:[Array]},backfillToValue:{type:Function,default:e=>e},multiple:{type:Boolean,default:void 0},options:{type:Array,default:()=>[]},getOptions:{type:Function}};function h(e){return e?.toString()??""}const g={...v,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=i,e.commonProps=v,e.defineCommonMethod=u,e.defineProvideValue=r,e.emptyToValue=l,e.getChained=s,e.getNode=function(e,...i){if(e)return"function"==typeof e?e(...i):"string"==typeof e?e:t.markRaw(e)},e.plainProps=y,e.provideKey=n,e.shallowDeep=o,e.treeProps=g,e.usePlain=function(e){const i=t.inject(n),r=d(e),u=e.backfill&&(e.fields?.length?e.fields.map((t=>e.backfill[t])).filter(Boolean):e.backfill[e.field]),a=t.ref(u||o(void 0!==e.defaultValue?r.value:e.multiple?[]:"")),s=t.ref([]),v=t.computed((()=>s.value.length?s.value:e.options)),y=()=>e.customGetQuery?e.customGetQuery(a.value,l,e):e.multiple&&e.fields?e.fields.reduce(((t,i,n)=>(t[i]=l(a.value?.[n],e.emptyValue),t)),{}):{[e.field]:l(o(t.toRaw(a.value)),e.emptyValue)},{flag:h,updateFlag:g}=c(),{flag:m,updateFlag:b}=c(),V={reset(){const{multiple:t}=e;g(),b(),a.value=e.resetToInitialValue&&r.value?.slice()||(t?[]:"")},updateWrapperQuery(){g(),i&&Object.entries(y()).forEach((([e,t])=>i.updateQueryValue(e,t)))},get validator(){return e.validator},getQuery:y};i?.register(V);const{insetDisabled:w,insetHide:Q}=f(e,V);!u&&e.defaultValue&&V.updateWrapperQuery();const S=[];function k(t){e.getOptions?.((e=>{const t=a.value;a.value=void 0,s.value=e||[],a.value=t}),e.query||{},{trigger:t,change:(e,t)=>{t&&(r.value=e),F(e)},search:(e,t)=>{t&&(r.value=e),A(e),i?.search()}})}function A(e){e!==a.value&&(a.value=e,V.updateWrapperQuery())}function F(e){A(e),i?.insetSearch()}return t.onBeforeUnmount((()=>S.forEach((e=>e())))),S.push(t.watch((()=>e.field),((e,t)=>{e!==t&&i?.removeUnreferencedField(t),V.updateWrapperQuery()}))),S.push(t.watch((()=>[e.fields||e.field,e.fields?e.fields.map((t=>e.query[t])).filter(Boolean):e.query[e.field]]),(([t,i],[n])=>{const r=e.backfillToValue(i,t,e.query);t.toString()===n.toString()&&p(r)!==p(a.value)&&h.value&&A(r)}))),S.push(t.watch((()=>[e.fields||e.field,e.fields?e.fields.map((t=>e.backfill?.[t])).filter(Boolean):e.backfill?.[e.field]]),(([t,i],[n])=>{const r=e.backfillToValue(i,t,e.backfill);t.toString()===n.toString()&&p(r)!==p(a.value)&&(b(),A(r))}))),S.push(t.watch((()=>[e.depend,e.dependFields,e.dependFields&&[].concat(e.dependFields).map((t=>e.query?.[t])).join(",")||""]),(([t,i,n],[r,u,l])=>{m.value&&n!==l&&(k("depend"),t===r&&i?.toString()===u?.toString()&&void 0!==a.value&&""!==a.value.toString()&&A(e.multiple?[]:""))}))),S.push(t.watch((()=>e.getOptions),k.bind(null,"initial"),{immediate:!0})),{wrapper:i,option:V,checked:a,getQuery:y,insetDisabled:w,insetHide:Q,finalOption:v,updateCheckedValue:A,change:F,reset:V.reset}},e.useTree=function(e){const i=t.inject(n),r=d(e),u=t.ref([]),a=t.ref([]),o=t.computed((()=>a.value.length?a.value:e.options)),p=()=>S.value||r.value?e.customGetQuery?e.customGetQuery(u.value,l,e):e.fields?.length?e.fields.reduce(((t,i,n)=>Object.assign(t,{[i]:l(u.value[n],e.emptyValue)})),{}):{[e.field]:l(e.emitPath?[...u.value]:u.value.slice(-1)[0],e.emptyValue)}:{},{flag:v,updateFlag:y}=c(),{flag:g,updateFlag:m}=c(),b={reset(){return y(),m(),u.value=e.resetToInitialValue&&r.value?.slice()||[],this},get validator(){return e.validator},updateWrapperQuery(){y(),i&&Object.entries(p()).forEach((([e,t])=>i.updateQueryValue(e,t)))},getQuery:p};i?.register(b);const{insetDisabled:V,insetHide:w}=f(e,b),Q=[];t.onBeforeUnmount((()=>Q.forEach((e=>e()))));const S=t.ref("function"!=typeof e.getOptions||!!e.fields?.length);function k(t){e.getOptions?.((e=>{a.value=e||[],S.value=!0}),e.query||{},{trigger:t,change:(e,t)=>{t&&(r.value=e),F(e)},search:(e,t)=>{t&&(r.value=e),A(e),i?.search()}})}function A(e){const t=Array.isArray(e)?e:O(e);t.join("")!==u.value.join("")&&(u.value=t,b.updateWrapperQuery())}function F(e){A(e||[]),i?.insetSearch()}function O(t){if(!t&&0!==t)return[];const{valueKey:i,childrenKey:n}=e;return s(o.value,(e=>e[i]===t)).map((e=>e[i]),n).filter(Boolean)}return t.watch(S,(t=>t&&function(){const{backfill:t,field:i,fields:n}=e;if(t)if(n){const e=n.reduce(((e,i)=>(t[i]&&e.push(t[i]),e)),[]);if(e.length)return u.value=e,void b.updateWrapperQuery()}else if(t[i])return u.value=O(t[i]),void b.updateWrapperQuery();r.value?.length&&(u.value="string"==typeof r.value?O(r.value):r.value.slice(),"string"==typeof r.value&&(r.value=u.value.slice()),b.updateWrapperQuery())}()),{immediate:!0}),Q.push(t.watch((()=>e.fields||[e.field]),((e,t)=>{e.toString()!==t.toString()&&i&&t.forEach((t=>e.includes(t)||i.removeUnreferencedField(t))),b.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],[i,n])=>{e===i&&h(t)!==h(n)&&v.value&&(u.value="string"==typeof t?O(t):t)}))),Q.push(t.watch((()=>e.fields?.length?e.fields.reduce(((t,i)=>(e.backfill?.[i]&&t.push(e.backfill[i]),t)),[]):e.backfill?.[e.field]),((e,t)=>{if(S.value&&h(e)!==h(t))if(m(),Array.isArray(e))A(e);else{if(!e&&0!==e)return void(u.value.length&&(u.value=[]));A(O(e))}}))),Q.push(t.watch((()=>[e.depend,e.dependFields,e.dependFields&&[].concat(e.dependFields).map((t=>e.query?.[t])).join(",")||""]),(([e,t,i],[n,r,a])=>{g.value&&i!==a&&(k("depend"),e===n&&t?.toString()===r?.toString()&&u.value.length&&A("string"==typeof u.value?"":[]))}))),Q.push(t.watch((()=>e.getOptions),k.bind(null,"initial"),{immediate:!0})),{wrapper:i,option:b,checked:u,getQuery:p,finalOption:o,insetDisabled:V,insetHide:w,change:F,reset:b.reset}},e.useWrapper=function(e,r){const u=[];t.onBeforeUnmount((()=>u.splice(0)));const a={};let l=!1,o=[];const s={realtime:t.ref(e.realtime),register(n){u.push(n);const r=()=>{l=!0,n.reset(),n.updateWrapperQuery();const i=u.indexOf(n);-1!==i&&u.splice(i,1),e.searchAtDatumChanged&&c(),l=!1,o.forEach((e=>{t.del(d.value,e),delete a[e]})),o=[]},s=t.getCurrentInstance();return s&&t.onBeforeUnmount(r,i?s.proxy:s),r},updateQueryValue(e,i){l&&o.push(e),t.set(d.value,e,i),a[e]=i},insetSearch(){e.realtime&&c()},search:c,removeUnreferencedField(e){let i=0;u.some((t=>(t.getQuery().hasOwnProperty(e)&&(i+=1),i))),i||(t.del(d.value,e),delete a[e])}};t.provide(n,s);const d=t.ref({...e.backfill}),f=()=>({...d.value,...e.backfill,...a});async function c(){const t=await p();t?e.toast?.(t):r?.search?.(f())}async function p(){return(await Promise.all(u.map((e=>e.validator?.(d.value))))).find((e=>e&&"string"==typeof e))}return{child:u,wrapperInstance:s,query:d,getQuery:f,search:c,reset:function(){u.forEach((e=>{e.reset(),e.updateWrapperQuery()})),r?.reset?.(f())},validate:p}},e.wrapperProps=a}));
//# sourceMappingURL=index.umd.min.js.map

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

import * as vue_demi from 'vue-demi';
import * as _vue_composition_api from '@vue/composition-api';
import { Ref, PropType, ExtractPropTypes, VNode, UnwrapRef } from 'vue-demi';

@@ -88,3 +88,3 @@

wrapperInstance: {
realtime: vue_demi.Ref<boolean | undefined>;
realtime: _vue_composition_api.Ref<boolean>;
register(compOption: CommonMethod): () => void;

@@ -96,3 +96,5 @@ updateQueryValue(field: string, value: any): void;

};
query: vue_demi.Ref<Record<string, string>>;
query: _vue_composition_api.Ref<{
[x: string]: string;
}>;
getQuery: () => {

@@ -113,2 +115,7 @@ [x: string]: any;

/**
* 对值进行浅拷贝
* @param {*} val
*/
declare function shallowDeep<T extends unknown>(val: T): T;
/**
* 获取指定层级的父级(包括自身)

@@ -123,5 +130,3 @@ * @param {Record<string, any>[]} data 数据源

*/
declare function getNode(node: string | ((...args: any[]) => VNode) | VNode, ...args: any[]): string | VNode<vue_demi.RendererNode, vue_demi.RendererElement, {
[key: string]: any;
}>;
declare function getNode(node: string | ((...args: any[]) => VNode) | VNode | undefined | null, ...args: any[]): string | VNode | undefined;

@@ -148,3 +153,3 @@ /** 隐藏元素 */

/** 条件值可能的类型 */
type ValueType$1 = string | string[];
type ValueType$1 = number | string | string[];
/** 改变当前条件值触发方式 */

@@ -210,3 +215,4 @@ interface TriggerOption {

readonly emptyValue: {
readonly type: PropType<string | number | null | undefined>;
readonly type: PropType<string | number | boolean | null | undefined>;
readonly default: undefined;
};

@@ -279,3 +285,4 @@ /** 校验函数, 返回字符串不通过, 会触发提示 - 提交时触发 */

readonly emptyValue: {
readonly type: PropType<string | number | null | undefined>;
readonly type: PropType<string | number | boolean | null | undefined>;
readonly default: undefined;
};

@@ -304,7 +311,7 @@ readonly validator: {

};
checked: vue_demi.Ref<string | string[]>;
checked: _vue_composition_api.Ref<string | string[]>;
getQuery: () => Record<string, any>;
insetDisabled: vue_demi.Ref<boolean>;
insetHide: vue_demi.Ref<boolean>;
finalOption: vue_demi.ComputedRef<Record<string, any>[]>;
insetDisabled: _vue_composition_api.Ref<boolean>;
insetHide: _vue_composition_api.Ref<boolean>;
finalOption: _vue_composition_api.ComputedRef<Record<string, any>[]>;
updateCheckedValue: (value: string | string[]) => void;

@@ -371,3 +378,4 @@ change: (value: string | string[]) => void;

readonly emptyValue: {
readonly type: PropType<string | number | null | undefined>;
readonly type: PropType<string | number | boolean | null | undefined>;
readonly default: undefined;
};

@@ -398,7 +406,7 @@ readonly validator: {

};
checked: vue_demi.Ref<ValueType[]>;
checked: _vue_composition_api.Ref<ValueType[]>;
getQuery: () => Record<string, any>;
finalOption: vue_demi.ComputedRef<Record<string, any>[]>;
insetDisabled: vue_demi.Ref<boolean>;
insetHide: vue_demi.Ref<boolean>;
finalOption: _vue_composition_api.ComputedRef<Record<string, any>[]>;
insetDisabled: _vue_composition_api.Ref<boolean>;
insetHide: _vue_composition_api.Ref<boolean>;
change: (values: ValueType[] | ValueType) => void;

@@ -431,2 +439,2 @@ reset: () => CommonMethod;

export { CommonMethod, CoreCondition, GetOptions, GetQuery, HideOption, IS_COMPOSITION_VERSION, PlainProps, ProvideValue, TreeProps, TriggerOption, ValueType$1 as ValueType, WrapperOption, WrapperProps, commonProps, defineCommonMethod, defineProvideValue, emptyToValue, getChained, getNode, plainProps, provideKey, treeProps, usePlain, useTree, useWrapper, wrapperProps };
export { CommonMethod, CoreCondition, GetOptions, GetQuery, HideOption, IS_COMPOSITION_VERSION, PlainProps, ProvideValue, TreeProps, TriggerOption, ValueType$1 as ValueType, WrapperOption, WrapperProps, commonProps, defineCommonMethod, defineProvideValue, emptyToValue, getChained, getNode, plainProps, provideKey, shallowDeep, treeProps, usePlain, useTree, useWrapper, wrapperProps };

@@ -5,3 +5,3 @@ import { ExtractPropTypes } from 'vue-demi';

/** 获取条件的初始值 */
export declare function useInitialValue<T extends ExtractPropTypes<Readonly<typeof commonProps>>>(props: T): import("vue-demi").WritableComputedRef<any>;
export declare function useInitialValue<T extends ExtractPropTypes<Readonly<typeof commonProps>>>(props: T): import("@vue/composition-api").WritableComputedRef<any>;
/**

@@ -11,4 +11,4 @@ * 获取当前组件的显示和隐藏状态

export declare function useDisplay<T extends ExtractPropTypes<Readonly<typeof commonProps>>>(props: T, option: CommonMethod): {
insetDisabled: import("vue-demi").Ref<boolean>;
insetHide: import("vue-demi").Ref<boolean>;
insetDisabled: import("@vue/composition-api").Ref<boolean>;
insetHide: import("@vue/composition-api").Ref<boolean>;
};

@@ -20,4 +20,4 @@ /**

export declare function useDisableInCurrentCycle(initialValue?: boolean): {
flag: import("vue-demi").Ref<boolean>;
flag: import("@vue/composition-api").Ref<boolean>;
updateFlag: () => void;
};

@@ -15,7 +15,7 @@ import { ExtractPropTypes } from 'vue-demi';

};
checked: import("vue-demi").Ref<string | string[]>;
checked: import("@vue/composition-api").Ref<string | string[]>;
getQuery: () => Record<string, any>;
insetDisabled: import("vue-demi").Ref<boolean>;
insetHide: import("vue-demi").Ref<boolean>;
finalOption: import("vue-demi").ComputedRef<Record<string, any>[]>;
insetDisabled: import("@vue/composition-api").Ref<boolean>;
insetHide: import("@vue/composition-api").Ref<boolean>;
finalOption: import("@vue/composition-api").ComputedRef<Record<string, any>[]>;
updateCheckedValue: (value: string | string[]) => void;

@@ -22,0 +22,0 @@ change: (value: string | string[]) => void;

@@ -55,3 +55,4 @@ import { PropType } from 'vue-demi';

readonly emptyValue: {
readonly type: PropType<string | number | null | undefined>;
readonly type: PropType<string | number | boolean | null | undefined>;
readonly default: undefined;
};

@@ -58,0 +59,0 @@ readonly validator: {

@@ -24,3 +24,3 @@ import { type PropType } from 'vue-demi';

/** 条件值可能的类型 */
export type ValueType = string | string[];
export type ValueType = number | string | string[];
/** 改变当前条件值触发方式 */

@@ -86,3 +86,4 @@ export interface TriggerOption {

readonly emptyValue: {
readonly type: PropType<string | number | null | undefined>;
readonly type: PropType<string | number | boolean | null | undefined>;
readonly default: undefined;
};

@@ -89,0 +90,0 @@ /** 校验函数, 返回字符串不通过, 会触发提示 - 提交时触发 */

@@ -17,7 +17,7 @@ import { ExtractPropTypes } from 'vue-demi';

};
checked: import("vue-demi").Ref<ValueType[]>;
checked: import("@vue/composition-api").Ref<ValueType[]>;
getQuery: () => Record<string, any>;
finalOption: import("vue-demi").ComputedRef<Record<string, any>[]>;
insetDisabled: import("vue-demi").Ref<boolean>;
insetHide: import("vue-demi").Ref<boolean>;
finalOption: import("@vue/composition-api").ComputedRef<Record<string, any>[]>;
insetDisabled: import("@vue/composition-api").Ref<boolean>;
insetHide: import("@vue/composition-api").Ref<boolean>;
change: (values: ValueType[] | ValueType) => void;

@@ -24,0 +24,0 @@ reset: () => import("../constant").CommonMethod;

@@ -59,3 +59,4 @@ import { PropType } from 'vue-demi';

readonly emptyValue: {
readonly type: PropType<string | number | null | undefined>;
readonly type: PropType<string | number | boolean | null | undefined>;
readonly default: undefined;
};

@@ -62,0 +63,0 @@ readonly validator: {

@@ -17,3 +17,3 @@ import { ExtractPropTypes } from 'vue-demi';

wrapperInstance: {
realtime: import("vue-demi").Ref<boolean | undefined>;
realtime: import("@vue/composition-api").Ref<boolean>;
register(compOption: CommonMethod): () => void;

@@ -25,3 +25,5 @@ updateQueryValue(field: string, value: any): void;

};
query: import("vue-demi").Ref<Record<string, string>>;
query: import("@vue/composition-api").Ref<{
[x: string]: string;
}>;
getQuery: () => {

@@ -28,0 +30,0 @@ [x: string]: any;

@@ -9,2 +9,7 @@ import { VNode } from 'vue-demi';

/**
* 对值进行浅拷贝
* @param {*} val
*/
export declare function shallowDeep<T extends unknown>(val: T): T;
/**
* 获取指定层级的父级(包括自身)

@@ -19,4 +24,2 @@ * @param {Record<string, any>[]} data 数据源

*/
export declare function getNode(node: string | ((...args: any[]) => VNode) | VNode, ...args: any[]): string | VNode<import("vue-demi").RendererNode, import("vue-demi").RendererElement, {
[key: string]: any;
}>;
export declare function getNode(node: string | ((...args: any[]) => VNode) | VNode | undefined | null, ...args: any[]): string | VNode | undefined;

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

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

{
"name": "@xiaohaih/condition-core",
"version": "0.3.1",
"version": "0.3.2",
"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';

@@ -1,3 +0,13 @@

import { ExtractPropTypes, computed, inject, onBeforeUnmount, PropType, ref, watch, watchEffect } from 'vue-demi';
import { emptyToValue } from '../../utils/index';
import {
ExtractPropTypes,
computed,
inject,
onBeforeUnmount,
PropType,
ref,
watch,
watchEffect,
toRaw,
} from 'vue-demi';
import { emptyToValue, shallowDeep } from '../../utils/index';
import { CommonMethod, defineCommonMethod, provideKey, ProvideValue } from '../constant';

@@ -31,5 +41,4 @@ import { useDisplay, useDisableInCurrentCycle, useInitialValue } from '../assist';

initialBackfillValue ||
(props.defaultValue !== undefined ? initialValue.value : props.multiple ? [] : '')
// 防止数组引用导致默认值发生改变
.slice(),
// 防止数组引用导致默认值发生改变
shallowDeep(props.defaultValue !== undefined ? initialValue.value : props.multiple ? [] : ''),
);

@@ -47,3 +56,3 @@ /** 远程获取的数据源 */

)
: { [props.field]: emptyToValue(checked.value, props.emptyValue) };
: { [props.field]: emptyToValue(shallowDeep(toRaw(checked.value)), props.emptyValue) };
};

@@ -107,3 +116,3 @@ // 防止触发搜索时, query 产生变化内部重复赋值

if (!realtimeFlag.value) return;
checked.value = _val;
updateCheckedValue(_val);
},

@@ -110,0 +119,0 @@ ),

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

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

@@ -30,3 +30,3 @@ import { type PropType } from 'vue-demi';

/** 条件值可能的类型 */
export type ValueType = string | string[];
export type ValueType = number | string | string[];

@@ -80,3 +80,6 @@ /** 改变当前条件值触发方式 */

/** 空置时提交的值 - 默认置为 undefined */
emptyValue: { type: [String, Number, null, undefined] as PropType<undefined | null | string | number> },
emptyValue: {
type: [String, Number, Boolean, null, undefined] as PropType<undefined | null | boolean | string | number>,
default: undefined,
},
/** 校验函数, 返回字符串不通过, 会触发提示 - 提交时触发 */

@@ -92,3 +95,3 @@ validator: {

defaultValue: {
type: [String, Array, Function] as PropType<
type: [String, Number, Array, Function] as PropType<
ValueType | ((query: Record<string, any>, backfill?: Record<string, any>) => ValueType)

@@ -95,0 +98,0 @@ >,

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

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

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

@@ -0,0 +0,0 @@ import { del, getCurrentInstance, onBeforeUnmount, provide, ExtractPropTypes, ref, set, watch, toRefs } from 'vue-demi';

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

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

@@ -14,2 +14,10 @@ import { markRaw, VNode } from 'vue-demi';

/**
* 对值进行浅拷贝
* @param {*} val
*/
export function shallowDeep<T extends unknown>(val: T): T {
return Array.isArray(val) ? ([...val] as T) : val;
}
/**
* 获取指定层级的父级(包括自身)

@@ -42,4 +50,6 @@ * @param {Record<string, any>[]} data 数据源

*/
export function getNode(node: string | ((...args: any[]) => VNode) | VNode, ...args: any[]) {
export function getNode(node: string | ((...args: any[]) => VNode) | VNode | undefined | null, ...args: any[]) {
// 直接抛出 null, template 中会报错
if (!node) return null as unknown as {};
return typeof node === 'function' ? node(...args) : typeof node === 'string' ? node : markRaw(node);
}

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