@tmagic/stage 1.0.0-rc.3 → 1.0.0-rc.4
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.es.js +57 -19
- package/dist/tmagic-stage.es.js.map +1 -1
- package/dist/tmagic-stage.umd.js +57 -19
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/dist/types/src/StageDragResize.d.ts +11 -1
- package/dist/types/src/const.d.ts +21 -0
- package/dist/types/src/types.d.ts +2 -0
- package/dist/types/src/util.d.ts +2 -1
- package/package.json +5 -4
- package/src/Rule.ts +13 -5
- package/src/StageDragResize.ts +45 -17
- package/src/StageMask.ts +7 -6
- package/src/const.ts +22 -2
- package/src/types.ts +2 -0
- package/src/util.ts +21 -1
package/dist/tmagic-stage.umd.js
CHANGED
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
return Mode2;
|
|
39
39
|
})(Mode || {});
|
|
40
40
|
const SELECTED_CLASS = "tmagic-stage-selected-area";
|
|
41
|
+
const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
|
|
42
|
+
const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
|
|
41
43
|
|
|
42
44
|
const getParents = (el, relative) => {
|
|
43
45
|
let cur = el.parentElement;
|
|
@@ -184,12 +186,29 @@
|
|
|
184
186
|
item.classList.add(`${SELECTED_CLASS}-parents`);
|
|
185
187
|
});
|
|
186
188
|
};
|
|
189
|
+
const getGuideLineFromCache = (type) => {
|
|
190
|
+
const key = {
|
|
191
|
+
[GuidesType.HORIZONTAL]: H_GUIDE_LINE_STORAGE_KEY,
|
|
192
|
+
[GuidesType.VERTICAL]: V_GUIDE_LINE_STORAGE_KEY
|
|
193
|
+
}[type];
|
|
194
|
+
if (!key)
|
|
195
|
+
return [];
|
|
196
|
+
const guideLineCacheData = globalThis.localStorage.getItem(key);
|
|
197
|
+
if (guideLineCacheData) {
|
|
198
|
+
try {
|
|
199
|
+
return JSON.parse(guideLineCacheData) || [];
|
|
200
|
+
} catch (e) {
|
|
201
|
+
console.error(e);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return [];
|
|
205
|
+
};
|
|
187
206
|
|
|
188
207
|
class StageDragResize extends EventEmitter.EventEmitter {
|
|
189
208
|
constructor(config) {
|
|
190
209
|
super();
|
|
191
|
-
this.horizontalGuidelines =
|
|
192
|
-
this.verticalGuidelines =
|
|
210
|
+
this.horizontalGuidelines = getGuideLineFromCache(GuidesType.HORIZONTAL);
|
|
211
|
+
this.verticalGuidelines = getGuideLineFromCache(GuidesType.VERTICAL);
|
|
193
212
|
this.elementGuidelines = [];
|
|
194
213
|
this.mode = Mode.ABSOLUTE;
|
|
195
214
|
this.moveableOptions = {};
|
|
@@ -260,10 +279,32 @@
|
|
|
260
279
|
this.mode = getMode(el);
|
|
261
280
|
this.destroyGhostEl();
|
|
262
281
|
this.updateDragEl(el);
|
|
282
|
+
this.setElementGuidelines(el);
|
|
263
283
|
this.moveableOptions = this.getOptions({
|
|
264
284
|
target: this.dragEl
|
|
265
285
|
});
|
|
266
286
|
}
|
|
287
|
+
setElementGuidelines(el) {
|
|
288
|
+
const nodes = el.parentElement?.children || [];
|
|
289
|
+
this.elementGuidelines.forEach((node) => {
|
|
290
|
+
node.remove();
|
|
291
|
+
});
|
|
292
|
+
this.elementGuidelines = [];
|
|
293
|
+
if (this.mode === Mode.ABSOLUTE) {
|
|
294
|
+
const frame = document.createDocumentFragment();
|
|
295
|
+
for (const node of nodes) {
|
|
296
|
+
const { width, height } = node.getBoundingClientRect();
|
|
297
|
+
if (node === el)
|
|
298
|
+
continue;
|
|
299
|
+
const { left, top } = getOffset(node);
|
|
300
|
+
const elementGuideline = document.createElement("div");
|
|
301
|
+
elementGuideline.style.cssText = `position: absolute;width: ${width}px;height: ${height}px;top: ${top}px;left: ${left}px`;
|
|
302
|
+
this.elementGuidelines.push(elementGuideline);
|
|
303
|
+
frame.append(elementGuideline);
|
|
304
|
+
}
|
|
305
|
+
this.container.append(frame);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
267
308
|
initMoveable() {
|
|
268
309
|
this.moveable?.destroy();
|
|
269
310
|
this.moveable = new Moveable__default["default"](this.container, {
|
|
@@ -348,14 +389,6 @@
|
|
|
348
389
|
this.destroyGhostEl();
|
|
349
390
|
});
|
|
350
391
|
}
|
|
351
|
-
getSnapElements(runtime, el) {
|
|
352
|
-
const { renderer, mask } = this.core;
|
|
353
|
-
const getSnapElements = runtime?.getSnapElements || (() => {
|
|
354
|
-
const doc = renderer.contentWindow?.document;
|
|
355
|
-
return doc ? Array.from(doc.querySelectorAll("[id]")) : [];
|
|
356
|
-
});
|
|
357
|
-
return getSnapElements(el).filter((element) => element !== this.target && !this.target?.contains(element) && element !== mask.page);
|
|
358
|
-
}
|
|
359
392
|
sort() {
|
|
360
393
|
if (!this.target || !this.ghostEl)
|
|
361
394
|
throw new Error("\u672A\u77E5\u9519\u8BEF");
|
|
@@ -650,8 +683,8 @@
|
|
|
650
683
|
class Rule extends EventEmitter__default["default"] {
|
|
651
684
|
constructor(container) {
|
|
652
685
|
super();
|
|
653
|
-
this.horizontalGuidelines =
|
|
654
|
-
this.verticalGuidelines =
|
|
686
|
+
this.horizontalGuidelines = getGuideLineFromCache(GuidesType.HORIZONTAL);
|
|
687
|
+
this.verticalGuidelines = getGuideLineFromCache(GuidesType.VERTICAL);
|
|
655
688
|
this.getGuidesStyle = (type) => ({
|
|
656
689
|
position: "fixed",
|
|
657
690
|
zIndex: 1,
|
|
@@ -675,6 +708,7 @@
|
|
|
675
708
|
type: GuidesType.HORIZONTAL,
|
|
676
709
|
guides: this.horizontalGuidelines
|
|
677
710
|
});
|
|
711
|
+
globalThis.localStorage.setItem(H_GUIDE_LINE_STORAGE_KEY, JSON.stringify(e.guides));
|
|
678
712
|
};
|
|
679
713
|
this.vGuidesChangeGuidesHandler = (e) => {
|
|
680
714
|
this.verticalGuidelines = e.guides;
|
|
@@ -682,10 +716,11 @@
|
|
|
682
716
|
type: GuidesType.VERTICAL,
|
|
683
717
|
guides: this.verticalGuidelines
|
|
684
718
|
});
|
|
719
|
+
globalThis.localStorage.setItem(V_GUIDE_LINE_STORAGE_KEY, JSON.stringify(e.guides));
|
|
685
720
|
};
|
|
686
721
|
this.container = container;
|
|
687
|
-
this.hGuides = this.createGuides(GuidesType.HORIZONTAL);
|
|
688
|
-
this.vGuides = this.createGuides(GuidesType.VERTICAL);
|
|
722
|
+
this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
|
|
723
|
+
this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
|
|
689
724
|
this.hGuides.on("changeGuides", this.hGuidesChangeGuidesHandler);
|
|
690
725
|
this.vGuides.on("changeGuides", this.vGuidesChangeGuidesHandler);
|
|
691
726
|
this.containerResizeObserver = new ResizeObserver(() => {
|
|
@@ -719,6 +754,8 @@
|
|
|
719
754
|
type: GuidesType.HORIZONTAL,
|
|
720
755
|
guides: []
|
|
721
756
|
});
|
|
757
|
+
globalThis.localStorage.setItem(V_GUIDE_LINE_STORAGE_KEY, "[]");
|
|
758
|
+
globalThis.localStorage.setItem(H_GUIDE_LINE_STORAGE_KEY, "[]");
|
|
722
759
|
}
|
|
723
760
|
showRule(show = true) {
|
|
724
761
|
if (show) {
|
|
@@ -842,7 +879,6 @@
|
|
|
842
879
|
if (this.maxScrollLeft > 0) {
|
|
843
880
|
this.scrollLeft = this.scrollLeft + deltaX;
|
|
844
881
|
}
|
|
845
|
-
this.fixScrollValue();
|
|
846
882
|
this.scroll();
|
|
847
883
|
this.emit("scroll", event);
|
|
848
884
|
};
|
|
@@ -897,9 +933,10 @@
|
|
|
897
933
|
const { clientHeight, clientWidth } = entry.target;
|
|
898
934
|
this.setHeight(clientHeight);
|
|
899
935
|
this.setWidth(clientWidth);
|
|
900
|
-
this.fixScrollValue();
|
|
901
936
|
this.scroll();
|
|
902
|
-
this.core.dr.
|
|
937
|
+
if (this.core.dr.moveable) {
|
|
938
|
+
this.core.dr.updateMoveable();
|
|
939
|
+
}
|
|
903
940
|
});
|
|
904
941
|
this.pageResizeObserver.observe(page);
|
|
905
942
|
this.wrapperResizeObserver = new ResizeObserver((entries) => {
|
|
@@ -939,6 +976,7 @@
|
|
|
939
976
|
super.destroy();
|
|
940
977
|
}
|
|
941
978
|
scroll() {
|
|
979
|
+
this.fixScrollValue();
|
|
942
980
|
let { scrollLeft, scrollTop } = this;
|
|
943
981
|
if (this.pageScrollParent) {
|
|
944
982
|
this.pageScrollParent.scrollTo({
|
|
@@ -967,10 +1005,10 @@
|
|
|
967
1005
|
this.content.style.width = `${width}px`;
|
|
968
1006
|
}
|
|
969
1007
|
setMaxScrollLeft() {
|
|
970
|
-
this.maxScrollLeft = this.width - this.wrapperWidth;
|
|
1008
|
+
this.maxScrollLeft = Math.max(this.width - this.wrapperWidth, 0);
|
|
971
1009
|
}
|
|
972
1010
|
setMaxScrollTop() {
|
|
973
|
-
this.maxScrollTop = this.height - this.wrapperHeight;
|
|
1011
|
+
this.maxScrollTop = Math.max(this.height - this.wrapperHeight, 0);
|
|
974
1012
|
}
|
|
975
1013
|
fixScrollValue() {
|
|
976
1014
|
if (this.scrollTop < 0)
|