@tmagic/editor 1.8.0-beta.1 → 1.8.0-beta.11

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 (232) hide show
  1. package/dist/es/Editor.vue_vue_type_script_setup_true_lang.js +31 -5
  2. package/dist/es/components/CodeBlockEditor.vue_vue_type_script_setup_true_lang.js +21 -113
  3. package/dist/es/components/CodeParams.vue_vue_type_script_setup_true_lang.js +7 -1
  4. package/dist/es/components/CompareForm.js +5 -0
  5. package/dist/es/components/CompareForm.vue_vue_type_script_setup_true_lang.js +196 -0
  6. package/dist/es/components/ContentMenu.vue_vue_type_script_setup_true_lang.js +1 -1
  7. package/dist/es/components/FloatingBox.vue_vue_type_script_setup_true_lang.js +2 -2
  8. package/dist/es/components/Icon.vue_vue_type_script_setup_true_lang.js +1 -1
  9. package/dist/es/components/Resizer.vue_vue_type_script_setup_true_lang.js +1 -1
  10. package/dist/es/components/ScrollBar.vue_vue_type_script_setup_true_lang.js +1 -1
  11. package/dist/es/components/ScrollViewer.vue_vue_type_script_setup_true_lang.js +1 -1
  12. package/dist/es/components/SearchInput.vue_vue_type_script_setup_true_lang.js +1 -1
  13. package/dist/es/components/SplitView.vue_vue_type_script_setup_true_lang.js +1 -1
  14. package/dist/es/components/ToolButton.vue_vue_type_script_setup_true_lang.js +7 -7
  15. package/dist/es/components/Tree.vue_vue_type_script_setup_true_lang.js +1 -1
  16. package/dist/es/components/TreeNode.vue_vue_type_script_setup_true_lang.js +1 -1
  17. package/dist/es/editorProps.js +2 -0
  18. package/dist/es/fields/Code.vue_vue_type_script_setup_true_lang.js +20 -4
  19. package/dist/es/fields/CodeLink.vue_vue_type_script_setup_true_lang.js +3 -6
  20. package/dist/es/fields/CodeSelect.vue_vue_type_script_setup_true_lang.js +19 -3
  21. package/dist/es/fields/CodeSelectCol.vue_vue_type_script_setup_true_lang.js +42 -8
  22. package/dist/es/fields/CondOpSelect.vue_vue_type_script_setup_true_lang.js +1 -1
  23. package/dist/es/fields/DataSourceFieldSelect/FieldSelect.vue_vue_type_script_setup_true_lang.js +14 -6
  24. package/dist/es/fields/DataSourceFieldSelect/Index.vue_vue_type_script_setup_true_lang.js +3 -3
  25. package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +41 -16
  26. package/dist/es/fields/DataSourceInput.vue_vue_type_script_setup_true_lang.js +2 -2
  27. package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +9 -5
  28. package/dist/es/fields/DataSourceMethods.vue_vue_type_script_setup_true_lang.js +40 -19
  29. package/dist/es/fields/DataSourceMocks.vue_vue_type_script_setup_true_lang.js +17 -9
  30. package/dist/es/fields/DataSourceSelect.vue_vue_type_script_setup_true_lang.js +4 -2
  31. package/dist/es/fields/DisplayConds.vue_vue_type_script_setup_true_lang.js +1 -1
  32. package/dist/es/fields/EventSelect.vue_vue_type_script_setup_true_lang.js +59 -12
  33. package/dist/es/fields/KeyValue.vue_vue_type_script_setup_true_lang.js +12 -7
  34. package/dist/es/fields/PageFragmentSelect.vue_vue_type_script_setup_true_lang.js +1 -1
  35. package/dist/es/fields/StyleSetter/Index.vue_vue_type_script_setup_true_lang.js +1 -1
  36. package/dist/es/fields/StyleSetter/components/BackgroundPosition.vue_vue_type_script_setup_true_lang.js +1 -1
  37. package/dist/es/fields/StyleSetter/components/Border.vue_vue_type_script_setup_true_lang.js +28 -6
  38. package/dist/es/fields/StyleSetter/components/Box.vue_vue_type_script_setup_true_lang.js +1 -1
  39. package/dist/es/fields/StyleSetter/icons/background-repeat/NoRepeat.js +1 -1
  40. package/dist/es/fields/StyleSetter/icons/background-repeat/Repeat.js +1 -1
  41. package/dist/es/fields/StyleSetter/icons/background-repeat/RepeatX.js +1 -1
  42. package/dist/es/fields/StyleSetter/icons/background-repeat/RepeatY.js +1 -1
  43. package/dist/es/fields/StyleSetter/icons/display/Block.js +1 -1
  44. package/dist/es/fields/StyleSetter/icons/display/Flex.js +1 -1
  45. package/dist/es/fields/StyleSetter/icons/display/Inline.js +1 -1
  46. package/dist/es/fields/StyleSetter/icons/display/InlineBlock.js +1 -1
  47. package/dist/es/fields/StyleSetter/icons/display/None.js +1 -1
  48. package/dist/es/fields/StyleSetter/icons/flex-direction/Column.js +1 -1
  49. package/dist/es/fields/StyleSetter/icons/flex-direction/ColumnReverse.js +1 -1
  50. package/dist/es/fields/StyleSetter/icons/flex-direction/Row.js +1 -1
  51. package/dist/es/fields/StyleSetter/icons/flex-direction/RowReverse.js +1 -1
  52. package/dist/es/fields/StyleSetter/icons/justify-content/Center.js +1 -1
  53. package/dist/es/fields/StyleSetter/icons/justify-content/FlexEnd.js +1 -1
  54. package/dist/es/fields/StyleSetter/icons/justify-content/FlexStart.js +1 -1
  55. package/dist/es/fields/StyleSetter/icons/justify-content/SpaceAround.js +1 -1
  56. package/dist/es/fields/StyleSetter/icons/justify-content/SpaceBetween.js +1 -1
  57. package/dist/es/fields/StyleSetter/icons/text-align/Center.js +1 -1
  58. package/dist/es/fields/StyleSetter/icons/text-align/Left.js +1 -1
  59. package/dist/es/fields/StyleSetter/icons/text-align/Right.js +1 -1
  60. package/dist/es/fields/StyleSetter/pro/Background.vue_vue_type_script_setup_true_lang.js +1 -1
  61. package/dist/es/fields/StyleSetter/pro/Border.vue_vue_type_script_setup_true_lang.js +1 -1
  62. package/dist/es/fields/StyleSetter/pro/Font.vue_vue_type_script_setup_true_lang.js +1 -1
  63. package/dist/es/fields/StyleSetter/pro/Layout.vue_vue_type_script_setup_true_lang.js +1 -1
  64. package/dist/es/fields/StyleSetter/pro/Position.vue_vue_type_script_setup_true_lang.js +1 -1
  65. package/dist/es/fields/StyleSetter/pro/Transform.vue_vue_type_script_setup_true_lang.js +1 -1
  66. package/dist/es/fields/UISelect.vue_vue_type_script_setup_true_lang.js +9 -6
  67. package/dist/es/hooks/use-code-block-edit.js +7 -4
  68. package/dist/es/hooks/use-data-source-edit.js +5 -2
  69. package/dist/es/hooks/use-stage.js +22 -10
  70. package/dist/es/icons/CenterIcon.vue_vue_type_script_setup_true_lang.js +1 -1
  71. package/dist/es/icons/CodeIcon.vue_vue_type_script_setup_true_lang.js +1 -1
  72. package/dist/es/icons/FolderMinusIcon.vue_vue_type_script_setup_true_lang.js +1 -1
  73. package/dist/es/index.js +14 -3
  74. package/dist/es/initService.js +7 -7
  75. package/dist/es/layouts/AddPageBox.vue_vue_type_script_setup_true_lang.js +1 -1
  76. package/dist/es/layouts/CodeEditor.vue_vue_type_script_setup_true_lang.js +7 -6
  77. package/dist/es/layouts/Framework.vue_vue_type_script_setup_true_lang.js +14 -9
  78. package/dist/es/layouts/NavMenu.vue_vue_type_script_setup_true_lang.js +12 -4
  79. package/dist/es/layouts/NavMenuColumn.vue_vue_type_script_setup_true_lang.js +1 -1
  80. package/dist/es/layouts/history-list/Bucket.js +5 -0
  81. package/dist/es/layouts/history-list/Bucket.vue_vue_type_script_setup_true_lang.js +71 -0
  82. package/dist/es/layouts/history-list/BucketTab.js +5 -0
  83. package/dist/es/layouts/history-list/BucketTab.vue_vue_type_script_setup_true_lang.js +62 -0
  84. package/dist/es/layouts/history-list/GroupRow.js +5 -0
  85. package/dist/es/layouts/history-list/GroupRow.vue_vue_type_script_setup_true_lang.js +269 -0
  86. package/dist/es/layouts/history-list/HistoryDiffDialog.js +5 -0
  87. package/dist/es/layouts/history-list/HistoryDiffDialog.vue_vue_type_script_setup_true_lang.js +294 -0
  88. package/dist/es/layouts/history-list/HistoryListPanel.js +5 -0
  89. package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +327 -0
  90. package/dist/es/layouts/history-list/InitialRow.js +5 -0
  91. package/dist/es/layouts/history-list/InitialRow.vue_vue_type_script_setup_true_lang.js +83 -0
  92. package/dist/es/layouts/history-list/PageTab.js +5 -0
  93. package/dist/es/layouts/history-list/PageTab.vue_vue_type_script_setup_true_lang.js +95 -0
  94. package/dist/es/layouts/history-list/composables.js +184 -0
  95. package/dist/es/layouts/history-list/useHistoryList.js +56 -0
  96. package/dist/es/layouts/history-list/useHistoryRevert.js +313 -0
  97. package/dist/es/layouts/page-bar/AddButton.vue_vue_type_script_setup_true_lang.js +1 -1
  98. package/dist/es/layouts/page-bar/PageBar.vue_vue_type_script_setup_true_lang.js +5 -3
  99. package/dist/es/layouts/page-bar/PageBarScrollContainer.vue_vue_type_script_setup_true_lang.js +1 -1
  100. package/dist/es/layouts/page-bar/PageList.vue_vue_type_script_setup_true_lang.js +1 -1
  101. package/dist/es/layouts/page-bar/Search.vue_vue_type_script_setup_true_lang.js +2 -2
  102. package/dist/es/layouts/props-panel/FormPanel.vue_vue_type_script_setup_true_lang.js +1 -1
  103. package/dist/es/layouts/props-panel/PropsPanel.vue_vue_type_script_setup_true_lang.js +6 -2
  104. package/dist/es/layouts/sidebar/ComponentListPanel.vue_vue_type_script_setup_true_lang.js +2 -2
  105. package/dist/es/layouts/sidebar/Sidebar.vue_vue_type_script_setup_true_lang.js +8 -4
  106. package/dist/es/layouts/sidebar/code-block/CodeBlockList.vue_vue_type_script_setup_true_lang.js +4 -4
  107. package/dist/es/layouts/sidebar/code-block/CodeBlockListPanel.vue_vue_type_script_setup_true_lang.js +2 -2
  108. package/dist/es/layouts/sidebar/code-block/useContentMenu.js +1 -1
  109. package/dist/es/layouts/sidebar/data-source/DataSourceAddButton.vue_vue_type_script_setup_true_lang.js +1 -1
  110. package/dist/es/layouts/sidebar/data-source/DataSourceConfigPanel.vue_vue_type_script_setup_true_lang.js +19 -6
  111. package/dist/es/layouts/sidebar/data-source/DataSourceList.vue_vue_type_script_setup_true_lang.js +1 -1
  112. package/dist/es/layouts/sidebar/data-source/DataSourceListPanel.vue_vue_type_script_setup_true_lang.js +25 -3
  113. package/dist/es/layouts/sidebar/data-source/useContentMenu.js +1 -1
  114. package/dist/es/layouts/sidebar/layer/LayerMenu.vue_vue_type_script_setup_true_lang.js +6 -6
  115. package/dist/es/layouts/sidebar/layer/LayerNodeTool.vue_vue_type_script_setup_true_lang.js +2 -2
  116. package/dist/es/layouts/sidebar/layer/LayerPanel.vue_vue_type_script_setup_true_lang.js +1 -1
  117. package/dist/es/layouts/sidebar/layer/use-node-status.js +1 -1
  118. package/dist/es/layouts/workspace/Breadcrumb.vue_vue_type_script_setup_true_lang.js +1 -1
  119. package/dist/es/layouts/workspace/Workspace.vue_vue_type_script_setup_true_lang.js +1 -1
  120. package/dist/es/layouts/workspace/viewer/NodeListMenu.vue_vue_type_script_setup_true_lang.js +1 -1
  121. package/dist/es/layouts/workspace/viewer/Stage.vue_vue_type_script_setup_true_lang.js +2 -2
  122. package/dist/es/layouts/workspace/viewer/StageOverlay.vue_vue_type_script_setup_true_lang.js +1 -1
  123. package/dist/es/layouts/workspace/viewer/ViewerMenu.vue_vue_type_script_setup_true_lang.js +9 -9
  124. package/dist/es/services/BaseService.js +31 -68
  125. package/dist/es/services/codeBlock.js +286 -8
  126. package/dist/es/services/componentList.js +2 -2
  127. package/dist/es/services/dataSource.js +287 -8
  128. package/dist/es/services/dep.js +21 -9
  129. package/dist/es/services/editor.js +655 -194
  130. package/dist/es/services/events.js +2 -2
  131. package/dist/es/services/history.js +390 -47
  132. package/dist/es/services/keybinding.js +5 -5
  133. package/dist/es/services/props.js +8 -8
  134. package/dist/es/services/stageOverlay.js +2 -2
  135. package/dist/es/services/storage.js +2 -2
  136. package/dist/es/services/ui.js +5 -2
  137. package/dist/es/style.css +456 -8
  138. package/dist/es/utils/code-block.js +122 -0
  139. package/dist/es/utils/content-menu.js +19 -12
  140. package/dist/es/utils/data-source/index.js +2 -0
  141. package/dist/es/utils/dep/worker.js +1 -1
  142. package/dist/es/utils/editor.js +105 -51
  143. package/dist/es/utils/history.js +220 -0
  144. package/dist/es/utils/indexed-db.js +86 -0
  145. package/dist/es/utils/undo-redo.js +80 -1
  146. package/dist/style.css +456 -8
  147. package/dist/tmagic-editor.umd.cjs +11149 -6646
  148. package/package.json +8 -8
  149. package/src/Editor.vue +25 -1
  150. package/src/components/CodeBlockEditor.vue +20 -109
  151. package/src/components/CodeParams.vue +6 -0
  152. package/src/components/CompareForm.vue +277 -0
  153. package/src/components/ToolButton.vue +2 -2
  154. package/src/editorProps.ts +9 -0
  155. package/src/fields/Code.vue +19 -3
  156. package/src/fields/CodeLink.vue +2 -5
  157. package/src/fields/CodeSelect.vue +17 -1
  158. package/src/fields/CodeSelectCol.vue +37 -3
  159. package/src/fields/DataSourceFieldSelect/FieldSelect.vue +23 -3
  160. package/src/fields/DataSourceFieldSelect/Index.vue +2 -2
  161. package/src/fields/DataSourceFields.vue +48 -10
  162. package/src/fields/DataSourceInput.vue +3 -3
  163. package/src/fields/DataSourceMethodSelect.vue +12 -4
  164. package/src/fields/DataSourceMethods.vue +55 -24
  165. package/src/fields/DataSourceMocks.vue +13 -3
  166. package/src/fields/DataSourceSelect.vue +4 -1
  167. package/src/fields/EventSelect.vue +57 -8
  168. package/src/fields/KeyValue.vue +17 -4
  169. package/src/fields/StyleSetter/components/Border.vue +15 -6
  170. package/src/fields/UISelect.vue +5 -2
  171. package/src/hooks/use-code-block-edit.ts +9 -5
  172. package/src/hooks/use-data-source-edit.ts +2 -2
  173. package/src/hooks/use-stage.ts +26 -9
  174. package/src/index.ts +8 -0
  175. package/src/initService.ts +1 -1
  176. package/src/layouts/CodeEditor.vue +17 -5
  177. package/src/layouts/Framework.vue +11 -6
  178. package/src/layouts/NavMenu.vue +12 -3
  179. package/src/layouts/history-list/Bucket.vue +91 -0
  180. package/src/layouts/history-list/BucketTab.vue +72 -0
  181. package/src/layouts/history-list/GroupRow.vue +304 -0
  182. package/src/layouts/history-list/HistoryDiffDialog.vue +281 -0
  183. package/src/layouts/history-list/HistoryListPanel.vue +367 -0
  184. package/src/layouts/history-list/InitialRow.vue +71 -0
  185. package/src/layouts/history-list/PageTab.vue +118 -0
  186. package/src/layouts/history-list/composables.ts +309 -0
  187. package/src/layouts/history-list/useHistoryList.ts +60 -0
  188. package/src/layouts/history-list/useHistoryRevert.ts +421 -0
  189. package/src/layouts/page-bar/PageBar.vue +4 -2
  190. package/src/layouts/props-panel/PropsPanel.vue +5 -1
  191. package/src/layouts/sidebar/ComponentListPanel.vue +9 -5
  192. package/src/layouts/sidebar/Sidebar.vue +8 -3
  193. package/src/layouts/sidebar/code-block/CodeBlockList.vue +5 -5
  194. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +1 -1
  195. package/src/layouts/sidebar/code-block/useContentMenu.ts +1 -1
  196. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +31 -2
  197. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +27 -2
  198. package/src/layouts/sidebar/data-source/useContentMenu.ts +1 -1
  199. package/src/layouts/sidebar/layer/LayerMenu.vue +19 -11
  200. package/src/layouts/sidebar/layer/LayerNodeTool.vue +7 -4
  201. package/src/layouts/sidebar/layer/use-node-status.ts +9 -6
  202. package/src/layouts/workspace/viewer/Stage.vue +1 -1
  203. package/src/layouts/workspace/viewer/ViewerMenu.vue +8 -8
  204. package/src/services/BaseService.ts +35 -86
  205. package/src/services/codeBlock.ts +361 -5
  206. package/src/services/dataSource.ts +336 -6
  207. package/src/services/dep.ts +32 -9
  208. package/src/services/editor.ts +834 -194
  209. package/src/services/history.ts +509 -49
  210. package/src/services/keybinding.ts +3 -3
  211. package/src/services/props.ts +2 -2
  212. package/src/services/ui.ts +7 -0
  213. package/src/theme/history-list-panel.scss +557 -0
  214. package/src/theme/page-bar.scss +0 -4
  215. package/src/theme/props-panel.scss +3 -3
  216. package/src/theme/style-setter/border.scss +4 -1
  217. package/src/theme/theme.scss +1 -0
  218. package/src/type.ts +613 -31
  219. package/src/utils/code-block.ts +150 -0
  220. package/src/utils/content-menu.ts +25 -13
  221. package/src/utils/data-source/index.ts +2 -0
  222. package/src/utils/dep/worker.ts +5 -3
  223. package/src/utils/editor.ts +166 -60
  224. package/src/utils/history.ts +286 -0
  225. package/src/utils/index.ts +3 -0
  226. package/src/utils/indexed-db.ts +122 -0
  227. package/src/utils/undo-redo.ts +111 -0
  228. package/types/index.d.ts +3197 -896
  229. package/dist/es/utils/compose.js +0 -44
  230. package/dist/es/utils/editor-history.js +0 -100
  231. package/src/utils/compose.ts +0 -52
  232. package/src/utils/editor-history.ts +0 -138
