@tmagic/stage 1.0.0-rc.12 → 1.0.0-rc.13
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 +32 -61
- package/dist/tmagic-stage.es.js.map +1 -1
- package/dist/tmagic-stage.umd.js +40 -60
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/dist/types/src/Rule.d.ts +1 -0
- package/dist/types/src/const.d.ts +0 -2
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/util.d.ts +5 -6
- package/package.json +5 -5
- package/src/Rule.ts +22 -25
- package/src/StageDragResize.ts +8 -5
- package/src/const.ts +0 -3
- package/src/index.ts +1 -0
- package/src/util.ts +10 -42
package/src/Rule.ts
CHANGED
|
@@ -2,14 +2,13 @@ import EventEmitter from 'events';
|
|
|
2
2
|
|
|
3
3
|
import Guides, { GuidesEvents } from '@scena/guides';
|
|
4
4
|
|
|
5
|
-
import { GuidesType
|
|
6
|
-
import { getGuideLineFromCache } from './util';
|
|
5
|
+
import { GuidesType } from './const';
|
|
7
6
|
|
|
8
7
|
export default class Rule extends EventEmitter {
|
|
9
8
|
public hGuides: Guides;
|
|
10
9
|
public vGuides: Guides;
|
|
11
|
-
public horizontalGuidelines: number[] =
|
|
12
|
-
public verticalGuidelines: number[] =
|
|
10
|
+
public horizontalGuidelines: number[] = [];
|
|
11
|
+
public verticalGuidelines: number[] = [];
|
|
13
12
|
|
|
14
13
|
private container: HTMLDivElement;
|
|
15
14
|
private containerResizeObserver: ResizeObserver;
|
|
@@ -28,6 +27,7 @@ export default class Rule extends EventEmitter {
|
|
|
28
27
|
this.vGuides.resize();
|
|
29
28
|
this.hGuides.resize();
|
|
30
29
|
});
|
|
30
|
+
|
|
31
31
|
this.containerResizeObserver.observe(this.container);
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -45,33 +45,34 @@ export default class Rule extends EventEmitter {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
public clearGuides() {
|
|
52
|
-
this.horizontalGuidelines = [];
|
|
53
|
-
this.verticalGuidelines = [];
|
|
48
|
+
public setGuides([hLines, vLines]: [number[], number[]]) {
|
|
49
|
+
this.horizontalGuidelines = hLines;
|
|
50
|
+
this.verticalGuidelines = vLines;
|
|
54
51
|
|
|
55
|
-
this.
|
|
56
|
-
defaultGuides:
|
|
52
|
+
this.hGuides.setState({
|
|
53
|
+
defaultGuides: hLines,
|
|
57
54
|
});
|
|
58
55
|
|
|
59
|
-
this.
|
|
60
|
-
defaultGuides:
|
|
56
|
+
this.vGuides.setState({
|
|
57
|
+
defaultGuides: vLines,
|
|
61
58
|
});
|
|
62
59
|
|
|
63
60
|
this.emit('changeGuides', {
|
|
64
|
-
type: GuidesType.
|
|
65
|
-
guides:
|
|
61
|
+
type: GuidesType.HORIZONTAL,
|
|
62
|
+
guides: hLines,
|
|
66
63
|
});
|
|
67
64
|
|
|
68
65
|
this.emit('changeGuides', {
|
|
69
|
-
type: GuidesType.
|
|
70
|
-
guides:
|
|
66
|
+
type: GuidesType.VERTICAL,
|
|
67
|
+
guides: vLines,
|
|
71
68
|
});
|
|
69
|
+
}
|
|
72
70
|
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
/**
|
|
72
|
+
* 清空所有参考线
|
|
73
|
+
*/
|
|
74
|
+
public clearGuides() {
|
|
75
|
+
this.setGuides([[], []]);
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
/**
|
|
@@ -101,7 +102,7 @@ export default class Rule extends EventEmitter {
|
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
scrollRule(scrollTop: number) {
|
|
105
|
+
public scrollRule(scrollTop: number) {
|
|
105
106
|
this.hGuides.scrollGuides(scrollTop);
|
|
106
107
|
this.hGuides.scroll(0);
|
|
107
108
|
|
|
@@ -142,8 +143,6 @@ export default class Rule extends EventEmitter {
|
|
|
142
143
|
type: GuidesType.HORIZONTAL,
|
|
143
144
|
guides: this.horizontalGuidelines,
|
|
144
145
|
});
|
|
145
|
-
|
|
146
|
-
globalThis.localStorage.setItem(H_GUIDE_LINE_STORAGE_KEY, JSON.stringify(e.guides));
|
|
147
146
|
};
|
|
148
147
|
|
|
149
148
|
private vGuidesChangeGuidesHandler = (e: GuidesEvents['changeGuides']) => {
|
|
@@ -152,7 +151,5 @@ export default class Rule extends EventEmitter {
|
|
|
152
151
|
type: GuidesType.VERTICAL,
|
|
153
152
|
guides: this.verticalGuidelines,
|
|
154
153
|
});
|
|
155
|
-
|
|
156
|
-
globalThis.localStorage.setItem(V_GUIDE_LINE_STORAGE_KEY, JSON.stringify(e.guides));
|
|
157
154
|
};
|
|
158
155
|
}
|
package/src/StageDragResize.ts
CHANGED
|
@@ -26,7 +26,7 @@ import MoveableHelper from 'moveable-helper';
|
|
|
26
26
|
import { DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, Mode, ZIndex } from './const';
|
|
27
27
|
import StageCore from './StageCore';
|
|
28
28
|
import type { SortEventData, StageDragResizeConfig } from './types';
|
|
29
|
-
import { getAbsolutePosition,
|
|
29
|
+
import { getAbsolutePosition, getMode, getOffset } from './util';
|
|
30
30
|
|
|
31
31
|
/** 拖动状态 */
|
|
32
32
|
enum ActionStatus {
|
|
@@ -52,9 +52,9 @@ export default class StageDragResize extends EventEmitter {
|
|
|
52
52
|
/** Moveable拖拽类实例 */
|
|
53
53
|
public moveable?: Moveable;
|
|
54
54
|
/** 水平参考线 */
|
|
55
|
-
public horizontalGuidelines: number[] =
|
|
55
|
+
public horizontalGuidelines: number[] = [];
|
|
56
56
|
/** 垂直参考线 */
|
|
57
|
-
public verticalGuidelines: number[] =
|
|
57
|
+
public verticalGuidelines: number[] = [];
|
|
58
58
|
/** 对齐元素集合 */
|
|
59
59
|
public elementGuidelines: HTMLElement[] = [];
|
|
60
60
|
/** 布局方式:流式布局、绝对定位、固定定位 */
|
|
@@ -132,7 +132,9 @@ export default class StageDragResize extends EventEmitter {
|
|
|
132
132
|
this.moveableOptions.verticalGuidelines = guidelines;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
this.
|
|
135
|
+
if (this.moveable) {
|
|
136
|
+
this.updateMoveable();
|
|
137
|
+
}
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
public clearGuides() {
|
|
@@ -499,7 +501,8 @@ export default class StageDragResize extends EventEmitter {
|
|
|
499
501
|
|
|
500
502
|
bounds: {
|
|
501
503
|
top: 0,
|
|
502
|
-
|
|
504
|
+
// 设置0的话无法移动到left为0,所以只能设置为-1
|
|
505
|
+
left: -1,
|
|
503
506
|
right: this.container.clientWidth,
|
|
504
507
|
bottom: this.container.clientHeight,
|
|
505
508
|
...(moveableOptions.bounds || {}),
|
package/src/const.ts
CHANGED
|
@@ -68,6 +68,3 @@ export enum Mode {
|
|
|
68
68
|
|
|
69
69
|
/** 选中节点的class name */
|
|
70
70
|
export const SELECTED_CLASS = 'tmagic-stage-selected-area';
|
|
71
|
-
|
|
72
|
-
export const H_GUIDE_LINE_STORAGE_KEY = '$MagicStageHorizontalGuidelinesData';
|
|
73
|
-
export const V_GUIDE_LINE_STORAGE_KEY = '$MagicStageVerticalGuidelinesData';
|
package/src/index.ts
CHANGED
package/src/util.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import {
|
|
19
|
+
import { Mode, SELECTED_CLASS } from './const';
|
|
20
20
|
import type { Offset } from './types';
|
|
21
21
|
|
|
22
22
|
const getParents = (el: Element, relative: Element) => {
|
|
@@ -73,31 +73,19 @@ export const isSameDomain = (targetUrl = '', source = globalThis.location.host)
|
|
|
73
73
|
return getHost(targetUrl) === source;
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
export const isAbsolute = (
|
|
77
|
-
if (!el) return false;
|
|
78
|
-
return getComputedStyle(el).position === 'absolute';
|
|
79
|
-
};
|
|
76
|
+
export const isAbsolute = (style: CSSStyleDeclaration): boolean => style.position === 'absolute';
|
|
80
77
|
|
|
81
|
-
export const isRelative = (
|
|
82
|
-
if (!el) return false;
|
|
83
|
-
return getComputedStyle(el).position === 'relative';
|
|
84
|
-
};
|
|
78
|
+
export const isRelative = (style: CSSStyleDeclaration): boolean => style.position === 'relative';
|
|
85
79
|
|
|
86
|
-
export const isStatic = (
|
|
87
|
-
if (!el) return false;
|
|
88
|
-
return getComputedStyle(el).position === 'static';
|
|
89
|
-
};
|
|
80
|
+
export const isStatic = (style: CSSStyleDeclaration): boolean => style.position === 'static';
|
|
90
81
|
|
|
91
|
-
export const isFixed = (
|
|
92
|
-
if (!el) return false;
|
|
93
|
-
return getComputedStyle(el).position === 'fixed';
|
|
94
|
-
};
|
|
82
|
+
export const isFixed = (style: CSSStyleDeclaration): boolean => style.position === 'fixed';
|
|
95
83
|
|
|
96
84
|
export const isFixedParent = (el: HTMLElement) => {
|
|
97
85
|
let fixed = false;
|
|
98
86
|
let dom = el;
|
|
99
87
|
while (dom) {
|
|
100
|
-
fixed = isFixed(dom);
|
|
88
|
+
fixed = isFixed(getComputedStyle(dom));
|
|
101
89
|
if (fixed) {
|
|
102
90
|
break;
|
|
103
91
|
}
|
|
@@ -112,22 +100,22 @@ export const isFixedParent = (el: HTMLElement) => {
|
|
|
112
100
|
|
|
113
101
|
export const getMode = (el: HTMLElement): Mode => {
|
|
114
102
|
if (isFixedParent(el)) return Mode.FIXED;
|
|
115
|
-
|
|
103
|
+
const style = getComputedStyle(el);
|
|
104
|
+
if (isStatic(style) || isRelative(style)) return Mode.SORTABLE;
|
|
116
105
|
return Mode.ABSOLUTE;
|
|
117
106
|
};
|
|
118
107
|
|
|
119
108
|
export const getScrollParent = (element: HTMLElement, includeHidden = false): HTMLElement | null => {
|
|
120
109
|
let style = getComputedStyle(element);
|
|
121
|
-
const excludeStaticParent = style.position === 'absolute';
|
|
122
110
|
const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/;
|
|
123
111
|
|
|
124
|
-
if (style
|
|
112
|
+
if (isFixed(style)) return null;
|
|
125
113
|
|
|
126
114
|
for (let parent = element; parent.parentElement; ) {
|
|
127
115
|
parent = parent.parentElement;
|
|
128
116
|
style = getComputedStyle(parent);
|
|
129
117
|
|
|
130
|
-
if (
|
|
118
|
+
if (isAbsolute(style) && isStatic(style)) continue;
|
|
131
119
|
|
|
132
120
|
if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) return parent;
|
|
133
121
|
}
|
|
@@ -161,23 +149,3 @@ export const addSelectedClassName = (el: Element, doc: Document) => {
|
|
|
161
149
|
item.classList.add(`${SELECTED_CLASS}-parents`);
|
|
162
150
|
});
|
|
163
151
|
};
|
|
164
|
-
|
|
165
|
-
export const getGuideLineFromCache = (type: GuidesType): number[] => {
|
|
166
|
-
const key = {
|
|
167
|
-
[GuidesType.HORIZONTAL]: H_GUIDE_LINE_STORAGE_KEY,
|
|
168
|
-
[GuidesType.VERTICAL]: V_GUIDE_LINE_STORAGE_KEY,
|
|
169
|
-
}[type];
|
|
170
|
-
|
|
171
|
-
if (!key) return [];
|
|
172
|
-
|
|
173
|
-
const guideLineCacheData = globalThis.localStorage.getItem(key);
|
|
174
|
-
if (guideLineCacheData) {
|
|
175
|
-
try {
|
|
176
|
-
return JSON.parse(guideLineCacheData) || [];
|
|
177
|
-
} catch (e) {
|
|
178
|
-
console.error(e);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return [];
|
|
183
|
-
};
|