@meta2d/core 1.0.67 → 1.0.68

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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { commonAnchors, commonPens, cube } from './diagrams';
1
+ import { commonAnchors, commonPens, cube, reset, updateFormData } from './diagrams';
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, getGlobalColor, isDomShapes, } from './pen';
4
4
  import { rotatePoint } from './point';
@@ -16,6 +16,7 @@ import { getter } from './utils/object';
16
16
  import { getCookie, getMeta2dData, queryURLParams } from './utils/url';
17
17
  import { HotkeyType } from './data';
18
18
  import { Message, messageList } from './message';
19
+ import { le5leTheme } from './theme';
19
20
  export class Meta2d {
20
21
  store;
21
22
  canvas;
@@ -146,12 +147,9 @@ export class Meta2d {
146
147
  ruleColor: this.store.theme[theme].ruleColor,
147
148
  ruleOptions: this.store.theme[theme].ruleOptions,
148
149
  });
150
+ // 更新全局的主题css变量
151
+ le5leTheme.updateCssRule(this.store.id, theme);
149
152
  this.render();
150
- // 更新pen的主题
151
- for (let i = 0; i < this.store.data.pens.length; i++) {
152
- const pen = this.store.data.pens[i];
153
- pen.onSetTheme?.(theme, this.store.theme[theme]);
154
- }
155
153
  }
156
154
  setDatabyOptions(options = {}) {
157
155
  const { color, activeColor, activeBackground, grid, gridColor, gridSize, fromArrow, toArrow, rule, ruleColor, textColor, x = 0, y = 0, } = options;
@@ -181,6 +179,10 @@ export class Meta2d {
181
179
  }
182
180
  this.resize();
183
181
  this.canvas.listen();
182
+ // 创建主题样式表
183
+ if (this.store.data.theme) {
184
+ le5leTheme.createThemeSheet(this.store.data.theme, this.store.id);
185
+ }
184
186
  }
