@tmagic/editor 1.8.0-beta.5 → 1.8.0-beta.6

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.
Files changed (42) hide show
  1. package/dist/es/fields/CodeSelectCol.vue_vue_type_script_setup_true_lang.js +4 -1
  2. package/dist/es/fields/DataSourceFieldSelect/FieldSelect.vue_vue_type_script_setup_true_lang.js +8 -2
  3. package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +25 -8
  4. package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +6 -4
  5. package/dist/es/fields/DataSourceMethods.vue_vue_type_script_setup_true_lang.js +25 -12
  6. package/dist/es/fields/StyleSetter/components/Border.vue_vue_type_script_setup_true_lang.js +27 -5
  7. package/dist/es/index.js +2 -2
  8. package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +2 -2
  9. package/dist/es/layouts/history-list/InitialRow.vue_vue_type_script_setup_true_lang.js +12 -4
  10. package/dist/es/layouts/sidebar/data-source/DataSourceConfigPanel.vue_vue_type_script_setup_true_lang.js +16 -3
  11. package/dist/es/layouts/sidebar/data-source/DataSourceListPanel.vue_vue_type_script_setup_true_lang.js +23 -1
  12. package/dist/es/services/codeBlock.js +30 -19
  13. package/dist/es/services/dataSource.js +29 -21
  14. package/dist/es/services/editor.js +52 -33
  15. package/dist/es/services/history.js +10 -15
  16. package/dist/es/style.css +4 -1
  17. package/dist/es/utils/data-source/index.js +2 -0
  18. package/dist/es/utils/editor.js +68 -48
  19. package/dist/es/utils/history.js +42 -33
  20. package/dist/style.css +4 -1
  21. package/dist/tmagic-editor.umd.cjs +376 -206
  22. package/package.json +7 -7
  23. package/src/fields/CodeSelectCol.vue +7 -1
  24. package/src/fields/DataSourceFieldSelect/FieldSelect.vue +16 -2
  25. package/src/fields/DataSourceFields.vue +37 -8
  26. package/src/fields/DataSourceMethodSelect.vue +9 -4
  27. package/src/fields/DataSourceMethods.vue +42 -21
  28. package/src/fields/StyleSetter/components/Border.vue +15 -6
  29. package/src/layouts/history-list/HistoryListPanel.vue +2 -2
  30. package/src/layouts/history-list/InitialRow.vue +3 -0
  31. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +30 -2
  32. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +26 -1
  33. package/src/services/codeBlock.ts +28 -22
  34. package/src/services/dataSource.ts +29 -24
  35. package/src/services/editor.ts +41 -37
  36. package/src/services/history.ts +14 -19
  37. package/src/theme/style-setter/border.scss +4 -1
  38. package/src/type.ts +16 -1
  39. package/src/utils/data-source/index.ts +2 -0
  40. package/src/utils/editor.ts +125 -59
  41. package/src/utils/history.ts +46 -36
  42. package/types/index.d.ts +87 -68
@@ -1,6 +1,7 @@
1
1
  import { Layout, canUsePluginMethods } from "../type.js";
2
2
  import BaseService from "./BaseService.js";
3
3
  import props_default from "./props.js";
4
+ import { getLastPushedHistoryIds } from "../utils/history.js";
4
5
  import history_default from "./history.js";
5
6
  import storage_default, { Protocol } from "./storage.js";
6
7
  import { COPY_STORAGE_KEY, calcAlignCenterStyle, calcLayerTargetIndex, calcMoveStyle, classifyDragSources, collectRelatedNodes, describeStepForRevert, editorNodeMergeCustomizer, fixNodePosition, getInitPositionStyle, getNodeIndex, getPageFragmentList, getPageList, moveItemsInContainer, resolveSelectedNode, setChildrenLayout, setLayout, toggleFixedPosition } from "../utils/editor.js";
@@ -83,7 +84,7 @@ var Editor = class extends BaseService {
83
84
  this.state.pageFragmentLength = 0;
84
85
  this.state.stageLoading = false;
85
86
  }
86
- this.emit("root-change", value, preValue);
87
+ this.emit("root-change", value, preValue, options);
87
88
  }
88
89
  }