@@ -1,4 +1,4 @@
1
- import BaseService_default from "./BaseService.js";
1
+ import BaseService from "./BaseService.js";
2
2
  import { toLine } from "@tmagic/utils";
3
3
  import { reactive } from "vue";
4
4
  import { cloneDeep } from "lodash-es";
@@ -14,7 +14,7 @@ var canUsePluginMethods = {
14
14
  };
15
15
  var eventMap = reactive({});
16
16
  var methodMap = reactive({});
17
- var Events = class extends BaseService_default {
17
+ var Events = class extends BaseService {
18
18
  constructor() {
19
19
  super([...canUsePluginMethods.async.map((methodName) => ({
20
20
  name: methodName,
@@ -1,59 +1,196 @@
1
- import BaseService_default from "./BaseService.js";
1
+ import BaseService from "./BaseService.js";
2
+ import { getEditorConfig } from "../utils/config.js";
2
3
  import { UndoRedo } from "../utils/undo-redo.js";
4
+ import { deserializeStacks, getOrCreateStack, markStackSaved, mergeSteps, serializeStacks, undoFloor } from "../utils/history.js";
5
+ import { idbGet, idbSet } from "../utils/indexed-db.js";
6
+ import editor_default from "./editor.js";
7
+ import { guid } from "@tmagic/utils";
3
8
  import { reactive } from "vue";
4
9
  //#region packages/editor/src/services/history.ts
5
- var History = class extends BaseService_default {
10
+ var canUsePluginMethods = { sync: [
11
+ "push",
12
+ "undo",
13
+ "redo"
14
+ ] };
15
+ /** 各内置历史类型的默认展示名称(用于历史面板 tab / 分组标题等)。扩展类型可通过 registerStepType / setStepName 登记。 */
16
+ var DEFAULT_STEP_NAMES = {
17
+ page: "页面",
18
+ codeBlock: "代码块",
19
+ dataSource: "数据源"
20
+ };
21
+ /** 各历史类型对应的分组 `kind`(展示用):page→page,codeBlock→code-block,dataSource→data-source。扩展类型缺省回退到 stepType 本身。 */
22
+ var STEP_TYPE_KIND = {
23
+ page: "page",
24
+ codeBlock: "code-block",
25
+ dataSource: "data-source"
26
+ };
27
+ /** 历史记录持久化快照的默认存储位置与结构版本。 */
28
+ var DEFAULT_DB_NAME = "tmagic-editor";
29
+ var DEFAULT_STORE_NAME = "history";
30
+ var DEFAULT_KEY = "default";
31
+ var PERSIST_VERSION = 3;
32
+ var History = class extends BaseService {
6
33
  state = reactive({
7
- pageSteps: {},
8
- pageId: void 0,
9
- canRedo: false,
10
- canUndo: false
34
+ steps: {
35
+ page: {},
36
+ codeBlock: {},
37
+ dataSource: {}
38
+ },
39
+ stepNames: { ...DEFAULT_STEP_NAMES }
11
40
  });
12
41
  constructor() {
13
- super([]);
14
- this.on("change", this.setCanUndoRedo);
42
+ super([...canUsePluginMethods.sync.map((methodName) => ({
43
+ name: methodName,
44
+ isAsync: false
45
+ }))]);
15
46
  }
16
- reset() {
17
- this.state.pageSteps = {};
18
- this.resetPage();
47
+ /**
48
+ * 注册一个扩展历史类型,使其可与内置 `page` / `codeBlock` / `dataSource` 一样走统一的
49
+ * {@link push} / {@link undo} / {@link redo}(按 id 分栈、独立 undo/redo)。
50
+ *
51
+ * @param stepType 自定义历史类型标识(勿与内置类型重名)
52
+ * @param options.event push/undo/redo 后派发的事件名,缺省为 `${stepType}-history-change`
53
+ * @param options.name 历史面板中的展示名称(tab / 分组标题等),缺省回退到 stepType 本身
54
+ */
55
+ registerStepType(stepType, options = {}) {
56
+ this.getStepBucket(stepType);
57
+ if (options.name !== void 0) this.state.stepNames[stepType] = options.name;
19
58
  }
20
- resetPage() {
21
- this.state.pageId = void 0;
22
- this.state.canRedo = false;
23
- this.state.canUndo = false;
59
+ /**
60
+ * 读取指定历史类型的展示名称(用于历史面板 tab / 分组标题等)。
61
+ * 未登记名称时回退到 stepType 本身。
62
+ */
63
+ getStepName(stepType) {
64
+ return this.state.stepNames[stepType] ?? `${stepType}`;
24
65
  }
25
- changePage(page) {
26
- if (!page) return;
27
- this.state.pageId = page.id;
28
- if (!this.state.pageSteps[this.state.pageId]) this.state.pageSteps[this.state.pageId] = new UndoRedo();
29
- this.setCanUndoRedo();
30
- this.emit("page-change", this.state.pageSteps[this.state.pageId]);
66
+ /**
67
+ * 设置指定历史类型的展示名称(用于历史面板 tab / 分组标题等)。
68
+ * 内置 `page` / `codeBlock` / `dataSource` 也可在此覆盖默认中文名。
69
+ */
70
+ setStepName(stepType, name) {
71
+ this.state.stepNames[stepType] = name;
72
+ }
73
+ reset() {
74
+ this.clearAllSteps();
31
75
  }
32
76
  resetState() {
33
- this.state.pageId = void 0;
34
- this.state.pageSteps = {};
35
- this.state.canRedo = false;
36
- this.state.canUndo = false;
77
+ this.clearAllSteps();
37
78
  }
38
- push(state) {
39
- const undoRedo = this.getUndoRedo();
40
- if (!undoRedo) return null;
41
- undoRedo.pushElement(state);
42
- this.emit("change", state);
43
- return state;
79
+ /**
80
+ * 为指定历史栈(默认 `page`,也适用于 codeBlock / dataSource / 扩展类型)种入一条「初始基线」记录。
81
+ *
82
+ * 该记录是一条 `opType: 'initial'` 的 step,作为对应栈 **index 0 的固定底线**:
83
+ * - 它是一条真实入栈的 step(随栈一起持久化),但被钉为撤销/回滚的下限——cursor 永不低于它,
84
+ * 因此不会被 undo / goto / revert 触达(详见 {@link undo} / {@link undoFloor});
85
+ * - 历史面板把它过滤出分组列表(见 {@link getHistoryGroups}),改由底部「初始」行展示。
86
+ *
87
+ * 仅当目标栈为空时种入(保证 initial 一定位于 index 0);已存在 initial 底线时不重复种入。
88
+ *
89
+ * @param stepType 历史类型
90
+ * @param id 目标栈 id(page 为 pageId,其余类型为对应资源 id)
91
+ * @param options 基线展示信息(名称 / 描述 / 来源)
92
+ */
93
+ setMarker(stepType, id, options = {}) {
94
+ if (!this.isValidStackId(id)) return null;
95
+ const existing = this.getMarker(stepType, id);
96
+ if (existing) return existing;
97
+ const stack = getOrCreateStack(this.getStepBucket(stepType), id);
98
+ if (stack.getLength() > 0) return null;
99
+ const marker = {
100
+ uuid: guid(),
101
+ opType: "initial",
102
+ diff: [],
103
+ data: {
104
+ name: options.name || "",
105
+ id
106
+ },
107
+ extra: {
108
+ ...options.extra || {},
109
+ ...stepType === "page" ? {
110
+ selectedBefore: [],
111
+ selectedAfter: [],
112
+ modifiedNodeIds: /* @__PURE__ */ new Map()
113
+ } : {}
114
+ },
115
+ historyDescription: options.description || "未修改的初始状态",
116
+ timestamp: Date.now(),
117
+ ...options.source ? { source: options.source } : {}
118
+ };
119
+ stack.pushElement(marker);
120
+ this.emit("marker-change", {
121
+ id,
122
+ marker,
123
+ stepType
124
+ });
125
+ return marker;
44
126
  }
45
- undo() {
46
- const undoRedo = this.getUndoRedo();
127
+ /**
128
+ * 读取指定历史栈的初始基线 step(栈 index 0 且 `opType: 'initial'`);
129
+ * 不存在或 id 缺省时返回 undefined。
130
+ */
131
+ getMarker(stepType, id) {
132
+ if (!this.isValidStackId(id)) return void 0;
133
+ const first = this.state.steps[stepType]?.[id]?.getElementList()[0];
134
+ return first?.opType === "initial" ? first : void 0;
135
+ }
136
+ push(stepType, step, id) {
137
+ if (!this.isValidStackId(id)) return null;
138
+ this.fillStepMeta(step);
139
+ getOrCreateStack(this.getStepBucket(stepType), id).pushElement(step);
140
+ this.emit("change", step, stepType, id);
141
+ return step;
142
+ }
143
+ undo(stepType, id) {
144
+ if (!this.isValidStackId(id)) return null;
145
+ const undoRedo = this.state.steps[stepType]?.[id];
47
146
  if (!undoRedo) return null;
48
- const state = undoRedo.undo();
49
- this.emit("change", state);
50
- return state;
147
+ if (undoRedo.getCursor() <= undoFloor(undoRedo)) return null;
148
+ const step = undoRedo.undo();
149
+ if (step) this.emit("change", step, stepType, id);
150
+ return step;
51
151
  }
52
- redo() {
53
- const undoRedo = this.getUndoRedo();
152
+ redo(stepType, id) {
153
+ if (!this.isValidStackId(id)) return null;
154
+ const undoRedo = this.state.steps[stepType]?.[id];
54
155
  if (!undoRedo) return null;
55
- const state = undoRedo.redo();
56
- this.emit("change", state);
156
+ const step = undoRedo.redo();
157
+ if (step) this.emit("change", step, stepType, id);
158
+ return step;
159
+ }
160
+ /**
161
+ * 是否可对指定历史栈撤销(cursor 高于 initial 基线底线)。
162
+ * @param stepType 历史类型
163
+ * @param id 目标栈 id;缺省 / 无效时返回 false
164
+ */
165
+ canUndo(stepType, id) {
166
+ if (!this.isValidStackId(id)) return false;
167
+ const undoRedo = this.state.steps[stepType]?.[id];
168
+ return undoRedo ? undoRedo.getCursor() > undoFloor(undoRedo) : false;
169
+ }
170
+ /**
171
+ * 是否可对指定历史栈重做。
172
+ * @param stepType 历史类型
173
+ * @param id 目标栈 id;缺省 / 无效时返回 false
174
+ */
175
+ canRedo(stepType, id) {
176
+ if (!this.isValidStackId(id)) return false;
177
+ return this.state.steps[stepType]?.[id]?.canRedo() ?? false;
178
+ }
179
+ /** 读取指定页面历史栈当前游标所在的 step(cursor - 1);无则返回 null。 */
180
+ getCurrentPageStep(pageId) {
181
+ if (!this.isValidStackId(pageId)) return null;
182
+ return this.state.steps.page[pageId]?.getCurrentElement() ?? null;
183
+ }
184
+ /**
185
+ * 用 `state` 替换指定页面栈当前游标所在的 step(并丢弃其后的重做尾部),游标不变。
186
+ * 用于「连续 set root 记录合并」等就地替换最新一条的场景;替换成功后派发 `change`。
187
+ */
188
+ replaceCurrentStep(stepType, state, id) {
189
+ if (!this.isValidStackId(id)) return null;
190
+ const undoRedo = getOrCreateStack(this.getStepBucket(stepType), id);
191
+ this.fillStepMeta(state);
192
+ if (!undoRedo.replaceCurrentElement(state)) return null;
193
+ this.emit("change", state, stepType, id);
57
194
  return state;
58
195
  }
59
196
  destroy() {
@@ -61,14 +198,220 @@ var History = class extends BaseService_default {
61
198
  this.removeAllListeners();
62
199
  this.removeAllPlugins();
63
200
  }
64
- getUndoRedo() {
65
- if (!this.state.pageId) return null;
66
- return this.state.pageSteps[this.state.pageId];
201
+ /**
202
+ * 清空历史记录栈。统一入口,所有类型(page / codeBlock / dataSource / 扩展)行为一致:
203
+ * - 传入 `id`:仅清空 `stepType` 下该 id 对应的栈;
204
+ * - 缺省 `id`:清空 `stepType` 下的全部栈。
205
+ *
206
+ * 仅删除撤销/重做记录,不会改动 DSL / 代码块 / 数据源本身。清空时会**保留各栈原有的
207
+ * initial 基线**(文案 / 来源),无基线时清空成空栈。清空后派发 `clear`(签名 `(id, stepType)`)。
208
+ *
209
+ * @param stepType 历史类型
210
+ * @param id 目标栈 id;缺省表示清空该类型下全部栈
211
+ */
212
+ clear(stepType, id) {
213
+ const bucket = this.state.steps[stepType];
214
+ if (!bucket) return;
215
+ if (this.isValidStackId(id)) this.clearStack(stepType, id);
216
+ else if (id === void 0) Object.keys(bucket).forEach((stackId) => this.clearStack(stepType, stackId));
217
+ else return;
218
+ this.emit("clear", {
219
+ id,
220
+ stepType
221
+ });
222
+ }
223
+ /**
224
+ * 标记历史记录为「已保存」(把对应栈当前游标所在的记录标为 `saved`)。统一入口:
225
+ * - 缺省 `id`:标记**全部类型、全部栈**(整份 DSL 落库场景),派发 `mark-saved` 且 `kind: 'all'`;
226
+ * - 传入 `id`:仅标记 `stepType` 下该 id 对应的栈,派发 `mark-saved` 且 `kind` 为 `stepType`。
227
+ *
228
+ * 同一栈内任意时刻最多只有一条记录为 `saved`;从 IndexedDB 恢复时游标会被定位到最近一条已保存记录之后。
229
+ *
230
+ * @param stepType 历史类型
231
+ * @param id 目标栈 id;缺省表示标记全部类型 / 全部栈
232
+ */
233
+ markSaved(stepType, id) {
234
+ if (id === void 0) {
235
+ Object.values(this.state.steps).forEach((bucket) => Object.values(bucket).forEach(markStackSaved));
236
+ this.emit("mark-saved", { kind: "all" });
237
+ return;
238
+ }
239
+ if (!this.isValidStackId(id)) return;
240
+ markStackSaved(this.state.steps[stepType]?.[id]);
241
+ this.emit("mark-saved", {
242
+ kind: stepType,
243
+ id
244
+ });
245
+ }
246
+ /**
247
+ * 把当前内存中的全部历史栈(页面 / 代码块 / 数据源 / 扩展类型)序列化后写入本地 IndexedDB。
248
+ *
249
+ * - 每个 UndoRedo 栈连同其游标、容量一并保存,恢复后可继续 undo/redo;
250
+ * - `key` 用于区分不同活动页 / 项目(同一 store 下可保存多份快照),缺省为 `default`;
251
+ * - 返回写入成功的快照对象,便于调用方记录 savedAt 等信息;
252
+ * - 不支持 IndexedDB 的环境(如 SSR)会 reject。
253
+ */
254
+ async saveToIndexedDB(options = {}) {
255
+ const { dbName = DEFAULT_DB_NAME, storeName = DEFAULT_STORE_NAME, key = DEFAULT_KEY, appId } = options;
256
+ const steps = {
257
+ page: {},
258
+ codeBlock: {},
259
+ dataSource: {}
260
+ };
261
+ Object.entries(this.state.steps).forEach(([stepType, bucket]) => {
262
+ steps[stepType] = serializeStacks(bucket);
263
+ });
264
+ const snapshot = {
265
+ version: PERSIST_VERSION,
266
+ steps,
267
+ savedAt: Date.now()
268
+ };
269
+ await idbSet(this.resolveDbName(dbName, appId), storeName, key, snapshot);
270
+ this.emit("save-to-indexed-db", snapshot);
271
+ return snapshot;
272
+ }
273
+ /**
274
+ * 从本地 IndexedDB 读取此前保存的历史快照并重建全部撤销/重做栈。
275
+ *
276
+ * - 读取到的每个栈都会经 {@link UndoRedo.fromSerialized} 还原(含游标),随后可直接 undo/redo;
277
+ * - 会整体覆盖当前内存中的历史状态(活动页由 editorService 维护,不在此恢复);
278
+ * - 找不到对应记录时返回 null,且不改动当前状态;
279
+ * - 不支持 IndexedDB 的环境(如 SSR)会 reject。
280
+ */
281
+ async restoreFromIndexedDB(options = {}) {
282
+ const { dbName = DEFAULT_DB_NAME, storeName = DEFAULT_STORE_NAME, key = DEFAULT_KEY, appId } = options;
283
+ const snapshot = await idbGet(this.resolveDbName(dbName, appId), storeName, key);
284
+ if (!snapshot) return null;
285
+ const parseDSL = getEditorConfig("parseDSL");
286
+ const steps = {
287
+ page: {},
288
+ codeBlock: {},
289
+ dataSource: {}
290
+ };
291
+ Object.entries(snapshot.steps).forEach(([stepType, bucket]) => {
292
+ steps[stepType] = deserializeStacks(bucket, parseDSL);
293
+ });
294
+ this.state.steps = steps;
295
+ this.emit("restore-from-indexed-db", snapshot);
296
+ return snapshot;
297
+ }
298
+ getStepList(stepType, id) {
299
+ if (!this.isValidStackId(id)) return [];
300
+ const undoRedo = this.state.steps[stepType]?.[id];
301
+ if (!undoRedo) return [];
302
+ const list = undoRedo.getElementList();
303
+ const cursor = undoRedo.getCursor();
304
+ return list.map((step, index) => ({
305
+ step,
306
+ index,
307
+ applied: index < cursor
308
+ }));
309
+ }
310
+ getHistoryGroups(stepType, id) {
311
+ const bucket = this.state.steps[stepType];
312
+ if (!bucket) return [];
313
+ const kind = STEP_TYPE_KIND[stepType] ?? stepType;
314
+ const collect = (stackId) => {
315
+ const undoRedo = bucket[stackId];
316
+ if (!undoRedo) return [];
317
+ const list = undoRedo.getElementList();
318
+ if (!list.length) return [];
319
+ return mergeSteps(kind, stackId, list, undoRedo.getCursor()).filter((group) => group.opType !== "initial");
320
+ };
321
+ if (this.isValidStackId(id)) return collect(id);
322
+ return Object.keys(bucket).flatMap((stackId) => collect(stackId));
323
+ }
324
+ /**
325
+ * 读取指定历史栈的当前游标(已应用步骤数量)。统一入口,替代旧的
326
+ * `getPageCursor` / `getCodeBlockCursor` / `getDataSourceCursor`。
327
+ * - `id` 缺省或非法、或对应栈不存在时返回 0;
328
+ * - `stepType` 支持 `page` / `codeBlock` / `dataSource` / 扩展类型。
329
+ */
330
+ getCursor(stepType, id) {
331
+ if (!this.isValidStackId(id)) return 0;
332
+ return this.state.steps[stepType]?.[id]?.getCursor() ?? 0;
333
+ }
334
+ /**
335
+ * 按历史记录 uuid 在指定历史类型的栈中查找其所属 id 与索引,统一入口,替代旧的
336
+ * `getPageStepIndexByUuid` / `findCodeBlockStepLocationByUuid` / `findDataSourceStepLocationByUuid`。
337
+ *
338
+ * - 传入 `id`:仅在该 id 对应的单个栈中查找(如页面历史按活动页查看,传入 pageId);
339
+ * - 缺省 `id`:遍历该类型下全部栈查找(代码块 / 数据源等按全部资源分桶的场景)。
340
+ *
341
+ * 找不到时返回 null。供「按 uuid 回滚」等需要把 uuid 映射回 (id, index) 的场景使用。
342
+ *
343
+ * @param stepType 历史类型
344
+ * @param uuid 目标历史记录的 uuid
345
+ * @param id 目标栈 id;缺省表示遍历该类型下全部栈
346
+ */
347
+ findStepLocationByUuid(stepType, uuid, id) {
348
+ if (!uuid) return null;
349
+ const bucket = this.state.steps[stepType];
350
+ if (!bucket) return null;
351
+ if (this.isValidStackId(id)) {
352
+ const index = this.getStepList(stepType, id).findIndex((entry) => entry.step.uuid === uuid);
353
+ return index >= 0 ? {
354
+ id,
355
+ index
356
+ } : null;
357
+ }
358
+ for (const stackId of Object.keys(bucket)) {
359
+ const index = this.getStepList(stepType, stackId).findIndex((entry) => entry.step.uuid === uuid);
360
+ if (index >= 0) return {
361
+ id: stackId,
362
+ index
363
+ };
364
+ }
365
+ return null;
366
+ }
367
+ usePlugin(options) {
368
+ super.usePlugin(options);
369
+ }
370
+ emit(eventName, ...args) {
371
+ return super.emit(eventName, ...args);
372
+ }
373
+ /**
374
+ * 取出指定历史类型的栈桶(`Record<id, UndoRedo>`);不存在时按需创建空桶,
375
+ * 从而支持通过 {@link registerStepType} 或首次 push 动态扩展历史类型。
376
+ */
377
+ getStepBucket(stepType) {
378
+ if (!this.state.steps[stepType]) this.state.steps[stepType] = {};
379
+ return this.state.steps[stepType];
380
+ }
381
+ /**
382
+ * 清空单个历史栈并按需重建其 initial 基线(保留原基线的文案 / 来源)。
383
+ */
384
+ clearStack(stepType, id) {
385
+ const marker = this.getMarker(stepType, id);
386
+ this.getStepBucket(stepType)[id] = new UndoRedo();
387
+ if (marker) this.setMarker(stepType, id, {
388
+ name: marker.data?.name,
389
+ description: marker.historyDescription,
390
+ source: marker.source
391
+ });
392
+ }
393
+ /** 入栈前补全 step 的 uuid / timestamp(调用方未指定时)。 */
394
+ fillStepMeta(step) {
395
+ if (step.uuid === void 0) step.uuid = guid();
396
+ if (step.timestamp === void 0) step.timestamp = Date.now();
397
+ }
398
+ /** 校验「按 id 分栈」类型(codeBlock / dataSource / 扩展)的 id 是否有效。 */
399
+ isValidStackId(id) {
400
+ return id !== void 0 && id !== null && `${id}` !== "";
401
+ }
402
+ /** 清空全部历史栈内容(保留已注册的类型键,使扩展类型在 reset 后仍可用)。 */
403
+ clearAllSteps() {
404
+ Object.keys(this.state.steps).forEach((stepType) => {
405
+ this.state.steps[stepType] = {};
406
+ });
67
407
  }
68
- setCanUndoRedo() {
69
- const undoRedo = this.getUndoRedo();
70
- this.state.canRedo = undoRedo?.canRedo() || false;
71
- this.state.canUndo = undoRedo?.canUndo() || false;
408
+ /**
409
+ * 把基础 dbName 与当前 DSL(root app)的 id 拼成最终库名,实现不同应用历史隔离。
410
+ * 取不到 app id(如尚未加载 DSL)时退回基础 dbName。
411
+ */
412
+ resolveDbName(dbName, appId) {
413
+ const resolvedAppId = appId ?? editor_default.get("root")?.id;
414
+ return resolvedAppId ? `${dbName}-${resolvedAppId}` : dbName;
72
415
  }
73
416
  };
74
417
  var history_default = new History();
@@ -1,11 +1,11 @@
1
1
  import { KeyBindingCommand } from "../type.js";
2
- import BaseService_default from "./BaseService.js";
2
+ import BaseService from "./BaseService.js";
3
3
  import editor_default from "./editor.js";
4
4
  import ui_default from "./ui.js";
5
5
  import { isPage, isPageFragment } from "@tmagic/utils";
6
6
  import KeyController from "keycon";
7
7
  //#region packages/editor/src/services/keybinding.ts
8
- var Keybinding = class extends BaseService_default {
8
+ var Keybinding = class extends BaseService {
9
9
  ctrlKey = /mac os x/.test(navigator.userAgent.toLowerCase()) ? "meta" : "ctrl";
10
10
  controllers = /* @__PURE__ */ new Map();
11
11
  bindingList = [];
@@ -13,7 +13,7 @@ var Keybinding = class extends BaseService_default {
13
13
  [KeyBindingCommand.DELETE_NODE]: () => {
14
14
  const nodes = editor_default.get("nodes");
15
15
  if (!nodes || isPage(nodes[0]) || isPageFragment(nodes[0])) return;
16
- editor_default.remove(nodes);
16
+ editor_default.remove(nodes, { historySource: "shortcut" });
17
17
  },
18
18
  [KeyBindingCommand.COPY_NODE]: () => {
19
19
  const nodes = editor_default.get("nodes");
@@ -23,13 +23,13 @@ var Keybinding = class extends BaseService_default {
23
23
  const nodes = editor_default.get("nodes");
24
24
  if (!nodes || isPage(nodes[0]) || isPageFragment(nodes[0])) return;
25
25
  editor_default.copy(nodes);
26
- editor_default.remove(nodes);
26
+ editor_default.remove(nodes, { historySource: "shortcut" });
27
27
  },
28
28
  [KeyBindingCommand.PASTE_NODE]: () => {
29
29
  editor_default.get("nodes") && editor_default.paste({
30
30
  offsetX: 10,
31
31
  offsetY: 10
32
- });
32
+ }, void 0, { historySource: "shortcut" });
33
33
  },
34
34
  [KeyBindingCommand.UNDO]: () => {
35
35
  editor_default.undo();
@@ -1,10 +1,10 @@
1
- import BaseService_default from "./BaseService.js";
1
+ import BaseService from "./BaseService.js";
2
2
  import { fillConfig } from "../utils/props.js";
3
3
  import editor_default from "./editor.js";
4
4
  import { getNodePath, getValueByKeyPath, guid, setValueByKeyPath, toLine } from "@tmagic/utils";
5
5
  import { Target, Watcher } from "@tmagic/core";
6
6
  import { reactive } from "vue";
7
- import { cloneDeep, mergeWith } from "lodash-es";
7
+ import { cloneDeep as cloneDeep$1, mergeWith } from "lodash-es";
8
8
  //#region packages/editor/src/services/props.ts
9
9
  var canUsePluginMethods = {
10
10
  async: [
@@ -17,7 +17,7 @@ var canUsePluginMethods = {
17
17
  ],
18
18
  sync: ["createId", "setNewItemId"]
19
19
  };
20
- var Props = class extends BaseService_default {
20
+ var Props = class extends BaseService {
21
21
  state = reactive({
22
22
  propsConfigMap: {},
23
23
  propsValueMap: {},
@@ -57,9 +57,9 @@ var Props = class extends BaseService_default {
57
57
  getPropsConfigs() {
58
58
  return this.state.propsConfigMap;
59
59
  }
60
- async fillConfig(config, labelWidth) {
60
+ async fillConfig(config, labelWidth = "80px") {
61
61
  return fillConfig(config, {
62
- labelWidth: typeof labelWidth !== "function" ? labelWidth : "80px",
62
+ labelWidth,
63
63
  disabledDataSource: this.getDisabledDataSource(),
64
64
  disabledCodeBlock: this.getDisabledCodeBlock()
65
65
  });
@@ -77,7 +77,7 @@ var Props = class extends BaseService_default {
77
77
  */
78
78
  async getPropsConfig(type, data) {
79
79
  if (type === "area") return await this.getPropsConfig("button", data);
80
- return cloneDeep(this.state.propsConfigMap[toLine(type)] || await this.fillConfig([]));
80
+ return cloneDeep$1(this.state.propsConfigMap[toLine(type)] || await this.fillConfig([]));
81
81
  }
82
82
  hasPropsConfig(type) {
83
83
  return !!this.state.propsConfigMap[toLine(type)];
@@ -116,14 +116,14 @@ var Props = class extends BaseService_default {
116
116
  }
117
117
  const id = this.createId(type);
118
118
  const defaultPropsValue = this.getDefaultPropsValue(type);
119
- const data = this.setNewItemId(cloneDeep({
119
+ const data = this.setNewItemId(cloneDeep$1({
120
120
  type,
121
121
  ...defaultValue
122
122
  }));
123
123
  return {
124
124
  id,
125
125
  ...defaultPropsValue,
126
- ...mergeWith({}, cloneDeep(this.state.propsValueMap[type] || {}), data)
126
+ ...mergeWith({}, cloneDeep$1(this.state.propsValueMap[type] || {}), data)
127
127
  };
128
128
  }
129
129
  hasPropsValue(type) {
@@ -1,4 +1,4 @@
1
- import BaseService_default from "./BaseService.js";
1
+ import BaseService from "./BaseService.js";
2
2
  import editor_default from "./editor.js";
3
3
  import { useStage } from "../hooks/use-stage.js";
4
4
  import { getIdFromEl } from "@tmagic/utils";
@@ -13,7 +13,7 @@ var canUsePluginMethods = {
13
13
  "createStage"
14
14
  ]
15
15
  };
16
- var StageOverlay = class extends BaseService_default {
16
+ var StageOverlay = class extends BaseService {
17
17
  state = shallowReactive({
18
18
  wrapDiv: document.createElement("div"),
19
19
  sourceEl: null,
@@ -1,4 +1,4 @@
1
- import BaseService_default from "./BaseService.js";
1
+ import BaseService from "./BaseService.js";
2
2
  import { getEditorConfig } from "../utils/config.js";
3
3
  import serialize from "serialize-javascript";
4
4
  //#region packages/editor/src/services/storage.ts
@@ -24,7 +24,7 @@ var canUsePluginMethods = {
24
24
  /**
25
25
  * 数据存储服务
26
26
  */
27
- var WebStorage = class extends BaseService_default {
27
+ var WebStorage = class extends BaseService {
28
28
  storage = globalThis.localStorage;
29
29
  namespace = "tmagic";
30
30
  constructor() {
@@ -1,4 +1,4 @@
1
- import BaseService_default from "./BaseService.js";
1
+ import BaseService from "./BaseService.js";
2
2
  import storage_default, { Protocol } from "./storage.js";
3
3
  import editor_default from "./editor.js";
4
4
  import "../utils/const.js";
@@ -31,6 +31,7 @@ var state = shallowReactive({
31
31
  showPageListButton: true,
32
32
  hideSlideBar: false,
33
33
  sideBarItems: [],
34
+ sideBarActiveTabName: "",
34
35
  navMenuRect: {
35
36
  left: 0,
36
37
  top: 0,
@@ -48,7 +49,7 @@ var canUsePluginMethods = {
48
49
  async: ["zoom", "calcZoom"],
49
50
  sync: []
50
51
  };
51
- var Ui = class extends BaseService_default {
52
+ var Ui = class extends BaseService {
52
53
  constructor() {
53
54
  super(canUsePluginMethods.async.map((methodName) => ({
54
55
  name: methodName,
@@ -63,7 +64,9 @@ var Ui = class extends BaseService_default {
63
64
  }
64
65
  if (name === "showGuides") mask?.showGuides(value);
65
66
  if (name === "showRule") mask?.showRule(value);
67
+ const preValue = state[name];
66
68
  state[name] = value;
69
+ if (preValue !== value) this.emit("state-change", name, value, preValue);
67
70
  }
68
71
  get(name) {
69
72
  return state[name];