@knotx/plugins-bounding 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 +497 -0
- package/dist/index.d.cts +103 -0
- package/dist/index.d.mts +103 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.mjs +491 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 格桑
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsxRuntime = require('@knotx/jsx/jsx-runtime');
|
|
4
|
+
const core = require('@knotx/core');
|
|
5
|
+
const decorators = require('@knotx/decorators');
|
|
6
|
+
const interact = require('interactjs');
|
|
7
|
+
const rxjs = require('rxjs');
|
|
8
|
+
const operators = require('rxjs/operators');
|
|
9
|
+
require('@knotx/plugins-canvas');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
12
|
+
|
|
13
|
+
const interact__default = /*#__PURE__*/_interopDefaultCompat(interact);
|
|
14
|
+
|
|
15
|
+
var __create = Object.create;
|
|
16
|
+
var __defProp = Object.defineProperty;
|
|
17
|
+
var __defProps = Object.defineProperties;
|
|
18
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
19
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
20
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
21
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
22
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
23
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
24
|
+
var __typeError = (msg) => {
|
|
25
|
+
throw TypeError(msg);
|
|
26
|
+
};
|
|
27
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
28
|
+
var __spreadValues = (a, b) => {
|
|
29
|
+
for (var prop in b || (b = {}))
|
|
30
|
+
if (__hasOwnProp.call(b, prop))
|
|
31
|
+
__defNormalProp(a, prop, b[prop]);
|
|
32
|
+
if (__getOwnPropSymbols)
|
|
33
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
34
|
+
if (__propIsEnum.call(b, prop))
|
|
35
|
+
__defNormalProp(a, prop, b[prop]);
|
|
36
|
+
}
|
|
37
|
+
return a;
|
|
38
|
+
};
|
|
39
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
40
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
41
|
+
var __decoratorStart = (base) => {
|
|
42
|
+
var _a2;
|
|
43
|
+
return [, , , __create((_a2 = base == null ? void 0 : base[__knownSymbol("metadata")]) != null ? _a2 : null)];
|
|
44
|
+
};
|
|
45
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
46
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
47
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
48
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
49
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
50
|
+
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);
|
|
51
|
+
return value;
|
|
52
|
+
};
|
|
53
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
54
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
55
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
56
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
57
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
58
|
+
return __privateGet(this, extra);
|
|
59
|
+
}, set [name](x) {
|
|
60
|
+
return __privateSet(this, extra, x);
|
|
61
|
+
} }, name));
|
|
62
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
63
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
64
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
65
|
+
if (k) {
|
|
66
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
67
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
68
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
69
|
+
}
|
|
70
|
+
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;
|
|
71
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
72
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
73
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
74
|
+
}
|
|
75
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
76
|
+
};
|
|
77
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
78
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
79
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
80
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
81
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
82
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
83
|
+
var _render_dec, _destroy_dec, _init_dec, _getResizeHandleAttributes_dec, _canvasScale_dec, _canInteract_dec, _endInteraction_dec, _startInteraction_dec, _dispatchNodeOperation_dec, _getNode_dec, _nodes_dec, _a, _init;
|
|
84
|
+
const DEFAULT_CONNECT_HANDLE_POSITIONS = [
|
|
85
|
+
{ top: true },
|
|
86
|
+
{ right: true },
|
|
87
|
+
{ bottom: true },
|
|
88
|
+
{ left: true }
|
|
89
|
+
];
|
|
90
|
+
const DEFAULT_OPTIONS = {
|
|
91
|
+
features: {
|
|
92
|
+
resize: true,
|
|
93
|
+
connect: true,
|
|
94
|
+
boundingBox: true
|
|
95
|
+
},
|
|
96
|
+
sizes: {
|
|
97
|
+
resizeHandle: 6,
|
|
98
|
+
connectHandle: 5,
|
|
99
|
+
boundingBoxThreshold: 8
|
|
100
|
+
},
|
|
101
|
+
styles: {
|
|
102
|
+
resizeHandle: {
|
|
103
|
+
fill: "#fff",
|
|
104
|
+
stroke: "var(--knotx-plugin__bounding-resize-handle-color, #6366f1)",
|
|
105
|
+
strokeWidth: 1
|
|
106
|
+
},
|
|
107
|
+
connectHandle: {
|
|
108
|
+
fill: "var(--knotx-primary-color, #6366f1)",
|
|
109
|
+
stroke: "#fff",
|
|
110
|
+
strokeWidth: 1
|
|
111
|
+
},
|
|
112
|
+
boundingBox: {
|
|
113
|
+
stroke: "var(--knotx-plugin__bounding-resize-handle-color, #6366f1)",
|
|
114
|
+
strokeWidth: 1
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
resize: {
|
|
118
|
+
minWidth: 30,
|
|
119
|
+
minHeight: 30,
|
|
120
|
+
inertia: true,
|
|
121
|
+
handles: [
|
|
122
|
+
"left-top",
|
|
123
|
+
"right-top",
|
|
124
|
+
"right-bottom",
|
|
125
|
+
"left-bottom"
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
class Bounding extends (_a = core.BasePlugin, _nodes_dec = [decorators.inject.nodes()], _getNode_dec = [decorators.inject.getNode()], _dispatchNodeOperation_dec = [decorators.inject.dispatchNodeOperation()], _startInteraction_dec = [decorators.inject.startInteraction()], _endInteraction_dec = [decorators.inject.endInteraction()], _canInteract_dec = [decorators.inject.canInteract()], _canvasScale_dec = [decorators.inject.canvas.transform((state) => state.scale)], _getResizeHandleAttributes_dec = [decorators.register("getCustomResizeHandleAttributes")], _init_dec = [decorators.OnInit], _destroy_dec = [decorators.OnDestroy], _render_dec = [decorators.layer(core.Layer.Nodes, 1)], _a) {
|
|
130
|
+
constructor(options = {}) {
|
|
131
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
132
|
+
super();
|
|
133
|
+
this.options = options;
|
|
134
|
+
__runInitializers(_init, 5, this);
|
|
135
|
+
__publicField(this, "name", "bounding");
|
|
136
|
+
__publicField(this, "nodes", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
|
|
137
|
+
__publicField(this, "getNode", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
|
|
138
|
+
__publicField(this, "dispatchNodeOperation", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
|
|
139
|
+
__publicField(this, "startInteraction", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
|
|
140
|
+
__publicField(this, "endInteraction", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
|
|
141
|
+
__publicField(this, "canInteract", __runInitializers(_init, 28, this)), __runInitializers(_init, 31, this);
|
|
142
|
+
__publicField(this, "canvasScale", __runInitializers(_init, 32, this, 1)), __runInitializers(_init, 35, this);
|
|
143
|
+
__publicField(this, "subscription");
|
|
144
|
+
__publicField(this, "resizeHandleClassName", core.bem(this.name, "resize-handle"));
|
|
145
|
+
__publicField(this, "connectHandleClassName", core.bem(this.name, "connect-handle"));
|
|
146
|
+
__publicField(this, "boundingBoxClassName", core.bem(this.name, "bounding-box"));
|
|
147
|
+
__publicField(this, "getResizeHandleAttributes", __runInitializers(_init, 36, this, (nodeId, position) => {
|
|
148
|
+
return {
|
|
149
|
+
"className": this.resizeHandleClassName,
|
|
150
|
+
"data-plugin-id": this.pluginId,
|
|
151
|
+
"data-resize-target": nodeId,
|
|
152
|
+
"data-resize-handle-position": position
|
|
153
|
+
};
|
|
154
|
+
})), __runInitializers(_init, 39, this);
|
|
155
|
+
this.options = __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options), {
|
|
156
|
+
features: __spreadValues(__spreadValues({}, DEFAULT_OPTIONS.features), options.features),
|
|
157
|
+
sizes: __spreadValues(__spreadValues({}, DEFAULT_OPTIONS.sizes), options.sizes),
|
|
158
|
+
styles: {
|
|
159
|
+
resizeHandle: __spreadValues(__spreadValues({}, (_a2 = DEFAULT_OPTIONS.styles) == null ? void 0 : _a2.resizeHandle), (_b = options.styles) == null ? void 0 : _b.resizeHandle),
|
|
160
|
+
connectHandle: __spreadValues(__spreadValues({}, (_c = DEFAULT_OPTIONS.styles) == null ? void 0 : _c.connectHandle), (_d = options.styles) == null ? void 0 : _d.connectHandle),
|
|
161
|
+
boundingBox: __spreadValues(__spreadValues({}, (_e = DEFAULT_OPTIONS.styles) == null ? void 0 : _e.boundingBox), (_f = options.styles) == null ? void 0 : _f.boundingBox)
|
|
162
|
+
},
|
|
163
|
+
resize: __spreadValues(__spreadValues({}, DEFAULT_OPTIONS.resize), options.resize)
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
init() {
|
|
167
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
168
|
+
const resizeStart$ = new rxjs.Subject();
|
|
169
|
+
const resizeMove$ = new rxjs.Subject();
|
|
170
|
+
const resizeEnd$ = new rxjs.Subject();
|
|
171
|
+
const startResize = (nodeId, position) => {
|
|
172
|
+
const node = this.getNode(nodeId);
|
|
173
|
+
if (!(node == null ? void 0 : node.measured))
|
|
174
|
+
return;
|
|
175
|
+
resizeStart$.next({
|
|
176
|
+
nodeId,
|
|
177
|
+
startWidth: node.measured.width,
|
|
178
|
+
startHeight: node.measured.height,
|
|
179
|
+
startX: node.position.x,
|
|
180
|
+
startY: node.position.y,
|
|
181
|
+
position
|
|
182
|
+
});
|
|
183
|
+
this.startInteraction(this.pluginId, "resize", core.InteractionPriority.EntityMeasureDrag);
|
|
184
|
+
};
|
|
185
|
+
const endResize = () => {
|
|
186
|
+
resizeEnd$.next();
|
|
187
|
+
this.endInteraction(this.pluginId, "resize");
|
|
188
|
+
};
|
|
189
|
+
const updateResize = (event) => {
|
|
190
|
+
if (!this.canInteract(this.pluginId, "resize")) {
|
|
191
|
+
endResize();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const scale = this.canvasScale;
|
|
195
|
+
resizeMove$.next({
|
|
196
|
+
dx: event.dx / scale,
|
|
197
|
+
dy: event.dy / scale
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
if ((_a2 = this.options.features) == null ? void 0 : _a2.resize) {
|
|
201
|
+
const currentInteractable = interact__default(`[data-plugin-id="${this.pluginId}"].${this.resizeHandleClassName}`).resizable({
|
|
202
|
+
edges: { left: true, right: true, bottom: true, top: true },
|
|
203
|
+
inertia: (_b = this.options.resize) == null ? void 0 : _b.inertia,
|
|
204
|
+
cursorChecker: (_action, _interactable, element) => {
|
|
205
|
+
var _a3;
|
|
206
|
+
const position = (_a3 = element.getAttribute("data-resize-handle-position")) != null ? _a3 : "";
|
|
207
|
+
return this.getCursorStyle(position);
|
|
208
|
+
},
|
|
209
|
+
listeners: {
|
|
210
|
+
start: (event) => {
|
|
211
|
+
const nodeId = event.target.getAttribute("data-resize-target");
|
|
212
|
+
const position = event.target.getAttribute("data-resize-handle-position");
|
|
213
|
+
if (!nodeId)
|
|
214
|
+
return;
|
|
215
|
+
startResize(nodeId, position);
|
|
216
|
+
},
|
|
217
|
+
move: updateResize,
|
|
218
|
+
end: endResize
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
this.subscription = resizeStart$.pipe(
|
|
222
|
+
operators.switchMap((startEvent) => {
|
|
223
|
+
const draftId = `${this.pluginId}-${startEvent.nodeId}`;
|
|
224
|
+
const { nodeId, startWidth, startHeight, startX, startY, position } = startEvent;
|
|
225
|
+
let currentWidth = startWidth;
|
|
226
|
+
let currentHeight = startHeight;
|
|
227
|
+
let currentX = startX;
|
|
228
|
+
let currentY = startY;
|
|
229
|
+
this.dispatchNodeOperation({
|
|
230
|
+
type: "startDraft",
|
|
231
|
+
draftId
|
|
232
|
+
});
|
|
233
|
+
return resizeMove$.pipe(
|
|
234
|
+
operators.map((moveEvent) => {
|
|
235
|
+
var _a3, _b2, _c2, _d2;
|
|
236
|
+
let nextWidth = currentWidth;
|
|
237
|
+
let nextHeight = currentHeight;
|
|
238
|
+
let nextX = currentX;
|
|
239
|
+
let nextY = currentY;
|
|
240
|
+
const minWidth = (_b2 = (_a3 = this.options.resize) == null ? void 0 : _a3.minWidth) != null ? _b2 : 30;
|
|
241
|
+
const minHeight = (_d2 = (_c2 = this.options.resize) == null ? void 0 : _c2.minHeight) != null ? _d2 : 30;
|
|
242
|
+
if (position.includes("right")) {
|
|
243
|
+
nextWidth = Math.max(minWidth, currentWidth + moveEvent.dx);
|
|
244
|
+
}
|
|
245
|
+
if (position.includes("left")) {
|
|
246
|
+
const deltaX = Math.min(moveEvent.dx, currentWidth - minWidth);
|
|
247
|
+
nextX = currentX + deltaX;
|
|
248
|
+
nextWidth = currentWidth - deltaX;
|
|
249
|
+
}
|
|
250
|
+
if (position.includes("bottom")) {
|
|
251
|
+
nextHeight = Math.max(minHeight, currentHeight + moveEvent.dy);
|
|
252
|
+
}
|
|
253
|
+
if (position.includes("top")) {
|
|
254
|
+
const deltaY = Math.min(moveEvent.dy, currentHeight - minHeight);
|
|
255
|
+
nextY = currentY + deltaY;
|
|
256
|
+
nextHeight = currentHeight - deltaY;
|
|
257
|
+
}
|
|
258
|
+
currentWidth = nextWidth;
|
|
259
|
+
currentHeight = nextHeight;
|
|
260
|
+
currentX = nextX;
|
|
261
|
+
currentY = nextY;
|
|
262
|
+
return {
|
|
263
|
+
nodeId,
|
|
264
|
+
width: currentWidth,
|
|
265
|
+
height: currentHeight,
|
|
266
|
+
x: currentX,
|
|
267
|
+
y: currentY
|
|
268
|
+
};
|
|
269
|
+
}),
|
|
270
|
+
operators.tap((resizeData) => {
|
|
271
|
+
const node = this.getNode(resizeData.nodeId);
|
|
272
|
+
if (node) {
|
|
273
|
+
this.dispatchNodeOperation({
|
|
274
|
+
type: "draftOperation",
|
|
275
|
+
draftId,
|
|
276
|
+
operation: {
|
|
277
|
+
type: "update",
|
|
278
|
+
id: resizeData.nodeId,
|
|
279
|
+
data: {
|
|
280
|
+
position: {
|
|
281
|
+
x: resizeData.x,
|
|
282
|
+
y: resizeData.y
|
|
283
|
+
},
|
|
284
|
+
measured: {
|
|
285
|
+
width: resizeData.width,
|
|
286
|
+
height: resizeData.height
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}),
|
|
293
|
+
operators.takeUntil(resizeEnd$.pipe(
|
|
294
|
+
operators.tap(() => {
|
|
295
|
+
this.dispatchNodeOperation({
|
|
296
|
+
type: "commitDraft",
|
|
297
|
+
draftId
|
|
298
|
+
});
|
|
299
|
+
})
|
|
300
|
+
))
|
|
301
|
+
);
|
|
302
|
+
})
|
|
303
|
+
).subscribe();
|
|
304
|
+
this.subscription.add(() => {
|
|
305
|
+
currentInteractable == null ? void 0 : currentInteractable.unset();
|
|
306
|
+
resizeStart$.complete();
|
|
307
|
+
resizeMove$.complete();
|
|
308
|
+
resizeEnd$.complete();
|
|
309
|
+
});
|
|
310
|
+
if ((_c = this.options.features) == null ? void 0 : _c.boundingBox) {
|
|
311
|
+
const boundingInteractable = interact__default(`[data-plugin-id="${this.pluginId}"].${this.boundingBoxClassName}`).resizable({
|
|
312
|
+
enabled: (_d = this.options.features) == null ? void 0 : _d.resize,
|
|
313
|
+
edges: { left: true, right: true, bottom: true, top: true },
|
|
314
|
+
inertia: (_e = this.options.resize) == null ? void 0 : _e.inertia,
|
|
315
|
+
cursorChecker: (action) => this.getCursorStyle(this.getPositionByEdges(action.edges)),
|
|
316
|
+
listeners: {
|
|
317
|
+
start: (event) => {
|
|
318
|
+
const nodeId = event.target.getAttribute("data-resize-target");
|
|
319
|
+
const position = this.getPositionByEdges(event.edges);
|
|
320
|
+
if (!nodeId)
|
|
321
|
+
return;
|
|
322
|
+
startResize(nodeId, position);
|
|
323
|
+
},
|
|
324
|
+
move: updateResize,
|
|
325
|
+
end: endResize
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
(_f = this.subscription) == null ? void 0 : _f.add(() => boundingInteractable.unset());
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
destroy() {
|
|
333
|
+
var _a2;
|
|
334
|
+
(_a2 = this.subscription) == null ? void 0 : _a2.unsubscribe();
|
|
335
|
+
}
|
|
336
|
+
render() {
|
|
337
|
+
var _a2;
|
|
338
|
+
const nodes = core.use(() => this.nodes);
|
|
339
|
+
const pluginId = this.pluginId;
|
|
340
|
+
const nodesType = (_a2 = this.options.resize) == null ? void 0 : _a2.nodesType;
|
|
341
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
342
|
+
"svg",
|
|
343
|
+
{
|
|
344
|
+
style: {
|
|
345
|
+
position: "absolute",
|
|
346
|
+
left: 0,
|
|
347
|
+
top: 0,
|
|
348
|
+
pointerEvents: "none",
|
|
349
|
+
overflow: "visible"
|
|
350
|
+
},
|
|
351
|
+
children: nodes.map((node) => {
|
|
352
|
+
var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
353
|
+
const { position: { x, y }, measured, type } = node;
|
|
354
|
+
if (!measured)
|
|
355
|
+
return null;
|
|
356
|
+
if (nodesType && !nodesType.includes(type))
|
|
357
|
+
return null;
|
|
358
|
+
const { width, height } = measured;
|
|
359
|
+
const resizeSize = (_c = (_a3 = this.options.sizes) == null ? void 0 : _a3.resizeHandle) != null ? _c : (_b = DEFAULT_OPTIONS.sizes) == null ? void 0 : _b.resizeHandle;
|
|
360
|
+
const resizeStyles = (_f = (_d = this.options.styles) == null ? void 0 : _d.resizeHandle) != null ? _f : (_e = DEFAULT_OPTIONS.styles) == null ? void 0 : _e.resizeHandle;
|
|
361
|
+
const connectSize = (_i = (_g = this.options.sizes) == null ? void 0 : _g.connectHandle) != null ? _i : (_h = DEFAULT_OPTIONS.sizes) == null ? void 0 : _h.connectHandle;
|
|
362
|
+
const connectStyles = (_l = (_j = this.options.styles) == null ? void 0 : _j.connectHandle) != null ? _l : (_k = DEFAULT_OPTIONS.styles) == null ? void 0 : _k.connectHandle;
|
|
363
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("g", { style: { pointerEvents: "auto" }, children: [
|
|
364
|
+
((_m = this.options.features) == null ? void 0 : _m.boundingBox) && /* @__PURE__ */ jsxRuntime.jsx(
|
|
365
|
+
"rect",
|
|
366
|
+
{
|
|
367
|
+
className: this.boundingBoxClassName,
|
|
368
|
+
"data-plugin-id": this.pluginId,
|
|
369
|
+
"data-resize-target": node.id,
|
|
370
|
+
x,
|
|
371
|
+
y,
|
|
372
|
+
width,
|
|
373
|
+
height,
|
|
374
|
+
fill: "none",
|
|
375
|
+
stroke: (_o = (_n = this.options.styles) == null ? void 0 : _n.boundingBox) == null ? void 0 : _o.stroke,
|
|
376
|
+
strokeWidth: (_q = (_p = this.options.styles) == null ? void 0 : _p.boundingBox) == null ? void 0 : _q.strokeWidth,
|
|
377
|
+
style: { pointerEvents: "auto" }
|
|
378
|
+
}
|
|
379
|
+
),
|
|
380
|
+
((_r = this.options.features) == null ? void 0 : _r.resize) && ((_t = (_s = this.options.resize) == null ? void 0 : _s.handles) == null ? void 0 : _t.map((position, index) => {
|
|
381
|
+
let handleX = x;
|
|
382
|
+
let handleY = y;
|
|
383
|
+
const [xPosition, yPosition] = position.split("-");
|
|
384
|
+
switch (xPosition) {
|
|
385
|
+
case "right":
|
|
386
|
+
handleX += width;
|
|
387
|
+
break;
|
|
388
|
+
case "left":
|
|
389
|
+
break;
|
|
390
|
+
default:
|
|
391
|
+
handleX += width / 2;
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
switch (yPosition != null ? yPosition : xPosition) {
|
|
395
|
+
case "bottom":
|
|
396
|
+
handleY += height;
|
|
397
|
+
break;
|
|
398
|
+
case "top":
|
|
399
|
+
break;
|
|
400
|
+
default:
|
|
401
|
+
handleY += height / 2;
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
return /* @__PURE__ */ jsxRuntime.jsx("g", { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
405
|
+
"rect",
|
|
406
|
+
__spreadProps(__spreadValues({}, this.getResizeHandleAttributes(node.id, position)), {
|
|
407
|
+
x: handleX - resizeSize / 2,
|
|
408
|
+
y: handleY - resizeSize / 2,
|
|
409
|
+
width: resizeSize,
|
|
410
|
+
height: resizeSize,
|
|
411
|
+
fill: resizeStyles == null ? void 0 : resizeStyles.fill,
|
|
412
|
+
stroke: resizeStyles == null ? void 0 : resizeStyles.stroke,
|
|
413
|
+
strokeWidth: resizeStyles == null ? void 0 : resizeStyles.strokeWidth
|
|
414
|
+
})
|
|
415
|
+
) }, `resize-${index}`);
|
|
416
|
+
})),
|
|
417
|
+
((_u = this.options.features) == null ? void 0 : _u.connect) && DEFAULT_CONNECT_HANDLE_POSITIONS.map((position, index) => {
|
|
418
|
+
let handleX = x + width / 2;
|
|
419
|
+
let handleY = y + height / 2;
|
|
420
|
+
if (position.right)
|
|
421
|
+
handleX = x + width;
|
|
422
|
+
if (position.left)
|
|
423
|
+
handleX = x;
|
|
424
|
+
if (position.bottom)
|
|
425
|
+
handleY = y + height;
|
|
426
|
+
if (position.top)
|
|
427
|
+
handleY = y;
|
|
428
|
+
return /* @__PURE__ */ jsxRuntime.jsx("g", { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
429
|
+
"circle",
|
|
430
|
+
{
|
|
431
|
+
className: this.connectHandleClassName,
|
|
432
|
+
"data-plugin-id": pluginId,
|
|
433
|
+
"data-handle-target": node.id,
|
|
434
|
+
cx: handleX,
|
|
435
|
+
cy: handleY,
|
|
436
|
+
r: connectSize,
|
|
437
|
+
fill: connectStyles == null ? void 0 : connectStyles.fill,
|
|
438
|
+
stroke: connectStyles == null ? void 0 : connectStyles.stroke,
|
|
439
|
+
strokeWidth: connectStyles == null ? void 0 : connectStyles.strokeWidth
|
|
440
|
+
}
|
|
441
|
+
) }, `connect-${index}`);
|
|
442
|
+
})
|
|
443
|
+
] }, node.id);
|
|
444
|
+
})
|
|
445
|
+
}
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
getCursorStyle(position) {
|
|
449
|
+
switch (position) {
|
|
450
|
+
case "left-top":
|
|
451
|
+
case "right-bottom":
|
|
452
|
+
return "nwse-resize";
|
|
453
|
+
case "right-top":
|
|
454
|
+
case "left-bottom":
|
|
455
|
+
return "nesw-resize";
|
|
456
|
+
case "left":
|
|
457
|
+
case "right":
|
|
458
|
+
return "ew-resize";
|
|
459
|
+
case "top":
|
|
460
|
+
case "bottom":
|
|
461
|
+
return "ns-resize";
|
|
462
|
+
default:
|
|
463
|
+
return "default";
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
getPositionByEdges(edges) {
|
|
467
|
+
const positions = [];
|
|
468
|
+
if (edges == null ? void 0 : edges.left) {
|
|
469
|
+
positions.push("left");
|
|
470
|
+
}
|
|
471
|
+
if (edges == null ? void 0 : edges.right) {
|
|
472
|
+
positions.push("right");
|
|
473
|
+
}
|
|
474
|
+
if (edges == null ? void 0 : edges.top) {
|
|
475
|
+
positions.push("top");
|
|
476
|
+
}
|
|
477
|
+
if (edges == null ? void 0 : edges.bottom) {
|
|
478
|
+
positions.push("bottom");
|
|
479
|
+
}
|
|
480
|
+
return positions.join("-");
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
_init = __decoratorStart(_a);
|
|
484
|
+
__decorateElement(_init, 1, "init", _init_dec, Bounding);
|
|
485
|
+
__decorateElement(_init, 1, "destroy", _destroy_dec, Bounding);
|
|
486
|
+
__decorateElement(_init, 1, "render", _render_dec, Bounding);
|
|
487
|
+
__decorateElement(_init, 5, "nodes", _nodes_dec, Bounding);
|
|
488
|
+
__decorateElement(_init, 5, "getNode", _getNode_dec, Bounding);
|
|
489
|
+
__decorateElement(_init, 5, "dispatchNodeOperation", _dispatchNodeOperation_dec, Bounding);
|
|
490
|
+
__decorateElement(_init, 5, "startInteraction", _startInteraction_dec, Bounding);
|
|
491
|
+
__decorateElement(_init, 5, "endInteraction", _endInteraction_dec, Bounding);
|
|
492
|
+
__decorateElement(_init, 5, "canInteract", _canInteract_dec, Bounding);
|
|
493
|
+
__decorateElement(_init, 5, "canvasScale", _canvasScale_dec, Bounding);
|
|
494
|
+
__decorateElement(_init, 5, "getResizeHandleAttributes", _getResizeHandleAttributes_dec, Bounding);
|
|
495
|
+
__decoratorMetadata(_init, Bounding);
|
|
496
|
+
|
|
497
|
+
exports.Bounding = Bounding;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { HorizontalAlignment, VerticalAlignment, BasePlugin, NodeData, NodeOperation, InteractionPriority } from '@knotx/core';
|
|
2
|
+
|
|
3
|
+
declare module '@knotx/core' {
|
|
4
|
+
interface PluginData {
|
|
5
|
+
bounding: {
|
|
6
|
+
/**
|
|
7
|
+
* 获取自定义的 resize handle 属性
|
|
8
|
+
* @param nodeId 节点 ID
|
|
9
|
+
* @param position 位置
|
|
10
|
+
* @returns 属性对象
|
|
11
|
+
*/
|
|
12
|
+
getCustomResizeHandleAttributes: (nodeId: string, position: ResizeHandlePosition) => Record<string, string>;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
interface ResizeEvent {
|
|
17
|
+
nodeId: string;
|
|
18
|
+
startWidth: number;
|
|
19
|
+
startHeight: number;
|
|
20
|
+
startX: number;
|
|
21
|
+
startY: number;
|
|
22
|
+
position: string;
|
|
23
|
+
}
|
|
24
|
+
interface ResizeData {
|
|
25
|
+
nodeId: string;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
}
|
|
29
|
+
interface ConnectHandlePosition {
|
|
30
|
+
top?: boolean;
|
|
31
|
+
right?: boolean;
|
|
32
|
+
bottom?: boolean;
|
|
33
|
+
left?: boolean;
|
|
34
|
+
}
|
|
35
|
+
type ResizeHandlePosition = `${HorizontalAlignment}-${VerticalAlignment}` | HorizontalAlignment | VerticalAlignment;
|
|
36
|
+
interface BoundingOptions {
|
|
37
|
+
features?: {
|
|
38
|
+
resize?: boolean;
|
|
39
|
+
connect?: boolean;
|
|
40
|
+
boundingBox?: boolean;
|
|
41
|
+
};
|
|
42
|
+
sizes?: {
|
|
43
|
+
resizeHandle?: number;
|
|
44
|
+
connectHandle?: number;
|
|
45
|
+
boundingBoxThreshold?: number;
|
|
46
|
+
};
|
|
47
|
+
styles?: {
|
|
48
|
+
resizeHandle?: {
|
|
49
|
+
fill?: string;
|
|
50
|
+
stroke?: string;
|
|
51
|
+
strokeWidth?: number;
|
|
52
|
+
};
|
|
53
|
+
connectHandle?: {
|
|
54
|
+
fill?: string;
|
|
55
|
+
stroke?: string;
|
|
56
|
+
strokeWidth?: number;
|
|
57
|
+
shadowColor?: string;
|
|
58
|
+
shadowWidth?: number;
|
|
59
|
+
};
|
|
60
|
+
boundingBox?: {
|
|
61
|
+
stroke?: string;
|
|
62
|
+
strokeWidth?: number;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
resize?: {
|
|
66
|
+
minWidth?: number;
|
|
67
|
+
minHeight?: number;
|
|
68
|
+
inertia?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* default: @var DEFAULT_RESIZE_HANDLES
|
|
71
|
+
*/
|
|
72
|
+
handles?: ResizeHandlePosition[];
|
|
73
|
+
/**
|
|
74
|
+
* 指定哪些节点类型可以被 resize
|
|
75
|
+
* 默认所有节点
|
|
76
|
+
*/
|
|
77
|
+
nodesType?: string[];
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
declare class Bounding extends BasePlugin<'bounding'> {
|
|
81
|
+
private options;
|
|
82
|
+
name: "bounding";
|
|
83
|
+
nodes: NodeData[];
|
|
84
|
+
getNode: (id: string) => NodeData | undefined;
|
|
85
|
+
dispatchNodeOperation: (operation: NodeOperation) => void;
|
|
86
|
+
startInteraction: (pluginId: string, type: string, priority: InteractionPriority) => void;
|
|
87
|
+
endInteraction: (pluginId: string, type: string) => void;
|
|
88
|
+
canInteract: (pluginId: string, type: string, autoStartPriority?: InteractionPriority) => boolean;
|
|
89
|
+
canvasScale: number;
|
|
90
|
+
private subscription?;
|
|
91
|
+
private resizeHandleClassName;
|
|
92
|
+
private connectHandleClassName;
|
|
93
|
+
private boundingBoxClassName;
|
|
94
|
+
private getResizeHandleAttributes;
|
|
95
|
+
constructor(options?: BoundingOptions);
|
|
96
|
+
init(): void;
|
|
97
|
+
destroy(): void;
|
|
98
|
+
render(): JSX.Element;
|
|
99
|
+
private getCursorStyle;
|
|
100
|
+
private getPositionByEdges;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { Bounding, type BoundingOptions, type ConnectHandlePosition, type ResizeData, type ResizeEvent, type ResizeHandlePosition };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { HorizontalAlignment, VerticalAlignment, BasePlugin, NodeData, NodeOperation, InteractionPriority } from '@knotx/core';
|
|
2
|
+
|
|
3
|
+
declare module '@knotx/core' {
|
|
4
|
+
interface PluginData {
|
|
5
|
+
bounding: {
|
|
6
|
+
/**
|
|
7
|
+
* 获取自定义的 resize handle 属性
|
|
8
|
+
* @param nodeId 节点 ID
|
|
9
|
+
* @param position 位置
|
|
10
|
+
* @returns 属性对象
|
|
11
|
+
*/
|
|
12
|
+
getCustomResizeHandleAttributes: (nodeId: string, position: ResizeHandlePosition) => Record<string, string>;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
interface ResizeEvent {
|
|
17
|
+
nodeId: string;
|
|
18
|
+
startWidth: number;
|
|
19
|
+
startHeight: number;
|
|
20
|
+
startX: number;
|
|
21
|
+
startY: number;
|
|
22
|
+
position: string;
|
|
23
|
+
}
|
|
24
|
+
interface ResizeData {
|
|
25
|
+
nodeId: string;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
}
|
|
29
|
+
interface ConnectHandlePosition {
|
|
30
|
+
top?: boolean;
|
|
31
|
+
right?: boolean;
|
|
32
|
+
bottom?: boolean;
|
|
33
|
+
left?: boolean;
|
|
34
|
+
}
|
|
35
|
+
type ResizeHandlePosition = `${HorizontalAlignment}-${VerticalAlignment}` | HorizontalAlignment | VerticalAlignment;
|
|
36
|
+
interface BoundingOptions {
|
|
37
|
+
features?: {
|
|
38
|
+
resize?: boolean;
|
|
39
|
+
connect?: boolean;
|
|
40
|
+
boundingBox?: boolean;
|
|
41
|
+
};
|
|
42
|
+
sizes?: {
|
|
43
|
+
resizeHandle?: number;
|
|
44
|
+
connectHandle?: number;
|
|
45
|
+
boundingBoxThreshold?: number;
|
|
46
|
+
};
|
|
47
|
+
styles?: {
|
|
48
|
+
resizeHandle?: {
|
|
49
|
+
fill?: string;
|
|
50
|
+
stroke?: string;
|
|
51
|
+
strokeWidth?: number;
|
|
52
|
+
};
|
|
53
|
+
connectHandle?: {
|
|
54
|
+
fill?: string;
|
|
55
|
+
stroke?: string;
|
|
56
|
+
strokeWidth?: number;
|
|
57
|
+
shadowColor?: string;
|
|
58
|
+
shadowWidth?: number;
|
|
59
|
+
};
|
|
60
|
+
boundingBox?: {
|
|
61
|
+
stroke?: string;
|
|
62
|
+
strokeWidth?: number;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
resize?: {
|
|
66
|
+
minWidth?: number;
|
|
67
|
+
minHeight?: number;
|
|
68
|
+
inertia?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* default: @var DEFAULT_RESIZE_HANDLES
|
|
71
|
+
*/
|
|
72
|
+
handles?: ResizeHandlePosition[];
|
|
73
|
+
/**
|
|
74
|
+
* 指定哪些节点类型可以被 resize
|
|
75
|
+
* 默认所有节点
|
|
76
|
+
*/
|
|
77
|
+
nodesType?: string[];
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
declare class Bounding extends BasePlugin<'bounding'> {
|
|
81
|
+
private options;
|
|
82
|
+
name: "bounding";
|
|
83
|
+
nodes: NodeData[];
|
|
84
|
+
getNode: (id: string) => NodeData | undefined;
|
|
85
|
+
dispatchNodeOperation: (operation: NodeOperation) => void;
|
|
86
|
+
startInteraction: (pluginId: string, type: string, priority: InteractionPriority) => void;
|
|
87
|
+
endInteraction: (pluginId: string, type: string) => void;
|
|
88
|
+
canInteract: (pluginId: string, type: string, autoStartPriority?: InteractionPriority) => boolean;
|
|
89
|
+
canvasScale: number;
|
|
90
|
+
private subscription?;
|
|
91
|
+
private resizeHandleClassName;
|
|
92
|
+
private connectHandleClassName;
|
|
93
|
+
private boundingBoxClassName;
|
|
94
|
+
private getResizeHandleAttributes;
|
|
95
|
+
constructor(options?: BoundingOptions);
|
|
96
|
+
init(): void;
|
|
97
|
+
destroy(): void;
|
|
98
|
+
render(): JSX.Element;
|
|
99
|
+
private getCursorStyle;
|
|
100
|
+
private getPositionByEdges;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { Bounding, type BoundingOptions, type ConnectHandlePosition, type ResizeData, type ResizeEvent, type ResizeHandlePosition };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { HorizontalAlignment, VerticalAlignment, BasePlugin, NodeData, NodeOperation, InteractionPriority } from '@knotx/core';
|
|
2
|
+
|
|
3
|
+
declare module '@knotx/core' {
|
|
4
|
+
interface PluginData {
|
|
5
|
+
bounding: {
|
|
6
|
+
/**
|
|
7
|
+
* 获取自定义的 resize handle 属性
|
|
8
|
+
* @param nodeId 节点 ID
|
|
9
|
+
* @param position 位置
|
|
10
|
+
* @returns 属性对象
|
|
11
|
+
*/
|
|
12
|
+
getCustomResizeHandleAttributes: (nodeId: string, position: ResizeHandlePosition) => Record<string, string>;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
interface ResizeEvent {
|
|
17
|
+
nodeId: string;
|
|
18
|
+
startWidth: number;
|
|
19
|
+
startHeight: number;
|
|
20
|
+
startX: number;
|
|
21
|
+
startY: number;
|
|
22
|
+
position: string;
|
|
23
|
+
}
|
|
24
|
+
interface ResizeData {
|
|
25
|
+
nodeId: string;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
}
|
|
29
|
+
interface ConnectHandlePosition {
|
|
30
|
+
top?: boolean;
|
|
31
|
+
right?: boolean;
|
|
32
|
+
bottom?: boolean;
|
|
33
|
+
left?: boolean;
|
|
34
|
+
}
|
|
35
|
+
type ResizeHandlePosition = `${HorizontalAlignment}-${VerticalAlignment}` | HorizontalAlignment | VerticalAlignment;
|
|
36
|
+
interface BoundingOptions {
|
|
37
|
+
features?: {
|
|
38
|
+
resize?: boolean;
|
|
39
|
+
connect?: boolean;
|
|
40
|
+
boundingBox?: boolean;
|
|
41
|
+
};
|
|
42
|
+
sizes?: {
|
|
43
|
+
resizeHandle?: number;
|
|
44
|
+
connectHandle?: number;
|
|
45
|
+
boundingBoxThreshold?: number;
|
|
46
|
+
};
|
|
47
|
+
styles?: {
|
|
48
|
+
resizeHandle?: {
|
|
49
|
+
fill?: string;
|
|
50
|
+
stroke?: string;
|
|
51
|
+
strokeWidth?: number;
|
|
52
|
+
};
|
|
53
|
+
connectHandle?: {
|
|
54
|
+
fill?: string;
|
|
55
|
+
stroke?: string;
|
|
56
|
+
strokeWidth?: number;
|
|
57
|
+
shadowColor?: string;
|
|
58
|
+
shadowWidth?: number;
|
|
59
|
+
};
|
|
60
|
+
boundingBox?: {
|
|
61
|
+
stroke?: string;
|
|
62
|
+
strokeWidth?: number;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
resize?: {
|
|
66
|
+
minWidth?: number;
|
|
67
|
+
minHeight?: number;
|
|
68
|
+
inertia?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* default: @var DEFAULT_RESIZE_HANDLES
|
|
71
|
+
*/
|
|
72
|
+
handles?: ResizeHandlePosition[];
|
|
73
|
+
/**
|
|
74
|
+
* 指定哪些节点类型可以被 resize
|
|
75
|
+
* 默认所有节点
|
|
76
|
+
*/
|
|
77
|
+
nodesType?: string[];
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
declare class Bounding extends BasePlugin<'bounding'> {
|
|
81
|
+
private options;
|
|
82
|
+
name: "bounding";
|
|
83
|
+
nodes: NodeData[];
|
|
84
|
+
getNode: (id: string) => NodeData | undefined;
|
|
85
|
+
dispatchNodeOperation: (operation: NodeOperation) => void;
|
|
86
|
+
startInteraction: (pluginId: string, type: string, priority: InteractionPriority) => void;
|
|
87
|
+
endInteraction: (pluginId: string, type: string) => void;
|
|
88
|
+
canInteract: (pluginId: string, type: string, autoStartPriority?: InteractionPriority) => boolean;
|
|
89
|
+
canvasScale: number;
|
|
90
|
+
private subscription?;
|
|
91
|
+
private resizeHandleClassName;
|
|
92
|
+
private connectHandleClassName;
|
|
93
|
+
private boundingBoxClassName;
|
|
94
|
+
private getResizeHandleAttributes;
|
|
95
|
+
constructor(options?: BoundingOptions);
|
|
96
|
+
init(): void;
|
|
97
|
+
destroy(): void;
|
|
98
|
+
render(): JSX.Element;
|
|
99
|
+
private getCursorStyle;
|
|
100
|
+
private getPositionByEdges;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { Bounding, type BoundingOptions, type ConnectHandlePosition, type ResizeData, type ResizeEvent, type ResizeHandlePosition };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
import { jsx, jsxs } from '@knotx/jsx/jsx-runtime';
|
|
2
|
+
import { Layer, bem, use, BasePlugin, InteractionPriority } from '@knotx/core';
|
|
3
|
+
import { inject, register, layer, OnInit, OnDestroy } from '@knotx/decorators';
|
|
4
|
+
import interact from 'interactjs';
|
|
5
|
+
import { Subject } from 'rxjs';
|
|
6
|
+
import { switchMap, map, tap, takeUntil } from 'rxjs/operators';
|
|
7
|
+
import '@knotx/plugins-canvas';
|
|
8
|
+
|
|
9
|
+
var __create = Object.create;
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __defProps = Object.defineProperties;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
14
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
17
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
18
|
+
var __typeError = (msg) => {
|
|
19
|
+
throw TypeError(msg);
|
|
20
|
+
};
|
|
21
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
22
|
+
var __spreadValues = (a, b) => {
|
|
23
|
+
for (var prop in b || (b = {}))
|
|
24
|
+
if (__hasOwnProp.call(b, prop))
|
|
25
|
+
__defNormalProp(a, prop, b[prop]);
|
|
26
|
+
if (__getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
28
|
+
if (__propIsEnum.call(b, prop))
|
|
29
|
+
__defNormalProp(a, prop, b[prop]);
|
|
30
|
+
}
|
|
31
|
+
return a;
|
|
32
|
+
};
|
|
33
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
34
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
35
|
+
var __decoratorStart = (base) => {
|
|
36
|
+
var _a2;
|
|
37
|
+
return [, , , __create((_a2 = base == null ? void 0 : base[__knownSymbol("metadata")]) != null ? _a2 : null)];
|
|
38
|
+
};
|
|
39
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
40
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
41
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
42
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
43
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
44
|
+
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);
|
|
45
|
+
return value;
|
|
46
|
+
};
|
|
47
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
48
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
49
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
50
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
51
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
52
|
+
return __privateGet(this, extra);
|
|
53
|
+
}, set [name](x) {
|
|
54
|
+
return __privateSet(this, extra, x);
|
|
55
|
+
} }, name));
|
|
56
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
57
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
58
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
59
|
+
if (k) {
|
|
60
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
61
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
62
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
63
|
+
}
|
|
64
|
+
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;
|
|
65
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
66
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
67
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
68
|
+
}
|
|
69
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
70
|
+
};
|
|
71
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
72
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
73
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
74
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
75
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
76
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
77
|
+
var _render_dec, _destroy_dec, _init_dec, _getResizeHandleAttributes_dec, _canvasScale_dec, _canInteract_dec, _endInteraction_dec, _startInteraction_dec, _dispatchNodeOperation_dec, _getNode_dec, _nodes_dec, _a, _init;
|
|
78
|
+
const DEFAULT_CONNECT_HANDLE_POSITIONS = [
|
|
79
|
+
{ top: true },
|
|
80
|
+
{ right: true },
|
|
81
|
+
{ bottom: true },
|
|
82
|
+
{ left: true }
|
|
83
|
+
];
|
|
84
|
+
const DEFAULT_OPTIONS = {
|
|
85
|
+
features: {
|
|
86
|
+
resize: true,
|
|
87
|
+
connect: true,
|
|
88
|
+
boundingBox: true
|
|
89
|
+
},
|
|
90
|
+
sizes: {
|
|
91
|
+
resizeHandle: 6,
|
|
92
|
+
connectHandle: 5,
|
|
93
|
+
boundingBoxThreshold: 8
|
|
94
|
+
},
|
|
95
|
+
styles: {
|
|
96
|
+
resizeHandle: {
|
|
97
|
+
fill: "#fff",
|
|
98
|
+
stroke: "var(--knotx-plugin__bounding-resize-handle-color, #6366f1)",
|
|
99
|
+
strokeWidth: 1
|
|
100
|
+
},
|
|
101
|
+
connectHandle: {
|
|
102
|
+
fill: "var(--knotx-primary-color, #6366f1)",
|
|
103
|
+
stroke: "#fff",
|
|
104
|
+
strokeWidth: 1
|
|
105
|
+
},
|
|
106
|
+
boundingBox: {
|
|
107
|
+
stroke: "var(--knotx-plugin__bounding-resize-handle-color, #6366f1)",
|
|
108
|
+
strokeWidth: 1
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
resize: {
|
|
112
|
+
minWidth: 30,
|
|
113
|
+
minHeight: 30,
|
|
114
|
+
inertia: true,
|
|
115
|
+
handles: [
|
|
116
|
+
"left-top",
|
|
117
|
+
"right-top",
|
|
118
|
+
"right-bottom",
|
|
119
|
+
"left-bottom"
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
class Bounding extends (_a = BasePlugin, _nodes_dec = [inject.nodes()], _getNode_dec = [inject.getNode()], _dispatchNodeOperation_dec = [inject.dispatchNodeOperation()], _startInteraction_dec = [inject.startInteraction()], _endInteraction_dec = [inject.endInteraction()], _canInteract_dec = [inject.canInteract()], _canvasScale_dec = [inject.canvas.transform((state) => state.scale)], _getResizeHandleAttributes_dec = [register("getCustomResizeHandleAttributes")], _init_dec = [OnInit], _destroy_dec = [OnDestroy], _render_dec = [layer(Layer.Nodes, 1)], _a) {
|
|
124
|
+
constructor(options = {}) {
|
|
125
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
126
|
+
super();
|
|
127
|
+
this.options = options;
|
|
128
|
+
__runInitializers(_init, 5, this);
|
|
129
|
+
__publicField(this, "name", "bounding");
|
|
130
|
+
__publicField(this, "nodes", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
|
|
131
|
+
__publicField(this, "getNode", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
|
|
132
|
+
__publicField(this, "dispatchNodeOperation", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
|
|
133
|
+
__publicField(this, "startInteraction", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
|
|
134
|
+
__publicField(this, "endInteraction", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
|
|
135
|
+
__publicField(this, "canInteract", __runInitializers(_init, 28, this)), __runInitializers(_init, 31, this);
|
|
136
|
+
__publicField(this, "canvasScale", __runInitializers(_init, 32, this, 1)), __runInitializers(_init, 35, this);
|
|
137
|
+
__publicField(this, "subscription");
|
|
138
|
+
__publicField(this, "resizeHandleClassName", bem(this.name, "resize-handle"));
|
|
139
|
+
__publicField(this, "connectHandleClassName", bem(this.name, "connect-handle"));
|
|
140
|
+
__publicField(this, "boundingBoxClassName", bem(this.name, "bounding-box"));
|
|
141
|
+
__publicField(this, "getResizeHandleAttributes", __runInitializers(_init, 36, this, (nodeId, position) => {
|
|
142
|
+
return {
|
|
143
|
+
"className": this.resizeHandleClassName,
|
|
144
|
+
"data-plugin-id": this.pluginId,
|
|
145
|
+
"data-resize-target": nodeId,
|
|
146
|
+
"data-resize-handle-position": position
|
|
147
|
+
};
|
|
148
|
+
})), __runInitializers(_init, 39, this);
|
|
149
|
+
this.options = __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options), {
|
|
150
|
+
features: __spreadValues(__spreadValues({}, DEFAULT_OPTIONS.features), options.features),
|
|
151
|
+
sizes: __spreadValues(__spreadValues({}, DEFAULT_OPTIONS.sizes), options.sizes),
|
|
152
|
+
styles: {
|
|
153
|
+
resizeHandle: __spreadValues(__spreadValues({}, (_a2 = DEFAULT_OPTIONS.styles) == null ? void 0 : _a2.resizeHandle), (_b = options.styles) == null ? void 0 : _b.resizeHandle),
|
|
154
|
+
connectHandle: __spreadValues(__spreadValues({}, (_c = DEFAULT_OPTIONS.styles) == null ? void 0 : _c.connectHandle), (_d = options.styles) == null ? void 0 : _d.connectHandle),
|
|
155
|
+
boundingBox: __spreadValues(__spreadValues({}, (_e = DEFAULT_OPTIONS.styles) == null ? void 0 : _e.boundingBox), (_f = options.styles) == null ? void 0 : _f.boundingBox)
|
|
156
|
+
},
|
|
157
|
+
resize: __spreadValues(__spreadValues({}, DEFAULT_OPTIONS.resize), options.resize)
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
init() {
|
|
161
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
162
|
+
const resizeStart$ = new Subject();
|
|
163
|
+
const resizeMove$ = new Subject();
|
|
164
|
+
const resizeEnd$ = new Subject();
|
|
165
|
+
const startResize = (nodeId, position) => {
|
|
166
|
+
const node = this.getNode(nodeId);
|
|
167
|
+
if (!(node == null ? void 0 : node.measured))
|
|
168
|
+
return;
|
|
169
|
+
resizeStart$.next({
|
|
170
|
+
nodeId,
|
|
171
|
+
startWidth: node.measured.width,
|
|
172
|
+
startHeight: node.measured.height,
|
|
173
|
+
startX: node.position.x,
|
|
174
|
+
startY: node.position.y,
|
|
175
|
+
position
|
|
176
|
+
});
|
|
177
|
+
this.startInteraction(this.pluginId, "resize", InteractionPriority.EntityMeasureDrag);
|
|
178
|
+
};
|
|
179
|
+
const endResize = () => {
|
|
180
|
+
resizeEnd$.next();
|
|
181
|
+
this.endInteraction(this.pluginId, "resize");
|
|
182
|
+
};
|
|
183
|
+
const updateResize = (event) => {
|
|
184
|
+
if (!this.canInteract(this.pluginId, "resize")) {
|
|
185
|
+
endResize();
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const scale = this.canvasScale;
|
|
189
|
+
resizeMove$.next({
|
|
190
|
+
dx: event.dx / scale,
|
|
191
|
+
dy: event.dy / scale
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
if ((_a2 = this.options.features) == null ? void 0 : _a2.resize) {
|
|
195
|
+
const currentInteractable = interact(`[data-plugin-id="${this.pluginId}"].${this.resizeHandleClassName}`).resizable({
|
|
196
|
+
edges: { left: true, right: true, bottom: true, top: true },
|
|
197
|
+
inertia: (_b = this.options.resize) == null ? void 0 : _b.inertia,
|
|
198
|
+
cursorChecker: (_action, _interactable, element) => {
|
|
199
|
+
var _a3;
|
|
200
|
+
const position = (_a3 = element.getAttribute("data-resize-handle-position")) != null ? _a3 : "";
|
|
201
|
+
return this.getCursorStyle(position);
|
|
202
|
+
},
|
|
203
|
+
listeners: {
|
|
204
|
+
start: (event) => {
|
|
205
|
+
const nodeId = event.target.getAttribute("data-resize-target");
|
|
206
|
+
const position = event.target.getAttribute("data-resize-handle-position");
|
|
207
|
+
if (!nodeId)
|
|
208
|
+
return;
|
|
209
|
+
startResize(nodeId, position);
|
|
210
|
+
},
|
|
211
|
+
move: updateResize,
|
|
212
|
+
end: endResize
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
this.subscription = resizeStart$.pipe(
|
|
216
|
+
switchMap((startEvent) => {
|
|
217
|
+
const draftId = `${this.pluginId}-${startEvent.nodeId}`;
|
|
218
|
+
const { nodeId, startWidth, startHeight, startX, startY, position } = startEvent;
|
|
219
|
+
let currentWidth = startWidth;
|
|
220
|
+
let currentHeight = startHeight;
|
|
221
|
+
let currentX = startX;
|
|
222
|
+
let currentY = startY;
|
|
223
|
+
this.dispatchNodeOperation({
|
|
224
|
+
type: "startDraft",
|
|
225
|
+
draftId
|
|
226
|
+
});
|
|
227
|
+
return resizeMove$.pipe(
|
|
228
|
+
map((moveEvent) => {
|
|
229
|
+
var _a3, _b2, _c2, _d2;
|
|
230
|
+
let nextWidth = currentWidth;
|
|
231
|
+
let nextHeight = currentHeight;
|
|
232
|
+
let nextX = currentX;
|
|
233
|
+
let nextY = currentY;
|
|
234
|
+
const minWidth = (_b2 = (_a3 = this.options.resize) == null ? void 0 : _a3.minWidth) != null ? _b2 : 30;
|
|
235
|
+
const minHeight = (_d2 = (_c2 = this.options.resize) == null ? void 0 : _c2.minHeight) != null ? _d2 : 30;
|
|
236
|
+
if (position.includes("right")) {
|
|
237
|
+
nextWidth = Math.max(minWidth, currentWidth + moveEvent.dx);
|
|
238
|
+
}
|
|
239
|
+
if (position.includes("left")) {
|
|
240
|
+
const deltaX = Math.min(moveEvent.dx, currentWidth - minWidth);
|
|
241
|
+
nextX = currentX + deltaX;
|
|
242
|
+
nextWidth = currentWidth - deltaX;
|
|
243
|
+
}
|
|
244
|
+
if (position.includes("bottom")) {
|
|
245
|
+
nextHeight = Math.max(minHeight, currentHeight + moveEvent.dy);
|
|
246
|
+
}
|
|
247
|
+
if (position.includes("top")) {
|
|
248
|
+
const deltaY = Math.min(moveEvent.dy, currentHeight - minHeight);
|
|
249
|
+
nextY = currentY + deltaY;
|
|
250
|
+
nextHeight = currentHeight - deltaY;
|
|
251
|
+
}
|
|
252
|
+
currentWidth = nextWidth;
|
|
253
|
+
currentHeight = nextHeight;
|
|
254
|
+
currentX = nextX;
|
|
255
|
+
currentY = nextY;
|
|
256
|
+
return {
|
|
257
|
+
nodeId,
|
|
258
|
+
width: currentWidth,
|
|
259
|
+
height: currentHeight,
|
|
260
|
+
x: currentX,
|
|
261
|
+
y: currentY
|
|
262
|
+
};
|
|
263
|
+
}),
|
|
264
|
+
tap((resizeData) => {
|
|
265
|
+
const node = this.getNode(resizeData.nodeId);
|
|
266
|
+
if (node) {
|
|
267
|
+
this.dispatchNodeOperation({
|
|
268
|
+
type: "draftOperation",
|
|
269
|
+
draftId,
|
|
270
|
+
operation: {
|
|
271
|
+
type: "update",
|
|
272
|
+
id: resizeData.nodeId,
|
|
273
|
+
data: {
|
|
274
|
+
position: {
|
|
275
|
+
x: resizeData.x,
|
|
276
|
+
y: resizeData.y
|
|
277
|
+
},
|
|
278
|
+
measured: {
|
|
279
|
+
width: resizeData.width,
|
|
280
|
+
height: resizeData.height
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}),
|
|
287
|
+
takeUntil(resizeEnd$.pipe(
|
|
288
|
+
tap(() => {
|
|
289
|
+
this.dispatchNodeOperation({
|
|
290
|
+
type: "commitDraft",
|
|
291
|
+
draftId
|
|
292
|
+
});
|
|
293
|
+
})
|
|
294
|
+
))
|
|
295
|
+
);
|
|
296
|
+
})
|
|
297
|
+
).subscribe();
|
|
298
|
+
this.subscription.add(() => {
|
|
299
|
+
currentInteractable == null ? void 0 : currentInteractable.unset();
|
|
300
|
+
resizeStart$.complete();
|
|
301
|
+
resizeMove$.complete();
|
|
302
|
+
resizeEnd$.complete();
|
|
303
|
+
});
|
|
304
|
+
if ((_c = this.options.features) == null ? void 0 : _c.boundingBox) {
|
|
305
|
+
const boundingInteractable = interact(`[data-plugin-id="${this.pluginId}"].${this.boundingBoxClassName}`).resizable({
|
|
306
|
+
enabled: (_d = this.options.features) == null ? void 0 : _d.resize,
|
|
307
|
+
edges: { left: true, right: true, bottom: true, top: true },
|
|
308
|
+
inertia: (_e = this.options.resize) == null ? void 0 : _e.inertia,
|
|
309
|
+
cursorChecker: (action) => this.getCursorStyle(this.getPositionByEdges(action.edges)),
|
|
310
|
+
listeners: {
|
|
311
|
+
start: (event) => {
|
|
312
|
+
const nodeId = event.target.getAttribute("data-resize-target");
|
|
313
|
+
const position = this.getPositionByEdges(event.edges);
|
|
314
|
+
if (!nodeId)
|
|
315
|
+
return;
|
|
316
|
+
startResize(nodeId, position);
|
|
317
|
+
},
|
|
318
|
+
move: updateResize,
|
|
319
|
+
end: endResize
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
(_f = this.subscription) == null ? void 0 : _f.add(() => boundingInteractable.unset());
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
destroy() {
|
|
327
|
+
var _a2;
|
|
328
|
+
(_a2 = this.subscription) == null ? void 0 : _a2.unsubscribe();
|
|
329
|
+
}
|
|
330
|
+
render() {
|
|
331
|
+
var _a2;
|
|
332
|
+
const nodes = use(() => this.nodes);
|
|
333
|
+
const pluginId = this.pluginId;
|
|
334
|
+
const nodesType = (_a2 = this.options.resize) == null ? void 0 : _a2.nodesType;
|
|
335
|
+
return /* @__PURE__ */ jsx(
|
|
336
|
+
"svg",
|
|
337
|
+
{
|
|
338
|
+
style: {
|
|
339
|
+
position: "absolute",
|
|
340
|
+
left: 0,
|
|
341
|
+
top: 0,
|
|
342
|
+
pointerEvents: "none",
|
|
343
|
+
overflow: "visible"
|
|
344
|
+
},
|
|
345
|
+
children: nodes.map((node) => {
|
|
346
|
+
var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
347
|
+
const { position: { x, y }, measured, type } = node;
|
|
348
|
+
if (!measured)
|
|
349
|
+
return null;
|
|
350
|
+
if (nodesType && !nodesType.includes(type))
|
|
351
|
+
return null;
|
|
352
|
+
const { width, height } = measured;
|
|
353
|
+
const resizeSize = (_c = (_a3 = this.options.sizes) == null ? void 0 : _a3.resizeHandle) != null ? _c : (_b = DEFAULT_OPTIONS.sizes) == null ? void 0 : _b.resizeHandle;
|
|
354
|
+
const resizeStyles = (_f = (_d = this.options.styles) == null ? void 0 : _d.resizeHandle) != null ? _f : (_e = DEFAULT_OPTIONS.styles) == null ? void 0 : _e.resizeHandle;
|
|
355
|
+
const connectSize = (_i = (_g = this.options.sizes) == null ? void 0 : _g.connectHandle) != null ? _i : (_h = DEFAULT_OPTIONS.sizes) == null ? void 0 : _h.connectHandle;
|
|
356
|
+
const connectStyles = (_l = (_j = this.options.styles) == null ? void 0 : _j.connectHandle) != null ? _l : (_k = DEFAULT_OPTIONS.styles) == null ? void 0 : _k.connectHandle;
|
|
357
|
+
return /* @__PURE__ */ jsxs("g", { style: { pointerEvents: "auto" }, children: [
|
|
358
|
+
((_m = this.options.features) == null ? void 0 : _m.boundingBox) && /* @__PURE__ */ jsx(
|
|
359
|
+
"rect",
|
|
360
|
+
{
|
|
361
|
+
className: this.boundingBoxClassName,
|
|
362
|
+
"data-plugin-id": this.pluginId,
|
|
363
|
+
"data-resize-target": node.id,
|
|
364
|
+
x,
|
|
365
|
+
y,
|
|
366
|
+
width,
|
|
367
|
+
height,
|
|
368
|
+
fill: "none",
|
|
369
|
+
stroke: (_o = (_n = this.options.styles) == null ? void 0 : _n.boundingBox) == null ? void 0 : _o.stroke,
|
|
370
|
+
strokeWidth: (_q = (_p = this.options.styles) == null ? void 0 : _p.boundingBox) == null ? void 0 : _q.strokeWidth,
|
|
371
|
+
style: { pointerEvents: "auto" }
|
|
372
|
+
}
|
|
373
|
+
),
|
|
374
|
+
((_r = this.options.features) == null ? void 0 : _r.resize) && ((_t = (_s = this.options.resize) == null ? void 0 : _s.handles) == null ? void 0 : _t.map((position, index) => {
|
|
375
|
+
let handleX = x;
|
|
376
|
+
let handleY = y;
|
|
377
|
+
const [xPosition, yPosition] = position.split("-");
|
|
378
|
+
switch (xPosition) {
|
|
379
|
+
case "right":
|
|
380
|
+
handleX += width;
|
|
381
|
+
break;
|
|
382
|
+
case "left":
|
|
383
|
+
break;
|
|
384
|
+
default:
|
|
385
|
+
handleX += width / 2;
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
switch (yPosition != null ? yPosition : xPosition) {
|
|
389
|
+
case "bottom":
|
|
390
|
+
handleY += height;
|
|
391
|
+
break;
|
|
392
|
+
case "top":
|
|
393
|
+
break;
|
|
394
|
+
default:
|
|
395
|
+
handleY += height / 2;
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
return /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(
|
|
399
|
+
"rect",
|
|
400
|
+
__spreadProps(__spreadValues({}, this.getResizeHandleAttributes(node.id, position)), {
|
|
401
|
+
x: handleX - resizeSize / 2,
|
|
402
|
+
y: handleY - resizeSize / 2,
|
|
403
|
+
width: resizeSize,
|
|
404
|
+
height: resizeSize,
|
|
405
|
+
fill: resizeStyles == null ? void 0 : resizeStyles.fill,
|
|
406
|
+
stroke: resizeStyles == null ? void 0 : resizeStyles.stroke,
|
|
407
|
+
strokeWidth: resizeStyles == null ? void 0 : resizeStyles.strokeWidth
|
|
408
|
+
})
|
|
409
|
+
) }, `resize-${index}`);
|
|
410
|
+
})),
|
|
411
|
+
((_u = this.options.features) == null ? void 0 : _u.connect) && DEFAULT_CONNECT_HANDLE_POSITIONS.map((position, index) => {
|
|
412
|
+
let handleX = x + width / 2;
|
|
413
|
+
let handleY = y + height / 2;
|
|
414
|
+
if (position.right)
|
|
415
|
+
handleX = x + width;
|
|
416
|
+
if (position.left)
|
|
417
|
+
handleX = x;
|
|
418
|
+
if (position.bottom)
|
|
419
|
+
handleY = y + height;
|
|
420
|
+
if (position.top)
|
|
421
|
+
handleY = y;
|
|
422
|
+
return /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(
|
|
423
|
+
"circle",
|
|
424
|
+
{
|
|
425
|
+
className: this.connectHandleClassName,
|
|
426
|
+
"data-plugin-id": pluginId,
|
|
427
|
+
"data-handle-target": node.id,
|
|
428
|
+
cx: handleX,
|
|
429
|
+
cy: handleY,
|
|
430
|
+
r: connectSize,
|
|
431
|
+
fill: connectStyles == null ? void 0 : connectStyles.fill,
|
|
432
|
+
stroke: connectStyles == null ? void 0 : connectStyles.stroke,
|
|
433
|
+
strokeWidth: connectStyles == null ? void 0 : connectStyles.strokeWidth
|
|
434
|
+
}
|
|
435
|
+
) }, `connect-${index}`);
|
|
436
|
+
})
|
|
437
|
+
] }, node.id);
|
|
438
|
+
})
|
|
439
|
+
}
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
getCursorStyle(position) {
|
|
443
|
+
switch (position) {
|
|
444
|
+
case "left-top":
|
|
445
|
+
case "right-bottom":
|
|
446
|
+
return "nwse-resize";
|
|
447
|
+
case "right-top":
|
|
448
|
+
case "left-bottom":
|
|
449
|
+
return "nesw-resize";
|
|
450
|
+
case "left":
|
|
451
|
+
case "right":
|
|
452
|
+
return "ew-resize";
|
|
453
|
+
case "top":
|
|
454
|
+
case "bottom":
|
|
455
|
+
return "ns-resize";
|
|
456
|
+
default:
|
|
457
|
+
return "default";
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
getPositionByEdges(edges) {
|
|
461
|
+
const positions = [];
|
|
462
|
+
if (edges == null ? void 0 : edges.left) {
|
|
463
|
+
positions.push("left");
|
|
464
|
+
}
|
|
465
|
+
if (edges == null ? void 0 : edges.right) {
|
|
466
|
+
positions.push("right");
|
|
467
|
+
}
|
|
468
|
+
if (edges == null ? void 0 : edges.top) {
|
|
469
|
+
positions.push("top");
|
|
470
|
+
}
|
|
471
|
+
if (edges == null ? void 0 : edges.bottom) {
|
|
472
|
+
positions.push("bottom");
|
|
473
|
+
}
|
|
474
|
+
return positions.join("-");
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
_init = __decoratorStart(_a);
|
|
478
|
+
__decorateElement(_init, 1, "init", _init_dec, Bounding);
|
|
479
|
+
__decorateElement(_init, 1, "destroy", _destroy_dec, Bounding);
|
|
480
|
+
__decorateElement(_init, 1, "render", _render_dec, Bounding);
|
|
481
|
+
__decorateElement(_init, 5, "nodes", _nodes_dec, Bounding);
|
|
482
|
+
__decorateElement(_init, 5, "getNode", _getNode_dec, Bounding);
|
|
483
|
+
__decorateElement(_init, 5, "dispatchNodeOperation", _dispatchNodeOperation_dec, Bounding);
|
|
484
|
+
__decorateElement(_init, 5, "startInteraction", _startInteraction_dec, Bounding);
|
|
485
|
+
__decorateElement(_init, 5, "endInteraction", _endInteraction_dec, Bounding);
|
|
486
|
+
__decorateElement(_init, 5, "canInteract", _canInteract_dec, Bounding);
|
|
487
|
+
__decorateElement(_init, 5, "canvasScale", _canvasScale_dec, Bounding);
|
|
488
|
+
__decorateElement(_init, 5, "getResizeHandleAttributes", _getResizeHandleAttributes_dec, Bounding);
|
|
489
|
+
__decoratorMetadata(_init, Bounding);
|
|
490
|
+
|
|
491
|
+
export { Bounding };
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@knotx/plugins-bounding",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"description": "Bounding 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-bounding"
|
|
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
|
+
"@interactjs/actions": "^1.10.27",
|
|
33
|
+
"@interactjs/core": "^1.10.27",
|
|
34
|
+
"@interactjs/modifiers": "^1.10.27",
|
|
35
|
+
"@interactjs/types": "^1.10.27",
|
|
36
|
+
"interactjs": "^1.10.27",
|
|
37
|
+
"rxjs": "^7.8.1",
|
|
38
|
+
"@knotx/plugins-canvas": "0.0.0",
|
|
39
|
+
"@knotx/decorators": "0.0.0",
|
|
40
|
+
"@knotx/core": "0.0.0",
|
|
41
|
+
"@knotx/render": "0.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@knotx/build-config": "0.0.0",
|
|
45
|
+
"@knotx/eslint-config": "0.0.0",
|
|
46
|
+
"@knotx/jsx": "0.0.0",
|
|
47
|
+
"@knotx/typescript-config": "0.0.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "unbuild --failOnWarn=false",
|
|
51
|
+
"dev": "unbuild --stub",
|
|
52
|
+
"lint": "eslint .",
|
|
53
|
+
"typecheck": "tsc --noEmit"
|
|
54
|
+
}
|
|
55
|
+
}
|