@meta2d/core 1.0.61 → 1.0.63
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 +1 -1
- package/src/canvas/canvas.d.ts +4 -3
- package/src/canvas/canvas.js +52 -24
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +10 -4
- package/src/core.js +192 -11
- package/src/core.js.map +1 -1
- package/src/event/event.d.ts +7 -1
- package/src/event/event.js +1 -0
- package/src/event/event.js.map +1 -1
- package/src/message/index.d.ts +1 -0
- package/src/message/index.js +2 -0
- package/src/message/index.js.map +1 -0
- package/src/message/message.d.ts +28 -0
- package/src/message/message.js +162 -0
- package/src/message/message.js.map +1 -0
- package/src/pen/model.d.ts +10 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.d.ts +1 -0
- package/src/pen/render.js +41 -3
- package/src/pen/render.js.map +1 -1
- package/src/popconfirm/index.d.ts +1 -0
- package/src/popconfirm/index.js +2 -0
- package/src/popconfirm/index.js.map +1 -0
- package/src/popconfirm/popconfirm.d.ts +21 -0
- package/src/popconfirm/popconfirm.js +135 -0
- package/src/popconfirm/popconfirm.js.map +1 -0
- package/src/store/store.d.ts +1 -1
package/src/core.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { Rect } from './rect';
|
|
|
9
9
|
import { Event, TriggerCondition } from './event';
|
|
10
10
|
import { ViewMap } from './map';
|
|
11
11
|
import { MqttClient } from 'mqtt';
|
|
12
|
+
import { MessageOptions } from './message';
|
|
12
13
|
export declare class Meta2d {
|
|
13
14
|
store: Meta2dStore;
|
|
14
15
|
canvas: Canvas;
|
|
@@ -29,7 +30,7 @@ export declare class Meta2d {
|
|
|
29
30
|
url?: string;
|
|
30
31
|
method?: string;
|
|
31
32
|
}) => boolean | string;
|
|
32
|
-
events: Record<number, (pen: Pen, e: Event) => void>;
|
|
33
|
+
events: Record<number, (pen: Pen, e: Event, params?: any) => void>;
|
|
33
34
|
map: ViewMap;
|
|
34
35
|
mapTimer: any;
|
|
35
36
|
constructor(parent: string | HTMLElement, opts?: Options);
|
|
@@ -60,6 +61,8 @@ export declare class Meta2d {
|
|
|
60
61
|
setDatabyOptions(options?: Options): void;
|
|
61
62
|
private init;
|
|
62
63
|
initEventFns(): void;
|
|
64
|
+
message(options: MessageOptions): void;
|
|
65
|
+
closeAll(): void;
|
|
63
66
|
navigatorTo(id: string): Promise<void>;
|
|
64
67
|
doSendDataEvent(value: any, topics?: string): void;
|
|
65
68
|
sendDataToNetWork(value: any, pen: Pen, e: any): Promise<void>;
|
|
@@ -68,8 +71,8 @@ export declare class Meta2d {
|
|
|
68
71
|
*
|
|
69
72
|
* @param emit 是否发送消息
|
|
70
73
|
*/
|
|
71
|
-
addPen(pen: Pen, history?: boolean, emit?: boolean): Promise<Pen>;
|
|
72
|
-
addPens(pens: Pen[], history?: boolean): Promise<Pen[]>;
|
|
74
|
+
addPen(pen: Pen, history?: boolean, emit?: boolean, abs?: boolean): Promise<Pen>;
|
|
75
|
+
addPens(pens: Pen[], history?: boolean, abs?: boolean): Promise<Pen[]>;
|
|
73
76
|
render(patchFlags?: boolean | number): void;
|
|
74
77
|
setBackgroundImage(url: string, data?: any): Promise<void>;
|
|
75
78
|
setBackgroundColor(color?: string): void;
|
|
@@ -87,6 +90,8 @@ export declare class Meta2d {
|
|
|
87
90
|
cacheData(id: string): void;
|
|
88
91
|
loadCacheData(id: string): void;
|
|
89
92
|
initBindDatas(): void;
|
|
93
|
+
jetLinksList: any[];
|
|
94
|
+
jetLinksClient: any;
|
|
90
95
|
initBinds(): void;
|
|
91
96
|
connectSocket(): void;
|
|
92
97
|
/**
|
|
@@ -172,6 +177,7 @@ export declare class Meta2d {
|
|
|
172
177
|
active(pens: Pen[], emit?: boolean): void;
|
|
173
178
|
inactive(): void;
|
|
174
179
|
activeAll(): void;
|
|
180
|
+
focus(id: string): void;
|
|
175
181
|
/**
|
|
176
182
|
* 删除画笔
|
|
177
183
|
* @param pens 需要删除的画笔们
|
|
@@ -343,7 +349,7 @@ export declare class Meta2d {
|
|
|
343
349
|
formatPainter(): void;
|
|
344
350
|
clearFormatPainter(): void;
|
|
345
351
|
alignNodes(align: string, pens?: Pen[], rect?: Rect): void;
|
|
346
|
-
alignNodesV(align: string, pens?: Pen[]): void;
|
|
352
|
+
alignNodesV(align: string, pens?: Pen[], whole?: boolean): void;
|
|
347
353
|
/**
|
|
348
354
|
* 对齐画笔,基于第一个画笔
|
|
349
355
|
* @param align 左对齐,右对齐,上对齐,下对齐,居中对齐
|
package/src/core.js
CHANGED
|
@@ -15,6 +15,7 @@ import { Scroll } from './scroll';
|
|
|
15
15
|
import { getter } from './utils/object';
|
|
16
16
|
import { queryURLParams } from './utils/url';
|
|
17
17
|
import { HotkeyType } from './data';
|
|
18
|
+
import { Message, messageList } from './message';
|
|
18
19
|
export class Meta2d {
|
|
19
20
|
store;
|
|
20
21
|
canvas;
|
|
@@ -262,7 +263,7 @@ export class Meta2d {
|
|
|
262
263
|
}
|
|
263
264
|
console.warn('[meta2d] StopVideo event value is not a string');
|
|
264
265
|
};
|
|
265
|
-
this.events[EventAction.JS] = (pen, e) => {
|
|
266
|
+
this.events[EventAction.JS] = (pen, e, params) => {
|
|
266
267
|
if (e.value && !e.fn) {
|
|
267
268
|
try {
|
|
268
269
|
if (typeof e.value !== 'string') {
|
|
@@ -275,7 +276,7 @@ export class Meta2d {
|
|
|
275
276
|
console.error('[meta2d]: Error on make a function:', err);
|
|
276
277
|
}
|
|
277
278
|
}
|
|
278
|
-
e.fn?.(pen, e.params, { meta2d: this, eventName: e.name });
|
|
279
|
+
e.fn?.(pen, params || e.params, { meta2d: this, eventName: e.name });
|
|
279
280
|
};
|
|
280
281
|
this.events[EventAction.GlobalFn] = (pen, e) => {
|
|
281
282
|
if (typeof e.value !== 'string') {
|
|
@@ -359,6 +360,52 @@ export class Meta2d {
|
|
|
359
360
|
this.events[EventAction.SendData] = (pen, e) => {
|
|
360
361
|
if (e.list?.length) {
|
|
361
362
|
// if (e.targetType === 'id') {
|
|
363
|
+
if (e.network && e.network.protocol === "jetLinks") {
|
|
364
|
+
const list = [];
|
|
365
|
+
e.list.forEach((item, index) => {
|
|
366
|
+
const _pen = item.params ? this.findOne(item.params) : pen;
|
|
367
|
+
list[index] = {
|
|
368
|
+
deviceId: _pen.deviceId,
|
|
369
|
+
productId: _pen.productId,
|
|
370
|
+
properties: {}
|
|
371
|
+
};
|
|
372
|
+
for (let key in item.value) {
|
|
373
|
+
if (item.value[key] === undefined || item.value[key] === '') {
|
|
374
|
+
//找到绑定了这个设备属性的图元属性
|
|
375
|
+
const realTime = _pen.realTimes?.find((item) => item.propertyId === key);
|
|
376
|
+
if (realTime) {
|
|
377
|
+
list[index].properties[key] = _pen[realTime.key];
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
else if (typeof item.value[key] === 'string' && item.value[key]?.indexOf('${') > -1) {
|
|
381
|
+
let keys = item.value[key].match(/(?<=\$\{).*?(?=\})/g);
|
|
382
|
+
if (keys?.length) {
|
|
383
|
+
list[index].properties[key] = _pen[keys[0]];
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
list[index].properties[key] = item.value[key];
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
if (this.jetLinksClient && list.length) {
|
|
392
|
+
list.forEach((item) => {
|
|
393
|
+
this.jetLinksClient.send(JSON.stringify({
|
|
394
|
+
"type": "sub",
|
|
395
|
+
"topic": `/device-message-sender/${item.productId}/${item.deviceId}`,
|
|
396
|
+
"parameter": {
|
|
397
|
+
"messageType": "WRITE_PROPERTY",
|
|
398
|
+
"properties": item.properties,
|
|
399
|
+
"headers": {
|
|
400
|
+
"async": false
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
"id": item.productId + '/' + item.deviceId + '-' + s8()
|
|
404
|
+
}));
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
362
409
|
const value = {};
|
|
363
410
|
e.list.forEach((item) => {
|
|
364
411
|
const _pen = item.params ? this.findOne(item.params) : pen;
|
|
@@ -474,6 +521,22 @@ export class Meta2d {
|
|
|
474
521
|
window.parent.postMessage(JSON.stringify({ name: e.value, value }), '*');
|
|
475
522
|
return;
|
|
476
523
|
};
|
|
524
|
+
this.events[EventAction.Message] = (pen, e) => {
|
|
525
|
+
this.message({
|
|
526
|
+
theme: e.params,
|
|
527
|
+
content: e.value,
|
|
528
|
+
...e.extend
|
|
529
|
+
});
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
message(options) {
|
|
533
|
+
const message = new Message(this.canvas.parentElement, options);
|
|
534
|
+
message.init();
|
|
535
|
+
}
|
|
536
|
+
closeAll() {
|
|
537
|
+
for (let key in messageList) {
|
|
538
|
+
messageList[key].close();
|
|
539
|
+
}
|
|
477
540
|
}
|
|
478
541
|
async navigatorTo(id) {
|
|
479
542
|
if (!id) {
|
|
@@ -660,11 +723,11 @@ export class Meta2d {
|
|
|
660
723
|
*
|
|
661
724
|
* @param emit 是否发送消息
|
|
662
725
|
*/
|
|
663
|
-
async addPen(pen, history, emit = true) {
|
|
664
|
-
return await this.canvas.addPen(pen, history, emit);
|
|
726
|
+
async addPen(pen, history, emit = true, abs = false) {
|
|
727
|
+
return await this.canvas.addPen(pen, history, emit, abs);
|
|
665
728
|
}
|
|
666
|
-
async addPens(pens, history) {
|
|
667
|
-
return await this.canvas.addPens(pens, history);
|
|
729
|
+
async addPens(pens, history, abs = false) {
|
|
730
|
+
return await this.canvas.addPens(pens, history, abs);
|
|
668
731
|
}
|
|
669
732
|
render(patchFlags) {
|
|
670
733
|
this.canvas?.render(patchFlags);
|
|
@@ -779,6 +842,12 @@ export class Meta2d {
|
|
|
779
842
|
this.startVideo();
|
|
780
843
|
this.doInitJS();
|
|
781
844
|
this.doInitFn();
|
|
845
|
+
setTimeout(() => {
|
|
846
|
+
const pen = this.store.data.pens.find((pen) => pen.autofocus);
|
|
847
|
+
if (pen) {
|
|
848
|
+
this.focus(pen.id);
|
|
849
|
+
}
|
|
850
|
+
}, 100);
|
|
782
851
|
if (this.store.data.iconUrls) {
|
|
783
852
|
for (const item of this.store.data.iconUrls) {
|
|
784
853
|
loadCss(item, () => {
|
|
@@ -866,7 +935,10 @@ export class Meta2d {
|
|
|
866
935
|
});
|
|
867
936
|
});
|
|
868
937
|
}
|
|
938
|
+
jetLinksList = [];
|
|
939
|
+
jetLinksClient;
|
|
869
940
|
initBinds() {
|
|
941
|
+
this.jetLinksList = [];
|
|
870
942
|
this.store.bind = {};
|
|
871
943
|
this.store.data.pens.forEach((pen) => {
|
|
872
944
|
pen.realTimes?.forEach((realTime) => {
|
|
@@ -878,6 +950,26 @@ export class Meta2d {
|
|
|
878
950
|
id: pen.id,
|
|
879
951
|
key: realTime.key,
|
|
880
952
|
});
|
|
953
|
+
//JetLinks
|
|
954
|
+
const productId = realTime.productId || pen.productId;
|
|
955
|
+
const deviceId = realTime.deviceId || pen.deviceId;
|
|
956
|
+
const propertyId = realTime.propertyId;
|
|
957
|
+
if (productId && deviceId && propertyId) {
|
|
958
|
+
const index = this.jetLinksList.findIndex((item) => item.topic.startsWith(`/${productId}/${deviceId}`));
|
|
959
|
+
if (index > -1) {
|
|
960
|
+
const properties = this.jetLinksList[index].properties;
|
|
961
|
+
if (!properties.includes(realTime.propertyId)) {
|
|
962
|
+
this.jetLinksList[index].properties.push(realTime.propertyId);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
else {
|
|
966
|
+
this.jetLinksList.push({
|
|
967
|
+
topic: `/${productId}/${deviceId}`,
|
|
968
|
+
deviceId,
|
|
969
|
+
properties: [realTime.propertyId]
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
}
|
|
881
973
|
}
|
|
882
974
|
});
|
|
883
975
|
});
|
|
@@ -1524,6 +1616,14 @@ export class Meta2d {
|
|
|
1524
1616
|
this.canvas.active(this.store.data.pens.filter((pen) => !pen.parentId && pen.locked !== LockState.Disable));
|
|
1525
1617
|
this.render();
|
|
1526
1618
|
}
|
|
1619
|
+
focus(id) {
|
|
1620
|
+
const pen = this.findOne(id);
|
|
1621
|
+
if (pen) {
|
|
1622
|
+
this.store.hover = pen;
|
|
1623
|
+
this.store.hover.calculative.hover = true;
|
|
1624
|
+
this.showInput(pen);
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1527
1627
|
/**
|
|
1528
1628
|
* 删除画笔
|
|
1529
1629
|
* @param pens 需要删除的画笔们
|
|
@@ -1920,7 +2020,41 @@ export class Meta2d {
|
|
|
1920
2020
|
sqlIndex += 1;
|
|
1921
2021
|
}
|
|
1922
2022
|
}
|
|
1923
|
-
|
|
2023
|
+
else if (net.protocol === 'jetLinks') {
|
|
2024
|
+
if (this.jetLinksList.length) {
|
|
2025
|
+
this.jetLinksClient = new WebSocket(`${net.url}/${localStorage.getItem('X-Access-Token') || this.getCookie('X-Access-Token') || new URLSearchParams(location.search).get('X-Access-Token') || ''}`);
|
|
2026
|
+
//消息接收
|
|
2027
|
+
this.jetLinksClient.onmessage = (e) => {
|
|
2028
|
+
const mess = JSON.parse(e.data);
|
|
2029
|
+
if (mess.payload && mess.payload.success && mess.payload?.properties) {
|
|
2030
|
+
const data = [];
|
|
2031
|
+
for (let key in mess.payload.properties) {
|
|
2032
|
+
if (!key.startsWith('_')) {
|
|
2033
|
+
data.push({
|
|
2034
|
+
id: `${mess.payload.headers.productId}#${mess.payload.deviceId}#${key}`,
|
|
2035
|
+
value: mess.payload.properties[key]
|
|
2036
|
+
});
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
this.setDatas(data, { history: false });
|
|
2040
|
+
}
|
|
2041
|
+
};
|
|
2042
|
+
this.jetLinksClient.onopen = () => {
|
|
2043
|
+
this.jetLinksList.forEach((item) => {
|
|
2044
|
+
this.jetLinksClient.send(JSON.stringify({
|
|
2045
|
+
"type": "sub",
|
|
2046
|
+
"topic": `/device${item.topic}/message/property/report`,
|
|
2047
|
+
"parameter": {
|
|
2048
|
+
"deviceId": item.deviceId,
|
|
2049
|
+
"properties": item.properties,
|
|
2050
|
+
"history": 1
|
|
2051
|
+
},
|
|
2052
|
+
"id": item.topic + '-' + s8()
|
|
2053
|
+
}));
|
|
2054
|
+
});
|
|
2055
|
+
};
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
1924
2058
|
});
|
|
1925
2059
|
}
|
|
1926
2060
|
this.onNetworkConnect(https);
|
|
@@ -2586,6 +2720,14 @@ export class Meta2d {
|
|
|
2586
2720
|
}
|
|
2587
2721
|
break;
|
|
2588
2722
|
case 'click':
|
|
2723
|
+
if (this.store.data.locked && e.pen && (!e.pen.disabled)) {
|
|
2724
|
+
if (e.pen.switch) {
|
|
2725
|
+
e.pen.checked = !e.pen.checked;
|
|
2726
|
+
e.pen.calculative.checked = e.pen.checked;
|
|
2727
|
+
e.pen.calculative.gradient = undefined;
|
|
2728
|
+
e.pen.calculative.radialGradient = undefined;
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2589
2731
|
e.pen && e.pen.onClick && (!e.pen.disabled) && e.pen.onClick(e.pen, this.canvas.mousePos);
|
|
2590
2732
|
this.store.data.locked && e.pen && (!e.pen.disabled) && this.doEvent(e.pen, eventName);
|
|
2591
2733
|
break;
|
|
@@ -2748,8 +2890,13 @@ export class Meta2d {
|
|
|
2748
2890
|
});
|
|
2749
2891
|
}
|
|
2750
2892
|
else {
|
|
2751
|
-
pen.events?.forEach((event, index) => {
|
|
2893
|
+
pen.events?.forEach(async (event, index) => {
|
|
2752
2894
|
if (indexArr.includes(index)) {
|
|
2895
|
+
if (event.confirm) {
|
|
2896
|
+
if (!await this.canvas.popconfirm.showModal(pen, this.canvas.mousePos, event.confirmTitle)) {
|
|
2897
|
+
return;
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
2753
2900
|
event.actions.forEach((action) => {
|
|
2754
2901
|
if (action.timeout) {
|
|
2755
2902
|
let timer = setTimeout(() => {
|
|
@@ -3869,7 +4016,7 @@ export class Meta2d {
|
|
|
3869
4016
|
});
|
|
3870
4017
|
}
|
|
3871
4018
|
//对齐大屏
|
|
3872
|
-
alignNodesV(align, pens = this.store.data.pens) {
|
|
4019
|
+
alignNodesV(align, pens = this.store.data.pens, whole = false) {
|
|
3873
4020
|
const width = this.store.data.width || this.store.options.width;
|
|
3874
4021
|
const height = this.store.data.height || this.store.options.height;
|
|
3875
4022
|
let rect = {
|
|
@@ -3879,8 +4026,41 @@ export class Meta2d {
|
|
|
3879
4026
|
height,
|
|
3880
4027
|
};
|
|
3881
4028
|
const initPens = deepClone(pens); // 原 pens ,深拷贝一下
|
|
3882
|
-
|
|
3883
|
-
this.
|
|
4029
|
+
if (whole) {
|
|
4030
|
+
const scale = this.store.data.scale;
|
|
4031
|
+
const rect = this.getRect(pens);
|
|
4032
|
+
const x = (rect.x - this.store.data.origin.x) / scale;
|
|
4033
|
+
const y = (rect.y - this.store.data.origin.y) / scale;
|
|
4034
|
+
const w = rect.width / scale;
|
|
4035
|
+
const h = rect.height / scale;
|
|
4036
|
+
let moveX = 0;
|
|
4037
|
+
let moveY = 0;
|
|
4038
|
+
switch (align) {
|
|
4039
|
+
case 'left':
|
|
4040
|
+
moveX = -x;
|
|
4041
|
+
break;
|
|
4042
|
+
case 'right':
|
|
4043
|
+
moveX = width - (x + w);
|
|
4044
|
+
break;
|
|
4045
|
+
case 'top':
|
|
4046
|
+
moveY = -y;
|
|
4047
|
+
break;
|
|
4048
|
+
case 'bottom':
|
|
4049
|
+
moveY = height - (y + h);
|
|
4050
|
+
break;
|
|
4051
|
+
case 'center':
|
|
4052
|
+
moveX = width / 2 - (x + w / 2);
|
|
4053
|
+
break;
|
|
4054
|
+
case 'middle':
|
|
4055
|
+
moveY = height / 2 - (y + h / 2);
|
|
4056
|
+
break;
|
|
4057
|
+
}
|
|
4058
|
+
this.translatePens(pens, moveX * scale, moveY * scale);
|
|
4059
|
+
}
|
|
4060
|
+
else {
|
|
4061
|
+
for (const item of pens) {
|
|
4062
|
+
this.alignPen(align, item, rect);
|
|
4063
|
+
}
|
|
3884
4064
|
}
|
|
3885
4065
|
this.initImageCanvas(pens);
|
|
3886
4066
|
this.initTemplateCanvas(pens);
|
|
@@ -4857,6 +5037,7 @@ export class Meta2d {
|
|
|
4857
5037
|
this.stopDataMock();
|
|
4858
5038
|
this.closeSocket();
|
|
4859
5039
|
this.closeNetwork();
|
|
5040
|
+
this.closeAll();
|
|
4860
5041
|
this.store.emitter.all.clear(); // 内存释放
|
|
4861
5042
|
this.canvas.destroy();
|
|
4862
5043
|
this.canvas = undefined;
|