mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
3 lines
30 KiB
JavaScript
3 lines
30 KiB
JavaScript
System.register(["./index-legacy-tP3UZPmW.js"],(function(t,e){"use strict";var r,a,n,o;return{setters:[t=>{r=t.E,a=t.e,n=t.s,o=t.c}],execute:function(){t("u",(function(t=""){let e,r,a;return"string"==typeof t?e=t:({componentType:e,app:r}=t),e&&""!==e||(e="container"),r||(r=VueDemi.inject("app")),a=r?.resolveComponent(e),a||e.startsWith("magic-ui-")||(e=`magic-ui-${Ne(e)}`,a=r?.resolveComponent(e)),a??e}));var i="object"==typeof global&&global&&global.Object===Object&&global,s="object"==typeof self&&self&&self.Object===Object&&self,c=i||s||Function("return this")(),u=c.Symbol,d=Object.prototype,h=d.hasOwnProperty,l=d.toString,p=u?u.toStringTag:void 0,f=Object.prototype.toString,y=u?u.toStringTag:void 0;function g(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":y&&y in Object(t)?function(t){var e=h.call(t,p),r=t[p];try{t[p]=void 0;var a=!0}catch(o){}var n=l.call(t);return a&&(e?t[p]=r:delete t[p]),n}(t):function(t){return f.call(t)}(t)}function b(t){return null!=t&&"object"==typeof t}var m=Array.isArray;function v(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function j(t){return t}function _(t){if(!v(t))return!1;var e=g(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}var D,A=c["__core-js_shared__"],O=(D=/[^.]+$/.exec(A&&A.keys&&A.keys.IE_PROTO||""))?"Symbol(src)_1."+D:"",w=Function.prototype.toString;function S(t){if(null!=t){try{return w.call(t)}catch(e){}try{return t+""}catch(e){}}return""}var T=/^\[object .+?Constructor\]$/,E=Function.prototype,I=Object.prototype,k=E.toString,C=I.hasOwnProperty,P=RegExp("^"+k.call(C).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function $(t){return!(!v(t)||(e=t,O&&O in e))&&(_(t)?P:T).test(S(t));var e}function M(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return $(r)?r:void 0}var x,L,U,F=M(c,"WeakMap"),R=Object.create,B=function(){function t(){}return function(e){if(!v(e))return{};if(R)return R(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),V=Date.now,z=function(){try{var t=M(Object,"defineProperty");return t({},"",{}),t}catch(e){}}(),q=z?function(t,e){return z(t,"toString",{configurable:!0,enumerable:!1,value:(r=e,function(){return r}),writable:!0});var r}:j,N=(x=q,L=0,U=0,function(){var t=V(),e=16-(t-U);if(U=t,e>0){if(++L>=800)return arguments[0]}else L=0;return x.apply(void 0,arguments)});function W(t){return t!=t}function G(t,e){return!(null==t||!t.length)&&function(t,e,r){return e==e?function(t,e,r){for(var a=r-1,n=t.length;++a<n;)if(t[a]===e)return a;return-1}(t,e,r):function(t,e,r){for(var a=t.length,n=r+-1;++n<a;)if(e(t[n],n,t))return n;return-1}(t,W,r)}(t,e,0)>-1}var J=/^(?:0|[1-9]\d*)$/;function H(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&J.test(t))&&t>-1&&t%1==0&&t<e}function K(t,e){return t===e||t!=t&&e!=e}var Z=Object.prototype.hasOwnProperty;function Q(t,e,r){var a=t[e];Z.call(t,e)&&K(a,r)&&(void 0!==r||e in t)||function(t,e,r){"__proto__"==e&&z?z(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}(t,e,r)}var X=Math.max;function Y(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}function tt(t){return null!=t&&Y(t.length)&&!_(t)}var et=Object.prototype;function rt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||et)}function at(t){return b(t)&&"[object Arguments]"==g(t)}var nt=Object.prototype,ot=nt.hasOwnProperty,it=nt.propertyIsEnumerable,st=at(function(){return arguments}())?at:function(t){return b(t)&&ot.call(t,"callee")&&!it.call(t,"callee")},ct="object"==typeof t&&t&&!t.nodeType&&t,ut=ct&&"object"==typeof e&&e&&!e.nodeType&&e,dt=ut&&ut.exports===ct?c.Buffer:void 0,ht=(dt?dt.isBuffer:void 0)||function(){return!1},lt={};function pt(t){return function(e){return t(e)}}lt["[object Float32Array]"]=lt["[object Float64Array]"]=lt["[object Int8Array]"]=lt["[object Int16Array]"]=lt["[object Int32Array]"]=lt["[object Uint8Array]"]=lt["[object Uint8ClampedArray]"]=lt["[object Uint16Array]"]=lt["[object Uint32Array]"]=!0,lt["[object Arguments]"]=lt["[object Array]"]=lt["[object ArrayBuffer]"]=lt["[object Boolean]"]=lt["[object DataView]"]=lt["[object Date]"]=lt["[object Error]"]=lt["[object Function]"]=lt["[object Map]"]=lt["[object Number]"]=lt["[object Object]"]=lt["[object RegExp]"]=lt["[object Set]"]=lt["[object String]"]=lt["[object WeakMap]"]=!1;var ft="object"==typeof t&&t&&!t.nodeType&&t,yt=ft&&"object"==typeof e&&e&&!e.nodeType&&e,gt=yt&&yt.exports===ft&&i.process,bt=function(){try{var t=yt&&yt.require&&yt.require("util").types;return t||gt&>.binding&>.binding("util")}catch(e){}}(),mt=bt&&bt.isTypedArray,vt=mt?pt(mt):function(t){return b(t)&&Y(t.length)&&!!lt[g(t)]},jt=Object.prototype.hasOwnProperty;function _t(t,e){var r=m(t),a=!r&&st(t),n=!r&&!a&&ht(t),o=!r&&!a&&!n&&vt(t),i=r||a||n||o,s=i?function(t,e){for(var r=-1,a=Array(t);++r<t;)a[r]=e(r);return a}(t.length,String):[],c=s.length;for(var u in t)!jt.call(t,u)||i&&("length"==u||n&&("offset"==u||"parent"==u)||o&&("buffer"==u||"byteLength"==u||"byteOffset"==u)||H(u,c))||s.push(u);return s}function Dt(t,e){return function(r){return t(e(r))}}var At=Dt(Object.keys,Object),Ot=Object.prototype.hasOwnProperty;function wt(t){return tt(t)?_t(t):function(t){if(!rt(t))return At(t);var e=[];for(var r in Object(t))Ot.call(t,r)&&"constructor"!=r&&e.push(r);return e}(t)}var St=M(Object,"create"),Tt=Object.prototype.hasOwnProperty,Et=Object.prototype.hasOwnProperty;function It(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var a=t[e];this.set(a[0],a[1])}}function kt(t,e){for(var r=t.length;r--;)if(K(t[r][0],e))return r;return-1}It.prototype.clear=function(){this.__data__=St?St(null):{},this.size=0},It.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},It.prototype.get=function(t){var e=this.__data__;if(St){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return Tt.call(e,t)?e[t]:void 0},It.prototype.has=function(t){var e=this.__data__;return St?void 0!==e[t]:Et.call(e,t)},It.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=St&&void 0===e?"__lodash_hash_undefined__":e,this};var Ct=Array.prototype.splice;function Pt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var a=t[e];this.set(a[0],a[1])}}Pt.prototype.clear=function(){this.__data__=[],this.size=0},Pt.prototype.delete=function(t){var e=this.__data__,r=kt(e,t);return!(r<0||(r==e.length-1?e.pop():Ct.call(e,r,1),--this.size,0))},Pt.prototype.get=function(t){var e=this.__data__,r=kt(e,t);return r<0?void 0:e[r][1]},Pt.prototype.has=function(t){return kt(this.__data__,t)>-1},Pt.prototype.set=function(t,e){var r=this.__data__,a=kt(r,t);return a<0?(++this.size,r.push([t,e])):r[a][1]=e,this};var $t=M(c,"Map");function Mt(t,e){var r,a,n=t.__data__;return("string"==(a=typeof(r=e))||"number"==a||"symbol"==a||"boolean"==a?"__proto__"!==r:null===r)?n["string"==typeof e?"string":"hash"]:n.map}function xt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var a=t[e];this.set(a[0],a[1])}}function Lt(t,e){for(var r=-1,a=e.length,n=t.length;++r<a;)t[n+r]=e[r];return t}xt.prototype.clear=function(){this.size=0,this.__data__={hash:new It,map:new($t||Pt),string:new It}},xt.prototype.delete=function(t){var e=Mt(this,t).delete(t);return this.size-=e?1:0,e},xt.prototype.get=function(t){return Mt(this,t).get(t)},xt.prototype.has=function(t){return Mt(this,t).has(t)},xt.prototype.set=function(t,e){var r=Mt(this,t),a=r.size;return r.set(t,e),this.size+=r.size==a?0:1,this};var Ut=u?u.isConcatSpreadable:void 0;function Ft(t){return m(t)||st(t)||!!(Ut&&t&&t[Ut])}var Rt=Dt(Object.getPrototypeOf,Object);function Bt(t){var e=this.__data__=new Pt(t);this.size=e.size}Bt.prototype.clear=function(){this.__data__=new Pt,this.size=0},Bt.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Bt.prototype.get=function(t){return this.__data__.get(t)},Bt.prototype.has=function(t){return this.__data__.has(t)},Bt.prototype.set=function(t,e){var r=this.__data__;if(r instanceof Pt){var a=r.__data__;if(!$t||a.length<199)return a.push([t,e]),this.size=++r.size,this;r=this.__data__=new xt(a)}return r.set(t,e),this.size=r.size,this};var Vt="object"==typeof t&&t&&!t.nodeType&&t,zt=Vt&&"object"==typeof e&&e&&!e.nodeType&&e,qt=zt&&zt.exports===Vt?c.Buffer:void 0;qt&&qt.allocUnsafe;var Nt=Object.prototype.propertyIsEnumerable,Wt=Object.getOwnPropertySymbols,Gt=Wt?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var r=-1,a=null==t?0:t.length,n=0,o=[];++r<a;){var i=t[r];e(i,r,t)&&(o[n++]=i)}return o}(Wt(t),(function(e){return Nt.call(t,e)})))}:function(){return[]};function Jt(t){return function(t,e,r){var a=e(t);return m(t)?a:Lt(a,r(t))}(t,wt,Gt)}var Ht=M(c,"DataView"),Kt=M(c,"Promise"),Zt=M(c,"Set"),Qt="[object Map]",Xt="[object Promise]",Yt="[object Set]",te="[object WeakMap]",ee="[object DataView]",re=S(Ht),ae=S($t),ne=S(Kt),oe=S(Zt),ie=S(F),se=g;(Ht&&se(new Ht(new ArrayBuffer(1)))!=ee||$t&&se(new $t)!=Qt||Kt&&se(Kt.resolve())!=Xt||Zt&&se(new Zt)!=Yt||F&&se(new F)!=te)&&(se=function(t){var e=g(t),r="[object Object]"==e?t.constructor:void 0,a=r?S(r):"";if(a)switch(a){case re:return ee;case ae:return Qt;case ne:return Xt;case oe:return Yt;case ie:return te}return e});var ce=Object.prototype.hasOwnProperty,ue=c.Uint8Array;function de(t){var e=new t.constructor(t.byteLength);return new ue(e).set(new ue(t)),e}var he=/\w*$/,le=u?u.prototype:void 0,pe=le?le.valueOf:void 0;function fe(t,e,r){var a,n,o,i,s,c=t.constructor;switch(e){case"[object ArrayBuffer]":return de(t);case"[object Boolean]":case"[object Date]":return new c(+t);case"[object DataView]":return s=de((i=t).buffer),new i.constructor(s,i.byteOffset,i.byteLength);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return function(t){var e=de(t.buffer);return new t.constructor(e,t.byteOffset,t.length)}(t);case"[object Map]":case"[object Set]":return new c;case"[object Number]":case"[object String]":return new c(t);case"[object RegExp]":return(o=new(n=t).constructor(n.source,he.exec(n))).lastIndex=n.lastIndex,o;case"[object Symbol]":return a=t,pe?Object(pe.call(a)):{}}}var ye=bt&&bt.isMap,ge=ye?pt(ye):function(t){return b(t)&&"[object Map]"==se(t)},be=bt&&bt.isSet,me=be?pt(be):function(t){return b(t)&&"[object Set]"==se(t)},ve="[object Arguments]",je="[object Function]",_e="[object Object]",De={};function Ae(t,e,r,a,n,o){var i;if(void 0!==i)return i;if(!v(t))return t;var s=m(t);if(s)i=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&ce.call(t,"index")&&(r.index=t.index,r.input=t.input),r}(t);else{var c=se(t),u=c==je||"[object GeneratorFunction]"==c;if(ht(t))return t.slice();if(c==_e||c==ve||u&&!n)i=u?{}:function(t){return"function"!=typeof t.constructor||rt(t)?{}:B(Rt(t))}(t);else{if(!De[c])return n?t:{};i=fe(t,c)}}o||(o=new Bt);var d=o.get(t);if(d)return d;o.set(t,i),me(t)?t.forEach((function(a){i.add(Ae(a,e,r,0,t,o))})):ge(t)&&t.forEach((function(a,n){i.set(n,Ae(a,e,r,0,t,o))}));var h=s?void 0:Jt(t);return function(t,e){for(var r=-1,a=null==t?0:t.length;++r<a&&!1!==e(t[r],r,t););}(h||t,(function(a,n){h&&(a=t[n=a]),Q(i,n,Ae(a,e,r,0,t,o))})),i}function Oe(t){return Ae(t,5)}function we(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new xt;++e<r;)this.add(t[e])}function Se(t,e){return t.has(e)}function Te(t){var e=-1,r=Array(t.size);return t.forEach((function(t){r[++e]=t})),r}function Ee(t){return b(t)&&tt(t)}De[ve]=De["[object Array]"]=De["[object ArrayBuffer]"]=De["[object DataView]"]=De["[object Boolean]"]=De["[object Date]"]=De["[object Float32Array]"]=De["[object Float64Array]"]=De["[object Int8Array]"]=De["[object Int16Array]"]=De["[object Int32Array]"]=De["[object Map]"]=De["[object Number]"]=De[_e]=De["[object RegExp]"]=De["[object Set]"]=De["[object String]"]=De["[object Symbol]"]=De["[object Uint8Array]"]=De["[object Uint8ClampedArray]"]=De["[object Uint16Array]"]=De["[object Uint32Array]"]=!0,De["[object Error]"]=De[je]=De["[object WeakMap]"]=!1,we.prototype.add=we.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},we.prototype.has=function(t){return this.__data__.has(t)};var Ie=Zt&&1/Te(new Zt([,-0]))[1]==1/0?function(t){return new Zt(t)}:function(){};!function(t,e){N(function(t,e,r){return e=X(void 0===e?t.length-1:e,0),function(){for(var a=arguments,n=-1,o=X(a.length-e,0),i=Array(o);++n<o;)i[n]=a[e+n];n=-1;for(var s=Array(e+1);++n<e;)s[n]=a[n];return s[e]=r(i),function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}(t,this,s)}}(t,e,j),t+"")}((function(t){return function(t,e,r){var a=-1,n=G,o=t.length,i=!0,s=[],c=s;if(o>=200){var u=Ie(t);if(u)return Te(u);i=!1,n=Se,c=new we}else c=s;t:for(;++a<o;){var d=t[a],h=d;if(d=0!==d?d:0,i&&h==h){for(var l=c.length;l--;)if(c[l]===h)continue t;s.push(d)}else n(c,h,r)||(c!==s&&c.push(h),s.push(d))}return s}(function(t,e,r,a,n){var o=-1,i=t.length;for(r||(r=Ft),n||(n=[]);++o<i;){var s=t[o];r(s)&&Lt(n,s)}return n}(t,0,Ee))}));class ke{}class Ce extends ke{data={};event=(()=>new a.EventEmitter)();constructor(t){super(),this.data=t}update(t,e){e?He(e,t,this.data):this.data=t;const r={updateData:t,path:e??""};e&&this.event.emit(e,r),this.event.emit("",r)}on(t,e){this.event.on(t,e)}off(t,e){this.event.off(t,e)}getData(t){return t?Je(t,this.data):this.data}destroy(){}}class Pe extends r{isInit=!1;app;mockData;#t="base";#e;#r;#a;#n=[];#o=[];constructor(t){super(),this.#e=t.schema.id,this.#r=t.schema,this.app=t.app,this.setFields(t.schema.fields),this.setMethods(t.schema.methods||[]);let e=t.initialData;const r=t.ObservedDataClass||Ce;if("editor"===this.app.platform)this.mockData=t.schema.mocks?.find((t=>t.useInEditor))?.data||this.getDefaultData(),e=Oe(this.mockData);else if("boolean"==typeof t.useMock&&t.useMock)this.mockData=t.schema.mocks?.find((t=>t.enable))?.data,e=this.mockData||this.getDefaultData();else{if(t.initialData)return this.#a=new r(t.initialData??{}),void(this.isInit=!0);e=this.getDefaultData()}this.#a=new r(e??{})}get id(){return this.#e}get type(){return this.#t}get schema(){return this.#r}get fields(){return this.#n}get methods(){return this.#o}setFields(t){this.#n=t}setMethods(t){this.#o=t}get data(){return this.#a.getData("")}setData(t,e){this.#a.update(t,e);const r={updateData:t,path:e};this.emit("change",r)}setValue(t,e){return this.setData(e,t)}onDataChange(t,e){this.#a.on(t,e)}offDataChange(t,e){this.#a.off(t,e)}getDefaultData(){return Ye(this.#n)}async init(){this.isInit=!0}destroy(){this.#n=[],this.removeAllListeners(),this.#a.destroy()}}const $e=t=>Object.entries(t).reduce(((t,[e,r])=>{let a=r;return"object"==typeof r&&(a=JSON.stringify(r)),void 0!==r?`${t}${t?"&":""}${globalThis.encodeURIComponent(e)}=${globalThis.encodeURIComponent(`${a}`)}`:t}),""),Me=async t=>{const{url:e,method:r="GET",headers:a={},params:n={},data:o={},...i}=t,s=$e(n);let c=JSON.stringify(o);return a["Content-Type"]?.includes("application/x-www-form-urlencoded")&&(c=$e(o)),(await globalThis.fetch(s?`${e}?${s}`:e,{method:r,headers:a,body:"GET"===r?void 0:c,...i})).json()},xe=new Map,Le=(t,e)=>{let r=!0;for(const{op:n,value:o,range:i,field:s}of t){const[t,...c]=s,u=e[t];if(!u||!c.length)break;try{const t=Je(c.join("."),u);if(!Xe(n,t,o,i)){r=!1;break}}catch(a){console.warn(a)}}return r},Ue=(t,e)=>{if(!t[qe]||!Array.isArray(t[qe])||!t[qe].length)return!0;for(const{cond:r}of t[qe])if(r&&Le(r,e))return!0;return!1},Fe=(t,e,r=[],a={})=>{const n={...a,[e]:{}};let o=Oe(a[e]),i=n[e];return r.forEach(((e,a)=>{Object.assign(i,o),a!==r.length-1?(Array.isArray(o[e])&&(o[e]={},i[e]={}),o=o[e],i=i[e]):i[e]=t})),n},Re=(t,e)=>t.replaceAll(er,((t,r)=>{try{return Je(r,e)}catch(a){return t}})),Be=(t,e)=>"string"==typeof t?Re(t,e):t?.isBindDataSource&&t.dataSourceId?e[t.dataSourceId]:t?.isBindDataSourceField&&t.dataSourceId&&"string"==typeof t.template?Re(t.template,e[t.dataSourceId]):Array.isArray(t)&&"string"==typeof t[0]?((t,e)=>{const[r,...a]=t,n=r.indexOf(tr);if(n>-1){const i=e[r.substring(n+tr.length)];if(!i)return t;try{return Je(a.join("."),i)}catch(o){return t}}return t})(t,e):t,Ve=({compile:t,dsId:e,item:r,deps:a,condDeps:n,inEditor:o,ctxData:i})=>{const{items:s,...c}=r,u=Oe(c);return n[c.id]?.keys.length&&!o&&(u.condResult=Ue(c,i)),Array.isArray(s)&&s.length?u.items=s.map((r=>Ve({compile:t,dsId:e,item:r,deps:a,condDeps:n,inEditor:o,ctxData:i}))):s&&(u.items=s),a[u.id]?.keys.length?Qe(t,u,{[e]:a},e):u};class ze extends r{static dataSourceClassMap=(()=>new Map)();static ObservedDataClass=(()=>Ce)();static register(t,e){ze.dataSourceClassMap.set(t,e)}static getDataSourceClass(t){return ze.dataSourceClassMap.get(t)}static registerObservedData(t){ze.ObservedDataClass=t}app;dataSourceMap=(()=>new Map)();data={};useMock=!1;constructor({app:t,useMock:e,initialData:r}){super(),this.app=t,this.useMock=e,r&&(this.data=r),t.dsl?.dataSources?.forEach((t=>{this.addDataSource(t)}));const a=Array.from(this.dataSourceMap);"function"==typeof Promise.allSettled?Promise.allSettled(a.map((([,t])=>this.init(t)))).then((t=>{const e={},r={};t.forEach(((t,n)=>{const o=a[n][0];"fulfilled"===t.status?this.data[o]?e[o]=this.data[o]:delete e[o]:"rejected"===t.status&&(delete e[o],r[o]=t.reason)})),this.emit("init",e,r)})):Promise.all(a.map((([,t])=>this.init(t)))).then((()=>{this.emit("init",this.data)})).catch((()=>{this.emit("init",this.data)}))}async init(t){if(!(t.isInit||this.app.jsEngine&&t.schema.disabledInitInJsEngine?.includes(this.app.jsEngine))){for(const e of t.methods){if("function"!=typeof e.content)return;"beforeInit"===e.timing&&await e.content({params:{},dataSource:t,app:this.app})}await t.init();for(const e of t.methods){if("function"!=typeof e.content)return;"afterInit"===e.timing&&await e.content({params:{},dataSource:t,app:this.app})}}}get(t){return this.dataSourceMap.get(t)}async addDataSource(t){if(!t)return;const e=new(ze.dataSourceClassMap.get(t.type)||Pe)({app:this.app,schema:t,request:this.app.request,useMock:this.useMock,initialData:this.data[t.id],ObservedDataClass:ze.ObservedDataClass});this.dataSourceMap.set(t.id,e),this.data[e.id]=e.data,e.on("change",(t=>{this.setData(e,t)}))}setData(t,e){this.data[t.id]=t.data,this.emit("change",t.id,e)}removeDataSource(t){this.get(t)?.destroy(),delete this.data[t],this.dataSourceMap.delete(t)}updateSchema(t){t.forEach((t=>{if(!this.get(t.id))return;this.removeDataSource(t.id),this.addDataSource(t);const e=this.get(t.id);e&&this.init(e)}))}compiledNode({items:t,...e},r,a=!1){const n=Oe(e);return t&&(n.items=Array.isArray(t)&&a?t.map((t=>this.compiledNode(t,r,a))):t),!1===e.condResult||!1===e.visible?n:Qe((t=>Be(t,this.data)),n,this.app.dsl?.dataSourceDeps||{},r)}compliedConds(t){return Ue(t,this.data)}compliedIteratorItemConds(t,e,r=[]){const[a,...n]=r,o=this.get(a);if(!o)return!0;const i=Fe(t,o.id,n,this.data);return Ue(e,i)}compliedIteratorItems(t,e,r=[]){const[a,...n]=r,o=this.get(a);if(!o)return e;const i="editor"===this.app.platform,s=Fe(t,o.id,n,this.data),{deps:c={},condDeps:u={}}=((t,e,r)=>{let a;if(r){const r=[];e.forEach((t=>{rr(t,(t=>{r.push(t.id)}))})),a=`${t.id}:${r.join(":")}`}else a=`${t.id}:${e.map((t=>t.id)).join(":")}`;if(xe.has(a))return xe.get(a);const n=new ur;n.addTarget(new nr({id:t.id,type:"data-source",isTarget:(e,r)=>!`${e}`.includes(Ke)&&ir(t,e,r,!0)})),n.addTarget(new nr({id:t.id,type:"cond",isTarget:(e,r)=>sr(t,e,r,!0)})),n.collect(e,{},!0);const{deps:o}=n.getTarget(t.id,"data-source"),{deps:i}=n.getTarget(t.id,"cond"),s={deps:o,condDeps:i};return xe.set(a,s),s})(o.schema,e,i);return Object.keys(c).length||Object.keys(u).length?e.map((t=>Ve({compile:t=>Be(t,s),dsId:o.id,item:t,deps:c,condDeps:u,inEditor:i,ctxData:s}))):e}destroy(){this.removeAllListeners(),this.data={},this.dataSourceMap.forEach((t=>{t.destroy()})),this.dataSourceMap.clear()}onDataChange(t,e,r){return this.get(t)?.onDataChange(e,r)}offDataChange(t,e,r){return this.get(t)?.offDataChange(e,r)}}ze.register("http",class extends Pe{isLoading=!1;error;httpOptions;#i;#s=[];#c=[];#t="http";constructor(t){const{options:e}=t.schema;super(t),this.httpOptions=e,"function"==typeof t.request?this.#i=t.request:"function"==typeof globalThis.fetch&&(this.#i=Me),this.methods.forEach((t=>{"function"==typeof t.content&&("beforeRequest"===t.timing&&this.#s.push(t.content),"afterRequest"===t.timing&&this.#c.push(t.content))}))}get type(){return this.#t}async init(){this.schema.autoFetch&&await this.request(),super.init()}async request(t={}){this.isLoading=!0;const{url:e,params:r,data:a,headers:n,...o}=this.httpOptions;let i={url:"function"==typeof e?e({app:this.app,dataSource:this}):e,params:"function"==typeof r?r({app:this.app,dataSource:this}):r,data:"function"==typeof a?a({app:this.app,dataSource:this}):a,headers:"function"==typeof n?n({app:this.app,dataSource:this}):n,...o,...t};try{for(const t of this.#s)await t({options:i,params:{},dataSource:this,app:this.app});if("function"==typeof this.schema.beforeRequest&&(i=await this.schema.beforeRequest(i,{app:this.app,dataSource:this})),this.mockData)this.setData(this.mockData);else{let t=await(this.#i?.(i));for(const e of this.#c)await e({res:t,options:i,params:{},dataSource:this,app:this.app});if("function"==typeof this.schema.afterResponse&&(t=await this.schema.afterResponse(t,{app:this.app,dataSource:this,options:i})),this.schema.responseOptions?.dataPath){const e=Je(this.schema.responseOptions.dataPath,t);this.setData(e)}else this.setData(t)}this.error=void 0}catch(s){this.error={msg:s.message},this.emit("error",s)}this.isLoading=!1}get(t){return this.request({...t,method:"GET"})}post(t){return this.request({...t,method:"POST"})}});const qe="displayConds",Ne=(t="")=>t.replace(/\B([A-Z])/g,"-$1").toLowerCase(),We=t=>"[object Object]"===Object.prototype.toString.call(t),Ge=t=>`${t}`.replaceAll(/\[(\d+)\]/g,".$1").split("."),Je=(t="",e={})=>(Array.isArray(t)?t:Ge(t)).reduce(((r,a)=>{if(We(r))return r[a];if(Array.isArray(r)&&/^\d*$/.test(`${a}`))return r[a];throw new Error(`${e}中不存在${t}`)}),e),He=(t,e,r={})=>n(r,t,e),Ke="__tmagic__",Ze="__tmagic__dslNode",Qe=(t,e,r={},a)=>{let n=[];if(a){const t=r[a];n=t?.[e.id].keys||[]}else n=((t={},e)=>Array.from(Object.values(t).reduce(((t,r)=>((r[e]?.keys||[]).forEach((e=>t.add(e))),t)),new Set)))(r,e.id);return n.forEach((r=>{const a=Ge(r),n=a.map(((t,e)=>e<a.length-1?t:`${Ke}${t}`));let o,i=Je(n,e);if(void 0===i)try{const t=Je(r,e);He(n.join("."),t,e),i=t}catch(s){return void console.warn(s)}try{o=t(i)}catch(s){console.error(s),o=""}He(r,o,e)})),e},Xe=(t,e,r,a=[])=>{switch("string"==typeof e&&void 0===r&&(r=""),t){case"is":case"=":return e===r;case"not":case"!=":return e!==r;case">":return e>r;case">=":return e>=r;case"<":return e<r;case"<=":return e<=r;case"between":return a.length>1&&e>=a[0]&&e<=a[1];case"not_between":return a.length<2||e<a[0]||e>a[1];case"include":return e?.includes?.(r);case"not_include":return void 0===e||!e.includes?.(r)}return!1},Ye=t=>{const e={},r={string:void 0,object:{},array:[],boolean:void 0,number:void 0,null:null,any:void 0};return t.forEach((t=>{if(void 0===t.defaultValue)"object"!==t.type?t.type?e[t.name]=r[t.type]:e[t.name]=void 0:e[t.name]=t.fields?Ye(t.fields):r.object;else{if("array"===t.type&&!Array.isArray(t.defaultValue))return void(e[t.name]=r.array);if("object"===t.type&&!We(t.defaultValue)){if("string"==typeof t.defaultValue){try{e[t.name]=JSON.parse(t.defaultValue)}catch(a){e[t.name]=r.object}return}return void(e[t.name]=r.object)}e[t.name]=o(t.defaultValue)}})),e},tr="ds-field::",er=/\$\{([\s\S]+?)\}/g,rr=(t,e,r=[],a=!1)=>{a||e(t,r),Array.isArray(t.items)&&t.items.length&&(r.push(t),t.items.forEach((t=>{rr(t,e,[...r],a)}))),a&&e(t,r)};var ar=(t=>(t.DEFAULT="default",t.CODE_BLOCK="code-block",t.DATA_SOURCE="data-source",t.DATA_SOURCE_METHOD="data-source-method",t.DATA_SOURCE_COND="data-source-cond",t))(ar||{});class nr{isTarget;id;name;type=(()=>ar.DEFAULT)();deps={};isCollectByDefault;constructor(t){this.isTarget=t.isTarget,this.id=t.id,this.name=t.name,this.isCollectByDefault=t.isCollectByDefault??!0,t.type&&(this.type=t.type),t.initialDeps&&(this.deps=t.initialDeps)}updateDep({id:t,name:e,key:r,data:a}){const n=this.deps[t]||{name:e,keys:[]};n.name=e,n.data=a,this.deps[t]=n,-1===n.keys.indexOf(r)&&n.keys.push(r)}removeDep(t,e){if(void 0===t)return void Object.keys(this.deps).forEach((t=>{delete this.deps[t]}));const r=this.deps[t];if(r)if(e){const a=r.keys.indexOf(e);r.keys.splice(a,1),0===r.keys.length&&delete this.deps[t]}else delete this.deps[t]}hasDep(t,e){const r=this.deps[t];return Boolean(r?.keys.find((t=>t===e)))}destroy(){this.deps={}}}const or=(t,e)=>{let r=e;return t.some(((e,a)=>{const n=r.find((({name:t})=>t===e));return r=n?.fields||[],n&&"array"===n.type&&/^(?!\d+$).*$/.test(`${t[a+1]}`)&&a<t.length-1}))},ir=(t,e,r,a=!1)=>{if(!r||!["string","object"].includes(typeof r))return!1;if(`${e}`.startsWith(qe))return!1;if("string"==typeof r)return((t,e,r=!1)=>{const a=t.match(er)||[];if(a.length<=0)return!1;const n=[],o=[];return a.forEach((t=>{const r=t.substring(2,t.length-1),a=Ge(r),i=a.shift();i&&i===e.id&&(or(a,e.fields)?n.push(t):o.push(t))})),r?n.length>0:o.length>0})(r,t,a);if(We(r)&&r?.isBindDataSource&&r.dataSourceId&&r.dataSourceId===t.id)return!0;if(((t,e)=>t?.isBindDataSourceField&&t.dataSourceId&&t.dataSourceId===e&&"string"==typeof t.template)(r,t.id))return!0;if(((t,e)=>{if(!Array.isArray(t)||"string"!=typeof t[0])return!1;const[r]=t,a=r.indexOf(tr);return-1!==a&&r.substring(a+tr.length)===e})(r,t.id)){const[,...e]=r,n=or(e,t.fields);return a?n:!n}return!1},sr=(t,e,r,a=!1)=>{if(!Array.isArray(r)||!t)return!1;const[n,...o]=r;if(n!==t.id||!`${e}`.startsWith(qe))return!1;if(t.fields?.find((t=>t.name===o[0]))){const e=or(o,t.fields);return a?e:!e}return!1},cr=(t,e,r)=>{for(const a of Object.values(t))for(const t of Object.values(a))r&&t.type!==r||e(t)};class ur{targetsList={};childrenProp="items";idProp="id";nameProp="name";constructor(t){t?.initialTargets&&(this.targetsList=t.initialTargets),t?.childrenProp&&(this.childrenProp=t.childrenProp)}getTargetsList(){return this.targetsList}getTargets(t=ar.DEFAULT){return this.targetsList[t]||{}}addTarget(t){const e=this.getTargets(t.type)||{};this.targetsList[t.type]=e,e[t.id]=t}getTarget(t,e=ar.DEFAULT){return this.getTargets(e)[t]}hasTarget(t,e=ar.DEFAULT){return Boolean(this.getTarget(t,e))}hasSpecifiedTypeTarget(t=ar.DEFAULT){return Object.keys(this.getTargets(t)).length>0}removeTarget(t,e=ar.DEFAULT){const r=this.getTargets(e);r[t]&&(r[t].destroy(),delete r[t])}removeTargets(t=ar.DEFAULT){const e=this.targetsList[t];if(e){for(const t of Object.values(e))t.destroy();delete this.targetsList[t]}}clearTargets(){for(const t of Object.keys(this.targetsList))delete this.targetsList[t]}collect(t,e={},r=!1,a){this.collectByCallback(t,a,(({node:t,target:a})=>{this.removeTargetDep(a,t),this.collectItem(t,a,e,r)}))}collectByCallback(t,e,r){cr(this.targetsList,(a=>{if(e||a.isCollectByDefault)for(const e of t)r({node:e,target:a})}),e)}clear(t,e){let{targetsList:r}=this;e&&(r={[e]:this.getTargets(e)});const a=[];cr(r,(e=>{if(t)for(const r of t)e.removeDep(r[this.idProp]),Array.isArray(r[this.childrenProp])&&r[this.childrenProp].length&&!a.includes(r[this.idProp])&&(a.push(r[this.idProp]),this.clear(r[this.childrenProp]));else e.removeDep()}))}clearByType(t,e){this.clear(e,t)}collectItem(t,e,r={},a=!1){const n=(o,i="")=>{const s=(o,s)=>{const c=o===this.childrenProp,u=i?`${i}.${o}`:o;if(e.isTarget(u,s))e.updateDep({id:t[this.idProp],name:`${t[this.nameProp]||t[this.idProp]}`,data:r,key:u});else if(!c&&Array.isArray(s))for(let t=0,e=s.length;t<e;t++){const e=s[t];We(e)&&n(e,`${u}[${t}]`)}else We(s)&&n(s,u);if(c&&a&&Array.isArray(s))for(const t of s)this.collectItem(t,e,r,a)};for(const[t,e]of Object.entries(o))void 0!==e&&""!==e&&"id"!==t&&"name"!==t&&s(t,e)};n(t)}removeTargetDep(t,e,r){if(t.removeDep(e[this.idProp],r),void 0===r&&Array.isArray(e[this.childrenProp])&&e[this.childrenProp].length)for(const a of e[this.childrenProp])this.removeTargetDep(t,a,r)}}const dr=t("b",((t,e=VueDemi.inject("app"))=>{return void 0!==(r=t.config)[Ze]&&!0!==r[Ze]||!t.config.id?void 0:e?.getNode(t.config.id,t.iteratorContainerId,t.iteratorIndex);var r})),hr=t("r",((t,e={})=>{if(!t)return;const r={config:t.data,...e};t.emit("created",r),VueDemi.onMounted((()=>{t.emit("mounted",r)})),VueDemi.onBeforeUnmount((()=>{t.emit("destroy",r)}))}));t("c",(({methods:t={},config:e,iteratorContainerId:r,iteratorIndex:a})=>{const n=VueDemi.inject("app"),o=dr({config:e,iteratorContainerId:r,iteratorIndex:a},n);return o&&hr(o,t),{app:n,node:o}})),t("a",(t=>{const e=VueDemi.inject("app"),r=VueDemi.ref("default"),a=new Map,n=new Map,o=new Map,i=(t,{style:e,className:r,...i})=>{e&&a.set(t,e),r&&n.set(t,r),o.set(t,VueDemi.shallowReactive(i))};return VueDemi.watchEffect((()=>{i("default",{style:t.config.style,className:t.config.className})})),VueDemi.onScopeDispose((()=>{o.clear()})),{status:VueDemi.computed((()=>r.value)),style:VueDemi.computed((()=>{const n=r.value||"default",o=a.get("default")||{},i=a.get(n);let s=e?.transformStyle(o)||{};return"default"!==n&&i&&(s=Object.keys(i).reduce(((t,e)=>{const r=i[e];return null==r||isNaN(r)||""===r?{...t,[e]:i[e]}:{...t}}),s)),t.config.displayHidden&&(s.display="none"),void 0!==t.config.condResult&&"mount"===t.config.displayRenderModel&&!1===t.config.condResult&&(s.display="none"),s})),className:VueDemi.computed((()=>{const e=r.value||"default",a=n.get(e)??"",o=[];return t.config.type&&o.push(`magic-ui-${Ne(t.config.type)}`),t.config.layout&&o.push(`magic-layout-${t.config.layout}`),a&&o.push(a),o.join(" ")})),setStatus:t=>{r.value=t},registerStatus:i}})),t("_",((t,e)=>{const r=t.__vccOpts||t;for(const[a,n]of e)r[a]=n;return r}))}}}));
|
|
//# sourceMappingURL=plugin-vueexport-helper-legacy-BYKHBkp1.js.map
|