@meta2d/core 1.0.80 → 1.0.81-alpha.1

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
@@ -3,7 +3,7 @@ import { Canvas } from './canvas';
3
3
  import { Options, PenPlugin, PluginOptions } from './options';
4
4
  import { calcTextDrawRect, calcTextLines, calcTextRect, facePen, getWords, LockState, Pen, renderPenRaw, IValue, setElemPosition } from './pen';
5
5
  import { Point } from './point';
6
- import { EditAction, register, registerAnchors, registerCanvasDraw, registerLineAnimateDraws, Meta2dData, Meta2dStore, Network, HttpOptions, Sql } from './store';
6
+ import { EditAction, register, registerAnchors, registerCanvasDraw, Meta2dData, Meta2dStore, Network, HttpOptions, Sql } from './store';
7
7
  import { Padding } from './utils';
8
8
  import { Rect } from './rect';
9
9
  import { Event, TriggerCondition } from './event';
@@ -149,7 +149,8 @@ export declare class Meta2d {
149
149
  register: typeof register;
150
150
  registerCanvasDraw: typeof registerCanvasDraw;
151
151
  registerAnchors: typeof registerAnchors;
152
- registerLineAnimateDraws: typeof registerLineAnimateDraws;
152
+ registerLineAnimateDraws: (name: any, drawFunc: any) => void;
153
+ updateLineAnimateDraws(name: any, option: any): void;
153
154
  registerMoveDock(dock: (store: Meta2dStore, rect: Rect, pens: Pen[], offset: Point) => {
154
155
  xDock: Point;
155
156
  yDock: Point;
package/src/core.js CHANGED
@@ -2,7 +2,7 @@ import { commonAnchors, commonPens, cube, reset, updateFormData } from './diagra
2
2
  import { Canvas } from './canvas';
3
3
  import { calcInView, calcTextDrawRect, calcTextLines, calcTextRect, facePen, formatAttrs, getAllChildren, getFromAnchor, getParent, getToAnchor, getWords, LockState, PenType, renderPenRaw, setElemPosition, connectLine, nearestAnchor, setChildValue, isAncestor, isShowChild, CanvasLayer, validationPlugin, setLifeCycleFunc, getAllFollowers, isInteraction, calcWorldAnchors, isDomShapes, } from './pen';
4
4
  import { rotatePoint } from './point';
5
- import { clearStore, EditType, globalStore, register, registerAnchors, registerCanvasDraw, registerLineAnimateDraws, useStore, } from './store';
5
+ import { clearStore, EditType, globalStore, register, registerAnchors, registerCanvasDraw, useStore, } from './store';
6
6
  import { formatPadding, loadCss, s8, valueInArray, valueInRange, } from './utils';
7
7
  import { calcCenter, calcRelativeRect, calcRightBottom, getRect, rectInRect, } from './rect';
8
8
  import { deepClone } from './utils/clone';
@@ -229,7 +229,16 @@ export class Meta2d {
229
229
  initEventFns() {
230
230
  this.events[EventAction.Link] = (pen, e) => {
231
231
  if (window && e.value && typeof e.value === 'string') {
232
- window.open(e.value, e.params ?? '_blank');
232
+ let url = e.value;
233
+ if (url.includes('${')) {
234
+ let keys = url.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
235
+ if (keys) {
236
+ keys?.forEach((key) => {
237
+ url = url.replace(`\${${key}}`, pen[key] || this.getDynamicParam(key));
238
+ });
239
+ }
240
+ }
241
+ window.open(url, e.params ?? '_blank');
233
242
  return;
234
243
  }
235
244
  console.warn('[meta2d] Link param is not a string');
@@ -239,13 +248,34 @@ export class Meta2d {
239
248
  const value = e.value;
240
249
  if (value && typeof value === 'object') {
241
250
  const pens = e.params ? this.find(e.params) : this.find(pen.id);
251
+ const _value = {};
252
+ for (let key in value) {
253
+ if (value[key]?.id) {
254
+ _value[key] = this.store.pens[value[key].id]?.[value[key].key];
255
+ }
256
+ else {
257
+ if (typeof value[key] === 'string' && value[key].includes('${')) {
258
+ let __value = value[key];
259
+ let keys = __value.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
260
+ if (keys) {
261
+ keys.forEach((key) => {
262
+ __value = __value.replace(`\${${key}}`, pen[key] || this.getDynamicParam(key));
263
+ });
264
+ }
265
+ _value[key] = __value;
266
+ }
267
+ else {
268
+ _value[key] = value[key];
269
+ }
270
+ }
271
+ }
242
272
  pens.forEach((pen) => {
243
- if (value.hasOwnProperty('visible')) {
244
- if (pen.visible !== value.visible) {
245
- this.setVisible(pen, value.visible);
273
+ if (_value.hasOwnProperty('visible')) {
274
+ if (pen.visible !== _value.visible) {
275
+ this.setVisible(pen, _value.visible);
246
276
  }
247
277
  }
248
- this.setValue({ id: pen.id, ...value }, { render: false, doEvent: false });
278
+ this.setValue({ id: pen.id, ..._value }, { render: false, doEvent: false });
249
279
  });
250
280
  this.render();
251
281
  return;
@@ -404,7 +434,7 @@ export class Meta2d {
404
434
  let keys = e.params.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
405
435
  if (keys) {
406
436
  keys?.forEach((key) => {
407
- url = url.replace(`\${${key}}`, pen[key]);
437
+ url = url.replace(`\${${key}}`, pen[key] || this.getDynamicParam(key));
408
438
  });
409
439
  }
410
440
  }
@@ -526,7 +556,19 @@ export class Meta2d {
526
556
  value[item.prop] = pen[item.key];
527
557
  }
528
558
  else {
529
- value[item.prop] = this.convertType(item.value, item.type);
559
+ if (typeof item.value === 'string' && item.value.includes('${')) {
560
+ let _value = item.value;
561
+ let keys = _value.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
562
+ if (keys) {
563
+ keys.forEach((key) => {
564
+ _value = _value.replace(`\${${key}}`, this.getDynamicParam(key));
565
+ });
566
+ }
567
+ value[item.prop] = _value;
568
+ }
569
+ else {
570
+ value[item.prop] = this.convertType(item.value, item.type);
571
+ }
530
572
  }
531
573
  }
532
574
  });
@@ -956,6 +998,7 @@ export class Meta2d {
956
998
  this.render();
957
999
  }
958
1000
  loadLineAnimateDraws() {
1001
+ globalStore.lineAnimateDraws = {};
959
1002
  Object.entries(this.store.data.lineAnimateDraws).forEach(([key, drawFunc]) => {
960
1003
  globalStore.lineAnimateDraws[key] = eval(drawFunc);
961
1004
  });
@@ -1326,7 +1369,22 @@ export class Meta2d {
1326
1369
  register = register;
1327
1370
  registerCanvasDraw = registerCanvasDraw;
1328
1371
  registerAnchors = registerAnchors;
1329
- registerLineAnimateDraws = registerLineAnimateDraws;
1372
+ registerLineAnimateDraws = (name, drawFunc) => {
1373
+ drawFunc = typeof drawFunc === 'string' ? drawFunc : drawFunc.toString();
1374
+ this.store.data.lineAnimateDraws[name] = drawFunc;
1375
+ // 同步到store
1376
+ globalStore.lineAnimateDraws[name] = eval(drawFunc);
1377
+ };
1378
+ updateLineAnimateDraws(name, option) {
1379
+ if (!option)
1380
+ return;
1381
+ delete this.store.data.lineAnimateDraws[name];
1382
+ delete globalStore.lineAnimateDraws[name];
1383
+ if (option === -1) { // -1 表示删除
1384
+ return;
1385
+ }
1386
+ this.registerLineAnimateDraws(option.name || name, option.code);
1387
+ }
1330
1388
  // customeDock = (store, rect, pens, offset) => {xDock, yDock}
1331
1389
  // customDock return:
1332
1390
  // {
@@ -1476,6 +1534,7 @@ export class Meta2d {
1476
1534
  pen.currentAnimation = undefined;
1477
1535
  pen.calculative.pause = undefined;
1478
1536
  pen.calculative.start = undefined;
1537
+ pen.calculative.cycleStart = undefined;
1479
1538
  pen.calculative.duration = undefined;
1480
1539
  pen.calculative.animatePos = 0;
1481
1540
  this.store.animates.delete(pen);
@@ -2330,7 +2389,24 @@ export class Meta2d {
2330
2389
  }
2331
2390
  }
2332
2391
  net.times = 0;
2333
- this.mqttClients[net.index] = mqtt.connect(url, net.options);
2392
+ let options = deepClone(net.options);
2393
+ if (options?.username && options.username.includes('${')) {
2394
+ let keys = options.username.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
2395
+ if (keys) {
2396
+ keys.forEach((key) => {
2397
+ options.username = options.username.replace(`\${${key}}`, this.getDynamicParam(key));
2398
+ });
2399
+ }
2400
+ }
2401
+ if (options?.password && options.password.includes('${')) {
2402
+ let keys = options.password.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
2403
+ if (keys) {
2404
+ keys.forEach((key) => {
2405
+ options.password = options.password.replace(`\${${key}}`, this.getDynamicParam(key));
2406
+ });
2407
+ }
2408
+ }
2409
+ this.mqttClients[net.index] = mqtt.connect(url, options);
2334
2410
  this.mqttClients[net.index].on('message', (topic, message) => {
2335
2411
  this.socketCallback(message.toString(), {
2336
2412
  topic,
@@ -2352,7 +2428,16 @@ export class Meta2d {
2352
2428
  }
2353
2429
  });
2354
2430
  if (net.topics) {
2355
- this.mqttClients[net.index].subscribe(net.topics.split(','));
2431
+ let topics = net.topics;
2432
+ if (topics.indexOf('${') > -1) {
2433
+ let keys = topics.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
2434
+ if (keys) {
2435
+ keys.forEach((key) => {
2436
+ topics = topics.replace(`\${${key}}`, this.getDynamicParam(key));
2437
+ });
2438
+ }
2439
+ }
2440
+ this.mqttClients[net.index].subscribe(topics.split(','));
2356
2441
  }
2357
2442
  }
2358
2443
  connectNetWebSocket(net) {
@@ -3169,13 +3254,19 @@ export class Meta2d {
3169
3254
  break;
3170
3255
  case 'change':
3171
3256
  e.pen && updateFormData(e.pen);
3172
- this.store.data.locked &&
3173
- e &&
3174
- !e.disabled &&
3175
- this.doEvent(e, eventName);
3257
+ if (e.pen) {
3258
+ this.store.data.locked && !e.pen.disabled &&
3259
+ this.doEvent(e.pen, eventName);
3260
+ }
3261
+ else {
3262
+ this.store.data.locked &&
3263
+ e &&
3264
+ !e.disabled &&
3265
+ this.doEvent(e, eventName);
3266
+ }
3176
3267
  break;
3177
3268
  }
3178
- this.doMessageEvent(eventName);
3269
+ this.doMessageEvent(eventName, e);
3179
3270
  };
3180
3271
  doEvent = (pen, eventName) => {
3181
3272
  if (!pen) {