@meta2d/core 1.0.84 → 1.0.86

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
@@ -101,6 +101,8 @@ export declare class Meta2d {
101
101
  ruleColor?: string;
102
102
  }): void;
103
103
  open(data?: Meta2dData, render?: boolean): void;
104
+ dirtyData(active?: boolean): any[];
105
+ clearDirtyData(): void;
104
106
  cacheData(id: string): void;
105
107
  loadCacheData(id: string): void;
106
108
  loadLineAnimateDraws(): void;
package/src/core.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { commonAnchors, commonPens, cube, reset, updateFormData } from './diagrams';
2
2
  import { Canvas } from './canvas';
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';
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, defaultFormat, findOutliersByZScore, } from './pen';
4
4
  import { rotatePoint } from './point';
5
5
  import { clearStore, EditType, globalStore, register, registerAnchors, registerCanvasDraw, useStore, } from './store';
6
6
  import { formatPadding, loadCss, s8, valueInArray, valueInRange, } from './utils';
@@ -177,18 +177,20 @@ export class Meta2d {
177
177
  this.setBackgroundColor(this.store.theme[theme].background);
178
178
  this.canvas.parentElement.style.background =
179
179
  this.store.theme[theme].parentBackground;
180
- this.store.data.color = this.store.theme[theme].color;
181
180
  this.setOptions({
182
181
  ruleColor: this.store.theme[theme].ruleColor,
183
182
  ruleOptions: this.store.theme[theme].ruleOptions,
184
183
  });
185
184
  // 更新全局的主题css变量
186
- le5leTheme.updateCssRule(this.store.id, theme);
187
- this.canvas.initGlobalStyle();
188
- for (let i = 0; i < this.store.data.pens.length; i++) {
189
- const pen = this.store.data.pens[i];
190
- // 调用pen的主题设置函数,如果单个pen有主题的自定义设置的话
191
- pen.setTheme && pen.setTheme(pen, this.store.styles);
185
+ if (!(this.store.options.themeOnlyCanvas || this.store.data.themeOnlyCanvas)) {
186
+ this.store.data.color = this.store.theme[theme].color;
187
+ le5leTheme.updateCssRule(this.store.id, theme);
188
+ this.canvas.initGlobalStyle();
189
+ for (let i = 0; i < this.store.data.pens.length; i++) {
190
+ const pen = this.store.data.pens[i];
191
+ // 调用pen的主题设置函数,如果单个pen有主题的自定义设置的话
192
+ pen.setTheme && pen.setTheme(pen, this.store.styles);
193
+ }
192
194
  }
193
195
  this.render();
194
196
  }
@@ -696,14 +698,25 @@ export class Meta2d {
696
698
  }
697
699
  if (network.protocol === 'http') {
698
700
  if (typeof network.headers === 'object') {
699
- for (let i in network.headers) {
700
- if (typeof network.headers[i] === 'string') {
701
- let keys = network.headers[i].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
702
- if (keys) {
703
- network.headers[i] = network.headers[i].replace(`\${${keys[0]}}`, this.getDynamicParam(keys[0]));
704
- }
701
+ /*for (let i in network.headers) {
702
+ if (typeof network.headers[i] === 'string') {
703
+ let keys = network.headers[i].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
704
+ if (keys) {
705
+ network.headers[i] = network.headers[i].replace(
706
+ `\${${keys[0]}}`,
707
+ this.getDynamicParam(keys[0])
708
+ );
709
+ }
710
+ }
711
+ }*/
712
+ let headersStr = JSON.stringify(network.headers);
713
+ let keys = headersStr.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
714
+ if (keys?.length) {
715
+ for (let i = 0; i < keys.length; i++) {
716
+ headersStr = headersStr.replace(`\${${keys[i]}}`, this.getDynamicParam(keys[i]));
705
717
  }
706
718
  }
719
+ network.headers = JSON.parse(headersStr);
707
720
  }
708
721
  let params = undefined;
709
722
  let url = network.url;
@@ -948,6 +961,53 @@ export class Meta2d {
948
961
  this.canvas.scroll.init();
949
962
  }
950
963
  }
964
+ dirtyData(active) {
965
+ //获取画布脏数据
966
+ const pens = this.store.data.pens;
967
+ const width = this.store.data.width || this.store.options.width;
968
+ const height = this.store.data.height || this.store.options.height;
969
+ const dirtyPens = [];
970
+ for (let i = pens.length - 1; i >= 0; i--) {
971
+ let pen = pens[i];
972
+ if (pen.parentId) {
973
+ const parent = this.store.pens[pen.parentId];
974
+ if (pen.x > 10 || pen.y > 10 || pen.width > 10 || pen.height > 10) {
975
+ // 子图元坐标值很大
976
+ dirtyPens.push(pen);
977
+ }
978
+ else if (!parent.children || !parent.children.includes(pen.id)) {
979
+ //已经解组但子图元还有父图元id
980
+ dirtyPens.push(pen);
981
+ }
982
+ }
983
+ if (width && height) {
984
+ //大屏区域外
985
+ let rect = this.getPenRect(pen);
986
+ if (rect.x < -10 || rect.y < -10 || rect.x + rect.width > width || rect.y + rect.height > height) {
987
+ dirtyPens.push(pen);
988
+ }
989
+ }
990
+ //无效连线 单个锚点连线
991
+ }
992
+ if (!width || !height) {
993
+ //2d 偏移量很大
994
+ let outpens = findOutliersByZScore(pens);
995
+ outpens.forEach((item) => {
996
+ let repeat = dirtyPens.filter((_item) => _item.id === item.id);
997
+ if (!repeat.length) {
998
+ dirtyPens.push(item);
999
+ }
1000
+ });
1001
+ }
1002
+ if (active) {
1003
+ this.active(dirtyPens);
1004
+ }
1005
+ return dirtyPens;
1006
+ }
1007
+ clearDirtyData() {
1008
+ let dirtyPens = this.dirtyData();
1009
+ this.delete(dirtyPens, true);
1010
+ }
951
1011
  cacheData(id) {
952
1012
  if (id && this.store.options.cacheLength) {
953
1013
  let index = this.store.cacheDatas.findIndex((item) => item.data && item.data._id === id);
@@ -1848,27 +1908,33 @@ export class Meta2d {
1848
1908
  calcRightBottom(rect);
1849
1909
  calcCenter(rect);
1850
1910
  child.calculative.worldRect = rect;
1851
- if (rectInRect(rect, parent.calculative.worldRect, true)) {
1911
+ if (parent.container && rectInRect(rect, parent.calculative.worldRect, true)) { //取所有图元的范围
1852
1912
  const childRect = calcRelativeRect(rect, parent.calculative.worldRect);
1853
1913
  Object.assign(child, childRect);
1854
1914
  }
1855
1915
  else {
1856
- let x = Math.min(rect.x, parent.calculative.worldRect.x);
1857
- let y = Math.min(rect.y, parent.calculative.worldRect.y);
1858
- let ex = Math.max(rect.ex, parent.calculative.worldRect.ex);
1859
- let ey = Math.max(rect.ey, parent.calculative.worldRect.ey);
1860
- parent.calculative.worldRect = {
1861
- x: x,
1862
- y: y,
1863
- width: ex - x,
1864
- height: ey - y,
1865
- ex,
1866
- ey,
1867
- };
1916
+ if (parent.container) { //容器模式取操作过程中最大范围
1917
+ let x = Math.min(rect.x, parent.calculative.worldRect.x);
1918
+ let y = Math.min(rect.y, parent.calculative.worldRect.y);
1919
+ let ex = Math.max(rect.ex, parent.calculative.worldRect.ex);
1920
+ let ey = Math.max(rect.ey, parent.calculative.worldRect.ey);
1921
+ parent.calculative.worldRect = {
1922
+ x: x,
1923
+ y: y,
1924
+ width: ex - x,
1925
+ height: ey - y,
1926
+ ex,
1927
+ ey,
1928
+ };
1929
+ calcCenter(parent.calculative.worldRect);
1930
+ }
1931
+ else { //取所有图元的范围
1932
+ const pens = parent.children.map((cid) => this.store.pens[cid]);
1933
+ parent.calculative.worldRect = getRect(pens);
1934
+ }
1868
1935
  if (!parent.parentId) {
1869
1936
  Object.assign(parent, parent.calculative.worldRect);
1870
1937
  }
1871
- calcCenter(parent.calculative.worldRect);
1872
1938
  parent.children.forEach((cid) => {
1873
1939
  const cPen = this.store.pens[cid];
1874
1940
  const childRect = calcRelativeRect(cPen.calculative.worldRect, parent.calculative.worldRect);
@@ -2548,7 +2614,17 @@ export class Meta2d {
2548
2614
  const method = sql.method || 'get';
2549
2615
  let _sql = sql.sql;
2550
2616
  if (method === 'list') {
2551
- _sql += ` LIMIT ${sql.pageSize || 20}` + (sql.current > 1 ? (' OFFSET ' + (sql.current - 1) * sql.pageSize) : '');
2617
+ // _sql+= ` LIMIT ${sql.pageSize||20}`+(sql.current>1?(' OFFSET '+(sql.current-1)*sql.pageSize):'');
2618
+ if (sql.dbType === "oracle") {
2619
+ if (!_sql.includes('OFFSET')) {
2620
+ _sql += ` OFFSET ${(sql.current || 1 - 1) * (sql.pageSize || 20)} ROWS FETCH NEXT ${sql.pageSize || 20} ROWS ONLY`;
2621
+ }
2622
+ }
2623
+ else {
2624
+ if (!_sql.includes('LIMIT')) {
2625
+ _sql += ` LIMIT ${sql.pageSize || 20}` + (sql.current > 1 ? (' OFFSET ' + (sql.current - 1) * (sql.pageSize || 20)) : '');
2626
+ }
2627
+ }
2552
2628
  }
2553
2629
  const res = await fetch(`/api/iot/data/sql/${method}`, {
2554
2630
  method: 'POST',
@@ -2883,24 +2959,46 @@ export class Meta2d {
2883
2959
  }
2884
2960
  }
2885
2961
  if (typeof req.headers === 'object') {
2886
- for (let i in req.headers) {
2887
- if (typeof req.headers[i] === 'string') {
2888
- let keys = req.headers[i].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
2889
- if (keys) {
2890
- req.headers[i] = req.headers[i].replace(`\${${keys[0]}}`, this.getDynamicParam(keys[0]));
2891
- }
2962
+ /*for (let i in req.headers) {
2963
+ if (typeof req.headers[i] === 'string') {
2964
+ let keys = req.headers[i].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
2965
+ if (keys) {
2966
+ req.headers[i] = req.headers[i].replace(
2967
+ `\${${keys[0]}}`,
2968
+ this.getDynamicParam(keys[0])
2969
+ );
2970
+ }
2971
+ }
2972
+ }*/
2973
+ let headersStr = JSON.stringify(req.headers);
2974
+ let keys = headersStr.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
2975
+ if (keys?.length) {
2976
+ for (let i = 0; i < keys.length; i++) {
2977
+ headersStr = headersStr.replace(`\${${keys[i]}}`, this.getDynamicParam(keys[i]));
2892
2978
  }
2893
2979
  }
2980
+ req.headers = JSON.parse(headersStr);
2894
2981
  }
2895
2982
  if (typeof req.body === 'object') {
2896
- for (let i in req.body) {
2897
- if (typeof req.body[i] === 'string') {
2898
- let keys = req.body[i].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
2899
- if (keys) {
2900
- req.body[i] = req.body[i].replace(`\${${keys[0]}}`, this.getDynamicParam(keys[0]));
2901
- }
2983
+ /*for (let i in req.body) {
2984
+ if (typeof req.body[i] === 'string') {
2985
+ let keys = req.body[i].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
2986
+ if (keys) {
2987
+ req.body[i] = req.body[i].replace(
2988
+ `\${${keys[0]}}`,
2989
+ this.getDynamicParam(keys[0])
2990
+ );
2991
+ }
2992
+ }
2993
+ }*/
2994
+ let bodyStr = JSON.stringify(req.body);
2995
+ let keys = bodyStr.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
2996
+ if (keys?.length) {
2997
+ for (let i = 0; i < keys.length; i++) {
2998
+ bodyStr = bodyStr.replace(`\${${keys[i]}}`, this.getDynamicParam(keys[i]));
2902
2999
  }
2903
3000
  }
3001
+ req.body = JSON.parse(bodyStr);
2904
3002
  }
2905
3003
  // 默认每一秒请求一次
2906
3004
  const res = await fetch(req.url, {
@@ -4623,7 +4721,7 @@ export class Meta2d {
4623
4721
  });
4624
4722
  for (let i = 1; i < pens.length; i++) {
4625
4723
  const pen = pens[i];
4626
- this.setValue({ id: pen.id, ...attrs }, { render: false, doEvent: false });
4724
+ this.setValue({ id: pen.id, ...defaultFormat, ...attrs }, { render: false, doEvent: false });
4627
4725
  }
4628
4726
  this.render();
4629
4727
  this.pushHistory({
@@ -4646,7 +4744,7 @@ export class Meta2d {
4646
4744
  });
4647
4745
  for (let i = 0; i < pens.length - 1; i++) {
4648
4746
  const pen = pens[i];
4649
- this.setValue({ id: pen.id, ...attrs }, { render: false, doEvent: false });
4747
+ this.setValue({ id: pen.id, ...defaultFormat, ...attrs }, { render: false, doEvent: false });
4650
4748
  }
4651
4749
  this.render();
4652
4750
  this.pushHistory({
@@ -4688,7 +4786,7 @@ export class Meta2d {
4688
4786
  const attrs = JSON.parse(localStorage.getItem('meta2d-formatPainter'));
4689
4787
  for (let i = 0; i < pens.length; i++) {
4690
4788
  const pen = pens[i];
4691
- this.setValue({ id: pen.id, ...attrs }, { render: false, doEvent: false });
4789
+ this.setValue({ id: pen.id, ...defaultFormat, ...attrs }, { render: false, doEvent: false });
4692
4790
  }
4693
4791
  this.render();
4694
4792
  this.pushHistory({