89
90
  /**
@@ -106,12 +107,14 @@ var Editor = class extends BaseService {
106
107
  if (!root) return {
107
108
  node: null,
108
109
  parent: null,
109
- page: null
110
+ page: null,
111
+ path: []
110
112
  };
111
113
  if (id === root.id) return {
112
114
  node: root,
113
115
  parent: null,
114
- page: null
116
+ page: null,
117
+ path: []
115
118
  };
116
119
  const pageIdStr = `${this.get("page")?.id || ""}`;
117
120
  const currentPageNode = root.items?.find((item) => `${item.id}` === pageIdStr);
@@ -431,13 +434,12 @@ var Editor = class extends BaseService {
431
434
  this.emit("remove", nodes);
432
435
  }
433
436
  async doUpdate(config, { changeRecords = [], historySource } = {}) {
434
- const root = this.get("root");
435
- if (!root) throw new Error("root为空");
437
+ if (!this.get("root")) throw new Error("root为空");
436
438
  if (!config?.id) throw new Error("没有配置或者配置缺少id值");
437
439
  const info = this.getNodeInfo(config.id, false);
438
440
  if (!info.node) throw new Error(`获取不到id为${config.id}的节点`);
439
441
  const node = toRaw(info.node);
440
- let newConfig = await toggleFixedPosition(toRaw(config), node, root, this.getLayout);
442
+ let newConfig = await toggleFixedPosition(toRaw(config), node, info.path, this.getLayout);
441
443
  newConfig = mergeWith(cloneDeep$1(node), newConfig, editorNodeMergeCustomizer);
442
444
  if (!newConfig.type) throw new Error("配置缺少type值");
443
445
  if (newConfig.type === NodeType.ROOT) {
@@ -812,46 +814,61 @@ var Editor = class extends BaseService {
812
814
  }
813
815
  /**
814
816
  * 下列 *AndGetHistoryId 方法与对应的普通操作(add / remove / update ...)行为完全一致,
815
- * 唯一区别是返回值为本次写入历史栈的历史记录 uuid{@link StepValue.uuid}),
816
- * 而非节点 / 节点数组。可用于精确引用 / 定位该条历史记录(埋点、revert、跨端同步等)。
817
+ * 返回值在 {@link DslOpWithHistoryIdsResult} 中同时包含原操作结果与本次写入历史栈的 uuid 列表({@link StepValue.uuid}),
818
+ * 可用于精确引用 / 定位该条历史记录(埋点、revert、跨端同步等)。
817
819
  *
818
- * 当本次操作未写入历史(doNotPushHistory 为 true、或操作无实际变更 / 提前返回)时返回 null。
820
+ * 当本次操作未写入历史(doNotPushHistory 为 true、或操作无实际变更 / 提前返回)时 historyIds 为 `[]`。
819
821
  */
