@knotx/plugins-group 0.0.0
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/LICENSE +21 -0
- package/dist/index.cjs +501 -0
- package/dist/index.d.cts +117 -0
- package/dist/index.d.mts +117 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.mjs +499 -0
- package/package.json +50 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
import { jsx } from '@knotx/jsx/jsx-runtime';
|
|
2
|
+
import { isDraftOperation, isInitOperation, bem, BasePlugin } from '@knotx/core';
|
|
3
|
+
import { DualRelation } from '@knotx/data';
|
|
4
|
+
import { inject, nodeType, register, OnInit, OnDestroy } from '@knotx/decorators';
|
|
5
|
+
import { skip, pipe, tap, map } from 'rxjs';
|
|
6
|
+
import '@knotx/plugins-base-render';
|
|
7
|
+
|
|
8
|
+
var __create = Object.create;
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __defProps = Object.defineProperties;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
13
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
14
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
16
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
17
|
+
var __typeError = (msg) => {
|
|
18
|
+
throw TypeError(msg);
|
|
19
|
+
};
|
|
20
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
21
|
+
var __spreadValues = (a, b) => {
|
|
22
|
+
for (var prop in b || (b = {}))
|
|
23
|
+
if (__hasOwnProp.call(b, prop))
|
|
24
|
+
__defNormalProp(a, prop, b[prop]);
|
|
25
|
+
if (__getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
27
|
+
if (__propIsEnum.call(b, prop))
|
|
28
|
+
__defNormalProp(a, prop, b[prop]);
|
|
29
|
+
}
|
|
30
|
+
return a;
|
|
31
|
+
};
|
|
32
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
33
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
34
|
+
var __decoratorStart = (base) => {
|
|
35
|
+
var _a2;
|
|
36
|
+
return [, , , __create((_a2 = base == null ? void 0 : base[__knownSymbol("metadata")]) != null ? _a2 : null)];
|
|
37
|
+
};
|
|
38
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
39
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
40
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
41
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
42
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
43
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
44
|
+
return value;
|
|
45
|
+
};
|
|
46
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
47
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
48
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
49
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
50
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
51
|
+
return __privateGet(this, extra);
|
|
52
|
+
}, set [name](x) {
|
|
53
|
+
return __privateSet(this, extra, x);
|
|
54
|
+
} }, name));
|
|
55
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
56
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
57
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
58
|
+
if (k) {
|
|
59
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
60
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
61
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
62
|
+
}
|
|
63
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
64
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
65
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
66
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
67
|
+
}
|
|
68
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
69
|
+
};
|
|
70
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
71
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
72
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
73
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
74
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
75
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
76
|
+
var _moveGroup_dec, _removeNodesFromGroup_dec, _addNodesToGroup_dec, _deleteGroup_dec, _dissolveGroup_dec, _createGroup_dec, _renderGroup_dec, _destroy_dec, _init_dec, _registerNodeLevelGetter_dec, _addNodePipe_dec, _dispatchNodeOperation_dec, _getNodeDraft_dec, _getNode_dec, _a, _init;
|
|
77
|
+
const _Group = class _Group extends (_a = BasePlugin, _getNode_dec = [inject.getNode()], _getNodeDraft_dec = [inject.getNodeDraft()], _dispatchNodeOperation_dec = [inject.dispatchNodeOperation()], _addNodePipe_dec = [inject.addNodePipe()], _registerNodeLevelGetter_dec = [inject.baseRender.registerNodeLevelGetter()], _init_dec = [OnInit], _destroy_dec = [OnDestroy], _renderGroup_dec = [nodeType("group")], _createGroup_dec = [register("createGroup")], _dissolveGroup_dec = [register("dissolveGroup")], _deleteGroup_dec = [register("deleteGroup")], _addNodesToGroup_dec = [register("addNodesToGroup")], _removeNodesFromGroup_dec = [register("removeNodesFromGroup")], _moveGroup_dec = [register("moveGroup")], _a) {
|
|
78
|
+
constructor() {
|
|
79
|
+
super(...arguments);
|
|
80
|
+
__runInitializers(_init, 5, this);
|
|
81
|
+
__publicField(this, "name", "group");
|
|
82
|
+
__publicField(this, "getNode", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
|
|
83
|
+
__publicField(this, "getNodeDraft", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
|
|
84
|
+
__publicField(this, "dispatchNodeOperation", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
|
|
85
|
+
__publicField(this, "addNodePipe", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
|
|
86
|
+
__publicField(this, "registerNodeLevelGetter", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
|
|
87
|
+
__publicField(this, "dualRelation", new DualRelation());
|
|
88
|
+
__publicField(this, "subscriptions", []);
|
|
89
|
+
__publicField(this, "createGroup", __runInitializers(_init, 28, this, ({ id: groupId, nodeIds, config, data = {} }) => {
|
|
90
|
+
const { autoBounds = true, padding = _Group.DEFAULT_GROUP_PADDING, style = _Group.DEFAULT_GROUP_STYLE } = config || {};
|
|
91
|
+
const groupNode = {
|
|
92
|
+
id: groupId,
|
|
93
|
+
type: "group",
|
|
94
|
+
position: {
|
|
95
|
+
x: 0,
|
|
96
|
+
y: 0
|
|
97
|
+
},
|
|
98
|
+
data,
|
|
99
|
+
groupConfig: {
|
|
100
|
+
autoBounds,
|
|
101
|
+
padding,
|
|
102
|
+
style
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const bounds = this.calculateBounds(groupNode, {
|
|
106
|
+
getChildren: () => nodeIds
|
|
107
|
+
});
|
|
108
|
+
groupNode.position = {
|
|
109
|
+
x: (bounds == null ? void 0 : bounds.x) || 0,
|
|
110
|
+
y: (bounds == null ? void 0 : bounds.y) || 0
|
|
111
|
+
};
|
|
112
|
+
groupNode.measured = {
|
|
113
|
+
width: (bounds == null ? void 0 : bounds.width) || 0,
|
|
114
|
+
height: (bounds == null ? void 0 : bounds.height) || 0
|
|
115
|
+
};
|
|
116
|
+
this.dispatchNodeOperation({
|
|
117
|
+
type: "batch",
|
|
118
|
+
operations: [
|
|
119
|
+
{
|
|
120
|
+
type: "add",
|
|
121
|
+
data: groupNode
|
|
122
|
+
},
|
|
123
|
+
...nodeIds.map((id) => ({
|
|
124
|
+
type: "update",
|
|
125
|
+
id,
|
|
126
|
+
data: {
|
|
127
|
+
group: groupId
|
|
128
|
+
}
|
|
129
|
+
}))
|
|
130
|
+
]
|
|
131
|
+
});
|
|
132
|
+
return groupId;
|
|
133
|
+
})), __runInitializers(_init, 31, this);
|
|
134
|
+
__publicField(this, "dissolveGroup", __runInitializers(_init, 32, this, (groupId) => {
|
|
135
|
+
this.dispatchNodeOperation({
|
|
136
|
+
type: "batch",
|
|
137
|
+
operations: [
|
|
138
|
+
{
|
|
139
|
+
type: "remove",
|
|
140
|
+
id: groupId
|
|
141
|
+
},
|
|
142
|
+
...Array.from(this.dualRelation.getChildren(groupId)).map((id) => ({
|
|
143
|
+
type: "update",
|
|
144
|
+
id,
|
|
145
|
+
data: {
|
|
146
|
+
group: void 0
|
|
147
|
+
}
|
|
148
|
+
}))
|
|
149
|
+
]
|
|
150
|
+
});
|
|
151
|
+
return true;
|
|
152
|
+
})), __runInitializers(_init, 35, this);
|
|
153
|
+
__publicField(this, "deleteGroup", __runInitializers(_init, 36, this, (groupId, recursive = false) => {
|
|
154
|
+
const children = Array.from(recursive ? this.dualRelation.getDescendants(groupId) : this.dualRelation.getChildren(groupId));
|
|
155
|
+
if (children.length === 0) {
|
|
156
|
+
this.dispatchNodeOperation({
|
|
157
|
+
type: "remove",
|
|
158
|
+
id: groupId
|
|
159
|
+
});
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
this.dispatchNodeOperation({
|
|
163
|
+
type: "batch",
|
|
164
|
+
operations: [
|
|
165
|
+
{
|
|
166
|
+
type: "remove",
|
|
167
|
+
id: groupId
|
|
168
|
+
},
|
|
169
|
+
...children.map((id) => ({
|
|
170
|
+
type: "remove",
|
|
171
|
+
id
|
|
172
|
+
}))
|
|
173
|
+
]
|
|
174
|
+
});
|
|
175
|
+
return true;
|
|
176
|
+
})), __runInitializers(_init, 39, this);
|
|
177
|
+
__publicField(this, "addNodesToGroup", __runInitializers(_init, 40, this, (groupId, nodeIds) => {
|
|
178
|
+
const groupNode = this.getNode(groupId);
|
|
179
|
+
if (!groupNode || groupNode.type !== "group") {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
const validNodeIds = nodeIds.filter((id) => {
|
|
183
|
+
const node = this.getNode(id);
|
|
184
|
+
return node && node.group !== groupId;
|
|
185
|
+
});
|
|
186
|
+
if (validNodeIds.length === 0) {
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
this.dispatchNodeOperation({
|
|
190
|
+
type: "batch",
|
|
191
|
+
operations: validNodeIds.map((id) => ({
|
|
192
|
+
type: "update",
|
|
193
|
+
id,
|
|
194
|
+
data: {
|
|
195
|
+
group: groupId
|
|
196
|
+
}
|
|
197
|
+
}))
|
|
198
|
+
});
|
|
199
|
+
return true;
|
|
200
|
+
})), __runInitializers(_init, 43, this);
|
|
201
|
+
__publicField(this, "removeNodesFromGroup", __runInitializers(_init, 44, this, (groupId, nodeIds) => {
|
|
202
|
+
const groupNode = this.getNode(groupId);
|
|
203
|
+
if (!groupNode || groupNode.type !== "group") {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
const validNodeIds = nodeIds.filter((id) => {
|
|
207
|
+
const node = this.getNode(id);
|
|
208
|
+
return node && node.group === groupId;
|
|
209
|
+
});
|
|
210
|
+
if (validNodeIds.length === 0) {
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
this.dispatchNodeOperation({
|
|
214
|
+
type: "batch",
|
|
215
|
+
operations: validNodeIds.map((id) => ({
|
|
216
|
+
type: "update",
|
|
217
|
+
id,
|
|
218
|
+
data: {
|
|
219
|
+
group: void 0
|
|
220
|
+
}
|
|
221
|
+
}))
|
|
222
|
+
});
|
|
223
|
+
return true;
|
|
224
|
+
})), __runInitializers(_init, 47, this);
|
|
225
|
+
__publicField(this, "moveGroup", __runInitializers(_init, 48, this, (groupId, position, isDelta = false) => {
|
|
226
|
+
const operation = this.buildMoveGroupOperation(groupId, position, isDelta);
|
|
227
|
+
if (operation.type === "batch" && operation.operations.length === 0) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
this.dispatchNodeOperation(operation);
|
|
231
|
+
return true;
|
|
232
|
+
})), __runInitializers(_init, 51, this);
|
|
233
|
+
}
|
|
234
|
+
init() {
|
|
235
|
+
this.subscriptions.push(
|
|
236
|
+
this.dualRelation.version.pipe(skip(1)).subscribe((version) => {
|
|
237
|
+
console.warn("dualRelation version changed", version, this.dualRelation.changeHistory);
|
|
238
|
+
})
|
|
239
|
+
);
|
|
240
|
+
this.subscriptions.push({
|
|
241
|
+
unsubscribe: this.registerNodeLevelGetter((node) => {
|
|
242
|
+
return this.dualRelation.getNodeLevel(node.id);
|
|
243
|
+
})
|
|
244
|
+
});
|
|
245
|
+
this.addNodePipe({
|
|
246
|
+
transform: () => pipe(
|
|
247
|
+
// 组关系维护检测
|
|
248
|
+
tap((operation) => {
|
|
249
|
+
if (isDraftOperation(operation)) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const checkRelation = (operation2) => {
|
|
253
|
+
switch (operation2.type) {
|
|
254
|
+
case "batch":
|
|
255
|
+
for (const op of operation2.operations) {
|
|
256
|
+
checkRelation(op);
|
|
257
|
+
}
|
|
258
|
+
break;
|
|
259
|
+
case "add":
|
|
260
|
+
if (operation2.data.group) {
|
|
261
|
+
this.dualRelation.add(operation2.data.group, operation2.data.id);
|
|
262
|
+
}
|
|
263
|
+
break;
|
|
264
|
+
case "update": {
|
|
265
|
+
const currentNode = this.getNode(operation2.id);
|
|
266
|
+
if (!("group" in operation2.data) || operation2.data.group === (currentNode == null ? void 0 : currentNode.group)) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (currentNode == null ? void 0 : currentNode.group) {
|
|
270
|
+
this.dualRelation.removeChild(currentNode.id);
|
|
271
|
+
}
|
|
272
|
+
if (operation2.data.group) {
|
|
273
|
+
this.dualRelation.add(operation2.data.group, operation2.id);
|
|
274
|
+
}
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
case "remove":
|
|
278
|
+
this.dualRelation.removeParent(operation2.id);
|
|
279
|
+
this.dualRelation.removeChild(operation2.id);
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
this.dualRelation.batch(() => {
|
|
284
|
+
checkRelation(operation);
|
|
285
|
+
});
|
|
286
|
+
}),
|
|
287
|
+
map((operation) => {
|
|
288
|
+
if (isInitOperation(operation)) {
|
|
289
|
+
const groupNodesMap = /* @__PURE__ */ new Map();
|
|
290
|
+
operation.operations.forEach((op) => {
|
|
291
|
+
if (op.type !== "add" || !op.data.group) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
groupNodesMap.set(op.data.id, op.data);
|
|
295
|
+
});
|
|
296
|
+
return __spreadProps(__spreadValues({}, operation), { operations: operation.operations.map((op) => {
|
|
297
|
+
if (op.type !== "add" || op.data.type !== "group") {
|
|
298
|
+
return op;
|
|
299
|
+
}
|
|
300
|
+
const bounds = this.calculateBounds(op.data, {
|
|
301
|
+
getNode: (id) => groupNodesMap.get(id)
|
|
302
|
+
});
|
|
303
|
+
return __spreadProps(__spreadValues({}, op), {
|
|
304
|
+
data: __spreadProps(__spreadValues({}, op.data), {
|
|
305
|
+
position: {
|
|
306
|
+
x: (bounds == null ? void 0 : bounds.x) || 0,
|
|
307
|
+
y: (bounds == null ? void 0 : bounds.y) || 0
|
|
308
|
+
},
|
|
309
|
+
measured: {
|
|
310
|
+
width: (bounds == null ? void 0 : bounds.width) || 0,
|
|
311
|
+
height: (bounds == null ? void 0 : bounds.height) || 0
|
|
312
|
+
}
|
|
313
|
+
})
|
|
314
|
+
});
|
|
315
|
+
}) });
|
|
316
|
+
}
|
|
317
|
+
const isDraft = isDraftOperation(operation);
|
|
318
|
+
if (isDraft && operation.type === "draftOperation") {
|
|
319
|
+
switch (operation.operation.type) {
|
|
320
|
+
case "update": {
|
|
321
|
+
if (!operation.operation.data.position) {
|
|
322
|
+
return operation;
|
|
323
|
+
}
|
|
324
|
+
const groupMoveOperation = this.buildMoveGroupOperation(operation.operation.id, operation.operation.data.position);
|
|
325
|
+
if (!groupMoveOperation.operations.length) {
|
|
326
|
+
return operation;
|
|
327
|
+
}
|
|
328
|
+
return {
|
|
329
|
+
type: "draftOperation",
|
|
330
|
+
draftId: operation.draftId,
|
|
331
|
+
operation: groupMoveOperation
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return operation;
|
|
337
|
+
})
|
|
338
|
+
)
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
destroy() {
|
|
342
|
+
this.subscriptions.forEach((subscription) => subscription.unsubscribe());
|
|
343
|
+
}
|
|
344
|
+
renderGroup({ node: groupNode }) {
|
|
345
|
+
const getNode = (id) => this.getNodeDraft(id) || this.getNode(id);
|
|
346
|
+
const bounds = this.calculateBounds(groupNode, { getNode });
|
|
347
|
+
if (!bounds)
|
|
348
|
+
return null;
|
|
349
|
+
return /* @__PURE__ */ jsx(
|
|
350
|
+
"div",
|
|
351
|
+
{
|
|
352
|
+
className: _Group.GROUP_WRAPPER_CLASSNAME,
|
|
353
|
+
style: __spreadProps(__spreadValues({
|
|
354
|
+
width: `${bounds.width}px`,
|
|
355
|
+
height: `${bounds.height}px`
|
|
356
|
+
}, groupNode.groupConfig ? groupNode.groupConfig.style : _Group.DEFAULT_GROUP_STYLE), {
|
|
357
|
+
pointerEvents: "all"
|
|
358
|
+
})
|
|
359
|
+
},
|
|
360
|
+
groupNode.id
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
calculateBounds(node, {
|
|
364
|
+
getChildren = (nodeId) => Array.from(this.dualRelation.getChildren(nodeId)),
|
|
365
|
+
getNode = this.getNode
|
|
366
|
+
} = {}) {
|
|
367
|
+
var _a2, _b, _c;
|
|
368
|
+
const { padding = 0, autoBounds } = (_a2 = node.groupConfig) != null ? _a2 : {
|
|
369
|
+
padding: _Group.DEFAULT_GROUP_PADDING,
|
|
370
|
+
autoBounds: true
|
|
371
|
+
};
|
|
372
|
+
if (!autoBounds && node.position && node.measured) {
|
|
373
|
+
return {
|
|
374
|
+
x: node.position.x - padding,
|
|
375
|
+
y: node.position.y - padding,
|
|
376
|
+
width: node.measured.width + padding * 2,
|
|
377
|
+
height: node.measured.height + padding * 2
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
const nodeIds = getChildren(node.id);
|
|
381
|
+
if (!nodeIds.length)
|
|
382
|
+
return null;
|
|
383
|
+
let minX = Infinity;
|
|
384
|
+
let minY = Infinity;
|
|
385
|
+
let maxX = -Infinity;
|
|
386
|
+
let maxY = -Infinity;
|
|
387
|
+
let hasValidNode = false;
|
|
388
|
+
for (const nodeId of nodeIds) {
|
|
389
|
+
const node2 = getNode(nodeId);
|
|
390
|
+
if (!node2)
|
|
391
|
+
continue;
|
|
392
|
+
hasValidNode = true;
|
|
393
|
+
const { x, y } = node2.position;
|
|
394
|
+
const width = ((_b = node2.measured) == null ? void 0 : _b.width) || 0;
|
|
395
|
+
const height = ((_c = node2.measured) == null ? void 0 : _c.height) || 0;
|
|
396
|
+
minX = Math.min(minX, x);
|
|
397
|
+
minY = Math.min(minY, y);
|
|
398
|
+
maxX = Math.max(maxX, x + width);
|
|
399
|
+
maxY = Math.max(maxY, y + height);
|
|
400
|
+
}
|
|
401
|
+
if (!hasValidNode)
|
|
402
|
+
return null;
|
|
403
|
+
return {
|
|
404
|
+
x: minX - padding,
|
|
405
|
+
y: minY - padding,
|
|
406
|
+
width: maxX - minX + padding * 2,
|
|
407
|
+
height: maxY - minY + padding * 2
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
buildMoveGroupOperation(groupId, position, isDelta = false) {
|
|
411
|
+
const groupNode = this.getNode(groupId);
|
|
412
|
+
if (!groupNode || groupNode.type !== "group") {
|
|
413
|
+
return {
|
|
414
|
+
type: "batch",
|
|
415
|
+
operations: []
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
const children = Array.from(this.dualRelation.getDescendants(groupId));
|
|
419
|
+
if (children.length === 0) {
|
|
420
|
+
return {
|
|
421
|
+
type: "batch",
|
|
422
|
+
operations: []
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
const currentPosition = groupNode.position;
|
|
426
|
+
let dx = 0;
|
|
427
|
+
let dy = 0;
|
|
428
|
+
if (isDelta) {
|
|
429
|
+
dx = position.x;
|
|
430
|
+
dy = position.y;
|
|
431
|
+
} else {
|
|
432
|
+
dx = position.x - currentPosition.x;
|
|
433
|
+
dy = position.y - currentPosition.y;
|
|
434
|
+
}
|
|
435
|
+
if (dx === 0 && dy === 0) {
|
|
436
|
+
return {
|
|
437
|
+
type: "batch",
|
|
438
|
+
operations: []
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
return {
|
|
442
|
+
type: "batch",
|
|
443
|
+
operations: [
|
|
444
|
+
{
|
|
445
|
+
type: "update",
|
|
446
|
+
id: groupId,
|
|
447
|
+
data: {
|
|
448
|
+
position: {
|
|
449
|
+
x: isDelta ? currentPosition.x + position.x : position.x,
|
|
450
|
+
y: isDelta ? currentPosition.y + position.y : position.y
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
...children.map((id) => {
|
|
455
|
+
var _a2;
|
|
456
|
+
const nodePosition = ((_a2 = this.getNode(id)) == null ? void 0 : _a2.position) || { x: 0, y: 0 };
|
|
457
|
+
return {
|
|
458
|
+
type: "update",
|
|
459
|
+
id,
|
|
460
|
+
data: {
|
|
461
|
+
position: {
|
|
462
|
+
x: nodePosition.x + dx,
|
|
463
|
+
y: nodePosition.y + dy
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
})
|
|
468
|
+
]
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
_init = __decoratorStart(_a);
|
|
473
|
+
__decorateElement(_init, 1, "init", _init_dec, _Group);
|
|
474
|
+
__decorateElement(_init, 1, "destroy", _destroy_dec, _Group);
|
|
475
|
+
__decorateElement(_init, 1, "renderGroup", _renderGroup_dec, _Group);
|
|
476
|
+
__decorateElement(_init, 5, "getNode", _getNode_dec, _Group);
|
|
477
|
+
__decorateElement(_init, 5, "getNodeDraft", _getNodeDraft_dec, _Group);
|
|
478
|
+
__decorateElement(_init, 5, "dispatchNodeOperation", _dispatchNodeOperation_dec, _Group);
|
|
479
|
+
__decorateElement(_init, 5, "addNodePipe", _addNodePipe_dec, _Group);
|
|
480
|
+
__decorateElement(_init, 5, "registerNodeLevelGetter", _registerNodeLevelGetter_dec, _Group);
|
|
481
|
+
__decorateElement(_init, 5, "createGroup", _createGroup_dec, _Group);
|
|
482
|
+
__decorateElement(_init, 5, "dissolveGroup", _dissolveGroup_dec, _Group);
|
|
483
|
+
__decorateElement(_init, 5, "deleteGroup", _deleteGroup_dec, _Group);
|
|
484
|
+
__decorateElement(_init, 5, "addNodesToGroup", _addNodesToGroup_dec, _Group);
|
|
485
|
+
__decorateElement(_init, 5, "removeNodesFromGroup", _removeNodesFromGroup_dec, _Group);
|
|
486
|
+
__decorateElement(_init, 5, "moveGroup", _moveGroup_dec, _Group);
|
|
487
|
+
__decoratorMetadata(_init, _Group);
|
|
488
|
+
__publicField(_Group, "GROUP_WRAPPER_CLASSNAME", bem("group", "wrapper"));
|
|
489
|
+
__publicField(_Group, "DEFAULT_GROUP_PADDING", 10);
|
|
490
|
+
__publicField(_Group, "DEFAULT_GROUP_STYLE", {
|
|
491
|
+
backgroundColor: "rgba(0, 100, 255, 0.05)",
|
|
492
|
+
borderColor: "rgba(0, 100, 255, 0.3)",
|
|
493
|
+
borderWidth: 1,
|
|
494
|
+
borderStyle: "solid",
|
|
495
|
+
borderRadius: 4
|
|
496
|
+
});
|
|
497
|
+
let Group = _Group;
|
|
498
|
+
|
|
499
|
+
export { Group };
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@knotx/plugins-group",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"description": "Group Plugin for Knotx",
|
|
6
|
+
"author": "boenfu",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/boenfu/knotx#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/boenfu/knotx.git",
|
|
12
|
+
"directory": "packages/plugins-group"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.mjs",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"rxjs": "^7.8.1",
|
|
33
|
+
"@knotx/core": "0.0.0",
|
|
34
|
+
"@knotx/decorators": "0.0.0",
|
|
35
|
+
"@knotx/data": "0.0.0",
|
|
36
|
+
"@knotx/plugins-base-render": "0.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@knotx/build-config": "0.0.0",
|
|
40
|
+
"@knotx/eslint-config": "0.0.0",
|
|
41
|
+
"@knotx/typescript-config": "0.0.0",
|
|
42
|
+
"@knotx/jsx": "0.0.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "unbuild --failOnWarn=false",
|
|
46
|
+
"dev": "unbuild --stub",
|
|
47
|
+
"lint": "eslint .",
|
|
48
|
+
"typecheck": "tsc --noEmit"
|
|
49
|
+
}
|
|
50
|
+
}
|