@tmagic/editor 1.7.3 → 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.
@@ -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
- path.forEach((value) => {
1046
- offset.left = offset.left + globalThis.parseFloat(value.style?.left || 0);
1047
- offset.top = offset.top + globalThis.parseFloat(value.style?.top || 0);
1048
- });
1049
- return {
1050
- ...node.style || {},
1051
- ...offset
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
- path.forEach((value) => {
1064
- offset.left = offset.left - globalThis.parseFloat(value.style?.left || 0);
1065
- offset.top = offset.top - globalThis.parseFloat(value.style?.top || 0);
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
  }
@@ -5405,9 +5442,35 @@ const _sfc_main$1f = /* @__PURE__ */ defineComponent({
5405
5442
  }
5406
5443
  }
5407
5444
  ]);
5445
+ const parseContent = (content) => {
5446
+ if (typeof content === "string") {
5447
+ const parseDSL = getEditorConfig("parseDSL");
5448
+ return parseDSL(content);
5449
+ }
5450
+ return content;
5451
+ };
5408
5452
  const submitForm = (values, data) => {
5409
5453
  changedValue.value = void 0;
5410
- emit("submit", values, data);
5454
+ emit(
5455
+ "submit",
5456
+ {
5457
+ ...values,
5458
+ content: parseContent(values.content)
5459
+ },
5460
+ {
5461
+ ...data,
5462
+ changeRecords: data.changeRecords?.map((record) => {
5463
+ let { value } = record;
5464
+ if (record.propPath === "content" && typeof value === "string") {
5465
+ value = parseContent(value);
5466
+ }
5467
+ return {
5468
+ ...record,
5469
+ value
5470
+ };
5471
+ })
5472
+ }
5473
+ );
5411
5474
  };
5412
5475
  const errorHandler = (error) => {
5413
5476
  tMagicMessage.error(error.message);
@@ -5703,12 +5766,6 @@ const _sfc_main$1e = /* @__PURE__ */ defineComponent({
5703
5766
  });
5704
5767
  };
5705
5768
  const submitCodeHandler = (value, data) => {
5706
- if (value.content) {
5707
- const parseDSL = getEditorConfig("parseDSL");
5708
- if (typeof value.content === "string") {
5709
- value.content = parseDSL(value.content);
5710
- }
5711
- }
5712
5769
  if (editIndex > -1) {
5713
5770
  emit("change", value, {
5714
5771
  modifyKey: editIndex,
@@ -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
- path.forEach((value) => {
5839
- offset.left = offset.left + globalThis.parseFloat(value.style?.left || 0);
5840
- offset.top = offset.top + globalThis.parseFloat(value.style?.top || 0);
5841
- });
5842
- return {
5843
- ...node.style || {},
5844
- ...offset
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
- path.forEach((value) => {
5857
- offset.left = offset.left - globalThis.parseFloat(value.style?.left || 0);
5858
- offset.top = offset.top - globalThis.parseFloat(value.style?.top || 0);
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
  }
@@ -10198,9 +10235,35 @@
10198
10235
  }
10199
10236
  }
10200
10237
  ]);
10238
+ const parseContent = (content) => {
10239
+ if (typeof content === "string") {
10240
+ const parseDSL = getEditorConfig("parseDSL");
10241
+ return parseDSL(content);
10242
+ }
10243
+ return content;
10244
+ };
10201
10245
  const submitForm = (values, data) => {
10202
10246
  changedValue.value = void 0;
10203
- emit("submit", values, data);
10247
+ emit(
10248
+ "submit",
10249
+ {
10250
+ ...values,
10251
+ content: parseContent(values.content)
10252
+ },
10253
+ {
10254
+ ...data,
10255
+ changeRecords: data.changeRecords?.map((record) => {
10256
+ let { value } = record;
10257
+ if (record.propPath === "content" && typeof value === "string") {
10258
+ value = parseContent(value);
10259
+ }
10260
+ return {
10261
+ ...record,
10262
+ value
10263
+ };
10264
+ })
10265
+ }
10266
+ );
10204
10267
  };
10205
10268
  const errorHandler = (error) => {
10206
10269
  designPlugin.tMagicMessage.error(error.message);
@@ -10496,12 +10559,6 @@
10496
10559
  });
10497
10560
  };
