@flowgram-vue/free-history-plugin 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/LICENSE +22 -0
  2. package/dist/index.cjs +681 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +194 -0
  5. package/dist/index.js +672 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +64 -0
  8. package/src/changes/add-line-change.ts +36 -0
  9. package/src/changes/add-node-change.ts +35 -0
  10. package/src/changes/change-line-data.ts +33 -0
  11. package/src/changes/delete-line-change.ts +36 -0
  12. package/src/changes/delete-node-change.ts +33 -0
  13. package/src/changes/index.ts +12 -0
  14. package/src/composables/index.ts +6 -0
  15. package/src/composables/use-undo-redo.ts +38 -0
  16. package/src/create-free-history-plugin.ts +38 -0
  17. package/src/env.d.ts +10 -0
  18. package/src/free-history-config.ts +73 -0
  19. package/src/free-history-manager.ts +127 -0
  20. package/src/free-history-registers.ts +18 -0
  21. package/src/handlers/change-content-handler.ts +48 -0
  22. package/src/handlers/drag-nodes-handler.ts +44 -0
  23. package/src/history-entity-manager.ts +44 -0
  24. package/src/hooks/index.ts +6 -0
  25. package/src/index.ts +11 -0
  26. package/src/operation-metas/add-line.ts +44 -0
  27. package/src/operation-metas/add-node.ts +46 -0
  28. package/src/operation-metas/base.ts +23 -0
  29. package/src/operation-metas/change-line-data.ts +58 -0
  30. package/src/operation-metas/delete-line.ts +41 -0
  31. package/src/operation-metas/delete-node.ts +44 -0
  32. package/src/operation-metas/drag-nodes.ts +43 -0
  33. package/src/operation-metas/index.ts +24 -0
  34. package/src/operation-metas/move-child-nodes.ts +42 -0
  35. package/src/operation-metas/reset-layout.ts +33 -0
  36. package/src/types.ts +173 -0
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { type PluginContext } from '@flowgram-vue/core';
7
+ import { WorkflowResetLayoutService } from '@flowgram-vue/free-layout-core';
8
+ import { type OperationMeta } from '@flowgram-vue/history';
9
+
10
+ import { FreeOperationType, type ResetLayoutOperationValue } from '../types';
11
+ import { baseOperationMeta } from './base';
12
+
13
+ export const resetLayoutOperationMeta: OperationMeta<
14
+ ResetLayoutOperationValue,
15
+ PluginContext,
16
+ void
17
+ > = {
18
+ ...baseOperationMeta,
19
+ type: FreeOperationType.resetLayout,
20
+ inverse: op => ({
21
+ ...op,
22
+ value: {
23
+ ...op.value,
24
+ value: op.value.oldValue,
25
+ oldValue: op.value.value,
26
+ },
27
+ }),
28
+ apply: async (operation, ctx: PluginContext) => {
29
+ const reset = ctx.get<WorkflowResetLayoutService>(WorkflowResetLayoutService);
30
+ await reset.layoutToPositions(operation.value.ids, operation.value.value);
31
+ },
32
+ shouldMerge: () => false,
33
+ };
package/src/types.ts ADDED
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /* eslint-disable @typescript-eslint/naming-convention */
7
+ import { type IPoint } from '@flowgram-vue/utils';
8
+ import { type Operation, type OperationMeta } from '@flowgram-vue/history';
9
+ import {
10
+ type WorkflowContentChangeType,
11
+ type WorkflowContentChangeEvent,
12
+ type WorkflowLineEntity,
13
+ type WorkflowLinePortInfo,
14
+ type WorkflowNodeJSON,
15
+ type PositionMap,
16
+ } from '@flowgram-vue/free-layout-core';
17
+ import { type FlowNodeEntity, type FlowNodeJSON } from '@flowgram-vue/document';
18
+ import { type EntityData, type PluginContext } from '@flowgram-vue/core';
19
+
20
+ export enum FreeOperationType {
21
+ addLine = 'addLine',
22
+ deleteLine = 'deleteLine',
23
+ changeLineData = 'changeLineData',
24
+ moveNode = 'moveNode',
25
+ addNode = 'addNode',
26
+ deleteNode = 'deleteNode',
27
+ changeNodeData = 'changeNodeData',
28
+ resetLayout = 'resetLayout',
29
+ dragNodes = 'dragNodes',
30
+ moveChildNodes = 'moveChildNodes',
31
+ }
32
+
33
+ export interface AddOrDeleteLineOperationValue extends WorkflowLinePortInfo {
34
+ id: string;
35
+ }
36
+
37
+ export interface ChangeLineDataValue {
38
+ id: string;
39
+ oldValue: unknown;
40
+ newValue: unknown;
41
+ }
42
+ export interface AddOrDeleteWorkflowNodeOperationValue {
43
+ node: WorkflowNodeJSON;
44
+ parentID?: string;
45
+ }
46
+
47
+ export interface AddLineOperation extends Operation {
48
+ type: FreeOperationType.addLine;
49
+ value: AddOrDeleteLineOperationValue;
50
+ }
51
+
52
+ export interface ChangeLineDataOperation extends Operation {
53
+ type: FreeOperationType.changeLineData;
54
+ value: ChangeLineDataValue;
55
+ }
56
+
57
+ export interface DeleteLineOperation extends Operation {
58
+ type: FreeOperationType.deleteLine;
59
+ value: AddOrDeleteLineOperationValue;
60
+ }
61
+
62
+ export interface MoveNodeOperation extends Operation {
63
+ type: FreeOperationType.moveNode;
64
+ value: MoveNodeOperationValue;
65
+ }
66
+
67
+ export interface AddWorkflowNodeOperation extends Operation {
68
+ type: FreeOperationType.addNode;
69
+ value: AddOrDeleteWorkflowNodeOperationValue;
70
+ }
71
+
72
+ export interface DeleteWorkflowNodeOperation extends Operation {
73
+ type: FreeOperationType.deleteNode;
74
+ value: AddOrDeleteWorkflowNodeOperationValue;
75
+ }
76
+
77
+ export interface MoveNodeOperationValue {
78
+ id: string;
79
+ value: {
80
+ x: number;
81
+ y: number;
82
+ };
83
+ oldValue: {
84
+ x: number;
85
+ y: number;
86
+ };
87
+ }
88
+
89
+ export interface DragNodeOperationValue {
90
+ ids: string[];
91
+ value: IPoint[];
92
+ oldValue: IPoint[];
93
+ }
94
+
95
+ export interface ResetLayoutOperationValue {
96
+ ids: string[];
97
+ value: PositionMap;
98
+ oldValue: PositionMap;
99
+ }
100
+
101
+ export interface ContentChangeTypeToOperation<T extends Operation> {
102
+ type: WorkflowContentChangeType;
103
+ toOperation: (event: WorkflowContentChangeEvent, ctx: PluginContext) => T | undefined;
104
+ }
105
+
106
+ export interface EntityDataType {
107
+ type: FreeOperationType;
108
+ toEntityData: (node: FlowNodeEntity, ctx: PluginContext) => EntityData;
109
+ }
110
+
111
+ export interface ChangeNodeDataValue {
112
+ id: string;
113
+ value: unknown;
114
+ oldValue: unknown;
115
+ path: string;
116
+ }
117
+
118
+ export interface ChangeLineDataValue {
119
+ id: string;
120
+ newValue: unknown;
121
+ oldValue: unknown;
122
+ }
123
+
124
+ /**
125
+ * 将node转成json
126
+ */
127
+ export type NodeToJson = (node: FlowNodeEntity) => FlowNodeJSON;
128
+ /**
129
+ * 将line转成json
130
+ */
131
+ export type LineToJson = (node: WorkflowLineEntity) => FlowNodeJSON;
132
+ /**
133
+ * 根据节点id获取label
134
+ */
135
+ export type GetNodeLabelById = (id: string) => string;
136
+ /**
137
+ * 根据节点获取label
138
+ */
139
+ export type GetNodeLabel = (node: FlowNodeJSON) => string;
140
+ /**
141
+ * 根据分支获取label
142
+ */
143
+ export type GetBlockLabel = (node: FlowNodeJSON) => string;
144
+ /**
145
+ * 根据节点获取URI
146
+ */
147
+ export type GetNodeURI = (id: string) => string | any;
148
+ /**
149
+ * 根据连线获取URI
150
+ */
151
+ export type GetLineURI = (id: string) => string | any;
152
+
153
+ /**
154
+ * 插件配置
155
+ */
156
+ export interface FreeHistoryPluginOptions<CTX extends PluginContext = PluginContext> {
157
+ enable?: boolean;
158
+ limit?: number;
159
+ nodeToJSON?: (ctx: CTX) => NodeToJson;
160
+ getNodeLabelById?: (ctx: CTX) => GetNodeLabelById;
161
+ getNodeLabel?: (ctx: CTX) => GetNodeLabel;
162
+ getBlockLabel?: (ctx: CTX) => GetBlockLabel;
163
+ getNodeURI?: (ctx: CTX) => GetNodeURI;
164
+ getLineURI?: (ctx: CTX) => GetLineURI;
165
+ operationMetas?: OperationMeta[];
166
+ enableChangeNode?: boolean; // default true
167
+ enableChangeLineData?: boolean; // default true
168
+ uri?: string | any;
169
+ }
170
+
171
+ export interface IHandler<E> {
172
+ handle: (event: E, ctx: PluginContext) => void | Promise<void>;
173
+ }