@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.umd.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('events'), require('@tmagic/utils'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'events', '@tmagic/utils', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicStage = {}, global.EventEmitter, global.utils, global.
|
|
5
|
-
})(this, (function (exports, EventEmitter, utils, Moveable, MoveableHelper,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('events'), require('@tmagic/utils'), require('keycon'), require('moveable'), require('moveable-helper'), require('lodash-es'), require('@scena/guides')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'events', '@tmagic/utils', 'keycon', 'moveable', 'moveable-helper', 'lodash-es', '@scena/guides'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicStage = {}, global.EventEmitter, global.utils, global.KeyController, global.Moveable, global.MoveableHelper, global.lodashEs, global.Guides));
|
|
5
|
+
})(this, (function (exports, EventEmitter, utils, KeyController, Moveable, MoveableHelper, lodashEs, Guides) { 'use strict';
|
|
6
6
|
|
|
7
7
|
const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
|
|
8
8
|
|
|
9
9
|
const EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
|
|
10
|
+
const KeyController__default = /*#__PURE__*/_interopDefaultLegacy(KeyController);
|
|
10
11
|
const Moveable__default = /*#__PURE__*/_interopDefaultLegacy(Moveable);
|
|
11
12
|
const MoveableHelper__default = /*#__PURE__*/_interopDefaultLegacy(MoveableHelper);
|
|
12
|
-
const KeyController__default = /*#__PURE__*/_interopDefaultLegacy(KeyController);
|
|
13
13
|
const Guides__default = /*#__PURE__*/_interopDefaultLegacy(Guides);
|
|
14
14
|
|
|
15
15
|
const GHOST_EL_ID_PREFIX = "ghost_el_";
|
|
@@ -44,6 +44,18 @@
|
|
|
44
44
|
})(Mode || {});
|
|
45
45
|
const SELECTED_CLASS = "tmagic-stage-selected-area";
|
|
46
46
|
|
|
47
|
+
var ContainerHighlightType = /* @__PURE__ */ ((ContainerHighlightType2) => {
|
|
48
|
+
ContainerHighlightType2["DEFAULT"] = "default";
|
|
49
|
+
ContainerHighlightType2["ALT"] = "alt";
|
|
50
|
+
return ContainerHighlightType2;
|
|
51
|
+
})(ContainerHighlightType || {});
|
|
52
|
+
var StageDragStatus = /* @__PURE__ */ ((StageDragStatus2) => {
|
|
53
|
+
StageDragStatus2["START"] = "start";
|
|
54
|
+
StageDragStatus2["ING"] = "ing";
|
|
55
|
+
StageDragStatus2["END"] = "end";
|
|
56
|
+
return StageDragStatus2;
|
|
57
|
+
})(StageDragStatus || {});
|
|
58
|
+
|
|
47
59
|
const getParents = (el, relative) => {
|
|
48
60
|
let cur = el.parentElement;
|
|
49
61
|
const parents = [];
|
|
@@ -221,14 +233,27 @@
|
|
|
221
233
|
elementGuidelines = [];
|
|
222
234
|
mode = Mode.ABSOLUTE;
|
|
223
235
|
moveableOptions = {};
|
|
224
|
-
dragStatus =
|
|
236
|
+
dragStatus = StageDragStatus.END;
|
|
225
237
|
ghostEl;
|
|
226
238
|
moveableHelper;
|
|
239
|
+
isContainerHighlight = false;
|
|
227
240
|
constructor(config) {
|
|
228
241
|
super();
|
|
229
242
|
this.core = config.core;
|
|
230
243
|
this.container = config.container;
|
|
231
244
|
this.mask = config.mask;
|
|
245
|
+
KeyController__default.default.global.keydown("alt", (e) => {
|
|
246
|
+
e.inputEvent.preventDefault();
|
|
247
|
+
this.isContainerHighlight = true;
|
|
248
|
+
});
|
|
249
|
+
KeyController__default.default.global.keyup("alt", (e) => {
|
|
250
|
+
e.inputEvent.preventDefault();
|
|
251
|
+
const doc = this.core.renderer.contentWindow?.document;
|
|
252
|
+
if (doc && this.canContainerHighlight()) {
|
|
253
|
+
utils.removeClassNameByClassName(doc, this.core.containerHighlightClassName);
|
|
254
|
+
}
|
|
255
|
+
this.isContainerHighlight = false;
|
|
256
|
+
});
|
|
232
257
|
}
|
|
233
258
|
select(el, event) {
|
|
234
259
|
const oldTarget = this.target;
|
|
@@ -293,7 +318,7 @@
|
|
|
293
318
|
this.moveable?.destroy();
|
|
294
319
|
this.destroyGhostEl();
|
|
295
320
|
this.destroyDragEl();
|
|
296
|
-
this.dragStatus =
|
|
321
|
+
this.dragStatus = StageDragStatus.END;
|
|
297
322
|
this.removeAllListeners();
|
|
298
323
|
}
|
|
299
324
|
init(el) {
|
|
@@ -357,7 +382,7 @@
|
|
|
357
382
|
this.moveable.on("resizeStart", (e) => {
|
|
358
383
|
if (!this.target)
|
|
359
384
|
return;
|
|
360
|
-
this.dragStatus =
|
|
385
|
+
this.dragStatus = StageDragStatus.START;
|
|
361
386
|
this.moveableHelper?.onResizeStart(e);
|
|
362
387
|
frame.top = this.target.offsetTop;
|
|
363
388
|
frame.left = this.target.offsetLeft;
|
|
@@ -366,7 +391,7 @@
|
|
|
366
391
|
if (!this.moveable || !this.target || !this.dragEl)
|
|
367
392
|
return;
|
|
368
393
|
const { beforeTranslate } = drag;
|
|
369
|
-
this.dragStatus =
|
|
394
|
+
this.dragStatus = StageDragStatus.ING;
|
|
370
395
|
this.moveableHelper?.onResize(e);
|
|
371
396
|
if (this.mode === Mode.SORTABLE) {
|
|
372
397
|
this.target.style.top = "0px";
|
|
@@ -377,7 +402,7 @@
|
|
|
377
402
|
this.target.style.width = `${width}px`;
|
|
378
403
|
this.target.style.height = `${height}px`;
|
|
379
404
|
}).on("resizeEnd", () => {
|
|
380
|
-
this.dragStatus =
|
|
405
|
+
this.dragStatus = StageDragStatus.END;
|
|
381
406
|
this.update(true);
|
|
382
407
|
});
|
|
383
408
|
}
|
|
@@ -394,7 +419,7 @@
|
|
|
394
419
|
this.moveable.on("dragStart", (e) => {
|
|
395
420
|
if (!this.target)
|
|
396
421
|
throw new Error("\u672A\u9009\u4E2D\u7EC4\u4EF6");
|
|
397
|
-
this.dragStatus =
|
|
422
|
+
this.dragStatus = StageDragStatus.START;
|
|
398
423
|
this.moveableHelper?.onDragStart(e);
|
|
399
424
|
if (this.mode === Mode.SORTABLE) {
|
|
400
425
|
this.ghostEl = this.generateGhostEl(this.target);
|
|
@@ -408,8 +433,10 @@
|
|
|
408
433
|
globalThis.clearTimeout(timeout);
|
|
409
434
|
timeout = void 0;
|
|
410
435
|
}
|
|
411
|
-
|
|
412
|
-
|
|
436
|
+
if (this.canContainerHighlight()) {
|
|
437
|
+
timeout = this.core.getAddContainerHighlightClassNameTimeout(e.inputEvent, [this.target]);
|
|
438
|
+
}
|
|
439
|
+
this.dragStatus = StageDragStatus.ING;
|
|
413
440
|
if (this.ghostEl) {
|
|
414
441
|
this.ghostEl.style.top = `${frame.top + e.beforeTranslate[1]}px`;
|
|
415
442
|
return;
|
|
@@ -423,10 +450,10 @@
|
|
|
423
450
|
timeout = void 0;
|
|
424
451
|
}
|
|
425
452
|
let parentEl = null;
|
|
426
|
-
if (doc) {
|
|
453
|
+
if (doc && this.canContainerHighlight()) {
|
|
427
454
|
parentEl = utils.removeClassNameByClassName(doc, this.core.containerHighlightClassName);
|
|
428
455
|
}
|
|
429
|
-
if (this.dragStatus ===
|
|
456
|
+
if (this.dragStatus === StageDragStatus.ING) {
|
|
430
457
|
if (parentEl) {
|
|
431
458
|
this.update(false, parentEl);
|
|
432
459
|
} else {
|
|
@@ -439,7 +466,7 @@
|
|
|
439
466
|
}
|
|
440
467
|
}
|
|
441
468
|
}
|
|
442
|
-
this.dragStatus =
|
|
469
|
+
this.dragStatus = StageDragStatus.END;
|
|
443
470
|
this.destroyGhostEl();
|
|
444
471
|
});
|
|
445
472
|
}
|
|
@@ -447,17 +474,17 @@
|
|
|
447
474
|
if (!this.moveable)
|
|
448
475
|
throw new Error("moveable \u672A\u521D\u59CB\u5316");
|
|
449
476
|
this.moveable.on("rotateStart", (e) => {
|
|
450
|
-
this.dragStatus =
|
|
477
|
+
this.dragStatus = StageDragStatus.START;
|
|
451
478
|
this.moveableHelper?.onRotateStart(e);
|
|
452
479
|
}).on("rotate", (e) => {
|
|
453
480
|
if (!this.target || !this.dragEl)
|
|
454
481
|
return;
|
|
455
|
-
this.dragStatus =
|
|
482
|
+
this.dragStatus = StageDragStatus.ING;
|
|
456
483
|
this.moveableHelper?.onRotate(e);
|
|
457
484
|
const frame = this.moveableHelper?.getFrame(e.target);
|
|
458
485
|
this.target.style.transform = frame?.toCSSObject().transform || "";
|
|
459
486
|
}).on("rotateEnd", (e) => {
|
|
460
|
-
this.dragStatus =
|
|
487
|
+
this.dragStatus = StageDragStatus.END;
|
|
461
488
|
const frame = this.moveableHelper?.getFrame(e.target);
|
|
462
489
|
this.emit("update", {
|
|
463
490
|
el: this.target,
|
|
@@ -471,17 +498,17 @@
|
|
|
471
498
|
if (!this.moveable)
|
|
472
499
|
throw new Error("moveable \u672A\u521D\u59CB\u5316");
|
|
473
500
|
this.moveable.on("scaleStart", (e) => {
|
|
474
|
-
this.dragStatus =
|
|
501
|
+
this.dragStatus = StageDragStatus.START;
|
|
475
502
|
this.moveableHelper?.onScaleStart(e);
|
|
476
503
|
}).on("scale", (e) => {
|
|
477
504
|
if (!this.target || !this.dragEl)
|
|
478
505
|
return;
|
|
479
|
-
this.dragStatus =
|
|
506
|
+
this.dragStatus = StageDragStatus.ING;
|
|
480
507
|
this.moveableHelper?.onScale(e);
|
|
481
508
|
const frame = this.moveableHelper?.getFrame(e.target);
|
|
482
509
|
this.target.style.transform = frame?.toCSSObject().transform || "";
|
|
483
510
|
}).on("scaleEnd", (e) => {
|
|
484
|
-
this.dragStatus =
|
|
511
|
+
this.dragStatus = StageDragStatus.END;
|
|
485
512
|
const frame = this.moveableHelper?.getFrame(e.target);
|
|
486
513
|
this.emit("update", {
|
|
487
514
|
el: this.target,
|
|
@@ -529,9 +556,13 @@
|
|
|
529
556
|
top = calcValueByFontsize(doc, this.dragEl.offsetTop) + parseFloat(translateY) - calcValueByFontsize(doc, parentTop);
|
|
530
557
|
}
|
|
531
558
|
this.emit("update", {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
559
|
+
data: [
|
|
560
|
+
{
|
|
561
|
+
el: this.target,
|
|
562
|
+
style: isResize ? { left, top, width, height } : { left, top }
|
|
563
|
+
}
|
|
564
|
+
],
|
|
565
|
+
parentEl
|
|
535
566
|
});
|
|
536
567
|
}
|
|
537
568
|
generateGhostEl(el) {
|
|
@@ -622,6 +653,9 @@
|
|
|
622
653
|
...moveableOptions
|
|
623
654
|
};
|
|
624
655
|
}
|
|
656
|
+
canContainerHighlight() {
|
|
657
|
+
return this.core.containerHighlightType === ContainerHighlightType.DEFAULT || this.core.containerHighlightType === ContainerHighlightType.ALT && this.isContainerHighlight;
|
|
658
|
+
}
|
|
625
659
|
}
|
|
626
660
|
|
|
627
661
|
class TargetCalibrate extends EventEmitter.EventEmitter {
|
|
@@ -1108,6 +1142,7 @@
|
|
|
1108
1142
|
targetList = [];
|
|
1109
1143
|
dragElList = [];
|
|
1110
1144
|
moveableForMulti;
|
|
1145
|
+
dragStatus = StageDragStatus.END;
|
|
1111
1146
|
multiMoveableHelper;
|
|
1112
1147
|
constructor(config) {
|
|
1113
1148
|
super();
|
|
@@ -1153,6 +1188,7 @@
|
|
|
1153
1188
|
id: matchEventTarget.id
|
|
1154
1189
|
});
|
|
1155
1190
|
});
|
|
1191
|
+
this.dragStatus = StageDragStatus.START;
|
|
1156
1192
|
}).on("dragGroup", (params) => {
|
|
1157
1193
|
const { events } = params;
|
|
1158
1194
|
events.forEach((ev) => {
|
|
@@ -1169,8 +1205,15 @@
|
|
|
1169
1205
|
}
|
|
1170
1206
|
});
|
|
1171
1207
|
this.multiMoveableHelper?.onDragGroup(params);
|
|
1208
|
+
this.dragStatus = StageDragStatus.ING;
|
|
1172
1209
|
}).on("dragGroupEnd", () => {
|
|
1173
1210
|
this.update();
|
|
1211
|
+
this.dragStatus = StageDragStatus.END;
|
|
1212
|
+
}).on("clickGroup", (params) => {
|
|
1213
|
+
const { inputTarget, targets } = params;
|
|
1214
|
+
if (!this.mask.isMultiSelectStatus && targets.length > 1 && targets.includes(inputTarget)) {
|
|
1215
|
+
this.emit("select", inputTarget.id.replace(DRAG_EL_ID_PREFIX, ""));
|
|
1216
|
+
}
|
|
1174
1217
|
});
|
|
1175
1218
|
}
|
|
1176
1219
|
canSelect(el, stop) {
|
|
@@ -1217,16 +1260,19 @@
|
|
|
1217
1260
|
const doc = contentWindow?.document;
|
|
1218
1261
|
if (!doc)
|
|
1219
1262
|
return;
|
|
1220
|
-
this.
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1263
|
+
this.emit("update", {
|
|
1264
|
+
data: this.targetList.map((targetItem) => {
|
|
1265
|
+
const offset = { left: targetItem.offsetLeft, top: targetItem.offsetTop };
|
|
1266
|
+
const left = calcValueByFontsize(doc, offset.left);
|
|
1267
|
+
const top = calcValueByFontsize(doc, offset.top);
|
|
1268
|
+
const width = calcValueByFontsize(doc, targetItem.clientWidth);
|
|
1269
|
+
const height = calcValueByFontsize(doc, targetItem.clientHeight);
|
|
1270
|
+
return {
|
|
1271
|
+
el: targetItem,
|
|
1272
|
+
style: isResize ? { left, top, width, height } : { left, top }
|
|
1273
|
+
};
|
|
1274
|
+
}),
|
|
1275
|
+
parentEl: null
|
|
1230
1276
|
});
|
|
1231
1277
|
}
|
|
1232
1278
|
getOptions(options = {}) {
|
|
@@ -1238,13 +1284,21 @@
|
|
|
1238
1284
|
defaultGroupRotate: 0,
|
|
1239
1285
|
defaultGroupOrigin: "50% 50%",
|
|
1240
1286
|
draggable: true,
|
|
1241
|
-
resizable:
|
|
1287
|
+
resizable: false,
|
|
1242
1288
|
throttleDrag: 0,
|
|
1243
1289
|
startDragRotate: 0,
|
|
1244
1290
|
throttleDragRotate: 0,
|
|
1245
1291
|
zoom: 1,
|
|
1246
1292
|
origin: true,
|
|
1247
1293
|
padding: { left: 0, top: 0, right: 0, bottom: 0 },
|
|
1294
|
+
snappable: true,
|
|
1295
|
+
bounds: {
|
|
1296
|
+
top: 0,
|
|
1297
|
+
left: -1,
|
|
1298
|
+
right: this.container.clientWidth - 1,
|
|
1299
|
+
bottom: this.container.clientHeight,
|
|
1300
|
+
...multiMoveableOptions.bounds || {}
|
|
1301
|
+
},
|
|
1248
1302
|
...options,
|
|
1249
1303
|
...multiMoveableOptions
|
|
1250
1304
|
};
|
|
@@ -1352,6 +1406,7 @@
|
|
|
1352
1406
|
zoom = DEFAULT_ZOOM;
|
|
1353
1407
|
containerHighlightClassName;
|
|
1354
1408
|
containerHighlightDuration;
|
|
1409
|
+
containerHighlightType;
|
|
1355
1410
|
isContainer;
|
|
1356
1411
|
canSelect;
|
|
1357
1412
|
constructor(config) {
|
|
@@ -1360,8 +1415,9 @@
|
|
|
1360
1415
|
this.setZoom(config.zoom);
|
|
1361
1416
|
this.canSelect = config.canSelect || ((el) => !!el.id);
|
|
1362
1417
|
this.isContainer = config.isContainer;
|
|
1363
|
-
this.containerHighlightClassName = config.containerHighlightClassName;
|
|
1364
|
-
this.containerHighlightDuration = config.containerHighlightDuration;
|
|
1418
|
+
this.containerHighlightClassName = config.containerHighlightClassName || CONTAINER_HIGHLIGHT_CLASS;
|
|
1419
|
+
this.containerHighlightDuration = config.containerHighlightDuration || 800;
|
|
1420
|
+
this.containerHighlightType = config.containerHighlightType;
|
|
1365
1421
|
this.renderer = new StageRender({ core: this });
|
|
1366
1422
|
this.mask = new StageMask({ core: this });
|
|
1367
1423
|
this.dr = new StageDragResize({ core: this, container: this.mask.content, mask: this.mask });
|
|
@@ -1388,6 +1444,8 @@
|
|
|
1388
1444
|
const el = await this.getElementFromPoint(event);
|
|
1389
1445
|
if (!el)
|
|
1390
1446
|
return;
|
|
1447
|
+
if (this.multiDr.dragStatus === StageDragStatus.ING)
|
|
1448
|
+
return;
|
|
1391
1449
|
await this.highlight(el);
|
|
1392
1450
|
if (this.highlightedDom === this.selectedDom) {
|
|
1393
1451
|
this.highlightLayer.clearHighlight();
|
|
@@ -1419,6 +1477,10 @@
|
|
|
1419
1477
|
});
|
|
1420
1478
|
this.multiDr.on("update", (data) => {
|
|
1421
1479
|
setTimeout(() => this.emit("update", data));
|
|
1480
|
+
}).on("select", async (id) => {
|
|
1481
|
+
const el = await this.getTargetElement(id);
|
|
1482
|
+
this.select(el);
|
|
1483
|
+
setTimeout(() => this.emit("select", el));
|
|
1422
1484
|
});
|
|
1423
1485
|
}
|
|
1424
1486
|
getElementsFromPoint(event) {
|
|
@@ -1582,6 +1644,7 @@
|
|
|
1582
1644
|
}
|
|
1583
1645
|
|
|
1584
1646
|
exports.CONTAINER_HIGHLIGHT_CLASS = CONTAINER_HIGHLIGHT_CLASS;
|
|
1647
|
+
exports.ContainerHighlightType = ContainerHighlightType;
|
|
1585
1648
|
exports.DEFAULT_ZOOM = DEFAULT_ZOOM;
|
|
1586
1649
|
exports.DRAG_EL_ID_PREFIX = DRAG_EL_ID_PREFIX;
|
|
1587
1650
|
exports.GHOST_EL_ID_PREFIX = GHOST_EL_ID_PREFIX;
|
|
@@ -1592,6 +1655,7 @@
|
|
|
1592
1655
|
exports.PAGE_CLASS = PAGE_CLASS;
|
|
1593
1656
|
exports.SELECTED_CLASS = SELECTED_CLASS;
|
|
1594
1657
|
exports.StageDragResize = StageDragResize;
|
|
1658
|
+
exports.StageDragStatus = StageDragStatus;
|
|
1595
1659
|
exports.StageMask = StageMask;
|
|
1596
1660
|
exports.StageRender = StageRender;
|
|
1597
1661
|
exports.ZIndex = ZIndex;
|