820
- /** 等价于 {@link add},但返回本次写入历史记录的 uuid(未入栈时返回 null)。 */
822
+ /** 等价于 {@link add},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
821
823
  async addAndGetHistoryId(addNode, parent, options = {}) {
822
824
  this.lastPushedHistoryId = null;
823
- await this.add(addNode, parent, options);
824
- return this.lastPushedHistoryId;
825
+ return {
826
+ result: await this.add(addNode, parent, options),
827
+ historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId)
828
+ };
825
829
  }
826
- /** 等价于 {@link remove},但返回本次写入历史记录的 uuid(未入栈时返回 null)。 */
830
+ /** 等价于 {@link remove},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
827
831
  async removeAndGetHistoryId(nodeOrNodeList, options = {}) {
828
832
  this.lastPushedHistoryId = null;
829
833
  await this.remove(nodeOrNodeList, options);
830
- return this.lastPushedHistoryId;
834
+ return {
835
+ result: void 0,
836
+ historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId)
837
+ };
831
838
  }
832
- /** 等价于 {@link update},但返回本次写入历史记录的 uuid(未入栈时返回 null)。 */
839
+ /** 等价于 {@link update},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
833
840
  async updateAndGetHistoryId(config, data = {}) {
834
841
  this.lastPushedHistoryId = null;
835
- await this.update(config, data);
836
- return this.lastPushedHistoryId;
842
+ return {
843
+ result: await this.update(config, data),
844
+ historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId)
845
+ };
837
846
  }
838
- /** 等价于 {@link moveLayer},但返回本次写入历史记录的 uuid(未入栈时返回 null)。 */
847
+ /** 等价于 {@link moveLayer},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
839
848
  async moveLayerAndGetHistoryId(offset, options = {}) {
840
849
  this.lastPushedHistoryId = null;
841
850
  await this.moveLayer(offset, options);
842
- return this.lastPushedHistoryId;
851
+ return {
852
+ result: void 0,
853
+ historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId)
854
+ };
843
855
  }
844
- /** 等价于 {@link moveToContainer},但返回本次写入历史记录的 uuid(未入栈时返回 null)。 */
856
+ /** 等价于 {@link moveToContainer},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
845
857
  async moveToContainerAndGetHistoryId(config, targetId, options = {}) {
846
858
  this.lastPushedHistoryId = null;
847
- await this.moveToContainer(config, targetId, options);
848
- return this.lastPushedHistoryId;
859
+ return {
860
+ result: await this.moveToContainer(config, targetId, options),
861
+ historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId)
862
+ };
849
863
  }
850
- /** 等价于 {@link dragTo},但返回本次写入历史记录的 uuid(未入栈时返回 null)。 */
864
+ /** 等价于 {@link dragTo},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
851
865
  async dragToAndGetHistoryId(config, targetParent, targetIndex, options = {}) {
852
866
  this.lastPushedHistoryId = null;
853
867
  await this.dragTo(config, targetParent, targetIndex, options);
854
- return this.lastPushedHistoryId;
868
+ return {
869
+ result: void 0,
870
+ historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId)
871
+ };
855
872
  }
856
873
  /**
857
874
  * 撤销当前操作
@@ -960,17 +977,19 @@ var Editor = class extends BaseService {
960
977
  return revertedStep;
961
978
  }
962
979
  /**
963
- * 通过历史记录 uuid 回滚当前页面的某条历史步骤,语义与 {@link revertPageStep} 完全一致,
964
- * 仅入参从 index 改为 uuid{@link StepValue.uuid})。uuid 不随栈内步骤增删而变化,
965
- * 更适合业务侧持有引用后再回滚(埋点、跨端同步等场景)。
980
+ * 通过历史记录 uuid 回滚当前页面的历史步骤,语义与 {@link revertPageStep} 完全一致,
981
+ * 仅入参从 index 改为 uuid 列表({@link StepValue.uuid})。按数组顺序依次回滚,
982
+ * 返回与入参同序的结果列表(某项失败时为 `null`)。
966
983
  *
967
- * @param uuid 目标历史记录的 uuid,通常由 *AndGetHistoryId 方法返回
968
- * @returns 反向后产生的新 step;找不到对应 uuid / 未应用 / 反向失败时返回 null
984
+ * @param uuids 目标历史记录的 uuid 列表,通常由 *AndGetHistoryId 方法返回的 `historyIds`
969
985
  */
