@tmagic/editor 1.8.0-beta.2 → 1.8.0-beta.21

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 (308) hide show
  1. package/dist/es/Editor.vue_vue_type_script_setup_true_lang.js +43 -9
  2. package/dist/es/components/CodeBlockEditor.vue_vue_type_script_setup_true_lang.js +8 -4
  3. package/dist/es/components/CodeParams.vue_vue_type_script_setup_true_lang.js +3 -2
  4. package/dist/es/components/CompareForm.vue_vue_type_script_setup_true_lang.js +22 -98
  5. package/dist/es/components/ContentMenu.vue_vue_type_script_setup_true_lang.js +32 -9
  6. package/dist/es/components/FloatingBox.vue_vue_type_script_setup_true_lang.js +68 -17
  7. package/dist/es/components/Icon.vue_vue_type_script_setup_true_lang.js +1 -1
  8. package/dist/es/components/Resizer.vue_vue_type_script_setup_true_lang.js +1 -1
  9. package/dist/es/components/ScrollBar.js +0 -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/components/ViewForm.js +5 -0
  18. package/dist/es/components/ViewForm.vue_vue_type_script_setup_true_lang.js +58 -0
  19. package/dist/es/editorProps.js +9 -1
  20. package/dist/es/fields/Code.vue_vue_type_script_setup_true_lang.js +16 -5
  21. package/dist/es/fields/CodeLink.vue_vue_type_script_setup_true_lang.js +7 -7
  22. package/dist/es/fields/CodeSelect.vue_vue_type_script_setup_true_lang.js +81 -44
  23. package/dist/es/fields/CodeSelectCol.vue_vue_type_script_setup_true_lang.js +10 -3
  24. package/dist/es/fields/CondOpSelect.vue_vue_type_script_setup_true_lang.js +7 -19
  25. package/dist/es/fields/DataSourceFieldSelect/FieldSelect.vue_vue_type_script_setup_true_lang.js +13 -6
  26. package/dist/es/fields/DataSourceFieldSelect/Index.vue_vue_type_script_setup_true_lang.js +11 -8
  27. package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +39 -12
  28. package/dist/es/fields/DataSourceInput.vue_vue_type_script_setup_true_lang.js +11 -20
  29. package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +11 -6
  30. package/dist/es/fields/DataSourceMethods.vue_vue_type_script_setup_true_lang.js +30 -14
  31. package/dist/es/fields/DataSourceMocks.vue_vue_type_script_setup_true_lang.js +11 -4
  32. package/dist/es/fields/DataSourceSelect.vue_vue_type_script_setup_true_lang.js +5 -2
  33. package/dist/es/fields/DisplayConds.vue_vue_type_script_setup_true_lang.js +38 -6
  34. package/dist/es/fields/EventSelect.vue_vue_type_script_setup_true_lang.js +156 -155
  35. package/dist/es/fields/KeyValue.vue_vue_type_script_setup_true_lang.js +5 -2
  36. package/dist/es/fields/PageFragmentSelect.vue_vue_type_script_setup_true_lang.js +5 -2
  37. package/dist/es/fields/StyleSetter/Index.vue_vue_type_script_setup_true_lang.js +8 -10
  38. package/dist/es/fields/StyleSetter/components/BackgroundPosition.vue_vue_type_script_setup_true_lang.js +5 -2
  39. package/dist/es/fields/StyleSetter/components/Border.vue_vue_type_script_setup_true_lang.js +28 -6
  40. package/dist/es/fields/StyleSetter/components/Box.vue_vue_type_script_setup_true_lang.js +1 -1
  41. package/dist/es/fields/StyleSetter/icons/align-items/Center.js +31 -0
  42. package/dist/es/fields/StyleSetter/icons/align-items/FlexEnd.js +31 -0
  43. package/dist/es/fields/StyleSetter/icons/align-items/FlexStart.js +31 -0
  44. package/dist/es/fields/StyleSetter/icons/align-items/SpaceAround.js +50 -0
  45. package/dist/es/fields/StyleSetter/icons/align-items/SpaceBetween.js +50 -0
  46. package/dist/es/fields/StyleSetter/icons/background-repeat/NoRepeat.js +7 -7
  47. package/dist/es/fields/StyleSetter/icons/background-repeat/Repeat.js +6 -3
  48. package/dist/es/fields/StyleSetter/icons/background-repeat/RepeatX.js +29 -6
  49. package/dist/es/fields/StyleSetter/icons/background-repeat/RepeatY.js +32 -6
  50. package/dist/es/fields/StyleSetter/icons/display/Block.js +1 -1
  51. package/dist/es/fields/StyleSetter/icons/display/Flex.js +1 -1
  52. package/dist/es/fields/StyleSetter/icons/display/Inline.js +1 -1
  53. package/dist/es/fields/StyleSetter/icons/display/InlineBlock.js +1 -1
  54. package/dist/es/fields/StyleSetter/icons/display/None.js +1 -1
  55. package/dist/es/fields/StyleSetter/icons/flex-direction/Column.js +11 -3
  56. package/dist/es/fields/StyleSetter/icons/flex-direction/ColumnReverse.js +11 -3
  57. package/dist/es/fields/StyleSetter/icons/flex-direction/Row.js +11 -3
  58. package/dist/es/fields/StyleSetter/icons/flex-direction/RowReverse.js +11 -3
  59. package/dist/es/fields/StyleSetter/icons/justify-content/Center.js +17 -3
  60. package/dist/es/fields/StyleSetter/icons/justify-content/FlexEnd.js +19 -3
  61. package/dist/es/fields/StyleSetter/icons/justify-content/FlexStart.js +19 -3
  62. package/dist/es/fields/StyleSetter/icons/justify-content/SpaceAround.js +37 -3
  63. package/dist/es/fields/StyleSetter/icons/justify-content/SpaceBetween.js +33 -3
  64. package/dist/es/fields/StyleSetter/icons/text-align/Center.js +1 -1
  65. package/dist/es/fields/StyleSetter/icons/text-align/Left.js +1 -1
  66. package/dist/es/fields/StyleSetter/icons/text-align/Right.js +1 -1
  67. package/dist/es/fields/StyleSetter/pro/Background.vue_vue_type_script_setup_true_lang.js +56 -30
  68. package/dist/es/fields/StyleSetter/pro/Border.vue_vue_type_script_setup_true_lang.js +7 -4
  69. package/dist/es/fields/StyleSetter/pro/Font.vue_vue_type_script_setup_true_lang.js +35 -26
  70. package/dist/es/fields/StyleSetter/pro/Layout.vue_vue_type_script_setup_true_lang.js +76 -48
  71. package/dist/es/fields/StyleSetter/pro/Position.vue_vue_type_script_setup_true_lang.js +29 -23
  72. package/dist/es/fields/StyleSetter/pro/Transform.vue_vue_type_script_setup_true_lang.js +7 -4
  73. package/dist/es/fields/UISelect.js +0 -1
  74. package/dist/es/fields/UISelect.vue_vue_type_script_setup_true_lang.js +5 -2
  75. package/dist/es/hooks/use-code-block-edit.js +6 -3
  76. package/dist/es/hooks/use-compare-form.js +119 -0
  77. package/dist/es/hooks/use-data-source-edit.js +5 -2
  78. package/dist/es/hooks/use-stage.js +9 -4
  79. package/dist/es/icons/CenterIcon.vue_vue_type_script_setup_true_lang.js +1 -1
  80. package/dist/es/icons/CodeIcon.vue_vue_type_script_setup_true_lang.js +1 -1
  81. package/dist/es/icons/DatasourceIcon.js +17 -0
  82. package/dist/es/icons/FolderMinusIcon.vue_vue_type_script_setup_true_lang.js +1 -1
  83. package/dist/es/index.js +24 -10
  84. package/dist/es/initService.js +19 -13
  85. package/dist/es/layouts/AddPageBox.vue_vue_type_script_setup_true_lang.js +1 -1
  86. package/dist/es/layouts/CodeEditor.vue_vue_type_script_setup_true_lang.js +24 -12
  87. package/dist/es/layouts/Framework.vue_vue_type_script_setup_true_lang.js +25 -18
  88. package/dist/es/layouts/NavMenu.vue_vue_type_script_setup_true_lang.js +4 -4
  89. package/dist/es/layouts/NavMenuColumn.vue_vue_type_script_setup_true_lang.js +1 -1
  90. package/dist/es/layouts/history-list/Bucket.vue_vue_type_script_setup_true_lang.js +25 -38
  91. package/dist/es/layouts/history-list/BucketTab.js +5 -0
  92. package/dist/es/layouts/history-list/BucketTab.vue_vue_type_script_setup_true_lang.js +62 -0
  93. package/dist/es/layouts/history-list/GroupRow.vue_vue_type_script_setup_true_lang.js +177 -88
  94. package/dist/es/layouts/history-list/HistoryDiffDialog.vue_vue_type_script_setup_true_lang.js +139 -37
  95. package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +164 -107
  96. package/dist/es/layouts/history-list/InitialRow.vue_vue_type_script_setup_true_lang.js +44 -9
  97. package/dist/es/layouts/history-list/PageTab.vue_vue_type_script_setup_true_lang.js +49 -53
  98. package/dist/es/layouts/history-list/composables.js +138 -108
  99. package/dist/es/layouts/history-list/useHistoryList.js +56 -0
  100. package/dist/es/layouts/history-list/useHistoryRevert.js +317 -0
  101. package/dist/es/layouts/page-bar/AddButton.vue_vue_type_script_setup_true_lang.js +1 -1
  102. package/dist/es/layouts/page-bar/PageBar.vue_vue_type_script_setup_true_lang.js +5 -3
  103. package/dist/es/layouts/page-bar/PageBarScrollContainer.vue_vue_type_script_setup_true_lang.js +1 -1
  104. package/dist/es/layouts/page-bar/PageList.vue_vue_type_script_setup_true_lang.js +1 -1
  105. package/dist/es/layouts/page-bar/Search.vue_vue_type_script_setup_true_lang.js +2 -2
  106. package/dist/es/layouts/props-panel/FormPanel.vue_vue_type_script_setup_true_lang.js +50 -7
  107. package/dist/es/layouts/props-panel/PropsPanel.vue_vue_type_script_setup_true_lang.js +33 -13
  108. package/dist/es/layouts/props-panel/use-style-panel.js +3 -2
  109. package/dist/es/layouts/sidebar/ComponentListPanel.vue_vue_type_script_setup_true_lang.js +3 -3
  110. package/dist/es/layouts/sidebar/Sidebar.vue_vue_type_script_setup_true_lang.js +26 -38
  111. package/dist/es/layouts/sidebar/code-block/CodeBlockList.vue_vue_type_script_setup_true_lang.js +4 -4
  112. package/dist/es/layouts/sidebar/code-block/CodeBlockListPanel.vue_vue_type_script_setup_true_lang.js +4 -4
  113. package/dist/es/layouts/sidebar/code-block/useContentMenu.js +19 -4
  114. package/dist/es/layouts/sidebar/data-source/DataSourceAddButton.vue_vue_type_script_setup_true_lang.js +1 -1
  115. package/dist/es/layouts/sidebar/data-source/DataSourceConfigPanel.vue_vue_type_script_setup_true_lang.js +23 -6
  116. package/dist/es/layouts/sidebar/data-source/DataSourceList.vue_vue_type_script_setup_true_lang.js +1 -1
  117. package/dist/es/layouts/sidebar/data-source/DataSourceListPanel.vue_vue_type_script_setup_true_lang.js +27 -5
  118. package/dist/es/layouts/sidebar/data-source/useContentMenu.js +19 -4
  119. package/dist/es/layouts/sidebar/layer/LayerMenu.vue_vue_type_script_setup_true_lang.js +8 -8
  120. package/dist/es/layouts/sidebar/layer/LayerNodeContent.js +5 -0
  121. package/dist/es/layouts/sidebar/layer/LayerNodeContent.vue_vue_type_script_setup_true_lang.js +46 -0
  122. package/dist/es/layouts/sidebar/layer/LayerNodeTool.vue_vue_type_script_setup_true_lang.js +2 -2
  123. package/dist/es/layouts/sidebar/layer/LayerPanel.vue_vue_type_script_setup_true_lang.js +3 -2
  124. package/dist/es/layouts/sidebar/layer/use-click.js +3 -3
  125. package/dist/es/layouts/sidebar/layer/use-node-status.js +2 -2
  126. package/dist/es/layouts/workspace/Breadcrumb.vue_vue_type_script_setup_true_lang.js +1 -1
  127. package/dist/es/layouts/workspace/Workspace.vue_vue_type_script_setup_true_lang.js +1 -1
  128. package/dist/es/layouts/workspace/viewer/NodeListMenu.vue_vue_type_script_setup_true_lang.js +9 -3
  129. package/dist/es/layouts/workspace/viewer/Stage.vue_vue_type_script_setup_true_lang.js +2 -2
  130. package/dist/es/layouts/workspace/viewer/StageOverlay.vue_vue_type_script_setup_true_lang.js +1 -1
  131. package/dist/es/layouts/workspace/viewer/ViewerMenu.vue_vue_type_script_setup_true_lang.js +16 -16
  132. package/dist/es/plugin.js +5 -2
  133. package/dist/es/services/codeBlock.js +137 -56
  134. package/dist/es/services/dataSource.js +122 -52
  135. package/dist/es/services/dep.js +162 -41
  136. package/dist/es/services/editor.js +613 -179
  137. package/dist/es/services/events.js +2 -2
  138. package/dist/es/services/history.js +350 -386
  139. package/dist/es/services/keybinding.js +6 -6
  140. package/dist/es/services/props.js +3 -2
  141. package/dist/es/services/storage.js +2 -2
  142. package/dist/es/services/ui.js +10 -2
  143. package/dist/es/style.css +549 -113
  144. package/dist/es/utils/config.js +4 -1
  145. package/dist/es/utils/const.js +2 -2
  146. package/dist/es/utils/content-menu.js +19 -11
  147. package/dist/es/utils/data-source/index.js +34 -11
  148. package/dist/es/utils/dep/collect-worker-client.js +114 -0
  149. package/dist/es/utils/dep/idle-task.js +70 -22
  150. package/dist/es/utils/dep/worker.js +1 -1
  151. package/dist/es/utils/editor.js +103 -49
  152. package/dist/es/utils/event.js +135 -0
  153. package/dist/es/utils/history.js +220 -0
  154. package/dist/es/utils/indexed-db.js +86 -0
  155. package/dist/es/utils/monaco-editor.js +22 -6
  156. package/dist/es/utils/operator.js +2 -2
  157. package/dist/es/utils/props.js +114 -33
  158. package/dist/es/utils/type-match-rules.js +367 -0
  159. package/dist/es/utils/undo-redo.js +60 -1
  160. package/dist/style.css +549 -113
  161. package/dist/themes/magic-admin.css +3028 -0
  162. package/dist/tmagic-editor.umd.cjs +14403 -10121
  163. package/package.json +8 -8
  164. package/src/Editor.vue +43 -2
  165. package/src/components/CodeBlockEditor.vue +3 -0
  166. package/src/components/CompareForm.vue +18 -146
  167. package/src/components/ContentMenu.vue +44 -8
  168. package/src/components/FloatingBox.vue +84 -9
  169. package/src/components/ScrollBar.vue +0 -67
  170. package/src/components/ToolButton.vue +2 -2
  171. package/src/components/ViewForm.vue +55 -0
  172. package/src/editorProps.ts +30 -0
  173. package/src/fields/Code.vue +10 -2
  174. package/src/fields/CodeLink.vue +2 -5
  175. package/src/fields/CodeSelect.vue +54 -40
  176. package/src/fields/CodeSelectCol.vue +8 -1
  177. package/src/fields/CondOpSelect.vue +2 -24
  178. package/src/fields/DataSourceFieldSelect/FieldSelect.vue +16 -2
  179. package/src/fields/DataSourceFieldSelect/Index.vue +14 -5
  180. package/src/fields/DataSourceFields.vue +42 -8
  181. package/src/fields/DataSourceInput.vue +10 -28
  182. package/src/fields/DataSourceMethodSelect.vue +9 -4
  183. package/src/fields/DataSourceMethods.vue +42 -21
  184. package/src/fields/DataSourceMocks.vue +3 -0
  185. package/src/fields/DisplayConds.vue +18 -1
  186. package/src/fields/EventSelect.vue +152 -166
  187. package/src/fields/StyleSetter/Index.vue +3 -12
  188. package/src/fields/StyleSetter/components/Border.vue +15 -6
  189. package/src/fields/StyleSetter/icons/align-items/Center.vue +19 -0
  190. package/src/fields/StyleSetter/icons/align-items/FlexEnd.vue +19 -0
  191. package/src/fields/StyleSetter/icons/align-items/FlexStart.vue +19 -0
  192. package/src/fields/StyleSetter/icons/align-items/SpaceAround.vue +34 -0
  193. package/src/fields/StyleSetter/icons/align-items/SpaceBetween.vue +34 -0
  194. package/src/fields/StyleSetter/icons/align-items/index.ts +5 -0
  195. package/src/fields/StyleSetter/icons/background-repeat/NoRepeat.vue +20 -4
  196. package/src/fields/StyleSetter/icons/background-repeat/Repeat.vue +10 -28
  197. package/src/fields/StyleSetter/icons/background-repeat/RepeatX.vue +4 -5
  198. package/src/fields/StyleSetter/icons/background-repeat/RepeatY.vue +4 -5
  199. package/src/fields/StyleSetter/icons/flex-direction/Column.vue +4 -3
  200. package/src/fields/StyleSetter/icons/flex-direction/ColumnReverse.vue +4 -3
  201. package/src/fields/StyleSetter/icons/flex-direction/Row.vue +4 -3
  202. package/src/fields/StyleSetter/icons/flex-direction/RowReverse.vue +4 -3
  203. package/src/fields/StyleSetter/icons/justify-content/Center.vue +5 -2
  204. package/src/fields/StyleSetter/icons/justify-content/FlexEnd.vue +15 -2
  205. package/src/fields/StyleSetter/icons/justify-content/FlexStart.vue +15 -2
  206. package/src/fields/StyleSetter/icons/justify-content/SpaceAround.vue +28 -3
  207. package/src/fields/StyleSetter/icons/justify-content/SpaceBetween.vue +28 -2
  208. package/src/fields/StyleSetter/pro/Background.vue +99 -55
  209. package/src/fields/StyleSetter/pro/Border.vue +9 -11
  210. package/src/fields/StyleSetter/pro/Font.vue +66 -64
  211. package/src/fields/StyleSetter/pro/Layout.vue +211 -139
  212. package/src/fields/StyleSetter/pro/Position.vue +69 -67
  213. package/src/fields/StyleSetter/pro/Transform.vue +23 -25
  214. package/src/fields/UISelect.vue +0 -12
  215. package/src/hooks/index.ts +1 -0
  216. package/src/hooks/use-code-block-edit.ts +4 -3
  217. package/src/hooks/use-compare-form.ts +187 -0
  218. package/src/hooks/use-data-source-edit.ts +2 -2
  219. package/src/hooks/use-stage.ts +5 -3
  220. package/src/icons/DatasourceIcon.vue +7 -0
  221. package/src/index.ts +12 -0
  222. package/src/initService.ts +26 -16
  223. package/src/layouts/CodeEditor.vue +34 -11
  224. package/src/layouts/Framework.vue +15 -8
  225. package/src/layouts/NavMenu.vue +3 -3
  226. package/src/layouts/history-list/Bucket.vue +33 -41
  227. package/src/layouts/history-list/BucketTab.vue +72 -0
  228. package/src/layouts/history-list/GroupRow.vue +190 -93
  229. package/src/layouts/history-list/HistoryDiffDialog.vue +169 -90
  230. package/src/layouts/history-list/HistoryListPanel.vue +191 -95
  231. package/src/layouts/history-list/InitialRow.vue +38 -8
  232. package/src/layouts/history-list/PageTab.vue +67 -43
  233. package/src/layouts/history-list/composables.ts +239 -125
  234. package/src/layouts/history-list/useHistoryList.ts +60 -0
  235. package/src/layouts/history-list/useHistoryRevert.ts +425 -0
  236. package/src/layouts/page-bar/PageBar.vue +4 -2
  237. package/src/layouts/props-panel/FormPanel.vue +72 -6
  238. package/src/layouts/props-panel/PropsPanel.vue +62 -18
  239. package/src/layouts/props-panel/use-style-panel.ts +4 -3
  240. package/src/layouts/sidebar/ComponentListPanel.vue +10 -6
  241. package/src/layouts/sidebar/Sidebar.vue +13 -6
  242. package/src/layouts/sidebar/code-block/CodeBlockList.vue +5 -5
  243. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +5 -2
  244. package/src/layouts/sidebar/code-block/useContentMenu.ts +14 -2
  245. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +34 -2
  246. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +29 -4
  247. package/src/layouts/sidebar/data-source/useContentMenu.ts +14 -2
  248. package/src/layouts/sidebar/layer/LayerMenu.vue +21 -13
  249. package/src/layouts/sidebar/layer/LayerNodeContent.vue +57 -0
  250. package/src/layouts/sidebar/layer/LayerNodeTool.vue +7 -4
  251. package/src/layouts/sidebar/layer/LayerPanel.vue +4 -1
  252. package/src/layouts/sidebar/layer/use-click.ts +3 -3
  253. package/src/layouts/sidebar/layer/use-node-status.ts +2 -2
  254. package/src/layouts/workspace/viewer/NodeListMenu.vue +4 -1
  255. package/src/layouts/workspace/viewer/Stage.vue +1 -1
  256. package/src/layouts/workspace/viewer/ViewerMenu.vue +15 -15
  257. package/src/plugin.ts +6 -3
  258. package/src/services/codeBlock.ts +152 -47
  259. package/src/services/dataSource.ts +120 -41
  260. package/src/services/dep.ts +292 -47
  261. package/src/services/editor.ts +820 -224
  262. package/src/services/events.ts +3 -3
  263. package/src/services/history.ts +449 -412
  264. package/src/services/keybinding.ts +6 -6
  265. package/src/services/ui.ts +33 -5
  266. package/src/theme/code-block.scss +37 -0
  267. package/src/theme/common/var.scss +1 -1
  268. package/src/theme/component-list-panel.scss +2 -2
  269. package/src/theme/data-source-field.scss +4 -0
  270. package/src/theme/display-conds.scss +11 -0
  271. package/src/theme/event.scss +70 -1
  272. package/src/theme/floating-box.scss +9 -1
  273. package/src/theme/framework.scss +4 -1
  274. package/src/theme/history-list-panel.scss +157 -23
  275. package/src/theme/layer-node-content.scss +14 -0
  276. package/src/theme/nav-menu.scss +5 -1
  277. package/src/theme/page-bar.scss +0 -4
  278. package/src/theme/props-panel.scss +5 -4
  279. package/src/theme/scroll-bar.scss +64 -0
  280. package/src/theme/style-setter/border.scss +17 -5
  281. package/src/theme/theme.scss +4 -0
  282. package/src/theme/themes/magic-admin/index.scss +214 -0
  283. package/src/theme/ui-select.scss +9 -0
  284. package/src/type.ts +668 -124
  285. package/src/utils/config.ts +9 -1
  286. package/src/utils/const.ts +3 -2
  287. package/src/utils/content-menu.ts +20 -11
  288. package/src/utils/data-source/index.ts +32 -12
  289. package/src/utils/dep/collect-worker-client.ts +149 -0
  290. package/src/utils/dep/idle-task.ts +104 -35
  291. package/src/utils/dep/worker.ts +113 -9
  292. package/src/utils/editor.ts +166 -60
  293. package/src/utils/event.ts +237 -0
  294. package/src/utils/history.ts +286 -0
  295. package/src/utils/index.ts +4 -0
  296. package/src/utils/indexed-db.ts +122 -0
  297. package/src/utils/monaco-editor.ts +27 -0
  298. package/src/utils/operator.ts +2 -2
  299. package/src/utils/props.ts +114 -11
  300. package/src/utils/type-match-rules.ts +684 -0
  301. package/src/utils/undo-redo.ts +88 -0
  302. package/types/index.d.ts +1990 -517
  303. package/dist/es/layouts/history-list/CodeBlockTab.js +0 -5
  304. package/dist/es/layouts/history-list/CodeBlockTab.vue_vue_type_script_setup_true_lang.js +0 -62
  305. package/dist/es/layouts/history-list/DataSourceTab.js +0 -5
  306. package/dist/es/layouts/history-list/DataSourceTab.vue_vue_type_script_setup_true_lang.js +0 -62
  307. package/src/layouts/history-list/CodeBlockTab.vue +0 -61
  308. package/src/layouts/history-list/DataSourceTab.vue +0 -61
