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.4.0 to 0.4.1

6

CHANGELOG.md
# @xiaohaih/condition-core
## 0.4.1
### Patch Changes
- 条件组件增加插槽, 支持条件项排序(包括 VNode)
## 0.4.0

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

46

dist/index.cjs.js

@@ -36,2 +36,3 @@ 'use strict';

realtime: vueDemi.ref(props.realtime),
queryChangedInWrapper: vueDemi.ref(props.realtime),
register(compOption) {

@@ -94,2 +95,13 @@ child.push(compOption);

});
vueDemi.watch(() => props.backfill, val => {
wrapperInstance.queryChangedInWrapper.value = true;
query.value = {
...val
};
vueDemi.nextTick(() => {
wrapperInstance.queryChangedInWrapper.value = false;
});
}, {
deep: true
});
async function search() {

@@ -313,5 +325,5 @@ const msg = await validate();

/** 初始是否存在回填值 */
const initialBackfillValue = props.backfill && (props.fields?.length ?
const initialBackfillValue = props.query && (props.fields?.length ?
// 防止回填值不存在时产生一个空数组(undefined[])
props.fields.map(key => props.backfill[key]).filter(Boolean) : props.backfill[props.field]);
props.fields.map(key => props.query[key]).filter(Boolean) : props.query[props.field]);
/** 当前选中值 */

@@ -383,14 +395,26 @@ const checked = vueDemi.shallowRef(initialBackfillValue || props.defaultValue !== undefined ? clone(initialValue.value) : undefined);

updateCheckedValue(_val);
wrapper?.queryChangedInWrapper.value || wrapper?.insetSearch();
}));
// 回填值发生变化时触发更新
unwatchs.push(vueDemi.watch(() => [props.fields || props.field, props.fields ? props.fields.map(k => props.backfill?.[k]).filter(Boolean) : props.backfill?.[props.field]], ([_field, val], [__field]) => {
// 存在回填值时回填, 不存在时不做改动
const _val = props.backfillToValue(val, _field, props.backfill);
if (_field.toString() !== __field.toString() || isEqualExcludeEmptyValue(_val, checked.value)) return;
updateBackfillFlag();
updateCheckedValue(_val);
}));
// // 回填值发生变化时触发更新
// unwatchs.push(
// watch(
// () =>
// [
// props.fields || props.field,
// props.fields
// ? props.fields.map((k) => props.backfill?.[k]).filter(Boolean)
// : props.backfill?.[props.field],
// ] as const,
// ([_field, val], [__field]) => {
// // 存在回填值时回填, 不存在时不做改动
// const _val = props.backfillToValue(val, _field, props.backfill);
// if (_field.toString() !== __field.toString() || isEqualExcludeEmptyValue(_val, checked.value)) return;
// updateBackfillFlag();
// updateCheckedValue(_val);
// },
// ),
// );
// 存在依赖项
unwatchs.push(vueDemi.watch(() => [props.depend, props.dependFields, props.dependFields && [].concat(props.dependFields).map(k => props.query?.[k])], ([_depend, _dependFields, val], [__depend, __dependFields, oldVal]) => {
if (!backfillFlag.value) return;
if (!realtimeFlag.value) return;
if (val === oldVal) return;

@@ -397,0 +421,0 @@ getOption('depend');

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

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

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

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

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

realtime: ref(props.realtime),
queryChangedInWrapper: ref(props.realtime),
register(compOption) {

@@ -92,2 +93,13 @@ child.push(compOption);

});
watch(() => props.backfill, val => {
wrapperInstance.queryChangedInWrapper.value = true;
query.value = {
...val
};
nextTick(() => {
wrapperInstance.queryChangedInWrapper.value = false;
});
}, {
deep: true
});
async function search() {

@@ -311,5 +323,5 @@ const msg = await validate();

/** 初始是否存在回填值 */
const initialBackfillValue = props.backfill && (props.fields?.length ?
const initialBackfillValue = props.query && (props.fields?.length ?
// 防止回填值不存在时产生一个空数组(undefined[])
props.fields.map(key => props.backfill[key]).filter(Boolean) : props.backfill[props.field]);
props.fields.map(key => props.query[key]).filter(Boolean) : props.query[props.field]);
/** 当前选中值 */

@@ -381,14 +393,26 @@ const checked = shallowRef(initialBackfillValue || props.defaultValue !== undefined ? clone(initialValue.value) : undefined);

updateCheckedValue(_val);
wrapper?.queryChangedInWrapper.value || wrapper?.insetSearch();
}));
// 回填值发生变化时触发更新
unwatchs.push(watch(() => [props.fields || props.field, props.fields ? props.fields.map(k => props.backfill?.[k]).filter(Boolean) : props.backfill?.[props.field]], ([_field, val], [__field]) => {
// 存在回填值时回填, 不存在时不做改动
const _val = props.backfillToValue(val, _field, props.backfill);
if (_field.toString() !== __field.toString() || isEqualExcludeEmptyValue(_val, checked.value)) return;
updateBackfillFlag();
updateCheckedValue(_val);
}));
// // 回填值发生变化时触发更新
// unwatchs.push(
// watch(
// () =>
// [
// props.fields || props.field,
// props.fields
// ? props.fields.map((k) => props.backfill?.[k]).filter(Boolean)
// : props.backfill?.[props.field],
// ] as const,
// ([_field, val], [__field]) => {
// // 存在回填值时回填, 不存在时不做改动
// const _val = props.backfillToValue(val, _field, props.backfill);
// if (_field.toString() !== __field.toString() || isEqualExcludeEmptyValue(_val, checked.value)) return;
// updateBackfillFlag();
// updateCheckedValue(_val);
// },
// ),
// );
// 存在依赖项
unwatchs.push(watch(() => [props.depend, props.dependFields, props.dependFields && [].concat(props.dependFields).map(k => props.query?.[k])], ([_depend, _dependFields, val], [__depend, __dependFields, oldVal]) => {
if (!backfillFlag.value) return;
if (!realtimeFlag.value) return;
if (val === oldVal) return;

@@ -395,0 +419,0 @@ getOption('depend');

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

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

@@ -154,2 +154,3 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {

realtime: vueDemi.ref(props.realtime),
queryChangedInWrapper: vueDemi.ref(props.realtime),
register(compOption) {

@@ -212,2 +213,13 @@ child.push(compOption);

});
vueDemi.watch(() => props.backfill, val => {
wrapperInstance.queryChangedInWrapper.value = true;
query.value = {
...val
};
vueDemi.nextTick(() => {
wrapperInstance.queryChangedInWrapper.value = false;
});
}, {
deep: true
});
async function search() {

@@ -431,5 +443,5 @@ const msg = await validate();

/** 初始是否存在回填值 */
const initialBackfillValue = props.backfill && (props.fields?.length ?
const initialBackfillValue = props.query && (props.fields?.length ?
// 防止回填值不存在时产生一个空数组(undefined[])
props.fields.map(key => props.backfill[key]).filter(Boolean) : props.backfill[props.field]);
props.fields.map(key => props.query[key]).filter(Boolean) : props.query[props.field]);
/** 当前选中值 */

@@ -501,14 +513,26 @@ const checked = vueDemi.shallowRef(initialBackfillValue || props.defaultValue !== undefined ? clone(initialValue.value) : undefined);

updateCheckedValue(_val);
wrapper?.queryChangedInWrapper.value || wrapper?.insetSearch();
}));
// 回填值发生变化时触发更新
unwatchs.push(vueDemi.watch(() => [props.fields || props.field, props.fields ? props.fields.map(k => props.backfill?.[k]).filter(Boolean) : props.backfill?.[props.field]], ([_field, val], [__field]) => {
// 存在回填值时回填, 不存在时不做改动
const _val = props.backfillToValue(val, _field, props.backfill);
if (_field.toString() !== __field.toString() || isEqualExcludeEmptyValue(_val, checked.value)) return;
updateBackfillFlag();
updateCheckedValue(_val);
}));
// // 回填值发生变化时触发更新
// unwatchs.push(
// watch(
// () =>
// [
// props.fields || props.field,
// props.fields
// ? props.fields.map((k) => props.backfill?.[k]).filter(Boolean)
// : props.backfill?.[props.field],
// ] as const,
// ([_field, val], [__field]) => {
// // 存在回填值时回填, 不存在时不做改动
// const _val = props.backfillToValue(val, _field, props.backfill);
// if (_field.toString() !== __field.toString() || isEqualExcludeEmptyValue(_val, checked.value)) return;
// updateBackfillFlag();
// updateCheckedValue(_val);
// },
// ),
// );
// 存在依赖项
unwatchs.push(vueDemi.watch(() => [props.depend, props.dependFields, props.dependFields && [].concat(props.dependFields).map(k => props.query?.[k])], ([_depend, _dependFields, val], [__depend, __dependFields, oldVal]) => {
if (!backfillFlag.value) return;
if (!realtimeFlag.value) return;
if (val === oldVal) return;

@@ -515,0 +539,0 @@ getOption('depend');

@@ -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,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,n){return n?(t.directive(e,n),u):t.directive(e)},mount:function(u,o){return i||((i=new t(Object.assign({propsData:n},e,{provide:Object.assign(r,e.provide)}))).$mount(u,o),i)},unmount:function(){i&&(i.$destroy(),i=void 0)}};return u}}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 r(e){return e}function u(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}};function l(e,t){return Array.isArray(e)?e.filter(Boolean).length?e:t:"number"==typeof e?e:e||t}function a(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 f(e){return null==e||"object"!=typeof e&&"function"!=typeof e}function c(e,t){if(f(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 p(e,t,n="children"){for(const i of e){if(t(i))return[i];if(i[n]?.length){const e=p(i[n],t);if(e.length)return e.unshift(i),e}}return[]}function v(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 y(e,n){const i=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:n}),o=()=>{if("function"==typeof e.hide){r.value!==e.hide(u())&&(r.value=e.hide(u()))}else if("function"==typeof e.disabled){i.value!==e.disabled(u())&&(i.value=e.disabled(u()))}};let l=[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]&&(r.value="boolean"==typeof e[1]&&e[1],e[1]),o()}))];return t.onBeforeUnmount((()=>(l.forEach((e=>e())),l=[]))),{insetDisabled:i,insetHide:r}}function h(e=!0){const n=t.ref(e);return{flag:n,updateFlag:()=>{n.value=!e,t.nextTick((()=>{n.value=e}))}}}const m={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]},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]}},g={...m,fields:{type:[Array]},backfillToValue:{type:Function,default:e=>e},options:{type:Array,default:()=>[]},getOptions:{type:Function}};const b={...m,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=m,e.defineCommonMethod=u,e.defineProvideValue=r,e.emptyToValue=l,e.getChained=p,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=a,e.isPrimitive=f,e.plainProps=g,e.provideKey=i,e.treeProps=b,e.usePlain=function(e){const n=t.inject(i),r=v(e),u=e.backfill&&(e.fields?.length?e.fields.map((t=>e.backfill[t])).filter(Boolean):e.backfill[e.field]),o=t.shallowRef(u||void 0!==e.defaultValue?c(r.value):void 0),d=t.ref([]),f=t.computed((()=>d.value.length?d.value:e.options)),p=()=>{if(e.customGetQuery)return e.customGetQuery(o.value,l,e);const t=c(o.value);return e.multiple&&e.fields?e.fields.reduce(((n,i,r)=>(n[i]=l(t?.[r],e.emptyValue),n)),{}):{[e.field]:l(t,e.emptyValue)}},{flag:m,updateFlag:g}=h(),{flag:b,updateFlag:V}=h(),w={reset(){const{multiple:t}=e;g(),V(),o.value=e.resetToInitialValue&&r.value?.slice()||(t?[]:"")},updateWrapperQuery(){g(),n&&Object.entries(p()).forEach((([e,t])=>n.updateQueryValue(e,t)))},get validator(){return e.validator},getQuery:p};n?.register(w);const{insetDisabled:Q,insetHide:k}=y(e,w);!u&&e.defaultValue&&w.updateWrapperQuery();const O=[];function F(t){e.getOptions?.((e=>{const t=o.value;o.value=void 0,d.value=e||[],o.value=t}),e.query||{},{trigger:t,change:(e,t)=>{t&&(r.value=e),q(e)},search:(e,t)=>{t&&(r.value=e),S(e),n?.search()}})}function S(e){e!==o.value&&(o.value=e,w.updateWrapperQuery())}function q(e){S(e),n?.insetSearch()}return t.onBeforeUnmount((()=>O.forEach((e=>e())))),O.push(t.watch((()=>e.field),((e,t)=>{e!==t&&n?.removeUnreferencedField(t),w.updateWrapperQuery()}))),O.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])=>{if(!m.value)return;const r=e.backfillToValue(n,t,e.query);t.toString()!==i.toString()||a(r,o.value)||S(r)}))),O.push(t.watch((()=>[e.fields||e.field,e.fields?e.fields.map((t=>e.backfill?.[t])).filter(Boolean):e.backfill?.[e.field]]),(([t,n],[i])=>{const r=e.backfillToValue(n,t,e.backfill);t.toString()!==i.toString()||a(r,o.value)||(V(),S(r))}))),O.push(t.watch((()=>[e.depend,e.dependFields,e.dependFields&&[].concat(e.dependFields).map((t=>e.query?.[t]))]),(([t,n,i],[r,u,l])=>{b.value&&i!==l&&(F("depend"),t===r&&a(n,u)&&(s(o.value)||S(e.multiple?[]:"")))}))),O.push(t.watch((()=>e.getOptions),F.bind(null,"initial"),{immediate:!0})),{wrapper:n,option:w,checked:o,getQuery:p,insetDisabled:Q,insetHide:k,finalOption:f,updateCheckedValue:S,change:q,reset:w.reset}},e.useTree=function(e){const n=t.inject(i),r=v(e),u=t.ref(),o=t.ref([]),d=t.computed((()=>o.value.length?o.value:e.options)),f=t.computed((()=>e.fields?e.fields.reduce(((t,n)=>(t[n]=e.emptyValue,t)),{}):{[e.field]:e.emptyValue})),m=()=>{if(!S.value&&!r.value)return{};let t=c(u.value);const{...n}=f.value;return e.customGetQuery?e.customGetQuery(t,l,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]]=l(t,e.emptyValue)})):n[e.field]=t:n[e.fields?.[0]||e.field]=l(t,e.emptyValue),n):n},{flag:g,updateFlag:b}=h(),{flag:V,updateFlag:w}=h(),Q={reset(){return b(),w(),u.value=e.resetToInitialValue&&r.value?.slice()||[],this},get validator(){return e.validator},updateWrapperQuery(){b(),n&&Object.entries(m()).forEach((([e,t])=>n.updateQueryValue(e,t)))},getQuery:m};n?.register(Q);const{insetDisabled:k,insetHide:O}=y(e,Q),F=[];t.onBeforeUnmount((()=>F.forEach((e=>e()))));const S=t.ref("function"!=typeof e.getOptions||!!e.fields?.length);function q(t){e.getOptions?.((e=>{o.value=e||[],S.value=!0}),e.query||{},{trigger:t,change:(e,t)=>{t&&(r.value=e),B(e)},search:(e,t)=>{t&&(r.value=e),A(e),n?.search()}})}function A(e){a(u.value,e)||(u.value=e,Q.updateWrapperQuery())}function B(e){A(e),n?.insetSearch()}function E(t){if(s(t))return[];const{valueKey:n,childrenKey:i}=e;return p(d.value,(e=>e[n]===t)).map((e=>e[n]),i).filter(Boolean)}return t.watch(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 u.value=e,void Q.updateWrapperQuery()}else if(t[n])return u.value=E(t[n]),void Q.updateWrapperQuery();r.value?.length&&(u.value="string"==typeof r.value?E(r.value):r.value.slice(),"string"==typeof r.value&&(r.value=c(u.value)),Q.updateWrapperQuery())}()),{immediate:!0}),F.push(t.watch((()=>e.fields||[e.field]),((e,t)=>{e.toString()!==t.toString()&&n&&t.forEach((t=>e.includes(t)||n.removeUnreferencedField(t))),Q.updateWrapperQuery()}))),F.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&&a(t,i)}))),F.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)=>{S.value&&(a(e,t)||w())}))),F.push(t.watch((()=>[e.depend,e.dependFields,e.dependFields&&[].concat(e.dependFields).map((t=>e.query?.[t]))]),(([e,t,n],[i,r,u])=>{V.value&&(a(n,u)||(q("depend"),e===i&&t?.toString()===r?.toString()&&A(void 0)))}))),F.push(t.watch((()=>e.getOptions),q.bind(null,"initial"),{immediate:!0})),{wrapper:n,option:Q,checked:u,getQuery:m,finalOption:d,insetDisabled:k,insetHide:O,change:B,reset:Q.reset}},e.useWrapper=function(e,r){const u=[];t.onBeforeUnmount((()=>u.splice(0)));const o={};let l=!1,a=[];const s={realtime:t.ref(e.realtime),register(i){u.push(i);const r=()=>{l=!0,i.reset(),i.updateWrapperQuery();const n=u.indexOf(i);-1!==n&&u.splice(n,1),e.searchAtDatumChanged&&c(),l=!1,a.forEach((e=>{t.del(d.value,e),delete o[e]})),a=[]},s=t.getCurrentInstance();return s&&t.onBeforeUnmount(r,n?s.proxy:s),r},updateQueryValue(e,n){l&&a.push(e),t.set(d.value,e,n),o[e]=n},insetSearch(){e.realtime&&c()},search:c,removeUnreferencedField(e){let n=0;u.some((t=>(t.getQuery().hasOwnProperty(e)&&(n+=1),n))),n||(t.del(d.value,e),delete o[e])}};t.provide(i,s);const d=t.ref({...e.backfill}),f=()=>({...d.value,...e.backfill,...o});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=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,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,n){return n?(t.directive(e,n),u):t.directive(e)},mount:function(u,a){return i||((i=new t(Object.assign({propsData:n},e,{provide:Object.assign(r,e.provide)}))).$mount(u,a),i)},unmount:function(){i&&(i.$destroy(),i=void 0)}};return u}}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 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 o(e,t){return Array.isArray(e)?e.filter(Boolean).length?e:t:"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 f(e){return null==e||"object"!=typeof e&&"function"!=typeof e}function c(e,t){if(f(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 p(e,t,n="children"){for(const i of e){if(t(i))return[i];if(i[n]?.length){const e=p(i[n],t);if(e.length)return e.unshift(i),e}}return[]}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 v(e,n){const i=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:n}),a=()=>{if("function"==typeof e.hide){r.value!==e.hide(u())&&(r.value=e.hide(u()))}else if("function"==typeof e.disabled){i.value!==e.disabled(u())&&(i.value=e.disabled(u()))}};let o=[t.watch((()=>e.query),a,{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]&&(r.value="boolean"==typeof e[1]&&e[1],e[1]),a()}))];return t.onBeforeUnmount((()=>(o.forEach((e=>e())),o=[]))),{insetDisabled:i,insetHide:r}}function h(e=!0){const n=t.ref(e);return{flag:n,updateFlag:()=>{n.value=!e,t.nextTick((()=>{n.value=e}))}}}const m={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]},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]}},g={...m,fields:{type:[Array]},backfillToValue:{type:Function,default:e=>e},options:{type:Array,default:()=>[]},getOptions:{type:Function}};const b={...m,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=m,e.defineCommonMethod=u,e.defineProvideValue=r,e.emptyToValue=o,e.getChained=p,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=f,e.plainProps=g,e.provideKey=i,e.treeProps=b,e.usePlain=function(e){const n=t.inject(i),r=y(e),u=e.query&&(e.fields?.length?e.fields.map((t=>e.query[t])).filter(Boolean):e.query[e.field]),a=t.shallowRef(u||void 0!==e.defaultValue?c(r.value):void 0),d=t.ref([]),f=t.computed((()=>d.value.length?d.value:e.options)),p=()=>{if(e.customGetQuery)return e.customGetQuery(a.value,o,e);const t=c(a.value);return e.multiple&&e.fields?e.fields.reduce(((n,i,r)=>(n[i]=o(t?.[r],e.emptyValue),n)),{}):{[e.field]:o(t,e.emptyValue)}},{flag:m,updateFlag:g}=h(),{flag:b,updateFlag:V}=h(),w={reset(){const{multiple:t}=e;g(),V(),a.value=e.resetToInitialValue&&r.value?.slice()||(t?[]:"")},updateWrapperQuery(){g(),n&&Object.entries(p()).forEach((([e,t])=>n.updateQueryValue(e,t)))},get validator(){return e.validator},getQuery:p};n?.register(w);const{insetDisabled:q,insetHide:Q}=v(e,w);!u&&e.defaultValue&&w.updateWrapperQuery();const O=[];function F(t){e.getOptions?.((e=>{const t=a.value;a.value=void 0,d.value=e||[],a.value=t}),e.query||{},{trigger:t,change:(e,t)=>{t&&(r.value=e),A(e)},search:(e,t)=>{t&&(r.value=e),S(e),n?.search()}})}function S(e){e!==a.value&&(a.value=e,w.updateWrapperQuery())}function A(e){S(e),n?.insetSearch()}return t.onBeforeUnmount((()=>O.forEach((e=>e())))),O.push(t.watch((()=>e.field),((e,t)=>{e!==t&&n?.removeUnreferencedField(t),w.updateWrapperQuery()}))),O.push(t.watch((()=>[e.fields||e.field,e.fields?e.fields.map((t=>e.query[t])).filter(Boolean):e.query[e.field]]),(([t,i],[r])=>{if(!m.value)return;const u=e.backfillToValue(i,t,e.query);t.toString()!==r.toString()||l(u,a.value)||(S(u),n?.queryChangedInWrapper.value||n?.insetSearch())}))),O.push(t.watch((()=>[e.depend,e.dependFields,e.dependFields&&[].concat(e.dependFields).map((t=>e.query?.[t]))]),(([t,n,i],[r,u,o])=>{m.value&&i!==o&&(F("depend"),t===r&&l(n,u)&&(s(a.value)||S(e.multiple?[]:"")))}))),O.push(t.watch((()=>e.getOptions),F.bind(null,"initial"),{immediate:!0})),{wrapper:n,option:w,checked:a,getQuery:p,insetDisabled:q,insetHide:Q,finalOption:f,updateCheckedValue:S,change:A,reset:w.reset}},e.useTree=function(e){const n=t.inject(i),r=y(e),u=t.ref(),a=t.ref([]),d=t.computed((()=>a.value.length?a.value:e.options)),f=t.computed((()=>e.fields?e.fields.reduce(((t,n)=>(t[n]=e.emptyValue,t)),{}):{[e.field]:e.emptyValue})),m=()=>{if(!S.value&&!r.value)return{};let t=c(u.value);const{...n}=f.value;return e.customGetQuery?e.customGetQuery(t,o,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]]=o(t,e.emptyValue)})):n[e.field]=t:n[e.fields?.[0]||e.field]=o(t,e.emptyValue),n):n},{flag:g,updateFlag:b}=h(),{flag:V,updateFlag:w}=h(),q={reset(){return b(),w(),u.value=e.resetToInitialValue&&r.value?.slice()||[],this},get validator(){return e.validator},updateWrapperQuery(){b(),n&&Object.entries(m()).forEach((([e,t])=>n.updateQueryValue(e,t)))},getQuery:m};n?.register(q);const{insetDisabled:Q,insetHide:O}=v(e,q),F=[];t.onBeforeUnmount((()=>F.forEach((e=>e()))));const S=t.ref("function"!=typeof e.getOptions||!!e.fields?.length);function A(t){e.getOptions?.((e=>{a.value=e||[],S.value=!0}),e.query||{},{trigger:t,change:(e,t)=>{t&&(r.value=e),I(e)},search:(e,t)=>{t&&(r.value=e),C(e),n?.search()}})}function C(e){l(u.value,e)||(u.value=e,q.updateWrapperQuery())}function I(e){C(e),n?.insetSearch()}function k(t){if(s(t))return[];const{valueKey:n,childrenKey:i}=e;return p(d.value,(e=>e[n]===t)).map((e=>e[n]),i).filter(Boolean)}return t.watch(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 u.value=e,void q.updateWrapperQuery()}else if(t[n])return u.value=k(t[n]),void q.updateWrapperQuery();r.value?.length&&(u.value="string"==typeof r.value?k(r.value):r.value.slice(),"string"==typeof r.value&&(r.value=c(u.value)),q.updateWrapperQuery())}()),{immediate:!0}),F.push(t.watch((()=>e.fields||[e.field]),((e,t)=>{e.toString()!==t.toString()&&n&&t.forEach((t=>e.includes(t)||n.removeUnreferencedField(t))),q.updateWrapperQuery()}))),F.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)}))),F.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)=>{S.value&&(l(e,t)||w())}))),F.push(t.watch((()=>[e.depend,e.dependFields,e.dependFields&&[].concat(e.dependFields).map((t=>e.query?.[t]))]),(([e,t,n],[i,r,u])=>{V.value&&(l(n,u)||(A("depend"),e===i&&t?.toString()===r?.toString()&&C(void 0)))}))),F.push(t.watch((()=>e.getOptions),A.bind(null,"initial"),{immediate:!0})),{wrapper:n,option:q,checked:u,getQuery:m,finalOption:d,insetDisabled:Q,insetHide:O,change:I,reset:q.reset}},e.useWrapper=function(e,r){const u=[];t.onBeforeUnmount((()=>u.splice(0)));const a={};let o=!1,l=[];const s={realtime:t.ref(e.realtime),queryChangedInWrapper:t.ref(e.realtime),register(i){u.push(i);const r=()=>{o=!0,i.reset(),i.updateWrapperQuery();const n=u.indexOf(i);-1!==n&&u.splice(n,1),e.searchAtDatumChanged&&c(),o=!1,l.forEach((e=>{t.del(d.value,e),delete a[e]})),l=[]},s=t.getCurrentInstance();return s&&t.onBeforeUnmount(r,n?s.proxy:s),r},updateQueryValue(e,n){o&&l.push(e),t.set(d.value,e,n),a[e]=n},insetSearch(){e.realtime&&c()},search:c,removeUnreferencedField(e){let n=0;u.some((t=>(t.getQuery().hasOwnProperty(e)&&(n+=1),n))),n||(t.del(d.value,e),delete a[e])}};t.provide(i,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 t.watch((()=>e.backfill),(e=>{s.queryChangedInWrapper.value=!0,d.value={...e},t.nextTick((()=>{s.queryChangedInWrapper.value=!1}))}),{deep:!0}),{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

@@ -15,2 +15,6 @@ import * as vue_demi from 'vue-demi';

/**
* 当 query 变化是, 是否在 wrapper 处触发的
*/
queryChangedInWrapper: Ref<boolean | undefined>;
/**
* 子组件需主动注册组件, 否则不会生效

@@ -90,2 +94,3 @@ * @param {CommonMethod} config 提供父组件校验, 重置等方法

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

@@ -92,0 +97,0 @@ updateQueryValue(field: string, value: any): void;

@@ -13,2 +13,6 @@ import { type Ref } from 'vue-demi';

/**
* 当 query 变化是, 是否在 wrapper 处触发的
*/
queryChangedInWrapper: Ref<boolean | undefined>;
/**
* 子组件需主动注册组件, 否则不会生效

@@ -15,0 +19,0 @@ * @param {CommonMethod} config 提供父组件校验, 重置等方法

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

realtime: import("vue-demi").Ref<boolean | undefined>;
queryChangedInWrapper: import("vue-demi").Ref<boolean | undefined>;
register(compOption: CommonMethod): () => void;

@@ -20,0 +21,0 @@ updateQueryValue(field: string, value: any): void;

{
"name": "@xiaohaih/condition-core",
"version": "0.4.0",
"version": "0.4.1",
"description": "",

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

@@ -16,2 +16,6 @@ import { version, type Ref } from 'vue-demi';

/**
* 当 query 变化是, 是否在 wrapper 处触发的
*/
queryChangedInWrapper: Ref<boolean | undefined>;
/**
* 子组件需主动注册组件, 否则不会生效

@@ -18,0 +22,0 @@ * @param {CommonMethod} config 提供父组件校验, 重置等方法

@@ -31,7 +31,7 @@ import {

const initialBackfillValue =
props.backfill &&
props.query &&
(props.fields?.length
? // 防止回填值不存在时产生一个空数组(undefined[])
props.fields.map((key) => props.backfill![key]).filter(Boolean)
: props.backfill[props.field]);
props.fields.map((key) => props.query[key]).filter(Boolean)
: props.query[props.field]);
/** 当前选中值 */

@@ -112,24 +112,25 @@ const checked = shallowRef<ValueType | ValueType[]>(

updateCheckedValue(_val);
wrapper?.queryChangedInWrapper.value || wrapper?.insetSearch();
},
),
);
// 回填值发生变化时触发更新
unwatchs.push(
watch(
() =>
[
props.fields || props.field,
props.fields
? props.fields.map((k) => props.backfill?.[k]).filter(Boolean)
: props.backfill?.[props.field],
] as const,
([_field, val], [__field]) => {
// 存在回填值时回填, 不存在时不做改动
const _val = props.backfillToValue(val, _field, props.backfill);
if (_field.toString() !== __field.toString() || isEqualExcludeEmptyValue(_val, checked.value)) return;
updateBackfillFlag();
updateCheckedValue(_val);
},
),
);
// // 回填值发生变化时触发更新
// unwatchs.push(
// watch(
// () =>
// [
// props.fields || props.field,
// props.fields
// ? props.fields.map((k) => props.backfill?.[k]).filter(Boolean)
// : props.backfill?.[props.field],
// ] as const,
// ([_field, val], [__field]) => {
// // 存在回填值时回填, 不存在时不做改动
// const _val = props.backfillToValue(val, _field, props.backfill);
// if (_field.toString() !== __field.toString() || isEqualExcludeEmptyValue(_val, checked.value)) return;
// updateBackfillFlag();
// updateCheckedValue(_val);
// },
// ),
// );
// 存在依赖项