970
- async revertPageStepById(uuid) {
971
- const index = history_default.getPageStepIndexByUuid(uuid);
972
- if (index < 0) return null;
973
- return this.revertPageStep(index);
986
+ async revertPageStepById(uuids) {
987
+ const results = [];
988
+ for (const uuid of uuids) {
989
+ const index = history_default.getPageStepIndexByUuid(uuid);
990
+ results.push(index < 0 ? null : await this.revertPageStep(index));
991
+ }
992
+ return results;
974
993
  }
975
994
  /**
976
995
  * 跳转当前页面历史栈到指定游标位置。
@@ -6,13 +6,12 @@ import { idbGet, idbSet } from "../utils/indexed-db.js";
6
6
  import editor_default from "./editor.js";
7
7
  import { guid } from "@tmagic/utils";
8
8
  import { reactive } from "vue";
9
- import serialize from "serialize-javascript";
10
9
  //#region packages/editor/src/services/history.ts
11
10
  /** 历史记录持久化快照的默认存储位置与结构版本。 */
12
11
  var DEFAULT_DB_NAME = "tmagic-editor";
13
12
  var DEFAULT_STORE_NAME = "history";
14
13
  var DEFAULT_KEY = "default";
15
- var PERSIST_VERSION = 1;
14
+ var PERSIST_VERSION = 2;
16
15
  var History = class extends BaseService {
17
16
  state = reactive({
18
17
  pageSteps: {},
@@ -335,7 +334,7 @@ var History = class extends BaseService {
335
334
  dataSourceState: serializeStacks(this.state.dataSourceState),
336
335
  savedAt: Date.now()
337
336
  };
338
- await idbSet(this.resolveDbName(dbName, appId), storeName, key, serialize(snapshot));
337
+ await idbSet(this.resolveDbName(dbName, appId), storeName, key, snapshot);
339
338
  this.emit("save-to-indexed-db", snapshot);
340
339
  return snapshot;
341
340
  }
@@ -349,13 +348,12 @@ var History = class extends BaseService {
349
348
  */
350
349
  async restoreFromIndexedDB(options = {}) {
351
350
  const { dbName = DEFAULT_DB_NAME, storeName = DEFAULT_STORE_NAME, key = DEFAULT_KEY, appId } = options;
352
- const raw = await idbGet(this.resolveDbName(dbName, appId), storeName, key);
353
- if (!raw) return null;
354
- const snapshot = typeof raw === "string" ? getEditorConfig("parseDSL")(`(${raw})`) : raw;
351
+ const snapshot = await idbGet(this.resolveDbName(dbName, appId), storeName, key);
355
352
  if (!snapshot) return null;
356
- this.state.pageSteps = deserializeStacks(snapshot.pageSteps);
357
- this.state.codeBlockState = deserializeStacks(snapshot.codeBlockState);
358
- this.state.dataSourceState = deserializeStacks(snapshot.dataSourceState);
353
+ const parseDSL = getEditorConfig("parseDSL");
354
+ this.state.pageSteps = deserializeStacks(snapshot.pageSteps, parseDSL);
355
+ this.state.codeBlockState = deserializeStacks(snapshot.codeBlockState, parseDSL);
356
+ this.state.dataSourceState = deserializeStacks(snapshot.dataSourceState, parseDSL);
359
357
  this.state.pageId = snapshot.pageId;
360
358
  this.setCanUndoRedo();
361
359
  this.emit("restore-from-indexed-db", snapshot);
@@ -395,11 +393,8 @@ var History = class extends BaseService {
395
393
  return mergePageSteps(targetPageId, list, undoRedo.getCursor()).filter((group) => group.opType !== "initial");
396
394
  }
397
395
  /**
398
- * 取出全部代码块的历史栈,按 codeBlockId 分组。
399
- * 同一栈内相邻、同 opType 且作用于同一 id 的多步会被合并为一个 group:
400
- * - 这正是"代码块/数据源各自按 id 分栈"的天然表现,再叠加"连续修改同目标的相邻步骤合并展示"。
401
- * - 合并后 group 暴露子步骤数组,UI 可展开查看每一步的 changeRecords。
402
- * - applied 字段:组内最后一步是否处于已应用段。
396
+ * 取出全部代码块的历史栈,按 codeBlockId 分桶展示。
397
+ * 同一栈内每条操作记录独立成组,不做相邻 update 合并。
403
398
  */
404
399
  getCodeBlockHistoryGroups() {
405
400
  const groups = [];
@@ -496,7 +491,7 @@ var History = class extends BaseService {
496
491
  return null;
497
492
  }
498
493
  /**
499
- * 取出全部数据源的历史栈,按 dataSourceId 分组。同上。
494
+ * 取出全部数据源的历史栈,按 dataSourceId 分桶展示。同上,每条操作独立成组。
500
495
  */
501
496
  getDataSourceHistoryGroups() {
502
497
  const groups = [];
package/dist/es/style.css CHANGED
@@ -2093,9 +2093,12 @@ fieldset.m-fieldset .m-form-tip {
2093
2093
  .border-box-container .border-icon-container .border-icon + .border-icon {
2094
2094
  margin-left: 8px;
2095
2095
  }
2096
+ .border-box-container .border-icon-container .border-icon.configured {
2097
+ border-color: var(--el-color-success, var(--td-success-color, #2ba471));
2098
+ }
2096
2099
  .border-box-container .border-icon-container .border-icon.active {
2097
2100
  border-width: 1px;
2098
- border-color: var(--el-color-primary);
2101
+ border-color: var(--el-color-primary, var(--td-brand-color, #0052d9));
2099
2102
  }
2100
2103
  .border-box-container .border-icon-container .border-icon.border-icon-top {
2101
2104
  border-top-width: 2px;
@@ -7,6 +7,7 @@ var dataSourceFormConfig = {
7
7
  items: [
8
8
  {
9
9
  title: "数据定义",
10
+ status: "fields",
10
11
  items: [{
11
12
  name: "fields",
12
13
  type: "data-source-fields",
@@ -15,6 +16,7 @@ var dataSourceFormConfig = {
15
16
  },
16
17
  {
17
18
  title: "方法定义",
19
+ status: "methods",
18
20
  items: [{
19
21
  name: "methods",
20
22
  type: "data-source-methods",
@@ -74,12 +74,26 @@ var getMiddleTop = (node, parentNode, stage) => {
74
74
  }
75
75
  return (Math.min(parentHeight, wrapperHeightDeal) - height) / 2;
76
76
  };
77
+ var removeConflictPosition = (style, primary, secondary) => {
78
+ const isInvalid = (value) => value === "" || value === 0 || value === void 0 || value === null;
79
+ if (!(primary in style) || !(secondary in style)) return;
80
+ const primaryValue = style[primary];
81
+ const secondaryValue = style[secondary];
82
+ const primaryInvalid = isInvalid(primaryValue);
83
+ const secondaryInvalid = isInvalid(secondaryValue);
84
+ if (primaryInvalid && !secondaryInvalid) delete style[primary];
85
+ else if (secondaryInvalid && !primaryInvalid) delete style[secondary];
86
+ else if (primaryInvalid && secondaryInvalid) if (secondaryValue === 0 && primaryValue !== 0) delete style[primary];
87
+ else delete style[secondary];
88
+ };
77
89
  var getInitPositionStyle = (style = {}, layout) => {
78
90
  if (layout === Layout.ABSOLUTE) {
79
91
  const newStyle = {
80
92
  ...style,
81
93
  position: "absolute"
82
94
  };
95
+ removeConflictPosition(newStyle, "left", "right");
96
+ removeConflictPosition(newStyle, "top", "bottom");
83
97
  if (typeof newStyle.left === "undefined" && typeof newStyle.right === "undefined") newStyle.left = 0;
84
98
  return newStyle;
85
99
  }
@@ -104,58 +118,63 @@ var setLayout = (node, layout) => {
104
118
  }
105
119
  return node;
106
120
  };
107
- var change2Fixed = (node, root) => {
121
+ var hasPositionValue = (style, key) => typeof style?.[key] !== "undefined" && style?.[key] !== "";
122
+ /**
123
+ * 沿节点路径累加(或抵消)某一方向上的定位偏移量
124
+ * 当路径上的祖先使用了反方向定位(例如计算 left 时祖先用了 right)或非数值定位时,
125
+ * 无法简单地通过求和换算坐标,此时返回 0 表示放弃补偿、保持原值
126
+ * @param path 从根到目标节点的路径(含节点自身)
127
+ * @param dir 需要累加的定位方向
128
+ * @param opposite 反方向定位属性
129
+ * @param sign change2Fixed 取 1(累加祖先偏移),Fixed2Other 取 -1(抵消祖先偏移)
130
+ * @param init 偏移量初始值
131
+ */
132
+ var accumulatePositionOffset = (path, dir, opposite, sign, init = 0) => {
133
+ let offset = init;
134
+ for (const value of path) {
135
+ if (hasPositionValue(value.style, opposite) || !isNumber(value.style?.[dir] || 0)) return 0;
136
+ offset = offset + sign * Number(value.style?.[dir] || 0);
137
+ }
138
+ return offset;
139
+ };
140
+ var change2Fixed = (node, path) => {
108
141
  const style = { ...node.style || {} };
109
- const path = getNodePath(node.id, root.items);
110
- const offset = {
111
- left: 0,
112
- top: 0
113
- };
114
- if (!node.style?.right && isNumber(node.style?.left || 0)) for (const value of path) {
115
- if (value.style?.right || !isNumber(value.style?.left || 0)) {
116
- offset.left = 0;
117
- break;
118
- }
119
- offset.left = offset.left + Number(value.style?.left || 0);
142
+ if (!hasPositionValue(node.style, "right") && isNumber(node.style?.left || 0)) {
143
+ const left = accumulatePositionOffset(path, "left", "right", 1);
144
+ if (left) style.left = left;
145
+ } else if (hasPositionValue(node.style, "right") && isNumber(node.style?.right || 0)) {
146
+ const right = accumulatePositionOffset(path, "right", "left", 1);
147
+ if (right) style.right = right;
120
148
  }
121
- if (!node.style?.bottom && isNumber(node.style?.top || 0)) for (const value of path) {
122
- if (value.style?.bottom || !isNumber(value.style?.top || 0)) {
123
- offset.top = 0;
124
- break;
125
- }
126
- offset.top = offset.top + Number(value.style?.top || 0);
149
+ if (!hasPositionValue(node.style, "bottom") && isNumber(node.style?.top || 0)) {
150
+ const top = accumulatePositionOffset(path, "top", "bottom", 1);
151
+ if (top) style.top = top;
152
+ } else if (hasPositionValue(node.style, "bottom") && isNumber(node.style?.bottom || 0)) {
153
+ const bottom = accumulatePositionOffset(path, "bottom", "top", 1);
154
+ if (bottom) style.bottom = bottom;
127
155
  }
128
- if (offset.left) style.left = offset.left;
129
- if (offset.top) style.top = offset.top;
130
156
  return style;
131
157
  };
132
- var Fixed2Other = async (node, root, getLayout) => {
133
- const path = getNodePath(node.id, root.items);
158
+ var Fixed2Other = async (node, path, getLayout) => {
134
159
  const cur = path.pop();
135
160
  const offset = {
136
- left: cur?.style?.left || 0,
137
- top: cur?.style?.top || 0
161
+ left: 0,
162
+ top: 0,
163
+ right: 0,
164
+ bottom: 0
138
165
  };
139
- if (!node.style?.right && isNumber(node.style?.left || 0)) for (const value of path) {
140
- if (value.style?.right || !isNumber(value.style?.left || 0)) {
141
- offset.left = 0;
142
- break;
143
- }
144
- offset.left = offset.left - Number(value.style?.left || 0);
145
- }
146
- if (!node.style?.bottom && isNumber(node.style?.top || 0)) for (const value of path) {
147
- if (value.style?.bottom || !isNumber(value.style?.top || 0)) {
148
- offset.top = 0;
149
- break;
150
- }
151
- offset.top = offset.top - Number(value.style?.top || 0);
152
- }
166
+ if (!hasPositionValue(node.style, "right") && isNumber(node.style?.left || 0)) offset.left = accumulatePositionOffset(path, "left", "right", -1, Number(cur?.style?.left || 0));
167
+ else if (hasPositionValue(node.style, "right") && isNumber(node.style?.right || 0)) offset.right = accumulatePositionOffset(path, "right", "left", -1, Number(cur?.style?.right || 0));
168
+ if (!hasPositionValue(node.style, "bottom") && isNumber(node.style?.top || 0)) offset.top = accumulatePositionOffset(path, "top", "bottom", -1, Number(cur?.style?.top || 0));
169
+ else if (hasPositionValue(node.style, "bottom") && isNumber(node.style?.bottom || 0)) offset.bottom = accumulatePositionOffset(path, "bottom", "top", -1, Number(cur?.style?.bottom || 0));
153
170
  const style = node.style || {};
154
171
  const parent = path.pop();
155
172
  if (!parent) return getRelativeStyle(style);
156
173
  if (await getLayout(parent) !== Layout.RELATIVE) {
157
174
  if (offset.left) style.left = offset.left;
158
175
  if (offset.top) style.top = offset.top;
176
+ if (offset.right) style.right = offset.right;
177
+ if (offset.bottom) style.bottom = offset.bottom;
159
178
  return {
160
179
  ...style,
161
180
  position: "absolute"
@@ -187,11 +206,11 @@ var fixNodeLeft = (config, parent, doc) => {
187
206
  };
188
207
  var fixNodePosition = (config, parent, stage) => {
189
208
  if (config.style?.position !== "absolute") return config.style;
190
- return {
191
- ...config.style || {},
192
- top: getMiddleTop(config, parent, stage),
193
- left: fixNodeLeft(config, parent, stage?.renderer?.contentWindow?.document)
194
- };
209
+ const style = { ...config.style || {} };
210
+ const baseStyle = config.style || {};
211
+ if ("left" in baseStyle && !("right" in baseStyle)) style.left = fixNodeLeft(config, parent, stage?.renderer?.contentWindow?.document);
212
+ if ("top" in baseStyle && !("bottom" in baseStyle)) style.top = getMiddleTop(config, parent, stage);
213
+ return style;
195
214
  };
196
215
  var serializeConfig = (config) => serialize(config, {
197
216
  space: 2,
@@ -268,13 +287,14 @@ var buildChangeRecords = (value, basePath) => {
268
287
  var resolveSelectedNode = (config, getNodeInfoFn, rootId) => {
269
288
  const id = typeof config === "string" || typeof config === "number" ? config : config.id;
270
289
  if (!id) throw new Error("没有ID,无法选中");
271
- const { node, parent, page } = getNodeInfoFn(id);
290
+ const { node, parent, page, path } = getNodeInfoFn(id);
272
291
  if (!node) throw new Error("获取不到组件信息");
273
292
  if (node.id === rootId) throw new Error("不能选根节点");
274
293
  return {
275
294
  node,
276
295
  parent,
277
- page
296
+ page,
297
+ path
278
298
  };
279
299
  };
280
300
  /**
@@ -286,11 +306,11 @@ var resolveSelectedNode = (config, getNodeInfoFn, rootId) => {
286
306
  * @param getLayoutFn 获取父节点布局方式的回调函数
287
307
  * @returns 处理后的节点配置(深拷贝)
288
308
  */
289
- var toggleFixedPosition = async (dist, src, root, getLayoutFn) => {
309
+ var toggleFixedPosition = async (dist, src, path, getLayoutFn) => {
290
310
  const newConfig = cloneDeep$1(dist);
291
311
  if (!isPop(src) && newConfig.style?.position) {
292
- if (isFixed(newConfig.style) && !isFixed(src.style || {})) newConfig.style = change2Fixed(newConfig, root);
293
- else if (!isFixed(newConfig.style) && isFixed(src.style || {})) newConfig.style = await Fixed2Other(newConfig, root, getLayoutFn);
312
+ if (isFixed(newConfig.style) && !isFixed(src.style || {})) newConfig.style = change2Fixed(newConfig, path);
313
+ else if (!isFixed(newConfig.style) && isFixed(src.style || {})) newConfig.style = await Fixed2Other(newConfig, path, getLayoutFn);
294
314
  }
295
315
  return newConfig;
296
316
  };
@@ -1,6 +1,7 @@
1
1
  import { UndoRedo } from "./undo-redo.js";
2
2
  import { guid } from "@tmagic/utils";
3
3
  import { cloneDeep } from "lodash-es";
4
+ import serialize from "serialize-javascript";
4
5
  //#region packages/editor/src/utils/history.ts
5
6
  /**
6
7
  * 「回滚」生成的新 step 简短描述。代码块 / 数据源共用。
@@ -66,46 +67,29 @@ var markStackSaved = (undoRedo) => {
66
67
  };
67
68
  /**
68
69
  * 把单个「按 id 分栈」的历史栈(代码块 / 数据源)拆成若干 group:
69
- * - 把"新增/删除"独立成组(语义上属于一次性事件,不应与 update 合并);
70
- * - 连续 'update' 合并到同一组,组内 steps 顺序就是发生顺序。
70
+ * 每条操作记录独立成组,不做相邻 update 合并(与页面历史的合并策略不同)。
71
71
  *
72
72
  * 代码块与数据源除 `kind` 外结构完全一致,统一由本方法处理;`kind` 决定返回的具体分组类型。
73
73
  */
74
74
  var mergeStackSteps = (kind, id, list, cursor) => {
75
- const groups = [];
76
- let current = null;
77
75
  const currentIndex = cursor - 1;
78
- list.forEach((step, index) => {
79
- const { opType } = step;
76
+ return list.map((step, index) => {
80
77
  const applied = index < cursor;
81
78
  const isCurrent = index === currentIndex;
82
- if (opType === "update" && current?.opType === "update") {
83
- current.steps.push({
79
+ return {
80
+ kind,
81
+ id,
82
+ opType: step.opType,
83
+ steps: [{
84
84
  step,
85
85
  index,
86
86
  applied,
87
87
  isCurrent
88
- });
89
- current.applied = applied;
90
- if (isCurrent) current.isCurrent = true;
91
- } else {
92
- current = {
93
- kind,
94
- id,
95
- opType,
96
- steps: [{
97
- step,
98
- index,
99
- applied,
100
- isCurrent
101
- }],
102
- applied,
103
- isCurrent
104
- };
105
- groups.push(current);
106
- }
88
+ }],
89
+ applied,
90
+ isCurrent
91
+ };
107
92
  });
108
- return groups;
109
93
  };
110
94
  /**
111
95
  * 把页面栈拆成若干 group:
@@ -186,22 +170,45 @@ var detectPageTargetName = (step) => {
186
170
  return items?.length ? `${items.length} 个节点` : void 0;
187
171
  }
188
172
  };
189
- /** 把 `Record<Id, UndoRedo>` 整体序列化为 `Record<Id, SerializedUndoRedo>`。 */
173
+ /**
174
+ * 把 `Record<Id, UndoRedo>` 整体序列化为 `Record<Id, SerializedUndoRedo>`。
175
+ *
176
+ * 序列化(深克隆)的同一趟里,只把每条 step 中可能含函数的 `diff` 用 serialize-javascript 序列化成字符串,
177
+ * 其余字段(uuid / opType / timestamp / `modifiedNodeIds` Map 等)原样保留,交给 IndexedDB 结构化克隆。
178
+ * 这样既能写入函数,又避免序列化整份快照的开销;读取时再由 {@link parseStacksStepDiff} 还原 diff。
179
+ * 不含 `diff` 的元素(如通用栈)原样透传。
180
+ */
190
181
  var serializeStacks = (stacks) => {
191
182
  const result = {};
192
183
  Object.entries(stacks).forEach(([id, undoRedo]) => {
193
- if (undoRedo) result[id] = undoRedo.serialize();
184
+ if (!undoRedo) return;
185
+ const serialized = undoRedo.serialize();
186
+ result[id] = {
187
+ ...serialized,
188
+ elementList: serialized.elementList.map((step) => step.diff === void 0 ? step : Object.assign({}, step, { diff: serialize(step.diff) }))
189
+ };
194
190
  });
195
191
  return result;
196
192
  };
197
193
  /**
198
194
  * 把 `Record<Id, SerializedUndoRedo>` 整体还原为 `Record<Id, UndoRedo>`。
199
195
  * 还原时把每个栈的游标定位到最近一条已保存(`saved === true`)记录之后。
196
+ *
197
+ * 与 {@link serializeStacks} 相反:当传入 `parse`(parseDSL)时,把每条 step 中以字符串形式存储的 `diff`
198
+ * 解析回真实对象(含函数);不含 `diff` 的元素(如通用栈)原样透传。
200
199
  */
201
- var deserializeStacks = (stacks = {}) => {
200
+ var deserializeStacks = (stacks = {}, parse) => {
202
201
  const result = {};
203
202
  Object.entries(stacks).forEach(([id, serialized]) => {
204
- if (serialized) result[id] = UndoRedo.fromSerialized(serialized, { isSavedStep: (element) => element.saved === true });
203
+ if (!serialized) return;
204
+ const elementList = parse ? serialized.elementList.map((step) => {
205
+ const { diff } = step;
206
+ return typeof diff === "string" ? Object.assign({}, step, { diff: parse(`(${diff})`) }) : step;
207
+ }) : serialized.elementList;
208
+ result[id] = UndoRedo.fromSerialized({
209
+ ...serialized,
210
+ elementList
211
+ }, { isSavedStep: (element) => element.saved === true });
205
212
  });
206
213
  return result;
207
214
  };
@@ -219,5 +226,7 @@ var getOrCreateStack = (stacks, id) => {
219
226
  var undoFloor = (undoRedo) => {
220
227
  return undoRedo.getElementList()[0]?.opType === "initial" ? 1 : 0;
221
228
  };
229
+ /** 将单次 push 产生的 history uuid(或 null)转为 *AndGetHistoryId 返回用的 uuid 列表。 */
230
+ var getLastPushedHistoryIds = (historyId) => historyId ? [historyId] : [];
222
231
  //#endregion
223
- export { createStackStep, describeRevertStep, deserializeStacks, detectPageTargetId, detectPageTargetName, detectStackOpType, getOrCreateStack, markStackSaved, mergePageSteps, mergeStackSteps, serializeStacks, undoFloor };
232
+ export { createStackStep, describeRevertStep, deserializeStacks, detectPageTargetId, detectPageTargetName, detectStackOpType, getLastPushedHistoryIds, getOrCreateStack, markStackSaved, mergePageSteps, mergeStackSteps, serializeStacks, undoFloor };
package/dist/style.css CHANGED
@@ -2093,9 +2093,12 @@ fieldset.m-fieldset .m-form-tip {
2093
2093
  .border-box-container .border-icon-container .border-icon + .border-icon {
2094
2094
  margin-left: 8px;
2095
2095
  }
2096
+ .border-box-container .border-icon-container .border-icon.configured {
2097
+ border-color: var(--el-color-success, var(--td-success-color, #2ba471));
2098
+ }
2096
2099
  .border-box-container .border-icon-container .border-icon.active {
2097
2100
  border-width: 1px;
2098
- border-color: var(--el-color-primary);
2101
+ border-color: var(--el-color-primary, var(--td-brand-color, #0052d9));
2099
2102
  }
2100
2103
  .border-box-container .border-icon-container .border-icon.border-icon-top {
2101
2104
  border-top-width: 2px;