@@ -0,0 +1,286 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making TMagicEditor available.
3
+ *
4
+ * Copyright (C) 2025 Tencent. All rights reserved.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import { cloneDeep } from 'lodash-es';
20
+ import serialize from 'serialize-javascript';
21
+
22
+ import type { Id } from '@tmagic/core';
23
+ import type { ChangeRecord } from '@tmagic/form';
24
+ import { guid } from '@tmagic/utils';
25
+
26
+ import type { BaseStepValue, HistoryGroup, StepDiffItem } from '@editor/type';
27
+
28
+ import { UndoRedo } from './undo-redo';
29
+
30
+ /**
31
+ * 「回滚」生成的新 step 简短描述。代码块 / 数据源共用。
32
+ * 二者逻辑一致,仅展示名取值字段不同(代码块取 `name`,数据源取 `title`),
33
+ * 因此通过 `getLabel` 注入取值方式。
34
+ *
35
+ * @param id 关联的代码块 / 数据源 id
36
+ * @param diff 单条变更 diff(缺省视为空)
37
+ * @param getLabel 从快照取展示名
38
+ */
39
+ export const describeRevertStep = <T extends object>(
40
+ id: Id,
41
+ { oldSchema, newSchema, changeRecords }: StepDiffItem<T> = {},
42
+ getLabel: (schema: T) => string | undefined,
43
+ ): string => {
44
+ const labelOf = (schema: T) => getLabel(schema) || (schema as { id?: Id }).id;
45
+ if (!oldSchema && newSchema) return `撤回新增 ${labelOf(newSchema) || id}`;
46
+ if (oldSchema && !newSchema) return `还原已删除的 ${labelOf(oldSchema) || id}`;
47
+ const label = (newSchema && getLabel(newSchema)) || (oldSchema && getLabel(oldSchema)) || `${id}`;
48
+ const propPath = changeRecords?.[0]?.propPath;
49
+ return propPath ? `还原 ${label} · ${propPath}` : `还原 ${label}`;
50
+ };
51
+
52
+ /**
53
+ * 根据 old/new 是否为 null 推断 opType(与 push 时的约定一致)。
54
+ */
55
+ export const detectStackOpType = (oldVal: unknown, newVal: unknown): 'add' | 'remove' | 'update' => {
56
+ if (oldVal === null && newVal !== null) return 'add';
57
+ if (oldVal !== null && newVal === null) return 'remove';
58
+ return 'update';
59
+ };
60
+
61
+ /**
62
+ * 构造一条代码块 / 数据源「按 id 分栈」的历史记录:两者除 payload 字段命名外完全一致。
63
+ *
64
+ * - `add`:oldValue = null;`remove`:newValue = null;`update`:两者都有,可带 changeRecords 做局部更新。
65
+ * - 内容会做 cloneDeep 防止后续被外部引用篡改;opType 依据 old/new 是否为 null 推断。
66
+ * - 仅负责构造 step 并返回,入栈与事件 emit 由统一的 history.push(stepType, step, id) 处理。
67
+ * - 不直接驱动业务 service,调用方负责实际写回。
68
+ */
69
+ export const createStackStep = <T, S extends BaseStepValue<T>>(
70
+ id: Id,
71
+ // payload 以 {@link BaseStepValue} 为基础:透传字段(historyDescription / source / operator / rootStep / extra)
72
+ // 随 BaseStepValue 演进自动同步,原样写入 step;自动生成字段(uuid / data / opType / diff / timestamp / saved)
73
+ // 从 payload 中排除,由本方法内部构造。oldValue / newValue / changeRecords / name 为构造 diff 与 data 用的输入。
74
+ payload: Omit<BaseStepValue<T>, 'uuid' | 'data' | 'opType' | 'diff' | 'timestamp' | 'saved'> & {
75
+ oldValue: T | null;
76
+ newValue: T | null;
77
+ changeRecords?: ChangeRecord[];
78
+ /** 展示名(缺省时从快照 name / title 推断)。 */
79
+ name?: string;
80
+ },
81
+ ): S | null => {
82
+ if (!id) return null;
83
+
84
+ const oldSchema = payload.oldValue ? cloneDeep(payload.oldValue) : null;
85
+ const newSchema = payload.newValue ? cloneDeep(payload.newValue) : null;
86
+ const changeRecords = payload.changeRecords?.length ? cloneDeep(payload.changeRecords) : undefined;
87
+ const opType = detectStackOpType(payload.oldValue, payload.newValue);
88
+ // 展示名:代码块取 name,数据源取 title,取不到则留空(不影响 undo/redo,仅用于展示)。
89
+ const schema = (payload.newValue ?? payload.oldValue) as { name?: string; title?: string } | null;
90
+ const name = payload.name ?? schema?.name ?? schema?.title ?? '';
91
+
92
+ const step: BaseStepValue<T> = {
93
+ uuid: guid(),
94
+ data: { name, id },
95
+ opType,
96
+ diff: [
97
+ {
98
+ ...(newSchema !== null ? { newSchema } : {}),
99
+ ...(oldSchema !== null ? { oldSchema } : {}),
100
+ ...(opType === 'update' && changeRecords ? { changeRecords } : {}),
101
+ },
102
+ ],
103
+ historyDescription: payload.historyDescription,
104
+ source: payload.source,
105
+ operator: payload.operator,
106
+ rootStep: payload.rootStep,
107
+ timestamp: Date.now(),
108
+ extra: payload.extra,
109
+ };
110
+
111
+ return step as S;
112
+ };
113
+
114
+ export const markStackSaved = <S extends { saved?: boolean }>(undoRedo?: UndoRedo<S>): void => {
115
+ if (!undoRedo) return;
116
+ undoRedo.updateElements((element) => {
117
+ element.saved = false;
118
+ });
119
+ undoRedo.updateCurrentElement((element) => {
120
+ element.saved = true;
121
+ });
122
+ };
123
+
124
+ /**
125
+ * 把单个历史栈(页面 / 代码块 / 数据源 / 扩展类型)的步骤列表按"目标"做相邻合并:
126
+ * - 单实体的 'update' 按 targetId 与相邻同 targetId 的 update 合并到一个 group,组内可展开查看每步;
127
+ * - 'add' / 'remove' 始终独立成组(语义上是结构变更,不应被收纳进单实体修改组);
128
+ * - 多实体 'update'(如页面批量改属性)也独立成组(无明确单一目标,避免误合并)。
129
+ *
130
+ * 各类型行为完全一致,仅 `kind` 与 step 快照类型不同,统一由本方法处理。
131
+ */
132
+ export const mergeSteps = <T extends BaseStepValue>(
133
+ kind: string,
134
+ id: Id,
135
+ list: T[],
136
+ cursor: number,
137
+ ): HistoryGroup<T>[] => {
138
+ const groups: HistoryGroup<T>[] = [];
139
+ let current: HistoryGroup<T> | null = null;
140
+ const currentIndex = cursor - 1;
141
+ list.forEach((step, index) => {
142
+ const applied = index < cursor;
143
+ const isCurrent = index === currentIndex;
144
+ const targetId = detectTargetId(step);
145
+ const targetName = detectTargetName(step);
146
+ const entry = { step, index, applied, isCurrent };
147
+
148
+ // 仅"单实体 update"参与合并;其它情形(add/remove/多实体 update)始终独立成组。
149
+ const mergeable = step.opType === 'update' && targetId !== undefined;
150
+ if (mergeable && current?.opType === 'update' && current.targetId === targetId) {
151
+ current.steps.push(entry);
152
+ current.applied = applied;
153
+ if (isCurrent) current.isCurrent = true;
154
+ // 保持目标名为最近一次的(重命名时也能反映)
155
+ if (targetName) current.targetName = targetName;
156
+ } else {
157
+ current = {
158
+ kind,
159
+ id,
160
+ opType: step.opType,
161
+ targetId: mergeable ? targetId : undefined,
162
+ targetName,
163
+ steps: [entry],
164
+ applied,
165
+ isCurrent,
166
+ };
167
+ groups.push(current);
168
+ }
169
+ });
170
+ return groups;
171
+ };
172
+
173
+ /**
174
+ * 解析 step 中的"目标 id"用于合并:
175
+ * - 单实体 update:取唯一一项 diff 的快照 id;快照无 id 时(如 CodeBlockContent)回退到 `step.data.id`
176
+ * (即资源 id),使代码块 / 数据源同样能按资源合并相邻 update;
177
+ * - 其它情形(多实体 update / add / remove):返回 undefined,表示不参与合并。
178
+ */
179
+ export const detectTargetId = (step: BaseStepValue): Id | undefined => {
180
+ if (step.opType !== 'update') return undefined;
181
+ const items = step.diff;
182
+ if (items?.length !== 1) return undefined;
183
+ const newSchema = items[0].newSchema as { id?: Id } | undefined;
184
+ const oldSchema = items[0].oldSchema as { id?: Id } | undefined;
185
+ return newSchema?.id ?? oldSchema?.id ?? step.data?.id;
186
+ };
187
+
188
+ /** 解析 step 中的目标可读名(用于 UI 展示)。 */
189
+ export const detectTargetName = (step: BaseStepValue): string | undefined => {
190
+ const items = step.diff;
191
+ if (step.opType === 'update') {
192
+ if (items?.length === 1) {
193
+ const node = (items[0].newSchema || items[0].oldSchema) as { name?: string; type?: string; id?: Id } | undefined;
194
+ return (node?.name as string) || (node?.type as string) || (node?.id !== undefined ? `${node.id}` : undefined);
195
+ }
196
+ return items?.length ? `${items.length} 个节点` : undefined;
197
+ }
198
+ if (step.opType === 'add') {
199
+ if (items?.length === 1) {
200
+ const n = items[0].newSchema as { name?: string; type?: string; id?: Id } | undefined;
201
+ return (n?.name as string) || (n?.type as string) || `${n?.id}`;
202
+ }
203
+ return items?.length ? `${items.length} 个节点` : undefined;
204
+ }
205
+ if (step.opType === 'remove') {
206
+ if (items?.length === 1) {
207
+ const n = items[0].oldSchema as { name?: string; type?: string; id?: Id } | undefined;
208
+ return (n?.name as string) || (n?.type as string) || `${n?.id}`;
209
+ }
210
+ return items?.length ? `${items.length} 个节点` : undefined;
211
+ }
212
+ return undefined;
213
+ };
214
+
215
+ /**
216
+ * 把 `Record<Id, UndoRedo>` 整体序列化为 `Record<Id, SerializedUndoRedo>`。
217
+ *
218
+ * 序列化(深克隆)的同一趟里,只把每条 step 中可能含函数的 `diff` 用 serialize-javascript 序列化成字符串,
219
+ * 其余字段(uuid / opType / timestamp / `modifiedNodeIds` Map 等)原样保留,交给 IndexedDB 结构化克隆。
220
+ * 这样既能写入函数,又避免序列化整份快照的开销;读取时再由 {@link parseStacksStepDiff} 还原 diff。
221
+ * 不含 `diff` 的元素(如通用栈)原样透传。
222
+ */
223
+ export const serializeStacks = <T extends { diff?: unknown }>(stacks: Record<Id, UndoRedo<T>>) => {
224
+ const result: Record<Id, ReturnType<UndoRedo<T>['serialize']>> = {};
225
+ Object.entries(stacks).forEach(([id, undoRedo]) => {
226
+ if (!undoRedo) return;
227
+ const serialized = undoRedo.serialize();
228
+ result[id] = {
229
+ ...serialized,
230
+ elementList: serialized.elementList.map((step) =>
231
+ step.diff === undefined ? step : Object.assign({}, step, { diff: serialize(step.diff) }),
232
+ ),
233
+ };
234
+ });
235
+ return result;
236
+ };
237
+
238
+ /**
239
+ * 把 `Record<Id, SerializedUndoRedo>` 整体还原为 `Record<Id, UndoRedo>`。
240
+ * 还原时把每个栈的游标定位到最近一条已保存(`saved === true`)记录之后。
241
+ *
242
+ * 与 {@link serializeStacks} 相反:当传入 `parse`(parseDSL)时,把每条 step 中以字符串形式存储的 `diff`
243
+ * 解析回真实对象(含函数);不含 `diff` 的元素(如通用栈)原样透传。
244
+ */
245
+ export const deserializeStacks = <T extends { saved?: boolean }>(
246
+ stacks: Record<Id, ReturnType<UndoRedo<T>['serialize']>> = {},
247
+ parse?: (serialized: string) => unknown,
248
+ ): Record<Id, UndoRedo<T>> => {
249
+ const result: Record<Id, UndoRedo<T>> = {};
250
+ Object.entries(stacks).forEach(([id, serialized]) => {
251
+ if (!serialized) return;
252
+ const elementList = parse
253
+ ? serialized.elementList.map((step) => {
254
+ const { diff } = step as { diff?: unknown };
255
+ return typeof diff === 'string' ? Object.assign({}, step, { diff: parse(`(${diff})`) }) : step;
256
+ })
257
+ : serialized.elementList;
258
+ result[id] = UndoRedo.fromSerialized<T>(
259
+ { ...serialized, elementList },
260
+ { isSavedStep: (element) => element.saved === true },
261
+ );
262
+ });
263
+ return result;
264
+ };
265
+
266
+ /**
267
+ * 按 id 从「按 id 分栈」的记录表(代码块 / 数据源)中获取(或创建)对应的 UndoRedo 栈。
268
+ */
269
+ export const getOrCreateStack = <T>(stacks: Record<Id, UndoRedo<T>>, id: Id): UndoRedo<T> => {
270
+ if (!stacks[id]) {
271
+ stacks[id] = new UndoRedo<T>();
272
+ }
273
+ return stacks[id];
274
+ };
275
+
276
+ /**
277
+ * 撤销下限:当栈 index 0 是 `opType: 'initial'` 的基线 step 时为 1(基线不可被撤销),否则为 0。
278
+ * 适用于所有历史类型(page / codeBlock / dataSource / 扩展),把 cursor 钉在基线之上,
279
+ * 保证 undo / canUndo / goto 都不会越过初始基线。
280
+ */
281
+ export const undoFloor = (undoRedo: UndoRedo<any>): number => {
282
+ return undoRedo.getElementList()[0]?.opType === 'initial' ? 1 : 0;
283
+ };
284
+
285
+ /** 将单次 push 产生的 history uuid(或 null)转为 *AndGetHistoryId 返回用的 uuid 列表。 */
286
+ export const getLastPushedHistoryIds = (historyId: string | null): string[] => (historyId ? [historyId] : []);
@@ -27,5 +27,9 @@ export * from './dep/idle-task';
27
27
  export * from './scroll-viewer';
