@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.
- package/dist/es/Editor.vue_vue_type_script_setup_true_lang.js +43 -9
- package/dist/es/components/CodeBlockEditor.vue_vue_type_script_setup_true_lang.js +8 -4
- package/dist/es/components/CodeParams.vue_vue_type_script_setup_true_lang.js +3 -2
- package/dist/es/components/CompareForm.vue_vue_type_script_setup_true_lang.js +22 -98
- package/dist/es/components/ContentMenu.vue_vue_type_script_setup_true_lang.js +32 -9
- package/dist/es/components/FloatingBox.vue_vue_type_script_setup_true_lang.js +68 -17
- package/dist/es/components/Icon.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/Resizer.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/ScrollBar.js +0 -1
- package/dist/es/components/ScrollBar.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/ScrollViewer.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/SearchInput.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/SplitView.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/ToolButton.vue_vue_type_script_setup_true_lang.js +7 -7
- package/dist/es/components/Tree.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/TreeNode.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/ViewForm.js +5 -0
- package/dist/es/components/ViewForm.vue_vue_type_script_setup_true_lang.js +58 -0
- package/dist/es/editorProps.js +9 -1
- package/dist/es/fields/Code.vue_vue_type_script_setup_true_lang.js +16 -5
- package/dist/es/fields/CodeLink.vue_vue_type_script_setup_true_lang.js +7 -7
- package/dist/es/fields/CodeSelect.vue_vue_type_script_setup_true_lang.js +81 -44
- package/dist/es/fields/CodeSelectCol.vue_vue_type_script_setup_true_lang.js +10 -3
- package/dist/es/fields/CondOpSelect.vue_vue_type_script_setup_true_lang.js +7 -19
- package/dist/es/fields/DataSourceFieldSelect/FieldSelect.vue_vue_type_script_setup_true_lang.js +13 -6
- package/dist/es/fields/DataSourceFieldSelect/Index.vue_vue_type_script_setup_true_lang.js +11 -8
- package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +39 -12
- package/dist/es/fields/DataSourceInput.vue_vue_type_script_setup_true_lang.js +11 -20
- package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +11 -6
- package/dist/es/fields/DataSourceMethods.vue_vue_type_script_setup_true_lang.js +30 -14
- package/dist/es/fields/DataSourceMocks.vue_vue_type_script_setup_true_lang.js +11 -4
- package/dist/es/fields/DataSourceSelect.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/fields/DisplayConds.vue_vue_type_script_setup_true_lang.js +38 -6
- package/dist/es/fields/EventSelect.vue_vue_type_script_setup_true_lang.js +156 -155
- package/dist/es/fields/KeyValue.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/fields/PageFragmentSelect.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/fields/StyleSetter/Index.vue_vue_type_script_setup_true_lang.js +8 -10
- package/dist/es/fields/StyleSetter/components/BackgroundPosition.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/fields/StyleSetter/components/Border.vue_vue_type_script_setup_true_lang.js +28 -6
- package/dist/es/fields/StyleSetter/components/Box.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/icons/align-items/Center.js +31 -0
- package/dist/es/fields/StyleSetter/icons/align-items/FlexEnd.js +31 -0
- package/dist/es/fields/StyleSetter/icons/align-items/FlexStart.js +31 -0
- package/dist/es/fields/StyleSetter/icons/align-items/SpaceAround.js +50 -0
- package/dist/es/fields/StyleSetter/icons/align-items/SpaceBetween.js +50 -0
- package/dist/es/fields/StyleSetter/icons/background-repeat/NoRepeat.js +7 -7
- package/dist/es/fields/StyleSetter/icons/background-repeat/Repeat.js +6 -3
- package/dist/es/fields/StyleSetter/icons/background-repeat/RepeatX.js +29 -6
- package/dist/es/fields/StyleSetter/icons/background-repeat/RepeatY.js +32 -6
- package/dist/es/fields/StyleSetter/icons/display/Block.js +1 -1
- package/dist/es/fields/StyleSetter/icons/display/Flex.js +1 -1
- package/dist/es/fields/StyleSetter/icons/display/Inline.js +1 -1
- package/dist/es/fields/StyleSetter/icons/display/InlineBlock.js +1 -1
- package/dist/es/fields/StyleSetter/icons/display/None.js +1 -1
- package/dist/es/fields/StyleSetter/icons/flex-direction/Column.js +11 -3
- package/dist/es/fields/StyleSetter/icons/flex-direction/ColumnReverse.js +11 -3
- package/dist/es/fields/StyleSetter/icons/flex-direction/Row.js +11 -3
- package/dist/es/fields/StyleSetter/icons/flex-direction/RowReverse.js +11 -3
- package/dist/es/fields/StyleSetter/icons/justify-content/Center.js +17 -3
- package/dist/es/fields/StyleSetter/icons/justify-content/FlexEnd.js +19 -3
- package/dist/es/fields/StyleSetter/icons/justify-content/FlexStart.js +19 -3
- package/dist/es/fields/StyleSetter/icons/justify-content/SpaceAround.js +37 -3
- package/dist/es/fields/StyleSetter/icons/justify-content/SpaceBetween.js +33 -3
- package/dist/es/fields/StyleSetter/icons/text-align/Center.js +1 -1
- package/dist/es/fields/StyleSetter/icons/text-align/Left.js +1 -1
- package/dist/es/fields/StyleSetter/icons/text-align/Right.js +1 -1
- package/dist/es/fields/StyleSetter/pro/Background.vue_vue_type_script_setup_true_lang.js +56 -30
- package/dist/es/fields/StyleSetter/pro/Border.vue_vue_type_script_setup_true_lang.js +7 -4
- package/dist/es/fields/StyleSetter/pro/Font.vue_vue_type_script_setup_true_lang.js +35 -26
- package/dist/es/fields/StyleSetter/pro/Layout.vue_vue_type_script_setup_true_lang.js +76 -48
- package/dist/es/fields/StyleSetter/pro/Position.vue_vue_type_script_setup_true_lang.js +29 -23
- package/dist/es/fields/StyleSetter/pro/Transform.vue_vue_type_script_setup_true_lang.js +7 -4
- package/dist/es/fields/UISelect.js +0 -1
- package/dist/es/fields/UISelect.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/hooks/use-code-block-edit.js +6 -3
- package/dist/es/hooks/use-compare-form.js +119 -0
- package/dist/es/hooks/use-data-source-edit.js +5 -2
- package/dist/es/hooks/use-stage.js +9 -4
- package/dist/es/icons/CenterIcon.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/icons/CodeIcon.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/icons/DatasourceIcon.js +17 -0
- package/dist/es/icons/FolderMinusIcon.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/index.js +24 -10
- package/dist/es/initService.js +19 -13
- package/dist/es/layouts/AddPageBox.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/CodeEditor.vue_vue_type_script_setup_true_lang.js +24 -12
- package/dist/es/layouts/Framework.vue_vue_type_script_setup_true_lang.js +25 -18
- package/dist/es/layouts/NavMenu.vue_vue_type_script_setup_true_lang.js +4 -4
- package/dist/es/layouts/NavMenuColumn.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/history-list/Bucket.vue_vue_type_script_setup_true_lang.js +25 -38
- package/dist/es/layouts/history-list/BucketTab.js +5 -0
- package/dist/es/layouts/history-list/BucketTab.vue_vue_type_script_setup_true_lang.js +62 -0
- package/dist/es/layouts/history-list/GroupRow.vue_vue_type_script_setup_true_lang.js +177 -88
- package/dist/es/layouts/history-list/HistoryDiffDialog.vue_vue_type_script_setup_true_lang.js +139 -37
- package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +164 -107
- package/dist/es/layouts/history-list/InitialRow.vue_vue_type_script_setup_true_lang.js +44 -9
- package/dist/es/layouts/history-list/PageTab.vue_vue_type_script_setup_true_lang.js +49 -53
- package/dist/es/layouts/history-list/composables.js +138 -108
- package/dist/es/layouts/history-list/useHistoryList.js +56 -0
- package/dist/es/layouts/history-list/useHistoryRevert.js +317 -0
- package/dist/es/layouts/page-bar/AddButton.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/page-bar/PageBar.vue_vue_type_script_setup_true_lang.js +5 -3
- package/dist/es/layouts/page-bar/PageBarScrollContainer.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/page-bar/PageList.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/page-bar/Search.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/layouts/props-panel/FormPanel.vue_vue_type_script_setup_true_lang.js +50 -7
- package/dist/es/layouts/props-panel/PropsPanel.vue_vue_type_script_setup_true_lang.js +33 -13
- package/dist/es/layouts/props-panel/use-style-panel.js +3 -2
- package/dist/es/layouts/sidebar/ComponentListPanel.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/es/layouts/sidebar/Sidebar.vue_vue_type_script_setup_true_lang.js +26 -38
- package/dist/es/layouts/sidebar/code-block/CodeBlockList.vue_vue_type_script_setup_true_lang.js +4 -4
- package/dist/es/layouts/sidebar/code-block/CodeBlockListPanel.vue_vue_type_script_setup_true_lang.js +4 -4
- package/dist/es/layouts/sidebar/code-block/useContentMenu.js +19 -4
- package/dist/es/layouts/sidebar/data-source/DataSourceAddButton.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/sidebar/data-source/DataSourceConfigPanel.vue_vue_type_script_setup_true_lang.js +23 -6
- package/dist/es/layouts/sidebar/data-source/DataSourceList.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/sidebar/data-source/DataSourceListPanel.vue_vue_type_script_setup_true_lang.js +27 -5
- package/dist/es/layouts/sidebar/data-source/useContentMenu.js +19 -4
- package/dist/es/layouts/sidebar/layer/LayerMenu.vue_vue_type_script_setup_true_lang.js +8 -8
- package/dist/es/layouts/sidebar/layer/LayerNodeContent.js +5 -0
- package/dist/es/layouts/sidebar/layer/LayerNodeContent.vue_vue_type_script_setup_true_lang.js +46 -0
- package/dist/es/layouts/sidebar/layer/LayerNodeTool.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/layouts/sidebar/layer/LayerPanel.vue_vue_type_script_setup_true_lang.js +3 -2
- package/dist/es/layouts/sidebar/layer/use-click.js +3 -3
- package/dist/es/layouts/sidebar/layer/use-node-status.js +2 -2
- package/dist/es/layouts/workspace/Breadcrumb.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/workspace/Workspace.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/workspace/viewer/NodeListMenu.vue_vue_type_script_setup_true_lang.js +9 -3
- package/dist/es/layouts/workspace/viewer/Stage.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/layouts/workspace/viewer/StageOverlay.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/workspace/viewer/ViewerMenu.vue_vue_type_script_setup_true_lang.js +16 -16
- package/dist/es/plugin.js +5 -2
- package/dist/es/services/codeBlock.js +137 -56
- package/dist/es/services/dataSource.js +122 -52
- package/dist/es/services/dep.js +162 -41
- package/dist/es/services/editor.js +613 -179
- package/dist/es/services/events.js +2 -2
- package/dist/es/services/history.js +350 -386
- package/dist/es/services/keybinding.js +6 -6
- package/dist/es/services/props.js +3 -2
- package/dist/es/services/storage.js +2 -2
- package/dist/es/services/ui.js +10 -2
- package/dist/es/style.css +549 -113
- package/dist/es/utils/config.js +4 -1
- package/dist/es/utils/const.js +2 -2
- package/dist/es/utils/content-menu.js +19 -11
- package/dist/es/utils/data-source/index.js +34 -11
- package/dist/es/utils/dep/collect-worker-client.js +114 -0
- package/dist/es/utils/dep/idle-task.js +70 -22
- package/dist/es/utils/dep/worker.js +1 -1
- package/dist/es/utils/editor.js +103 -49
- package/dist/es/utils/event.js +135 -0
- package/dist/es/utils/history.js +220 -0
- package/dist/es/utils/indexed-db.js +86 -0
- package/dist/es/utils/monaco-editor.js +22 -6
- package/dist/es/utils/operator.js +2 -2
- package/dist/es/utils/props.js +114 -33
- package/dist/es/utils/type-match-rules.js +367 -0
- package/dist/es/utils/undo-redo.js +60 -1
- package/dist/style.css +549 -113
- package/dist/themes/magic-admin.css +3028 -0
- package/dist/tmagic-editor.umd.cjs +14403 -10121
- package/package.json +8 -8
- package/src/Editor.vue +43 -2
- package/src/components/CodeBlockEditor.vue +3 -0
- package/src/components/CompareForm.vue +18 -146
- package/src/components/ContentMenu.vue +44 -8
- package/src/components/FloatingBox.vue +84 -9
- package/src/components/ScrollBar.vue +0 -67
- package/src/components/ToolButton.vue +2 -2
- package/src/components/ViewForm.vue +55 -0
- package/src/editorProps.ts +30 -0
- package/src/fields/Code.vue +10 -2
- package/src/fields/CodeLink.vue +2 -5
- package/src/fields/CodeSelect.vue +54 -40
- package/src/fields/CodeSelectCol.vue +8 -1
- package/src/fields/CondOpSelect.vue +2 -24
- package/src/fields/DataSourceFieldSelect/FieldSelect.vue +16 -2
- package/src/fields/DataSourceFieldSelect/Index.vue +14 -5
- package/src/fields/DataSourceFields.vue +42 -8
- package/src/fields/DataSourceInput.vue +10 -28
- package/src/fields/DataSourceMethodSelect.vue +9 -4
- package/src/fields/DataSourceMethods.vue +42 -21
- package/src/fields/DataSourceMocks.vue +3 -0
- package/src/fields/DisplayConds.vue +18 -1
- package/src/fields/EventSelect.vue +152 -166
- package/src/fields/StyleSetter/Index.vue +3 -12
- package/src/fields/StyleSetter/components/Border.vue +15 -6
- package/src/fields/StyleSetter/icons/align-items/Center.vue +19 -0
- package/src/fields/StyleSetter/icons/align-items/FlexEnd.vue +19 -0
- package/src/fields/StyleSetter/icons/align-items/FlexStart.vue +19 -0
- package/src/fields/StyleSetter/icons/align-items/SpaceAround.vue +34 -0
- package/src/fields/StyleSetter/icons/align-items/SpaceBetween.vue +34 -0
- package/src/fields/StyleSetter/icons/align-items/index.ts +5 -0
- package/src/fields/StyleSetter/icons/background-repeat/NoRepeat.vue +20 -4
- package/src/fields/StyleSetter/icons/background-repeat/Repeat.vue +10 -28
- package/src/fields/StyleSetter/icons/background-repeat/RepeatX.vue +4 -5
- package/src/fields/StyleSetter/icons/background-repeat/RepeatY.vue +4 -5
- package/src/fields/StyleSetter/icons/flex-direction/Column.vue +4 -3
- package/src/fields/StyleSetter/icons/flex-direction/ColumnReverse.vue +4 -3
- package/src/fields/StyleSetter/icons/flex-direction/Row.vue +4 -3
- package/src/fields/StyleSetter/icons/flex-direction/RowReverse.vue +4 -3
- package/src/fields/StyleSetter/icons/justify-content/Center.vue +5 -2
- package/src/fields/StyleSetter/icons/justify-content/FlexEnd.vue +15 -2
- package/src/fields/StyleSetter/icons/justify-content/FlexStart.vue +15 -2
- package/src/fields/StyleSetter/icons/justify-content/SpaceAround.vue +28 -3
- package/src/fields/StyleSetter/icons/justify-content/SpaceBetween.vue +28 -2
- package/src/fields/StyleSetter/pro/Background.vue +99 -55
- package/src/fields/StyleSetter/pro/Border.vue +9 -11
- package/src/fields/StyleSetter/pro/Font.vue +66 -64
- package/src/fields/StyleSetter/pro/Layout.vue +211 -139
- package/src/fields/StyleSetter/pro/Position.vue +69 -67
- package/src/fields/StyleSetter/pro/Transform.vue +23 -25
- package/src/fields/UISelect.vue +0 -12
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-code-block-edit.ts +4 -3
- package/src/hooks/use-compare-form.ts +187 -0
- package/src/hooks/use-data-source-edit.ts +2 -2
- package/src/hooks/use-stage.ts +5 -3
- package/src/icons/DatasourceIcon.vue +7 -0
- package/src/index.ts +12 -0
- package/src/initService.ts +26 -16
- package/src/layouts/CodeEditor.vue +34 -11
- package/src/layouts/Framework.vue +15 -8
- package/src/layouts/NavMenu.vue +3 -3
- package/src/layouts/history-list/Bucket.vue +33 -41
- package/src/layouts/history-list/BucketTab.vue +72 -0
- package/src/layouts/history-list/GroupRow.vue +190 -93
- package/src/layouts/history-list/HistoryDiffDialog.vue +169 -90
- package/src/layouts/history-list/HistoryListPanel.vue +191 -95
- package/src/layouts/history-list/InitialRow.vue +38 -8
- package/src/layouts/history-list/PageTab.vue +67 -43
- package/src/layouts/history-list/composables.ts +239 -125
- package/src/layouts/history-list/useHistoryList.ts +60 -0
- package/src/layouts/history-list/useHistoryRevert.ts +425 -0
- package/src/layouts/page-bar/PageBar.vue +4 -2
- package/src/layouts/props-panel/FormPanel.vue +72 -6
- package/src/layouts/props-panel/PropsPanel.vue +62 -18
- package/src/layouts/props-panel/use-style-panel.ts +4 -3
- package/src/layouts/sidebar/ComponentListPanel.vue +10 -6
- package/src/layouts/sidebar/Sidebar.vue +13 -6
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +5 -5
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +5 -2
- package/src/layouts/sidebar/code-block/useContentMenu.ts +14 -2
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +34 -2
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +29 -4
- package/src/layouts/sidebar/data-source/useContentMenu.ts +14 -2
- package/src/layouts/sidebar/layer/LayerMenu.vue +21 -13
- package/src/layouts/sidebar/layer/LayerNodeContent.vue +57 -0
- package/src/layouts/sidebar/layer/LayerNodeTool.vue +7 -4
- package/src/layouts/sidebar/layer/LayerPanel.vue +4 -1
- package/src/layouts/sidebar/layer/use-click.ts +3 -3
- package/src/layouts/sidebar/layer/use-node-status.ts +2 -2
- package/src/layouts/workspace/viewer/NodeListMenu.vue +4 -1
- package/src/layouts/workspace/viewer/Stage.vue +1 -1
- package/src/layouts/workspace/viewer/ViewerMenu.vue +15 -15
- package/src/plugin.ts +6 -3
- package/src/services/codeBlock.ts +152 -47
- package/src/services/dataSource.ts +120 -41
- package/src/services/dep.ts +292 -47
- package/src/services/editor.ts +820 -224
- package/src/services/events.ts +3 -3
- package/src/services/history.ts +449 -412
- package/src/services/keybinding.ts +6 -6
- package/src/services/ui.ts +33 -5
- package/src/theme/code-block.scss +37 -0
- package/src/theme/common/var.scss +1 -1
- package/src/theme/component-list-panel.scss +2 -2
- package/src/theme/data-source-field.scss +4 -0
- package/src/theme/display-conds.scss +11 -0
- package/src/theme/event.scss +70 -1
- package/src/theme/floating-box.scss +9 -1
- package/src/theme/framework.scss +4 -1
- package/src/theme/history-list-panel.scss +157 -23
- package/src/theme/layer-node-content.scss +14 -0
- package/src/theme/nav-menu.scss +5 -1
- package/src/theme/page-bar.scss +0 -4
- package/src/theme/props-panel.scss +5 -4
- package/src/theme/scroll-bar.scss +64 -0
- package/src/theme/style-setter/border.scss +17 -5
- package/src/theme/theme.scss +4 -0
- package/src/theme/themes/magic-admin/index.scss +214 -0
- package/src/theme/ui-select.scss +9 -0
- package/src/type.ts +668 -124
- package/src/utils/config.ts +9 -1
- package/src/utils/const.ts +3 -2
- package/src/utils/content-menu.ts +20 -11
- package/src/utils/data-source/index.ts +32 -12
- package/src/utils/dep/collect-worker-client.ts +149 -0
- package/src/utils/dep/idle-task.ts +104 -35
- package/src/utils/dep/worker.ts +113 -9
- package/src/utils/editor.ts +166 -60
- package/src/utils/event.ts +237 -0
- package/src/utils/history.ts +286 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/indexed-db.ts +122 -0
- package/src/utils/monaco-editor.ts +27 -0
- package/src/utils/operator.ts +2 -2
- package/src/utils/props.ts +114 -11
- package/src/utils/type-match-rules.ts +684 -0
- package/src/utils/undo-redo.ts +88 -0
- package/types/index.d.ts +1990 -517
- package/dist/es/layouts/history-list/CodeBlockTab.js +0 -5
- package/dist/es/layouts/history-list/CodeBlockTab.vue_vue_type_script_setup_true_lang.js +0 -62
- package/dist/es/layouts/history-list/DataSourceTab.js +0 -5
- package/dist/es/layouts/history-list/DataSourceTab.vue_vue_type_script_setup_true_lang.js +0 -62
- package/src/layouts/history-list/CodeBlockTab.vue +0 -61
- package/src/layouts/history-list/DataSourceTab.vue +0 -61
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { CODE_DRAFT_STORAGE_KEY } from "../type.js";
|
|
2
|
+
import { getEditorConfig } from "../utils/config.js";
|
|
2
3
|
import BaseService from "./BaseService.js";
|
|
4
|
+
import { createStackStep, describeRevertStep, getLastPushedHistoryIds } from "../utils/history.js";
|
|
3
5
|
import history_default from "./history.js";
|
|
4
|
-
import { getEditorConfig } from "../utils/config.js";
|
|
5
6
|
import storage_default, { Protocol } from "./storage.js";
|
|
6
7
|
import { COPY_CODE_STORAGE_KEY } from "../utils/editor.js";
|
|
7
8
|
import editor_default from "./editor.js";
|
|
@@ -20,17 +21,6 @@ var canUsePluginMethods = {
|
|
|
20
21
|
],
|
|
21
22
|
sync: ["setCodeDslByIdSync"]
|
|
22
23
|
};
|
|
23
|
-
/**
|
|
24
|
-
* 「回滚」生成的新 step 简短描述。仅 service 层使用。
|
|
25
|
-
*/
|
|
26
|
-
var describeRevertCodeBlockStep = (step) => {
|
|
27
|
-
const { oldContent, newContent, changeRecords, id } = step;
|
|
28
|
-
if (oldContent === null && newContent) return `撤回新增 ${newContent.name || newContent.id || id}`;
|
|
29
|
-
if (oldContent && newContent === null) return `还原已删除的 ${oldContent.name || oldContent.id || id}`;
|
|
30
|
-
const name = newContent?.name || oldContent?.name || `${id}`;
|
|
31
|
-
const propPath = changeRecords?.[0]?.propPath;
|
|
32
|
-
return propPath ? `还原 ${name} · ${propPath}` : `还原 ${name}`;
|
|
33
|
-
};
|
|
34
24
|
var CodeBlock = class extends BaseService {
|
|
35
25
|
state = reactive({
|
|
36
26
|
codeDsl: null,
|
|
@@ -39,6 +29,16 @@ var CodeBlock = class extends BaseService {
|
|
|
39
29
|
undeletableList: [],
|
|
40
30
|
paramsColConfig: void 0
|
|
41
31
|
});
|
|
32
|
+
/**
|
|
33
|
+
* 最近一次写入历史栈的代码块历史记录 uuid(单条写入场景:新增 / 更新)。
|
|
34
|
+
* 供 setCodeDslById(Sync)AndGetHistoryId 取回,普通方法不读取它。
|
|
35
|
+
*/
|
|
36
|
+
lastPushedHistoryId = null;
|
|
37
|
+
/**
|
|
38
|
+
* deleteCodeDslByIds 一次删除多个代码块时,按写入顺序收集的历史记录 uuid 列表。
|
|
39
|
+
* 在 deleteCodeDslByIds 入口处重置,供 deleteCodeDslByIdsAndGetHistoryId 取回。
|
|
40
|
+
*/
|
|
41
|
+
lastDeletedHistoryIds = [];
|
|
42
42
|
constructor() {
|
|
43
43
|
super([...canUsePluginMethods.async.map((methodName) => ({
|
|
44
44
|
name: methodName,
|
|
@@ -56,6 +56,7 @@ var CodeBlock = class extends BaseService {
|
|
|
56
56
|
async setCodeDsl(codeDsl) {
|
|
57
57
|
this.state.codeDsl = codeDsl;
|
|
58
58
|
this.emit("code-dsl-change", this.state.codeDsl);
|
|
59
|
+
this.emit("change", this.state.codeDsl);
|
|
59
60
|
}
|
|
60
61
|
/**
|
|
61
62
|
* 获取活动的代码块dsl数据源(默认从dsl中的codeBlocks字段读取)
|
|
@@ -86,10 +87,12 @@ var CodeBlock = class extends BaseService {
|
|
|
86
87
|
* @param options.doNotPushHistory 是否不写入历史记录(默认 false)
|
|
87
88
|
* @returns {void}
|
|
88
89
|
*/
|
|
89
|
-
async setCodeDslById(id, codeConfig, { changeRecords, doNotPushHistory = false } = {}) {
|
|
90
|
+
async setCodeDslById(id, codeConfig, { changeRecords, doNotPushHistory = false, historyDescription, historySource } = {}) {
|
|
90
91
|
this.setCodeDslByIdSync(id, codeConfig, true, {
|
|
91
92
|
changeRecords,
|
|
92
|
-
doNotPushHistory
|
|
93
|
+
doNotPushHistory,
|
|
94
|
+
historyDescription,
|
|
95
|
+
historySource
|
|
93
96
|
});
|
|
94
97
|
}
|
|
95
98
|
/**
|
|
@@ -104,7 +107,7 @@ var CodeBlock = class extends BaseService {
|
|
|
104
107
|
* @param options.historyDescription 入栈时附带的人类可读描述,用于历史面板展示
|
|
105
108
|
* @returns {void}
|
|
106
109
|
*/
|
|
107
|
-
setCodeDslByIdSync(id, codeConfig, force = true, { changeRecords, doNotPushHistory = false, historyDescription } = {}) {
|
|
110
|
+
setCodeDslByIdSync(id, codeConfig, force = true, { changeRecords, doNotPushHistory = false, historyDescription, historySource } = {}) {
|
|
108
111
|
const codeDsl = this.getCodeDsl();
|
|
109
112
|
if (!codeDsl) throw new Error("dsl中没有codeBlocks");
|
|
110
113
|
if (codeDsl[id] && !force) return;
|
|
@@ -119,13 +122,18 @@ var CodeBlock = class extends BaseService {
|
|
|
119
122
|
...codeConfigProcessed
|
|
120
123
|
};
|
|
121
124
|
const newContent = cloneDeep$1(codeDsl[id]);
|
|
122
|
-
if (!doNotPushHistory)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
if (!doNotPushHistory) {
|
|
126
|
+
const step = createStackStep(id, {
|
|
127
|
+
oldValue: oldContent,
|
|
128
|
+
newValue: newContent,
|
|
129
|
+
changeRecords,
|
|
130
|
+
historyDescription,
|
|
131
|
+
source: historySource
|
|
132
|
+
});
|
|
133
|
+
this.lastPushedHistoryId = (step ? history_default.push("codeBlock", step, id) : null)?.uuid ?? null;
|
|
134
|
+
}
|
|
128
135
|
this.emit("addOrUpdate", id, codeDsl[id]);
|
|
136
|
+
this.emit("change", this.getCodeDsl());
|
|
129
137
|
}
|
|
130
138
|
/**
|
|
131
139
|
* 根据代码块id数组获取代码dsl
|
|
@@ -204,19 +212,63 @@ var CodeBlock = class extends BaseService {
|
|
|
204
212
|
* @param options 可选配置
|
|
205
213
|
* @param options.doNotPushHistory 是否不写入历史记录(默认 false)
|
|
206
214
|
*/
|
|
207
|
-
async deleteCodeDslByIds(codeIds, { doNotPushHistory = false, historyDescription } = {}) {
|
|
215
|
+
async deleteCodeDslByIds(codeIds, { doNotPushHistory = false, historyDescription, historySource } = {}) {
|
|
208
216
|
const currentDsl = await this.getCodeDsl();
|
|
209
217
|
if (!currentDsl) return;
|
|
218
|
+
this.lastDeletedHistoryIds = [];
|
|
210
219
|
codeIds.forEach((id) => {
|
|
211
|
-
const
|
|
220
|
+
const oldValue = currentDsl[id] ? cloneDeep$1(currentDsl[id]) : null;
|
|
212
221
|
delete currentDsl[id];
|
|
213
|
-
if (
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
222
|
+
if (oldValue && !doNotPushHistory) {
|
|
223
|
+
const step = createStackStep(id, {
|
|
224
|
+
oldValue,
|
|
225
|
+
newValue: null,
|
|
226
|
+
historyDescription,
|
|
227
|
+
source: historySource
|
|
228
|
+
});
|
|
229
|
+
const uuid = step ? history_default.push("codeBlock", step, id)?.uuid : void 0;
|
|
230
|
+
if (uuid) this.lastDeletedHistoryIds.push(uuid);
|
|
231
|
+
}
|
|
218
232
|
this.emit("remove", id);
|
|
219
233
|
});
|
|
234
|
+
this.emit("change", this.getCodeDsl());
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* 下列 *AndGetHistoryId 方法与对应的写入方法行为完全一致,
|
|
238
|
+
* 返回值在 {@link DslOpWithHistoryIdsResult} 中同时包含原操作结果与本次写入的历史 uuid 列表,
|
|
239
|
+
* 可用于精确引用 / 定位该条历史记录(埋点、revert、跨端同步等)。
|
|
240
|
+
*
|
|
241
|
+
* 当本次操作未写入历史(doNotPushHistory 为 true、或无对应记录)时 historyIds 为 `[]`。
|
|
242
|
+
*/
|
|
243
|
+
/** 等价于 {@link setCodeDslById},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
|
|
244
|
+
async setCodeDslByIdAndGetHistoryId(id, codeConfig, options = {}) {
|
|
245
|
+
this.lastPushedHistoryId = null;
|
|
246
|
+
await this.setCodeDslById(id, codeConfig, options);
|
|
247
|
+
return {
|
|
248
|
+
result: void 0,
|
|
249
|
+
historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId)
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/** 等价于 {@link setCodeDslByIdSync},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
|
|
253
|
+
setCodeDslByIdSyncAndGetHistoryId(id, codeConfig, force = true, options = {}) {
|
|
254
|
+
this.lastPushedHistoryId = null;
|
|
255
|
+
this.setCodeDslByIdSync(id, codeConfig, force, options);
|
|
256
|
+
return {
|
|
257
|
+
result: void 0,
|
|
258
|
+
historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId)
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* 等价于 {@link deleteCodeDslByIds},并额外返回本次写入的全部历史记录 uuid(按删除顺序)。
|
|
263
|
+
* 一次删除多个代码块会产生多条历史记录;未写入任何历史时 historyIds 为 `[]`。
|
|
264
|
+
*/
|
|
265
|
+
async deleteCodeDslByIdsAndGetHistoryId(codeIds, options = {}) {
|
|
266
|
+
this.lastDeletedHistoryIds = [];
|
|
267
|
+
await this.deleteCodeDslByIds(codeIds, options);
|
|
268
|
+
return {
|
|
269
|
+
result: void 0,
|
|
270
|
+
historyIds: [...this.lastDeletedHistoryIds]
|
|
271
|
+
};
|
|
220
272
|
}
|
|
221
273
|
setParamsColConfig(config) {
|
|
222
274
|
this.state.paramsColConfig = config;
|
|
@@ -236,7 +288,7 @@ var CodeBlock = class extends BaseService {
|
|
|
236
288
|
* @returns 撤销的 step;栈不存在或已无可撤销时返回 null
|
|
237
289
|
*/
|
|
238
290
|
async undo(id) {
|
|
239
|
-
const step = history_default.
|
|
291
|
+
const step = history_default.undo("codeBlock", id);
|
|
240
292
|
if (!step) return null;
|
|
241
293
|
await this.applyHistoryStep(step, true);
|
|
242
294
|
return step;
|
|
@@ -247,18 +299,18 @@ var CodeBlock = class extends BaseService {
|
|
|
247
299
|
* @returns 重做的 step;栈不存在或已无可重做时返回 null
|
|
248
300
|
*/
|
|
249
301
|
async redo(id) {
|
|
250
|
-
const step = history_default.
|
|
302
|
+
const step = history_default.redo("codeBlock", id);
|
|
251
303
|
if (!step) return null;
|
|
252
304
|
await this.applyHistoryStep(step, false);
|
|
253
305
|
return step;
|
|
254
306
|
}
|
|
255
307
|
/** 是否可对指定代码块撤销。 */
|
|
256
308
|
canUndo(id) {
|
|
257
|
-
return history_default.
|
|
309
|
+
return history_default.canUndo("codeBlock", id);
|
|
258
310
|
}
|
|
259
311
|
/** 是否可对指定代码块重做。 */
|
|
260
312
|
canRedo(id) {
|
|
261
|
-
return history_default.
|
|
313
|
+
return history_default.canRedo("codeBlock", id);
|
|
262
314
|
}
|
|
263
315
|
/**
|
|
264
316
|
* 跳转指定代码块的历史栈到目标游标。语义同 editor.gotoPageStep。
|
|
@@ -268,7 +320,7 @@ var CodeBlock = class extends BaseService {
|
|
|
268
320
|
* @returns 实际移动到的最终游标位置
|
|
269
321
|
*/
|
|
270
322
|
async goto(id, targetCursor) {
|
|
271
|
-
let cursor = history_default.
|
|
323
|
+
let cursor = history_default.getCursor("codeBlock", id);
|
|
272
324
|
const target = Math.max(0, targetCursor);
|
|
273
325
|
while (cursor > target) {
|
|
274
326
|
if (!await this.undo(id)) break;
|
|
@@ -291,12 +343,29 @@ var CodeBlock = class extends BaseService {
|
|
|
291
343
|
* @returns 反向后产生的新 step;目标不存在 / 未应用时返回 null
|
|
292
344
|
*/
|
|
293
345
|
async revert(id, index) {
|
|
294
|
-
const entry = history_default.
|
|
346
|
+
const entry = history_default.getStepList("codeBlock", id)[index];
|
|
295
347
|
if (!entry?.applied) return null;
|
|
296
|
-
const
|
|
348
|
+
const { oldSchema, newSchema, changeRecords } = entry.step.diff?.[0] ?? {};
|
|
349
|
+
if (oldSchema && newSchema && !changeRecords?.length) return null;
|
|
350
|
+
const description = `回滚 #${index + 1}: ${describeRevertStep(entry.step.data.id, entry.step.diff?.[0], (s) => s.name)}`;
|
|
297
351
|
return await this.applyRevertStep(entry.step, description);
|
|
298
352
|
}
|
|
299
353
|
/**
|
|
354
|
+
* 通过历史记录 uuid 回滚代码块历史步骤,语义同 {@link revert},
|
|
355
|
+
* 仅无需调用方再传 codeBlockId 与 index:内部会按 uuid 在全部代码块栈中定位对应步骤后再回滚。
|
|
356
|
+
* 按数组顺序依次回滚,返回与入参同序的结果列表(某项失败时为 `null`)。
|
|
357
|
+
*
|
|
358
|
+
* @param uuids 目标历史记录的 uuid 列表,通常由 {@link setCodeDslByIdAndGetHistoryId} 等方法返回的 `historyIds`
|
|
359
|
+
*/
|
|
360
|
+
async revertById(uuids) {
|
|
361
|
+
const results = [];
|
|
362
|
+
for (const uuid of uuids) {
|
|
363
|
+
const location = history_default.findStepLocationByUuid("codeBlock", uuid);
|
|
364
|
+
results.push(location ? await this.revert(location.id, location.index) : null);
|
|
365
|
+
}
|
|
366
|
+
return results;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
300
369
|
* 生成代码块唯一id
|
|
301
370
|
* @returns {Id} 代码块唯一id
|
|
302
371
|
*/
|
|
@@ -361,16 +430,23 @@ var CodeBlock = class extends BaseService {
|
|
|
361
430
|
* 差异仅在于通过公开的 setCodeDslByIdSync / deleteCodeDslByIds 触发 push。
|
|
362
431
|
*/
|
|
363
432
|
async applyRevertStep(step, historyDescription) {
|
|
364
|
-
const { id
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
433
|
+
const { id } = step.data;
|
|
434
|
+
const { oldSchema, newSchema, changeRecords } = step.diff?.[0] ?? {};
|
|
435
|
+
if (!oldSchema && newSchema) {
|
|
436
|
+
await this.deleteCodeDslByIds([id], {
|
|
437
|
+
historyDescription,
|
|
438
|
+
historySource: "rollback"
|
|
439
|
+
});
|
|
440
|
+
return history_default.getStepList("codeBlock", id).slice(-1)[0]?.step ?? null;
|
|
368
441
|
}
|
|
369
|
-
if (
|
|
370
|
-
this.setCodeDslByIdSync(id, cloneDeep$1(
|
|
371
|
-
|
|
442
|
+
if (oldSchema && !newSchema) {
|
|
443
|
+
this.setCodeDslByIdSync(id, cloneDeep$1(oldSchema), true, {
|
|
444
|
+
historyDescription,
|
|
445
|
+
historySource: "rollback"
|
|
446
|
+
});
|
|
447
|
+
return history_default.getStepList("codeBlock", id).slice(-1)[0]?.step ?? null;
|
|
372
448
|
}
|
|
373
|
-
if (!
|
|
449
|
+
if (!oldSchema || !newSchema) return null;
|
|
374
450
|
if (changeRecords?.length) {
|
|
375
451
|
const current = this.getCodeContentById(id);
|
|
376
452
|
if (!current) return null;
|
|
@@ -381,17 +457,21 @@ var CodeBlock = class extends BaseService {
|
|
|
381
457
|
fallbackToFullReplace = true;
|
|
382
458
|
break;
|
|
383
459
|
}
|
|
384
|
-
const value = cloneDeep$1(getValueByKeyPath(record.propPath,
|
|
460
|
+
const value = cloneDeep$1(getValueByKeyPath(record.propPath, oldSchema));
|
|
385
461
|
setValueByKeyPath(record.propPath, value, patched);
|
|
386
462
|
}
|
|
387
|
-
this.setCodeDslByIdSync(id, fallbackToFullReplace ? cloneDeep$1(
|
|
463
|
+
this.setCodeDslByIdSync(id, fallbackToFullReplace ? cloneDeep$1(oldSchema) : patched, true, {
|
|
388
464
|
changeRecords,
|
|
389
|
-
historyDescription
|
|
465
|
+
historyDescription,
|
|
466
|
+
historySource: "rollback"
|
|
390
467
|
});
|
|
391
|
-
return history_default.
|
|
468
|
+
return history_default.getStepList("codeBlock", id).slice(-1)[0]?.step ?? null;
|
|
392
469
|
}
|
|
393
|
-
this.setCodeDslByIdSync(id, cloneDeep$1(
|
|
394
|
-
|
|
470
|
+
this.setCodeDslByIdSync(id, cloneDeep$1(oldSchema), true, {
|
|
471
|
+
historyDescription,
|
|
472
|
+
historySource: "rollback"
|
|
473
|
+
});
|
|
474
|
+
return history_default.getStepList("codeBlock", id).slice(-1)[0]?.step ?? null;
|
|
395
475
|
}
|
|
396
476
|
/**
|
|
397
477
|
* 把一条历史 step 应用到当前代码块服务上。
|
|
@@ -408,19 +488,20 @@ var CodeBlock = class extends BaseService {
|
|
|
408
488
|
* @param reverse true=撤销,false=重做
|
|
409
489
|
*/
|
|
410
490
|
async applyHistoryStep(step, reverse) {
|
|
411
|
-
const { id
|
|
412
|
-
|
|
491
|
+
const { id } = step.data;
|
|
492
|
+
const { oldSchema, newSchema, changeRecords } = step.diff?.[0] ?? {};
|
|
493
|
+
if (!oldSchema && newSchema) {
|
|
413
494
|
if (reverse) await this.deleteCodeDslByIds([id], { doNotPushHistory: true });
|
|
414
|
-
else this.setCodeDslByIdSync(id, cloneDeep$1(
|
|
495
|
+
else this.setCodeDslByIdSync(id, cloneDeep$1(newSchema), true, { doNotPushHistory: true });
|
|
415
496
|
return;
|
|
416
497
|
}
|
|
417
|
-
if (
|
|
418
|
-
if (reverse) this.setCodeDslByIdSync(id, cloneDeep$1(
|
|
498
|
+
if (oldSchema && !newSchema) {
|
|
499
|
+
if (reverse) this.setCodeDslByIdSync(id, cloneDeep$1(oldSchema), true, { doNotPushHistory: true });
|
|
419
500
|
else await this.deleteCodeDslByIds([id], { doNotPushHistory: true });
|
|
420
501
|
return;
|
|
421
502
|
}
|
|
422
|
-
if (!
|
|
423
|
-
const sourceForValues = reverse ?
|
|
503
|
+
if (!oldSchema || !newSchema) return;
|
|
504
|
+
const sourceForValues = reverse ? oldSchema : newSchema;
|
|
424
505
|
if (changeRecords?.length) {
|
|
425
506
|
const current = this.getCodeContentById(id);
|
|
426
507
|
if (!current) return;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import BaseService from "./BaseService.js";
|
|
2
|
+
import { createStackStep, describeRevertStep, getLastPushedHistoryIds } from "../utils/history.js";
|
|
2
3
|
import history_default from "./history.js";
|
|
3
4
|
import storage_default, { Protocol } from "./storage.js";
|
|
4
5
|
import { COPY_DS_STORAGE_KEY } from "../utils/editor.js";
|
|
@@ -26,18 +27,6 @@ var canUsePluginMethods = {
|
|
|
26
27
|
"createId"
|
|
27
28
|
]
|
|
28
29
|
};
|
|
29
|
-
/**
|
|
30
|
-
* 「回滚」生成的新 step 简短描述。
|
|
31
|
-
* 仅在 service 层使用,避免依赖 UI 层 composables。
|
|
32
|
-
*/
|
|
33
|
-
var describeRevertDataSourceStep = (step) => {
|
|
34
|
-
const { oldSchema, newSchema, changeRecords, id } = step;
|
|
35
|
-
if (oldSchema === null && newSchema) return `撤回新增 ${newSchema.title || newSchema.id || id}`;
|
|
36
|
-
if (oldSchema && newSchema === null) return `还原已删除的 ${oldSchema.title || oldSchema.id || id}`;
|
|
37
|
-
const title = newSchema?.title || oldSchema?.title || `${id}`;
|
|
38
|
-
const propPath = changeRecords?.[0]?.propPath;
|
|
39
|
-
return propPath ? `还原 ${title} · ${propPath}` : `还原 ${title}`;
|
|
40
|
-
};
|
|
41
30
|
var DataSource = class extends BaseService {
|
|
42
31
|
state = reactive({
|
|
43
32
|
datasourceTypeList: [],
|
|
@@ -48,6 +37,12 @@ var DataSource = class extends BaseService {
|
|
|
48
37
|
events: {},
|
|
49
38
|
methods: {}
|
|
50
39
|
});
|
|
40
|
+
/**
|
|
41
|
+
* 最近一次写入历史栈的数据源历史记录 uuid。
|
|
42
|
+
* 供 *AndGetHistoryId 系列方法在调用 add / update / remove 后取回本次产生的历史记录 id;
|
|
43
|
+
* 普通方法不读取它,调用前由 *AndGetHistoryId 重置为 null。
|
|
44
|
+
*/
|
|
45
|
+
lastPushedHistoryId = null;
|
|
51
46
|
constructor() {
|
|
52
47
|
super(canUsePluginMethods.sync.map((methodName) => ({
|
|
53
48
|
name: methodName,
|
|
@@ -91,18 +86,23 @@ var DataSource = class extends BaseService {
|
|
|
91
86
|
* @param options.doNotPushHistory 是否不写入历史记录(默认 false)
|
|
92
87
|
* @param options.historyDescription 入栈时附带的人类可读描述,用于历史面板展示
|
|
93
88
|
*/
|
|
94
|
-
add(config, { doNotPushHistory = false, historyDescription } = {}) {
|
|
89
|
+
add(config, { doNotPushHistory = false, historyDescription, historySource } = {}) {
|
|
95
90
|
const newConfig = {
|
|
96
91
|
...config,
|
|
97
92
|
id: config.id && !this.getDataSourceById(config.id) ? config.id : this.createId()
|
|
98
93
|
};
|
|
99
94
|
this.get("dataSources").push(newConfig);
|
|
100
|
-
if (!doNotPushHistory)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
95
|
+
if (!doNotPushHistory) {
|
|
96
|
+
const step = createStackStep(newConfig.id, {
|
|
97
|
+
oldValue: null,
|
|
98
|
+
newValue: newConfig,
|
|
99
|
+
historyDescription,
|
|
100
|
+
source: historySource
|
|
101
|
+
});
|
|
102
|
+
this.lastPushedHistoryId = (step ? history_default.push("dataSource", step, newConfig.id) : null)?.uuid ?? null;
|
|
103
|
+
}
|
|
105
104
|
this.emit("add", newConfig);
|
|
105
|
+
this.emit("change", this.get("dataSources"));
|
|
106
106
|
return newConfig;
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
@@ -113,22 +113,27 @@ var DataSource = class extends BaseService {
|
|
|
113
113
|
* @param data.doNotPushHistory 是否不写入历史记录(默认 false)
|
|
114
114
|
* @param data.historyDescription 入栈时附带的人类可读描述,用于历史面板展示
|
|
115
115
|
*/
|
|
116
|
-
update(config, { changeRecords = [], doNotPushHistory = false, historyDescription } = {}) {
|
|
116
|
+
update(config, { changeRecords = [], doNotPushHistory = false, historyDescription, historySource } = {}) {
|
|
117
117
|
const dataSources = this.get("dataSources");
|
|
118
118
|
const index = dataSources.findIndex((ds) => ds.id === config.id);
|
|
119
119
|
const oldConfig = dataSources[index];
|
|
120
120
|
const newConfig = cloneDeep$1(config);
|
|
121
121
|
dataSources[index] = newConfig;
|
|
122
|
-
if (!doNotPushHistory)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
if (!doNotPushHistory) {
|
|
123
|
+
const step = createStackStep(newConfig.id, {
|
|
124
|
+
oldValue: oldConfig ? cloneDeep$1(oldConfig) : null,
|
|
125
|
+
newValue: newConfig,
|
|
126
|
+
changeRecords,
|
|
127
|
+
historyDescription,
|
|
128
|
+
source: historySource
|
|
129
|
+
});
|
|
130
|
+
this.lastPushedHistoryId = (step ? history_default.push("dataSource", step, newConfig.id) : null)?.uuid ?? null;
|
|
131
|
+
}
|
|
128
132
|
this.emit("update", newConfig, {
|
|
129
133
|
oldConfig,
|
|
130
134
|
changeRecords
|
|
131
135
|
});
|
|
136
|
+
this.emit("change", this.get("dataSources"));
|
|
132
137
|
return newConfig;
|
|
133
138
|
}
|
|
134
139
|
/**
|
|
@@ -138,17 +143,54 @@ var DataSource = class extends BaseService {
|
|
|
138
143
|
* @param options.doNotPushHistory 是否不写入历史记录(默认 false)
|
|
139
144
|
* @param options.historyDescription 入栈时附带的人类可读描述,用于历史面板展示
|
|
140
145
|
*/
|
|
141
|
-
remove(id, { doNotPushHistory = false, historyDescription } = {}) {
|
|
146
|
+
remove(id, { doNotPushHistory = false, historyDescription, historySource } = {}) {
|
|
142
147
|
const dataSources = this.get("dataSources");
|
|
143
148
|
const index = dataSources.findIndex((ds) => ds.id === id);
|
|
144
149
|
const oldConfig = index !== -1 ? dataSources[index] : null;
|
|
145
150
|
dataSources.splice(index, 1);
|
|
146
|
-
if (oldConfig && !doNotPushHistory)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
+
if (oldConfig && !doNotPushHistory) {
|
|
152
|
+
const step = createStackStep(id, {
|
|
153
|
+
oldValue: cloneDeep$1(oldConfig),
|
|
154
|
+
newValue: null,
|
|
155
|
+
historyDescription,
|
|
156
|
+
source: historySource
|
|
157
|
+
});
|
|
158
|
+
this.lastPushedHistoryId = (step ? history_default.push("dataSource", step, id) : null)?.uuid ?? null;
|
|
159
|
+
}
|
|
151
160
|
this.emit("remove", id);
|
|
161
|
+
this.emit("change", this.get("dataSources"));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* 下列 *AndGetHistoryId 方法与对应的 add / update / remove 行为完全一致,
|
|
165
|
+
* 返回值在 {@link DslOpWithHistoryIdsResult} 中同时包含原操作结果与本次写入历史栈的 uuid 列表({@link DataSourceStepValue.uuid}),
|
|
166
|
+
* 可用于精确引用 / 定位该条历史记录(埋点、revert、跨端同步等)。
|
|
167
|
+
*
|
|
168
|
+
* 当本次操作未写入历史(doNotPushHistory 为 true、或无对应记录)时 historyIds 为 `[]`。
|
|
169
|
+
*/
|
|
170
|
+
/** 等价于 {@link add},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
|
|
171
|
+
addAndGetHistoryId(config, options = {}) {
|
|
172
|
+
this.lastPushedHistoryId = null;
|
|
173
|
+
return {
|
|
174
|
+
result: this.add(config, options),
|
|
175
|
+
historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/** 等价于 {@link update},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
|
|
179
|
+
updateAndGetHistoryId(config, options = {}) {
|
|
180
|
+
this.lastPushedHistoryId = null;
|
|
181
|
+
return {
|
|
182
|
+
result: this.update(config, options),
|
|
183
|
+
historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId)
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/** 等价于 {@link remove},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
|
|
187
|
+
removeAndGetHistoryId(id, options = {}) {
|
|
188
|
+
this.lastPushedHistoryId = null;
|
|
189
|
+
this.remove(id, options);
|
|
190
|
+
return {
|
|
191
|
+
result: void 0,
|
|
192
|
+
historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId)
|
|
193
|
+
};
|
|
152
194
|
}
|
|
153
195
|
/**
|
|
154
196
|
* 撤销指定数据源的最近一次变更。
|
|
@@ -161,7 +203,7 @@ var DataSource = class extends BaseService {
|
|
|
161
203
|
* @returns 撤销的 step;栈不存在或已无可撤销时返回 null
|
|
162
204
|
*/
|
|
163
205
|
undo(id) {
|
|
164
|
-
const step = history_default.
|
|
206
|
+
const step = history_default.undo("dataSource", id);
|
|
165
207
|
if (!step) return null;
|
|
166
208
|
this.applyHistoryStep(step, true);
|
|
167
209
|
return step;
|
|
@@ -172,18 +214,18 @@ var DataSource = class extends BaseService {
|
|
|
172
214
|
* @returns 重做的 step;栈不存在或已无可重做时返回 null
|
|
173
215
|
*/
|
|
174
216
|
redo(id) {
|
|
175
|
-
const step = history_default.
|
|
217
|
+
const step = history_default.redo("dataSource", id);
|
|
176
218
|
if (!step) return null;
|
|
177
219
|
this.applyHistoryStep(step, false);
|
|
178
220
|
return step;
|
|
179
221
|
}
|
|
180
222
|
/** 是否可对指定数据源撤销。 */
|
|
181
223
|
canUndo(id) {
|
|
182
|
-
return history_default.
|
|
224
|
+
return history_default.canUndo("dataSource", id);
|
|
183
225
|
}
|
|
184
226
|
/** 是否可对指定数据源重做。 */
|
|
185
227
|
canRedo(id) {
|
|
186
|
-
return history_default.
|
|
228
|
+
return history_default.canRedo("dataSource", id);
|
|
187
229
|
}
|
|
188
230
|
/**
|
|
189
231
|
* 跳转指定数据源的历史栈到目标游标。语义同 editor.gotoPageStep。
|
|
@@ -193,7 +235,7 @@ var DataSource = class extends BaseService {
|
|
|
193
235
|
* @returns 实际移动到的最终游标位置
|
|
194
236
|
*/
|
|
195
237
|
goto(id, targetCursor) {
|
|
196
|
-
let cursor = history_default.
|
|
238
|
+
let cursor = history_default.getCursor("dataSource", id);
|
|
197
239
|
const target = Math.max(0, targetCursor);
|
|
198
240
|
while (cursor > target) {
|
|
199
241
|
if (!this.undo(id)) break;
|
|
@@ -216,11 +258,27 @@ var DataSource = class extends BaseService {
|
|
|
216
258
|
* @returns 反向后产生的新 step;目标不存在 / 未应用时返回 null
|
|
217
259
|
*/
|
|
218
260
|
revert(id, index) {
|
|
219
|
-
const entry = history_default.
|
|
261
|
+
const entry = history_default.getStepList("dataSource", id)[index];
|
|
220
262
|
if (!entry?.applied) return null;
|
|
221
|
-
const
|
|
263
|
+
const { oldSchema, newSchema, changeRecords } = entry.step.diff?.[0] ?? {};
|
|
264
|
+
if (oldSchema && newSchema && !changeRecords?.length) return null;
|
|
265
|
+
const description = `回滚 #${index + 1}: ${describeRevertStep(entry.step.data.id, entry.step.diff?.[0], (s) => s.title)}`;
|
|
222
266
|
return this.applyRevertStep(entry.step, description);
|
|
223
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* 通过历史记录 uuid 回滚数据源历史步骤,语义同 {@link revert},
|
|
270
|
+
* 仅无需调用方再传 dataSourceId 与 index:内部会按 uuid 在全部数据源栈中定位对应步骤后再回滚。
|
|
271
|
+
* 按数组顺序依次回滚,返回与入参同序的结果列表(某项失败时为 `null`)。
|
|
272
|
+
*
|
|
273
|
+
* @param uuids 目标历史记录的 uuid 列表,通常由 {@link addAndGetHistoryId} 等方法返回的 `historyIds`
|
|
274
|
+
*/
|
|
275
|
+
revertById(uuids) {
|
|
276
|
+
return uuids.map((uuid) => {
|
|
277
|
+
const location = history_default.findStepLocationByUuid("dataSource", uuid);
|
|
278
|
+
if (!location) return null;
|
|
279
|
+
return this.revert(location.id, location.index);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
224
282
|
createId() {
|
|
225
283
|
return `ds_${guid()}`;
|
|
226
284
|
}
|
|
@@ -279,14 +337,21 @@ var DataSource = class extends BaseService {
|
|
|
279
337
|
* 同构,差异仅在于走对应的公共 add / update / remove 而不是带 doNotPushHistory 的版本。
|
|
280
338
|
*/
|
|
281
339
|
applyRevertStep(step, historyDescription) {
|
|
282
|
-
const { id
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
340
|
+
const { id } = step.data;
|
|
341
|
+
const { oldSchema, newSchema, changeRecords } = step.diff?.[0] ?? {};
|
|
342
|
+
if (!oldSchema && newSchema) {
|
|
343
|
+
this.remove(`${id}`, {
|
|
344
|
+
historyDescription,
|
|
345
|
+
historySource: "rollback"
|
|
346
|
+
});
|
|
347
|
+
return history_default.getStepList("dataSource", id).slice(-1)[0]?.step ?? null;
|
|
286
348
|
}
|
|
287
|
-
if (oldSchema && newSchema
|
|
288
|
-
this.add(cloneDeep$1(oldSchema), {
|
|
289
|
-
|
|
349
|
+
if (oldSchema && !newSchema) {
|
|
350
|
+
this.add(cloneDeep$1(oldSchema), {
|
|
351
|
+
historyDescription,
|
|
352
|
+
historySource: "rollback"
|
|
353
|
+
});
|
|
354
|
+
return history_default.getStepList("dataSource", id).slice(-1)[0]?.step ?? null;
|
|
290
355
|
}
|
|
291
356
|
if (!oldSchema || !newSchema) return null;
|
|
292
357
|
if (changeRecords?.length) {
|
|
@@ -304,12 +369,16 @@ var DataSource = class extends BaseService {
|
|
|
304
369
|
}
|
|
305
370
|
this.update(fallbackToFullReplace ? cloneDeep$1(oldSchema) : patched, {
|
|
306
371
|
changeRecords,
|
|
307
|
-
historyDescription
|
|
372
|
+
historyDescription,
|
|
373
|
+
historySource: "rollback"
|
|
308
374
|
});
|
|
309
|
-
return history_default.
|
|
375
|
+
return history_default.getStepList("dataSource", id).slice(-1)[0]?.step ?? null;
|
|
310
376
|
}
|
|
311
|
-
this.update(cloneDeep$1(oldSchema), {
|
|
312
|
-
|
|
377
|
+
this.update(cloneDeep$1(oldSchema), {
|
|
378
|
+
historyDescription,
|
|
379
|
+
historySource: "rollback"
|
|
380
|
+
});
|
|
381
|
+
return history_default.getStepList("dataSource", id).slice(-1)[0]?.step ?? null;
|
|
313
382
|
}
|
|
314
383
|
/**
|
|
315
384
|
* 把一条历史 step 应用到当前数据源服务上。
|
|
@@ -326,13 +395,14 @@ var DataSource = class extends BaseService {
|
|
|
326
395
|
* @param reverse true=撤销,false=重做
|
|
327
396
|
*/
|
|
328
397
|
applyHistoryStep(step, reverse) {
|
|
329
|
-
const { id
|
|
330
|
-
|
|
398
|
+
const { id } = step.data;
|
|
399
|
+
const { oldSchema, newSchema, changeRecords } = step.diff?.[0] ?? {};
|
|
400
|
+
if (!oldSchema && newSchema) {
|
|
331
401
|
if (reverse) this.remove(`${id}`, { doNotPushHistory: true });
|
|
332
402
|
else this.add(cloneDeep$1(newSchema), { doNotPushHistory: true });
|
|
333
403
|
return;
|
|
334
404
|
}
|
|
335
|
-
if (oldSchema && newSchema
|
|
405
|
+
if (oldSchema && !newSchema) {
|
|
336
406
|
if (reverse) this.add(cloneDeep$1(oldSchema), { doNotPushHistory: true });
|
|
337
407
|
else this.remove(`${id}`, { doNotPushHistory: true });
|
|
338
408
|
return;
|