@tmagic/stage 1.2.7 → 1.2.8
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.js +65 -51
- package/dist/tmagic-stage.js.map +1 -1
- package/dist/tmagic-stage.umd.cjs +69 -55
- package/dist/tmagic-stage.umd.cjs.map +1 -1
- package/package.json +6 -6
- package/src/ActionManager.ts +23 -16
- package/src/DragResizeHelper.ts +40 -2
- package/src/StageCore.ts +7 -4
- package/src/StageDragResize.ts +4 -34
- package/src/StageMultiDragResize.ts +28 -14
- package/src/types.ts +5 -2
- package/types/ActionManager.d.ts +1 -1
- package/types/DragResizeHelper.d.ts +2 -1
- package/types/StageCore.d.ts +2 -2
- package/types/StageMultiDragResize.d.ts +2 -0
- package/types/types.d.ts +5 -2
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('events'), require('keycon'), require('lodash-es'), require('@tmagic/core'), require('@tmagic/utils'), require('moveable'), require('moveable
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'events', 'keycon', 'lodash-es', '@tmagic/core', '@tmagic/utils', 'moveable', 'moveable
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicStage = {}, global.EventEmitter, global.KeyController, global.lodashEs, global.core, global.utils, global.
|
|
5
|
-
})(this, (function (exports, EventEmitter, KeyController, lodashEs, core, utils,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('events'), require('keycon'), require('lodash-es'), require('@tmagic/core'), require('@tmagic/utils'), require('moveable-helper'), require('moveable'), require('@scena/guides')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'events', 'keycon', 'lodash-es', '@tmagic/core', '@tmagic/utils', 'moveable-helper', 'moveable', '@scena/guides'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicStage = {}, global.EventEmitter, global.KeyController, global.lodashEs, global.core, global.utils, global.MoveableHelper, global.Moveable, global.Guides));
|
|
5
|
+
})(this, (function (exports, EventEmitter, KeyController, lodashEs, core, utils, MoveableHelper, Moveable, 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
10
|
const KeyController__default = /*#__PURE__*/_interopDefaultLegacy(KeyController);
|
|
11
|
-
const Moveable__default = /*#__PURE__*/_interopDefaultLegacy(Moveable);
|
|
12
11
|
const MoveableHelper__default = /*#__PURE__*/_interopDefaultLegacy(MoveableHelper);
|
|
12
|
+
const Moveable__default = /*#__PURE__*/_interopDefaultLegacy(Moveable);
|
|
13
13
|
const Guides__default = /*#__PURE__*/_interopDefaultLegacy(Guides);
|
|
14
14
|
|
|
15
15
|
const GHOST_EL_ID_PREFIX = "ghost_el_";
|
|
@@ -475,6 +475,29 @@
|
|
|
475
475
|
});
|
|
476
476
|
this.moveableHelper.onDragGroup(e);
|
|
477
477
|
}
|
|
478
|
+
getUpdatedElRect(el, parentEl, doc) {
|
|
479
|
+
const offset = this.mode === Mode.SORTABLE ? { left: 0, top: 0 } : { left: el.offsetLeft, top: el.offsetTop };
|
|
480
|
+
let left = calcValueByFontsize(doc, offset.left);
|
|
481
|
+
let top = calcValueByFontsize(doc, offset.top);
|
|
482
|
+
const width = calcValueByFontsize(doc, el.clientWidth);
|
|
483
|
+
const height = calcValueByFontsize(doc, el.clientHeight);
|
|
484
|
+
let shadowEl = this.getShadowEl();
|
|
485
|
+
const shadowEls = this.getShadowEls();
|
|
486
|
+
if (shadowEls.length) {
|
|
487
|
+
shadowEl = shadowEls.find((item) => item.id.endsWith(el.id));
|
|
488
|
+
}
|
|
489
|
+
if (parentEl && this.mode === Mode.ABSOLUTE && shadowEl) {
|
|
490
|
+
const targetShadowHtmlEl = shadowEl;
|
|
491
|
+
const targetShadowElOffsetLeft = targetShadowHtmlEl.offsetLeft || 0;
|
|
492
|
+
const targetShadowElOffsetTop = targetShadowHtmlEl.offsetTop || 0;
|
|
493
|
+
const frame = this.getFrame(shadowEl);
|
|
494
|
+
const [translateX, translateY] = frame?.properties.transform.translate.value;
|
|
495
|
+
const { left: parentLeft, top: parentTop } = getOffset(parentEl);
|
|
496
|
+
left = calcValueByFontsize(doc, targetShadowElOffsetLeft) + parseFloat(translateX) - calcValueByFontsize(doc, parentLeft);
|
|
497
|
+
top = calcValueByFontsize(doc, targetShadowElOffsetTop) + parseFloat(translateY) - calcValueByFontsize(doc, parentTop);
|
|
498
|
+
}
|
|
499
|
+
return { width, height, left, top };
|
|
500
|
+
}
|
|
478
501
|
setFramesSnapShot(events) {
|
|
479
502
|
if (this.framesSnapShot.length > 0)
|
|
480
503
|
return;
|
|
@@ -796,10 +819,7 @@
|
|
|
796
819
|
this.markContainerEnd = config.markContainerEnd;
|
|
797
820
|
this.delayedMarkContainer = config.delayedMarkContainer;
|
|
798
821
|
this.disabledDragStart = config.disabledDragStart;
|
|
799
|
-
this.dragResizeHelper =
|
|
800
|
-
container: config.container,
|
|
801
|
-
updateDragEl: config.updateDragEl
|
|
802
|
-
});
|
|
822
|
+
this.dragResizeHelper = config.dragResizeHelper;
|
|
803
823
|
this.on("update-moveable", () => {
|
|
804
824
|
if (this.moveable) {
|
|
805
825
|
this.updateMoveable();
|
|
@@ -1006,27 +1026,12 @@
|
|
|
1006
1026
|
const doc = this.getRenderDocument();
|
|
1007
1027
|
if (!doc)
|
|
1008
1028
|
return;
|
|
1009
|
-
const
|
|
1010
|
-
let left = calcValueByFontsize(doc, offset.left);
|
|
1011
|
-
let top = calcValueByFontsize(doc, offset.top);
|
|
1012
|
-
const width = calcValueByFontsize(doc, this.target.clientWidth);
|
|
1013
|
-
const height = calcValueByFontsize(doc, this.target.clientHeight);
|
|
1014
|
-
const shadowEl = this.dragResizeHelper.getShadowEl();
|
|
1015
|
-
if (parentEl && this.mode === Mode.ABSOLUTE && shadowEl) {
|
|
1016
|
-
const targetShadowHtmlEl = shadowEl;
|
|
1017
|
-
const targetShadowElOffsetLeft = targetShadowHtmlEl.offsetLeft || 0;
|
|
1018
|
-
const targetShadowElOffsetTop = targetShadowHtmlEl.offsetTop || 0;
|
|
1019
|
-
const frame = this.dragResizeHelper.getFrame(shadowEl);
|
|
1020
|
-
const [translateX, translateY] = frame?.properties.transform.translate.value;
|
|
1021
|
-
const { left: parentLeft, top: parentTop } = getOffset(parentEl);
|
|
1022
|
-
left = calcValueByFontsize(doc, targetShadowElOffsetLeft) + parseFloat(translateX) - calcValueByFontsize(doc, parentLeft);
|
|
1023
|
-
top = calcValueByFontsize(doc, targetShadowElOffsetTop) + parseFloat(translateY) - calcValueByFontsize(doc, parentTop);
|
|
1024
|
-
}
|
|
1029
|
+
const rect = this.dragResizeHelper.getUpdatedElRect(this.target, parentEl, doc);
|
|
1025
1030
|
this.emit("update", {
|
|
1026
1031
|
data: [
|
|
1027
1032
|
{
|
|
1028
1033
|
el: this.target,
|
|
1029
|
-
style: isResize ?
|
|
1034
|
+
style: isResize ? rect : { left: rect.left, top: rect.top }
|
|
1030
1035
|
}
|
|
1031
1036
|
],
|
|
1032
1037
|
parentEl
|
|
@@ -1083,6 +1088,8 @@
|
|
|
1083
1088
|
dragStatus = StageDragStatus.END;
|
|
1084
1089
|
dragResizeHelper;
|
|
1085
1090
|
getRenderDocument;
|
|
1091
|
+
delayedMarkContainer;
|
|
1092
|
+
markContainerEnd;
|
|
1086
1093
|
constructor(config) {
|
|
1087
1094
|
const moveableOptionsManagerConfig = {
|
|
1088
1095
|
container: config.container,
|
|
@@ -1090,12 +1097,11 @@
|
|
|
1090
1097
|
getRootContainer: config.getRootContainer
|
|
1091
1098
|
};
|
|
1092
1099
|
super(moveableOptionsManagerConfig);
|
|
1100
|
+
this.delayedMarkContainer = config.delayedMarkContainer;
|
|
1101
|
+
this.markContainerEnd = config.markContainerEnd;
|
|
1093
1102
|
this.container = config.container;
|
|
1094
1103
|
this.getRenderDocument = config.getRenderDocument;
|
|
1095
|
-
this.dragResizeHelper =
|
|
1096
|
-
container: config.container,
|
|
1097
|
-
updateDragEl: config.updateDragEl
|
|
1098
|
-
});
|
|
1104
|
+
this.dragResizeHelper = config.dragResizeHelper;
|
|
1099
1105
|
this.on("update-moveable", () => {
|
|
1100
1106
|
if (this.moveableForMulti) {
|
|
1101
1107
|
this.updateMoveable();
|
|
@@ -1119,6 +1125,7 @@
|
|
|
1119
1125
|
target: this.dragResizeHelper.getShadowEls()
|
|
1120
1126
|
})
|
|
1121
1127
|
);
|
|
1128
|
+
let timeout;
|
|
1122
1129
|
this.moveableForMulti.on("resizeGroupStart", (e) => {
|
|
1123
1130
|
this.dragResizeHelper.onResizeGroupStart(e);
|
|
1124
1131
|
this.dragStatus = StageDragStatus.START;
|
|
@@ -1132,10 +1139,16 @@
|
|
|
1132
1139
|
this.dragResizeHelper.onDragGroupStart(e);
|
|
1133
1140
|
this.dragStatus = StageDragStatus.START;
|
|
1134
1141
|
}).on("dragGroup", (e) => {
|
|
1142
|
+
if (timeout) {
|
|
1143
|
+
globalThis.clearTimeout(timeout);
|
|
1144
|
+
timeout = void 0;
|
|
1145
|
+
}
|
|
1146
|
+
timeout = this.delayedMarkContainer(e.inputEvent, this.targetList);
|
|
1135
1147
|
this.dragResizeHelper.onDragGroup(e);
|
|
1136
1148
|
this.dragStatus = StageDragStatus.ING;
|
|
1137
1149
|
}).on("dragGroupEnd", () => {
|
|
1138
|
-
this.
|
|
1150
|
+
const parentEl = this.markContainerEnd();
|
|
1151
|
+
this.update(false, parentEl);
|
|
1139
1152
|
this.dragStatus = StageDragStatus.END;
|
|
1140
1153
|
}).on("clickGroup", (e) => {
|
|
1141
1154
|
const { inputTarget, targets } = e;
|
|
@@ -1187,23 +1200,20 @@
|
|
|
1187
1200
|
this.moveableForMulti?.destroy();
|
|
1188
1201
|
this.dragResizeHelper.destroy();
|
|
1189
1202
|
}
|
|
1190
|
-
update(isResize = false) {
|
|
1203
|
+
update(isResize = false, parentEl = null) {
|
|
1191
1204
|
if (this.targetList.length === 0)
|
|
1192
1205
|
return;
|
|
1193
1206
|
const doc = this.getRenderDocument();
|
|
1194
1207
|
if (!doc)
|
|
1195
1208
|
return;
|
|
1196
1209
|
const data = this.targetList.map((targetItem) => {
|
|
1197
|
-
const
|
|
1198
|
-
const top = calcValueByFontsize(doc, targetItem.offsetTop);
|
|
1199
|
-
const width = calcValueByFontsize(doc, targetItem.clientWidth);
|
|
1200
|
-
const height = calcValueByFontsize(doc, targetItem.clientHeight);
|
|
1210
|
+
const rect = this.dragResizeHelper.getUpdatedElRect(targetItem, parentEl, doc);
|
|
1201
1211
|
return {
|
|
1202
1212
|
el: targetItem,
|
|
1203
|
-
style: isResize ?
|
|
1213
|
+
style: isResize ? rect : { left: rect.left, top: rect.top }
|
|
1204
1214
|
};
|
|
1205
1215
|
});
|
|
1206
|
-
this.emit("update", data,
|
|
1216
|
+
this.emit("update", { data, parentEl });
|
|
1207
1217
|
}
|
|
1208
1218
|
}
|
|
1209
1219
|
|
|
@@ -1246,27 +1256,28 @@
|
|
|
1246
1256
|
this.canSelect = config.canSelect || ((el) => !!el.id);
|
|
1247
1257
|
this.getRenderDocument = config.getRenderDocument;
|
|
1248
1258
|
this.isContainer = config.isContainer;
|
|
1259
|
+
const createDrHelper = () => new DragResizeHelper({
|
|
1260
|
+
container: config.container,
|
|
1261
|
+
updateDragEl: config.updateDragEl
|
|
1262
|
+
});
|
|
1249
1263
|
this.dr = new StageDragResize({
|
|
1250
1264
|
container: config.container,
|
|
1251
1265
|
disabledDragStart: config.disabledDragStart,
|
|
1266
|
+
moveableOptions: this.changeCallback(config.moveableOptions),
|
|
1267
|
+
dragResizeHelper: createDrHelper(),
|
|
1252
1268
|
getRootContainer: config.getRootContainer,
|
|
1253
1269
|
getRenderDocument: config.getRenderDocument,
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
delayedMarkContainer: (event, exclude) => {
|
|
1257
|
-
if (this.canAddToContainer()) {
|
|
1258
|
-
return this.delayedMarkContainer(event, exclude);
|
|
1259
|
-
}
|
|
1260
|
-
return void 0;
|
|
1261
|
-
},
|
|
1262
|
-
moveableOptions: this.changeCallback(config.moveableOptions)
|
|
1270
|
+
markContainerEnd: this.markContainerEnd.bind(this),
|
|
1271
|
+
delayedMarkContainer: this.delayedMarkContainer.bind(this)
|
|
1263
1272
|
});
|
|
1264
1273
|
this.multiDr = new StageMultiDragResize({
|
|
1265
1274
|
container: config.container,
|
|
1266
1275
|
multiMoveableOptions: config.multiMoveableOptions,
|
|
1276
|
+
dragResizeHelper: createDrHelper(),
|
|
1267
1277
|
getRootContainer: config.getRootContainer,
|
|
1268
1278
|
getRenderDocument: config.getRenderDocument,
|
|
1269
|
-
|
|
1279
|
+
markContainerEnd: this.markContainerEnd.bind(this),
|
|
1280
|
+
delayedMarkContainer: this.delayedMarkContainer.bind(this)
|
|
1270
1281
|
});
|
|
1271
1282
|
this.highlightLayer = new StageHighlight({
|
|
1272
1283
|
container: config.container,
|
|
@@ -1392,9 +1403,12 @@
|
|
|
1392
1403
|
}
|
|
1393
1404
|
}
|
|
1394
1405
|
delayedMarkContainer(event, excludeElList = []) {
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1406
|
+
if (this.canAddToContainer()) {
|
|
1407
|
+
return globalThis.setTimeout(() => {
|
|
1408
|
+
this.addContainerHighlightClassName(event, excludeElList);
|
|
1409
|
+
}, this.containerHighlightDuration);
|
|
1410
|
+
}
|
|
1411
|
+
return void 0;
|
|
1398
1412
|
}
|
|
1399
1413
|
destroy() {
|
|
1400
1414
|
this.container.removeEventListener("mousedown", this.mouseDownHandler);
|
|
@@ -1490,8 +1504,8 @@
|
|
|
1490
1504
|
};
|
|
1491
1505
|
this.emit("remove", data);
|
|
1492
1506
|
});
|
|
1493
|
-
this.multiDr.on("update", (data
|
|
1494
|
-
this.emit("multi-update", data
|
|
1507
|
+
this.multiDr.on("update", (data) => {
|
|
1508
|
+
this.emit("multi-update", data);
|
|
1495
1509
|
}).on("change-to-select", async (id) => {
|
|
1496
1510
|
if (this.isMultiSelectStatus)
|
|
1497
1511
|
return false;
|
|
@@ -2200,8 +2214,8 @@
|
|
|
2200
2214
|
this.actionManager.on("change-to-select", (el) => {
|
|
2201
2215
|
this.select(el);
|
|
2202
2216
|
setTimeout(() => this.emit("select", el));
|
|
2203
|
-
}).on("multi-update", (data
|
|
2204
|
-
this.emit("update",
|
|
2217
|
+
}).on("multi-update", (data) => {
|
|
2218
|
+
this.emit("update", data);
|
|
2205
2219
|
});
|
|
2206
2220
|
}
|
|
2207
2221
|
initHighlightEvent() {
|