28
28
  export * from './tree';
29
29
  export * from './undo-redo';
30
+ export * from './indexed-db';
31
+ export * from './history';
30
32
  export * from './const';
33
+ export * from './type-match-rules';
34
+ export * from './event';
31
35
  export { default as loadMonaco } from './monaco-editor';
@@ -0,0 +1,122 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making TMagicEditor available.
3
+ *
4
+ * Copyright (C) 2025 Tencent. All rights reserved.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ /**
20
+ * 一组极简的、基于原生 IndexedDB 的 Promise KV 工具,避免引入额外依赖。
21
+ * 仅用于浏览器环境;在不支持 IndexedDB 的环境(如 SSR / 部分测试环境)下会 reject。
22
+ */
23
+
24
+ /** 是否处于支持 IndexedDB 的环境。 */
25
+ export const isIndexedDBSupported = (): boolean => typeof indexedDB !== 'undefined' && indexedDB !== null;
26
+
27
+ /**
28
+ * 打开(必要时升级)数据库,确保目标 objectStore 存在后返回连接。
29
+ *
30
+ * 由于 objectStore 只能在 `onupgradeneeded` 内创建,这里先以当前版本打开,
31
+ * 若发现 store 不存在则关闭连接、以更高版本重开来按需创建,兼容动态 storeName。
32
+ */
33
+ export const openIndexedDB = (dbName: string, storeName: string): Promise<IDBDatabase> =>
34
+ new Promise((resolve, reject) => {
35
+ if (!isIndexedDBSupported()) {
36
+ reject(new Error('当前环境不支持 IndexedDB'));
37
+ return;
38
+ }
39
+
40
+ const request = indexedDB.open(dbName);
41
+
42
+ request.onupgradeneeded = () => {
43
+ const db = request.result;
44
+ if (!db.objectStoreNames.contains(storeName)) {
45
+ db.createObjectStore(storeName);
46
+ }
47
+ };
48
+
49
+ request.onerror = () => reject(request.error);
50
+
51
+ request.onsuccess = () => {
52
+ const db = request.result;
53
+ if (db.objectStoreNames.contains(storeName)) {
54
+ resolve(db);
55
+ return;
56
+ }
57
+
58
+ // store 不存在:以更高版本重开,在 onupgradeneeded 中创建。
59
+ const nextVersion = db.version + 1;
60
+ db.close();
61
+ const upgradeRequest = indexedDB.open(dbName, nextVersion);
62
+ upgradeRequest.onupgradeneeded = () => {
63
+ const upgradeDb = upgradeRequest.result;
64
+ if (!upgradeDb.objectStoreNames.contains(storeName)) {
65
+ upgradeDb.createObjectStore(storeName);
66
+ }
67
+ };
68
+ upgradeRequest.onerror = () => reject(upgradeRequest.error);
69
+ upgradeRequest.onsuccess = () => resolve(upgradeRequest.result);
70
+ };
71
+ });
72
+
73
+ /** 写入(覆盖)一条记录。value 通过结构化克隆存储,支持 Map / Set 等结构。 */
74
+ export const idbSet = async (dbName: string, storeName: string, key: IDBValidKey, value: unknown): Promise<void> => {
75
+ const db = await openIndexedDB(dbName, storeName);
76
+ try {
77
+ await new Promise<void>((resolve, reject) => {
78
+ const tx = db.transaction(storeName, 'readwrite');
79
+ tx.objectStore(storeName).put(value, key);
80
+ tx.oncomplete = () => resolve();
81
+ tx.onabort = () => reject(tx.error);
82
+ tx.onerror = () => reject(tx.error);
83
+ });
84
+ } finally {
85
+ db.close();
86
+ }
87
+ };
88
+
89
+ /** 读取一条记录,不存在时返回 undefined。 */
90
+ export const idbGet = async <T = unknown>(
91
+ dbName: string,
92
+ storeName: string,
93
+ key: IDBValidKey,
94
+ ): Promise<T | undefined> => {
95
+ const db = await openIndexedDB(dbName, storeName);
96
+ try {
97
+ return await new Promise<T | undefined>((resolve, reject) => {
98
+ const tx = db.transaction(storeName, 'readonly');
99
+ const request = tx.objectStore(storeName).get(key);
100
+ request.onsuccess = () => resolve(request.result as T | undefined);
101
+ request.onerror = () => reject(request.error);
102
+ });
103
+ } finally {
104
+ db.close();
105
+ }
106
+ };
107
+
108
+ /** 删除一条记录。 */
109
+ export const idbDelete = async (dbName: string, storeName: string, key: IDBValidKey): Promise<void> => {
110
+ const db = await openIndexedDB(dbName, storeName);
111
+ try {
112
+ await new Promise<void>((resolve, reject) => {
113
+ const tx = db.transaction(storeName, 'readwrite');
114
+ tx.objectStore(storeName).delete(key);
115
+ tx.oncomplete = () => resolve();
116
+ tx.onabort = () => reject(tx.error);
117
+ tx.onerror = () => reject(tx.error);
118
+ });
119
+ } finally {
120
+ db.close();
121
+ }
122
+ };
@@ -1,7 +1,34 @@
1
1
  let cached: Promise<typeof import('monaco-editor')> | undefined;
