@meta2d/core 1.0.36 → 1.0.37
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 +2 -2
- package/src/canvas/canvas.js +92 -32
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +21 -1
- package/src/core.js +76 -4
- package/src/core.js.map +1 -1
- package/src/diagrams/index.d.ts +1 -0
- package/src/diagrams/index.js +1 -0
- package/src/diagrams/index.js.map +1 -1
- package/src/options.d.ts +12 -0
- package/src/pen/index.d.ts +1 -0
- package/src/pen/index.js +1 -0
- package/src/pen/index.js.map +1 -1
- package/src/pen/model.d.ts +8 -0
- package/src/pen/model.js +1 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/plugin.d.ts +5 -0
- package/src/pen/plugin.js +88 -0
- package/src/pen/plugin.js.map +1 -0
- package/src/pen/render.js +6 -0
- package/src/pen/render.js.map +1 -1
- package/src/store/store.d.ts +2 -1
- package/src/store/store.js +1 -0
- package/src/store/store.js.map +1 -1
package/src/core.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventType, Handler, WildcardHandler } from 'mitt';
|
|
2
2
|
import { Canvas } from './canvas';
|
|
3
|
-
import { Options } from './options';
|
|
3
|
+
import { Options, PenPlugin, PluginOptions } from './options';
|
|
4
4
|
import { calcTextDrawRect, calcTextLines, calcTextRect, facePen, getWords, LockState, Pen, renderPenRaw, IValue, setElemPosition } from './pen';
|
|
5
5
|
import { Point } from './point';
|
|
6
6
|
import { EditAction, register, registerAnchors, registerCanvasDraw, Meta2dData, Meta2dStore, Network, HttpOptions } from './store';
|
|
@@ -16,6 +16,12 @@ export declare class Meta2d {
|
|
|
16
16
|
mqttClient: MqttClient;
|
|
17
17
|
websockets: WebSocket[];
|
|
18
18
|
mqttClients: MqttClient[];
|
|
19
|
+
penPluginMap: Map<PenPlugin, {
|
|
20
|
+
tag?: string;
|
|
21
|
+
name?: string;
|
|
22
|
+
id?: string;
|
|
23
|
+
option: Object;
|
|
24
|
+
}[]>;
|
|
19
25
|
socketFn: (e: string, context?: {
|
|
20
26
|
meta2d?: Meta2d;
|
|
21
27
|
type?: string;
|
|
@@ -421,6 +427,20 @@ export declare class Meta2d {
|
|
|
421
427
|
* @returns 组合图形
|
|
422
428
|
*/
|
|
423
429
|
toComponent(pens?: Pen[], showChild?: number, anchor?: boolean): Pen[];
|
|
430
|
+
/**
|
|
431
|
+
* @description 安装插件方法
|
|
432
|
+
* @param plugins 插件列表及其配置项
|
|
433
|
+
* @param pen {string | Pen} 接受tag、name、或者Pen对象*/
|
|
434
|
+
installPenPlugins(pen: {
|
|
435
|
+
tag?: string;
|
|
436
|
+
name?: string;
|
|
437
|
+
id?: string;
|
|
438
|
+
}, plugins: PluginOptions[]): void;
|
|
439
|
+
uninstallPenPlugins(pen: {
|
|
440
|
+
tag?: string;
|
|
441
|
+
name?: string;
|
|
442
|
+
id?: string;
|
|
443
|
+
}, plugins: PluginOptions[]): void;
|
|
424
444
|
setVisible(pen: Pen, visible: boolean, render?: boolean): void;
|
|
425
445
|
clearHover(): void;
|
|
426
446
|
closeSocket(): void;
|
package/src/core.js
CHANGED
|
@@ -83,7 +83,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
83
83
|
};
|
|
84
84
|
import { commonAnchors, commonPens, cube } from './diagrams';
|
|
85
85
|
import { Canvas } from './canvas';
|
|
86
|
-
import { calcInView, calcTextDrawRect, calcTextLines, calcTextRect, facePen, formatAttrs, getAllChildren, getFromAnchor, getParent, getToAnchor, getWords, LockState, PenType, renderPenRaw, setElemPosition, connectLine, nearestAnchor, setChildValue, isAncestor, isShowChild, CanvasLayer, } from './pen';
|
|
86
|
+
import { calcInView, calcTextDrawRect, calcTextLines, calcTextRect, facePen, formatAttrs, getAllChildren, getFromAnchor, getParent, getToAnchor, getWords, LockState, PenType, renderPenRaw, setElemPosition, connectLine, nearestAnchor, setChildValue, isAncestor, isShowChild, CanvasLayer, validationPlugin, } from './pen';
|
|
87
87
|
import { rotatePoint } from './point';
|
|
88
88
|
import { clearStore, EditType, globalStore, register, registerAnchors, registerCanvasDraw, useStore, } from './store';
|
|
89
89
|
import { formatPadding, loadCss, s8, valueInArray, valueInRange, } from './utils';
|
|
@@ -102,6 +102,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
102
102
|
function Meta2d(parent, opts) {
|
|
103
103
|
var _this = this;
|
|
104
104
|
if (opts === void 0) { opts = {}; }
|
|
105
|
+
this.penPluginMap = new Map();
|
|
105
106
|
this.events = {};
|
|
106
107
|
this.facePen = facePen;
|
|
107
108
|
this.getWords = getWords;
|
|
@@ -893,7 +894,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
893
894
|
var e_1, _a, e_2, _b, e_3, _c, e_4, _e;
|
|
894
895
|
var _this = this;
|
|
895
896
|
if (render === void 0) { render = true; }
|
|
896
|
-
this.clear(false, data.template);
|
|
897
|
+
this.clear(false, data === null || data === void 0 ? void 0 : data.template);
|
|
897
898
|
this.canvas.autoPolylineFlag = true;
|
|
898
899
|
if (data) {
|
|
899
900
|
this.setBackgroundImage(data.bkImage, data);
|
|
@@ -4112,11 +4113,16 @@ var Meta2d = /** @class */ (function () {
|
|
|
4112
4113
|
},
|
|
4113
4114
|
];
|
|
4114
4115
|
}
|
|
4116
|
+
//如果本身就是 一个 组合图元
|
|
4117
|
+
var parents = components.filter(function (pen) { return !pen.parentId; });
|
|
4115
4118
|
var p = components.find(function (pen) {
|
|
4116
4119
|
return pen.width === rect.width && pen.height === rect.height;
|
|
4117
4120
|
});
|
|
4118
4121
|
var oneIsParent = p && showChild === undefined;
|
|
4119
|
-
if (
|
|
4122
|
+
if (parents.length === 1) {
|
|
4123
|
+
parent = parents[0];
|
|
4124
|
+
}
|
|
4125
|
+
else if (oneIsParent) {
|
|
4120
4126
|
if (!p.children) {
|
|
4121
4127
|
p.children = [];
|
|
4122
4128
|
}
|
|
@@ -4142,10 +4148,76 @@ var Meta2d = /** @class */ (function () {
|
|
|
4142
4148
|
pen.locked = (_a = pen.lockedOnCombine) !== null && _a !== void 0 ? _a : LockState.DisableMove;
|
|
4143
4149
|
// pen.type = PenType.Node;
|
|
4144
4150
|
});
|
|
4145
|
-
return oneIsParent
|
|
4151
|
+
return (oneIsParent || parents.length === 1)
|
|
4146
4152
|
? deepClone(components)
|
|
4147
4153
|
: deepClone(__spreadArray([parent], __read(components), false));
|
|
4148
4154
|
};
|
|
4155
|
+
// TODO 安装pen插件 此处是否应当进行相关的适配?不再让插件内部处理install的目标逻辑?
|
|
4156
|
+
/**
|
|
4157
|
+
* @description 安装插件方法
|
|
4158
|
+
* @param plugins 插件列表及其配置项
|
|
4159
|
+
* @param pen {string | Pen} 接受tag、name、或者Pen对象*/
|
|
4160
|
+
Meta2d.prototype.installPenPlugins = function (pen, plugins) {
|
|
4161
|
+
var _this = this;
|
|
4162
|
+
if (!pen.tag && !pen.name && !pen.id)
|
|
4163
|
+
return;
|
|
4164
|
+
var type;
|
|
4165
|
+
pen.id ? type = 'id' :
|
|
4166
|
+
pen.tag ? type = 'tag' :
|
|
4167
|
+
pen.name ? type = 'name' : '';
|
|
4168
|
+
plugins.forEach(function (pluginConfig) {
|
|
4169
|
+
var _a, _b;
|
|
4170
|
+
var plugin = pluginConfig.plugin;
|
|
4171
|
+
var option = pluginConfig.options;
|
|
4172
|
+
if (!plugin)
|
|
4173
|
+
return;
|
|
4174
|
+
// 插件校验
|
|
4175
|
+
if (validationPlugin(plugin) && type) {
|
|
4176
|
+
plugin.install(pen, option);
|
|
4177
|
+
// 若当前不存在此插件
|
|
4178
|
+
if (!_this.penPluginMap.has(plugin)) {
|
|
4179
|
+
_this.penPluginMap.set(plugin, [(_a = {}, _a[type] = pen[type], _a.option = option, _a)]);
|
|
4180
|
+
}
|
|
4181
|
+
else {
|
|
4182
|
+
var op = _this.penPluginMap.get(plugin).find(function (i) {
|
|
4183
|
+
return i[type] === pen[type];
|
|
4184
|
+
});
|
|
4185
|
+
// 存在替换
|
|
4186
|
+
if (op) {
|
|
4187
|
+
op.option = option;
|
|
4188
|
+
}
|
|
4189
|
+
else {
|
|
4190
|
+
_this.penPluginMap.get(plugin).push((_b = {},
|
|
4191
|
+
_b[type] = pen[type],
|
|
4192
|
+
_b.option = option,
|
|
4193
|
+
_b));
|
|
4194
|
+
}
|
|
4195
|
+
}
|
|
4196
|
+
}
|
|
4197
|
+
});
|
|
4198
|
+
};
|
|
4199
|
+
Meta2d.prototype.uninstallPenPlugins = function (pen, plugins) {
|
|
4200
|
+
var _this = this;
|
|
4201
|
+
var type;
|
|
4202
|
+
pen.id ? type = 'id' :
|
|
4203
|
+
pen.tag ? type = 'tag' :
|
|
4204
|
+
pen.name ? type = 'name' : '';
|
|
4205
|
+
if (!type)
|
|
4206
|
+
return;
|
|
4207
|
+
plugins.forEach(function (pluginConfig) {
|
|
4208
|
+
var plugin = pluginConfig.plugin;
|
|
4209
|
+
plugin.uninstall(pen, pluginConfig.options);
|
|
4210
|
+
var mapList = _this.penPluginMap.get(plugin);
|
|
4211
|
+
var op = mapList.findIndex(function (i) { return i[type] === pen[type]; });
|
|
4212
|
+
if (op !== -1) {
|
|
4213
|
+
mapList.splice(op, 1);
|
|
4214
|
+
// TODO 在运行时 插件卸载后是否需要移除?
|
|
4215
|
+
if (mapList.length === 0) {
|
|
4216
|
+
_this.penPluginMap.delete(plugin);
|
|
4217
|
+
}
|
|
4218
|
+
}
|
|
4219
|
+
});
|
|
4220
|
+
};
|
|
4149
4221
|
Meta2d.prototype.setVisible = function (pen, visible, render) {
|
|
4150
4222
|
var e_18, _a;
|
|
4151
4223
|
if (render === void 0) { render = true; }
|