@tmagic/editor 1.7.4 → 1.7.5-beta.1
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.js +53 -16
- package/dist/tmagic-editor.umd.cjs +53 -16
- package/package.json +5 -5
- package/src/utils/editor.ts +60 -15
- package/types/index.d.ts +1 -2
package/dist/tmagic-editor.js
CHANGED
|
@@ -1037,33 +1037,65 @@ const setLayout = (node, layout) => {
|
|
|
1037
1037
|
return node;
|
|
1038
1038
|
};
|
|
1039
1039
|
const change2Fixed = (node, root) => {
|
|
1040
|
+
const style = {
|
|
1041
|
+
...node.style || {}
|
|
1042
|
+
};
|
|
1040
1043
|
const path = getNodePath(node.id, root.items);
|
|
1041
1044
|
const offset = {
|
|
1042
1045
|
left: 0,
|
|
1043
1046
|
top: 0
|
|
1044
1047
|
};
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1048
|
+
if (!node.style?.right && isNumber(node.style?.left || 0)) {
|
|
1049
|
+
for (const value of path) {
|
|
1050
|
+
if (value.style?.right || !isNumber(value.style?.left || 0)) {
|
|
1051
|
+
offset.left = 0;
|
|
1052
|
+
break;
|
|
1053
|
+
}
|
|
1054
|
+
offset.left = offset.left + Number(value.style?.left || 0);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
if (!node.style?.bottom && isNumber(node.style?.top || 0)) {
|
|
1058
|
+
for (const value of path) {
|
|
1059
|
+
if (value.style?.bottom || !isNumber(value.style?.top || 0)) {
|
|
1060
|
+
offset.top = 0;
|
|
1061
|
+
break;
|
|
1062
|
+
}
|
|
1063
|
+
offset.top = offset.top + Number(value.style?.top || 0);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
if (offset.left) {
|
|
1067
|
+
style.left = offset.left;
|
|
1068
|
+
}
|
|
1069
|
+
if (offset.top) {
|
|
1070
|
+
style.top = offset.top;
|
|
1071
|
+
}
|
|
1072
|
+
return style;
|
|
1053
1073
|
};
|
|
1054
1074
|
const Fixed2Other = async (node, root, getLayout) => {
|
|
1055
1075
|
const path = getNodePath(node.id, root.items);
|
|
1056
1076
|
const cur = path.pop();
|
|
1057
1077
|
const offset = {
|
|
1058
1078
|
left: cur?.style?.left || 0,
|
|
1059
|
-
top: cur?.style?.top || 0
|
|
1060
|
-
right: "",
|
|
1061
|
-
bottom: ""
|
|
1079
|
+
top: cur?.style?.top || 0
|
|
1062
1080
|
};
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1081
|
+
if (!node.style?.right && isNumber(node.style?.left || 0)) {
|
|
1082
|
+
for (const value of path) {
|
|
1083
|
+
if (value.style?.right || !isNumber(value.style?.left || 0)) {
|
|
1084
|
+
offset.left = 0;
|
|
1085
|
+
break;
|
|
1086
|
+
}
|
|
1087
|
+
offset.left = offset.left - Number(value.style?.left || 0);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
if (!node.style?.bottom && isNumber(node.style?.top || 0)) {
|
|
1091
|
+
for (const value of path) {
|
|
1092
|
+
if (value.style?.bottom || !isNumber(value.style?.top || 0)) {
|
|
1093
|
+
offset.top = 0;
|
|
1094
|
+
break;
|
|
1095
|
+
}
|
|
1096
|
+
offset.top = offset.top - Number(value.style?.top || 0);
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1067
1099
|
const style = node.style || {};
|
|
1068
1100
|
const parent = path.pop();
|
|
1069
1101
|
if (!parent) {
|
|
@@ -1071,9 +1103,14 @@ const Fixed2Other = async (node, root, getLayout) => {
|
|
|
1071
1103
|
}
|
|
1072
1104
|
const layout = await getLayout(parent);
|
|
1073
1105
|
if (layout !== Layout.RELATIVE) {
|
|
1106
|
+
if (offset.left) {
|
|
1107
|
+
style.left = offset.left;
|
|
1108
|
+
}
|
|
1109
|
+
if (offset.top) {
|
|
1110
|
+
style.top = offset.top;
|
|
1111
|
+
}
|
|
1074
1112
|
return {
|
|
1075
1113
|
...style,
|
|
1076
|
-
...offset,
|
|
1077
1114
|
position: "absolute"
|
|
1078
1115
|
};
|
|
1079
1116
|
}
|
|
@@ -5830,33 +5830,65 @@
|
|
|
5830
5830
|
return node;
|
|
5831
5831
|
};
|
|
5832
5832
|
const change2Fixed = (node, root) => {
|
|
5833
|
+
const style = {
|
|
5834
|
+
...node.style || {}
|
|
5835
|
+
};
|
|
5833
5836
|
const path = utils.getNodePath(node.id, root.items);
|
|
5834
5837
|
const offset = {
|
|
5835
5838
|
left: 0,
|
|
5836
5839
|
top: 0
|
|
5837
5840
|
};
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5841
|
+
if (!node.style?.right && utils.isNumber(node.style?.left || 0)) {
|
|
5842
|
+
for (const value of path) {
|
|
5843
|
+
if (value.style?.right || !utils.isNumber(value.style?.left || 0)) {
|
|
5844
|
+
offset.left = 0;
|
|
5845
|
+
break;
|
|
5846
|
+
}
|
|
5847
|
+
offset.left = offset.left + Number(value.style?.left || 0);
|
|
5848
|
+
}
|
|
5849
|
+
}
|
|
5850
|
+
if (!node.style?.bottom && utils.isNumber(node.style?.top || 0)) {
|
|
5851
|
+
for (const value of path) {
|
|
5852
|
+
if (value.style?.bottom || !utils.isNumber(value.style?.top || 0)) {
|
|
5853
|
+
offset.top = 0;
|
|
5854
|
+
break;
|
|
5855
|
+
}
|
|
5856
|
+
offset.top = offset.top + Number(value.style?.top || 0);
|
|
5857
|
+
}
|
|
5858
|
+
}
|
|
5859
|
+
if (offset.left) {
|
|
5860
|
+
style.left = offset.left;
|
|
5861
|
+
}
|
|
5862
|
+
if (offset.top) {
|
|
5863
|
+
style.top = offset.top;
|
|
5864
|
+
}
|
|
5865
|
+
return style;
|
|
5846
5866
|
};
|
|
5847
5867
|
const Fixed2Other = async (node, root, getLayout) => {
|
|
5848
5868
|
const path = utils.getNodePath(node.id, root.items);
|
|
5849
5869
|
const cur = path.pop();
|
|
5850
5870
|
const offset = {
|
|
5851
5871
|
left: cur?.style?.left || 0,
|
|
5852
|
-
top: cur?.style?.top || 0
|
|
5853
|
-
right: "",
|
|
5854
|
-
bottom: ""
|
|
5872
|
+
top: cur?.style?.top || 0
|
|
5855
5873
|
};
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5874
|
+
if (!node.style?.right && utils.isNumber(node.style?.left || 0)) {
|
|
5875
|
+
for (const value of path) {
|
|
5876
|
+
if (value.style?.right || !utils.isNumber(value.style?.left || 0)) {
|
|
5877
|
+
offset.left = 0;
|
|
5878
|
+
break;
|
|
5879
|
+
}
|
|
5880
|
+
offset.left = offset.left - Number(value.style?.left || 0);
|
|
5881
|
+
}
|
|
5882
|
+
}
|
|
5883
|
+
if (!node.style?.bottom && utils.isNumber(node.style?.top || 0)) {
|
|
5884
|
+
for (const value of path) {
|
|
5885
|
+
if (value.style?.bottom || !utils.isNumber(value.style?.top || 0)) {
|
|
5886
|
+
offset.top = 0;
|
|
5887
|
+
break;
|
|
5888
|
+
}
|
|
5889
|
+
offset.top = offset.top - Number(value.style?.top || 0);
|
|
5890
|
+
}
|
|
5891
|
+
}
|
|
5860
5892
|
const style = node.style || {};
|
|
5861
5893
|
const parent = path.pop();
|
|
5862
5894
|
if (!parent) {
|
|
@@ -5864,9 +5896,14 @@
|
|
|
5864
5896
|
}
|
|
5865
5897
|
const layout = await getLayout(parent);
|
|
5866
5898
|
if (layout !== Layout.RELATIVE) {
|
|
5899
|
+
if (offset.left) {
|
|
5900
|
+
style.left = offset.left;
|
|
5901
|
+
}
|
|
5902
|
+
if (offset.top) {
|
|
5903
|
+
style.top = offset.top;
|
|
5904
|
+
}
|
|
5867
5905
|
return {
|
|
5868
5906
|
...style,
|
|
5869
|
-
...offset,
|
|
5870
5907
|
position: "absolute"
|
|
5871
5908
|
};
|
|
5872
5909
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.7.
|
|
2
|
+
"version": "1.7.5-beta.1",
|
|
3
3
|
"name": "@tmagic/editor",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -57,11 +57,11 @@
|
|
|
57
57
|
"moveable": "^0.53.0",
|
|
58
58
|
"serialize-javascript": "^7.0.0",
|
|
59
59
|
"sortablejs": "^1.15.6",
|
|
60
|
-
"@tmagic/design": "1.7.4",
|
|
61
|
-
"@tmagic/stage": "1.7.4",
|
|
62
60
|
"@tmagic/form": "1.7.4",
|
|
63
|
-
"@tmagic/
|
|
64
|
-
"@tmagic/utils": "1.7.4"
|
|
61
|
+
"@tmagic/stage": "1.7.4",
|
|
62
|
+
"@tmagic/utils": "1.7.4",
|
|
63
|
+
"@tmagic/design": "1.7.4",
|
|
64
|
+
"@tmagic/table": "1.7.4"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@types/events": "^3.0.3",
|
package/src/utils/editor.ts
CHANGED
|
@@ -177,21 +177,45 @@ export const setLayout = (node: MNode, layout: Layout) => {
|
|
|
177
177
|
};
|
|
178
178
|
|
|
179
179
|
export const change2Fixed = (node: MNode, root: MApp) => {
|
|
180
|
+
const style = {
|
|
181
|
+
...(node.style || {}),
|
|
182
|
+
};
|
|
183
|
+
|
|
180
184
|
const path = getNodePath(node.id, root.items);
|
|
181
185
|
const offset = {
|
|
182
186
|
left: 0,
|
|
183
187
|
top: 0,
|
|
184
188
|
};
|
|
185
189
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
+
if (!node.style?.right && isNumber(node.style?.left || 0)) {
|
|
191
|
+
for (const value of path) {
|
|
192
|
+
if (value.style?.right || !isNumber(value.style?.left || 0)) {
|
|
193
|
+
offset.left = 0;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
offset.left = offset.left + Number(value.style?.left || 0);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
190
199
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
200
|
+
if (!node.style?.bottom && isNumber(node.style?.top || 0)) {
|
|
201
|
+
for (const value of path) {
|
|
202
|
+
if (value.style?.bottom || !isNumber(value.style?.top || 0)) {
|
|
203
|
+
offset.top = 0;
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
offset.top = offset.top + Number(value.style?.top || 0);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (offset.left) {
|
|
211
|
+
style.left = offset.left;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (offset.top) {
|
|
215
|
+
style.top = offset.top;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return style;
|
|
195
219
|
};
|
|
196
220
|
|
|
197
221
|
export const Fixed2Other = async (
|
|
@@ -204,14 +228,28 @@ export const Fixed2Other = async (
|
|
|
204
228
|
const offset = {
|
|
205
229
|
left: cur?.style?.left || 0,
|
|
206
230
|
top: cur?.style?.top || 0,
|
|
207
|
-
right: '',
|
|
208
|
-
bottom: '',
|
|
209
231
|
};
|
|
210
232
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
233
|
+
if (!node.style?.right && isNumber(node.style?.left || 0)) {
|
|
234
|
+
for (const value of path) {
|
|
235
|
+
if (value.style?.right || !isNumber(value.style?.left || 0)) {
|
|
236
|
+
offset.left = 0;
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
offset.left = offset.left - Number(value.style?.left || 0);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (!node.style?.bottom && isNumber(node.style?.top || 0)) {
|
|
244
|
+
for (const value of path) {
|
|
245
|
+
if (value.style?.bottom || !isNumber(value.style?.top || 0)) {
|
|
246
|
+
offset.top = 0;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
offset.top = offset.top - Number(value.style?.top || 0);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
215
253
|
const style = node.style || {};
|
|
216
254
|
|
|
217
255
|
const parent = path.pop();
|
|
@@ -221,9 +259,16 @@ export const Fixed2Other = async (
|
|
|
221
259
|
|
|
222
260
|
const layout = await getLayout(parent);
|
|
223
261
|
if (layout !== Layout.RELATIVE) {
|
|
262
|
+
if (offset.left) {
|
|
263
|
+
style.left = offset.left;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (offset.top) {
|
|
267
|
+
style.top = offset.top;
|
|
268
|
+
}
|
|
269
|
+
|
|
224
270
|
return {
|
|
225
271
|
...style,
|
|
226
|
-
...offset,
|
|
227
272
|
position: 'absolute',
|
|
228
273
|
};
|
|
229
274
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1601,8 +1601,7 @@ declare const getInitPositionStyle: (style: Record<string, any> | undefined, lay
|
|
|
1601
1601
|
declare const setChildrenLayout: (node: MContainer, layout: Layout) => MContainer;
|
|
1602
1602
|
declare const setLayout: (node: MNode, layout: Layout) => _tmagic_schema.MComponent | undefined;
|
|
1603
1603
|
declare const change2Fixed: (node: MNode, root: MApp) => {
|
|
1604
|
-
|
|
1605
|
-
top: number;
|
|
1604
|
+
[key: string]: any;
|
|
1606
1605
|
};
|
|
1607
1606
|
declare const Fixed2Other: (node: MNode, root: MApp, getLayout: (parent: MNode, node?: MNode) => Promise<Layout>) => Promise<Record<string, any>>;
|
|
1608
1607
|
declare const getGuideLineFromCache: (key: string) => number[];
|