@tmagic/editor 1.0.6 → 1.1.0-beta.2
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-editor.es.js +188 -58
- package/dist/tmagic-editor.es.js.map +1 -1
- package/dist/tmagic-editor.umd.js +220 -89
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/dist/types/src/Editor.vue.d.ts +28 -1
- package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +2 -0
- package/dist/types/src/services/editor.d.ts +6 -0
- package/dist/types/src/type.d.ts +3 -0
- package/dist/types/src/utils/editor.d.ts +8 -4
- package/package.json +8 -8
- package/src/Editor.vue +19 -1
- package/src/components/Icon.vue +1 -1
- package/src/components/ToolButton.vue +1 -1
- package/src/fields/UISelect.vue +1 -1
- package/src/layouts/AddPageBox.vue +1 -1
- package/src/layouts/sidebar/ComponentListPanel.vue +53 -1
- package/src/layouts/sidebar/LayerMenu.vue +1 -1
- package/src/layouts/sidebar/TabPane.vue +1 -1
- package/src/layouts/workspace/PageBar.vue +1 -1
- package/src/layouts/workspace/Stage.vue +52 -11
- package/src/layouts/workspace/ViewerMenu.vue +1 -1
- package/src/services/editor.ts +74 -17
- package/src/type.ts +3 -0
- package/src/utils/editor.ts +45 -35
package/src/utils/editor.ts
CHANGED
|
@@ -81,21 +81,17 @@ export const getNodeIndex = (node: MNode, parent: MContainer | MApp): number =>
|
|
|
81
81
|
return items.findIndex((item: MNode) => `${item.id}` === `${node.id}`);
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
export const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const setTop2Middle = (node: MNode, parentNode: MNode, stage: StageCore) => {
|
|
95
|
-
const style = node.style || {};
|
|
84
|
+
export const getRelativeStyle = (style: Record<string, any> = {}): Record<string, any> => ({
|
|
85
|
+
...style,
|
|
86
|
+
position: 'relative',
|
|
87
|
+
top: 0,
|
|
88
|
+
left: 0,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const getMiddleTop = (style: Record<string, any> = {}, parentNode: MNode, stage: StageCore) => {
|
|
96
92
|
let height = style.height || 0;
|
|
97
93
|
|
|
98
|
-
if (!stage || typeof style.top !== 'undefined' || !parentNode.style) return style;
|
|
94
|
+
if (!stage || typeof style.top !== 'undefined' || !parentNode.style) return style.top;
|
|
99
95
|
|
|
100
96
|
if (!isNumber(height)) {
|
|
101
97
|
height = 0;
|
|
@@ -105,43 +101,45 @@ const setTop2Middle = (node: MNode, parentNode: MNode, stage: StageCore) => {
|
|
|
105
101
|
|
|
106
102
|
if (isPage(parentNode)) {
|
|
107
103
|
const { scrollTop = 0, wrapperHeight } = stage.mask;
|
|
108
|
-
|
|
109
|
-
} else {
|
|
110
|
-
style.top = (parentHeight - height) / 2;
|
|
104
|
+
return (wrapperHeight - height) / 2 + scrollTop;
|
|
111
105
|
}
|
|
112
|
-
|
|
113
|
-
return style;
|
|
106
|
+
return (parentHeight - height) / 2;
|
|
114
107
|
};
|
|
115
108
|
|
|
116
|
-
export const
|
|
109
|
+
export const getInitPositionStyle = (
|
|
110
|
+
style: Record<string, any> = {},
|
|
111
|
+
layout: Layout,
|
|
112
|
+
parentNode: MNode,
|
|
113
|
+
stage: StageCore,
|
|
114
|
+
) => {
|
|
117
115
|
if (layout === Layout.ABSOLUTE) {
|
|
118
|
-
|
|
116
|
+
return {
|
|
117
|
+
...style,
|
|
119
118
|
position: 'absolute',
|
|
120
|
-
|
|
119
|
+
top: getMiddleTop(style, parentNode, stage),
|
|
121
120
|
};
|
|
122
|
-
return node;
|
|
123
121
|
}
|
|
124
122
|
|
|
125
123
|
if (layout === Layout.RELATIVE) {
|
|
126
|
-
return
|
|
124
|
+
return getRelativeStyle(style);
|
|
127
125
|
}
|
|
128
126
|
|
|
129
|
-
return
|
|
127
|
+
return style;
|
|
130
128
|
};
|
|
131
129
|
|
|
132
130
|
export const setLayout = (node: MNode, layout: Layout) => {
|
|
133
131
|
node.items?.forEach((child: MNode) => {
|
|
134
132
|
if (isPop(child)) return;
|
|
135
133
|
|
|
136
|
-
|
|
134
|
+
const style = child.style || {};
|
|
137
135
|
|
|
138
136
|
// 是 fixed 不做处理
|
|
139
|
-
if (
|
|
137
|
+
if (style.position === 'fixed') return;
|
|
140
138
|
|
|
141
139
|
if (layout !== Layout.RELATIVE) {
|
|
142
|
-
|
|
140
|
+
style.position = 'absolute';
|
|
143
141
|
} else {
|
|
144
|
-
|
|
142
|
+
child.style = getRelativeStyle(style);
|
|
145
143
|
child.style.right = 'auto';
|
|
146
144
|
child.style.bottom = 'auto';
|
|
147
145
|
}
|
|
@@ -161,11 +159,10 @@ export const change2Fixed = (node: MNode, root: MApp) => {
|
|
|
161
159
|
offset.top = offset.top + globalThis.parseFloat(value.style?.top || 0);
|
|
162
160
|
});
|
|
163
161
|
|
|
164
|
-
|
|
162
|
+
return {
|
|
165
163
|
...(node.style || {}),
|
|
166
164
|
...offset,
|
|
167
165
|
};
|
|
168
|
-
return node;
|
|
169
166
|
};
|
|
170
167
|
|
|
171
168
|
export const Fixed2Other = async (
|
|
@@ -186,23 +183,23 @@ export const Fixed2Other = async (
|
|
|
186
183
|
offset.left = offset.left - globalThis.parseFloat(value.style?.left || 0);
|
|
187
184
|
offset.top = offset.top - globalThis.parseFloat(value.style?.top || 0);
|
|
188
185
|
});
|
|
186
|
+
const style = node.style || {};
|
|
189
187
|
|
|
190
188
|
const parent = path.pop();
|
|
191
189
|
if (!parent) {
|
|
192
|
-
return
|
|
190
|
+
return getRelativeStyle(style);
|
|
193
191
|
}
|
|
194
192
|
|
|
195
193
|
const layout = await getLayout(parent);
|
|
196
194
|
if (layout !== Layout.RELATIVE) {
|
|
197
|
-
|
|
198
|
-
...
|
|
195
|
+
return {
|
|
196
|
+
...style,
|
|
199
197
|
...offset,
|
|
200
198
|
position: 'absolute',
|
|
201
199
|
};
|
|
202
|
-
return node;
|
|
203
200
|
}
|
|
204
201
|
|
|
205
|
-
return
|
|
202
|
+
return getRelativeStyle(style);
|
|
206
203
|
};
|
|
207
204
|
|
|
208
205
|
export const getGuideLineFromCache = (key: string): number[] => {
|
|
@@ -219,3 +216,16 @@ export const getGuideLineFromCache = (key: string): number[] => {
|
|
|
219
216
|
|
|
220
217
|
return [];
|
|
221
218
|
};
|
|
219
|
+
|
|
220
|
+
export const fixNodeLeft = (config: MNode, parent: MContainer, doc?: Document) => {
|
|
221
|
+
if (!doc || !config.style || !isNumber(config.style.left)) return config.style?.left;
|
|
222
|
+
|
|
223
|
+
const el = doc.getElementById(`${config.id}`);
|
|
224
|
+
const parentEl = doc.getElementById(`${parent.id}`);
|
|
225
|
+
|
|
226
|
+
if (el && parentEl && el.offsetWidth + config.style?.left > parentEl.offsetWidth) {
|
|
227
|
+
return parentEl.offsetWidth - el.offsetWidth;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return config.style.left;
|
|
231
|
+
};
|