@@ -145,3 +146,3 @@ unwatchs.push(

([_depend, _dependFields, val], [__depend, __dependFields, oldVal]) => {
if (!backfillFlag.value) return;
if (!realtimeFlag.value) return;
if (val === oldVal) return;

@@ -148,0 +149,0 @@ getOption('depend');

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

import { del, getCurrentInstance, onBeforeUnmount, provide, ExtractPropTypes, ref, set, watch, toRefs } from 'vue-demi';
import {
del,
getCurrentInstance,
onBeforeUnmount,
provide,
ExtractPropTypes,
ref,
set,
watch,
toRefs,
nextTick,
} from 'vue-demi';
import { IS_COMPOSITION_VERSION, provideKey, ProvideValue, CommonMethod, defineProvideValue } from '../constant';

@@ -36,2 +47,3 @@ import { wrapperProps } from './props';

realtime: ref(props.realtime),
queryChangedInWrapper: ref(props.realtime),
register(compOption) {

@@ -89,2 +101,13 @@ child.push(compOption);

const getQuery = () => ({ ...query.value, ...props.backfill, ...changedQueryObj });
watch(
() => props.backfill,
(val) => {
wrapperInstance.queryChangedInWrapper.value = true;
query.value = { ...val };
nextTick(() => {
wrapperInstance.queryChangedInWrapper.value = false;
});
},
{ deep: true },
);

@@ -91,0 +114,0 @@ async function search() {

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