2
2
 
3
+ // 是否为 Monaco 内部抛出的取消错误(Canceled)
4
+ // 销毁编辑器时,WordHighlighter 内部挂起的 Delayer 会被取消,
5
+ // 取消时 reject 出的 Canceled 错误没有 catch,会变成 "Uncaught (in promise) Canceled",
6
+ // 该错误本身无害,这里做一次性、全局的兜底处理,仅吞掉这类取消错误。
7
+ const isMonacoCanceledError = (reason: any): boolean => {
8
+ if (!reason) return false;
9
+ if (reason instanceof Error) {
10
+ return reason.name === 'Canceled' || reason.message === 'Canceled';
11
+ }
12
+ return reason === 'Canceled';
13
+ };
14
+
15
+ let canceledRejectionHandlerInstalled = false;
16
+ const installCanceledRejectionHandler = () => {
17
+ if (canceledRejectionHandlerInstalled || typeof globalThis.addEventListener !== 'function') return;
18
+ canceledRejectionHandlerInstalled = true;
19
+
20
+ globalThis.addEventListener('unhandledrejection', (event: PromiseRejectionEvent) => {
21
+ if (isMonacoCanceledError(event.reason)) {
22
+ // 阻止其冒泡到控制台,避免无意义的报错噪音
23
+ event.preventDefault();
24
+ }
25
+ });
26
+ };
27
+
3
28
  export default () => {
4
29
  if (!cached) {
30
+ installCanceledRejectionHandler();
31
+
5
32
  cached = Promise.all([import('emmet-monaco-es'), import('monaco-editor')]).then(([emmet, monaco]) => {
6
33
  const { emmetHTML, emmetCSS } = emmet;
7
34
  emmetHTML(monaco);
@@ -3,7 +3,7 @@ import { isEmpty } from 'lodash-es';
3
3
 
4
4
  import type { Id, MContainer, MNode } from '@tmagic/core';
5
5
  import { NodeType } from '@tmagic/core';
6
- import { calcValueByFontsize, getElById, isPage, isPageFragment } from '@tmagic/utils';
6
+ import { calcValueByFontsize, getElById, isPage, isPageOrFragment } from '@tmagic/utils';
7
7
 
8
8
  import editorService from '@editor/services/editor';
9
9
  import propsService from '@editor/services/props';
@@ -58,7 +58,7 @@ export const beforePaste = (position: PastePosition, config: MNode[], doc?: Docu
58
58
  };
59
59
  }
60
60
  const root = editorService.get('root');
61
- if ((isPage(pasteConfig) || isPageFragment(pasteConfig)) && root) {
61
+ if (isPageOrFragment(pasteConfig) && root) {
62
62
  pasteConfig.name = generatePageNameByApp(root, isPage(pasteConfig) ? NodeType.PAGE : NodeType.PAGE_FRAGMENT);
63
63
  }
64
64
  return pasteConfig as MNode;
@@ -16,8 +16,8 @@
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
-
20
19
  import {
20
+ HookType,
21
21
  NODE_CONDS_KEY,
22
22
  NODE_CONDS_RESULT_KEY,
23
23
  NODE_DISABLE_CODE_BLOCK_KEY,
@@ -45,10 +45,36 @@ export const numberOptions = [
45
45
  { text: '不在范围内', value: 'not_between' },
46
46
  ];
47
47
 
48
+ export const booleanOptions = [
49
+ { text: '是', value: 'is' },
50
+ { text: '不是', value: 'not' },
51
+ ];
52
+
53
+ /** 按字段类型返回条件运算符选项(UI 与 typeMatch 校验共用) */
54
+ export const getCondOpOptionsByFieldType = (type: string) => {
55
+ if (type === 'array') {
56
+ return arrayOptions;
57
+ }
58
+
59
+ if (type === 'boolean' || type === 'null') {
60
+ return booleanOptions;
61
+ }
62
+
63
+ if (type === 'number') {
64
+ return [...eqOptions, ...numberOptions];
65
+ }
66
+
67
+ if (type === 'string') {
68
+ return [...arrayOptions, ...eqOptions];
69
+ }
70
+
71
+ return [...arrayOptions, ...eqOptions, ...numberOptions];
72
+ };
73
+
48
74
  export const styleTabConfig: TabPaneConfig = {
49
75
  title: '样式',
50
76
  lazy: true,
51
- display: ({ services }: any) => !(services.uiService.get('showStylePanel') ?? true),
77
+ display: ({ services }: any) => !(services?.uiService?.get('showStylePanel') ?? true),
52
78
  items: [
53
79
  {
54
80
  name: 'style',
@@ -127,6 +153,7 @@ export const eventTabConfig: TabPaneConfig = {
127
153
  src: 'component',
128
154
  labelWidth: '100px',
129
155
  type: 'event-select',
156
+ rules: [{ typeMatch: true }],
130
157
  },
131
158
  ],
132
159
  };
@@ -139,6 +166,7 @@ export const advancedTabConfig: TabPaneConfig = {
139
166
  name: NODE_DISABLE_CODE_BLOCK_KEY,
140
167
  text: '禁用代码块',
141
168
  type: 'switch',
169
+ labelPosition: 'left',
142
170
  defaultValue: false,
143
171
  extra: '开启后,配置的代码块将不会被执行',
144
172
  },
@@ -146,29 +174,63 @@ export const advancedTabConfig: TabPaneConfig = {
146
174
  name: NODE_DISABLE_DATA_SOURCE_KEY,
147
175
  text: '禁用数据源',
148
176
  type: 'switch',
177
+ labelPosition: 'left',
149
178
  defaultValue: false,
150
179
  extra: '开启后,组件内配置的数据源相关配置将不会被编译,显隐条件将失效',
151
180
  },
152
181
  {
153
182
  name: 'created',
154
- text: 'created',
183
+ text: 'Created',
155
184
  labelPosition: 'top',
156
185
  type: 'code-select',
157
- extra: '组件初始化时执行',
186
+ titleExtra: '组件初始化时执行',
187
+ rules: [
188
+ { typeMatch: true, trigger: 'change' },
189
+ {
190
+ validator: ({ value, callback }: any) => {
191
+ if (value && value.hookType !== HookType.CODE) {
192
+ return callback('hookType 必须是 code');
193
+ }
194
+ callback();
195
+ },
196
+ },
197
+ ],
158
198
  },
159
199
  {
160
200
  name: 'mounted',
161
- text: 'mounted',
201
+ text: 'Mounted',
162
202
  labelPosition: 'top',
163
203
  type: 'code-select',
164
- extra: '组件挂载到dom时执行',
204
+ titleExtra: '组件挂载到dom时执行',
205
+ rules: [
206
+ { typeMatch: true, trigger: 'change' },
207
+ {
208
+ validator: ({ value, callback }: any) => {
209
+ if (value && value.hookType !== HookType.CODE) {
210
+ return callback('hookType 必须是 code');
211
+ }
212
+ callback();
213
+ },
214
+ },
215
+ ],
165
216
  },
166
217
  {
167
218
  name: 'display',
168
- text: 'display',
169
- extra: '控制组件是否渲染,关系的代码块返回值为false时不渲染',
219
+ text: 'Display',
220
+ titleExtra: '控制组件是否渲染,关系的代码块返回值为false时不渲染',
170
221
  labelPosition: 'top',
171
222
  type: 'code-select',
223
+ rules: [
224
+ { typeMatch: true, trigger: 'change' },
225
+ {
226
+ validator: ({ value, callback }: any) => {
227
+ if (value && value.hookType !== HookType.CODE) {
228
+ return callback('hookType 必须是 code');
229
+ }
230
+ callback();
231
+ },
232
+ },
233
+ ],
172
234
  },
173
235
  ],
174
236
  };
@@ -189,11 +251,19 @@ export const displayTabConfig: TabPaneConfig<DisplayCondsConfig> = {
189
251
  extra: (_state, { model }) =>
190
252
  `条件成立时${model[NODE_CONDS_RESULT_KEY] ? '隐藏' : '显示'},不成立时${model[NODE_CONDS_RESULT_KEY] ? '显示' : '隐藏'};<br />同一条件组内的所有条件配置同时成立时表示该条件组成立,任意一个条件组成立时表示条件成立(条件组内为且的关系,条件组间为或的关系);<br />条件为空时表示成立;`,
191
253
  },
254
+ {
255
+ text: '条件组配置',
256
+ static: true,
257
+ className: 'display-conds-title',
258
+ },
192
259
  {
193
260
  type: 'display-conds',
194
261
  name: NODE_CONDS_KEY,
195
262
  titlePrefix: '条件组',
263
+ fixed: 'right',
264
+ operateColWidth: 112,
196
265
  defaultValue: [],
266
+ rules: [{ typeMatch: true }],
197
267
  },
198
268
  ],
199
269
  };
@@ -228,10 +298,13 @@ export const fillConfig = (
228
298
  name: 'id',
229
299
  text: 'ID',
230
300
  type: 'text',
231
- disabled: true,
301
+ // 走纯文本渲染,避免出现 disabled 的灰底输入框;append 仍正常显示。
302
+ static: true,
303
+
232
304
  append: {
233
- type: 'button',
234
- text: '复制',
305
+ type: 'icon',
306
+ text: 'https://vip.image.video.qpic.cn/vupload/20260615/36cf7e1781493669935.svg',
307
+ extra: '复制',
235
308
  handler: (vm, { model }) => {
236
309
  navigator.clipboard
237
310
  .writeText(`${model.id}`)
@@ -264,6 +337,7 @@ export const fillConfig = (
264
337
  const tabConfig: TabConfig = {
265
338
  type: 'tab',
266
339
  labelWidth,
340
+ className: 'magic-right-panel-tabs-top',
267
341
  items: [
268
342
  {
269
343
  title: '属性',
@@ -286,3 +360,32 @@ export const fillConfig = (
286
360
 
287
361
  return [tabConfig];
288
362
  };
363
+
364
+ /**
365
+ * 将属性表单配置中「样式」tab-pane 的 `display` 强制置为 `true`。
366
+ *
367
+ * `propsService.getPropsConfig` 返回的样式 tab 默认带有
368
+ * `display: ({ services }) => !(services?.uiService?.get('showStylePanel') ?? true)`,
369
+ * 在对比 / 只读展示场景(CompareForm / ViewForm)下并不需要跟随 uiService 状态隐藏,
370
+ * 这里统一放开,保证样式 tab 始终可见。
371
+ *
372
+ * @param formConfig 组件属性表单配置
373
+ * @returns 处理后的表单配置(不修改入参,返回浅拷贝)
374
+ */
375
+ export const removeStyleDisplayConfig = (formConfig: FormConfig): FormConfig =>
376
+ formConfig.map((item) => {
377
+ if (!('type' in item)) return item;
378
+ if (item?.type !== 'tab' || !Array.isArray(item.items)) return item;
379
+
380
+ return {
381
+ ...item,
382
+ items: item.items.map((tabPane) => {
383
+ if (tabPane?.title !== '样式' || !Array.isArray(tabPane.items)) return tabPane;
384
+
385
+ return {
386
+ ...tabPane,
387
+ display: true,
388
+ };
389
+ }),
390
+ };
391
+ });