@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
package/dist/es/utils/compose.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
//#region packages/editor/src/utils/compose.ts
|
|
2
|
-
/**
|
|
3
|
-
* @param {Array} middleware
|
|
4
|
-
* @return {Function}
|
|
5
|
-
*/
|
|
6
|
-
var compose = (middleware, isAsync) => {
|
|
7
|
-
if (!Array.isArray(middleware)) throw new TypeError("Middleware 必须是一个数组!");
|
|
8
|
-
for (const fn of middleware) if (typeof fn !== "function") throw new TypeError("Middleware 必须由函数组成!");
|
|
9
|
-
/**
|
|
10
|
-
* @param {Object} args
|
|
11
|
-
* @return {Promise}
|
|
12
|
-
* @api public
|
|
13
|
-
*/
|
|
14
|
-
return (args, next) => {
|
|
15
|
-
let index = -1;
|
|
16
|
-
return dispatch(0);
|
|
17
|
-
function dispatch(i) {
|
|
18
|
-
if (i <= index) {
|
|
19
|
-
const error = /* @__PURE__ */ new Error("next() 被多次调用");
|
|
20
|
-
if (isAsync) return Promise.reject(error);
|
|
21
|
-
throw error;
|
|
22
|
-
}
|
|
23
|
-
index = i;
|
|
24
|
-
let fn = middleware[i];
|
|
25
|
-
if (i === middleware.length && next) fn = next;
|
|
26
|
-
if (!fn) {
|
|
27
|
-
if (isAsync) return Promise.resolve();
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (isAsync) try {
|
|
31
|
-
return Promise.resolve(fn(...args, dispatch.bind(null, i + 1)));
|
|
32
|
-
} catch (err) {
|
|
33
|
-
return Promise.reject(err);
|
|
34
|
-
}
|
|
35
|
-
try {
|
|
36
|
-
return fn(...args, dispatch.bind(null, i + 1));
|
|
37
|
-
} catch (err) {
|
|
38
|
-
throw err;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
//#endregion
|
|
44
|
-
export { compose };
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { getNodeIndex } from "./editor.js";
|
|
2
|
-
import { isPage, isPageFragment } from "@tmagic/utils";
|
|
3
|
-
import { NodeType } from "@tmagic/core";
|
|
4
|
-
import { toRaw } from "vue";
|
|
5
|
-
import { cloneDeep } from "lodash-es";
|
|
6
|
-
//#region packages/editor/src/utils/editor-history.ts
|
|
7
|
-
/**
|
|
8
|
-
* 应用 add 类型的历史操作
|
|
9
|
-
* reverse=true(撤销):从父节点中移除已添加的节点
|
|
10
|
-
* reverse=false(重做):重新添加节点到父节点中
|
|
11
|
-
*/
|
|
12
|
-
async function applyHistoryAddOp(step, reverse, ctx) {
|
|
13
|
-
const { root, stage } = ctx;
|
|
14
|
-
if (reverse) for (const node of step.nodes ?? []) {
|
|
15
|
-
const parent = ctx.getNodeById(step.parentId, false);
|
|
16
|
-
if (!parent?.items) continue;
|
|
17
|
-
const idx = getNodeIndex(node.id, parent);
|
|
18
|
-
if (typeof idx === "number" && idx !== -1) parent.items.splice(idx, 1);
|
|
19
|
-
await stage?.remove({
|
|
20
|
-
id: node.id,
|
|
21
|
-
parentId: parent.id,
|
|
22
|
-
root: cloneDeep(root)
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
const parent = ctx.getNodeById(step.parentId, false);
|
|
27
|
-
if (parent?.items) for (const node of step.nodes ?? []) {
|
|
28
|
-
const idx = step.indexMap?.[node.id] ?? parent.items.length;
|
|
29
|
-
parent.items.splice(idx, 0, cloneDeep(node));
|
|
30
|
-
await stage?.add({
|
|
31
|
-
config: cloneDeep(node),
|
|
32
|
-
parent: cloneDeep(parent),
|
|
33
|
-
parentId: parent.id,
|
|
34
|
-
root: cloneDeep(root)
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 应用 remove 类型的历史操作
|
|
41
|
-
* reverse=true(撤销):将已删除的节点按原位置重新插入
|
|
42
|
-
* reverse=false(重做):再次删除节点
|
|
43
|
-
*/
|
|
44
|
-
async function applyHistoryRemoveOp(step, reverse, ctx) {
|
|
45
|
-
const { root, stage } = ctx;
|
|
46
|
-
if (reverse) {
|
|
47
|
-
const sorted = [...step.removedItems ?? []].sort((a, b) => a.index - b.index);
|
|
48
|
-
for (const { node, parentId, index } of sorted) {
|
|
49
|
-
const parent = ctx.getNodeById(parentId, false);
|
|
50
|
-
if (!parent?.items) continue;
|
|
51
|
-
parent.items.splice(index, 0, cloneDeep(node));
|
|
52
|
-
await stage?.add({
|
|
53
|
-
config: cloneDeep(node),
|
|
54
|
-
parent: cloneDeep(parent),
|
|
55
|
-
parentId,
|
|
56
|
-
root: cloneDeep(root)
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
} else for (const { node, parentId } of step.removedItems ?? []) {
|
|
60
|
-
const parent = ctx.getNodeById(parentId, false);
|
|
61
|
-
if (!parent?.items) continue;
|
|
62
|
-
const idx = getNodeIndex(node.id, parent);
|
|
63
|
-
if (typeof idx === "number" && idx !== -1) parent.items.splice(idx, 1);
|
|
64
|
-
await stage?.remove({
|
|
65
|
-
id: node.id,
|
|
66
|
-
parentId,
|
|
67
|
-
root: cloneDeep(root)
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* 应用 update 类型的历史操作
|
|
73
|
-
* reverse=true(撤销):将节点恢复为 oldNode
|
|
74
|
-
* reverse=false(重做):将节点更新为 newNode
|
|
75
|
-
*/
|
|
76
|
-
async function applyHistoryUpdateOp(step, reverse, ctx) {
|
|
77
|
-
const { root, stage } = ctx;
|
|
78
|
-
const items = step.updatedItems ?? [];
|
|
79
|
-
for (const { oldNode, newNode } of items) {
|
|
80
|
-
const config = reverse ? oldNode : newNode;
|
|
81
|
-
if (config.type === NodeType.ROOT) {
|
|
82
|
-
ctx.setRoot(cloneDeep(config));
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
const info = ctx.getNodeInfo(config.id, false);
|
|
86
|
-
if (!info.parent) continue;
|
|
87
|
-
const idx = getNodeIndex(config.id, info.parent);
|
|
88
|
-
if (typeof idx !== "number" || idx === -1) continue;
|
|
89
|
-
info.parent.items[idx] = cloneDeep(config);
|
|
90
|
-
if (isPage(config) || isPageFragment(config)) ctx.setPage(config);
|
|
91
|
-
}
|
|
92
|
-
const curPage = ctx.getPage();
|
|
93
|
-
if (stage && curPage) await stage.update({
|
|
94
|
-
config: cloneDeep(toRaw(curPage)),
|
|
95
|
-
parentId: root.id,
|
|
96
|
-
root: cloneDeep(toRaw(root))
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
//#endregion
|
|
100
|
-
export { applyHistoryAddOp, applyHistoryRemoveOp, applyHistoryUpdateOp };
|
package/src/utils/compose.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {Array} middleware
|
|
3
|
-
* @return {Function}
|
|
4
|
-
*/
|
|
5
|
-
export const compose = (middleware: Function[], isAsync: boolean) => {
|
|
6
|
-
if (!Array.isArray(middleware)) throw new TypeError('Middleware 必须是一个数组!');
|
|
7
|
-
for (const fn of middleware) {
|
|
8
|
-
if (typeof fn !== 'function') throw new TypeError('Middleware 必须由函数组成!');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param {Object} args
|
|
13
|
-
* @return {Promise}
|
|
14
|
-
* @api public
|
|
15
|
-
*/
|
|
16
|
-
return (args: any[], next?: Function) => {
|
|
17
|
-
// last called middleware #
|
|
18
|
-
let index = -1;
|
|
19
|
-
return dispatch(0);
|
|
20
|
-
function dispatch(i: number): Promise<void> | void {
|
|
21
|
-
if (i <= index) {
|
|
22
|
-
const error = new Error('next() 被多次调用');
|
|
23
|
-
if (isAsync) {
|
|
24
|
-
return Promise.reject(error);
|
|
25
|
-
}
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
index = i;
|
|
29
|
-
let fn = middleware[i];
|
|
30
|
-
if (i === middleware.length && next) fn = next;
|
|
31
|
-
if (!fn) {
|
|
32
|
-
if (isAsync) {
|
|
33
|
-
return Promise.resolve();
|
|
34
|
-
}
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (isAsync) {
|
|
39
|
-
try {
|
|
40
|
-
return Promise.resolve(fn(...args, dispatch.bind(null, i + 1)));
|
|
41
|
-
} catch (err) {
|
|
42
|
-
return Promise.reject(err);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
return fn(...args, dispatch.bind(null, i + 1));
|
|
47
|
-
} catch (err) {
|
|
48
|
-
throw err;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
};
|
|
@@ -1,138 +0,0 @@
|
|
|
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 { toRaw } from 'vue';
|
|
20
|
-
import { cloneDeep } from 'lodash-es';
|
|
21
|
-
|
|
22
|
-
import type { Id, MApp, MContainer, MNode, MPage, MPageFragment } from '@tmagic/core';
|
|
23
|
-
import { NodeType } from '@tmagic/core';
|
|
24
|
-
import type StageCore from '@tmagic/stage';
|
|
25
|
-
import { isPage, isPageFragment } from '@tmagic/utils';
|
|
26
|
-
|
|
27
|
-
import type { EditorNodeInfo, StepValue } from '@editor/type';
|
|
28
|
-
import { getNodeIndex } from '@editor/utils/editor';
|
|
29
|
-
|
|
30
|
-
export interface HistoryOpContext {
|
|
31
|
-
root: MApp;
|
|
32
|
-
stage: StageCore | null;
|
|
33
|
-
getNodeById(id: Id, raw?: boolean): MNode | null;
|
|
34
|
-
getNodeInfo(id: Id, raw?: boolean): EditorNodeInfo;
|
|
35
|
-
setRoot(root: MApp): void;
|
|
36
|
-
setPage(page: MPage | MPageFragment): void;
|
|
37
|
-
getPage(): MPage | MPageFragment | null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 应用 add 类型的历史操作
|
|
42
|
-
* reverse=true(撤销):从父节点中移除已添加的节点
|
|
43
|
-
* reverse=false(重做):重新添加节点到父节点中
|
|
44
|
-
*/
|
|
45
|
-
export async function applyHistoryAddOp(step: StepValue, reverse: boolean, ctx: HistoryOpContext): Promise<void> {
|
|
46
|
-
const { root, stage } = ctx;
|
|
47
|
-
|
|
48
|
-
if (reverse) {
|
|
49
|
-
for (const node of step.nodes ?? []) {
|
|
50
|
-
const parent = ctx.getNodeById(step.parentId!, false) as MContainer;
|
|
51
|
-
if (!parent?.items) continue;
|
|
52
|
-
const idx = getNodeIndex(node.id, parent);
|
|
53
|
-
if (typeof idx === 'number' && idx !== -1) {
|
|
54
|
-
parent.items.splice(idx, 1);
|
|
55
|
-
}
|
|
56
|
-
await stage?.remove({ id: node.id, parentId: parent.id, root: cloneDeep(root) });
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
const parent = ctx.getNodeById(step.parentId!, false) as MContainer;
|
|
60
|
-
if (parent?.items) {
|
|
61
|
-
for (const node of step.nodes ?? []) {
|
|
62
|
-
const idx = step.indexMap?.[node.id] ?? parent.items.length;
|
|
63
|
-
parent.items.splice(idx, 0, cloneDeep(node));
|
|
64
|
-
await stage?.add({
|
|
65
|
-
config: cloneDeep(node),
|
|
66
|
-
parent: cloneDeep(parent),
|
|
67
|
-
parentId: parent.id,
|
|
68
|
-
root: cloneDeep(root),
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* 应用 remove 类型的历史操作
|
|
77
|
-
* reverse=true(撤销):将已删除的节点按原位置重新插入
|
|
78
|
-
* reverse=false(重做):再次删除节点
|
|
79
|
-
*/
|
|
80
|
-
export async function applyHistoryRemoveOp(step: StepValue, reverse: boolean, ctx: HistoryOpContext): Promise<void> {
|
|
81
|
-
const { root, stage } = ctx;
|
|
82
|
-
|
|
83
|
-
if (reverse) {
|
|
84
|
-
const sorted = [...(step.removedItems ?? [])].sort((a, b) => a.index - b.index);
|
|
85
|
-
for (const { node, parentId, index } of sorted) {
|
|
86
|
-
const parent = ctx.getNodeById(parentId, false) as MContainer;
|
|
87
|
-
if (!parent?.items) continue;
|
|
88
|
-
parent.items.splice(index, 0, cloneDeep(node));
|
|
89
|
-
await stage?.add({ config: cloneDeep(node), parent: cloneDeep(parent), parentId, root: cloneDeep(root) });
|
|
90
|
-
}
|
|
91
|
-
} else {
|
|
92
|
-
for (const { node, parentId } of step.removedItems ?? []) {
|
|
93
|
-
const parent = ctx.getNodeById(parentId, false) as MContainer;
|
|
94
|
-
if (!parent?.items) continue;
|
|
95
|
-
const idx = getNodeIndex(node.id, parent);
|
|
96
|
-
if (typeof idx === 'number' && idx !== -1) {
|
|
97
|
-
parent.items.splice(idx, 1);
|
|
98
|
-
}
|
|
99
|
-
await stage?.remove({ id: node.id, parentId, root: cloneDeep(root) });
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* 应用 update 类型的历史操作
|
|
106
|
-
* reverse=true(撤销):将节点恢复为 oldNode
|
|
107
|
-
* reverse=false(重做):将节点更新为 newNode
|
|
108
|
-
*/
|
|
109
|
-
export async function applyHistoryUpdateOp(step: StepValue, reverse: boolean, ctx: HistoryOpContext): Promise<void> {
|
|
110
|
-
const { root, stage } = ctx;
|
|
111
|
-
const items = step.updatedItems ?? [];
|
|
112
|
-
|
|
113
|
-
for (const { oldNode, newNode } of items) {
|
|
114
|
-
const config = reverse ? oldNode : newNode;
|
|
115
|
-
if (config.type === NodeType.ROOT) {
|
|
116
|
-
ctx.setRoot(cloneDeep(config) as MApp);
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
const info = ctx.getNodeInfo(config.id, false);
|
|
120
|
-
if (!info.parent) continue;
|
|
121
|
-
const idx = getNodeIndex(config.id, info.parent);
|
|
122
|
-
if (typeof idx !== 'number' || idx === -1) continue;
|
|
123
|
-
info.parent.items![idx] = cloneDeep(config);
|
|
124
|
-
|
|
125
|
-
if (isPage(config) || isPageFragment(config)) {
|
|
126
|
-
ctx.setPage(config as MPage | MPageFragment);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const curPage = ctx.getPage();
|
|
131
|
-
if (stage && curPage) {
|
|
132
|
-
await stage.update({
|
|
133
|
-
config: cloneDeep(toRaw(curPage)),
|
|
134
|
-
parentId: root.id,
|
|
135
|
-
root: cloneDeep(toRaw(root)),
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|