@meta2d/core 1.1.20 → 1.1.21

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.
package/src/core.d.ts CHANGED
@@ -270,10 +270,10 @@ export declare class Meta2d {
270
270
  iotAggregatePublish(item: any): void;
271
271
  closeIot(): void;
272
272
  connectSqls(): void;
273
- connectSSE(net: Network): void;
273
+ connectSSE(net: Network): Promise<void>;
274
274
  closeSSE(): void;
275
- connectNetMqtt(net: Network): void;
276
- connectNetWebSocket(net: Network): void;
275
+ connectNetMqtt(net: Network): Promise<void>;
276
+ connectNetWebSocket(net: Network): Promise<void>;
277
277
  getMqttUrl(): Promise<{
278
278
  username: any;
279
279
  password: any;
package/src/core.js CHANGED
@@ -695,6 +695,8 @@ export class Meta2d {
695
695
  //图纸更新
696
696
  const data = await getMeta2dData(this.store, id);
697
697
  if (data) {
698
+ data.locked = 1;
699
+ data.fits?.length && (globalThis.meta2dData = JSON.stringify(data));
698
700
  this.canvas.opening = true;
699
701
  this.open(data);
700
702
  this.lock(1);
@@ -2681,10 +2683,19 @@ export class Meta2d {
2681
2683
  });
2682
2684
  }
2683
2685
  }
2684
- connectSSE(net) {
2686
+ async connectSSE(net) {
2685
2687
  if (net.enable === false) {
2686
2688
  return;
2687
2689
  }
2690
+ if (net.preJs) {
2691
+ if (!net.preFn) {
2692
+ const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
2693
+ net.preFn = new AsyncFunction('network', net.preJs);
2694
+ }
2695
+ if (net.preFn) {
2696
+ net = await net.preFn(net);
2697
+ }
2698
+ }
2688
2699
  this.eventSources[net.index] = new EventSource(net.url, { withCredentials: net.withCredentials });
2689
2700
  this.eventSources[net.index].onmessage = (e) => {
2690
2701
  this.socketCallback(e.data, { type: 'SSE', url: net.url, name: net.name, net });
@@ -2702,10 +2713,19 @@ export class Meta2d {
2702
2713
  }
2703
2714
  });
2704
2715
  }
2705
- connectNetMqtt(net) {
2716
+ async connectNetMqtt(net) {
2706
2717
  if (net.enable === false) {
2707
2718
  return;
2708
2719
  }
2720
+ if (net.preJs) {
2721
+ if (!net.preFn) {
2722
+ const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
2723
+ net.preFn = new AsyncFunction('network', net.preJs);
2724
+ }
2725
+ if (net.preFn) {
2726
+ net = await net.preFn(net);
2727
+ }
2728
+ }
2709
2729
  if (net.options.clientId && !net.options.customClientId) {
2710
2730
  net.options.clientId = s8();
2711
2731
  }
@@ -2806,7 +2826,7 @@ export class Meta2d {
2806
2826
  }
2807
2827
  });
2808
2828
  }
2809
- connectNetWebSocket(net) {
2829
+ async connectNetWebSocket(net) {
2810
2830
  if (this.websockets[net.index]) {
2811
2831
  this.websockets[net.index].onclose = undefined;
2812
2832
  this.websockets[net.index]?.close();
@@ -2815,6 +2835,15 @@ export class Meta2d {
2815
2835
  if (net.enable === false) {
2816
2836
  return;
2817
2837
  }
2838
+ if (net.preJs) {
2839
+ if (!net.preFn) {
2840
+ const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
2841
+ net.preFn = new AsyncFunction('network', net.preJs);
2842
+ }
2843
+ if (net.preFn) {
2844
+ net = await net.preFn(net);
2845
+ }
2846
+ }
2818
2847
  let url = net.url;
2819
2848
  if (url.indexOf('${') > -1) {
2820
2849
  let keys = url.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
@@ -3239,6 +3268,16 @@ export class Meta2d {
3239
3268
  }
3240
3269
  async requestHttp(_req) {
3241
3270
  let req = deepClone(_req);
3271
+ const net = this.store.data.networks.filter((item) => item.protocol === 'http')[req.index];
3272
+ if (net.preJs) {
3273
+ if (!net.preFn) {
3274
+ const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor;
3275
+ net.preFn = new AsyncFunction('network', net.preJs);
3276
+ }
3277
+ if (net.preFn) {
3278
+ req = await net.preFn(req);
3279
+ }
3280
+ }
3242
3281
  if (req.url) {
3243
3282
  if (req.url.indexOf('${') > -1) {
3244
3283
  let keys = req.url.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
@@ -3298,7 +3337,6 @@ export class Meta2d {
3298
3337
  });
3299
3338
  if (res.ok) {
3300
3339
  const data = await res.text();
3301
- const net = this.store.data.networks.filter(item => item.protocol === 'http')[req.index];
3302
3340
  this.socketCallback(data, { type: 'http', method: req.method, url: req.url, name: req.name, net });
3303
3341
  }
3304
3342
  else {
@@ -5653,7 +5691,11 @@ export class Meta2d {
5653
5691
  }
5654
5692
  this.setValue({ id: pen.id, canvasLayer: layer }, { render: false, doEvent: false, history: false });
5655
5693
  }
5656
- else if (pen.externElement || pen.name === 'gif') {
5694
+ else if (pen.name.endsWith('Dom') ||
5695
+ isDomShapes.includes(pen.name) ||
5696
+ this.store.options.domShapes.includes(pen.name) ||
5697
+ pen.externElement ||
5698
+ pen.name === 'gif') {
5657
5699
  let zIndex = 0;
5658
5700
  // let zIndex = pen.calculative.zIndex === undefined ? 5 : pen.calculative.zIndex + 1;
5659
5701
  if (type === 'top') {