@tmagic/editor 1.8.0-beta.1 → 1.8.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/Editor.vue_vue_type_script_setup_true_lang.js +31 -5
- package/dist/es/components/CodeBlockEditor.vue_vue_type_script_setup_true_lang.js +21 -113
- package/dist/es/components/CodeParams.vue_vue_type_script_setup_true_lang.js +7 -1
- package/dist/es/components/CompareForm.js +5 -0
- package/dist/es/components/CompareForm.vue_vue_type_script_setup_true_lang.js +196 -0
- package/dist/es/components/ContentMenu.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/FloatingBox.vue_vue_type_script_setup_true_lang.js +2 -2
- 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.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/editorProps.js +2 -0
- package/dist/es/fields/Code.vue_vue_type_script_setup_true_lang.js +20 -4
- package/dist/es/fields/CodeLink.vue_vue_type_script_setup_true_lang.js +3 -6
- package/dist/es/fields/CodeSelect.vue_vue_type_script_setup_true_lang.js +19 -3
- package/dist/es/fields/CodeSelectCol.vue_vue_type_script_setup_true_lang.js +42 -8
- package/dist/es/fields/CondOpSelect.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/DataSourceFieldSelect/FieldSelect.vue_vue_type_script_setup_true_lang.js +14 -6
- package/dist/es/fields/DataSourceFieldSelect/Index.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +41 -16
- package/dist/es/fields/DataSourceInput.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +9 -5
- package/dist/es/fields/DataSourceMethods.vue_vue_type_script_setup_true_lang.js +40 -19
- package/dist/es/fields/DataSourceMocks.vue_vue_type_script_setup_true_lang.js +17 -9
- package/dist/es/fields/DataSourceSelect.vue_vue_type_script_setup_true_lang.js +4 -2
- package/dist/es/fields/DisplayConds.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/EventSelect.vue_vue_type_script_setup_true_lang.js +59 -12
- package/dist/es/fields/KeyValue.vue_vue_type_script_setup_true_lang.js +12 -7
- package/dist/es/fields/PageFragmentSelect.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/Index.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/components/BackgroundPosition.vue_vue_type_script_setup_true_lang.js +1 -1
- 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/background-repeat/NoRepeat.js +1 -1
- package/dist/es/fields/StyleSetter/icons/background-repeat/Repeat.js +1 -1
- package/dist/es/fields/StyleSetter/icons/background-repeat/RepeatX.js +1 -1
- package/dist/es/fields/StyleSetter/icons/background-repeat/RepeatY.js +1 -1
- 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 +1 -1
- package/dist/es/fields/StyleSetter/icons/flex-direction/ColumnReverse.js +1 -1
- package/dist/es/fields/StyleSetter/icons/flex-direction/Row.js +1 -1
- package/dist/es/fields/StyleSetter/icons/flex-direction/RowReverse.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/Center.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/FlexEnd.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/FlexStart.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/SpaceAround.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/SpaceBetween.js +1 -1
- 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 +1 -1
- package/dist/es/fields/StyleSetter/pro/Border.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/pro/Font.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/pro/Layout.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/pro/Position.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/pro/Transform.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/UISelect.vue_vue_type_script_setup_true_lang.js +9 -6
- package/dist/es/hooks/use-code-block-edit.js +7 -4
- package/dist/es/hooks/use-data-source-edit.js +5 -2
- package/dist/es/hooks/use-stage.js +22 -10
- 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/FolderMinusIcon.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/index.js +14 -3
- package/dist/es/initService.js +7 -7
- 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 +7 -6
- package/dist/es/layouts/Framework.vue_vue_type_script_setup_true_lang.js +14 -9
- package/dist/es/layouts/NavMenu.vue_vue_type_script_setup_true_lang.js +12 -4
- package/dist/es/layouts/NavMenuColumn.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/history-list/Bucket.js +5 -0
- package/dist/es/layouts/history-list/Bucket.vue_vue_type_script_setup_true_lang.js +71 -0
- 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.js +5 -0
- package/dist/es/layouts/history-list/GroupRow.vue_vue_type_script_setup_true_lang.js +269 -0
- package/dist/es/layouts/history-list/HistoryDiffDialog.js +5 -0
- package/dist/es/layouts/history-list/HistoryDiffDialog.vue_vue_type_script_setup_true_lang.js +294 -0
- package/dist/es/layouts/history-list/HistoryListPanel.js +5 -0
- package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +327 -0
- package/dist/es/layouts/history-list/InitialRow.js +5 -0
- package/dist/es/layouts/history-list/InitialRow.vue_vue_type_script_setup_true_lang.js +83 -0
- package/dist/es/layouts/history-list/PageTab.js +5 -0
- package/dist/es/layouts/history-list/PageTab.vue_vue_type_script_setup_true_lang.js +95 -0
- package/dist/es/layouts/history-list/composables.js +184 -0
- package/dist/es/layouts/history-list/useHistoryList.js +56 -0
- package/dist/es/layouts/history-list/useHistoryRevert.js +313 -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 +1 -1
- package/dist/es/layouts/props-panel/PropsPanel.vue_vue_type_script_setup_true_lang.js +6 -2
- package/dist/es/layouts/sidebar/ComponentListPanel.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/layouts/sidebar/Sidebar.vue_vue_type_script_setup_true_lang.js +8 -4
- 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 +2 -2
- package/dist/es/layouts/sidebar/code-block/useContentMenu.js +1 -1
- 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 +19 -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 +25 -3
- package/dist/es/layouts/sidebar/data-source/useContentMenu.js +1 -1
- package/dist/es/layouts/sidebar/layer/LayerMenu.vue_vue_type_script_setup_true_lang.js +6 -6
- 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 +1 -1
- package/dist/es/layouts/sidebar/layer/use-node-status.js +1 -1
- 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 +1 -1
- 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 +9 -9
- package/dist/es/services/BaseService.js +31 -68
- package/dist/es/services/codeBlock.js +286 -8
- package/dist/es/services/componentList.js +2 -2
- package/dist/es/services/dataSource.js +287 -8
- package/dist/es/services/dep.js +21 -9
- package/dist/es/services/editor.js +655 -194
- package/dist/es/services/events.js +2 -2
- package/dist/es/services/history.js +390 -47
- package/dist/es/services/keybinding.js +5 -5
- package/dist/es/services/props.js +8 -8
- package/dist/es/services/stageOverlay.js +2 -2
- package/dist/es/services/storage.js +2 -2
- package/dist/es/services/ui.js +5 -2
- package/dist/es/style.css +456 -8
- package/dist/es/utils/code-block.js +122 -0
- package/dist/es/utils/content-menu.js +19 -12
- package/dist/es/utils/data-source/index.js +2 -0
- package/dist/es/utils/dep/worker.js +1 -1
- package/dist/es/utils/editor.js +105 -51
- package/dist/es/utils/history.js +220 -0
- package/dist/es/utils/indexed-db.js +86 -0
- package/dist/es/utils/undo-redo.js +80 -1
- package/dist/style.css +456 -8
- package/dist/tmagic-editor.umd.cjs +11149 -6646
- package/package.json +8 -8
- package/src/Editor.vue +25 -1
- package/src/components/CodeBlockEditor.vue +20 -109
- package/src/components/CodeParams.vue +6 -0
- package/src/components/CompareForm.vue +277 -0
- package/src/components/ToolButton.vue +2 -2
- package/src/editorProps.ts +9 -0
- package/src/fields/Code.vue +19 -3
- package/src/fields/CodeLink.vue +2 -5
- package/src/fields/CodeSelect.vue +17 -1
- package/src/fields/CodeSelectCol.vue +37 -3
- package/src/fields/DataSourceFieldSelect/FieldSelect.vue +23 -3
- package/src/fields/DataSourceFieldSelect/Index.vue +2 -2
- package/src/fields/DataSourceFields.vue +48 -10
- package/src/fields/DataSourceInput.vue +3 -3
- package/src/fields/DataSourceMethodSelect.vue +12 -4
- package/src/fields/DataSourceMethods.vue +55 -24
- package/src/fields/DataSourceMocks.vue +13 -3
- package/src/fields/DataSourceSelect.vue +4 -1
- package/src/fields/EventSelect.vue +57 -8
- package/src/fields/KeyValue.vue +17 -4
- package/src/fields/StyleSetter/components/Border.vue +15 -6
- package/src/fields/UISelect.vue +5 -2
- package/src/hooks/use-code-block-edit.ts +9 -5
- package/src/hooks/use-data-source-edit.ts +2 -2
- package/src/hooks/use-stage.ts +26 -9
- package/src/index.ts +8 -0
- package/src/initService.ts +1 -1
- package/src/layouts/CodeEditor.vue +17 -5
- package/src/layouts/Framework.vue +11 -6
- package/src/layouts/NavMenu.vue +12 -3
- package/src/layouts/history-list/Bucket.vue +91 -0
- package/src/layouts/history-list/BucketTab.vue +72 -0
- package/src/layouts/history-list/GroupRow.vue +304 -0
- package/src/layouts/history-list/HistoryDiffDialog.vue +281 -0
- package/src/layouts/history-list/HistoryListPanel.vue +367 -0
- package/src/layouts/history-list/InitialRow.vue +71 -0
- package/src/layouts/history-list/PageTab.vue +118 -0
- package/src/layouts/history-list/composables.ts +309 -0
- package/src/layouts/history-list/useHistoryList.ts +60 -0
- package/src/layouts/history-list/useHistoryRevert.ts +421 -0
- package/src/layouts/page-bar/PageBar.vue +4 -2
- package/src/layouts/props-panel/PropsPanel.vue +5 -1
- package/src/layouts/sidebar/ComponentListPanel.vue +9 -5
- package/src/layouts/sidebar/Sidebar.vue +8 -3
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +5 -5
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +1 -1
- package/src/layouts/sidebar/code-block/useContentMenu.ts +1 -1
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +31 -2
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +27 -2
- package/src/layouts/sidebar/data-source/useContentMenu.ts +1 -1
- package/src/layouts/sidebar/layer/LayerMenu.vue +19 -11
- package/src/layouts/sidebar/layer/LayerNodeTool.vue +7 -4
- package/src/layouts/sidebar/layer/use-node-status.ts +9 -6
- package/src/layouts/workspace/viewer/Stage.vue +1 -1
- package/src/layouts/workspace/viewer/ViewerMenu.vue +8 -8
- package/src/services/BaseService.ts +35 -86
- package/src/services/codeBlock.ts +361 -5
- package/src/services/dataSource.ts +336 -6
- package/src/services/dep.ts +32 -9
- package/src/services/editor.ts +834 -194
- package/src/services/history.ts +509 -49
- package/src/services/keybinding.ts +3 -3
- package/src/services/props.ts +2 -2
- package/src/services/ui.ts +7 -0
- package/src/theme/history-list-panel.scss +557 -0
- package/src/theme/page-bar.scss +0 -4
- package/src/theme/props-panel.scss +3 -3
- package/src/theme/style-setter/border.scss +4 -1
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +613 -31
- package/src/utils/code-block.ts +150 -0
- package/src/utils/content-menu.ts +25 -13
- package/src/utils/data-source/index.ts +2 -0
- package/src/utils/dep/worker.ts +5 -3
- package/src/utils/editor.ts +166 -60
- package/src/utils/history.ts +286 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/indexed-db.ts +122 -0
- package/src/utils/undo-redo.ts +111 -0
- package/types/index.d.ts +3197 -896
- package/dist/es/utils/compose.js +0 -44
- package/dist/es/utils/editor-history.js +0 -100
- package/src/utils/compose.ts +0 -52
- package/src/utils/editor-history.ts +0 -138
|
@@ -4,14 +4,23 @@ import type { Writable } from 'type-fest';
|
|
|
4
4
|
|
|
5
5
|
import type { DataSourceSchema, EventOption, Id, MNode, TargetOptions } from '@tmagic/core';
|
|
6
6
|
import { Target, Watcher } from '@tmagic/core';
|
|
7
|
-
import type {
|
|
8
|
-
import { guid, toLine } from '@tmagic/utils';
|
|
7
|
+
import type { FormConfig } from '@tmagic/form';
|
|
8
|
+
import { getValueByKeyPath, guid, setValueByKeyPath, toLine } from '@tmagic/utils';
|
|
9
9
|
|
|
10
10
|
import editorService from '@editor/services/editor';
|
|
11
|
+
import historyService from '@editor/services/history';
|
|
11
12
|
import storageService, { Protocol } from '@editor/services/storage';
|
|
12
|
-
import type {
|
|
13
|
+
import type {
|
|
14
|
+
DataSourceStepValue,
|
|
15
|
+
DatasourceTypeOption,
|
|
16
|
+
DslOpWithHistoryIdsResult,
|
|
17
|
+
HistoryOpOptions,
|
|
18
|
+
HistoryOpOptionsWithChangeRecords,
|
|
19
|
+
SyncHookPlugin,
|
|
20
|
+
} from '@editor/type';
|
|
13
21
|
import { getFormConfig, getFormValue } from '@editor/utils/data-source';
|
|
14
22
|
import { COPY_DS_STORAGE_KEY } from '@editor/utils/editor';
|
|
23
|
+
import { createStackStep, describeRevertStep, getLastPushedHistoryIds } from '@editor/utils/history';
|
|
15
24
|
|
|
16
25
|
import BaseService from './BaseService';
|
|
17
26
|
|
|
@@ -58,6 +67,13 @@ class DataSource extends BaseService {
|
|
|
58
67
|
methods: {},
|
|
59
68
|
});
|
|
60
69
|
|
|
70
|
+
/**
|
|
71
|
+
* 最近一次写入历史栈的数据源历史记录 uuid。
|
|
72
|
+
* 供 *AndGetHistoryId 系列方法在调用 add / update / remove 后取回本次产生的历史记录 id;
|
|
73
|
+
* 普通方法不读取它,调用前由 *AndGetHistoryId 重置为 null。
|
|
74
|
+
*/
|
|
75
|
+
private lastPushedHistoryId: string | null = null;
|
|
76
|
+
|
|
61
77
|
constructor() {
|
|
62
78
|
super(canUsePluginMethods.sync.map((methodName) => ({ name: methodName, isAsync: false })));
|
|
63
79
|
}
|
|
@@ -102,7 +118,17 @@ class DataSource extends BaseService {
|
|
|
102
118
|
this.get('methods')[toLine(type)] = value;
|
|
103
119
|
}
|
|
104
120
|
|
|
105
|
-
|
|
121
|
+
/**
|
|
122
|
+
* 新增数据源
|
|
123
|
+
* @param config 数据源配置
|
|
124
|
+
* @param options 可选配置
|
|
125
|
+
* @param options.doNotPushHistory 是否不写入历史记录(默认 false)
|
|
126
|
+
* @param options.historyDescription 入栈时附带的人类可读描述,用于历史面板展示
|
|
127
|
+
*/
|
|
128
|
+
public add(
|
|
129
|
+
config: DataSourceSchema,
|
|
130
|
+
{ doNotPushHistory = false, historyDescription, historySource }: HistoryOpOptions = {},
|
|
131
|
+
) {
|
|
106
132
|
const newConfig = {
|
|
107
133
|
...config,
|
|
108
134
|
id: config.id && !this.getDataSourceById(config.id) ? config.id : this.createId(),
|
|
@@ -110,12 +136,39 @@ class DataSource extends BaseService {
|
|
|
110
136
|
|
|
111
137
|
this.get('dataSources').push(newConfig);
|
|
112
138
|
|
|
139
|
+
if (!doNotPushHistory) {
|
|
140
|
+
const step = createStackStep<DataSourceSchema, DataSourceStepValue>(newConfig.id, {
|
|
141
|
+
oldValue: null,
|
|
142
|
+
newValue: newConfig,
|
|
143
|
+
historyDescription,
|
|
144
|
+
source: historySource,
|
|
145
|
+
});
|
|
146
|
+
this.lastPushedHistoryId = (step ? historyService.push('dataSource', step, newConfig.id) : null)?.uuid ?? null;
|
|
147
|
+
}
|
|
148
|
+
|
|
113
149
|
this.emit('add', newConfig);
|
|
150
|
+
this.emit('change', this.get('dataSources'));
|
|
114
151
|
|
|
115
152
|
return newConfig;
|
|
116
153
|
}
|
|
117
154
|
|
|
118
|
-
|
|
155
|
+
/**
|
|
156
|
+
* 更新数据源
|
|
157
|
+
* @param config 数据源配置
|
|
158
|
+
* @param data 额外数据
|
|
159
|
+
* @param data.changeRecords form 端变更记录
|
|
160
|
+
* @param data.doNotPushHistory 是否不写入历史记录(默认 false)
|
|
161
|
+
* @param data.historyDescription 入栈时附带的人类可读描述,用于历史面板展示
|
|
162
|
+
*/
|
|
163
|
+
public update(
|
|
164
|
+
config: DataSourceSchema,
|
|
165
|
+
{
|
|
166
|
+
changeRecords = [],
|
|
167
|
+
doNotPushHistory = false,
|
|
168
|
+
historyDescription,
|
|
169
|
+
historySource,
|
|
170
|
+
}: HistoryOpOptionsWithChangeRecords = {},
|
|
171
|
+
) {
|
|
119
172
|
const dataSources = this.get('dataSources');
|
|
120
173
|
|
|
121
174
|
const index = dataSources.findIndex((ds) => ds.id === config.id);
|
|
@@ -125,20 +178,184 @@ class DataSource extends BaseService {
|
|
|
125
178
|
|
|
126
179
|
dataSources[index] = newConfig;
|
|
127
180
|
|
|
181
|
+
if (!doNotPushHistory) {
|
|
182
|
+
const step = createStackStep<DataSourceSchema, DataSourceStepValue>(newConfig.id, {
|
|
183
|
+
oldValue: oldConfig ? cloneDeep(oldConfig) : null,
|
|
184
|
+
newValue: newConfig,
|
|
185
|
+
changeRecords,
|
|
186
|
+
historyDescription,
|
|
187
|
+
source: historySource,
|
|
188
|
+
});
|
|
189
|
+
this.lastPushedHistoryId = (step ? historyService.push('dataSource', step, newConfig.id) : null)?.uuid ?? null;
|
|
190
|
+
}
|
|
191
|
+
|
|
128
192
|
this.emit('update', newConfig, {
|
|
129
193
|
oldConfig,
|
|
130
194
|
changeRecords,
|
|
131
195
|
});
|
|
196
|
+
this.emit('change', this.get('dataSources'));
|
|
132
197
|
|
|
133
198
|
return newConfig;
|
|
134
199
|
}
|
|
135
200
|
|
|
136
|
-
|
|
201
|
+
/**
|
|
202
|
+
* 删除数据源
|
|
203
|
+
* @param id 数据源 id
|
|
204
|
+
* @param options 可选配置
|
|
205
|
+
* @param options.doNotPushHistory 是否不写入历史记录(默认 false)
|
|
206
|
+
* @param options.historyDescription 入栈时附带的人类可读描述,用于历史面板展示
|
|
207
|
+
*/
|
|
208
|
+
public remove(id: string, { doNotPushHistory = false, historyDescription, historySource }: HistoryOpOptions = {}) {
|
|
137
209
|
const dataSources = this.get('dataSources');
|
|
138
210
|
const index = dataSources.findIndex((ds) => ds.id === id);
|
|
211
|
+
const oldConfig = index !== -1 ? dataSources[index] : null;
|
|
139
212
|
dataSources.splice(index, 1);
|
|
140
213
|
|
|
214
|
+
if (oldConfig && !doNotPushHistory) {
|
|
215
|
+
const step = createStackStep<DataSourceSchema, DataSourceStepValue>(id, {
|
|
216
|
+
oldValue: cloneDeep(oldConfig),
|
|
217
|
+
newValue: null,
|
|
218
|
+
historyDescription,
|
|
219
|
+
source: historySource,
|
|
220
|
+
});
|
|
221
|
+
this.lastPushedHistoryId = (step ? historyService.push('dataSource', step, id) : null)?.uuid ?? null;
|
|
222
|
+
}
|
|
223
|
+
|
|
141
224
|
this.emit('remove', id);
|
|
225
|
+
this.emit('change', this.get('dataSources'));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// #region AndGetHistoryId
|
|
229
|
+
/**
|
|
230
|
+
* 下列 *AndGetHistoryId 方法与对应的 add / update / remove 行为完全一致,
|
|
231
|
+
* 返回值在 {@link DslOpWithHistoryIdsResult} 中同时包含原操作结果与本次写入历史栈的 uuid 列表({@link DataSourceStepValue.uuid}),
|
|
232
|
+
* 可用于精确引用 / 定位该条历史记录(埋点、revert、跨端同步等)。
|
|
233
|
+
*
|
|
234
|
+
* 当本次操作未写入历史(doNotPushHistory 为 true、或无对应记录)时 historyIds 为 `[]`。
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
/** 等价于 {@link add},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
|
|
238
|
+
public addAndGetHistoryId(
|
|
239
|
+
config: DataSourceSchema,
|
|
240
|
+
options: HistoryOpOptions = {},
|
|
241
|
+
): DslOpWithHistoryIdsResult<DataSourceSchema> {
|
|
242
|
+
this.lastPushedHistoryId = null;
|
|
243
|
+
const result = this.add(config, options);
|
|
244
|
+
return { result, historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId) };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** 等价于 {@link update},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
|
|
248
|
+
public updateAndGetHistoryId(
|
|
249
|
+
config: DataSourceSchema,
|
|
250
|
+
options: HistoryOpOptionsWithChangeRecords = {},
|
|
251
|
+
): DslOpWithHistoryIdsResult<DataSourceSchema> {
|
|
252
|
+
this.lastPushedHistoryId = null;
|
|
253
|
+
const result = this.update(config, options);
|
|
254
|
+
return { result, historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId) };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** 等价于 {@link remove},并额外返回本次写入历史记录的 uuid 列表(未入栈时 historyIds 为 `[]`)。 */
|
|
258
|
+
public removeAndGetHistoryId(id: string, options: HistoryOpOptions = {}): DslOpWithHistoryIdsResult<void> {
|
|
259
|
+
this.lastPushedHistoryId = null;
|
|
260
|
+
this.remove(id, options);
|
|
261
|
+
return { result: undefined, historyIds: getLastPushedHistoryIds(this.lastPushedHistoryId) };
|
|
262
|
+
}
|
|
263
|
+
// #endregion AndGetHistoryId
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* 撤销指定数据源的最近一次变更。
|
|
267
|
+
*
|
|
268
|
+
* 内部走 add / update / remove,因此会自动触发 dataSourceService 的事件,
|
|
269
|
+
* 由 initService 中的对应 handler 重新收集 dep(DATA_SOURCE / DATA_SOURCE_COND / DATA_SOURCE_METHOD)。
|
|
270
|
+
* 所有写回都带 `doNotPushHistory: true`,避免在历史栈里产生新的记录。
|
|
271
|
+
*
|
|
272
|
+
* @param id 数据源 id
|
|
273
|
+
* @returns 撤销的 step;栈不存在或已无可撤销时返回 null
|
|
274
|
+
*/
|
|
275
|
+
public undo(id: Id) {
|
|
276
|
+
const step = historyService.undo('dataSource', id);
|
|
277
|
+
if (!step) return null;
|
|
278
|
+
this.applyHistoryStep(step, true);
|
|
279
|
+
return step;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* 重做指定数据源的下一次变更。
|
|
284
|
+
* @param id 数据源 id
|
|
285
|
+
* @returns 重做的 step;栈不存在或已无可重做时返回 null
|
|
286
|
+
*/
|
|
287
|
+
public redo(id: Id) {
|
|
288
|
+
const step = historyService.redo('dataSource', id);
|
|
289
|
+
if (!step) return null;
|
|
290
|
+
this.applyHistoryStep(step, false);
|
|
291
|
+
return step;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** 是否可对指定数据源撤销。 */
|
|
295
|
+
public canUndo(id: Id): boolean {
|
|
296
|
+
return historyService.canUndo('dataSource', id);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** 是否可对指定数据源重做。 */
|
|
300
|
+
public canRedo(id: Id): boolean {
|
|
301
|
+
return historyService.canRedo('dataSource', id);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* 跳转指定数据源的历史栈到目标游标。语义同 editor.gotoPageStep。
|
|
306
|
+
*
|
|
307
|
+
* @param id 数据源 id
|
|
308
|
+
* @param targetCursor 目标游标位置(已应用步骤数量)
|
|
309
|
+
* @returns 实际移动到的最终游标位置
|
|
310
|
+
*/
|
|
311
|
+
public goto(id: Id, targetCursor: number): number {
|
|
312
|
+
let cursor = historyService.getCursor('dataSource', id);
|
|
313
|
+
const target = Math.max(0, targetCursor);
|
|
314
|
+
while (cursor > target) {
|
|
315
|
+
if (!this.undo(id)) break;
|
|
316
|
+
cursor -= 1;
|
|
317
|
+
}
|
|
318
|
+
while (cursor < target) {
|
|
319
|
+
if (!this.redo(id)) break;
|
|
320
|
+
cursor += 1;
|
|
321
|
+
}
|
|
322
|
+
return cursor;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* 「回滚」指定数据源历史步骤(类 git revert 语义):
|
|
327
|
+
* - 不动原始栈结构(不移动 cursor、不丢弃任何步骤);
|
|
328
|
+
* - 把目标 step 的修改**反向应用**一次,并作为**新步骤**追加到栈顶;
|
|
329
|
+
* - 仅对已应用的步骤生效——未应用步骤本身就不存在于当前 schema 中,反向无意义。
|
|
330
|
+
*
|
|
331
|
+
* @param id 数据源 id
|
|
332
|
+
* @param index 目标 step 在该栈中的索引(0 为最早),通常由历史面板传入
|
|
333
|
+
* @returns 反向后产生的新 step;目标不存在 / 未应用时返回 null
|
|
334
|
+
*/
|
|
335
|
+
public revert(id: Id, index: number): DataSourceStepValue | null {
|
|
336
|
+
const list = historyService.getStepList('dataSource', id);
|
|
337
|
+
const entry = list[index];
|
|
338
|
+
if (!entry?.applied) return null;
|
|
339
|
+
// 更新类步骤(前后 schema 都存在)必须带 changeRecords 才支持回滚,否则只能整 schema 替换,会冲掉后续无关变更。
|
|
340
|
+
const { oldSchema, newSchema, changeRecords } = entry.step.diff?.[0] ?? {};
|
|
341
|
+
if (oldSchema && newSchema && !changeRecords?.length) return null;
|
|
342
|
+
const description = `回滚 #${index + 1}: ${describeRevertStep<DataSourceSchema>(entry.step.data.id, entry.step.diff?.[0], (s) => s.title)}`;
|
|
343
|
+
return this.applyRevertStep(entry.step, description);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* 通过历史记录 uuid 回滚数据源历史步骤,语义同 {@link revert},
|
|
348
|
+
* 仅无需调用方再传 dataSourceId 与 index:内部会按 uuid 在全部数据源栈中定位对应步骤后再回滚。
|
|
349
|
+
* 按数组顺序依次回滚,返回与入参同序的结果列表(某项失败时为 `null`)。
|
|
350
|
+
*
|
|
351
|
+
* @param uuids 目标历史记录的 uuid 列表,通常由 {@link addAndGetHistoryId} 等方法返回的 `historyIds`
|
|
352
|
+
*/
|
|
353
|
+
public revertById(uuids: string[]): (DataSourceStepValue | null)[] {
|
|
354
|
+
return uuids.map((uuid) => {
|
|
355
|
+
const location = historyService.findStepLocationByUuid('dataSource', uuid);
|
|
356
|
+
if (!location) return null;
|
|
357
|
+
return this.revert(location.id, location.index);
|
|
358
|
+
});
|
|
142
359
|
}
|
|
143
360
|
|
|
144
361
|
public createId(): string {
|
|
@@ -215,6 +432,119 @@ class DataSource extends BaseService {
|
|
|
215
432
|
}
|
|
216
433
|
});
|
|
217
434
|
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* 反向应用一个 step 并以新 step 入栈(不带 doNotPushHistory)。逻辑与 applyHistoryStep(reverse=true)
|
|
438
|
+
* 同构,差异仅在于走对应的公共 add / update / remove 而不是带 doNotPushHistory 的版本。
|
|
439
|
+
*/
|
|
440
|
+
private applyRevertStep(step: DataSourceStepValue, historyDescription: string): DataSourceStepValue | null {
|
|
441
|
+
const { id } = step.data;
|
|
442
|
+
const { oldSchema, newSchema, changeRecords } = step.diff?.[0] ?? {};
|
|
443
|
+
|
|
444
|
+
// 原本是新增 → revert 即删除
|
|
445
|
+
if (!oldSchema && newSchema) {
|
|
446
|
+
this.remove(`${id}`, { historyDescription, historySource: 'rollback' });
|
|
447
|
+
return historyService.getStepList('dataSource', id).slice(-1)[0]?.step ?? null;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// 原本是删除 → revert 即重新加回
|
|
451
|
+
if (oldSchema && !newSchema) {
|
|
452
|
+
this.add(cloneDeep(oldSchema), { historyDescription, historySource: 'rollback' });
|
|
453
|
+
return historyService.getStepList('dataSource', id).slice(-1)[0]?.step ?? null;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
if (!oldSchema || !newSchema) return null;
|
|
457
|
+
|
|
458
|
+
// 原本是更新 → 把 oldSchema 写回;优先按 changeRecords 局部 patch
|
|
459
|
+
if (changeRecords?.length) {
|
|
460
|
+
const current = this.getDataSourceById(`${id}`);
|
|
461
|
+
if (!current) return null;
|
|
462
|
+
const patched = cloneDeep(current) as DataSourceSchema;
|
|
463
|
+
let fallbackToFullReplace = false;
|
|
464
|
+
for (const record of changeRecords) {
|
|
465
|
+
if (!record.propPath) {
|
|
466
|
+
fallbackToFullReplace = true;
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
const value = cloneDeep(getValueByKeyPath(record.propPath, oldSchema));
|
|
470
|
+
setValueByKeyPath(record.propPath, value, patched);
|
|
471
|
+
}
|
|
472
|
+
this.update(fallbackToFullReplace ? cloneDeep(oldSchema) : patched, {
|
|
473
|
+
changeRecords,
|
|
474
|
+
historyDescription,
|
|
475
|
+
historySource: 'rollback',
|
|
476
|
+
});
|
|
477
|
+
return historyService.getStepList('dataSource', id).slice(-1)[0]?.step ?? null;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
this.update(cloneDeep(oldSchema), { historyDescription, historySource: 'rollback' });
|
|
481
|
+
return historyService.getStepList('dataSource', id).slice(-1)[0]?.step ?? null;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* 把一条历史 step 应用到当前数据源服务上。
|
|
486
|
+
*
|
|
487
|
+
* 复用现有的 add / update / remove,目的是借助它们发出的事件触发 initService 中
|
|
488
|
+
* 的依赖收集逻辑(DATA_SOURCE / DATA_SOURCE_COND / DATA_SOURCE_METHOD)。
|
|
489
|
+
* 所有写回都带 `doNotPushHistory: true`,确保不会在历史栈里产生新的记录。
|
|
490
|
+
*
|
|
491
|
+
* - oldSchema=null, newSchema≠null:原始为新增 → undo 删除;redo 再次 add
|
|
492
|
+
* - oldSchema≠null, newSchema=null:原始为删除 → undo 还原 add;redo 再次删除
|
|
493
|
+
* - 两侧都有:原始为更新 → 按 changeRecords 局部 patch;缺省退化为整 schema 替换
|
|
494
|
+
*
|
|
495
|
+
* @param step 历史 step
|
|
496
|
+
* @param reverse true=撤销,false=重做
|
|
497
|
+
*/
|
|
498
|
+
private applyHistoryStep(step: DataSourceStepValue, reverse: boolean): void {
|
|
499
|
+
const { id } = step.data;
|
|
500
|
+
const { oldSchema, newSchema, changeRecords } = step.diff?.[0] ?? {};
|
|
501
|
+
|
|
502
|
+
// 新增 / 删除:直接 add 或 remove,不走 patch 逻辑
|
|
503
|
+
if (!oldSchema && newSchema) {
|
|
504
|
+
if (reverse) {
|
|
505
|
+
this.remove(`${id}`, { doNotPushHistory: true });
|
|
506
|
+
} else {
|
|
507
|
+
this.add(cloneDeep(newSchema), { doNotPushHistory: true });
|
|
508
|
+
}
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if (oldSchema && !newSchema) {
|
|
513
|
+
if (reverse) {
|
|
514
|
+
this.add(cloneDeep(oldSchema), { doNotPushHistory: true });
|
|
515
|
+
} else {
|
|
516
|
+
this.remove(`${id}`, { doNotPushHistory: true });
|
|
517
|
+
}
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
if (!oldSchema || !newSchema) return;
|
|
522
|
+
|
|
523
|
+
// 更新场景:优先按 changeRecords 局部 patch;缺省退化为整 schema 替换
|
|
524
|
+
const sourceForValues = reverse ? oldSchema : newSchema;
|
|
525
|
+
|
|
526
|
+
if (changeRecords?.length) {
|
|
527
|
+
const current = this.getDataSourceById(`${id}`);
|
|
528
|
+
if (!current) return;
|
|
529
|
+
const patched = cloneDeep(current) as DataSourceSchema;
|
|
530
|
+
let fallbackToFullReplace = false;
|
|
531
|
+
for (const record of changeRecords) {
|
|
532
|
+
if (!record.propPath) {
|
|
533
|
+
fallbackToFullReplace = true;
|
|
534
|
+
break;
|
|
535
|
+
}
|
|
536
|
+
const value = cloneDeep(getValueByKeyPath(record.propPath, sourceForValues));
|
|
537
|
+
setValueByKeyPath(record.propPath, value, patched);
|
|
538
|
+
}
|
|
539
|
+
this.update(fallbackToFullReplace ? cloneDeep(sourceForValues) : patched, {
|
|
540
|
+
changeRecords,
|
|
541
|
+
doNotPushHistory: true,
|
|
542
|
+
});
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
this.update(cloneDeep(sourceForValues), { doNotPushHistory: true });
|
|
547
|
+
}
|
|
218
548
|
}
|
|
219
549
|
|
|
220
550
|
export type DataSourceService = DataSource;
|
package/src/services/dep.ts
CHANGED
|
@@ -109,9 +109,23 @@ class Dep extends BaseService {
|
|
|
109
109
|
|
|
110
110
|
public collect(nodes: MNode[], depExtendedData: DepExtendedData = {}, deep = false, type?: DepTargetType) {
|
|
111
111
|
this.set('collecting', true);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
|
|
113
|
+
const targets = this.watcher.getCollectableTargets(type);
|
|
114
|
+
|
|
115
|
+
if (targets.length) {
|
|
116
|
+
for (const node of nodes) {
|
|
117
|
+
// 先删除原有依赖,再批量收集
|
|
118
|
+
if (isPage(node)) {
|
|
119
|
+
for (const target of targets) {
|
|
120
|
+
this.removePageDep(target, depExtendedData);
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
this.watcher.removeTargetsDep(targets, node);
|
|
124
|
+
}
|
|
125
|
+
this.watcher.collectItems(node, targets, depExtendedData, deep);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
115
129
|
this.set('collecting', false);
|
|
116
130
|
|
|
117
131
|
this.emit('collected', nodes, deep);
|
|
@@ -176,7 +190,7 @@ class Dep extends BaseService {
|
|
|
176
190
|
dsl.dataSourceDeps[target.id] = target.deps;
|
|
177
191
|
} else if (target.type === DepTargetType.DATA_SOURCE_COND && dsl.dataSourceCondDeps) {
|
|
178
192
|
dsl.dataSourceCondDeps[target.id] = target.deps;
|
|
179
|
-
} else if (target.type === DepTargetType.DATA_SOURCE_METHOD) {
|
|
193
|
+
} else if (target.type === DepTargetType.DATA_SOURCE_METHOD && dsl.dataSourceMethodDeps) {
|
|
180
194
|
dsl.dataSourceMethodDeps[target.id] = target.deps;
|
|
181
195
|
}
|
|
182
196
|
}
|
|
@@ -194,11 +208,7 @@ class Dep extends BaseService {
|
|
|
194
208
|
public collectNode(node: MNode, target: Target, depExtendedData: DepExtendedData = {}, deep = false) {
|
|
195
209
|
// 先删除原有依赖,重新收集
|
|
196
210
|
if (isPage(node)) {
|
|
197
|
-
|
|
198
|
-
if (dep.data?.pageId && dep.data.pageId === depExtendedData.pageId) {
|
|
199
|
-
delete target.deps[depKey];
|
|
200
|
-
}
|
|
201
|
-
}
|
|
211
|
+
this.removePageDep(target, depExtendedData);
|
|
202
212
|
} else {
|
|
203
213
|
this.watcher.removeTargetDep(target, node);
|
|
204
214
|
}
|
|
@@ -263,6 +273,19 @@ class Dep extends BaseService {
|
|
|
263
273
|
return super.emit(eventName, ...args);
|
|
264
274
|
}
|
|
265
275
|
|
|
276
|
+
/**
|
|
277
|
+
* 删除指定 page 在该 target 下的旧依赖:
|
|
278
|
+
* 按 pageId 匹配,可清掉页面内已被删除节点的残留依赖
|
|
279
|
+
*/
|
|
280
|
+
private removePageDep(target: Target, depExtendedData: DepExtendedData = {}) {
|
|
281
|
+
for (const depKey of Object.keys(target.deps)) {
|
|
282
|
+
const dep = target.deps[depKey];
|
|
283
|
+
if (dep.data?.pageId && dep.data.pageId === depExtendedData.pageId) {
|
|
284
|
+
delete target.deps[depKey];
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
266
289
|
private enqueueTask(node: MNode, target: Target, depExtendedData: DepExtendedData, deep: boolean) {
|
|
267
290
|
this.idleTask.enqueueTask(
|
|
268
291
|
({ node, deep, target }) => {
|