10498
10561
  const submitCodeHandler = (value, data) => {
10499
- if (value.content) {
10500
- const parseDSL = getEditorConfig("parseDSL");
10501
- if (typeof value.content === "string") {
10502
- value.content = parseDSL(value.content);
10503
- }
10504
- }
10505
10562
  if (editIndex > -1) {
10506
10563
  emit("change", value, {
10507
10564
  modifyKey: editIndex,
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.7.3",
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.3",
61
- "@tmagic/stage": "1.7.3",
62
- "@tmagic/table": "1.7.3",
63
- "@tmagic/utils": "1.7.3",
64
- "@tmagic/form": "1.7.3"
60
+ "@tmagic/form": "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",
@@ -75,7 +75,7 @@
75
75
  "monaco-editor": "^0.48.0",
76
76
  "typescript": "^5.9.3",
77
77
  "vue": "^3.5.24",
78
- "@tmagic/core": "1.7.3"
78
+ "@tmagic/core": "1.7.4"
79
79
  },
80
80
  "peerDependenciesMeta": {
81
81
  "typescript": {
@@ -217,9 +217,38 @@ const functionConfig = computed<FormConfig>(() => [
217
217
  },
218
218
  ]);
219
219
 
220
+ const parseContent = (content: any) => {
221
+ if (typeof content === 'string') {
222
+ // 如果是字符串则转换为函数
223
+ const parseDSL = getEditorConfig('parseDSL');
224
+ return parseDSL<(..._args: any[]) => any>(content);
225
+ }
226
+ return content;
227
+ };
228
+
220
229
  const submitForm = (values: CodeBlockContent, data: ContainerChangeEventData) => {
221
230
  changedValue.value = undefined;
222
- emit('submit', values, data);
231
+
232
+ emit(
233
+ 'submit',
234
+ {
235
+ ...values,
236
+ content: parseContent(values.content),
237
+ },
238
+ {
239
+ ...data,
240
+ changeRecords: data.changeRecords?.map((record) => {
241
+ let { value } = record;
242
+ if (record.propPath === 'content' && typeof value === 'string') {
243
+ value = parseContent(value);
244
+ }
245
+ return {
246
+ ...record,
247
+ value,
248
+ };
249
+ }),
250
+ },
251
+ );
223
252
  };
224
253
 
225
254
  const errorHandler = (error: any) => {
@@ -31,7 +31,6 @@ import { type ColumnConfig, MagicTable } from '@tmagic/table';
31
31
 
32
32
  import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
33
33
  import type { CodeParamStatement } from '@editor/type';
34
- import { getEditorConfig } from '@editor/utils/config';
35
34
 
36
35
  defineOptions({
37
36
  name: 'MFieldsDataSourceMethods',
@@ -119,13 +118,6 @@ const createCodeHandler = () => {
119
118
  };
120
119
 
121
120
  const submitCodeHandler = (value: CodeBlockContent, data: ContainerChangeEventData) => {
122
- if (value.content) {
123
- // 在保存的时候转换代码内容
124
- const parseDSL = getEditorConfig('parseDSL');
125
- if (typeof value.content === 'string') {
126
- value.content = parseDSL<(..._args: any[]) => any>(value.content);
127
- }
128
- }
129
121
  if (editIndex > -1) {
130
122
  emit('change', value, {
131
123
  modifyKey: editIndex,
@@ -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
- path.forEach((value) => {
187
- offset.left = offset.left + globalThis.parseFloat(value.style?.left || 0);
188
- offset.top = offset.top + globalThis.parseFloat(value.style?.top || 0);
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
- return {
192
- ...(node.style || {}),
193
- ...offset,
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
- path.forEach((value) => {
212
- offset.left = offset.left - globalThis.parseFloat(value.style?.left || 0);
213
- offset.top = offset.top - globalThis.parseFloat(value.style?.top || 0);
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
- left: number;
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[];