@meta2d/core 1.0.58 → 1.0.59
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/package.json +37 -36
- package/src/canvas/canvas.js +46 -6
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +9 -1
- package/src/core.js +101 -22
- package/src/core.js.map +1 -1
- package/src/diagrams/index.d.ts +1 -0
- package/src/diagrams/index.js +2 -1
- package/src/diagrams/index.js.map +1 -1
- package/src/dialog/dialog.js +1 -1
- package/src/dialog/dialog.js.map +1 -1
- package/src/options.d.ts +5 -0
- package/src/options.js.map +1 -1
- package/src/pen/model.d.ts +1 -0
- package/src/pen/model.js.map +1 -1
package/src/core.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export declare class Meta2d {
|
|
|
59
59
|
setDatabyOptions(options?: Options): void;
|
|
60
60
|
private init;
|
|
61
61
|
initEventFns(): void;
|
|
62
|
-
navigatorTo(id: string): void
|
|
62
|
+
navigatorTo(id: string): Promise<void>;
|
|
63
63
|
doSendDataEvent(value: any, topics?: string): void;
|
|
64
64
|
sendDataToNetWork(value: any, pen: Pen, e: any): Promise<void>;
|
|
65
65
|
resize(width?: number, height?: number): void;
|
|
@@ -160,6 +160,13 @@ export declare class Meta2d {
|
|
|
160
160
|
combine(pens?: Pen[], showChild?: number): any;
|
|
161
161
|
uncombine(pen?: Pen): void;
|
|
162
162
|
appendChild(pens?: Pen[]): void;
|
|
163
|
+
/***
|
|
164
|
+
* 修改子图元大小,更新整个组合图元
|
|
165
|
+
* @param rect 新的大小 世界坐标
|
|
166
|
+
* @param child 待更新子图元
|
|
167
|
+
* @param parent 父图元
|
|
168
|
+
*/
|
|
169
|
+
updateRectbyChild(rect: Rect, child: Pen, parent: Pen): void;
|
|
163
170
|
isCombine(pen: Pen): boolean;
|
|
164
171
|
active(pens: Pen[], emit?: boolean): void;
|
|
165
172
|
inactive(): void;
|
|
@@ -218,6 +225,7 @@ export declare class Meta2d {
|
|
|
218
225
|
stopDataMock(): void;
|
|
219
226
|
penMock(pen: Pen): void;
|
|
220
227
|
penNetwork(pen: Pen): void;
|
|
228
|
+
getCookie(name: string): string;
|
|
221
229
|
getDynamicParam(key: string): any;
|
|
222
230
|
onNetworkConnect(https: Network[]): void;
|
|
223
231
|
requestHttp(_req: Network): Promise<void>;
|
package/src/core.js
CHANGED
|
@@ -4,7 +4,7 @@ import { calcInView, calcTextDrawRect, calcTextLines, calcTextRect, facePen, for
|
|
|
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';
|
|
7
|
-
import { calcCenter, calcRelativeRect, getRect, rectInRect, } from './rect';
|
|
7
|
+
import { calcCenter, calcRelativeRect, calcRightBottom, getRect, rectInRect, } from './rect';
|
|
8
8
|
import { deepClone } from './utils/clone';
|
|
9
9
|
import { EventAction } from './event';
|
|
10
10
|
import { ViewMap } from './map';
|
|
@@ -365,6 +365,12 @@ export class Meta2d {
|
|
|
365
365
|
if (value[key] === undefined || value[key] === '') {
|
|
366
366
|
value[key] = _pen[key];
|
|
367
367
|
}
|
|
368
|
+
else if (typeof value[key] === 'string' && value[key]?.indexOf('${') > -1) {
|
|
369
|
+
let keys = value[key].match(/(?<=\$\{).*?(?=\})/g);
|
|
370
|
+
if (keys?.length) {
|
|
371
|
+
value[key] = _pen[keys[0]];
|
|
372
|
+
}
|
|
373
|
+
}
|
|
368
374
|
}
|
|
369
375
|
// value.id = _pen.id;
|
|
370
376
|
if (_pen.deviceId) {
|
|
@@ -401,20 +407,49 @@ export class Meta2d {
|
|
|
401
407
|
return;
|
|
402
408
|
};
|
|
403
409
|
}
|
|
404
|
-
navigatorTo(id) {
|
|
410
|
+
async navigatorTo(id) {
|
|
405
411
|
if (!id) {
|
|
406
412
|
return;
|
|
407
413
|
}
|
|
408
|
-
let href = window.location.href;
|
|
409
|
-
let arr = href.split('id=');
|
|
410
|
-
if (arr.length > 1) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
+
// let href = window.location.href;
|
|
415
|
+
// let arr: string[] = href.split('id=');
|
|
416
|
+
// if (arr.length > 1) {
|
|
417
|
+
// let idx = arr[1].indexOf('&');
|
|
418
|
+
// if (idx === -1) {
|
|
419
|
+
// window.location.href = arr[0] + 'id=' + id;
|
|
420
|
+
// } else {
|
|
421
|
+
// window.location.href = arr[0] + 'id=' + id + arr[1].slice(idx);
|
|
422
|
+
// }
|
|
423
|
+
// }
|
|
424
|
+
//路径参数更新
|
|
425
|
+
const url = new URL(window.location);
|
|
426
|
+
url.searchParams.set('id', id);
|
|
427
|
+
history.pushState({}, '', url);
|
|
428
|
+
//图纸更新
|
|
429
|
+
const netWork = this.store.options.navigatorNetWork;
|
|
430
|
+
const collection = (location.href.includes('2d.') || location.href.includes('/2d')) ? '2d' : 'v';
|
|
431
|
+
const res = await fetch((netWork?.url || `/api/data/${collection}/get`) + (netWork?.method === 'GET' ? `?id=${id}` : ''), {
|
|
432
|
+
headers: {
|
|
433
|
+
Authorization: `Bearer ${this.getCookie('token') || localStorage.getItem('token') || new URLSearchParams(location.search).get('token') || ''}`,
|
|
434
|
+
},
|
|
435
|
+
method: netWork?.method || 'POST',
|
|
436
|
+
body: netWork?.method === 'GET' ? undefined : JSON.stringify({ id: id }),
|
|
437
|
+
});
|
|
438
|
+
if (res.ok) {
|
|
439
|
+
let data = await res.text();
|
|
440
|
+
if (data.constructor === Object || data.constructor === Array) {
|
|
441
|
+
data = JSON.parse(JSON.stringify(data));
|
|
414
442
|
}
|
|
415
|
-
else {
|
|
416
|
-
|
|
443
|
+
else if (typeof data === 'string') {
|
|
444
|
+
data = JSON.parse(data);
|
|
445
|
+
}
|
|
446
|
+
if (data.data) {
|
|
447
|
+
data = data.data;
|
|
417
448
|
}
|
|
449
|
+
this.open(data);
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
this.store.emitter.emit('error', { type: 'http', error: res });
|
|
418
453
|
}
|
|
419
454
|
}
|
|
420
455
|
doSendDataEvent(value, topics) {
|
|
@@ -1233,7 +1268,7 @@ export class Meta2d {
|
|
|
1233
1268
|
pen.parentId = parent.id;
|
|
1234
1269
|
const childRect = calcRelativeRect(pen.calculative.worldRect, rect);
|
|
1235
1270
|
Object.assign(pen, childRect);
|
|
1236
|
-
pen.locked = pen.lockedOnCombine ?? LockState.
|
|
1271
|
+
pen.locked = pen.lockedOnCombine ?? LockState.None;
|
|
1237
1272
|
pen.locked = (pen.interaction || isInteraction.includes(pen.name)) ? 0 : pen.locked;
|
|
1238
1273
|
});
|
|
1239
1274
|
//将组合后的父节点置底
|
|
@@ -1358,6 +1393,49 @@ export class Meta2d {
|
|
|
1358
1393
|
console.warn('Invalid operation!');
|
|
1359
1394
|
}
|
|
1360
1395
|
}
|
|
1396
|
+
/***
|
|
1397
|
+
* 修改子图元大小,更新整个组合图元
|
|
1398
|
+
* @param rect 新的大小 世界坐标
|
|
1399
|
+
* @param child 待更新子图元
|
|
1400
|
+
* @param parent 父图元
|
|
1401
|
+
*/
|
|
1402
|
+
updateRectbyChild(rect, child, parent) {
|
|
1403
|
+
calcRightBottom(rect);
|
|
1404
|
+
calcCenter(rect);
|
|
1405
|
+
child.calculative.worldRect = rect;
|
|
1406
|
+
if (rectInRect(rect, parent.calculative.worldRect, true)) {
|
|
1407
|
+
const childRect = calcRelativeRect(rect, parent.calculative.worldRect);
|
|
1408
|
+
Object.assign(child, childRect);
|
|
1409
|
+
}
|
|
1410
|
+
else {
|
|
1411
|
+
let x = Math.min(rect.x, parent.calculative.worldRect.x);
|
|
1412
|
+
let y = Math.min(rect.y, parent.calculative.worldRect.y);
|
|
1413
|
+
let ex = Math.max(rect.ex, parent.calculative.worldRect.ex);
|
|
1414
|
+
let ey = Math.max(rect.ey, parent.calculative.worldRect.ey);
|
|
1415
|
+
parent.calculative.worldRect = {
|
|
1416
|
+
x: x,
|
|
1417
|
+
y: y,
|
|
1418
|
+
width: ex - x,
|
|
1419
|
+
height: ey - y,
|
|
1420
|
+
ex,
|
|
1421
|
+
ey
|
|
1422
|
+
};
|
|
1423
|
+
if (!parent.parentId) {
|
|
1424
|
+
Object.assign(parent, parent.calculative.worldRect);
|
|
1425
|
+
}
|
|
1426
|
+
calcCenter(parent.calculative.worldRect);
|
|
1427
|
+
parent.children.forEach((cid) => {
|
|
1428
|
+
const cPen = this.store.pens[cid];
|
|
1429
|
+
const childRect = calcRelativeRect(cPen.calculative.worldRect, parent.calculative.worldRect);
|
|
1430
|
+
Object.assign(cPen, childRect);
|
|
1431
|
+
});
|
|
1432
|
+
if (parent.parentId) {
|
|
1433
|
+
this.updateRectbyChild(parent.calculative.worldRect, parent, this.store.pens[parent.parentId]);
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
this.canvas.updatePenRect(parent);
|
|
1437
|
+
this.render();
|
|
1438
|
+
}
|
|
1361
1439
|
isCombine(pen) {
|
|
1362
1440
|
if (pen.name === 'combine') {
|
|
1363
1441
|
return true;
|
|
@@ -1963,20 +2041,20 @@ export class Meta2d {
|
|
|
1963
2041
|
delete this.store.pensNetwork[pen.id];
|
|
1964
2042
|
}
|
|
1965
2043
|
}
|
|
2044
|
+
getCookie(name) {
|
|
2045
|
+
let arr;
|
|
2046
|
+
const reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
|
|
2047
|
+
if ((arr = document.cookie.match(reg))) {
|
|
2048
|
+
return decodeURIComponent(arr[2]);
|
|
2049
|
+
}
|
|
2050
|
+
else {
|
|
2051
|
+
return '';
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
1966
2054
|
//获取动态参数
|
|
1967
2055
|
getDynamicParam(key) {
|
|
1968
|
-
function getCookie(name) {
|
|
1969
|
-
let arr;
|
|
1970
|
-
const reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
|
|
1971
|
-
if ((arr = document.cookie.match(reg))) {
|
|
1972
|
-
return decodeURIComponent(arr[2]);
|
|
1973
|
-
}
|
|
1974
|
-
else {
|
|
1975
|
-
return '';
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
2056
|
let params = queryURLParams();
|
|
1979
|
-
let value = params[key] || localStorage[key] || getCookie(key) || '';
|
|
2057
|
+
let value = params[key] || localStorage[key] || this.getCookie(key) || '';
|
|
1980
2058
|
return value;
|
|
1981
2059
|
}
|
|
1982
2060
|
onNetworkConnect(https) {
|
|
@@ -4589,6 +4667,7 @@ export class Meta2d {
|
|
|
4589
4667
|
setLifeCycleFunc = setLifeCycleFunc;
|
|
4590
4668
|
destroy(onlyData) {
|
|
4591
4669
|
this.clear(false);
|
|
4670
|
+
this.stopDataMock();
|
|
4592
4671
|
this.closeSocket();
|
|
4593
4672
|
this.closeNetwork();
|
|
4594
4673
|
this.store.emitter.all.clear(); // 内存释放
|