@fox-js/flow
Advanced tools
Comparing version 4.0.1-34 to 4.0.1-35
"use strict";/*! | ||
* @fox-js/flow v4.0.1-33 Tue Sep 24 2024 17:17:13 GMT+0800 (中国标准时间) | ||
*/Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("vue"),f=require("@fox-js/fox");function de(o){return Object.prototype.toString.call(o)==="[object RegExp]"}const D=Symbol.for("BroadcastKey");class he{parent;children=[];callbacks=new Map;proxy=null;name;constructor(e,t,n){this.parent=e,this.proxy=t,this.name=n,e!==null&&e.addChild(this)}addChild(e){this.children.push(e)}removeChild(e){const t=this.children.findIndex(n=>e===n);t!==-1&&this.children.splice(t,1)}destroy(){this.parent!==null&&this.parent.removeChild(this),this.parent=null,this.proxy=null}emit(e,t,...n){if(e.maxLevel!==void 0&&e.maxLevel!==null&&e.maxLevel>0){if(e.level=e.level??0,e.level>e.maxLevel)return[];e.level++}let s=!1;!e.name||e.name==="*"?s=!0:!e.name||e.name==="+"?(s=!1,e.name="*"):de(e.name)&&this.name&&e.name.test(this.name)?s=!0:typeof e.name=="function"?s=Reflect.apply(e.name,null,[this.name]):e.name===this.name&&(s=!0);const r=[];if(s){const l=this.callbacks.get(t);if(typeof l=="function"){const a=Reflect.apply(l,this.proxy,[...n]);a!=null&&r.push(a)}const i=this.proxy??{};if(typeof i[t]=="function"){const a=Reflect.apply(i[t],i,[...n]);a!=null&&r.push(a)}}return this.children.forEach(l=>{const i=Reflect.apply(l.emit,l,[{...e},t,...n]);i!=null&&Array.isArray(i)&&Reflect.apply([].push,r,[...i])}),r}emitToChildren(e,t,...n){const s=[];return this.children.forEach(r=>{const l=Reflect.apply(r.emit,r,[{...e},t,...n]);l!=null&&Array.isArray(l)&&Reflect.apply([].push,s,[...l])}),s}on(e,t){this.callbacks.set(e,t)}}function pe(o,e,t,n){return new he(e,o,t)}const y="",J=new Map;function me(o,e=y){J.set(e,o)}function xe(o=y){return J.get(o)??null}const C=new WeakMap;function be(o,e,t=y){let n=C.get(o);n||(n=new Map,C.set(o,n)),n.set(t,e)}function we(o){const e=[],t=C.get(o);return t&&t.forEach((n,s)=>{e.push(n)}),e}function ve(o,e=y){const t=C.get(o);return t?t.get(e)??null:null}function ge(o,e=y){const t=C.get(o);return t?t.has(e):!1}function Fe(o){C.delete(o)}const Q=new Map,N=new WeakMap,v=o=>{let e=N.get(o);if(!e){const t=u.inject(D,null);e=pe(o,t),N.set(o,e);const n=o;n[D]=e,u.provide(D,e)}return e},Se=o=>{const e=o;e[D]=null,N.delete(o),u.provide(D,null)},ke=Symbol.for("SyncDataKey");function X(o){const e=f.useRoute(o);return e&&e.params?e.params[ke]??{}:{}}const K="FoxFlow";class Ce{data={}}const I=Symbol("nameKey"),W=Symbol("allDataListKey"),E=Symbol("dataListKey"),O=Symbol("proxyKey");class Re{[I]=y;[W]=[];[E]=[];[O]=null;get name(){return this[I]}get originalData(){const e=this[E];return e.length>0?e[0].original:{}}get data(){const e=this[E];return e.length>0?e[0].last:{}}get allDataList(){return this[W]}get dataList(){return this[E]}get proxy(){return this[O]}get route(){return f.useRoute(this.proxy??void 0)}}function Ee(o,e){const t=Q.get(e);if(t){let n=o;const s=new t;n.__proto__=s}return o}function De(o,e,t){const n=we(e);let s=[];!t||t===y?s=[]:Array.isArray(t)?s=t:s=[String(t??"")];const r=[];n.forEach(l=>{const i=String(l.name??"");(s.length===0||s.includes(i))&&r.push(l)}),o[W]=n,o[E]=r,o[O]=e,o[I]=t??y}function Y(o,e,t,...n){const s=v(o);return Reflect.apply(s.emit,s,[e,t,...n])}function Z(o,e=!0,t){const n=v(o);let s=null;if(!t||t===y)t=void 0,s={maxLevel:1,level:1};else if(Array.isArray(t)){const l=t;s={name:i=>l.includes(i)}}else s={name:String(t)};const r=n.emitToChildren(s,"validate",e);return r.length==1?r[0]:r.length>1?Promise.all(r).then(l=>{let i=[];return l.forEach(a=>{a.pass===!1&&Array.isArray(a.errors)&&(i=[...i,...a.errors])}),i.length>0?{pass:!1,errors:i}:{pass:!0}}):Promise.resolve({pass:!0})}function ee(o,e=!0,t){const n=v(o);let s=null;if(!t||t===y)t=void 0,s={maxLevel:1,level:1};else if(Array.isArray(t)){const r=t;s={name:l=>r.includes(l)}}else s={name:String(t)};n.emitToChildren(s,"clearValidate",e)}function te(o,e,t=!0){const n=v(o),s={maxLevel:1,level:1};n.emitToChildren(s,"setNameValidateRules",e,t)}const oe=o=>`_fox_ctrl_${o.path??o.name??""}_${o.root??"default"}`;function Ke(o,e,t){if(o==null||typeof o!="object")return;let n=o;const s=e.split(".");for(let r=0;r<s.length&&Reflect.has(n,s[r]);r++){if(r===s.length-1){n[s[r]]=t;return}if(n=n[s[r]],n==null||typeof n!="object")break}}function Ae(o,e,t,n){const s=v(o);let r=null;if(!n||n===y)n=void 0,r={maxLevel:1,level:1};else if(Array.isArray(n)){const l=n;r={name:i=>l.includes(i)}}else r={name:String(n)};s.emitToChildren(r,"setDomainProperty",e,t)}const Le=["beforeBack","back"],G="getShareBus",q="havePermission",Pe=["beforeExit","exit"],Me=["setCheckConditions","check"],Ve="cancelSubmit",He="endSubmit";let ne=["preSubmit","commit","submit","postSubmit"],M=[];function se(o){ne=[...o]}function re(o){M=[...o]}let V=null;function le(o){V=o}const je="foxOpenType";let Be=o=>{const e=f.useRoute(o);return e&&e.params?e.params[je]??"normal":"normal"};const w=Symbol("eventChainKey"),g=Symbol("sessionKey"),h=Symbol("proxyKey"),L=Symbol("userFlowKey"),F=Symbol("flowKey"),S=Symbol("stateKey"),B=Symbol("flowNameKey"),P=Symbol("allowResubmit"),k=Symbol("_getFlowEventChain"),m=Symbol("_getFlow"),_=Symbol("_reset"),ie=Symbol("_destroy"),d=Symbol("_execHook");function _e(o){return o==null?!1:o===!1?!0:typeof o=="object"&&Reflect.has(o,"pass")?!o.pass:!1}const R=function(o,e){return(n,...s)=>{try{const r=Reflect.apply(o,e,[n,...s]);f.isPromise(r)&&r.then(l=>{_e(l)?n.reject(l):n.resolve(l)}).catch(l=>{n.reject(l)})}catch(r){console.error(`[${K}] exec hook error`,r),n.reject(r)}}};class ae{[w]=null;[g]=new Ce;[h];[L];[F]=null;[S]="none";[B]="";[P]=!1;constructor(e,t){this[L]=e,this[h]=t}[k](e=!1){return e?new f.EventChain(this[g],!0):this[w]?this[w]:(this[w]=new f.EventChain(this[g],!0),this[w])}[m](e){if(!this[F]){const t=Be(this[h]);this[F]=Ee(this[L],t)}return De(this[F],this[h],e),this[F]}[_](){this[w]=null,this[S]="none"}[d](e,t){const n=this[m](t);if(Array.isArray(e)){const s=this[k](!0);e.forEach(r=>{const l=n[r];if(typeof l=="function"){const i=R(l,n);s?.post(i)}})}else{const s=n[e];if(typeof s=="function")return Reflect.apply(s,n,[this[g]])}}pretreat(e){return this[S]==="submit"?(console.warn(`[${K}]流程已经处于提交状态,无法加入预处理任务`),!1):(this[k]()?.post(e),this[S]="pretreat",!0)}[ie](){const e=this;e[w]=null,e[g]=null,e[h]=null,e[L]=null,e[F]=null}get name(){return this[B]??""}get proxy(){return this[h]}set allowResubmit(e){this[P]=e}get allowResubmit(){return this[P]}submit(e,t){if(typeof e=="string"&&(t=e,e=void 0),this[B]=t??"",!this[P]&&this[S]==="submit")return console.warn(`[${K}]流程已经处于提交状态,无法重复提交`),!1;e&&typeof e=="object"&&Object.assign(this[g].data,e);const n=this[k]();if(this[S]==="pretreat"&&V){try{V.lock()}catch{}n?.post(r=>{V?.unlock(),r.resolve()})}const s=this[m](t);Me.forEach(r=>{const l=s[r];typeof l=="function"&&n?.post(R(l,s))}),ne.forEach(r=>{const l=s[r];typeof l=="function"&&n?.post(R(l,s))}),n?.wait((r,...l)=>{this[_]();const i=s[He];typeof i=="function"&&Reflect.apply(i,s,[r,...l])},(r,...l)=>{this[_]();const i=()=>{const a=s[Ve];typeof a=="function"&&Reflect.apply(a,s,[r,...l])};if(Array.isArray(M)&&M.length>0){const a=this[k](!0);M.forEach(c=>{const b=s[c];typeof b=="function"&&a?.post(R(b,s))}),a?.wait(()=>i,()=>i)}else i()})}exit(e){return new Promise((t,n)=>{const s=this[k](!0),r=this[m](e);Pe.forEach(l=>{const i=r[l];typeof i=="function"&&s?.post(R(i,r))}),s?.wait((l,...i)=>{t(!0)},(l,...i)=>{t(!0)})})}back(e){return this[d](Le,e),!0}exec(e,t){return this[d](e,t)}getShareBus(e){const t=this[m](e);return typeof t[G]=="function"?Reflect.apply(t[G],t,[]):null}havePermission(e){const t=this[m]();return typeof t[q]=="function"?Reflect.apply(t[q],t,[e]):!0}setValue(e,t,n){const s=this[m](n??"");if(Array.isArray(s.allDataList)){for(let r of s.allDataList)if(r.name===n){Ke(r.last,e,t),r.last[e]=t;break}}}getValue(e,t){let n=null;const s=this[m](t??"");if(Array.isArray(s.allDataList)){for(let r of s.allDataList)if(r.name===t){n=r.last[e];break}}return n}get allDataList(){return this[m]().allDataList}get dataList(){return this[m]().dataList}getDataRecordByFieldName(e){return this.allDataList.find(s=>Reflect.ownKeys(s.last).includes(e))??null}broadcast(e,t,...n){return Reflect.apply(Y,null,[this[h],e,t,...n])}resetFields(e,t){let n=[];Array.isArray(t)?n=t:typeof t=="string"?n=[t]:n=[y];const s=this[h];n.forEach(r=>{const l=ve(s,r)??{original:{},last:{}},i={};if(f.extend(!0,i,l.original),Array.isArray(e))e.forEach(a=>{l.last[a]=i[a]});else if(e&&Array.isArray(e.include))(e.include??[]).forEach(c=>{l.last[c]=i[c]});else if(e&&Array.isArray(e.exclude)){let a=e.exclude??[];Reflect.ownKeys(i).forEach(c=>{typeof c=="string"&&(a.includes(c)||(l.last[c]=i[c]))})}else Object.assign(l.last,i)}),this.clearValidate(e,t)}validate(e=!0,t){return Z(this[h],e,t)}clearValidate(e=!0,t){return ee(this[h],e,t)}setNameValidateRules(e,t=!0){return te(this[h],e,t)}}const ce=Symbol.for("FoxControllerKey"),Te=Symbol.for("PageWrapperKey"),H=new WeakMap;let x=[];function $e(o,e){const t=u.toRaw(o);me(t,e)}function Ne(o,e,t){let n=t,s,r;const l={};if(typeof e=="string"?s=e:e&&typeof e=="object"&&(s=e.name,r=e.mixin,Object.assign(l,e)),!n){const p=u.getCurrentInstance();if(p===null)throw new Error("defineData must in setup hook");if(p.proxy==null)throw new Error("proxy is null");n=p.proxy}if(ge(n,s))throw new Error("duplicate definitions are not allowed, please Set different name!");const i=u.isReactive(o)?u.toRaw(o):o,a=xe(r);a&&f.extend(!0,i,a);const c=X(n);if(!s)f.extend(!0,i,c);else{const p=c[s];p&&typeof p=="object"&&f.extend(!0,i,p)}const b={};f.extend(!0,b,i);const A=u.reactive(i);if(be(n,{name:s??y,metadata:l,original:b,last:A},s),n){const p=v(n),U=()=>{s?p?.emitToChildren({name:s},"setModelValue",A):p?.emitToChildren({maxLevel:1,level:1},"setModelValue",A)};n.$.isMounted?U():u.onMounted(U)}return A}function Ie(o={},e){if(!e){const a=u.getCurrentInstance();if(a===null)throw new Error("defineData must in setup hook");if(a.proxy===null)throw new Error("proxy is null");e=a.proxy}v(e);const t=new ae(o,e);H.set(e,t),f.provideContextValue(e,ce,t),x.push({proxy:e,controller:t,state:"create"});const n=f.useEventProxy(e);let s=null,r=null;const l=f.useRoute(e);l&&l.path&&l.root&&(r=oe(l),s=(a,c)=>{a==="exit"?t.exit(c):a==="submit"?t.submit(c):a==="execHook"&&typeof c=="string"&&t[d](c)},n.on(r,s)),u.onBeforeMount(()=>{t[d]("beforeMount")}),u.onMounted(()=>{const a=e;a&&Oe(a,"mounted"),t[d](["mounted","endMounted"])}),u.onBeforeUnmount(()=>{t[d]("beforeUnmount")}),u.onUnmounted(()=>{t[d]("unmounted"),t[ie]();const a=e;a&&(Ue(a),Se(a),H.delete(a),Fe(a)),r&&s&&n.off(r,s)}),f.onFoxActivated(()=>{t[d]("activated")}),f.onFoxInactivated(()=>{t[d]("inactivated")});const i=u.inject(Te,null);i&&typeof i.beforeClose!="function"&&(i.used||(i.used=!0,i.beforeClose=async a=>{const c=e;if(c){const b=H.get(c);b?await b.exit():r&&n.emit(r,"exit")}typeof a=="function"&&a()},i.onShow=()=>{t[d]("activated")},i.onHide=()=>{t[d]("inactivated")}));try{t[d]("created")}catch(a){console.error(`[${K}] created error`,a)}return t}function We(o){let e=null;return o&&(e=H.get(o)??null),e||(o||(o=u.getCurrentInstance()?.proxy??void 0),o&&(e=f.injectContextValue(o,ce))),e}function Oe(o,e){for(let t=x.length-1;t>=0;t--){const n=x[t];if(n.proxy===o){n.state=e;break}}}function Ue(o){const e=x.findIndex(t=>t.proxy===o);e!==-1&&x.splice(e,1)}function j(o){if(!o){const e=x.length-1;if(e>=0){const t=x[e];if(t.state==="create")return t}return null}for(let e=x.length-1;e>=0;e--){const t=x[e];if(t.proxy&&t.proxy.$el){const n=t.proxy.$el;if(n===o||n.contains(o))return t}}return null}function Ge(o){if(!o){const e=u.getCurrentInstance();if(e===null)throw new Error("getSyncData must in setup hook");if(e.proxy===null)throw new Error("proxy is null");o=e.proxy}return X(o)}const ue=o=>{let{key:e,shiftKey:t,altKey:n,ctrlKey:s}=o,r=[];return t&&r.push("Shift"),n&&r.push("Alt"),s&&r.push("Ctrl"),r.push(e),r.join("+").toLocaleUpperCase()},fe=(o,e="Enter")=>{let t=[o.arg??e];return o.modifiers.Shift?t.splice(0,0,"Shift"):o.modifiers.Alt?t.splice(0,0,"Alt"):o.modifiers.Ctrl&&t.splice(0,0,"Ctrl"),t.join("+").toLocaleUpperCase()},T=new WeakMap,qe={mounted(o,e,t,n){const s=fe(e,"ENTER"),r=j(o),l=e.value??{},i=a=>{const c=ue(a);r&&r.controller&&c===s&&r.controller.submit(l)};o.addEventListener("keyup",i),T.set(o,i)},beforeUnmount(o,e,t,n){const s=T.get(o);T.delete(o),s&&o.removeEventListener("keyup",s)}},$=new WeakMap,ze={mounted(o,e,t,n){const s=fe(e,"ESCAPE"),r=j(o),l=e.value??{},i=a=>{const c=ue(a);r&&r.controller&&c===s&&r.controller.exit(l)};o.addEventListener("keyup",i),$.set(o,i)},beforeUnmount(o,e,t,n){const s=$.get(o);$.delete(o),s&&o.removeEventListener("keyup",s)}},z=(o,e,t)=>{t?e==="disabled"&&o.hasAttribute("disabled")?o.removeAttribute("disbaled"):o.style.display==="none"&&(o.style.display="block"):e==="disabled"?o.setAttribute("disabled",!0):o.style.display="none"},Je={mounted(o,e,t,n){const s=e.arg??"show";let r=e.value;r||(r=o.dataset.permission??[]),u.watchEffect(()=>{const l=j(o);if(l&&l.controller){const i=l.controller.havePermission(r);f.isPromise(i)?i.then(a=>{z(o,s,a)}):z(o,s,i)}})}},Qe={install(o){o.directive("submit",qe),o.directive("exit",ze),o.directive("permission",Je)}};function ye(o,e){Q.set(o,e)}const Xe={install(o,e={}){if(e.pretreatLocker&&le(e.pretreatLocker),e.customSubmitFlowHooks&&se(e.customSubmitFlowHooks),e.customCancelSubmitFlowHooks&&re(e.customCancelSubmitFlowHooks),e.systemFlows)for(let t in e.systemFlows){let n=e.systemFlows[t];ye(t,n)}Qe.install(o)}};exports.BaseFlow=Re;exports.DefaultKey=y;exports.FoxController=ae;exports.TAG=K;exports.createEventProxyName=oe;exports.default=Xe;exports.defineFoxController=Ie;exports.defineFoxData=Ne;exports.defineFoxMixinData=$e;exports.execBroadcast=Y;exports.execClearValidate=ee;exports.execSetDomainProperty=Ae;exports.execSetNameValidateRules=te;exports.execValidate=Z;exports.setCustomCancelSubmitFlowHooks=re;exports.setCustomSubmitFlowHooks=se;exports.setFoxSystemFlow=ye;exports.setPretreatLocker=le;exports.useFoxContext=j;exports.useFoxController=We;exports.useFoxSyncData=Ge; | ||
* @fox-js/flow v4.0.1-34 Tue Sep 24 2024 22:39:26 GMT+0800 (中国标准时间) | ||
*/Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("vue"),f=require("@fox-js/fox");function de(o){return Object.prototype.toString.call(o)==="[object RegExp]"}const D=Symbol.for("BroadcastKey");class he{parent;children=[];callbacks=new Map;proxy=null;name;constructor(e,t,n){this.parent=e,this.proxy=t,this.name=n,e!==null&&e.addChild(this)}addChild(e){this.children.push(e)}removeChild(e){const t=this.children.findIndex(n=>e===n);t!==-1&&this.children.splice(t,1)}destroy(){this.parent!==null&&this.parent.removeChild(this),this.parent=null,this.proxy=null}emit(e,t,...n){if(e.maxLevel!==void 0&&e.maxLevel!==null&&e.maxLevel>0){if(e.level=e.level??0,e.level>e.maxLevel)return[];e.level++}let s=!1;!e.name||e.name==="*"?s=!0:!e.name||e.name==="+"?(s=!1,e.name="*"):de(e.name)&&this.name&&e.name.test(this.name)?s=!0:typeof e.name=="function"?s=Reflect.apply(e.name,null,[this.name]):e.name===this.name&&(s=!0);const r=[];if(s){const l=this.callbacks.get(t);if(typeof l=="function"){const a=Reflect.apply(l,this.proxy,[...n]);a!=null&&r.push(a)}const i=this.proxy??{};if(typeof i[t]=="function"){const a=Reflect.apply(i[t],i,[...n]);a!=null&&r.push(a)}}return this.children.forEach(l=>{const i=Reflect.apply(l.emit,l,[{...e},t,...n]);i!=null&&Array.isArray(i)&&Reflect.apply([].push,r,[...i])}),r}emitToChildren(e,t,...n){const s=[];return this.children.forEach(r=>{const l=Reflect.apply(r.emit,r,[{...e},t,...n]);l!=null&&Array.isArray(l)&&Reflect.apply([].push,s,[...l])}),s}on(e,t){this.callbacks.set(e,t)}}function pe(o,e,t,n){return new he(e,o,t)}const y="",J=new Map;function me(o,e=y){J.set(e,o)}function xe(o=y){return J.get(o)??null}const C=new WeakMap;function be(o,e,t=y){let n=C.get(o);n||(n=new Map,C.set(o,n)),n.set(t,e)}function ve(o){const e=[],t=C.get(o);return t&&t.forEach((n,s)=>{e.push(n)}),e}function we(o,e=y){const t=C.get(o);return t?t.get(e)??null:null}function ge(o,e=y){const t=C.get(o);return t?t.has(e):!1}function Fe(o){C.delete(o)}const Q=new Map,N=new WeakMap,v=o=>{let e=N.get(o);if(!e){const t=u.inject(D,null);e=pe(o,t),N.set(o,e);const n=o;n[D]=e,u.provide(D,e)}return e},Se=o=>{const e=o;e[D]=null,N.delete(o),u.provide(D,null)},ke=Symbol.for("SyncDataKey");function X(o){const e=f.useRoute(o);return e&&e.params?e.params[ke]??{}:{}}const K="FoxFlow";class Ce{data={}}const I=Symbol("nameKey"),W=Symbol("allDataListKey"),E=Symbol("dataListKey"),O=Symbol("proxyKey");class Re{[I]=y;[W]=[];[E]=[];[O]=null;get name(){return this[I]}get originalData(){const e=this[E];return e.length>0?e[0].original:{}}get data(){const e=this[E];return e.length>0?e[0].last:{}}get allDataList(){return this[W]}get dataList(){return this[E]}get proxy(){return this[O]}get route(){return f.useRoute(this.proxy??void 0)}}function Ee(o,e){const t=Q.get(e);if(t){let n=o;const s=new t;n.__proto__=s}return o}function De(o,e,t){const n=ve(e);let s=[];!t||t===y?s=[]:Array.isArray(t)?s=t:s=[String(t??"")];const r=[];n.forEach(l=>{const i=String(l.name??"");(s.length===0||s.includes(i))&&r.push(l)}),o[W]=n,o[E]=r,o[O]=e,o[I]=t??y}function Y(o,e,t,...n){const s=v(o);return Reflect.apply(s.emit,s,[e,t,...n])}function Z(o,e=!0,t){const n=v(o);let s=null;if(!t||t===y)t=void 0,s={maxLevel:1,level:1};else if(Array.isArray(t)){const l=t;s={name:i=>l.includes(i)}}else s={name:String(t)};const r=n.emitToChildren(s,"validate",e);return r.length==1?r[0]:r.length>1?Promise.all(r).then(l=>{let i=[];return l.forEach(a=>{a.pass===!1&&Array.isArray(a.errors)&&(i=[...i,...a.errors])}),i.length>0?{pass:!1,errors:i}:{pass:!0}}):Promise.resolve({pass:!0})}function ee(o,e=!0,t){const n=v(o);let s=null;if(!t||t===y)t=void 0,s={maxLevel:1,level:1};else if(Array.isArray(t)){const r=t;s={name:l=>r.includes(l)}}else s={name:String(t)};n.emitToChildren(s,"clearValidate",e)}function te(o,e,t=!0){const n=v(o),s={maxLevel:1,level:1};n.emitToChildren(s,"setNameValidateRules",e,t)}const oe=o=>`_fox_ctrl_${o.path??o.name??""}_${o.root??"default"}`;function Ke(o,e,t){if(o==null||typeof o!="object")return;let n=o;const s=e.split(".");for(let r=0;r<s.length&&Reflect.has(n,s[r]);r++){if(r===s.length-1){n[s[r]]=t;return}if(n=n[s[r]],n==null||typeof n!="object")break}}function Ae(o,e,t,n){const s=v(o);let r=null;if(!n||n===y)n=void 0,r={maxLevel:1,level:1};else if(Array.isArray(n)){const l=n;r={name:i=>l.includes(i)}}else r={name:String(n)};s.emitToChildren(r,"setDomainProperty",e,t)}function Le(o,e,t,n){const s=v(o);let r=null;if(!n||n===y)n=void 0,r={maxLevel:1,level:1};else if(Array.isArray(n)){const l=n;r={name:i=>l.includes(i)}}else r={name:String(n)};s.emitToChildren(r,e,...t)}const Pe=["beforeBack","back"],G="getShareBus",q="havePermission",Me=["beforeExit","exit"],Ve=["setCheckConditions","check"],He="cancelSubmit",je="endSubmit";let ne=["preSubmit","commit","submit","postSubmit"],M=[];function se(o){ne=[...o]}function re(o){M=[...o]}let V=null;function le(o){V=o}const Be="foxOpenType";let Te=o=>{const e=f.useRoute(o);return e&&e.params?e.params[Be]??"normal":"normal"};const w=Symbol("eventChainKey"),g=Symbol("sessionKey"),h=Symbol("proxyKey"),L=Symbol("userFlowKey"),F=Symbol("flowKey"),S=Symbol("stateKey"),B=Symbol("flowNameKey"),P=Symbol("allowResubmit"),k=Symbol("_getFlowEventChain"),m=Symbol("_getFlow"),T=Symbol("_reset"),ie=Symbol("_destroy"),d=Symbol("_execHook");function _e(o){return o==null?!1:o===!1?!0:typeof o=="object"&&Reflect.has(o,"pass")?!o.pass:!1}const R=function(o,e){return(n,...s)=>{try{const r=Reflect.apply(o,e,[n,...s]);f.isPromise(r)&&r.then(l=>{_e(l)?n.reject(l):n.resolve(l)}).catch(l=>{n.reject(l)})}catch(r){console.error(`[${K}] exec hook error`,r),n.reject(r)}}};class ae{[w]=null;[g]=new Ce;[h];[L];[F]=null;[S]="none";[B]="";[P]=!1;constructor(e,t){this[L]=e,this[h]=t}[k](e=!1){return e?new f.EventChain(this[g],!0):this[w]?this[w]:(this[w]=new f.EventChain(this[g],!0),this[w])}[m](e){if(!this[F]){const t=Te(this[h]);this[F]=Ee(this[L],t)}return De(this[F],this[h],e),this[F]}[T](){this[w]=null,this[S]="none"}[d](e,t){const n=this[m](t);if(Array.isArray(e)){const s=this[k](!0);e.forEach(r=>{const l=n[r];if(typeof l=="function"){const i=R(l,n);s?.post(i)}})}else{const s=n[e];if(typeof s=="function")return Reflect.apply(s,n,[this[g]])}}pretreat(e){return this[S]==="submit"?(console.warn(`[${K}]流程已经处于提交状态,无法加入预处理任务`),!1):(this[k]()?.post(e),this[S]="pretreat",!0)}[ie](){const e=this;e[w]=null,e[g]=null,e[h]=null,e[L]=null,e[F]=null}get name(){return this[B]??""}get proxy(){return this[h]}set allowResubmit(e){this[P]=e}get allowResubmit(){return this[P]}submit(e,t){if(typeof e=="string"&&(t=e,e=void 0),this[B]=t??"",!this[P]&&this[S]==="submit")return console.warn(`[${K}]流程已经处于提交状态,无法重复提交`),!1;e&&typeof e=="object"&&Object.assign(this[g].data,e);const n=this[k]();if(this[S]==="pretreat"&&V){try{V.lock()}catch{}n?.post(r=>{V?.unlock(),r.resolve()})}const s=this[m](t);Ve.forEach(r=>{const l=s[r];typeof l=="function"&&n?.post(R(l,s))}),ne.forEach(r=>{const l=s[r];typeof l=="function"&&n?.post(R(l,s))}),n?.wait((r,...l)=>{this[T]();const i=s[je];typeof i=="function"&&Reflect.apply(i,s,[r,...l])},(r,...l)=>{this[T]();const i=()=>{const a=s[He];typeof a=="function"&&Reflect.apply(a,s,[r,...l])};if(Array.isArray(M)&&M.length>0){const a=this[k](!0);M.forEach(c=>{const b=s[c];typeof b=="function"&&a?.post(R(b,s))}),a?.wait(()=>i,()=>i)}else i()})}exit(e){return new Promise((t,n)=>{const s=this[k](!0),r=this[m](e);Me.forEach(l=>{const i=r[l];typeof i=="function"&&s?.post(R(i,r))}),s?.wait((l,...i)=>{t(!0)},(l,...i)=>{t(!0)})})}back(e){return this[d](Pe,e),!0}exec(e,t){return this[d](e,t)}getShareBus(e){const t=this[m](e);return typeof t[G]=="function"?Reflect.apply(t[G],t,[]):null}havePermission(e){const t=this[m]();return typeof t[q]=="function"?Reflect.apply(t[q],t,[e]):!0}setValue(e,t,n){const s=this[m](n??"");if(Array.isArray(s.allDataList)){for(let r of s.allDataList)if(r.name===n){Ke(r.last,e,t),r.last[e]=t;break}}}getValue(e,t){let n=null;const s=this[m](t??"");if(Array.isArray(s.allDataList)){for(let r of s.allDataList)if(r.name===t){n=r.last[e];break}}return n}get allDataList(){return this[m]().allDataList}get dataList(){return this[m]().dataList}getDataRecordByFieldName(e){return this.allDataList.find(s=>Reflect.ownKeys(s.last).includes(e))??null}broadcast(e,t,...n){return Reflect.apply(Y,null,[this[h],e,t,...n])}resetFields(e,t){let n=[];Array.isArray(t)?n=t:typeof t=="string"?n=[t]:n=[y];const s=this[h];n.forEach(r=>{const l=we(s,r)??{original:{},last:{}},i={};if(f.extend(!0,i,l.original),Array.isArray(e))e.forEach(a=>{l.last[a]=i[a]});else if(e&&Array.isArray(e.include))(e.include??[]).forEach(c=>{l.last[c]=i[c]});else if(e&&Array.isArray(e.exclude)){let a=e.exclude??[];Reflect.ownKeys(i).forEach(c=>{typeof c=="string"&&(a.includes(c)||(l.last[c]=i[c]))})}else Object.assign(l.last,i)}),this.clearValidate(e,t)}validate(e=!0,t){return Z(this[h],e,t)}clearValidate(e=!0,t){return ee(this[h],e,t)}setNameValidateRules(e,t=!0){return te(this[h],e,t)}}const ce=Symbol.for("FoxControllerKey"),$e=Symbol.for("PageWrapperKey"),H=new WeakMap;let x=[];function Ne(o,e){const t=u.toRaw(o);me(t,e)}function Ie(o,e,t){let n=t,s,r;const l={};if(typeof e=="string"?s=e:e&&typeof e=="object"&&(s=e.name,r=e.mixin,Object.assign(l,e)),!n){const p=u.getCurrentInstance();if(p===null)throw new Error("defineData must in setup hook");if(p.proxy==null)throw new Error("proxy is null");n=p.proxy}if(ge(n,s))throw new Error("duplicate definitions are not allowed, please Set different name!");const i=u.isReactive(o)?u.toRaw(o):o,a=xe(r);a&&f.extend(!0,i,a);const c=X(n);if(!s)f.extend(!0,i,c);else{const p=c[s];p&&typeof p=="object"&&f.extend(!0,i,p)}const b={};f.extend(!0,b,i);const A=u.reactive(i);if(be(n,{name:s??y,metadata:l,original:b,last:A},s),n){const p=v(n),U=()=>{s?p?.emitToChildren({name:s},"setModelValue",A):p?.emitToChildren({maxLevel:1,level:1},"setModelValue",A)};n.$.isMounted?U():u.onMounted(U)}return A}function We(o={},e){if(!e){const a=u.getCurrentInstance();if(a===null)throw new Error("defineData must in setup hook");if(a.proxy===null)throw new Error("proxy is null");e=a.proxy}v(e);const t=new ae(o,e);H.set(e,t),f.provideContextValue(e,ce,t),x.push({proxy:e,controller:t,state:"create"});const n=f.useEventProxy(e);let s=null,r=null;const l=f.useRoute(e);l&&l.path&&l.root&&(r=oe(l),s=(a,c)=>{a==="exit"?t.exit(c):a==="submit"?t.submit(c):a==="execHook"&&typeof c=="string"&&t[d](c)},n.on(r,s)),u.onBeforeMount(()=>{t[d]("beforeMount")}),u.onMounted(()=>{const a=e;a&&Ue(a,"mounted"),t[d](["mounted","endMounted"])}),u.onBeforeUnmount(()=>{t[d]("beforeUnmount")}),u.onUnmounted(()=>{t[d]("unmounted"),t[ie]();const a=e;a&&(Ge(a),Se(a),H.delete(a),Fe(a)),r&&s&&n.off(r,s)}),f.onFoxActivated(()=>{t[d]("activated")}),f.onFoxInactivated(()=>{t[d]("inactivated")});const i=u.inject($e,null);i&&typeof i.beforeClose!="function"&&(i.used||(i.used=!0,i.beforeClose=async a=>{const c=e;if(c){const b=H.get(c);b?await b.exit():r&&n.emit(r,"exit")}typeof a=="function"&&a()},i.onShow=()=>{t[d]("activated")},i.onHide=()=>{t[d]("inactivated")}));try{t[d]("created")}catch(a){console.error(`[${K}] created error`,a)}return t}function Oe(o){let e=null;return o&&(e=H.get(o)??null),e||(o||(o=u.getCurrentInstance()?.proxy??void 0),o&&(e=f.injectContextValue(o,ce))),e}function Ue(o,e){for(let t=x.length-1;t>=0;t--){const n=x[t];if(n.proxy===o){n.state=e;break}}}function Ge(o){const e=x.findIndex(t=>t.proxy===o);e!==-1&&x.splice(e,1)}function j(o){if(!o){const e=x.length-1;if(e>=0){const t=x[e];if(t.state==="create")return t}return null}for(let e=x.length-1;e>=0;e--){const t=x[e];if(t.proxy&&t.proxy.$el){const n=t.proxy.$el;if(n===o||n.contains(o))return t}}return null}function qe(o){if(!o){const e=u.getCurrentInstance();if(e===null)throw new Error("getSyncData must in setup hook");if(e.proxy===null)throw new Error("proxy is null");o=e.proxy}return X(o)}const ue=o=>{let{key:e,shiftKey:t,altKey:n,ctrlKey:s}=o,r=[];return t&&r.push("Shift"),n&&r.push("Alt"),s&&r.push("Ctrl"),r.push(e),r.join("+").toLocaleUpperCase()},fe=(o,e="Enter")=>{let t=[o.arg??e];return o.modifiers.Shift?t.splice(0,0,"Shift"):o.modifiers.Alt?t.splice(0,0,"Alt"):o.modifiers.Ctrl&&t.splice(0,0,"Ctrl"),t.join("+").toLocaleUpperCase()},_=new WeakMap,ze={mounted(o,e,t,n){const s=fe(e,"ENTER"),r=j(o),l=e.value??{},i=a=>{const c=ue(a);r&&r.controller&&c===s&&r.controller.submit(l)};o.addEventListener("keyup",i),_.set(o,i)},beforeUnmount(o,e,t,n){const s=_.get(o);_.delete(o),s&&o.removeEventListener("keyup",s)}},$=new WeakMap,Je={mounted(o,e,t,n){const s=fe(e,"ESCAPE"),r=j(o),l=e.value??{},i=a=>{const c=ue(a);r&&r.controller&&c===s&&r.controller.exit(l)};o.addEventListener("keyup",i),$.set(o,i)},beforeUnmount(o,e,t,n){const s=$.get(o);$.delete(o),s&&o.removeEventListener("keyup",s)}},z=(o,e,t)=>{t?e==="disabled"&&o.hasAttribute("disabled")?o.removeAttribute("disbaled"):o.style.display==="none"&&(o.style.display="block"):e==="disabled"?o.setAttribute("disabled",!0):o.style.display="none"},Qe={mounted(o,e,t,n){const s=e.arg??"show";let r=e.value;r||(r=o.dataset.permission??[]),u.watchEffect(()=>{const l=j(o);if(l&&l.controller){const i=l.controller.havePermission(r);f.isPromise(i)?i.then(a=>{z(o,s,a)}):z(o,s,i)}})}},Xe={install(o){o.directive("submit",ze),o.directive("exit",Je),o.directive("permission",Qe)}};function ye(o,e){Q.set(o,e)}const Ye={install(o,e={}){if(e.pretreatLocker&&le(e.pretreatLocker),e.customSubmitFlowHooks&&se(e.customSubmitFlowHooks),e.customCancelSubmitFlowHooks&&re(e.customCancelSubmitFlowHooks),e.systemFlows)for(let t in e.systemFlows){let n=e.systemFlows[t];ye(t,n)}Xe.install(o)}};exports.BaseFlow=Re;exports.DefaultKey=y;exports.FoxController=ae;exports.TAG=K;exports.createEventProxyName=oe;exports.default=Ye;exports.defineFoxController=We;exports.defineFoxData=Ie;exports.defineFoxMixinData=Ne;exports.execBroadcast=Y;exports.execCallFunc=Le;exports.execClearValidate=ee;exports.execSetDomainProperty=Ae;exports.execSetNameValidateRules=te;exports.execValidate=Z;exports.setCustomCancelSubmitFlowHooks=re;exports.setCustomSubmitFlowHooks=se;exports.setFoxSystemFlow=ye;exports.setPretreatLocker=le;exports.useFoxContext=j;exports.useFoxController=Oe;exports.useFoxSyncData=qe; |
@@ -148,2 +148,11 @@ import { App } from 'vue'; | ||
/** | ||
* 执行item组件组件的方法 | ||
* @param contextProxy | ||
* @param methodName | ||
* @param args | ||
* @param name | ||
*/ | ||
export declare function execCallFunc(contextProxy: ComponentPublicInstance, methodName: string, args: any[], name?: string | string[]): void; | ||
/** | ||
* 执行清理校验信息 | ||
@@ -162,5 +171,5 @@ * @param contextProxy | ||
* @param contextProxy | ||
* @param condition | ||
* @param key | ||
* @param value | ||
* @param name | ||
* @returns | ||
*/ | ||
@@ -167,0 +176,0 @@ export declare function execSetDomainProperty(contextProxy: ComponentPublicInstance, key: string, value: any, name?: string | string[]): void; |
import { inject as X, provide as Y, toRaw as Z, getCurrentInstance as V, isReactive as ue, reactive as fe, onMounted as ee, onBeforeMount as ye, onBeforeUnmount as de, onUnmounted as he, watchEffect as pe } from "vue"; | ||
import { useRoute as j, EventChain as q, extend as C, isPromise as te, provideContextValue as me, useEventProxy as be, onFoxActivated as xe, onFoxInactivated as we, injectContextValue as ve } from "@fox-js/fox"; | ||
import { useRoute as j, EventChain as q, extend as C, isPromise as te, provideContextValue as me, useEventProxy as be, onFoxActivated as xe, onFoxInactivated as ve, injectContextValue as we } from "@fox-js/fox"; | ||
/*! | ||
* @fox-js/flow v4.0.1-33 Tue Sep 24 2024 17:17:13 GMT+0800 (中国标准时间) | ||
* @fox-js/flow v4.0.1-34 Tue Sep 24 2024 22:39:26 GMT+0800 (中国标准时间) | ||
*/ | ||
@@ -119,11 +119,11 @@ function ge(o) { | ||
} | ||
const f = "", oe = /* @__PURE__ */ new Map(); | ||
function Fe(o, e = f) { | ||
const u = "", oe = /* @__PURE__ */ new Map(); | ||
function Fe(o, e = u) { | ||
oe.set(e, o); | ||
} | ||
function Ce(o = f) { | ||
function Ce(o = u) { | ||
return oe.get(o) ?? null; | ||
} | ||
const S = /* @__PURE__ */ new WeakMap(); | ||
function Re(o, e, t = f) { | ||
function Re(o, e, t = u) { | ||
let n = S.get(o); | ||
@@ -138,7 +138,7 @@ n || (n = /* @__PURE__ */ new Map(), S.set(o, n)), n.set(t, e); | ||
} | ||
function Ke(o, e = f) { | ||
function Ke(o, e = u) { | ||
const t = S.get(o); | ||
return t ? t.get(e) ?? null : null; | ||
} | ||
function De(o, e = f) { | ||
function De(o, e = u) { | ||
const t = S.get(o); | ||
@@ -150,3 +150,3 @@ return t ? t.has(e) : !1; | ||
} | ||
const ne = /* @__PURE__ */ new Map(), W = /* @__PURE__ */ new WeakMap(), x = (o) => { | ||
const ne = /* @__PURE__ */ new Map(), W = /* @__PURE__ */ new WeakMap(), b = (o) => { | ||
let e = W.get(o); | ||
@@ -180,3 +180,3 @@ if (!e) { | ||
*/ | ||
[N] = f; | ||
[N] = u; | ||
/** | ||
@@ -251,3 +251,3 @@ * all data list | ||
let s = []; | ||
!t || t === f ? s = [] : Array.isArray(t) ? s = t : s = [String(t ?? "")]; | ||
!t || t === u ? s = [] : Array.isArray(t) ? s = t : s = [String(t ?? "")]; | ||
const r = []; | ||
@@ -257,12 +257,12 @@ n.forEach((l) => { | ||
(s.length === 0 || s.includes(i)) && r.push(l); | ||
}), o[U] = n, o[R] = r, o[O] = e, o[N] = t ?? f; | ||
}), o[U] = n, o[R] = r, o[O] = e, o[N] = t ?? u; | ||
} | ||
function je(o, e, t, ...n) { | ||
const s = x(o); | ||
const s = b(o); | ||
return Reflect.apply(s.emit, s, [e, t, ...n]); | ||
} | ||
function Be(o, e = !0, t) { | ||
const n = x(o); | ||
const n = b(o); | ||
let s = null; | ||
if (!t || t === f) | ||
if (!t || t === u) | ||
t = void 0, s = { | ||
@@ -294,6 +294,6 @@ maxLevel: 1, | ||
} | ||
function _e(o, e = !0, t) { | ||
const n = x(o); | ||
function Te(o, e = !0, t) { | ||
const n = b(o); | ||
let s = null; | ||
if (!t || t === f) | ||
if (!t || t === u) | ||
t = void 0, s = { | ||
@@ -312,4 +312,4 @@ maxLevel: 1, | ||
} | ||
function Te(o, e, t = !0) { | ||
const n = x(o), s = { | ||
function _e(o, e, t = !0) { | ||
const n = b(o), s = { | ||
maxLevel: 1, | ||
@@ -336,5 +336,5 @@ level: 1 | ||
function ft(o, e, t, n) { | ||
const s = x(o); | ||
const s = b(o); | ||
let r = null; | ||
if (!n || n === f) | ||
if (!n || n === u) | ||
n = void 0, r = { | ||
@@ -353,2 +353,19 @@ maxLevel: 1, | ||
} | ||
function yt(o, e, t, n) { | ||
const s = b(o); | ||
let r = null; | ||
if (!n || n === u) | ||
n = void 0, r = { | ||
maxLevel: 1, | ||
level: 1 | ||
}; | ||
else if (Array.isArray(n)) { | ||
const l = n; | ||
r = { | ||
name: (i) => l.includes(i) | ||
}; | ||
} else | ||
r = { name: String(n) }; | ||
s.emitToChildren(r, e, ...t); | ||
} | ||
const Ne = ["beforeBack", "back"], z = "getShareBus", J = "havePermission", Ue = ["beforeExit", "exit"], Oe = ["setCheckConditions", "check"], Ie = "cancelSubmit", Ge = "endSubmit"; | ||
@@ -371,3 +388,3 @@ let re = ["preSubmit", "commit", "submit", "postSubmit"], L = []; | ||
}; | ||
const b = Symbol("eventChainKey"), w = Symbol("sessionKey"), y = Symbol("proxyKey"), D = Symbol("userFlowKey"), v = Symbol("flowKey"), g = Symbol("stateKey"), B = Symbol("flowNameKey"), A = Symbol("allowResubmit"), k = Symbol("_getFlowEventChain"), h = Symbol("_getFlow"), _ = Symbol("_reset"), le = Symbol("_destroy"), u = Symbol("_execHook"); | ||
const x = Symbol("eventChainKey"), v = Symbol("sessionKey"), y = Symbol("proxyKey"), D = Symbol("userFlowKey"), w = Symbol("flowKey"), g = Symbol("stateKey"), B = Symbol("flowNameKey"), A = Symbol("allowResubmit"), k = Symbol("_getFlowEventChain"), h = Symbol("_getFlow"), T = Symbol("_reset"), le = Symbol("_destroy"), f = Symbol("_execHook"); | ||
function Ye(o) { | ||
@@ -394,7 +411,7 @@ return o == null ? !1 : o === !1 ? !0 : typeof o == "object" && Reflect.has(o, "pass") ? !o.pass : !1; | ||
*/ | ||
[b] = null; | ||
[x] = null; | ||
/** | ||
* session属性 | ||
*/ | ||
[w] = new Me(); | ||
[v] = new Me(); | ||
/** | ||
@@ -411,3 +428,3 @@ * proxy属性 | ||
*/ | ||
[v] = null; | ||
[w] = null; | ||
/** | ||
@@ -439,3 +456,3 @@ * 流程状态 | ||
[k](e = !1) { | ||
return e ? new q(this[w], !0) : this[b] ? this[b] : (this[b] = new q(this[w], !0), this[b]); | ||
return e ? new q(this[v], !0) : this[x] ? this[x] : (this[x] = new q(this[v], !0), this[x]); | ||
} | ||
@@ -448,7 +465,7 @@ /** | ||
[h](e) { | ||
if (!this[v]) { | ||
if (!this[w]) { | ||
const t = Xe(this[y]); | ||
this[v] = He(this[D], t); | ||
this[w] = He(this[D], t); | ||
} | ||
return Ve(this[v], this[y], e), this[v]; | ||
return Ve(this[w], this[y], e), this[w]; | ||
} | ||
@@ -458,4 +475,4 @@ /** | ||
*/ | ||
[_]() { | ||
this[b] = null, this[g] = "none"; | ||
[T]() { | ||
this[x] = null, this[g] = "none"; | ||
} | ||
@@ -468,3 +485,3 @@ /** | ||
*/ | ||
[u](e, t) { | ||
[f](e, t) { | ||
const n = this[h](t); | ||
@@ -483,3 +500,3 @@ if (Array.isArray(e)) { | ||
if (typeof s == "function") | ||
return Reflect.apply(s, n, [this[w]]); | ||
return Reflect.apply(s, n, [this[v]]); | ||
} | ||
@@ -500,3 +517,3 @@ } | ||
const e = this; | ||
e[b] = null, e[w] = null, e[y] = null, e[D] = null, e[v] = null; | ||
e[x] = null, e[v] = null, e[y] = null, e[D] = null, e[w] = null; | ||
} | ||
@@ -536,3 +553,3 @@ /** | ||
return console.warn(`[${H}]流程已经处于提交状态,无法重复提交`), !1; | ||
e && typeof e == "object" && Object.assign(this[w].data, e); | ||
e && typeof e == "object" && Object.assign(this[v].data, e); | ||
const n = this[k](); | ||
@@ -557,3 +574,3 @@ if (this[g] === "pretreat" && P) { | ||
(r, ...l) => { | ||
this[_](); | ||
this[T](); | ||
const i = s[Ge]; | ||
@@ -563,3 +580,3 @@ typeof i == "function" && Reflect.apply(i, s, [r, ...l]); | ||
(r, ...l) => { | ||
this[_](); | ||
this[T](); | ||
const i = () => { | ||
@@ -608,3 +625,3 @@ const a = s[Ie]; | ||
back(e) { | ||
return this[u](Ne, e), !0; | ||
return this[f](Ne, e), !0; | ||
} | ||
@@ -617,3 +634,3 @@ /** | ||
exec(e, t) { | ||
return this[u](e, t); | ||
return this[f](e, t); | ||
} | ||
@@ -707,3 +724,3 @@ /** | ||
let n = []; | ||
Array.isArray(t) ? n = t : typeof t == "string" ? n = [t] : n = [f]; | ||
Array.isArray(t) ? n = t : typeof t == "string" ? n = [t] : n = [u]; | ||
const s = this[y]; | ||
@@ -744,3 +761,3 @@ n.forEach((r) => { | ||
clearValidate(e = !0, t) { | ||
return _e(this[y], e, t); | ||
return Te(this[y], e, t); | ||
} | ||
@@ -753,3 +770,3 @@ /** | ||
setNameValidateRules(e, t = !0) { | ||
return Te(this[y], e, t); | ||
return _e(this[y], e, t); | ||
} | ||
@@ -759,7 +776,7 @@ } | ||
let p = []; | ||
function yt(o, e) { | ||
function dt(o, e) { | ||
const t = Z(o); | ||
Fe(t, e); | ||
} | ||
function dt(o, e, t) { | ||
function ht(o, e, t) { | ||
let n = t, s, r; | ||
@@ -792,3 +809,3 @@ const l = {}; | ||
{ | ||
name: s ?? f, | ||
name: s ?? u, | ||
metadata: l, | ||
@@ -800,3 +817,3 @@ original: m, | ||
), n) { | ||
const d = x(n), G = () => { | ||
const d = b(n), G = () => { | ||
s ? d?.emitToChildren({ name: s }, "setModelValue", K) : d?.emitToChildren({ maxLevel: 1, level: 1 }, "setModelValue", K); | ||
@@ -808,3 +825,3 @@ }; | ||
} | ||
function ht(o = {}, e) { | ||
function pt(o = {}, e) { | ||
if (!e) { | ||
@@ -818,3 +835,3 @@ const a = V(); | ||
} | ||
x(e); | ||
b(e); | ||
const t = new Ze(o, e); | ||
@@ -830,18 +847,18 @@ M.set(e, t), me(e, ie, t), p.push({ | ||
l && l.path && l.root && (r = $e(l), s = (a, c) => { | ||
a === "exit" ? t.exit(c) : a === "submit" ? t.submit(c) : a === "execHook" && typeof c == "string" && t[u](c); | ||
a === "exit" ? t.exit(c) : a === "submit" ? t.submit(c) : a === "execHook" && typeof c == "string" && t[f](c); | ||
}, n.on(r, s)), ye(() => { | ||
t[u]("beforeMount"); | ||
t[f]("beforeMount"); | ||
}), ee(() => { | ||
const a = e; | ||
a && tt(a, "mounted"), t[u](["mounted", "endMounted"]); | ||
a && tt(a, "mounted"), t[f](["mounted", "endMounted"]); | ||
}), de(() => { | ||
t[u]("beforeUnmount"); | ||
t[f]("beforeUnmount"); | ||
}), he(() => { | ||
t[u]("unmounted"), t[le](); | ||
t[f]("unmounted"), t[le](); | ||
const a = e; | ||
a && (ot(a), Le(a), M.delete(a), Ae(a)), r && s && n.off(r, s); | ||
}), xe(() => { | ||
t[u]("activated"); | ||
}), we(() => { | ||
t[u]("inactivated"); | ||
t[f]("activated"); | ||
}), ve(() => { | ||
t[f]("inactivated"); | ||
}); | ||
@@ -857,8 +874,8 @@ const i = X(et, null); | ||
}, i.onShow = () => { | ||
t[u]("activated"); | ||
t[f]("activated"); | ||
}, i.onHide = () => { | ||
t[u]("inactivated"); | ||
t[f]("inactivated"); | ||
})); | ||
try { | ||
t[u]("created"); | ||
t[f]("created"); | ||
} catch (a) { | ||
@@ -869,5 +886,5 @@ console.error(`[${H}] created error`, a); | ||
} | ||
function pt(o) { | ||
function mt(o) { | ||
let e = null; | ||
return o && (e = M.get(o) ?? null), e || (o || (o = V()?.proxy ?? void 0), o && (e = ve(o, ie))), e; | ||
return o && (e = M.get(o) ?? null), e || (o || (o = V()?.proxy ?? void 0), o && (e = we(o, ie))), e; | ||
} | ||
@@ -907,3 +924,3 @@ function tt(o, e) { | ||
} | ||
function mt(o) { | ||
function bt(o) { | ||
if (!o) { | ||
@@ -925,3 +942,3 @@ const e = V(); | ||
return o.modifiers.Shift ? t.splice(0, 0, "Shift") : o.modifiers.Alt ? t.splice(0, 0, "Alt") : o.modifiers.Ctrl && t.splice(0, 0, "Ctrl"), t.join("+").toLocaleUpperCase(); | ||
}, T = /* @__PURE__ */ new WeakMap(), nt = { | ||
}, _ = /* @__PURE__ */ new WeakMap(), nt = { | ||
// 在绑定元素的父组件 | ||
@@ -934,8 +951,8 @@ // 及他自己的所有子节点都挂载完成后调用 | ||
}; | ||
o.addEventListener("keyup", i), T.set(o, i); | ||
o.addEventListener("keyup", i), _.set(o, i); | ||
}, | ||
// 绑定元素的父组件卸载后调用 | ||
beforeUnmount(o, e, t, n) { | ||
const s = T.get(o); | ||
T.delete(o), s && o.removeEventListener("keyup", s); | ||
const s = _.get(o); | ||
_.delete(o), s && o.removeEventListener("keyup", s); | ||
} | ||
@@ -987,3 +1004,3 @@ }, $ = /* @__PURE__ */ new WeakMap(), st = { | ||
} | ||
const bt = { | ||
const xt = { | ||
/** | ||
@@ -1005,14 +1022,15 @@ * 安装 | ||
ut as BaseFlow, | ||
f as DefaultKey, | ||
u as DefaultKey, | ||
Ze as FoxController, | ||
H as TAG, | ||
$e as createEventProxyName, | ||
bt as default, | ||
ht as defineFoxController, | ||
dt as defineFoxData, | ||
yt as defineFoxMixinData, | ||
xt as default, | ||
pt as defineFoxController, | ||
ht as defineFoxData, | ||
dt as defineFoxMixinData, | ||
je as execBroadcast, | ||
_e as execClearValidate, | ||
yt as execCallFunc, | ||
Te as execClearValidate, | ||
ft as execSetDomainProperty, | ||
Te as execSetNameValidateRules, | ||
_e as execSetNameValidateRules, | ||
Be as execValidate, | ||
@@ -1024,4 +1042,4 @@ ze as setCustomCancelSubmitFlowHooks, | ||
I as useFoxContext, | ||
pt as useFoxController, | ||
mt as useFoxSyncData | ||
mt as useFoxController, | ||
bt as useFoxSyncData | ||
}; |
(function(c,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue"),require("@fox-js/fox")):typeof define=="function"&&define.amd?define(["exports","vue","@fox-js/fox"],f):(c=typeof globalThis<"u"?globalThis:c||self,f(c.FoxFlow={},c.Vue,c.Fox))})(this,function(c,f,y){"use strict";/*! | ||
* @fox-js/flow v4.0.1-33 Tue Sep 24 2024 17:17:13 GMT+0800 (中国标准时间) | ||
*/function he(n){return Object.prototype.toString.call(n)==="[object RegExp]"}const E=Symbol.for("BroadcastKey");class me{parent;children=[];callbacks=new Map;proxy=null;name;constructor(e,t,o){this.parent=e,this.proxy=t,this.name=o,e!==null&&e.addChild(this)}addChild(e){this.children.push(e)}removeChild(e){const t=this.children.findIndex(o=>e===o);t!==-1&&this.children.splice(t,1)}destroy(){this.parent!==null&&this.parent.removeChild(this),this.parent=null,this.proxy=null}emit(e,t,...o){if(e.maxLevel!==void 0&&e.maxLevel!==null&&e.maxLevel>0){if(e.level=e.level??0,e.level>e.maxLevel)return[];e.level++}let s=!1;!e.name||e.name==="*"?s=!0:!e.name||e.name==="+"?(s=!1,e.name="*"):he(e.name)&&this.name&&e.name.test(this.name)?s=!0:typeof e.name=="function"?s=Reflect.apply(e.name,null,[this.name]):e.name===this.name&&(s=!0);const r=[];if(s){const l=this.callbacks.get(t);if(typeof l=="function"){const a=Reflect.apply(l,this.proxy,[...o]);a!=null&&r.push(a)}const i=this.proxy??{};if(typeof i[t]=="function"){const a=Reflect.apply(i[t],i,[...o]);a!=null&&r.push(a)}}return this.children.forEach(l=>{const i=Reflect.apply(l.emit,l,[{...e},t,...o]);i!=null&&Array.isArray(i)&&Reflect.apply([].push,r,[...i])}),r}emitToChildren(e,t,...o){const s=[];return this.children.forEach(r=>{const l=Reflect.apply(r.emit,r,[{...e},t,...o]);l!=null&&Array.isArray(l)&&Reflect.apply([].push,s,[...l])}),s}on(e,t){this.callbacks.set(e,t)}}function pe(n,e,t,o){return new me(e,n,t)}const d="",G=new Map;function be(n,e=d){G.set(e,n)}function we(n=d){return G.get(n)??null}const F=new WeakMap;function xe(n,e,t=d){let o=F.get(n);o||(o=new Map,F.set(n,o)),o.set(t,e)}function ge(n){const e=[],t=F.get(n);return t&&t.forEach((o,s)=>{e.push(o)}),e}function ve(n,e=d){const t=F.get(n);return t?t.get(e)??null:null}function Fe(n,e=d){const t=F.get(n);return t?t.has(e):!1}function Se(n){F.delete(n)}const q=new Map,T=new WeakMap,g=n=>{let e=T.get(n);if(!e){const t=f.inject(E,null);e=pe(n,t),T.set(n,e);const o=n;o[E]=e,f.provide(E,e)}return e},ke=n=>{const e=n;e[E]=null,T.delete(n),f.provide(E,null)},Ce=Symbol.for("SyncDataKey");function z(n){const e=y.useRoute(n);return e&&e.params?e.params[Ce]??{}:{}}const D="FoxFlow";class Re{data={}}const _=Symbol("nameKey"),$=Symbol("allDataListKey"),K=Symbol("dataListKey"),N=Symbol("proxyKey");class Ee{[_]=d;[$]=[];[K]=[];[N]=null;get name(){return this[_]}get originalData(){const e=this[K];return e.length>0?e[0].original:{}}get data(){const e=this[K];return e.length>0?e[0].last:{}}get allDataList(){return this[$]}get dataList(){return this[K]}get proxy(){return this[N]}get route(){return y.useRoute(this.proxy??void 0)}}function De(n,e){const t=q.get(e);if(t){let o=n;const s=new t;o.__proto__=s}return n}function Ke(n,e,t){const o=ge(e);let s=[];!t||t===d?s=[]:Array.isArray(t)?s=t:s=[String(t??"")];const r=[];o.forEach(l=>{const i=String(l.name??"");(s.length===0||s.includes(i))&&r.push(l)}),n[$]=o,n[K]=r,n[N]=e,n[_]=t??d}function J(n,e,t,...o){const s=g(n);return Reflect.apply(s.emit,s,[e,t,...o])}function Q(n,e=!0,t){const o=g(n);let s=null;if(!t||t===d)t=void 0,s={maxLevel:1,level:1};else if(Array.isArray(t)){const l=t;s={name:i=>l.includes(i)}}else s={name:String(t)};const r=o.emitToChildren(s,"validate",e);return r.length==1?r[0]:r.length>1?Promise.all(r).then(l=>{let i=[];return l.forEach(a=>{a.pass===!1&&Array.isArray(a.errors)&&(i=[...i,...a.errors])}),i.length>0?{pass:!1,errors:i}:{pass:!0}}):Promise.resolve({pass:!0})}function X(n,e=!0,t){const o=g(n);let s=null;if(!t||t===d)t=void 0,s={maxLevel:1,level:1};else if(Array.isArray(t)){const r=t;s={name:l=>r.includes(l)}}else s={name:String(t)};o.emitToChildren(s,"clearValidate",e)}function Y(n,e,t=!0){const o=g(n),s={maxLevel:1,level:1};o.emitToChildren(s,"setNameValidateRules",e,t)}const Z=n=>`_fox_ctrl_${n.path??n.name??""}_${n.root??"default"}`;function Ae(n,e,t){if(n==null||typeof n!="object")return;let o=n;const s=e.split(".");for(let r=0;r<s.length&&Reflect.has(o,s[r]);r++){if(r===s.length-1){o[s[r]]=t;return}if(o=o[s[r]],o==null||typeof o!="object")break}}function Le(n,e,t,o){const s=g(n);let r=null;if(!o||o===d)o=void 0,r={maxLevel:1,level:1};else if(Array.isArray(o)){const l=o;r={name:i=>l.includes(i)}}else r={name:String(o)};s.emitToChildren(r,"setDomainProperty",e,t)}const Pe=["beforeBack","back"],ee="getShareBus",te="havePermission",Me=["beforeExit","exit"],je=["setCheckConditions","check"],Ve="cancelSubmit",He="endSubmit";let ne=["preSubmit","commit","submit","postSubmit"],L=[];function oe(n){ne=[...n]}function se(n){L=[...n]}let P=null;function re(n){P=n}const Be="foxOpenType";let Te=n=>{const e=y.useRoute(n);return e&&e.params?e.params[Be]??"normal":"normal"};const v=Symbol("eventChainKey"),S=Symbol("sessionKey"),m=Symbol("proxyKey"),M=Symbol("userFlowKey"),k=Symbol("flowKey"),C=Symbol("stateKey"),I=Symbol("flowNameKey"),j=Symbol("allowResubmit"),R=Symbol("_getFlowEventChain"),p=Symbol("_getFlow"),W=Symbol("_reset"),le=Symbol("_destroy"),h=Symbol("_execHook");function _e(n){return n==null?!1:n===!1?!0:typeof n=="object"&&Reflect.has(n,"pass")?!n.pass:!1}const A=function(n,e){return(o,...s)=>{try{const r=Reflect.apply(n,e,[o,...s]);y.isPromise(r)&&r.then(l=>{_e(l)?o.reject(l):o.resolve(l)}).catch(l=>{o.reject(l)})}catch(r){console.error(`[${D}] exec hook error`,r),o.reject(r)}}};class ie{[v]=null;[S]=new Re;[m];[M];[k]=null;[C]="none";[I]="";[j]=!1;constructor(e,t){this[M]=e,this[m]=t}[R](e=!1){return e?new y.EventChain(this[S],!0):this[v]?this[v]:(this[v]=new y.EventChain(this[S],!0),this[v])}[p](e){if(!this[k]){const t=Te(this[m]);this[k]=De(this[M],t)}return Ke(this[k],this[m],e),this[k]}[W](){this[v]=null,this[C]="none"}[h](e,t){const o=this[p](t);if(Array.isArray(e)){const s=this[R](!0);e.forEach(r=>{const l=o[r];if(typeof l=="function"){const i=A(l,o);s?.post(i)}})}else{const s=o[e];if(typeof s=="function")return Reflect.apply(s,o,[this[S]])}}pretreat(e){return this[C]==="submit"?(console.warn(`[${D}]流程已经处于提交状态,无法加入预处理任务`),!1):(this[R]()?.post(e),this[C]="pretreat",!0)}[le](){const e=this;e[v]=null,e[S]=null,e[m]=null,e[M]=null,e[k]=null}get name(){return this[I]??""}get proxy(){return this[m]}set allowResubmit(e){this[j]=e}get allowResubmit(){return this[j]}submit(e,t){if(typeof e=="string"&&(t=e,e=void 0),this[I]=t??"",!this[j]&&this[C]==="submit")return console.warn(`[${D}]流程已经处于提交状态,无法重复提交`),!1;e&&typeof e=="object"&&Object.assign(this[S].data,e);const o=this[R]();if(this[C]==="pretreat"&&P){try{P.lock()}catch{}o?.post(r=>{P?.unlock(),r.resolve()})}const s=this[p](t);je.forEach(r=>{const l=s[r];typeof l=="function"&&o?.post(A(l,s))}),ne.forEach(r=>{const l=s[r];typeof l=="function"&&o?.post(A(l,s))}),o?.wait((r,...l)=>{this[W]();const i=s[He];typeof i=="function"&&Reflect.apply(i,s,[r,...l])},(r,...l)=>{this[W]();const i=()=>{const a=s[Ve];typeof a=="function"&&Reflect.apply(a,s,[r,...l])};if(Array.isArray(L)&&L.length>0){const a=this[R](!0);L.forEach(u=>{const x=s[u];typeof x=="function"&&a?.post(A(x,s))}),a?.wait(()=>i,()=>i)}else i()})}exit(e){return new Promise((t,o)=>{const s=this[R](!0),r=this[p](e);Me.forEach(l=>{const i=r[l];typeof i=="function"&&s?.post(A(i,r))}),s?.wait((l,...i)=>{t(!0)},(l,...i)=>{t(!0)})})}back(e){return this[h](Pe,e),!0}exec(e,t){return this[h](e,t)}getShareBus(e){const t=this[p](e);return typeof t[ee]=="function"?Reflect.apply(t[ee],t,[]):null}havePermission(e){const t=this[p]();return typeof t[te]=="function"?Reflect.apply(t[te],t,[e]):!0}setValue(e,t,o){const s=this[p](o??"");if(Array.isArray(s.allDataList)){for(let r of s.allDataList)if(r.name===o){Ae(r.last,e,t),r.last[e]=t;break}}}getValue(e,t){let o=null;const s=this[p](t??"");if(Array.isArray(s.allDataList)){for(let r of s.allDataList)if(r.name===t){o=r.last[e];break}}return o}get allDataList(){return this[p]().allDataList}get dataList(){return this[p]().dataList}getDataRecordByFieldName(e){return this.allDataList.find(s=>Reflect.ownKeys(s.last).includes(e))??null}broadcast(e,t,...o){return Reflect.apply(J,null,[this[m],e,t,...o])}resetFields(e,t){let o=[];Array.isArray(t)?o=t:typeof t=="string"?o=[t]:o=[d];const s=this[m];o.forEach(r=>{const l=ve(s,r)??{original:{},last:{}},i={};if(y.extend(!0,i,l.original),Array.isArray(e))e.forEach(a=>{l.last[a]=i[a]});else if(e&&Array.isArray(e.include))(e.include??[]).forEach(u=>{l.last[u]=i[u]});else if(e&&Array.isArray(e.exclude)){let a=e.exclude??[];Reflect.ownKeys(i).forEach(u=>{typeof u=="string"&&(a.includes(u)||(l.last[u]=i[u]))})}else Object.assign(l.last,i)}),this.clearValidate(e,t)}validate(e=!0,t){return Q(this[m],e,t)}clearValidate(e=!0,t){return X(this[m],e,t)}setNameValidateRules(e,t=!0){return Y(this[m],e,t)}}const ae=Symbol.for("FoxControllerKey"),$e=Symbol.for("PageWrapperKey"),V=new WeakMap;let w=[];function Ne(n,e){const t=f.toRaw(n);be(t,e)}function Ie(n,e,t){let o=t,s,r;const l={};if(typeof e=="string"?s=e:e&&typeof e=="object"&&(s=e.name,r=e.mixin,Object.assign(l,e)),!o){const b=f.getCurrentInstance();if(b===null)throw new Error("defineData must in setup hook");if(b.proxy==null)throw new Error("proxy is null");o=b.proxy}if(Fe(o,s))throw new Error("duplicate definitions are not allowed, please Set different name!");const i=f.isReactive(n)?f.toRaw(n):n,a=we(r);a&&y.extend(!0,i,a);const u=z(o);if(!s)y.extend(!0,i,u);else{const b=u[s];b&&typeof b=="object"&&y.extend(!0,i,b)}const x={};y.extend(!0,x,i);const B=f.reactive(i);if(xe(o,{name:s??d,metadata:l,original:x,last:B},s),o){const b=g(o),de=()=>{s?b?.emitToChildren({name:s},"setModelValue",B):b?.emitToChildren({maxLevel:1,level:1},"setModelValue",B)};o.$.isMounted?de():f.onMounted(de)}return B}function We(n={},e){if(!e){const a=f.getCurrentInstance();if(a===null)throw new Error("defineData must in setup hook");if(a.proxy===null)throw new Error("proxy is null");e=a.proxy}g(e);const t=new ie(n,e);V.set(e,t),y.provideContextValue(e,ae,t),w.push({proxy:e,controller:t,state:"create"});const o=y.useEventProxy(e);let s=null,r=null;const l=y.useRoute(e);l&&l.path&&l.root&&(r=Z(l),s=(a,u)=>{a==="exit"?t.exit(u):a==="submit"?t.submit(u):a==="execHook"&&typeof u=="string"&&t[h](u)},o.on(r,s)),f.onBeforeMount(()=>{t[h]("beforeMount")}),f.onMounted(()=>{const a=e;a&&Ue(a,"mounted"),t[h](["mounted","endMounted"])}),f.onBeforeUnmount(()=>{t[h]("beforeUnmount")}),f.onUnmounted(()=>{t[h]("unmounted"),t[le]();const a=e;a&&(Ge(a),ke(a),V.delete(a),Se(a)),r&&s&&o.off(r,s)}),y.onFoxActivated(()=>{t[h]("activated")}),y.onFoxInactivated(()=>{t[h]("inactivated")});const i=f.inject($e,null);i&&typeof i.beforeClose!="function"&&(i.used||(i.used=!0,i.beforeClose=async a=>{const u=e;if(u){const x=V.get(u);x?await x.exit():r&&o.emit(r,"exit")}typeof a=="function"&&a()},i.onShow=()=>{t[h]("activated")},i.onHide=()=>{t[h]("inactivated")}));try{t[h]("created")}catch(a){console.error(`[${D}] created error`,a)}return t}function Oe(n){let e=null;return n&&(e=V.get(n)??null),e||(n||(n=f.getCurrentInstance()?.proxy??void 0),n&&(e=y.injectContextValue(n,ae))),e}function Ue(n,e){for(let t=w.length-1;t>=0;t--){const o=w[t];if(o.proxy===n){o.state=e;break}}}function Ge(n){const e=w.findIndex(t=>t.proxy===n);e!==-1&&w.splice(e,1)}function H(n){if(!n){const e=w.length-1;if(e>=0){const t=w[e];if(t.state==="create")return t}return null}for(let e=w.length-1;e>=0;e--){const t=w[e];if(t.proxy&&t.proxy.$el){const o=t.proxy.$el;if(o===n||o.contains(n))return t}}return null}function qe(n){if(!n){const e=f.getCurrentInstance();if(e===null)throw new Error("getSyncData must in setup hook");if(e.proxy===null)throw new Error("proxy is null");n=e.proxy}return z(n)}const ce=n=>{let{key:e,shiftKey:t,altKey:o,ctrlKey:s}=n,r=[];return t&&r.push("Shift"),o&&r.push("Alt"),s&&r.push("Ctrl"),r.push(e),r.join("+").toLocaleUpperCase()},ue=(n,e="Enter")=>{let t=[n.arg??e];return n.modifiers.Shift?t.splice(0,0,"Shift"):n.modifiers.Alt?t.splice(0,0,"Alt"):n.modifiers.Ctrl&&t.splice(0,0,"Ctrl"),t.join("+").toLocaleUpperCase()},O=new WeakMap,ze={mounted(n,e,t,o){const s=ue(e,"ENTER"),r=H(n),l=e.value??{},i=a=>{const u=ce(a);r&&r.controller&&u===s&&r.controller.submit(l)};n.addEventListener("keyup",i),O.set(n,i)},beforeUnmount(n,e,t,o){const s=O.get(n);O.delete(n),s&&n.removeEventListener("keyup",s)}},U=new WeakMap,Je={mounted(n,e,t,o){const s=ue(e,"ESCAPE"),r=H(n),l=e.value??{},i=a=>{const u=ce(a);r&&r.controller&&u===s&&r.controller.exit(l)};n.addEventListener("keyup",i),U.set(n,i)},beforeUnmount(n,e,t,o){const s=U.get(n);U.delete(n),s&&n.removeEventListener("keyup",s)}},fe=(n,e,t)=>{t?e==="disabled"&&n.hasAttribute("disabled")?n.removeAttribute("disbaled"):n.style.display==="none"&&(n.style.display="block"):e==="disabled"?n.setAttribute("disabled",!0):n.style.display="none"},Qe={mounted(n,e,t,o){const s=e.arg??"show";let r=e.value;r||(r=n.dataset.permission??[]),f.watchEffect(()=>{const l=H(n);if(l&&l.controller){const i=l.controller.havePermission(r);y.isPromise(i)?i.then(a=>{fe(n,s,a)}):fe(n,s,i)}})}},Xe={install(n){n.directive("submit",ze),n.directive("exit",Je),n.directive("permission",Qe)}};function ye(n,e){q.set(n,e)}const Ye={install(n,e={}){if(e.pretreatLocker&&re(e.pretreatLocker),e.customSubmitFlowHooks&&oe(e.customSubmitFlowHooks),e.customCancelSubmitFlowHooks&&se(e.customCancelSubmitFlowHooks),e.systemFlows)for(let t in e.systemFlows){let o=e.systemFlows[t];ye(t,o)}Xe.install(n)}};c.BaseFlow=Ee,c.DefaultKey=d,c.FoxController=ie,c.TAG=D,c.createEventProxyName=Z,c.default=Ye,c.defineFoxController=We,c.defineFoxData=Ie,c.defineFoxMixinData=Ne,c.execBroadcast=J,c.execClearValidate=X,c.execSetDomainProperty=Le,c.execSetNameValidateRules=Y,c.execValidate=Q,c.setCustomCancelSubmitFlowHooks=se,c.setCustomSubmitFlowHooks=oe,c.setFoxSystemFlow=ye,c.setPretreatLocker=re,c.useFoxContext=H,c.useFoxController=Oe,c.useFoxSyncData=qe,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
* @fox-js/flow v4.0.1-34 Tue Sep 24 2024 22:39:26 GMT+0800 (中国标准时间) | ||
*/function he(n){return Object.prototype.toString.call(n)==="[object RegExp]"}const E=Symbol.for("BroadcastKey");class me{parent;children=[];callbacks=new Map;proxy=null;name;constructor(e,t,o){this.parent=e,this.proxy=t,this.name=o,e!==null&&e.addChild(this)}addChild(e){this.children.push(e)}removeChild(e){const t=this.children.findIndex(o=>e===o);t!==-1&&this.children.splice(t,1)}destroy(){this.parent!==null&&this.parent.removeChild(this),this.parent=null,this.proxy=null}emit(e,t,...o){if(e.maxLevel!==void 0&&e.maxLevel!==null&&e.maxLevel>0){if(e.level=e.level??0,e.level>e.maxLevel)return[];e.level++}let s=!1;!e.name||e.name==="*"?s=!0:!e.name||e.name==="+"?(s=!1,e.name="*"):he(e.name)&&this.name&&e.name.test(this.name)?s=!0:typeof e.name=="function"?s=Reflect.apply(e.name,null,[this.name]):e.name===this.name&&(s=!0);const r=[];if(s){const l=this.callbacks.get(t);if(typeof l=="function"){const a=Reflect.apply(l,this.proxy,[...o]);a!=null&&r.push(a)}const i=this.proxy??{};if(typeof i[t]=="function"){const a=Reflect.apply(i[t],i,[...o]);a!=null&&r.push(a)}}return this.children.forEach(l=>{const i=Reflect.apply(l.emit,l,[{...e},t,...o]);i!=null&&Array.isArray(i)&&Reflect.apply([].push,r,[...i])}),r}emitToChildren(e,t,...o){const s=[];return this.children.forEach(r=>{const l=Reflect.apply(r.emit,r,[{...e},t,...o]);l!=null&&Array.isArray(l)&&Reflect.apply([].push,s,[...l])}),s}on(e,t){this.callbacks.set(e,t)}}function pe(n,e,t,o){return new me(e,n,t)}const d="",G=new Map;function be(n,e=d){G.set(e,n)}function we(n=d){return G.get(n)??null}const F=new WeakMap;function xe(n,e,t=d){let o=F.get(n);o||(o=new Map,F.set(n,o)),o.set(t,e)}function ve(n){const e=[],t=F.get(n);return t&&t.forEach((o,s)=>{e.push(o)}),e}function ge(n,e=d){const t=F.get(n);return t?t.get(e)??null:null}function Fe(n,e=d){const t=F.get(n);return t?t.has(e):!1}function Se(n){F.delete(n)}const q=new Map,B=new WeakMap,x=n=>{let e=B.get(n);if(!e){const t=f.inject(E,null);e=pe(n,t),B.set(n,e);const o=n;o[E]=e,f.provide(E,e)}return e},ke=n=>{const e=n;e[E]=null,B.delete(n),f.provide(E,null)},Ce=Symbol.for("SyncDataKey");function z(n){const e=y.useRoute(n);return e&&e.params?e.params[Ce]??{}:{}}const D="FoxFlow";class Re{data={}}const _=Symbol("nameKey"),$=Symbol("allDataListKey"),K=Symbol("dataListKey"),N=Symbol("proxyKey");class Ee{[_]=d;[$]=[];[K]=[];[N]=null;get name(){return this[_]}get originalData(){const e=this[K];return e.length>0?e[0].original:{}}get data(){const e=this[K];return e.length>0?e[0].last:{}}get allDataList(){return this[$]}get dataList(){return this[K]}get proxy(){return this[N]}get route(){return y.useRoute(this.proxy??void 0)}}function De(n,e){const t=q.get(e);if(t){let o=n;const s=new t;o.__proto__=s}return n}function Ke(n,e,t){const o=ve(e);let s=[];!t||t===d?s=[]:Array.isArray(t)?s=t:s=[String(t??"")];const r=[];o.forEach(l=>{const i=String(l.name??"");(s.length===0||s.includes(i))&&r.push(l)}),n[$]=o,n[K]=r,n[N]=e,n[_]=t??d}function J(n,e,t,...o){const s=x(n);return Reflect.apply(s.emit,s,[e,t,...o])}function Q(n,e=!0,t){const o=x(n);let s=null;if(!t||t===d)t=void 0,s={maxLevel:1,level:1};else if(Array.isArray(t)){const l=t;s={name:i=>l.includes(i)}}else s={name:String(t)};const r=o.emitToChildren(s,"validate",e);return r.length==1?r[0]:r.length>1?Promise.all(r).then(l=>{let i=[];return l.forEach(a=>{a.pass===!1&&Array.isArray(a.errors)&&(i=[...i,...a.errors])}),i.length>0?{pass:!1,errors:i}:{pass:!0}}):Promise.resolve({pass:!0})}function X(n,e=!0,t){const o=x(n);let s=null;if(!t||t===d)t=void 0,s={maxLevel:1,level:1};else if(Array.isArray(t)){const r=t;s={name:l=>r.includes(l)}}else s={name:String(t)};o.emitToChildren(s,"clearValidate",e)}function Y(n,e,t=!0){const o=x(n),s={maxLevel:1,level:1};o.emitToChildren(s,"setNameValidateRules",e,t)}const Z=n=>`_fox_ctrl_${n.path??n.name??""}_${n.root??"default"}`;function Ae(n,e,t){if(n==null||typeof n!="object")return;let o=n;const s=e.split(".");for(let r=0;r<s.length&&Reflect.has(o,s[r]);r++){if(r===s.length-1){o[s[r]]=t;return}if(o=o[s[r]],o==null||typeof o!="object")break}}function Le(n,e,t,o){const s=x(n);let r=null;if(!o||o===d)o=void 0,r={maxLevel:1,level:1};else if(Array.isArray(o)){const l=o;r={name:i=>l.includes(i)}}else r={name:String(o)};s.emitToChildren(r,"setDomainProperty",e,t)}function Pe(n,e,t,o){const s=x(n);let r=null;if(!o||o===d)o=void 0,r={maxLevel:1,level:1};else if(Array.isArray(o)){const l=o;r={name:i=>l.includes(i)}}else r={name:String(o)};s.emitToChildren(r,e,...t)}const Me=["beforeBack","back"],ee="getShareBus",te="havePermission",je=["beforeExit","exit"],Ve=["setCheckConditions","check"],He="cancelSubmit",Te="endSubmit";let ne=["preSubmit","commit","submit","postSubmit"],L=[];function oe(n){ne=[...n]}function se(n){L=[...n]}let P=null;function re(n){P=n}const Be="foxOpenType";let _e=n=>{const e=y.useRoute(n);return e&&e.params?e.params[Be]??"normal":"normal"};const g=Symbol("eventChainKey"),S=Symbol("sessionKey"),m=Symbol("proxyKey"),M=Symbol("userFlowKey"),k=Symbol("flowKey"),C=Symbol("stateKey"),I=Symbol("flowNameKey"),j=Symbol("allowResubmit"),R=Symbol("_getFlowEventChain"),p=Symbol("_getFlow"),W=Symbol("_reset"),le=Symbol("_destroy"),h=Symbol("_execHook");function $e(n){return n==null?!1:n===!1?!0:typeof n=="object"&&Reflect.has(n,"pass")?!n.pass:!1}const A=function(n,e){return(o,...s)=>{try{const r=Reflect.apply(n,e,[o,...s]);y.isPromise(r)&&r.then(l=>{$e(l)?o.reject(l):o.resolve(l)}).catch(l=>{o.reject(l)})}catch(r){console.error(`[${D}] exec hook error`,r),o.reject(r)}}};class ie{[g]=null;[S]=new Re;[m];[M];[k]=null;[C]="none";[I]="";[j]=!1;constructor(e,t){this[M]=e,this[m]=t}[R](e=!1){return e?new y.EventChain(this[S],!0):this[g]?this[g]:(this[g]=new y.EventChain(this[S],!0),this[g])}[p](e){if(!this[k]){const t=_e(this[m]);this[k]=De(this[M],t)}return Ke(this[k],this[m],e),this[k]}[W](){this[g]=null,this[C]="none"}[h](e,t){const o=this[p](t);if(Array.isArray(e)){const s=this[R](!0);e.forEach(r=>{const l=o[r];if(typeof l=="function"){const i=A(l,o);s?.post(i)}})}else{const s=o[e];if(typeof s=="function")return Reflect.apply(s,o,[this[S]])}}pretreat(e){return this[C]==="submit"?(console.warn(`[${D}]流程已经处于提交状态,无法加入预处理任务`),!1):(this[R]()?.post(e),this[C]="pretreat",!0)}[le](){const e=this;e[g]=null,e[S]=null,e[m]=null,e[M]=null,e[k]=null}get name(){return this[I]??""}get proxy(){return this[m]}set allowResubmit(e){this[j]=e}get allowResubmit(){return this[j]}submit(e,t){if(typeof e=="string"&&(t=e,e=void 0),this[I]=t??"",!this[j]&&this[C]==="submit")return console.warn(`[${D}]流程已经处于提交状态,无法重复提交`),!1;e&&typeof e=="object"&&Object.assign(this[S].data,e);const o=this[R]();if(this[C]==="pretreat"&&P){try{P.lock()}catch{}o?.post(r=>{P?.unlock(),r.resolve()})}const s=this[p](t);Ve.forEach(r=>{const l=s[r];typeof l=="function"&&o?.post(A(l,s))}),ne.forEach(r=>{const l=s[r];typeof l=="function"&&o?.post(A(l,s))}),o?.wait((r,...l)=>{this[W]();const i=s[Te];typeof i=="function"&&Reflect.apply(i,s,[r,...l])},(r,...l)=>{this[W]();const i=()=>{const a=s[He];typeof a=="function"&&Reflect.apply(a,s,[r,...l])};if(Array.isArray(L)&&L.length>0){const a=this[R](!0);L.forEach(u=>{const v=s[u];typeof v=="function"&&a?.post(A(v,s))}),a?.wait(()=>i,()=>i)}else i()})}exit(e){return new Promise((t,o)=>{const s=this[R](!0),r=this[p](e);je.forEach(l=>{const i=r[l];typeof i=="function"&&s?.post(A(i,r))}),s?.wait((l,...i)=>{t(!0)},(l,...i)=>{t(!0)})})}back(e){return this[h](Me,e),!0}exec(e,t){return this[h](e,t)}getShareBus(e){const t=this[p](e);return typeof t[ee]=="function"?Reflect.apply(t[ee],t,[]):null}havePermission(e){const t=this[p]();return typeof t[te]=="function"?Reflect.apply(t[te],t,[e]):!0}setValue(e,t,o){const s=this[p](o??"");if(Array.isArray(s.allDataList)){for(let r of s.allDataList)if(r.name===o){Ae(r.last,e,t),r.last[e]=t;break}}}getValue(e,t){let o=null;const s=this[p](t??"");if(Array.isArray(s.allDataList)){for(let r of s.allDataList)if(r.name===t){o=r.last[e];break}}return o}get allDataList(){return this[p]().allDataList}get dataList(){return this[p]().dataList}getDataRecordByFieldName(e){return this.allDataList.find(s=>Reflect.ownKeys(s.last).includes(e))??null}broadcast(e,t,...o){return Reflect.apply(J,null,[this[m],e,t,...o])}resetFields(e,t){let o=[];Array.isArray(t)?o=t:typeof t=="string"?o=[t]:o=[d];const s=this[m];o.forEach(r=>{const l=ge(s,r)??{original:{},last:{}},i={};if(y.extend(!0,i,l.original),Array.isArray(e))e.forEach(a=>{l.last[a]=i[a]});else if(e&&Array.isArray(e.include))(e.include??[]).forEach(u=>{l.last[u]=i[u]});else if(e&&Array.isArray(e.exclude)){let a=e.exclude??[];Reflect.ownKeys(i).forEach(u=>{typeof u=="string"&&(a.includes(u)||(l.last[u]=i[u]))})}else Object.assign(l.last,i)}),this.clearValidate(e,t)}validate(e=!0,t){return Q(this[m],e,t)}clearValidate(e=!0,t){return X(this[m],e,t)}setNameValidateRules(e,t=!0){return Y(this[m],e,t)}}const ae=Symbol.for("FoxControllerKey"),Ne=Symbol.for("PageWrapperKey"),V=new WeakMap;let w=[];function Ie(n,e){const t=f.toRaw(n);be(t,e)}function We(n,e,t){let o=t,s,r;const l={};if(typeof e=="string"?s=e:e&&typeof e=="object"&&(s=e.name,r=e.mixin,Object.assign(l,e)),!o){const b=f.getCurrentInstance();if(b===null)throw new Error("defineData must in setup hook");if(b.proxy==null)throw new Error("proxy is null");o=b.proxy}if(Fe(o,s))throw new Error("duplicate definitions are not allowed, please Set different name!");const i=f.isReactive(n)?f.toRaw(n):n,a=we(r);a&&y.extend(!0,i,a);const u=z(o);if(!s)y.extend(!0,i,u);else{const b=u[s];b&&typeof b=="object"&&y.extend(!0,i,b)}const v={};y.extend(!0,v,i);const T=f.reactive(i);if(xe(o,{name:s??d,metadata:l,original:v,last:T},s),o){const b=x(o),de=()=>{s?b?.emitToChildren({name:s},"setModelValue",T):b?.emitToChildren({maxLevel:1,level:1},"setModelValue",T)};o.$.isMounted?de():f.onMounted(de)}return T}function Oe(n={},e){if(!e){const a=f.getCurrentInstance();if(a===null)throw new Error("defineData must in setup hook");if(a.proxy===null)throw new Error("proxy is null");e=a.proxy}x(e);const t=new ie(n,e);V.set(e,t),y.provideContextValue(e,ae,t),w.push({proxy:e,controller:t,state:"create"});const o=y.useEventProxy(e);let s=null,r=null;const l=y.useRoute(e);l&&l.path&&l.root&&(r=Z(l),s=(a,u)=>{a==="exit"?t.exit(u):a==="submit"?t.submit(u):a==="execHook"&&typeof u=="string"&&t[h](u)},o.on(r,s)),f.onBeforeMount(()=>{t[h]("beforeMount")}),f.onMounted(()=>{const a=e;a&&Ge(a,"mounted"),t[h](["mounted","endMounted"])}),f.onBeforeUnmount(()=>{t[h]("beforeUnmount")}),f.onUnmounted(()=>{t[h]("unmounted"),t[le]();const a=e;a&&(qe(a),ke(a),V.delete(a),Se(a)),r&&s&&o.off(r,s)}),y.onFoxActivated(()=>{t[h]("activated")}),y.onFoxInactivated(()=>{t[h]("inactivated")});const i=f.inject(Ne,null);i&&typeof i.beforeClose!="function"&&(i.used||(i.used=!0,i.beforeClose=async a=>{const u=e;if(u){const v=V.get(u);v?await v.exit():r&&o.emit(r,"exit")}typeof a=="function"&&a()},i.onShow=()=>{t[h]("activated")},i.onHide=()=>{t[h]("inactivated")}));try{t[h]("created")}catch(a){console.error(`[${D}] created error`,a)}return t}function Ue(n){let e=null;return n&&(e=V.get(n)??null),e||(n||(n=f.getCurrentInstance()?.proxy??void 0),n&&(e=y.injectContextValue(n,ae))),e}function Ge(n,e){for(let t=w.length-1;t>=0;t--){const o=w[t];if(o.proxy===n){o.state=e;break}}}function qe(n){const e=w.findIndex(t=>t.proxy===n);e!==-1&&w.splice(e,1)}function H(n){if(!n){const e=w.length-1;if(e>=0){const t=w[e];if(t.state==="create")return t}return null}for(let e=w.length-1;e>=0;e--){const t=w[e];if(t.proxy&&t.proxy.$el){const o=t.proxy.$el;if(o===n||o.contains(n))return t}}return null}function ze(n){if(!n){const e=f.getCurrentInstance();if(e===null)throw new Error("getSyncData must in setup hook");if(e.proxy===null)throw new Error("proxy is null");n=e.proxy}return z(n)}const ce=n=>{let{key:e,shiftKey:t,altKey:o,ctrlKey:s}=n,r=[];return t&&r.push("Shift"),o&&r.push("Alt"),s&&r.push("Ctrl"),r.push(e),r.join("+").toLocaleUpperCase()},ue=(n,e="Enter")=>{let t=[n.arg??e];return n.modifiers.Shift?t.splice(0,0,"Shift"):n.modifiers.Alt?t.splice(0,0,"Alt"):n.modifiers.Ctrl&&t.splice(0,0,"Ctrl"),t.join("+").toLocaleUpperCase()},O=new WeakMap,Je={mounted(n,e,t,o){const s=ue(e,"ENTER"),r=H(n),l=e.value??{},i=a=>{const u=ce(a);r&&r.controller&&u===s&&r.controller.submit(l)};n.addEventListener("keyup",i),O.set(n,i)},beforeUnmount(n,e,t,o){const s=O.get(n);O.delete(n),s&&n.removeEventListener("keyup",s)}},U=new WeakMap,Qe={mounted(n,e,t,o){const s=ue(e,"ESCAPE"),r=H(n),l=e.value??{},i=a=>{const u=ce(a);r&&r.controller&&u===s&&r.controller.exit(l)};n.addEventListener("keyup",i),U.set(n,i)},beforeUnmount(n,e,t,o){const s=U.get(n);U.delete(n),s&&n.removeEventListener("keyup",s)}},fe=(n,e,t)=>{t?e==="disabled"&&n.hasAttribute("disabled")?n.removeAttribute("disbaled"):n.style.display==="none"&&(n.style.display="block"):e==="disabled"?n.setAttribute("disabled",!0):n.style.display="none"},Xe={mounted(n,e,t,o){const s=e.arg??"show";let r=e.value;r||(r=n.dataset.permission??[]),f.watchEffect(()=>{const l=H(n);if(l&&l.controller){const i=l.controller.havePermission(r);y.isPromise(i)?i.then(a=>{fe(n,s,a)}):fe(n,s,i)}})}},Ye={install(n){n.directive("submit",Je),n.directive("exit",Qe),n.directive("permission",Xe)}};function ye(n,e){q.set(n,e)}const Ze={install(n,e={}){if(e.pretreatLocker&&re(e.pretreatLocker),e.customSubmitFlowHooks&&oe(e.customSubmitFlowHooks),e.customCancelSubmitFlowHooks&&se(e.customCancelSubmitFlowHooks),e.systemFlows)for(let t in e.systemFlows){let o=e.systemFlows[t];ye(t,o)}Ye.install(n)}};c.BaseFlow=Ee,c.DefaultKey=d,c.FoxController=ie,c.TAG=D,c.createEventProxyName=Z,c.default=Ze,c.defineFoxController=Oe,c.defineFoxData=We,c.defineFoxMixinData=Ie,c.execBroadcast=J,c.execCallFunc=Pe,c.execClearValidate=X,c.execSetDomainProperty=Le,c.execSetNameValidateRules=Y,c.execValidate=Q,c.setCustomCancelSubmitFlowHooks=se,c.setCustomSubmitFlowHooks=oe,c.setFoxSystemFlow=ye,c.setPretreatLocker=re,c.useFoxContext=H,c.useFoxController=Ue,c.useFoxSyncData=ze,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
{ | ||
"name": "@fox-js/flow", | ||
"type": "module", | ||
"version": "4.0.1-34", | ||
"version": "4.0.1-35", | ||
"description": "fox flow", | ||
@@ -6,0 +6,0 @@ "author": "jiangcheng", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86383
1648