@easy-editor/plugin-dashboard 0.0.17 → 1.0.1
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/README.md +121 -1
- package/dist/{cjs/index.js → index.cjs} +31 -63
- package/dist/index.d.ts +21 -4
- package/dist/index.js +31 -62
- package/package.json +12 -14
- package/dist/cjs/index.js.map +0 -1
- package/dist/esm/index.js +0 -915
- package/dist/esm/index.js.map +0 -1
- package/dist/materials/group/component.d.ts +0 -5
- package/dist/materials/group/configure.d.ts +0 -3
- package/dist/materials/group/index.d.ts +0 -3
- package/dist/materials/group/meta.d.ts +0 -3
package/dist/esm/index.js
DELETED
|
@@ -1,915 +0,0 @@
|
|
|
1
|
-
import { DESIGNER_EVENT, DragObjectType, getConvertedExtraKey } from '@easy-editor/core';
|
|
2
|
-
import { observable, computed, action } from 'mobx';
|
|
3
|
-
import { forwardRef } from 'react';
|
|
4
|
-
import { jsx } from 'react/jsx-runtime';
|
|
5
|
-
|
|
6
|
-
function _applyDecs2311(e, t, n, r, o, i) {
|
|
7
|
-
var a,
|
|
8
|
-
c,
|
|
9
|
-
u,
|
|
10
|
-
s,
|
|
11
|
-
f,
|
|
12
|
-
l,
|
|
13
|
-
p,
|
|
14
|
-
d = Symbol.metadata || Symbol.for("Symbol.metadata"),
|
|
15
|
-
m = Object.defineProperty,
|
|
16
|
-
h = Object.create,
|
|
17
|
-
y = [h(null), h(null)],
|
|
18
|
-
v = t.length;
|
|
19
|
-
function g(t, n, r) {
|
|
20
|
-
return function (o, i) {
|
|
21
|
-
n && (i = o, o = e);
|
|
22
|
-
for (var a = 0; a < t.length; a++) i = t[a].apply(o, r ? [i] : []);
|
|
23
|
-
return r ? i : o;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function b(e, t, n, r) {
|
|
27
|
-
if ("function" != typeof e && (r || void 0 !== e)) throw new TypeError(t + " must " + (n || "be") + " a function" + (r ? "" : " or undefined"));
|
|
28
|
-
return e;
|
|
29
|
-
}
|
|
30
|
-
function applyDec(e, t, n, r, o, i, u, s, f, l, p) {
|
|
31
|
-
function d(e) {
|
|
32
|
-
if (!p(e)) throw new TypeError("Attempted to access private element on non-instance");
|
|
33
|
-
}
|
|
34
|
-
var h = [].concat(t[0]),
|
|
35
|
-
v = t[3],
|
|
36
|
-
w = !u,
|
|
37
|
-
D = 1 === o,
|
|
38
|
-
S = 3 === o,
|
|
39
|
-
j = 4 === o,
|
|
40
|
-
E = 2 === o;
|
|
41
|
-
function I(t, n, r) {
|
|
42
|
-
return function (o, i) {
|
|
43
|
-
return n && (i = o, o = e), r && r(o), P[t].call(o, i);
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
if (!w) {
|
|
47
|
-
var P = {},
|
|
48
|
-
k = [],
|
|
49
|
-
F = S ? "get" : j || D ? "set" : "value";
|
|
50
|
-
if (f ? (l || D ? P = {
|
|
51
|
-
get: _setFunctionName(function () {
|
|
52
|
-
return v(this);
|
|
53
|
-
}, r, "get"),
|
|
54
|
-
set: function (e) {
|
|
55
|
-
t[4](this, e);
|
|
56
|
-
}
|
|
57
|
-
} : P[F] = v, l || _setFunctionName(P[F], r, E ? "" : F)) : l || (P = Object.getOwnPropertyDescriptor(e, r)), !l && !f) {
|
|
58
|
-
if ((c = y[+s][r]) && 7 != (c ^ o)) throw Error("Decorating two elements with the same name (" + P[F].name + ") is not supported yet");
|
|
59
|
-
y[+s][r] = o < 3 ? 1 : o;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
for (var N = e, O = h.length - 1; O >= 0; O -= n ? 2 : 1) {
|
|
63
|
-
var T = b(h[O], "A decorator", "be", !0),
|
|
64
|
-
z = n ? h[O - 1] : void 0,
|
|
65
|
-
A = {},
|
|
66
|
-
H = {
|
|
67
|
-
kind: ["field", "accessor", "method", "getter", "setter", "class"][o],
|
|
68
|
-
name: r,
|
|
69
|
-
metadata: a,
|
|
70
|
-
addInitializer: function (e, t) {
|
|
71
|
-
if (e.v) throw new TypeError("attempted to call addInitializer after decoration was finished");
|
|
72
|
-
b(t, "An initializer", "be", !0), i.push(t);
|
|
73
|
-
}.bind(null, A)
|
|
74
|
-
};
|
|
75
|
-
if (w) c = T.call(z, N, H), A.v = 1, b(c, "class decorators", "return") && (N = c);else if (H.static = s, H.private = f, c = H.access = {
|
|
76
|
-
has: f ? p.bind() : function (e) {
|
|
77
|
-
return r in e;
|
|
78
|
-
}
|
|
79
|
-
}, j || (c.get = f ? E ? function (e) {
|
|
80
|
-
return d(e), P.value;
|
|
81
|
-
} : I("get", 0, d) : function (e) {
|
|
82
|
-
return e[r];
|
|
83
|
-
}), E || S || (c.set = f ? I("set", 0, d) : function (e, t) {
|
|
84
|
-
e[r] = t;
|
|
85
|
-
}), N = T.call(z, D ? {
|
|
86
|
-
get: P.get,
|
|
87
|
-
set: P.set
|
|
88
|
-
} : P[F], H), A.v = 1, D) {
|
|
89
|
-
if ("object" == typeof N && N) (c = b(N.get, "accessor.get")) && (P.get = c), (c = b(N.set, "accessor.set")) && (P.set = c), (c = b(N.init, "accessor.init")) && k.unshift(c);else if (void 0 !== N) throw new TypeError("accessor decorators must return an object with get, set, or init properties or undefined");
|
|
90
|
-
} else b(N, (l ? "field" : "method") + " decorators", "return") && (l ? k.unshift(N) : P[F] = N);
|
|
91
|
-
}
|
|
92
|
-
return o < 2 && u.push(g(k, s, 1), g(i, s, 0)), l || w || (f ? D ? u.splice(-1, 0, I("get", s), I("set", s)) : u.push(E ? P[F] : b.call.bind(P[F])) : m(e, r, P)), N;
|
|
93
|
-
}
|
|
94
|
-
function w(e) {
|
|
95
|
-
return m(e, d, {
|
|
96
|
-
configurable: !0,
|
|
97
|
-
enumerable: !0,
|
|
98
|
-
value: a
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return a = h(null == a ? null : a), f = [], l = function (e) {
|
|
102
|
-
e && f.push(g(e));
|
|
103
|
-
}, p = function (t, r) {
|
|
104
|
-
for (var i = 0; i < n.length; i++) {
|
|
105
|
-
var a = n[i],
|
|
106
|
-
c = a[1],
|
|
107
|
-
l = 7 & c;
|
|
108
|
-
if ((8 & c) == t && !l == r) {
|
|
109
|
-
var p = a[2],
|
|
110
|
-
d = !!a[3],
|
|
111
|
-
m = 16 & c;
|
|
112
|
-
applyDec(t ? e : e.prototype, a, m, d ? "#" + p : _toPropertyKey(p), l, l < 2 ? [] : t ? s = s || [] : u = u || [], f, !!t, d, r, t && d ? function (t) {
|
|
113
|
-
return _checkInRHS(t) === e;
|
|
114
|
-
} : o);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}, p(8, 0), p(0, 0), p(8, 1), p(0, 1), l(u), l(s), c = f, v || w(e), {
|
|
118
|
-
e: c,
|
|
119
|
-
get c() {
|
|
120
|
-
var n = [];
|
|
121
|
-
return v && [w(e = applyDec(e, [t], r, e.name, 5, n)), g(n, 1)];
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
function _checkInRHS(e) {
|
|
126
|
-
if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null"));
|
|
127
|
-
return e;
|
|
128
|
-
}
|
|
129
|
-
function _setFunctionName(e, t, n) {
|
|
130
|
-
"symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : "");
|
|
131
|
-
try {
|
|
132
|
-
Object.defineProperty(e, "name", {
|
|
133
|
-
configurable: !0,
|
|
134
|
-
value: n ? n + " " + t : t
|
|
135
|
-
});
|
|
136
|
-
} catch (e) {}
|
|
137
|
-
return e;
|
|
138
|
-
}
|
|
139
|
-
function _toPrimitive(t, r) {
|
|
140
|
-
if ("object" != typeof t || !t) return t;
|
|
141
|
-
var e = t[Symbol.toPrimitive];
|
|
142
|
-
if (void 0 !== e) {
|
|
143
|
-
var i = e.call(t, r || "default");
|
|
144
|
-
if ("object" != typeof i) return i;
|
|
145
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
146
|
-
}
|
|
147
|
-
return ("string" === r ? String : Number)(t);
|
|
148
|
-
}
|
|
149
|
-
function _toPropertyKey(t) {
|
|
150
|
-
var i = _toPrimitive(t, "string");
|
|
151
|
-
return "symbol" == typeof i ? i : i + "";
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
let _initProto, _init_enabled, _init_extra_enabled, _init_guideLines, _init_extra_guideLines, _init_nodeLineMap, _init_extra_nodeLineMap, _init_adsorptionLines, _init_extra_adsorptionLines;
|
|
155
|
-
class GuideLine {
|
|
156
|
-
static {
|
|
157
|
-
[_init_enabled, _init_extra_enabled, _init_guideLines, _init_extra_guideLines, _init_nodeLineMap, _init_extra_nodeLineMap, _init_adsorptionLines, _init_extra_adsorptionLines, _initProto] = _applyDecs2311(this, [], [[observable, 1, "enabled"], [[observable, observable.shallow], 17, "guideLines"], [computed, 3, "guideLinesMap"], [[observable, observable.shallow], 17, "nodeLineMap"], [observable, 1, "adsorptionLines"], [action, 2, "addGuideLine"], [action, 2, "removeGuideLine"], [action, 2, "updateGuideLine"], [action, 2, "calculateGuideLineInfo"], [action, 2, "getAdsorptionPosition"], [action, 2, "resetAdsorptionLines"]]).e;
|
|
158
|
-
}
|
|
159
|
-
#A = (_initProto(this), _init_enabled(this, true));
|
|
160
|
-
get enabled() {
|
|
161
|
-
return this.#A;
|
|
162
|
-
}
|
|
163
|
-
set enabled(v) {
|
|
164
|
-
this.#A = v;
|
|
165
|
-
}
|
|
166
|
-
#B = (_init_extra_enabled(this), _init_guideLines(this, []));
|
|
167
|
-
get guideLines() {
|
|
168
|
-
return this.#B;
|
|
169
|
-
}
|
|
170
|
-
set guideLines(v) {
|
|
171
|
-
this.#B = v;
|
|
172
|
-
}
|
|
173
|
-
get guideLinesMap() {
|
|
174
|
-
const result = Object.groupBy(this.guideLines, item => item.type);
|
|
175
|
-
return {
|
|
176
|
-
verticalLinesMap: new Map(result.vertical?.map(item => [item.position, item])),
|
|
177
|
-
horizontalLinesMap: new Map(result.horizontal?.map(item => [item.position, item]))
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
#C = (_init_extra_guideLines(this), _init_nodeLineMap(this, {
|
|
181
|
-
verticalLinesMap: new Map(),
|
|
182
|
-
horizontalLinesMap: new Map()
|
|
183
|
-
}));
|
|
184
|
-
get nodeLineMap() {
|
|
185
|
-
return this.#C;
|
|
186
|
-
}
|
|
187
|
-
set nodeLineMap(v) {
|
|
188
|
-
this.#C = v;
|
|
189
|
-
}
|
|
190
|
-
#D = (_init_extra_nodeLineMap(this), _init_adsorptionLines(this, {
|
|
191
|
-
verticalLines: new Set(),
|
|
192
|
-
horizontalLines: new Set()
|
|
193
|
-
}));
|
|
194
|
-
get adsorptionLines() {
|
|
195
|
-
return this.#D;
|
|
196
|
-
}
|
|
197
|
-
set adsorptionLines(v) {
|
|
198
|
-
this.#D = v;
|
|
199
|
-
}
|
|
200
|
-
get currentDocument() {
|
|
201
|
-
return this.designer.currentDocument;
|
|
202
|
-
}
|
|
203
|
-
constructor(designer) {
|
|
204
|
-
this.designer = designer;
|
|
205
|
-
this.designer.onEvent(DESIGNER_EVENT.VIEWPORT_MOUNT, ({
|
|
206
|
-
viewport
|
|
207
|
-
}) => {
|
|
208
|
-
this.addGuideLine({
|
|
209
|
-
id: 'viewport-vertical-left',
|
|
210
|
-
type: 'vertical',
|
|
211
|
-
position: 0
|
|
212
|
-
});
|
|
213
|
-
this.addGuideLine({
|
|
214
|
-
id: 'viewport-vertical-middle',
|
|
215
|
-
type: 'vertical',
|
|
216
|
-
position: viewport.width / 2
|
|
217
|
-
});
|
|
218
|
-
this.addGuideLine({
|
|
219
|
-
id: 'viewport-vertical-right',
|
|
220
|
-
type: 'vertical',
|
|
221
|
-
position: viewport.width
|
|
222
|
-
});
|
|
223
|
-
this.addGuideLine({
|
|
224
|
-
id: 'viewport-horizontal-top',
|
|
225
|
-
type: 'horizontal',
|
|
226
|
-
position: 0
|
|
227
|
-
});
|
|
228
|
-
this.addGuideLine({
|
|
229
|
-
id: 'viewport-horizontal-middle',
|
|
230
|
-
type: 'horizontal',
|
|
231
|
-
position: viewport.height / 2
|
|
232
|
-
});
|
|
233
|
-
this.addGuideLine({
|
|
234
|
-
id: 'viewport-horizontal-bottom',
|
|
235
|
-
type: 'horizontal',
|
|
236
|
-
position: viewport.height
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
addGuideLine(guideLine) {
|
|
241
|
-
this.guideLines.push(guideLine);
|
|
242
|
-
}
|
|
243
|
-
removeGuideLine(id) {
|
|
244
|
-
const index = this.guideLines.findIndex(item => item.id === id);
|
|
245
|
-
if (index !== -1) {
|
|
246
|
-
this.guideLines.splice(index, 1);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
updateGuideLine(id, guideLine) {
|
|
250
|
-
const index = this.guideLines.findIndex(item => item.id === id);
|
|
251
|
-
if (index !== -1) {
|
|
252
|
-
this.guideLines[index] = guideLine;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
calculateGuideLineInfo() {
|
|
256
|
-
if (!this.enabled) return;
|
|
257
|
-
const verticalLinesMap = new Map();
|
|
258
|
-
const horizontalLinesMap = new Map();
|
|
259
|
-
const nodes = [...this.currentDocument.nodesMap.values()];
|
|
260
|
-
const selected = [];
|
|
261
|
-
for (const node of this.designer.selection.getNodes()) {
|
|
262
|
-
if (node.isGroup) {
|
|
263
|
-
selected.push(...node.getAllNodesInGroup().map(node => node.id));
|
|
264
|
-
} else {
|
|
265
|
-
selected.push(node.id);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
nodes.filter(node => !node.hidden).forEach(node => {
|
|
269
|
-
if (selected.includes(node.id) || node.isRoot || node.isGroup) return;
|
|
270
|
-
const nodeRect = node.getDashboardRect();
|
|
271
|
-
const verticalNodeLines = [nodeRect.left, nodeRect.left + nodeRect.width / 2, nodeRect.right];
|
|
272
|
-
const horizontalNodeLines = [nodeRect.top, nodeRect.top + nodeRect.height / 2, nodeRect.bottom];
|
|
273
|
-
for (const line of verticalNodeLines) {
|
|
274
|
-
const position = Math.round(line);
|
|
275
|
-
verticalLinesMap.set(position, {
|
|
276
|
-
type: 'vertical',
|
|
277
|
-
position
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
for (const line of horizontalNodeLines) {
|
|
281
|
-
const position = Math.round(line);
|
|
282
|
-
horizontalLinesMap.set(position, {
|
|
283
|
-
type: 'horizontal',
|
|
284
|
-
position
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
this.nodeLineMap.verticalLinesMap = verticalLinesMap;
|
|
289
|
-
this.nodeLineMap.horizontalLinesMap = horizontalLinesMap;
|
|
290
|
-
}
|
|
291
|
-
adsorptionSize = (_init_extra_adsorptionLines(this), 10);
|
|
292
|
-
getAdsorptionPosition(rect, adsorption) {
|
|
293
|
-
if (typeof adsorption === 'number') {
|
|
294
|
-
adsorption = [adsorption];
|
|
295
|
-
}
|
|
296
|
-
this.resetAdsorptionLines();
|
|
297
|
-
const adsorptionVerticalLines = [];
|
|
298
|
-
const adsorptionHorizontalLines = [];
|
|
299
|
-
const currentVerticalLine = [rect.left, rect.left + rect.width / 2, rect.right];
|
|
300
|
-
const currentHorizontalLine = [rect.top, rect.top + rect.height / 2, rect.bottom];
|
|
301
|
-
currentVerticalLine.forEach((item, index) => {
|
|
302
|
-
let minDistance = Number.POSITIVE_INFINITY;
|
|
303
|
-
this.nodeLineMap.verticalLinesMap.forEach((_, pos) => {
|
|
304
|
-
const distance = Math.abs(item - pos);
|
|
305
|
-
if (distance !== 0 && distance < this.adsorptionSize && distance < minDistance) {
|
|
306
|
-
minDistance = pos;
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
this.guideLinesMap.verticalLinesMap.forEach((_, pos) => {
|
|
310
|
-
const distance = Math.abs(item - pos);
|
|
311
|
-
if (distance !== 0 && distance < this.adsorptionSize && distance < minDistance) {
|
|
312
|
-
minDistance = pos;
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
if (minDistance !== Number.POSITIVE_INFINITY && adsorptionVerticalLines.findIndex(item => item.position === minDistance) === -1) {
|
|
316
|
-
adsorptionVerticalLines.push({
|
|
317
|
-
adsorption: index,
|
|
318
|
-
position: minDistance
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
currentHorizontalLine.forEach((item, index) => {
|
|
323
|
-
let minDistance = -1;
|
|
324
|
-
this.nodeLineMap.horizontalLinesMap.forEach((_, pos) => {
|
|
325
|
-
if (Math.abs(item - pos) < this.adsorptionSize) {
|
|
326
|
-
minDistance = pos;
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
this.guideLinesMap.horizontalLinesMap.forEach((_, pos) => {
|
|
330
|
-
const distance = Math.abs(item - pos);
|
|
331
|
-
if (distance < this.adsorptionSize && distance < minDistance) {
|
|
332
|
-
minDistance = pos;
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
if (minDistance !== -1 && adsorptionHorizontalLines.findIndex(item => item.position === minDistance) === -1) {
|
|
336
|
-
adsorptionHorizontalLines.push({
|
|
337
|
-
adsorption: index,
|
|
338
|
-
position: minDistance
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
const isAdsorption = adsorptionVerticalLines.length > 0 || adsorptionHorizontalLines.length > 0;
|
|
343
|
-
const adsorb = {
|
|
344
|
-
x: undefined,
|
|
345
|
-
y: undefined
|
|
346
|
-
};
|
|
347
|
-
if (isAdsorption) {
|
|
348
|
-
adsorptionVerticalLines.forEach(item => this.adsorptionLines.verticalLines.add(item.position));
|
|
349
|
-
adsorptionHorizontalLines.forEach(item => this.adsorptionLines.horizontalLines.add(item.position));
|
|
350
|
-
if (adsorptionVerticalLines.length > 0) {
|
|
351
|
-
if (adsorption) {
|
|
352
|
-
adsorb.x = adsorptionVerticalLines.find(item => adsorption.includes(item.adsorption));
|
|
353
|
-
} else {
|
|
354
|
-
const adsorptionPosition = Math.min(...adsorptionVerticalLines.map(item => item.position));
|
|
355
|
-
adsorb.x = adsorptionVerticalLines.find(item => item.position === adsorptionPosition);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
if (adsorptionHorizontalLines.length > 0) {
|
|
359
|
-
if (adsorption) {
|
|
360
|
-
adsorb.y = adsorptionHorizontalLines.find(item => adsorption.includes(item.adsorption));
|
|
361
|
-
} else {
|
|
362
|
-
const adsorptionPosition = Math.min(...adsorptionHorizontalLines.map(item => item.position));
|
|
363
|
-
adsorb.y = adsorptionHorizontalLines.find(item => item.position === adsorptionPosition);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
return {
|
|
368
|
-
isAdsorption,
|
|
369
|
-
adsorb
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
resetAdsorptionLines() {
|
|
373
|
-
this.adsorptionLines.verticalLines.clear();
|
|
374
|
-
this.adsorptionLines.horizontalLines.clear();
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
const Group = /*#__PURE__*/forwardRef((props, ref) => {
|
|
379
|
-
return /*#__PURE__*/jsx("div", {
|
|
380
|
-
ref: ref,
|
|
381
|
-
style: {
|
|
382
|
-
position: 'relative',
|
|
383
|
-
width: '100%',
|
|
384
|
-
height: '100%'
|
|
385
|
-
},
|
|
386
|
-
children: props?.children
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
const configure = {
|
|
391
|
-
props: [
|
|
392
|
-
],
|
|
393
|
-
component: {},
|
|
394
|
-
supports: {},
|
|
395
|
-
advanced: {
|
|
396
|
-
view: Group
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
const meta = {
|
|
401
|
-
componentName: 'Group',
|
|
402
|
-
title: '分组',
|
|
403
|
-
category: '内置',
|
|
404
|
-
configure
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
const updateNodeRect = (node, offset = {
|
|
408
|
-
x: 0,
|
|
409
|
-
y: 0
|
|
410
|
-
}) => {
|
|
411
|
-
if (node.isGroup) {
|
|
412
|
-
const nodeRect = node.getDashboardRect();
|
|
413
|
-
const delta = {
|
|
414
|
-
x: offset.x - nodeRect.x,
|
|
415
|
-
y: offset.y - nodeRect.y
|
|
416
|
-
};
|
|
417
|
-
for (const childNode of node.getAllNodesInGroup()) {
|
|
418
|
-
const childRect = childNode.getDashboardRect();
|
|
419
|
-
childNode.updateDashboardRect({
|
|
420
|
-
x: childRect.x + delta.x,
|
|
421
|
-
y: childRect.y + delta.y
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
} else {
|
|
425
|
-
node.updateDashboardRect({
|
|
426
|
-
x: offset.x,
|
|
427
|
-
y: offset.y
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
const updateNodeRectByDOM = (node, offset = {
|
|
432
|
-
x: 0,
|
|
433
|
-
y: 0
|
|
434
|
-
}) => {
|
|
435
|
-
const domNode = node.getDashboardContainer();
|
|
436
|
-
if (!domNode) {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
domNode.style.left = `${offset.x}px`;
|
|
440
|
-
domNode.style.top = `${offset.y}px`;
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
const defaultGroupSchema = {
|
|
444
|
-
componentName: 'Group',
|
|
445
|
-
title: '分组',
|
|
446
|
-
isGroup: true
|
|
447
|
-
};
|
|
448
|
-
const DashboardPlugin = options => {
|
|
449
|
-
const {
|
|
450
|
-
group = {}
|
|
451
|
-
} = options || {};
|
|
452
|
-
const {
|
|
453
|
-
schema: groupSchema = defaultGroupSchema
|
|
454
|
-
} = group || {};
|
|
455
|
-
return {
|
|
456
|
-
name: 'DashboardPlugin',
|
|
457
|
-
deps: [],
|
|
458
|
-
init(ctx) {
|
|
459
|
-
const {
|
|
460
|
-
designer,
|
|
461
|
-
simulator,
|
|
462
|
-
componentMetaManager,
|
|
463
|
-
hotkey,
|
|
464
|
-
logger
|
|
465
|
-
} = ctx;
|
|
466
|
-
const {
|
|
467
|
-
viewport
|
|
468
|
-
} = simulator;
|
|
469
|
-
hotkey.bind('ctrl+d', e => {
|
|
470
|
-
e.preventDefault();
|
|
471
|
-
logger.log('ctrl+d');
|
|
472
|
-
});
|
|
473
|
-
designer.onEvent(DESIGNER_EVENT.INIT, designer => {
|
|
474
|
-
designer.guideline = new GuideLine(designer);
|
|
475
|
-
});
|
|
476
|
-
componentMetaManager.createComponentMeta(meta);
|
|
477
|
-
simulator.addComponent('Group', Group);
|
|
478
|
-
const startOffsetNodeData = {
|
|
479
|
-
x: 0,
|
|
480
|
-
y: 0
|
|
481
|
-
};
|
|
482
|
-
designer.dragon.onDragstart(e => {
|
|
483
|
-
if (!e.shell) return;
|
|
484
|
-
const {
|
|
485
|
-
dragObject
|
|
486
|
-
} = e;
|
|
487
|
-
const shellRect = simulator.computeComponentInstanceRect(e.shell);
|
|
488
|
-
if (dragObject && dragObject.type === DragObjectType.NodeData) {
|
|
489
|
-
startOffsetNodeData.x = (e.globalX - shellRect?.left) / viewport.scale;
|
|
490
|
-
startOffsetNodeData.y = (e.globalY - shellRect?.top) / viewport.scale;
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
designer.onEvent(DESIGNER_EVENT.INSERT_NODE_BEFORE, e => {
|
|
494
|
-
const {
|
|
495
|
-
event
|
|
496
|
-
} = e;
|
|
497
|
-
const {
|
|
498
|
-
dragObject
|
|
499
|
-
} = event;
|
|
500
|
-
if (dragObject && dragObject.type === DragObjectType.NodeData) {
|
|
501
|
-
const nodeData = Array.isArray(dragObject.data) ? dragObject.data : [dragObject.data];
|
|
502
|
-
for (const schema of nodeData) {
|
|
503
|
-
if (!schema) continue;
|
|
504
|
-
if (!schema.$dashboard) {
|
|
505
|
-
schema.$dashboard = {};
|
|
506
|
-
}
|
|
507
|
-
if (!schema.$dashboard.rect) {
|
|
508
|
-
schema.$dashboard.rect = {};
|
|
509
|
-
}
|
|
510
|
-
schema.$dashboard.rect.x = event.canvasX - startOffsetNodeData.x;
|
|
511
|
-
schema.$dashboard.rect.y = event.canvasY - startOffsetNodeData.y;
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
let startNodes = {};
|
|
516
|
-
let startOffsetNodes = {};
|
|
517
|
-
let lastOffsetNodes = {};
|
|
518
|
-
designer.dragon.onDragstart(e => {
|
|
519
|
-
const {
|
|
520
|
-
dragObject
|
|
521
|
-
} = e;
|
|
522
|
-
if (dragObject && dragObject.type === DragObjectType.Node) {
|
|
523
|
-
designer.guideline.calculateGuideLineInfo();
|
|
524
|
-
for (const node of dragObject.nodes) {
|
|
525
|
-
if (!node) continue;
|
|
526
|
-
const rect = node.getDashboardRect();
|
|
527
|
-
if (rect) {
|
|
528
|
-
startNodes[node.id] = rect;
|
|
529
|
-
startOffsetNodes[node.id] = {
|
|
530
|
-
x: e.canvasX - rect.x,
|
|
531
|
-
y: e.canvasY - rect.y
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
const boxRect = calculateDashboardRectBox(dragObject.nodes);
|
|
536
|
-
if (boxRect) {
|
|
537
|
-
startNodes.box = boxRect;
|
|
538
|
-
startOffsetNodes.box = {
|
|
539
|
-
x: e.canvasX - boxRect.x,
|
|
540
|
-
y: e.canvasY - boxRect.y
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
designer.dragon.onDrag(e => {
|
|
546
|
-
const {
|
|
547
|
-
dragObject
|
|
548
|
-
} = e;
|
|
549
|
-
if (dragObject && dragObject.type === DragObjectType.Node) {
|
|
550
|
-
const {
|
|
551
|
-
x: boxStartX = 0,
|
|
552
|
-
y: boxStartY = 0,
|
|
553
|
-
width = 0,
|
|
554
|
-
height = 0
|
|
555
|
-
} = startNodes.box;
|
|
556
|
-
const {
|
|
557
|
-
x: boxX = 0,
|
|
558
|
-
y: boxY = 0
|
|
559
|
-
} = startOffsetNodes.box;
|
|
560
|
-
const {
|
|
561
|
-
isAdsorption,
|
|
562
|
-
adsorb
|
|
563
|
-
} = designer.guideline.getAdsorptionPosition(new DOMRect(e.canvasX - boxX, e.canvasY - boxY, width, height));
|
|
564
|
-
let adsorbX = undefined;
|
|
565
|
-
let adsorbY = undefined;
|
|
566
|
-
if (isAdsorption) {
|
|
567
|
-
if (adsorb.x) {
|
|
568
|
-
if (adsorb.x.adsorption === 0) {
|
|
569
|
-
adsorbX = adsorb.x.position;
|
|
570
|
-
} else if (adsorb.x.adsorption === 1) {
|
|
571
|
-
adsorbX = adsorb.x.position - width / 2;
|
|
572
|
-
} else if (adsorb.x.adsorption === 2) {
|
|
573
|
-
adsorbX = adsorb.x.position - width;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
if (adsorb.y) {
|
|
577
|
-
if (adsorb.y.adsorption === 0) {
|
|
578
|
-
adsorbY = adsorb.y.position;
|
|
579
|
-
} else if (adsorb.y.adsorption === 1) {
|
|
580
|
-
adsorbY = adsorb.y.position - height / 2;
|
|
581
|
-
} else if (adsorb.y.adsorption === 2) {
|
|
582
|
-
adsorbY = adsorb.y.position - height;
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
for (const node of dragObject.nodes) {
|
|
587
|
-
if (!node) continue;
|
|
588
|
-
const {
|
|
589
|
-
x: nodeStartX = 0,
|
|
590
|
-
y: nodeStartY = 0
|
|
591
|
-
} = startNodes[node.id];
|
|
592
|
-
const {
|
|
593
|
-
x,
|
|
594
|
-
y
|
|
595
|
-
} = startOffsetNodes[node.id];
|
|
596
|
-
let offsetX = e.canvasX - x;
|
|
597
|
-
let offsetY = e.canvasY - y;
|
|
598
|
-
if (isAdsorption) {
|
|
599
|
-
offsetX = adsorbX ? adsorbX + nodeStartX - boxStartX : offsetX;
|
|
600
|
-
offsetY = adsorbY ? adsorbY + nodeStartY - boxStartY : offsetY;
|
|
601
|
-
}
|
|
602
|
-
updateNodeRectByDOM(node, {
|
|
603
|
-
x: offsetX,
|
|
604
|
-
y: offsetY
|
|
605
|
-
});
|
|
606
|
-
lastOffsetNodes[node.id] = {
|
|
607
|
-
x: offsetX,
|
|
608
|
-
y: offsetY
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
});
|
|
613
|
-
designer.dragon.onDragend(e => {
|
|
614
|
-
const {
|
|
615
|
-
dragObject,
|
|
616
|
-
esc
|
|
617
|
-
} = e;
|
|
618
|
-
if (dragObject && dragObject.type === DragObjectType.Node) {
|
|
619
|
-
for (const node of dragObject.nodes) {
|
|
620
|
-
if (!node) continue;
|
|
621
|
-
if (esc) {
|
|
622
|
-
simulator.rerender();
|
|
623
|
-
} else {
|
|
624
|
-
const {
|
|
625
|
-
x: lastX = 0,
|
|
626
|
-
y: lastY = 0
|
|
627
|
-
} = lastOffsetNodes[node.id];
|
|
628
|
-
updateNodeRect(node, {
|
|
629
|
-
x: lastX,
|
|
630
|
-
y: lastY
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
designer.guideline.resetAdsorptionLines();
|
|
635
|
-
}
|
|
636
|
-
startNodes = {};
|
|
637
|
-
startOffsetNodes = {};
|
|
638
|
-
lastOffsetNodes = {};
|
|
639
|
-
});
|
|
640
|
-
},
|
|
641
|
-
extend({
|
|
642
|
-
extendClass,
|
|
643
|
-
extend
|
|
644
|
-
}) {
|
|
645
|
-
const {
|
|
646
|
-
Node,
|
|
647
|
-
Designer
|
|
648
|
-
} = extendClass;
|
|
649
|
-
const originalInit = Designer.prototype.init;
|
|
650
|
-
extend('Designer', {
|
|
651
|
-
init: {
|
|
652
|
-
value() {
|
|
653
|
-
originalInit.call(this);
|
|
654
|
-
this.guideline = new GuideLine(this);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
extend('Document', {
|
|
659
|
-
group: {
|
|
660
|
-
value(nodeIdList) {
|
|
661
|
-
if (nodeIdList.length === 0) return;
|
|
662
|
-
let nodeList = [];
|
|
663
|
-
if (typeof nodeIdList[0] === 'string') {
|
|
664
|
-
nodeList = nodeIdList.map(id => this.getNode(id));
|
|
665
|
-
}
|
|
666
|
-
const groupNode = this.createNode(groupSchema);
|
|
667
|
-
let maxZIndex = Number.POSITIVE_INFINITY;
|
|
668
|
-
for (const node of nodeList) {
|
|
669
|
-
if (node.index < maxZIndex) {
|
|
670
|
-
maxZIndex = node.index;
|
|
671
|
-
}
|
|
672
|
-
if (node && !node.isRoot) {
|
|
673
|
-
this.migrateNode(node, groupNode);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
this.rootNode?.insert(groupNode, maxZIndex);
|
|
677
|
-
return groupNode;
|
|
678
|
-
}
|
|
679
|
-
},
|
|
680
|
-
ungroup: {
|
|
681
|
-
value(group) {
|
|
682
|
-
let groupNode;
|
|
683
|
-
if (typeof group === 'string') {
|
|
684
|
-
groupNode = this.getNode(group);
|
|
685
|
-
} else {
|
|
686
|
-
groupNode = group;
|
|
687
|
-
}
|
|
688
|
-
if (!groupNode || !groupNode.isGroup || !groupNode.children) return;
|
|
689
|
-
const nodes = groupNode.childrenNodes;
|
|
690
|
-
while (nodes.length > 0) {
|
|
691
|
-
if (groupNode.parent) {
|
|
692
|
-
this.migrateNode(nodes[0], groupNode.parent);
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
this.removeNode(groupNode);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
});
|
|
699
|
-
const originalInitProps = Node.prototype.initBuiltinProps;
|
|
700
|
-
extend('Node', {
|
|
701
|
-
getDashboardContainer: {
|
|
702
|
-
value() {
|
|
703
|
-
const domNodes = this.getDOMNode();
|
|
704
|
-
return domNodes.length > 0 ? domNodes[0] : null;
|
|
705
|
-
}
|
|
706
|
-
},
|
|
707
|
-
getDashboardRect: {
|
|
708
|
-
value() {
|
|
709
|
-
if (!this.isGroup) {
|
|
710
|
-
const rect = this.getExtraPropValue('$dashboard.rect');
|
|
711
|
-
return new DOMRect(rect.x ?? 0, rect.y ?? 0, rect.width ?? 0, rect.height ?? 0);
|
|
712
|
-
}
|
|
713
|
-
let [minX, minY, maxX, maxY] = [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY];
|
|
714
|
-
for (const child of this.childrenNodes) {
|
|
715
|
-
const childRect = child.getDashboardRect();
|
|
716
|
-
minX = Math.min(minX, childRect.x);
|
|
717
|
-
minY = Math.min(minY, childRect.y);
|
|
718
|
-
maxX = Math.max(maxX, childRect.x + childRect.width);
|
|
719
|
-
maxY = Math.max(maxY, childRect.y + childRect.height);
|
|
720
|
-
}
|
|
721
|
-
return new DOMRect(minX, minY, maxX - minX, maxY - minY);
|
|
722
|
-
}
|
|
723
|
-
},
|
|
724
|
-
updateDashboardRect: {
|
|
725
|
-
value(rect) {
|
|
726
|
-
if (this.isGroup) return;
|
|
727
|
-
if (typeof rect.x === 'number') {
|
|
728
|
-
this.setExtraPropValue('$dashboard.rect.x', rect.x);
|
|
729
|
-
}
|
|
730
|
-
if (typeof rect.y === 'number') {
|
|
731
|
-
this.setExtraPropValue('$dashboard.rect.y', rect.y);
|
|
732
|
-
}
|
|
733
|
-
if (typeof rect.width === 'number') {
|
|
734
|
-
this.setExtraPropValue('$dashboard.rect.width', rect.width);
|
|
735
|
-
}
|
|
736
|
-
if (typeof rect.height === 'number') {
|
|
737
|
-
this.setExtraPropValue('$dashboard.rect.height', rect.height);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
},
|
|
741
|
-
isGroup: {
|
|
742
|
-
get() {
|
|
743
|
-
return this.getExtraPropValue('isGroup');
|
|
744
|
-
}
|
|
745
|
-
},
|
|
746
|
-
getCurrentGroup: {
|
|
747
|
-
value() {
|
|
748
|
-
let parent = this.parent;
|
|
749
|
-
while (parent && !parent.isGroup) {
|
|
750
|
-
parent = parent.parent;
|
|
751
|
-
}
|
|
752
|
-
return parent;
|
|
753
|
-
}
|
|
754
|
-
},
|
|
755
|
-
getTopGroup: {
|
|
756
|
-
value() {
|
|
757
|
-
let parent = this.parent;
|
|
758
|
-
let topGroup = null;
|
|
759
|
-
while (parent) {
|
|
760
|
-
if (parent.isGroup) {
|
|
761
|
-
topGroup = parent;
|
|
762
|
-
}
|
|
763
|
-
parent = parent.parent;
|
|
764
|
-
}
|
|
765
|
-
return topGroup;
|
|
766
|
-
}
|
|
767
|
-
},
|
|
768
|
-
getAllGroups: {
|
|
769
|
-
value() {
|
|
770
|
-
const groups = [];
|
|
771
|
-
let parent = this.parent;
|
|
772
|
-
while (parent) {
|
|
773
|
-
if (parent.isGroup) {
|
|
774
|
-
groups.push(parent);
|
|
775
|
-
}
|
|
776
|
-
parent = parent.parent;
|
|
777
|
-
}
|
|
778
|
-
return groups;
|
|
779
|
-
}
|
|
780
|
-
},
|
|
781
|
-
getNodesInGroup: {
|
|
782
|
-
value() {
|
|
783
|
-
if (!this.isGroup) return [];
|
|
784
|
-
const nodes = [];
|
|
785
|
-
for (const node of this.childrenNodes) {
|
|
786
|
-
if (!node.isGroup) {
|
|
787
|
-
nodes.push(node);
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
return nodes;
|
|
791
|
-
}
|
|
792
|
-
},
|
|
793
|
-
getAllNodesInGroup: {
|
|
794
|
-
value() {
|
|
795
|
-
if (!this.isGroup) return [];
|
|
796
|
-
const nodes = [];
|
|
797
|
-
for (const node of this.childrenNodes) {
|
|
798
|
-
if (node.isGroup) {
|
|
799
|
-
nodes.push(...node.getAllNodesInGroup());
|
|
800
|
-
} else {
|
|
801
|
-
nodes.push(node);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
return nodes;
|
|
805
|
-
}
|
|
806
|
-
},
|
|
807
|
-
initBuiltinProps: {
|
|
808
|
-
value() {
|
|
809
|
-
originalInitProps.call(this);
|
|
810
|
-
this.props.has(getConvertedExtraKey('isGroup')) || this.props.add(getConvertedExtraKey('isGroup'), false);
|
|
811
|
-
}
|
|
812
|
-
},
|
|
813
|
-
moveToLevel: {
|
|
814
|
-
value(level) {
|
|
815
|
-
if (level < -1 || level >= this.parent.childrenNodes.length) return;
|
|
816
|
-
if (this.index === level) return;
|
|
817
|
-
if (this.isRoot) return;
|
|
818
|
-
this.parent.insert(this, level);
|
|
819
|
-
}
|
|
820
|
-
},
|
|
821
|
-
levelTop: {
|
|
822
|
-
value() {
|
|
823
|
-
this.moveToLevel(0);
|
|
824
|
-
}
|
|
825
|
-
},
|
|
826
|
-
levelBottom: {
|
|
827
|
-
value() {
|
|
828
|
-
this.moveToLevel(-1);
|
|
829
|
-
}
|
|
830
|
-
},
|
|
831
|
-
levelUp: {
|
|
832
|
-
value() {
|
|
833
|
-
this.moveToLevel(this.index - 1);
|
|
834
|
-
}
|
|
835
|
-
},
|
|
836
|
-
levelDown: {
|
|
837
|
-
value() {
|
|
838
|
-
this.moveToLevel(this.index + 1);
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
});
|
|
842
|
-
extend('OffsetObserver', {
|
|
843
|
-
computeRect: {
|
|
844
|
-
value() {
|
|
845
|
-
const {
|
|
846
|
-
node,
|
|
847
|
-
instance
|
|
848
|
-
} = this.nodeInstance;
|
|
849
|
-
const host = node.document?.simulator;
|
|
850
|
-
const rect = host.computeComponentInstanceRect(instance);
|
|
851
|
-
const {
|
|
852
|
-
viewport
|
|
853
|
-
} = node.document.simulator;
|
|
854
|
-
const local = viewport.toLocalPoint({
|
|
855
|
-
clientX: rect.x,
|
|
856
|
-
clientY: rect.y
|
|
857
|
-
});
|
|
858
|
-
return new DOMRect(local.clientX, local.clientY, rect.width / viewport.scale, rect.height / viewport.scale);
|
|
859
|
-
}
|
|
860
|
-
},
|
|
861
|
-
height: {
|
|
862
|
-
get() {
|
|
863
|
-
return this.isRoot ? this.viewport.height : this._height;
|
|
864
|
-
}
|
|
865
|
-
},
|
|
866
|
-
width: {
|
|
867
|
-
get() {
|
|
868
|
-
return this.isRoot ? this.viewport.width : this._width;
|
|
869
|
-
}
|
|
870
|
-
},
|
|
871
|
-
top: {
|
|
872
|
-
get() {
|
|
873
|
-
return this.isRoot ? 0 : this._top;
|
|
874
|
-
}
|
|
875
|
-
},
|
|
876
|
-
left: {
|
|
877
|
-
get() {
|
|
878
|
-
return this.isRoot ? 0 : this._left;
|
|
879
|
-
}
|
|
880
|
-
},
|
|
881
|
-
bottom: {
|
|
882
|
-
get() {
|
|
883
|
-
return this.isRoot ? this.viewport.height : this._bottom;
|
|
884
|
-
}
|
|
885
|
-
},
|
|
886
|
-
right: {
|
|
887
|
-
get() {
|
|
888
|
-
return this.isRoot ? this.viewport.width : this._right;
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
});
|
|
892
|
-
extend('Simulator', {
|
|
893
|
-
getDashboardStyle: {
|
|
894
|
-
get() {
|
|
895
|
-
return this.get('dashboardStyle') || {};
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
});
|
|
899
|
-
}
|
|
900
|
-
};
|
|
901
|
-
};
|
|
902
|
-
const calculateDashboardRectBox = nodes => {
|
|
903
|
-
let [minX, minY, maxX, maxY] = [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY];
|
|
904
|
-
for (const node of nodes) {
|
|
905
|
-
const rect = node.getDashboardRect();
|
|
906
|
-
minX = Math.min(minX, rect.x);
|
|
907
|
-
minY = Math.min(minY, rect.y);
|
|
908
|
-
maxX = Math.max(maxX, rect.x + rect.width);
|
|
909
|
-
maxY = Math.max(maxY, rect.y + rect.height);
|
|
910
|
-
}
|
|
911
|
-
return new DOMRect(minX, minY, maxX - minX, maxY - minY);
|
|
912
|
-
};
|
|
913
|
-
|
|
914
|
-
export { DashboardPlugin as default };
|
|
915
|
-
//# sourceMappingURL=index.js.map
|