@shjjs/visual-ui 3.0.4 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,33 +1,33 @@
1
1
  import { isArray as c } from "lodash";
2
- const u = (l, n, r, a) => {
3
- if (!c(l))
4
- return l;
5
- let s = null;
6
- return s = l.map((e, p) => {
2
+ const m = (n, s, e, a) => {
3
+ if (!c(n))
4
+ return n;
5
+ let l = null;
6
+ return l = n.map((r, p) => {
7
7
  const i = {};
8
- return r && p === 0 && (n = f(e, n)), Object.keys(n).forEach((o) => {
9
- const t = n[o];
10
- t.alias ? i[t.alias] = e[t.mapping] : i[t.name] = e[t.mapping];
11
- }), a && (i.userdata = e), i;
12
- }), s;
13
- }, f = (l, n) => {
14
- const r = [];
15
- return Object.keys(l).forEach((a) => {
16
- const s = n.find((e) => e.name === a);
17
- s ? r.push({
18
- alias: s.alias,
8
+ return e && p === 0 && (s = f(r, s)), Object.keys(s).forEach((o) => {
9
+ const t = s[o];
10
+ t.alias ? i[t.alias] = r[t.mapping] : i[t.name] = r[t.mapping];
11
+ }), a && (i.userdata = r), i;
12
+ }), l;
13
+ }, f = (n, s) => {
14
+ const e = [];
15
+ return n ?? (n = []), Object.keys(n).forEach((a) => {
16
+ const l = s.find((r) => r.name === a);
17
+ l ? e.push({
18
+ alias: l.alias,
19
19
  name: a,
20
20
  label: a,
21
- mapping: s.mapping
22
- }) : r.push({
21
+ mapping: l.mapping
22
+ }) : e.push({
23
23
  alias: a,
24
24
  name: a,
25
25
  label: a,
26
26
  mapping: a
27
27
  });
28
- }), r;
28
+ }), e;
29
29
  };
30
30
  export {
31
31
  f as dynamicMappingData,
32
- u as mappingData
32
+ m as mappingData
33
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shjjs/visual-ui",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "国产自研零代码可视化源码工具",
5
5
  "keywords": [
6
6
  "three",
package/umd/index.js CHANGED
@@ -33389,7 +33389,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
33389
33389
 
33390
33390
  @babel/runtime/helpers/regenerator.js:
33391
33391
  (*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE *)
33392
- */const hL=class hL{constructor(){pr(this,"connections",new Map);pr(this,"connectionConfigs",new Map)}static getInstance(){return hL.instance||(hL.instance=new hL),hL.instance}generateConnectionKey(e){return JSON.stringify(e)}async getOrCreateConnection(e,t){const r=this.generateConnectionKey(e),n=this.connections.get(r);if(n&&n.isConnected())return n;this.connections.entries().forEach(([a])=>{const o=JSON.parse(a);o.uuid===e.uuid&&this.closeConnection(o)});const s=new CFn(e,t);this.connections.set(r,s),this.connectionConfigs.set(r,e);try{await s.connect()}catch{}return s}hasConnection(e){const t=this.generateConnectionKey(e),r=this.connections.get(t);return r!==void 0&&r.isConnected()}getAllConnections(){return new Map(this.connections)}closeConnection(e){const t=this.generateConnectionKey(e),r=this.connections.get(t);return r?(r.disconnect(),this.connections.delete(t),this.connectionConfigs.delete(t),!0):!1}closeAllConnections(){for(const[e,t]of this.connections)t.disconnect(),this.connections.delete(e),this.connectionConfigs.delete(e);return this.connections.clear(),this.connectionConfigs.clear(),!0}};pr(hL,"instance");let KF=hL;const p5r={getInstance:()=>KF.getInstance(),hasConnection:i=>KF.getInstance().hasConnection(i),closeConnection:i=>KF.getInstance().closeConnection(i),closeAllConnections:()=>{KF.getInstance().closeAllConnections()},removeConnectionByUUID:i=>{const e=KF.getInstance();e.getAllConnections().entries().forEach(([r])=>{const n=JSON.parse(r);n.uuid.includes(i)&&e.closeConnection(n)})}};class CFn{constructor(e,t={}){pr(this,"client",null);pr(this,"config");pr(this,"callbacks");pr(this,"connectionState","disconnected");pr(this,"subscriptions",new Map);this.config=e,this.callbacks=t}async connect(){return new Promise((e,t)=>{if(this.client&&this.client.connected){e();return}this.connectionState="connecting";const r={clientId:Su(),username:this.config.username,password:this.config.password,keepalive:this.config.keepalive||60,reconnectPeriod:this.config.reconnectPeriod||0,connectTimeout:this.config.connectTimeout||3e4,clean:this.config.clean!==!1,rejectUnauthorized:this.config.rejectUnauthorized!==!1},n=`${this.config.protocol}://${this.config.host}:${this.config.port}${this.config.endpoint}`;try{this.client=SFn.connect(n,r),this.client.on("connect",()=>{this.connectionState="connected",this.resubscribeTopics(),this.callbacks.onConnect&&this.callbacks.onConnect(),e()}),this.client.on("disconnect",()=>{this.connectionState="disconnected",this.callbacks.onDisconnect&&this.callbacks.onDisconnect()}),this.client.on("close",()=>{this.connectionState="disconnected",this.callbacks.onClose&&this.callbacks.onClose(),t(new Error("MQTT连接关闭"))}),this.client.on("error",s=>{this.connectionState="error",this.callbacks.onError&&this.callbacks.onError(s),t(s)}),this.client.on("message",(s,a)=>{this.callbacks.onMessage&&this.callbacks.onMessage(s,a);const o=this.subscriptions.get(s);o&&o.callback(s,a)}),this.client.on("reconnect",()=>{this.connectionState="reconnecting",this.callbacks.onReconnect&&this.callbacks.onReconnect()})}catch(s){this.connectionState="error",t(s)}})}disconnect(){this.client&&(this.client.end(!0),this.client=null,this.connectionState="disconnected")}subscribe(e,t=0,r){return new Promise((n,s)=>{if(!this.client||!this.client.connected){s(new Error("MQTT客户端未连接"));return}const a={qos:t};this.client.subscribe(e,a,o=>{o?s(o):(r&&this.subscriptions.set(e,{qos:t,callback:r}),n())})})}isConnected(){return this.client!==null&&this.client.connected}getConnectionState(){return this.connectionState}resubscribeTopics(){for(const[e,t]of this.subscriptions)this.subscribe(e,t.qos,t.callback).catch(r=>{})}}function TFn(i,e){return KF.getInstance().getOrCreateConnection(i,e)}const wFn=async(i,e,t)=>{try{const{protocol:r,endpoint:n,host:s,port:a,username:o,password:l,keepalive:u,clean:c,topic:d,qos:h}=i.source.mqtt;(await TFn({uuid:i.id,protocol:r,endpoint:n,host:s,port:a,username:o,password:l,keepalive:u,clean:c,topic:d,qos:h},{onConnect:()=>{t(jl.noneData(i.id))},onError:m=>{t(jl.noneData(i.id))},onDisconnect:()=>{t(jl.noneData(i.id))},onReconnect:()=>{t(jl.noneData(i.id))},onClose:()=>{t(jl.noneData(i.id))}})).subscribe(d,h,(m,x)=>{pl.processData(i.source,JSON.parse(x.toString()),i.id,e).then(v=>{t(v)}).catch(()=>{t(jl.noneData(i.id))})})}catch{t(jl.noneData(i.id))}},fL=class fL{constructor(){pr(this,"connections",new Map);pr(this,"connectionConfigs",new Map);pr(this,"pendingConnections",new Map)}static getInstance(){return fL.instance||(fL.instance=new fL),fL.instance}generateConnectionKey(e){return JSON.stringify(e)}async getOrCreateConnection(e,t){const r=this.generateConnectionKey(e),n=this.connections.get(r);if(n&&n.isConnected())return n;const s=Array.from(this.pendingConnections.entries()).find(([l])=>{try{return JSON.parse(l).uuid===e.uuid}catch{return!1}});if(s)try{return await s[1]}catch{}let a=0;Array.from(this.connections.entries()).forEach(([l,u])=>{try{JSON.parse(l).uuid===e.uuid&&(u.disconnect(),this.connections.delete(l),this.connectionConfigs.delete(l),a++)}catch{}}),Array.from(this.pendingConnections.keys()).forEach(l=>{try{JSON.parse(l).uuid===e.uuid&&this.pendingConnections.delete(l)}catch{}});const o=(async()=>{try{const l=new FFn(e,t);return await l.connect(),this.connections.set(r,l),this.connectionConfigs.set(r,e),l}catch(l){throw l}finally{this.pendingConnections.delete(r)}})();return this.pendingConnections.set(r,o),o}hasConnection(e){const t=this.generateConnectionKey(e),r=this.connections.get(t);return r!==void 0&&r.isConnected()}getAllConnections(){return new Map(this.connections)}closeConnection(e){const t=this.generateConnectionKey(e),r=this.connections.get(t);return r?(r.disconnect(),this.connections.delete(t),this.connectionConfigs.delete(t),this.pendingConnections.delete(t),!0):!1}closeAllConnections(){for(const[e,t]of this.connections)t.disconnect(),this.connections.delete(e),this.connectionConfigs.delete(e);return this.connections.clear(),this.connectionConfigs.clear(),this.pendingConnections.clear(),!0}};pr(fL,"instance");let g9=fL;const m5r={getInstance:()=>g9.getInstance(),hasConnection:i=>g9.getInstance().hasConnection(i),closeConnection:i=>g9.getInstance().closeConnection(i),closeAllConnections:()=>{g9.getInstance().closeAllConnections()},removeConnectionByUUID:i=>{const e=g9.getInstance();e.getAllConnections().entries().forEach(([r])=>{const n=JSON.parse(r);n.uuid.includes(i)&&e.closeConnection(n)})},forceCleanAll:()=>{const i=g9.getInstance(),e=i.getAllConnections();Array.from(e.entries()).forEach(([t,r])=>{try{const n=JSON.parse(t);r.disconnect()}catch{}}),i.closeAllConnections()}};class FFn{constructor(e,t={}){pr(this,"client",null);pr(this,"config");pr(this,"callbacks");pr(this,"connectionState","disconnected");pr(this,"reconnectAttempts",0);pr(this,"reconnectTimer",null);pr(this,"connectTimer",null);pr(this,"isManualDisconnect",!1);this.config=e,this.callbacks=t}async connect(){return new Promise((e,t)=>{if(this.client&&this.client.readyState===WebSocket.OPEN){e();return}this.connectionState="connecting";try{this.config.protocols?this.client=new WebSocket(this.config.url,this.config.protocols):this.client=new WebSocket(this.config.url),this.config.binaryType&&(this.client.binaryType=this.config.binaryType),this.config.timeout&&(this.connectTimer=setTimeout(()=>{this.client&&this.client.readyState===WebSocket.CONNECTING&&(this.client.close(),t(new Error("WebSocket连接超时")))},this.config.timeout)),this.client.onopen=()=>{if(this.connectTimer&&(clearTimeout(this.connectTimer),this.connectTimer=null),this.connectionState="connected",this.reconnectAttempts=0,this.isManualDisconnect=!1,this.config.isMessage&&this.config.message&&this.client&&this.client.readyState===WebSocket.OPEN)try{const r=typeof this.config.message=="string"?this.config.message:JSON.stringify(this.config.message);this.client.send(r)}catch{}this.callbacks.onOpen&&this.callbacks.onOpen(),e()},this.client.onclose=()=>{this.connectTimer&&(clearTimeout(this.connectTimer),this.connectTimer=null),this.connectionState="disconnected",!this.isManualDisconnect&&(this.callbacks.onClose&&this.callbacks.onClose(),this.config.reconnect&&this.reconnectAttempts<(this.config.maxReconnectAttempts||1/0)&&this.handleReconnect())},this.client.onmessage=r=>{if(this.callbacks.onMessage){let n=r.data;if(typeof n=="string")try{n=JSON.parse(n)}catch{}this.callbacks.onMessage(n)}},this.client.onerror=r=>{this.connectTimer&&(clearTimeout(this.connectTimer),this.connectTimer=null),this.connectionState="error",this.callbacks.onError&&this.callbacks.onError(r),t(r)}}catch(r){this.connectionState="error",t(r)}})}disconnect(){this.isManualDisconnect=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.connectTimer&&(clearTimeout(this.connectTimer),this.connectTimer=null),this.client&&(this.client.close(),this.client=null,this.connectionState="disconnected")}send(e){if(this.client&&this.client.readyState===WebSocket.OPEN){const t=typeof e=="string"?e:JSON.stringify(e);this.client.send(t)}}isConnected(){return this.client!==null&&this.client.readyState===WebSocket.OPEN}getConnectionState(){return this.connectionState}handleReconnect(){this.reconnectAttempts>=(this.config.maxReconnectAttempts||1/0)||(this.connectionState="reconnecting",this.reconnectAttempts++,this.callbacks.onReconnect&&this.callbacks.onReconnect(),this.reconnectTimer=setTimeout(()=>{this.connect().catch(e=>{})},this.config.reconnectInterval||3e3))}}function RFn(i,e){return g9.getInstance().getOrCreateConnection(i,e)}const PFn=async(i,e,t)=>{try{const{url:r,protocols:n,reconnect:s,reconnectInterval:a,maxReconnectAttempts:o,message:l,isMessage:u,headers:c,isHeaders:d,binaryType:h,timeout:p}=i.source.websocket;if(!r||r.trim()===""){t(jl.noneData(i.id));return}await RFn({uuid:i.id,url:r,protocols:n,reconnect:s,reconnectInterval:a,maxReconnectAttempts:o,message:l,isMessage:u,headers:c,isHeaders:d,binaryType:h,timeout:p},{onOpen:()=>{t(jl.noneData(i.id))},onError:m=>{t(jl.noneData(i.id))},onClose:()=>{t(jl.noneData(i.id))},onReconnect:()=>{t(jl.noneData(i.id))},onMessage:m=>{pl.processData(i.source,m,i.id,e).then(x=>{t(x)}).catch(()=>{t(jl.noneData(i.id))})}})}catch{t(jl.noneData(i.id))}},IFn=(i,e,t,r)=>{if(!Yt.isArray(i))return i;let n=null;return n=i.map((s,a)=>{const o={};return t&&a===0&&(e=MFn(s,e)),Object.keys(e).forEach(l=>{const u=e[l];u.alias?o[u.alias]=s[u.mapping]:o[u.name]=s[u.mapping]}),r&&(o.userdata=s),o}),n},MFn=(i,e)=>{const t=[];return Object.keys(i).forEach(r=>{const n=e.find(s=>s.name===r);n?t.push({alias:n.alias,name:r,label:r,mapping:n.mapping}):t.push({alias:r,name:r,label:r,mapping:r})}),t},BFn=(i,e)=>i&&i.reduce((t,r)=>{let n="default";e&&e.find(a=>a.name==="series")&&(n=r[e.find(a=>a.name==="series").name],delete r[e.find(a=>a.name==="series").name]);const s=t.find(a=>a.key===n);return s?s.data.push(r):t.push({key:n,data:[r]}),t},[]),pL=class pL{static addParser(e,t){this.parsers.add({type:e,parser:t})}static getParser(e){const t=Array.from(this.parsers).find(r=>r.type===e);return t==null?void 0:t.parser}static parse({sources:e,callback:t=a=>a||[],noUseMapping:r=!1,isInterval:n=!0,isEditor:s=!1}){try{if(e.length<=0)throw new Error("未找到数据源");e.forEach(a=>{this.handleDataSourceExecution(a,t,r,n,s)})}catch{t(null)}}static handleDataSourceExecution(e,t,r,n,s){if(s){this.executeDataSource(e,t,r,n,s);return}const{id:a,pid:o}=e;if(this.initializeDataSourceState(a),this.checkAndExecuteWaitingChildren(a),o&&o.toString()!=="-1"){const l=this.dataSourceStatePool.get(o);if(!l){this.waitingPool.set(a,{item:e,callback:t,noUseMapping:r,isInterval:n,isEditor:s});return}l.status==="completed"?this.executeDataSource(e,t,r,n,s):(this.waitingPool.set(a,{item:e,callback:t,noUseMapping:r,isInterval:n,isEditor:s}),l.callbacks.push(()=>{this.waitingPool.delete(a),this.executeDataSource(e,t,r,n,s)}))}else this.executeDataSource(e,t,r,n,s)}static initializeDataSourceState(e){this.dataSourceStatePool.has(e)||this.dataSourceStatePool.set(e,{id:e,status:"pending",callbacks:[]})}static markDataSourceExecuting(e){const t=this.dataSourceStatePool.get(e);t&&(t.status="executing")}static markDataSourceCompleted(e){const t=this.dataSourceStatePool.get(e);if(t){t.status="completed";const r=[...t.callbacks];t.callbacks=[],r.forEach(n=>{try{n()}catch{}})}}static checkAndExecuteWaitingChildren(e){if(!this.waitingPool.size)return;const t=[];this.waitingPool.forEach((r,n)=>{r.item.pid===e&&t.push({id:n,...r})});for(const r of t){const n=this.dataSourceStatePool.get(e);n&&(n.status==="completed"?(this.waitingPool.delete(r.id),this.executeDataSource(r.item,r.callback,r.noUseMapping,r.isInterval,r.isEditor)):n.callbacks.push(()=>{this.waitingPool.delete(r.id),this.executeDataSource(r.item,r.callback,r.noUseMapping,r.isInterval,r.isEditor)}))}}static executeDataSource(e,t,r,n,s){if(s){this.executeTask(e,r,s,a=>{t(a)});return}this.markDataSourceExecuting(e.id),this.setupInterval(e,n,r,s,t),this.executeTask(e,r,s,a=>{t(a),this.markDataSourceCompleted(e.id)})}static setupInterval(e,t,r,n,s){if(!t)return;const a=this.timerPool.get(e.id);if(a&&(clearInterval(a),this.timerPool.delete(e.id)),e.source.isAutoUpdate){const o=setInterval(()=>{this.markDataSourceExecuting(e.id),this.executeTask(e,r,n,l=>{s(l),this.markDataSourceCompleted(e.id)})},e.source.autoUpdateTime*1e3);this.timerPool.set(e.id,o)}}static executeTask(e,t,r,n){const s=e,{source:a}=s,o=this.getParser(a.type);o&&o(s,t,l=>{var u;if(r){n(l);return}!t&&((u=s.source.mapping)!=null&&u.length)?(drt(s.source.storage,l.finalKeyData),n(l.finalKeyData)):(drt(s.source.storage,l.noMappingData),n(l.noMappingData))})}static processData(e,t,r,n){const{filter:s,mapping:a,dynamicMapping:o,isUserdata:l}=Yt.cloneDeep(e);return new Promise(function(u){const c=t;pL.filterData(s,t).then(d=>{const h={id:r,finalKeyData:{id:r,data:null},finalUserData:{id:r,data:null},filteredData:{id:r,data:d},rawData:{id:r,data:c},noMappingData:null};if(!n&&a.length){const p=IFn(d,a,o,l);h.finalKeyData.data=p.length?BFn(p,a):d,h.finalUserData.data=p.length?p:d}else h.finalUserData.data=d,h.noMappingData=d;u(h)})})}static async filterData(e,t){if(!Yt.isString(e))return t;try{let r=e.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g,"");r=jl.replaceStringVariables(r);const n=`
33392
+ */const hL=class hL{constructor(){pr(this,"connections",new Map);pr(this,"connectionConfigs",new Map)}static getInstance(){return hL.instance||(hL.instance=new hL),hL.instance}generateConnectionKey(e){return JSON.stringify(e)}async getOrCreateConnection(e,t){const r=this.generateConnectionKey(e),n=this.connections.get(r);if(n&&n.isConnected())return n;this.connections.entries().forEach(([a])=>{const o=JSON.parse(a);o.uuid===e.uuid&&this.closeConnection(o)});const s=new CFn(e,t);this.connections.set(r,s),this.connectionConfigs.set(r,e);try{await s.connect()}catch{}return s}hasConnection(e){const t=this.generateConnectionKey(e),r=this.connections.get(t);return r!==void 0&&r.isConnected()}getAllConnections(){return new Map(this.connections)}closeConnection(e){const t=this.generateConnectionKey(e),r=this.connections.get(t);return r?(r.disconnect(),this.connections.delete(t),this.connectionConfigs.delete(t),!0):!1}closeAllConnections(){for(const[e,t]of this.connections)t.disconnect(),this.connections.delete(e),this.connectionConfigs.delete(e);return this.connections.clear(),this.connectionConfigs.clear(),!0}};pr(hL,"instance");let KF=hL;const p5r={getInstance:()=>KF.getInstance(),hasConnection:i=>KF.getInstance().hasConnection(i),closeConnection:i=>KF.getInstance().closeConnection(i),closeAllConnections:()=>{KF.getInstance().closeAllConnections()},removeConnectionByUUID:i=>{const e=KF.getInstance();e.getAllConnections().entries().forEach(([r])=>{const n=JSON.parse(r);n.uuid.includes(i)&&e.closeConnection(n)})}};class CFn{constructor(e,t={}){pr(this,"client",null);pr(this,"config");pr(this,"callbacks");pr(this,"connectionState","disconnected");pr(this,"subscriptions",new Map);this.config=e,this.callbacks=t}async connect(){return new Promise((e,t)=>{if(this.client&&this.client.connected){e();return}this.connectionState="connecting";const r={clientId:Su(),username:this.config.username,password:this.config.password,keepalive:this.config.keepalive||60,reconnectPeriod:this.config.reconnectPeriod||0,connectTimeout:this.config.connectTimeout||3e4,clean:this.config.clean!==!1,rejectUnauthorized:this.config.rejectUnauthorized!==!1},n=`${this.config.protocol}://${this.config.host}:${this.config.port}${this.config.endpoint}`;try{this.client=SFn.connect(n,r),this.client.on("connect",()=>{this.connectionState="connected",this.resubscribeTopics(),this.callbacks.onConnect&&this.callbacks.onConnect(),e()}),this.client.on("disconnect",()=>{this.connectionState="disconnected",this.callbacks.onDisconnect&&this.callbacks.onDisconnect()}),this.client.on("close",()=>{this.connectionState="disconnected",this.callbacks.onClose&&this.callbacks.onClose(),t(new Error("MQTT连接关闭"))}),this.client.on("error",s=>{this.connectionState="error",this.callbacks.onError&&this.callbacks.onError(s),t(s)}),this.client.on("message",(s,a)=>{this.callbacks.onMessage&&this.callbacks.onMessage(s,a);const o=this.subscriptions.get(s);o&&o.callback(s,a)}),this.client.on("reconnect",()=>{this.connectionState="reconnecting",this.callbacks.onReconnect&&this.callbacks.onReconnect()})}catch(s){this.connectionState="error",t(s)}})}disconnect(){this.client&&(this.client.end(!0),this.client=null,this.connectionState="disconnected")}subscribe(e,t=0,r){return new Promise((n,s)=>{if(!this.client||!this.client.connected){s(new Error("MQTT客户端未连接"));return}const a={qos:t};this.client.subscribe(e,a,o=>{o?s(o):(r&&this.subscriptions.set(e,{qos:t,callback:r}),n())})})}isConnected(){return this.client!==null&&this.client.connected}getConnectionState(){return this.connectionState}resubscribeTopics(){for(const[e,t]of this.subscriptions)this.subscribe(e,t.qos,t.callback).catch(r=>{})}}function TFn(i,e){return KF.getInstance().getOrCreateConnection(i,e)}const wFn=async(i,e,t)=>{try{const{protocol:r,endpoint:n,host:s,port:a,username:o,password:l,keepalive:u,clean:c,topic:d,qos:h}=i.source.mqtt;(await TFn({uuid:i.id,protocol:r,endpoint:n,host:s,port:a,username:o,password:l,keepalive:u,clean:c,topic:d,qos:h},{onConnect:()=>{t(jl.noneData(i.id))},onError:m=>{t(jl.noneData(i.id))},onDisconnect:()=>{t(jl.noneData(i.id))},onReconnect:()=>{t(jl.noneData(i.id))},onClose:()=>{t(jl.noneData(i.id))}})).subscribe(d,h,(m,x)=>{pl.processData(i.source,JSON.parse(x.toString()),i.id,e).then(v=>{t(v)}).catch(()=>{t(jl.noneData(i.id))})})}catch{t(jl.noneData(i.id))}},fL=class fL{constructor(){pr(this,"connections",new Map);pr(this,"connectionConfigs",new Map);pr(this,"pendingConnections",new Map)}static getInstance(){return fL.instance||(fL.instance=new fL),fL.instance}generateConnectionKey(e){return JSON.stringify(e)}async getOrCreateConnection(e,t){const r=this.generateConnectionKey(e),n=this.connections.get(r);if(n&&n.isConnected())return n;const s=Array.from(this.pendingConnections.entries()).find(([l])=>{try{return JSON.parse(l).uuid===e.uuid}catch{return!1}});if(s)try{return await s[1]}catch{}let a=0;Array.from(this.connections.entries()).forEach(([l,u])=>{try{JSON.parse(l).uuid===e.uuid&&(u.disconnect(),this.connections.delete(l),this.connectionConfigs.delete(l),a++)}catch{}}),Array.from(this.pendingConnections.keys()).forEach(l=>{try{JSON.parse(l).uuid===e.uuid&&this.pendingConnections.delete(l)}catch{}});const o=(async()=>{try{const l=new FFn(e,t);return await l.connect(),this.connections.set(r,l),this.connectionConfigs.set(r,e),l}catch(l){throw l}finally{this.pendingConnections.delete(r)}})();return this.pendingConnections.set(r,o),o}hasConnection(e){const t=this.generateConnectionKey(e),r=this.connections.get(t);return r!==void 0&&r.isConnected()}getAllConnections(){return new Map(this.connections)}closeConnection(e){const t=this.generateConnectionKey(e),r=this.connections.get(t);return r?(r.disconnect(),this.connections.delete(t),this.connectionConfigs.delete(t),this.pendingConnections.delete(t),!0):!1}closeAllConnections(){for(const[e,t]of this.connections)t.disconnect(),this.connections.delete(e),this.connectionConfigs.delete(e);return this.connections.clear(),this.connectionConfigs.clear(),this.pendingConnections.clear(),!0}};pr(fL,"instance");let g9=fL;const m5r={getInstance:()=>g9.getInstance(),hasConnection:i=>g9.getInstance().hasConnection(i),closeConnection:i=>g9.getInstance().closeConnection(i),closeAllConnections:()=>{g9.getInstance().closeAllConnections()},removeConnectionByUUID:i=>{const e=g9.getInstance();e.getAllConnections().entries().forEach(([r])=>{const n=JSON.parse(r);n.uuid.includes(i)&&e.closeConnection(n)})},forceCleanAll:()=>{const i=g9.getInstance(),e=i.getAllConnections();Array.from(e.entries()).forEach(([t,r])=>{try{const n=JSON.parse(t);r.disconnect()}catch{}}),i.closeAllConnections()}};class FFn{constructor(e,t={}){pr(this,"client",null);pr(this,"config");pr(this,"callbacks");pr(this,"connectionState","disconnected");pr(this,"reconnectAttempts",0);pr(this,"reconnectTimer",null);pr(this,"connectTimer",null);pr(this,"isManualDisconnect",!1);this.config=e,this.callbacks=t}async connect(){return new Promise((e,t)=>{if(this.client&&this.client.readyState===WebSocket.OPEN){e();return}this.connectionState="connecting";try{this.config.protocols?this.client=new WebSocket(this.config.url,this.config.protocols):this.client=new WebSocket(this.config.url),this.config.binaryType&&(this.client.binaryType=this.config.binaryType),this.config.timeout&&(this.connectTimer=setTimeout(()=>{this.client&&this.client.readyState===WebSocket.CONNECTING&&(this.client.close(),t(new Error("WebSocket连接超时")))},this.config.timeout)),this.client.onopen=()=>{if(this.connectTimer&&(clearTimeout(this.connectTimer),this.connectTimer=null),this.connectionState="connected",this.reconnectAttempts=0,this.isManualDisconnect=!1,this.config.isMessage&&this.config.message&&this.client&&this.client.readyState===WebSocket.OPEN)try{const r=typeof this.config.message=="string"?this.config.message:JSON.stringify(this.config.message);this.client.send(r)}catch{}this.callbacks.onOpen&&this.callbacks.onOpen(),e()},this.client.onclose=()=>{this.connectTimer&&(clearTimeout(this.connectTimer),this.connectTimer=null),this.connectionState="disconnected",!this.isManualDisconnect&&(this.callbacks.onClose&&this.callbacks.onClose(),this.config.reconnect&&this.reconnectAttempts<(this.config.maxReconnectAttempts||1/0)&&this.handleReconnect())},this.client.onmessage=r=>{if(this.callbacks.onMessage){let n=r.data;if(typeof n=="string")try{n=JSON.parse(n)}catch{}this.callbacks.onMessage(n)}},this.client.onerror=r=>{this.connectTimer&&(clearTimeout(this.connectTimer),this.connectTimer=null),this.connectionState="error",this.callbacks.onError&&this.callbacks.onError(r),t(r)}}catch(r){this.connectionState="error",t(r)}})}disconnect(){this.isManualDisconnect=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.connectTimer&&(clearTimeout(this.connectTimer),this.connectTimer=null),this.client&&(this.client.close(),this.client=null,this.connectionState="disconnected")}send(e){if(this.client&&this.client.readyState===WebSocket.OPEN){const t=typeof e=="string"?e:JSON.stringify(e);this.client.send(t)}}isConnected(){return this.client!==null&&this.client.readyState===WebSocket.OPEN}getConnectionState(){return this.connectionState}handleReconnect(){this.reconnectAttempts>=(this.config.maxReconnectAttempts||1/0)||(this.connectionState="reconnecting",this.reconnectAttempts++,this.callbacks.onReconnect&&this.callbacks.onReconnect(),this.reconnectTimer=setTimeout(()=>{this.connect().catch(e=>{})},this.config.reconnectInterval||3e3))}}function RFn(i,e){return g9.getInstance().getOrCreateConnection(i,e)}const PFn=async(i,e,t)=>{try{const{url:r,protocols:n,reconnect:s,reconnectInterval:a,maxReconnectAttempts:o,message:l,isMessage:u,headers:c,isHeaders:d,binaryType:h,timeout:p}=i.source.websocket;if(!r||r.trim()===""){t(jl.noneData(i.id));return}await RFn({uuid:i.id,url:r,protocols:n,reconnect:s,reconnectInterval:a,maxReconnectAttempts:o,message:l,isMessage:u,headers:c,isHeaders:d,binaryType:h,timeout:p},{onOpen:()=>{t(jl.noneData(i.id))},onError:m=>{t(jl.noneData(i.id))},onClose:()=>{t(jl.noneData(i.id))},onReconnect:()=>{t(jl.noneData(i.id))},onMessage:m=>{pl.processData(i.source,m,i.id,e).then(x=>{t(x)}).catch(()=>{t(jl.noneData(i.id))})}})}catch{t(jl.noneData(i.id))}},IFn=(i,e,t,r)=>{if(!Yt.isArray(i))return i;let n=null;return n=i.map((s,a)=>{const o={};return t&&a===0&&(e=MFn(s,e)),Object.keys(e).forEach(l=>{const u=e[l];u.alias?o[u.alias]=s[u.mapping]:o[u.name]=s[u.mapping]}),r&&(o.userdata=s),o}),n},MFn=(i,e)=>{const t=[];return i??(i=[]),Object.keys(i).forEach(r=>{const n=e.find(s=>s.name===r);n?t.push({alias:n.alias,name:r,label:r,mapping:n.mapping}):t.push({alias:r,name:r,label:r,mapping:r})}),t},BFn=(i,e)=>i&&i.reduce((t,r)=>{let n="default";e&&e.find(a=>a.name==="series")&&(n=r[e.find(a=>a.name==="series").name],delete r[e.find(a=>a.name==="series").name]);const s=t.find(a=>a.key===n);return s?s.data.push(r):t.push({key:n,data:[r]}),t},[]),pL=class pL{static addParser(e,t){this.parsers.add({type:e,parser:t})}static getParser(e){const t=Array.from(this.parsers).find(r=>r.type===e);return t==null?void 0:t.parser}static parse({sources:e,callback:t=a=>a||[],noUseMapping:r=!1,isInterval:n=!0,isEditor:s=!1}){try{if(e.length<=0)throw new Error("未找到数据源");e.forEach(a=>{this.handleDataSourceExecution(a,t,r,n,s)})}catch{t(null)}}static handleDataSourceExecution(e,t,r,n,s){if(s){this.executeDataSource(e,t,r,n,s);return}const{id:a,pid:o}=e;if(this.initializeDataSourceState(a),this.checkAndExecuteWaitingChildren(a),o&&o.toString()!=="-1"){const l=this.dataSourceStatePool.get(o);if(!l){this.waitingPool.set(a,{item:e,callback:t,noUseMapping:r,isInterval:n,isEditor:s});return}l.status==="completed"?this.executeDataSource(e,t,r,n,s):(this.waitingPool.set(a,{item:e,callback:t,noUseMapping:r,isInterval:n,isEditor:s}),l.callbacks.push(()=>{this.waitingPool.delete(a),this.executeDataSource(e,t,r,n,s)}))}else this.executeDataSource(e,t,r,n,s)}static initializeDataSourceState(e){this.dataSourceStatePool.has(e)||this.dataSourceStatePool.set(e,{id:e,status:"pending",callbacks:[]})}static markDataSourceExecuting(e){const t=this.dataSourceStatePool.get(e);t&&(t.status="executing")}static markDataSourceCompleted(e){const t=this.dataSourceStatePool.get(e);if(t){t.status="completed";const r=[...t.callbacks];t.callbacks=[],r.forEach(n=>{try{n()}catch{}})}}static checkAndExecuteWaitingChildren(e){if(!this.waitingPool.size)return;const t=[];this.waitingPool.forEach((r,n)=>{r.item.pid===e&&t.push({id:n,...r})});for(const r of t){const n=this.dataSourceStatePool.get(e);n&&(n.status==="completed"?(this.waitingPool.delete(r.id),this.executeDataSource(r.item,r.callback,r.noUseMapping,r.isInterval,r.isEditor)):n.callbacks.push(()=>{this.waitingPool.delete(r.id),this.executeDataSource(r.item,r.callback,r.noUseMapping,r.isInterval,r.isEditor)}))}}static executeDataSource(e,t,r,n,s){if(s){this.executeTask(e,r,s,a=>{t(a)});return}this.markDataSourceExecuting(e.id),this.setupInterval(e,n,r,s,t),this.executeTask(e,r,s,a=>{t(a),this.markDataSourceCompleted(e.id)})}static setupInterval(e,t,r,n,s){if(!t)return;const a=this.timerPool.get(e.id);if(a&&(clearInterval(a),this.timerPool.delete(e.id)),e.source.isAutoUpdate){const o=setInterval(()=>{this.markDataSourceExecuting(e.id),this.executeTask(e,r,n,l=>{s(l),this.markDataSourceCompleted(e.id)})},e.source.autoUpdateTime*1e3);this.timerPool.set(e.id,o)}}static executeTask(e,t,r,n){const s=e,{source:a}=s,o=this.getParser(a.type);o&&o(s,t,l=>{var u;if(r){n(l);return}!t&&((u=s.source.mapping)!=null&&u.length)?(drt(s.source.storage,l.finalKeyData),n(l.finalKeyData)):(drt(s.source.storage,l.noMappingData),n(l.noMappingData))})}static processData(e,t,r,n){const{filter:s,mapping:a,dynamicMapping:o,isUserdata:l}=Yt.cloneDeep(e);return new Promise(function(u){const c=t;pL.filterData(s,t).then(d=>{const h={id:r,finalKeyData:{id:r,data:null},finalUserData:{id:r,data:null},filteredData:{id:r,data:d},rawData:{id:r,data:c},noMappingData:null};if(!n&&a.length){const p=IFn(d,a,o,l);h.finalKeyData.data=p.length?BFn(p,a):d,h.finalUserData.data=p.length?p:d}else h.finalUserData.data=d,h.noMappingData=d;u(h)})})}static async filterData(e,t){if(!Yt.isString(e))return t;try{let r=e.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g,"");r=jl.replaceStringVariables(r);const n=`
33393
33393
  ${r}
33394
33394
  if (typeof filter !== 'function') {
33395
33395
  throw new Error('filter function is not defined in the provided code');