@meta2d/core 1.0.41 → 1.0.43
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.js +12 -3
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +2 -0
- package/src/core.js +95 -33
- package/src/core.js.map +1 -1
- package/src/diagrams/line/arrow.d.ts +2 -0
- package/src/diagrams/line/arrow.js +128 -0
- package/src/diagrams/line/arrow.js.map +1 -0
- package/src/diagrams/line/index.d.ts +1 -0
- package/src/diagrams/line/index.js +1 -0
- package/src/diagrams/line/index.js.map +1 -1
- package/src/diagrams/line/line.js +9 -1
- package/src/diagrams/line/line.js.map +1 -1
- package/src/options.js +1 -1
- package/src/pen/model.d.ts +9 -1
- package/src/pen/model.js +3 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.js +65 -17
- package/src/pen/render.js.map +1 -1
- package/src/store/store.d.ts +5 -0
- package/src/store/store.js +3 -0
- package/src/store/store.js.map +1 -1
- package/src/theme.d.ts +13 -0
- package/src/theme.js +23 -0
- package/src/theme.js.map +1 -0
package/src/core.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ export declare class Meta2d {
|
|
|
55
55
|
set beforeRemoveAnchor(fn: (pen: Pen, anchor: Point) => Promise<boolean>);
|
|
56
56
|
setOptions(opts?: Options): void;
|
|
57
57
|
getOptions(): Options;
|
|
58
|
+
setTheme(theme: string): void;
|
|
58
59
|
setDatabyOptions(options?: Options): void;
|
|
59
60
|
private init;
|
|
60
61
|
initEventFns(): void;
|
|
@@ -201,6 +202,7 @@ export declare class Meta2d {
|
|
|
201
202
|
sendDatabyHttp(data: string): Promise<void>;
|
|
202
203
|
closeHttp(): void;
|
|
203
204
|
updateTimer: any;
|
|
205
|
+
updateTimerList: any[];
|
|
204
206
|
connectNetwork(): void;
|
|
205
207
|
randomString(e: number): string;
|
|
206
208
|
penMock(pen: Pen): void;
|
package/src/core.js
CHANGED
|
@@ -113,6 +113,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
113
113
|
this.registerCanvasDraw = registerCanvasDraw;
|
|
114
114
|
this.registerAnchors = registerAnchors;
|
|
115
115
|
this.httpTimerList = [];
|
|
116
|
+
this.updateTimerList = [];
|
|
116
117
|
this.onEvent = function (eventName, e) {
|
|
117
118
|
switch (eventName) {
|
|
118
119
|
case 'add':
|
|
@@ -187,11 +188,13 @@ var Meta2d = /** @class */ (function () {
|
|
|
187
188
|
}
|
|
188
189
|
};
|
|
189
190
|
this.doEvent = function (pen, eventName) {
|
|
190
|
-
var _a, _b;
|
|
191
|
+
var _a, _b, _c, _e;
|
|
191
192
|
if (!pen) {
|
|
192
193
|
return;
|
|
193
194
|
}
|
|
194
|
-
|
|
195
|
+
var old = false; //是否是旧的事件
|
|
196
|
+
var indexArr = []; //事件条件成立的索引
|
|
197
|
+
(_a = pen.events) === null || _a === void 0 ? void 0 : _a.forEach(function (event, index) {
|
|
195
198
|
var _a;
|
|
196
199
|
if (event.actions && event.actions.length) {
|
|
197
200
|
if (event.name === eventName) {
|
|
@@ -213,15 +216,17 @@ var Meta2d = /** @class */ (function () {
|
|
|
213
216
|
flag = true;
|
|
214
217
|
}
|
|
215
218
|
if (flag) {
|
|
216
|
-
event.actions.forEach(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
});
|
|
219
|
+
// event.actions.forEach((action) => {
|
|
220
|
+
// if (this.events[action.action]) {
|
|
221
|
+
// this.events[action.action](pen, action);
|
|
222
|
+
// }
|
|
223
|
+
// });
|
|
224
|
+
indexArr.push(index);
|
|
221
225
|
}
|
|
222
226
|
}
|
|
223
227
|
}
|
|
224
228
|
else {
|
|
229
|
+
old = true;
|
|
225
230
|
if (_this.events[event.action] && event.name === eventName) {
|
|
226
231
|
var can = !((_a = event.where) === null || _a === void 0 ? void 0 : _a.type);
|
|
227
232
|
if (event.where) {
|
|
@@ -276,32 +281,66 @@ var Meta2d = /** @class */ (function () {
|
|
|
276
281
|
}
|
|
277
282
|
}
|
|
278
283
|
}
|
|
279
|
-
can &&
|
|
284
|
+
// can && this.events[event.action](pen, event);
|
|
285
|
+
if (can) {
|
|
286
|
+
indexArr.push(index);
|
|
287
|
+
}
|
|
280
288
|
}
|
|
281
289
|
}
|
|
282
290
|
});
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (trigger.conditionType === 'and') {
|
|
289
|
-
flag = trigger.conditions.every(function (condition) {
|
|
290
|
-
return _this.judgeCondition(pen, realTime.key, condition);
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
else if (trigger.conditionType === 'or') {
|
|
294
|
-
flag = trigger.conditions.some(function (condition) {
|
|
295
|
-
return _this.judgeCondition(pen, realTime.key, condition);
|
|
296
|
-
});
|
|
291
|
+
//所有的条件判断后,再统一执行条件成立的事件
|
|
292
|
+
if (old) {
|
|
293
|
+
(_b = pen.events) === null || _b === void 0 ? void 0 : _b.forEach(function (event, index) {
|
|
294
|
+
if (indexArr.includes(index)) {
|
|
295
|
+
_this.events[event.action](pen, event);
|
|
297
296
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
(_c = pen.events) === null || _c === void 0 ? void 0 : _c.forEach(function (event, index) {
|
|
301
|
+
if (indexArr.includes(index)) {
|
|
302
|
+
event.actions.forEach(function (action) {
|
|
303
|
+
if (_this.events[action.action]) {
|
|
304
|
+
_this.events[action.action](pen, action);
|
|
305
|
+
}
|
|
301
306
|
});
|
|
302
307
|
}
|
|
303
308
|
});
|
|
304
|
-
}
|
|
309
|
+
}
|
|
310
|
+
if (eventName === 'valueUpdate') {
|
|
311
|
+
(_e = pen.realTimes) === null || _e === void 0 ? void 0 : _e.forEach(function (realTime) {
|
|
312
|
+
var _a, _b;
|
|
313
|
+
var indexArr = [];
|
|
314
|
+
(_a = realTime.triggers) === null || _a === void 0 ? void 0 : _a.forEach(function (trigger, index) {
|
|
315
|
+
var flag = false;
|
|
316
|
+
if (trigger.conditionType === 'and') {
|
|
317
|
+
flag = trigger.conditions.every(function (condition) {
|
|
318
|
+
return _this.judgeCondition(pen, realTime.key, condition);
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
else if (trigger.conditionType === 'or') {
|
|
322
|
+
flag = trigger.conditions.some(function (condition) {
|
|
323
|
+
return _this.judgeCondition(pen, realTime.key, condition);
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
if (flag) {
|
|
327
|
+
indexArr.push(index);
|
|
328
|
+
// trigger.actions?.forEach((event) => {
|
|
329
|
+
// this.events[event.action](pen, event);
|
|
330
|
+
// });
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
//执行
|
|
334
|
+
(_b = realTime.triggers) === null || _b === void 0 ? void 0 : _b.forEach(function (trigger, index) {
|
|
335
|
+
var _a;
|
|
336
|
+
if (indexArr.includes(index)) {
|
|
337
|
+
(_a = trigger.actions) === null || _a === void 0 ? void 0 : _a.forEach(function (event) {
|
|
338
|
+
_this.events[event.action](pen, event);
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
}
|
|
305
344
|
// 事件冒泡,子执行完,父执行
|
|
306
345
|
_this.doEvent(_this.store.pens[pen.parentId], eventName);
|
|
307
346
|
};
|
|
@@ -426,6 +465,17 @@ var Meta2d = /** @class */ (function () {
|
|
|
426
465
|
Meta2d.prototype.getOptions = function () {
|
|
427
466
|
return this.store.options;
|
|
428
467
|
};
|
|
468
|
+
Meta2d.prototype.setTheme = function (theme) {
|
|
469
|
+
this.store.data.theme = theme;
|
|
470
|
+
this.setBackgroundColor(this.store.theme[theme].background);
|
|
471
|
+
this.canvas.parentElement.style.background = this.store.theme[theme].parentBackground;
|
|
472
|
+
this.store.data.color = this.store.theme[theme].color;
|
|
473
|
+
this.setOptions({
|
|
474
|
+
ruleColor: this.store.theme[theme].ruleColor,
|
|
475
|
+
ruleOptions: this.store.theme[theme].ruleOptions
|
|
476
|
+
});
|
|
477
|
+
this.render();
|
|
478
|
+
};
|
|
429
479
|
Meta2d.prototype.setDatabyOptions = function (options) {
|
|
430
480
|
if (options === void 0) { options = {}; }
|
|
431
481
|
var color = options.color, activeColor = options.activeColor, activeBackground = options.activeBackground, grid = options.grid, gridColor = options.gridColor, gridSize = options.gridSize, fromArrow = options.fromArrow, toArrow = options.toArrow, rule = options.rule, ruleColor = options.ruleColor, textColor = options.textColor;
|
|
@@ -1983,6 +2033,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
1983
2033
|
else if (net.protocol === 'http') {
|
|
1984
2034
|
https.push({
|
|
1985
2035
|
url: net.url,
|
|
2036
|
+
interval: net.interval,
|
|
1986
2037
|
headers: net.headers || undefined,
|
|
1987
2038
|
method: net.method,
|
|
1988
2039
|
body: net.body,
|
|
@@ -2183,20 +2234,26 @@ var Meta2d = /** @class */ (function () {
|
|
|
2183
2234
|
});
|
|
2184
2235
|
}); });
|
|
2185
2236
|
}
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2237
|
+
if (enable) {
|
|
2238
|
+
this.updateTimer = setInterval(function () {
|
|
2239
|
+
//模拟数据
|
|
2189
2240
|
_this.store.data.pens.forEach(function (pen) {
|
|
2190
2241
|
_this.penMock(pen);
|
|
2191
2242
|
});
|
|
2192
|
-
|
|
2243
|
+
// https.forEach(async (_item) => {
|
|
2244
|
+
// this.requestHttp(_item);
|
|
2245
|
+
// });
|
|
2246
|
+
// this.render();
|
|
2247
|
+
}, this.store.data.networkInterval || 1000);
|
|
2248
|
+
}
|
|
2249
|
+
https.forEach(function (_item, index) {
|
|
2250
|
+
_this.updateTimerList[index] = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2193
2251
|
return __generator(this, function (_a) {
|
|
2194
2252
|
this.requestHttp(_item);
|
|
2195
2253
|
return [2 /*return*/];
|
|
2196
2254
|
});
|
|
2197
|
-
}); });
|
|
2198
|
-
|
|
2199
|
-
}, this.store.data.networkInterval || 1000);
|
|
2255
|
+
}); }, _item.interval || 1000);
|
|
2256
|
+
});
|
|
2200
2257
|
};
|
|
2201
2258
|
Meta2d.prototype.requestHttp = function (_req) {
|
|
2202
2259
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -2253,6 +2310,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
2253
2310
|
this.websockets = undefined;
|
|
2254
2311
|
clearInterval(this.updateTimer);
|
|
2255
2312
|
this.updateTimer = undefined;
|
|
2313
|
+
this.updateTimerList &&
|
|
2314
|
+
this.updateTimerList.forEach(function (_updateTimer) {
|
|
2315
|
+
clearInterval(_updateTimer);
|
|
2316
|
+
_updateTimer = undefined;
|
|
2317
|
+
});
|
|
2256
2318
|
};
|
|
2257
2319
|
Meta2d.prototype.socketCallback = function (message, context) {
|
|
2258
2320
|
var _this = this;
|