185
187
  initEventFns() {
186
188
  this.events[EventAction.Link] = (pen, e) => {
@@ -357,7 +359,7 @@ export class Meta2d {
357
359
  if (e.params && typeof e.params === 'string') {
358
360
  let url = e.params;
359
361
  if (e.params.includes('${')) {
360
- let keys = e.params.match(/(?<=\$\{).*?(?=\})/g);
362
+ let keys = e.params.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
361
363
  if (keys) {
362
364
  keys?.forEach((key) => {
363
365
  url = url.replace(`\${${key}}`, pen[key]);
@@ -390,7 +392,7 @@ export class Meta2d {
390
392
  }
391
393
  else if (typeof item.value[key] === 'string' &&
392
394
  item.value[key]?.indexOf('${') > -1) {
393
- let keys = item.value[key].match(/(?<=\$\{).*?(?=\})/g);
395
+ let keys = item.value[key].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
394
396
  if (keys?.length) {
395
397
  list[index].properties[key] =
396
398
  _pen[keys[0]] ?? this.getDynamicParam(keys[0]);
@@ -423,6 +425,10 @@ export class Meta2d {
423
425
  if (pen.deviceId) {
424
426
  value.deviceId = pen.deviceId;
425
427
  }
428
+ if (pen.formId && pen.formData) {
429
+ //表单数据
430
+ Object.assign(value, pen.formData);
431
+ }
426
432
  this.sendDataToNetWork(value, pen, e);
427
433
  return;
428
434
  // }
@@ -437,7 +443,7 @@ export class Meta2d {
437
443
  }
438
444
  else if (typeof value[key] === 'string' &&
439
445
  value[key]?.indexOf('${') > -1) {
440
- let keys = value[key].match(/(?<=\$\{).*?(?=\})/g);
446
+ let keys = value[key].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
441
447
  if (keys?.length) {
442
448
  value[key] = _pen[keys[0]] ?? this.getDynamicParam(keys[0]);
443
449
  }
@@ -499,7 +505,7 @@ export class Meta2d {
499
505
  }
500
506
  else if (typeof item.value[key] === 'string' &&
501
507
  item.value[key]?.indexOf('${') > -1) {
502
- let keys = item.value[key].match(/(?<=\$\{).*?(?=\})/g);
508
+ let keys = item.value[key].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
503
509
  if (keys?.length) {
504
510
  value[key] = _pen[keys[0]] ?? this.getDynamicParam(keys[0]);
505
511
  }
@@ -514,7 +520,7 @@ export class Meta2d {
514
520
  return value;
515
521
  }
516
522
  else
517
- return null;
523
+ return {};
518
524
  }
519
525
  message(options) {
520
526
  const message = new Message(this.canvas.parentElement, options);
@@ -588,7 +594,7 @@ export class Meta2d {
588
594
  if (typeof network.headers === 'object') {
589
595
  for (let i in network.headers) {
590
596
  if (typeof network.headers[i] === 'string') {
591
- let keys = network.headers[i].match(/(?<=\$\{).*?(?=\})/g);
597
+ let keys = network.headers[i].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
592
598
  if (keys) {
593
599
  network.headers[i] = network.headers[i].replace(`\${${keys[0]}}`, this.getDynamicParam(keys[0]));
594
600
  }
@@ -606,7 +612,7 @@ export class Meta2d {
606
612
  }
607
613
  if (network.method === 'POST') {
608
614
  if (url.indexOf('${') > -1) {
609
- let keys = url.match(/(?<=\$\{).*?(?=\})/g);
615
+ let keys = url.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
610
616
  if (keys) {
611
617
  keys.forEach((key) => {
612
618
  url = url.replace(`\${${key}}`, getter(pen, key) || this.getDynamicParam(key));
@@ -770,6 +776,10 @@ export class Meta2d {
770
776
  this.clear(false, data?.template);
771
777
  this.canvas.autoPolylineFlag = true;
772
778
  if (data) {
779
+ // 根据图纸的主题设置主题
780
+ if (data.theme) {
781
+ this.setTheme(data.theme);
782
+ }
773
783
  this.setBackgroundImage(data.bkImage, data);
774
784
  Object.assign(this.store.data, data);
775
785
  this.store.data.pens = [];
@@ -2388,7 +2398,7 @@ export class Meta2d {
2388
2398
  let req = deepClone(_req);
2389
2399
  if (req.url) {
2390
2400
  if (req.url.indexOf('${') > -1) {
2391
- let keys = req.url.match(/(?<=\$\{).*?(?=\})/g);
2401
+ let keys = req.url.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
2392
2402
  if (keys) {
2393
2403
  keys.forEach((key) => {
2394
2404
  req.url = req.url.replace(`\${${key}}`, this.getDynamicParam(key));
@@ -2398,7 +2408,7 @@ export class Meta2d {
2398
2408
  if (typeof req.headers === 'object') {
2399
2409
  for (let i in req.headers) {
2400
2410
  if (typeof req.headers[i] === 'string') {
2401
- let keys = req.headers[i].match(/(?<=\$\{).*?(?=\})/g);
2411
+ let keys = req.headers[i].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
2402
2412
  if (keys) {
2403
2413
  req.headers[i] = req.headers[i].replace(`\${${keys[0]}}`, this.getDynamicParam(keys[0]));
2404
2414
  }
@@ -2408,7 +2418,7 @@ export class Meta2d {
2408
2418
  if (typeof req.body === 'object') {
2409
2419
  for (let i in req.body) {
2410
2420
  if (typeof req.body[i] === 'string') {
2411
- let keys = req.body[i].match(/(?<=\$\{).*?(?=\})/g);
2421
+ let keys = req.body[i].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
2412
2422
  if (keys) {
2413
2423
  req.body[i] = req.body[i].replace(`\${${keys[0]}}`, this.getDynamicParam(keys[0]));
2414
2424
  }
@@ -2752,6 +2762,16 @@ export class Meta2d {
2752
2762
  e.pen.calculative.radialGradient = undefined;
2753
2763
  }
2754
2764
  }
2765
+ if (e.pen && e.pen.formId) {
2766
+ const formPen = this.store.pens[e.pen.formId];
2767
+ if (e.pen.formType === 'submit') {
2768
+ this.store.data.locked && formPen && !formPen.disabled && this.doEvent(formPen, 'submit');
2769
+ }
2770
+ else if (e.pen.formType === 'reset') {
2771
+ reset(e.pen);
2772
+ this.store.data.locked && formPen && !formPen.disabled && this.doEvent(formPen, 'reset');
2773
+ }
2774
+ }
2755
2775
  e.pen &&
2756
2776
  e.pen.onClick &&
2757
2777
  !e.pen.disabled &&
@@ -2798,6 +2818,7 @@ export class Meta2d {
2798
2818
  this.doEvent(e.pen, eventName);
2799
2819
  break;
2800
2820
  case 'valueUpdate':
2821
+ e && updateFormData(e, e.formValue);
2801
2822
  this.store.data.locked && this.doEvent(e, eventName);
2802
2823
  this.canvas.tooltip.updateText(e);
2803
2824
  break;
@@ -2821,6 +2842,7 @@ export class Meta2d {
2821
2842
  this.doEvent(e, eventName);
2822
2843
  break;
2823
2844
  case 'change':
2845
+ e.pen && updateFormData(e.pen);
2824
2846
  this.store.data.locked &&
2825
2847
  e &&
2826
2848
  !e.disabled &&
@@ -5183,6 +5205,7 @@ export class Meta2d {
5183
5205
  this.closeSocket();
5184
5206
  this.closeNetwork();
5185
5207
  this.closeAll();
5208
+ le5leTheme.destroyThemeSheet(this.store.id);
5186
5209
  this.store.emitter.all.clear(); // 内存释放
5187
5210
  this.canvas.destroy();
5188
5211
  this.canvas = undefined;