@tmagic/stage 1.1.0-beta.8 → 1.1.0-beta.9
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/dist/tmagic-stage.mjs +97 -35
- package/dist/tmagic-stage.mjs.map +1 -1
- package/dist/tmagic-stage.umd.js +102 -38
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/package.json +4 -4
- package/src/StageCore.ts +18 -6
- package/src/StageDragResize.ts +49 -29
- package/src/StageMultiDragResize.ts +37 -12
- package/src/types.ts +32 -14
- package/types/StageCore.d.ts +2 -1
- package/types/StageDragResize.d.ts +2 -0
- package/types/StageMultiDragResize.d.ts +3 -1
- package/types/types.d.ts +30 -14
package/dist/tmagic-stage.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import EventEmitter$1, { EventEmitter } from 'events';
|
|
2
2
|
import { removeClassName, removeClassNameByClassName, createDiv, injectStyle, isSameDomain, getHost, addClassName } from '@tmagic/utils';
|
|
3
|
+
import KeyController from 'keycon';
|
|
3
4
|
import Moveable from 'moveable';
|
|
4
5
|
import MoveableHelper from 'moveable-helper';
|
|
5
|
-
import KeyController from 'keycon';
|
|
6
6
|
import { throttle } from 'lodash-es';
|
|
7
7
|
import Guides from '@scena/guides';
|
|
8
8
|
|
|
@@ -38,6 +38,18 @@ var Mode = /* @__PURE__ */ ((Mode2) => {
|
|
|
38
38
|
})(Mode || {});
|
|
39
39
|
const SELECTED_CLASS = "tmagic-stage-selected-area";
|
|
40
40
|
|
|
41
|
+
var ContainerHighlightType = /* @__PURE__ */ ((ContainerHighlightType2) => {
|
|
42
|
+
ContainerHighlightType2["DEFAULT"] = "default";
|
|
43
|
+
ContainerHighlightType2["ALT"] = "alt";
|
|
44
|
+
return ContainerHighlightType2;
|
|
45
|
+
})(ContainerHighlightType || {});
|
|
46
|
+
var StageDragStatus = /* @__PURE__ */ ((StageDragStatus2) => {
|
|
47
|
+
StageDragStatus2["START"] = "start";
|
|
48
|
+
StageDragStatus2["ING"] = "ing";
|
|
49
|
+
StageDragStatus2["END"] = "end";
|
|
50
|
+
return StageDragStatus2;
|
|
51
|
+
})(StageDragStatus || {});
|
|
52
|
+
|
|
41
53
|
const getParents = (el, relative) => {
|
|
42
54
|
let cur = el.parentElement;
|
|
43
55
|
const parents = [];
|
|
@@ -215,14 +227,27 @@ class StageDragResize extends EventEmitter {
|
|
|
215
227
|
elementGuidelines = [];
|
|
216
228
|
mode = Mode.ABSOLUTE;
|
|
217
229
|
moveableOptions = {};
|
|
218
|
-
dragStatus =
|
|
230
|
+
dragStatus = StageDragStatus.END;
|
|
219
231
|
ghostEl;
|
|
220
232
|
moveableHelper;
|
|
233
|
+
isContainerHighlight = false;
|
|
221
234
|
constructor(config) {
|
|
222
235
|
super();
|
|
223
236
|
this.core = config.core;
|
|
224
237
|
this.container = config.container;
|
|
225
238
|
this.mask = config.mask;
|
|
239
|
+
KeyController.global.keydown("alt", (e) => {
|
|
240
|
+
e.inputEvent.preventDefault();
|
|
241
|
+
this.isContainerHighlight = true;
|
|
242
|
+
});
|
|
243
|
+
KeyController.global.keyup("alt", (e) => {
|
|
244
|
+
e.inputEvent.preventDefault();
|
|
245
|
+
const doc = this.core.renderer.contentWindow?.document;
|
|
246
|
+
if (doc && this.canContainerHighlight()) {
|
|
247
|
+
removeClassNameByClassName(doc, this.core.containerHighlightClassName);
|
|
248
|
+
}
|
|
249
|
+
this.isContainerHighlight = false;
|
|
250
|
+
});
|
|
226
251
|
}
|
|
227
252
|
select(el, event) {
|
|
228
253
|
const oldTarget = this.target;
|
|
@@ -287,7 +312,7 @@ class StageDragResize extends EventEmitter {
|
|
|
287
312
|
this.moveable?.destroy();
|
|
288
313
|
this.destroyGhostEl();
|
|
289
314
|
this.destroyDragEl();
|
|
290
|
-
this.dragStatus =
|
|
315
|
+
this.dragStatus = StageDragStatus.END;
|
|
291
316
|
this.removeAllListeners();
|
|
292
317
|
}
|
|
293
318
|
init(el) {
|
|
@@ -351,7 +376,7 @@ class StageDragResize extends EventEmitter {
|
|
|
351
376
|
this.moveable.on("resizeStart", (e) => {
|
|
352
377
|
if (!this.target)
|
|
353
378
|
return;
|
|
354
|
-
this.dragStatus =
|
|
379
|
+
this.dragStatus = StageDragStatus.START;
|
|
355
380
|
this.moveableHelper?.onResizeStart(e);
|
|
356
381
|
frame.top = this.target.offsetTop;
|
|
357
382
|
frame.left = this.target.offsetLeft;
|
|
@@ -360,7 +385,7 @@ class StageDragResize extends EventEmitter {
|
|
|
360
385
|
if (!this.moveable || !this.target || !this.dragEl)
|
|
361
386
|
return;
|
|
362
387
|
const { beforeTranslate } = drag;
|
|
363
|
-
this.dragStatus =
|
|
388
|
+
this.dragStatus = StageDragStatus.ING;
|
|
364
389
|
this.moveableHelper?.onResize(e);
|
|
365
390
|
if (this.mode === Mode.SORTABLE) {
|
|
366
391
|
this.target.style.top = "0px";
|
|
@@ -371,7 +396,7 @@ class StageDragResize extends EventEmitter {
|
|
|
371
396
|
this.target.style.width = `${width}px`;
|
|
372
397
|
this.target.style.height = `${height}px`;
|
|
373
398
|
}).on("resizeEnd", () => {
|
|
374
|
-
this.dragStatus =
|
|
399
|
+
this.dragStatus = StageDragStatus.END;
|
|
375
400
|
this.update(true);
|
|
376
401
|
});
|
|
377
402
|
}
|
|
@@ -388,7 +413,7 @@ class StageDragResize extends EventEmitter {
|
|
|
388
413
|
this.moveable.on("dragStart", (e) => {
|
|
389
414
|
if (!this.target)
|
|
390
415
|
throw new Error("\u672A\u9009\u4E2D\u7EC4\u4EF6");
|
|
391
|
-
this.dragStatus =
|
|
416
|
+
this.dragStatus = StageDragStatus.START;
|
|
392
417
|
this.moveableHelper?.onDragStart(e);
|
|
393
418
|
if (this.mode === Mode.SORTABLE) {
|
|
394
419
|
this.ghostEl = this.generateGhostEl(this.target);
|
|
@@ -402,8 +427,10 @@ class StageDragResize extends EventEmitter {
|
|
|
402
427
|
globalThis.clearTimeout(timeout);
|
|
403
428
|
timeout = void 0;
|
|
404
429
|
}
|
|
405
|
-
|
|
406
|
-
|
|
430
|
+
if (this.canContainerHighlight()) {
|
|
431
|
+
timeout = this.core.getAddContainerHighlightClassNameTimeout(e.inputEvent, [this.target]);
|
|
432
|
+
}
|
|
433
|
+
this.dragStatus = StageDragStatus.ING;
|
|
407
434
|
if (this.ghostEl) {
|
|
408
435
|
this.ghostEl.style.top = `${frame.top + e.beforeTranslate[1]}px`;
|
|
409
436
|
return;
|
|
@@ -417,10 +444,10 @@ class StageDragResize extends EventEmitter {
|
|
|
417
444
|
timeout = void 0;
|
|
418
445
|
}
|
|
419
446
|
let parentEl = null;
|
|
420
|
-
if (doc) {
|
|
447
|
+
if (doc && this.canContainerHighlight()) {
|
|
421
448
|
parentEl = removeClassNameByClassName(doc, this.core.containerHighlightClassName);
|
|
422
449
|
}
|
|
423
|
-
if (this.dragStatus ===
|
|
450
|
+
if (this.dragStatus === StageDragStatus.ING) {
|
|
424
451
|
if (parentEl) {
|
|
425
452
|
this.update(false, parentEl);
|
|
426
453
|
} else {
|
|
@@ -433,7 +460,7 @@ class StageDragResize extends EventEmitter {
|
|
|
433
460
|
}
|
|
434
461
|
}
|
|
435
462
|
}
|
|
436
|
-
this.dragStatus =
|
|
463
|
+
this.dragStatus = StageDragStatus.END;
|
|
437
464
|
this.destroyGhostEl();
|
|
438
465
|
});
|
|
439
466
|
}
|
|
@@ -441,17 +468,17 @@ class StageDragResize extends EventEmitter {
|
|
|
441
468
|
if (!this.moveable)
|
|
442
469
|
throw new Error("moveable \u672A\u521D\u59CB\u5316");
|
|
443
470
|
this.moveable.on("rotateStart", (e) => {
|
|
444
|
-
this.dragStatus =
|
|
471
|
+
this.dragStatus = StageDragStatus.START;
|
|
445
472
|
this.moveableHelper?.onRotateStart(e);
|
|
446
473
|
}).on("rotate", (e) => {
|
|
447
474
|
if (!this.target || !this.dragEl)
|
|
448
475
|
return;
|
|
449
|
-
this.dragStatus =
|
|
476
|
+
this.dragStatus = StageDragStatus.ING;
|
|
450
477
|
this.moveableHelper?.onRotate(e);
|
|
451
478
|
const frame = this.moveableHelper?.getFrame(e.target);
|
|
452
479
|
this.target.style.transform = frame?.toCSSObject().transform || "";
|
|
453
480
|
}).on("rotateEnd", (e) => {
|
|
454
|
-
this.dragStatus =
|
|
481
|
+
this.dragStatus = StageDragStatus.END;
|
|
455
482
|
const frame = this.moveableHelper?.getFrame(e.target);
|
|
456
483
|
this.emit("update", {
|
|
457
484
|
el: this.target,
|
|
@@ -465,17 +492,17 @@ class StageDragResize extends EventEmitter {
|
|
|
465
492
|
if (!this.moveable)
|
|
466
493
|
throw new Error("moveable \u672A\u521D\u59CB\u5316");
|
|
467
494
|
this.moveable.on("scaleStart", (e) => {
|
|
468
|
-
this.dragStatus =
|
|
495
|
+
this.dragStatus = StageDragStatus.START;
|
|
469
496
|
this.moveableHelper?.onScaleStart(e);
|
|
470
497
|
}).on("scale", (e) => {
|
|
471
498
|
if (!this.target || !this.dragEl)
|
|
472
499
|
return;
|
|
473
|
-
this.dragStatus =
|
|
500
|
+
this.dragStatus = StageDragStatus.ING;
|
|
474
501
|
this.moveableHelper?.onScale(e);
|
|
475
502
|
const frame = this.moveableHelper?.getFrame(e.target);
|
|
476
503
|
this.target.style.transform = frame?.toCSSObject().transform || "";
|
|
477
504
|
}).on("scaleEnd", (e) => {
|
|
478
|
-
this.dragStatus =
|
|
505
|
+
this.dragStatus = StageDragStatus.END;
|
|
479
506
|
const frame = this.moveableHelper?.getFrame(e.target);
|
|
480
507
|
this.emit("update", {
|
|
481
508
|
el: this.target,
|
|
@@ -523,9 +550,13 @@ class StageDragResize extends EventEmitter {
|
|
|
523
550
|
top = calcValueByFontsize(doc, this.dragEl.offsetTop) + parseFloat(translateY) - calcValueByFontsize(doc, parentTop);
|
|
524
551
|
}
|
|
525
552
|
this.emit("update", {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
553
|
+
data: [
|
|
554
|
+
{
|
|
555
|
+
el: this.target,
|
|
556
|
+
style: isResize ? { left, top, width, height } : { left, top }
|
|
557
|
+
}
|
|
558
|
+
],
|
|
559
|
+
parentEl
|
|
529
560
|
});
|
|
530
561
|
}
|
|
531
562
|
generateGhostEl(el) {
|
|
@@ -616,6 +647,9 @@ class StageDragResize extends EventEmitter {
|
|
|
616
647
|
...moveableOptions
|
|
617
648
|
};
|
|
618
649
|
}
|
|
650
|
+
canContainerHighlight() {
|
|
651
|
+
return this.core.containerHighlightType === ContainerHighlightType.DEFAULT || this.core.containerHighlightType === ContainerHighlightType.ALT && this.isContainerHighlight;
|
|
652
|
+
}
|
|
619
653
|
}
|
|
620
654
|
|
|
621
655
|
class TargetCalibrate extends EventEmitter {
|
|
@@ -1102,6 +1136,7 @@ class StageMultiDragResize extends EventEmitter {
|
|
|
1102
1136
|
targetList = [];
|
|
1103
1137
|
dragElList = [];
|
|
1104
1138
|
moveableForMulti;
|
|
1139
|
+
dragStatus = StageDragStatus.END;
|
|
1105
1140
|
multiMoveableHelper;
|
|
1106
1141
|
constructor(config) {
|
|
1107
1142
|
super();
|
|
@@ -1147,6 +1182,7 @@ class StageMultiDragResize extends EventEmitter {
|
|
|
1147
1182
|
id: matchEventTarget.id
|
|
1148
1183
|
});
|
|
1149
1184
|
});
|
|
1185
|
+
this.dragStatus = StageDragStatus.START;
|
|
1150
1186
|
}).on("dragGroup", (params) => {
|
|
1151
1187
|
const { events } = params;
|
|
1152
1188
|
events.forEach((ev) => {
|
|
@@ -1163,8 +1199,15 @@ class StageMultiDragResize extends EventEmitter {
|
|
|
1163
1199
|
}
|
|
1164
1200
|
});
|
|
1165
1201
|
this.multiMoveableHelper?.onDragGroup(params);
|
|
1202
|
+
this.dragStatus = StageDragStatus.ING;
|
|
1166
1203
|
}).on("dragGroupEnd", () => {
|
|
1167
1204
|
this.update();
|
|
1205
|
+
this.dragStatus = StageDragStatus.END;
|
|
1206
|
+
}).on("clickGroup", (params) => {
|
|
1207
|
+
const { inputTarget, targets } = params;
|
|
1208
|
+
if (!this.mask.isMultiSelectStatus && targets.length > 1 && targets.includes(inputTarget)) {
|
|
1209
|
+
this.emit("select", inputTarget.id.replace(DRAG_EL_ID_PREFIX, ""));
|
|
1210
|
+
}
|
|
1168
1211
|
});
|
|
1169
1212
|
}
|
|
1170
1213
|
canSelect(el, stop) {
|
|
@@ -1211,16 +1254,19 @@ class StageMultiDragResize extends EventEmitter {
|
|
|
1211
1254
|
const doc = contentWindow?.document;
|
|
1212
1255
|
if (!doc)
|
|
1213
1256
|
return;
|
|
1214
|
-
this.
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1257
|
+
this.emit("update", {
|
|
1258
|
+
data: this.targetList.map((targetItem) => {
|
|
1259
|
+
const offset = { left: targetItem.offsetLeft, top: targetItem.offsetTop };
|
|
1260
|
+
const left = calcValueByFontsize(doc, offset.left);
|
|
1261
|
+
const top = calcValueByFontsize(doc, offset.top);
|
|
1262
|
+
const width = calcValueByFontsize(doc, targetItem.clientWidth);
|
|
1263
|
+
const height = calcValueByFontsize(doc, targetItem.clientHeight);
|
|
1264
|
+
return {
|
|
1265
|
+
el: targetItem,
|
|
1266
|
+
style: isResize ? { left, top, width, height } : { left, top }
|
|
1267
|
+
};
|
|
1268
|
+
}),
|
|
1269
|
+
parentEl: null
|
|
1224
1270
|
});
|
|
1225
1271
|
}
|
|
1226
1272
|
getOptions(options = {}) {
|
|
@@ -1232,13 +1278,21 @@ class StageMultiDragResize extends EventEmitter {
|
|
|
1232
1278
|
defaultGroupRotate: 0,
|
|
1233
1279
|
defaultGroupOrigin: "50% 50%",
|
|
1234
1280
|
draggable: true,
|
|
1235
|
-
resizable:
|
|
1281
|
+
resizable: false,
|
|
1236
1282
|
throttleDrag: 0,
|
|
1237
1283
|
startDragRotate: 0,
|
|
1238
1284
|
throttleDragRotate: 0,
|
|
1239
1285
|
zoom: 1,
|
|
1240
1286
|
origin: true,
|
|
1241
1287
|
padding: { left: 0, top: 0, right: 0, bottom: 0 },
|
|
1288
|
+
snappable: true,
|
|
1289
|
+
bounds: {
|
|
1290
|
+
top: 0,
|
|
1291
|
+
left: -1,
|
|
1292
|
+
right: this.container.clientWidth - 1,
|
|
1293
|
+
bottom: this.container.clientHeight,
|
|
1294
|
+
...multiMoveableOptions.bounds || {}
|
|
1295
|
+
},
|
|
1242
1296
|
...options,
|
|
1243
1297
|
...multiMoveableOptions
|
|
1244
1298
|
};
|
|
@@ -1346,6 +1400,7 @@ class StageCore extends EventEmitter {
|
|
|
1346
1400
|
zoom = DEFAULT_ZOOM;
|
|
1347
1401
|
containerHighlightClassName;
|
|
1348
1402
|
containerHighlightDuration;
|
|
1403
|
+
containerHighlightType;
|
|
1349
1404
|
isContainer;
|
|
1350
1405
|
canSelect;
|
|
1351
1406
|
constructor(config) {
|
|
@@ -1354,8 +1409,9 @@ class StageCore extends EventEmitter {
|
|
|
1354
1409
|
this.setZoom(config.zoom);
|
|
1355
1410
|
this.canSelect = config.canSelect || ((el) => !!el.id);
|
|
1356
1411
|
this.isContainer = config.isContainer;
|
|
1357
|
-
this.containerHighlightClassName = config.containerHighlightClassName;
|
|
1358
|
-
this.containerHighlightDuration = config.containerHighlightDuration;
|
|
1412
|
+
this.containerHighlightClassName = config.containerHighlightClassName || CONTAINER_HIGHLIGHT_CLASS;
|
|
1413
|
+
this.containerHighlightDuration = config.containerHighlightDuration || 800;
|
|
1414
|
+
this.containerHighlightType = config.containerHighlightType;
|
|
1359
1415
|
this.renderer = new StageRender({ core: this });
|
|
1360
1416
|
this.mask = new StageMask({ core: this });
|
|
1361
1417
|
this.dr = new StageDragResize({ core: this, container: this.mask.content, mask: this.mask });
|
|
@@ -1382,6 +1438,8 @@ class StageCore extends EventEmitter {
|
|
|
1382
1438
|
const el = await this.getElementFromPoint(event);
|
|
1383
1439
|
if (!el)
|
|
1384
1440
|
return;
|
|
1441
|
+
if (this.multiDr.dragStatus === StageDragStatus.ING)
|
|
1442
|
+
return;
|
|
1385
1443
|
await this.highlight(el);
|
|
1386
1444
|
if (this.highlightedDom === this.selectedDom) {
|
|
1387
1445
|
this.highlightLayer.clearHighlight();
|
|
@@ -1413,6 +1471,10 @@ class StageCore extends EventEmitter {
|
|
|
1413
1471
|
});
|
|
1414
1472
|
this.multiDr.on("update", (data) => {
|
|
1415
1473
|
setTimeout(() => this.emit("update", data));
|
|
1474
|
+
}).on("select", async (id) => {
|
|
1475
|
+
const el = await this.getTargetElement(id);
|
|
1476
|
+
this.select(el);
|
|
1477
|
+
setTimeout(() => this.emit("select", el));
|
|
1416
1478
|
});
|
|
1417
1479
|
}
|
|
1418
1480
|
getElementsFromPoint(event) {
|
|
@@ -1575,5 +1637,5 @@ class StageCore extends EventEmitter {
|
|
|
1575
1637
|
}
|
|
1576
1638
|
}
|
|
1577
1639
|
|
|
1578
|
-
export { CONTAINER_HIGHLIGHT_CLASS, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, PAGE_CLASS, SELECTED_CLASS, StageDragResize, StageMask, StageRender, ZIndex, addSelectedClassName, calcValueByFontsize, StageCore as default, down, getAbsolutePosition, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isRelative, isStatic, removeSelectedClassName, up };
|
|
1640
|
+
export { CONTAINER_HIGHLIGHT_CLASS, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, PAGE_CLASS, SELECTED_CLASS, StageDragResize, StageDragStatus, StageMask, StageRender, ZIndex, addSelectedClassName, calcValueByFontsize, StageCore as default, down, getAbsolutePosition, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isRelative, isStatic, removeSelectedClassName, up };
|
|
1579
1641
|
//# sourceMappingURL=tmagic-stage.mjs.map
|