@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.
- package/LICENSE +22 -0
- package/dist/index.cjs +681 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +194 -0
- package/dist/index.js +672 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
- package/src/changes/add-line-change.ts +36 -0
- package/src/changes/add-node-change.ts +35 -0
- package/src/changes/change-line-data.ts +33 -0
- package/src/changes/delete-line-change.ts +36 -0
- package/src/changes/delete-node-change.ts +33 -0
- package/src/changes/index.ts +12 -0
- package/src/composables/index.ts +6 -0
- package/src/composables/use-undo-redo.ts +38 -0
- package/src/create-free-history-plugin.ts +38 -0
- package/src/env.d.ts +10 -0
- package/src/free-history-config.ts +73 -0
- package/src/free-history-manager.ts +127 -0
- package/src/free-history-registers.ts +18 -0
- package/src/handlers/change-content-handler.ts +48 -0
- package/src/handlers/drag-nodes-handler.ts +44 -0
- package/src/history-entity-manager.ts +44 -0
- package/src/hooks/index.ts +6 -0
- package/src/index.ts +11 -0
- package/src/operation-metas/add-line.ts +44 -0
- package/src/operation-metas/add-node.ts +46 -0
- package/src/operation-metas/base.ts +23 -0
- package/src/operation-metas/change-line-data.ts +58 -0
- package/src/operation-metas/delete-line.ts +41 -0
- package/src/operation-metas/delete-node.ts +44 -0
- package/src/operation-metas/drag-nodes.ts +43 -0
- package/src/operation-metas/index.ts +24 -0
- package/src/operation-metas/move-child-nodes.ts +42 -0
- package/src/operation-metas/reset-layout.ts +33 -0
- package/src/types.ts +173 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
4
|
+
Copyright (c) 2026 Crayon
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,681 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var history = require('@flowgram-vue/history');
|
|
4
|
+
var core = require('@flowgram-vue/core');
|
|
5
|
+
var lodashEs = require('lodash-es');
|
|
6
|
+
var inversify = require('inversify');
|
|
7
|
+
var utils = require('@flowgram-vue/utils');
|
|
8
|
+
var freeLayoutCore = require('@flowgram-vue/free-layout-core');
|
|
9
|
+
var document = require('@flowgram-vue/document');
|
|
10
|
+
var vue = require('vue');
|
|
11
|
+
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
15
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
16
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
17
|
+
if (decorator = decorators[i])
|
|
18
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
19
|
+
if (kind && result) __defProp(target, key, result);
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
var HistoryEntityManager = class {
|
|
23
|
+
constructor() {
|
|
24
|
+
this._entityDataValues = /* @__PURE__ */ new Map();
|
|
25
|
+
this._toDispose = new utils.DisposableCollection();
|
|
26
|
+
}
|
|
27
|
+
addEntityData(entityData) {
|
|
28
|
+
this._entityDataValues.set(entityData, lodashEs.cloneDeep(entityData.toJSON()));
|
|
29
|
+
this._toDispose.push(
|
|
30
|
+
entityData.onWillChange((event) => {
|
|
31
|
+
const value = event.toJSON();
|
|
32
|
+
const oldValue = this._entityDataValues.get(entityData);
|
|
33
|
+
if (lodashEs.isEqual(value, oldValue)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this._entityDataValues.set(entityData, lodashEs.cloneDeep(value));
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
getValue(entityData) {
|
|
41
|
+
return this._entityDataValues.get(entityData);
|
|
42
|
+
}
|
|
43
|
+
setValue(entityData, value) {
|
|
44
|
+
return this._entityDataValues.set(entityData, value);
|
|
45
|
+
}
|
|
46
|
+
dispose() {
|
|
47
|
+
this._entityDataValues.clear();
|
|
48
|
+
this._toDispose.dispose();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
HistoryEntityManager = __decorateClass([
|
|
52
|
+
inversify.injectable()
|
|
53
|
+
], HistoryEntityManager);
|
|
54
|
+
|
|
55
|
+
// src/types.ts
|
|
56
|
+
var FreeOperationType = /* @__PURE__ */ ((FreeOperationType2) => {
|
|
57
|
+
FreeOperationType2["addLine"] = "addLine";
|
|
58
|
+
FreeOperationType2["deleteLine"] = "deleteLine";
|
|
59
|
+
FreeOperationType2["changeLineData"] = "changeLineData";
|
|
60
|
+
FreeOperationType2["moveNode"] = "moveNode";
|
|
61
|
+
FreeOperationType2["addNode"] = "addNode";
|
|
62
|
+
FreeOperationType2["deleteNode"] = "deleteNode";
|
|
63
|
+
FreeOperationType2["changeNodeData"] = "changeNodeData";
|
|
64
|
+
FreeOperationType2["resetLayout"] = "resetLayout";
|
|
65
|
+
FreeOperationType2["dragNodes"] = "dragNodes";
|
|
66
|
+
FreeOperationType2["moveChildNodes"] = "moveChildNodes";
|
|
67
|
+
return FreeOperationType2;
|
|
68
|
+
})(FreeOperationType || {});
|
|
69
|
+
|
|
70
|
+
// src/handlers/drag-nodes-handler.ts
|
|
71
|
+
var DragNodesHandler = class {
|
|
72
|
+
handle(event) {
|
|
73
|
+
if (event.type === "onDragEnd") {
|
|
74
|
+
this._dragNode(event);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
_dragNode(event) {
|
|
78
|
+
this._historyService.pushOperation(
|
|
79
|
+
{
|
|
80
|
+
type: "dragNodes" /* dragNodes */,
|
|
81
|
+
value: {
|
|
82
|
+
ids: event.nodes.map((node) => node.id),
|
|
83
|
+
value: event.nodes.map((node) => {
|
|
84
|
+
const { x, y } = node.getData(core.TransformData).position;
|
|
85
|
+
return {
|
|
86
|
+
x,
|
|
87
|
+
y
|
|
88
|
+
};
|
|
89
|
+
}),
|
|
90
|
+
oldValue: event.startPositions
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{ noApply: true }
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
__decorateClass([
|
|
98
|
+
inversify.inject(history.HistoryService)
|
|
99
|
+
], DragNodesHandler.prototype, "_historyService", 2);
|
|
100
|
+
DragNodesHandler = __decorateClass([
|
|
101
|
+
inversify.injectable()
|
|
102
|
+
], DragNodesHandler);
|
|
103
|
+
exports.FreeHistoryConfig = class FreeHistoryConfig {
|
|
104
|
+
constructor() {
|
|
105
|
+
this.enableChangeNode = true;
|
|
106
|
+
this.enableChangeLineData = true;
|
|
107
|
+
this.enable = false;
|
|
108
|
+
this.nodeToJSON = (node) => node.toJSON();
|
|
109
|
+
this.getNodeLabelById = (id) => id;
|
|
110
|
+
this.getNodeLabel = (node) => node.id;
|
|
111
|
+
this.getBlockLabel = (node) => node.id;
|
|
112
|
+
this.getNodeURI = (id) => `node:${id}`;
|
|
113
|
+
this.getLineURI = (id) => `line:${id}`;
|
|
114
|
+
}
|
|
115
|
+
init(ctx, options) {
|
|
116
|
+
this.enable = !!options?.enable;
|
|
117
|
+
if (options.nodeToJSON) {
|
|
118
|
+
this.nodeToJSON = options.nodeToJSON(ctx);
|
|
119
|
+
}
|
|
120
|
+
if (options.getNodeLabelById) {
|
|
121
|
+
this.getNodeLabelById = options.getNodeLabelById(ctx);
|
|
122
|
+
}
|
|
123
|
+
if (options.getNodeLabel) {
|
|
124
|
+
this.getNodeLabel = options.getNodeLabel(ctx);
|
|
125
|
+
}
|
|
126
|
+
if (options.getBlockLabel) {
|
|
127
|
+
this.getBlockLabel = options.getBlockLabel(ctx);
|
|
128
|
+
}
|
|
129
|
+
if (options.getNodeURI) {
|
|
130
|
+
this.getNodeURI = options.getNodeURI(ctx);
|
|
131
|
+
}
|
|
132
|
+
if (options.getLineURI) {
|
|
133
|
+
this.getLineURI = options.getLineURI(ctx);
|
|
134
|
+
}
|
|
135
|
+
if (options.enableChangeNode !== void 0) {
|
|
136
|
+
this.enableChangeNode = options.enableChangeNode;
|
|
137
|
+
}
|
|
138
|
+
if (options.enableChangeLineData !== void 0) {
|
|
139
|
+
this.enableChangeLineData = options.enableChangeLineData;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
exports.FreeHistoryConfig = __decorateClass([
|
|
144
|
+
inversify.injectable()
|
|
145
|
+
], exports.FreeHistoryConfig);
|
|
146
|
+
var deleteNodeChange = {
|
|
147
|
+
type: freeLayoutCore.WorkflowContentChangeType.DELETE_NODE,
|
|
148
|
+
toOperation: (event, ctx) => {
|
|
149
|
+
const config = ctx.get(exports.FreeHistoryConfig);
|
|
150
|
+
const node = event.entity;
|
|
151
|
+
const json = event.toJSON();
|
|
152
|
+
const parentID = node.parent?.id;
|
|
153
|
+
return {
|
|
154
|
+
type: "deleteNode" /* deleteNode */,
|
|
155
|
+
value: {
|
|
156
|
+
node: json,
|
|
157
|
+
parentID
|
|
158
|
+
},
|
|
159
|
+
uri: config.getNodeURI(node.id)
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
var deleteLineChange = {
|
|
164
|
+
type: freeLayoutCore.WorkflowContentChangeType.DELETE_LINE,
|
|
165
|
+
toOperation: (event, ctx) => {
|
|
166
|
+
const config = ctx.get(exports.FreeHistoryConfig);
|
|
167
|
+
const line = event.entity;
|
|
168
|
+
const value = {
|
|
169
|
+
from: line.info.from,
|
|
170
|
+
to: line.info.to || "",
|
|
171
|
+
fromPort: line.info.fromPort || "",
|
|
172
|
+
toPort: line.info.toPort || "",
|
|
173
|
+
data: line.info.data,
|
|
174
|
+
id: line.id
|
|
175
|
+
};
|
|
176
|
+
return {
|
|
177
|
+
type: "deleteLine" /* deleteLine */,
|
|
178
|
+
value,
|
|
179
|
+
uri: config.getNodeURI(line.id)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
var changeLineData = {
|
|
184
|
+
type: freeLayoutCore.WorkflowContentChangeType.LINE_DATA_CHANGE,
|
|
185
|
+
toOperation: (event, ctx) => {
|
|
186
|
+
const config = ctx.get(exports.FreeHistoryConfig);
|
|
187
|
+
const line = event.entity;
|
|
188
|
+
const value = {
|
|
189
|
+
id: line.id,
|
|
190
|
+
oldValue: event.oldValue,
|
|
191
|
+
newValue: line.lineData
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
type: "changeLineData" /* changeLineData */,
|
|
195
|
+
value,
|
|
196
|
+
uri: config.getLineURI(line.id)
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
var addNodeChange = {
|
|
201
|
+
type: freeLayoutCore.WorkflowContentChangeType.ADD_NODE,
|
|
202
|
+
toOperation: (event, ctx) => {
|
|
203
|
+
const config = ctx.get(exports.FreeHistoryConfig);
|
|
204
|
+
const document = ctx.get(freeLayoutCore.WorkflowDocument);
|
|
205
|
+
const node = event.entity;
|
|
206
|
+
const parentID = node.parent?.id;
|
|
207
|
+
const json = document.toNodeJSON(node);
|
|
208
|
+
return {
|
|
209
|
+
type: "addNode" /* addNode */,
|
|
210
|
+
value: {
|
|
211
|
+
node: json,
|
|
212
|
+
parentID
|
|
213
|
+
},
|
|
214
|
+
uri: config.getNodeURI(node.id)
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
var addLineChange = {
|
|
219
|
+
type: freeLayoutCore.WorkflowContentChangeType.ADD_LINE,
|
|
220
|
+
toOperation: (event, ctx) => {
|
|
221
|
+
const config = ctx.get(exports.FreeHistoryConfig);
|
|
222
|
+
const line = event.entity;
|
|
223
|
+
const value = {
|
|
224
|
+
from: line.info.from,
|
|
225
|
+
to: line.info.to || "",
|
|
226
|
+
fromPort: line.info.fromPort || "",
|
|
227
|
+
toPort: line.info.toPort || "",
|
|
228
|
+
data: line.info.data,
|
|
229
|
+
id: line.id
|
|
230
|
+
};
|
|
231
|
+
return {
|
|
232
|
+
type: "addLine" /* addLine */,
|
|
233
|
+
value,
|
|
234
|
+
uri: config.getLineURI(line.id)
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// src/changes/index.ts
|
|
240
|
+
var changes_default = [addLineChange, deleteLineChange, addNodeChange, deleteNodeChange, changeLineData];
|
|
241
|
+
|
|
242
|
+
// src/handlers/change-content-handler.ts
|
|
243
|
+
var ChangeContentHandler = class {
|
|
244
|
+
handle(event, ctx) {
|
|
245
|
+
if (!this._historyService.undoRedoService.canPush()) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (!this._historyConfig.enableChangeLineData && event.type === freeLayoutCore.WorkflowContentChangeType.LINE_DATA_CHANGE) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const change = changes_default.find((c) => c.type === event.type);
|
|
252
|
+
if (!change) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const operation = change.toOperation(event, ctx);
|
|
256
|
+
if (!operation) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
this._historyService.pushOperation(operation, { noApply: true });
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
__decorateClass([
|
|
263
|
+
inversify.inject(history.HistoryService)
|
|
264
|
+
], ChangeContentHandler.prototype, "_historyService", 2);
|
|
265
|
+
__decorateClass([
|
|
266
|
+
inversify.inject(exports.FreeHistoryConfig)
|
|
267
|
+
], ChangeContentHandler.prototype, "_historyConfig", 2);
|
|
268
|
+
ChangeContentHandler = __decorateClass([
|
|
269
|
+
inversify.injectable()
|
|
270
|
+
], ChangeContentHandler);
|
|
271
|
+
|
|
272
|
+
// src/operation-metas/base.ts
|
|
273
|
+
var baseOperationMeta = {
|
|
274
|
+
shouldMerge: (_op, prev, element) => {
|
|
275
|
+
if (!prev) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
if (
|
|
279
|
+
// 合并500ms内的操作, 如删除节点会联动删除线条
|
|
280
|
+
Date.now() - element.getTimestamp() < 500
|
|
281
|
+
) {
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// src/operation-metas/reset-layout.ts
|
|
289
|
+
var resetLayoutOperationMeta = {
|
|
290
|
+
...baseOperationMeta,
|
|
291
|
+
type: "resetLayout" /* resetLayout */,
|
|
292
|
+
inverse: (op) => ({
|
|
293
|
+
...op,
|
|
294
|
+
value: {
|
|
295
|
+
...op.value,
|
|
296
|
+
value: op.value.oldValue,
|
|
297
|
+
oldValue: op.value.value
|
|
298
|
+
}
|
|
299
|
+
}),
|
|
300
|
+
apply: async (operation, ctx) => {
|
|
301
|
+
const reset = ctx.get(freeLayoutCore.WorkflowResetLayoutService);
|
|
302
|
+
await reset.layoutToPositions(operation.value.ids, operation.value.value);
|
|
303
|
+
},
|
|
304
|
+
shouldMerge: () => false
|
|
305
|
+
};
|
|
306
|
+
var moveChildNodesOperationMeta = {
|
|
307
|
+
...baseOperationMeta,
|
|
308
|
+
type: document.OperationType.moveChildNodes,
|
|
309
|
+
inverse: (op) => ({
|
|
310
|
+
...op,
|
|
311
|
+
value: {
|
|
312
|
+
...op.value,
|
|
313
|
+
fromIndex: op.value.toIndex,
|
|
314
|
+
toIndex: op.value.fromIndex,
|
|
315
|
+
fromParentId: op.value.toParentId,
|
|
316
|
+
toParentId: op.value.fromParentId
|
|
317
|
+
}
|
|
318
|
+
}),
|
|
319
|
+
apply: (operation, ctx) => {
|
|
320
|
+
const document$1 = ctx.get(freeLayoutCore.WorkflowDocument);
|
|
321
|
+
document$1.moveChildNodes(operation.value);
|
|
322
|
+
const fromContainer = document$1.getNode(operation.value.fromParentId);
|
|
323
|
+
requestAnimationFrame(() => {
|
|
324
|
+
if (fromContainer && fromContainer.flowNodeType !== document.FlowNodeBaseType.ROOT) {
|
|
325
|
+
const fromContainerTransformData = fromContainer.getData(core.TransformData);
|
|
326
|
+
fromContainerTransformData.fireChange();
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
var dragNodesOperationMeta = {
|
|
332
|
+
...baseOperationMeta,
|
|
333
|
+
type: "dragNodes" /* dragNodes */,
|
|
334
|
+
inverse: (op) => ({
|
|
335
|
+
...op,
|
|
336
|
+
value: {
|
|
337
|
+
...op.value,
|
|
338
|
+
value: op.value.oldValue,
|
|
339
|
+
oldValue: op.value.value
|
|
340
|
+
}
|
|
341
|
+
}),
|
|
342
|
+
apply: (operation, ctx) => {
|
|
343
|
+
operation.value.ids.forEach((id, index) => {
|
|
344
|
+
const document = ctx.get(freeLayoutCore.WorkflowDocument);
|
|
345
|
+
const node = document.getNode(id);
|
|
346
|
+
if (!node) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const transform = node.getData(core.TransformData);
|
|
350
|
+
const point = operation.value.value[index];
|
|
351
|
+
transform.update({
|
|
352
|
+
position: {
|
|
353
|
+
x: point.x,
|
|
354
|
+
y: point.y
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
document.layout.updateAffectedTransform(node);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
var deleteNodeOperationMeta = {
|
|
362
|
+
...baseOperationMeta,
|
|
363
|
+
type: "deleteNode" /* deleteNode */,
|
|
364
|
+
inverse: (op) => ({
|
|
365
|
+
...op,
|
|
366
|
+
type: "addNode" /* addNode */
|
|
367
|
+
}),
|
|
368
|
+
apply: (operation, ctx) => {
|
|
369
|
+
const document = ctx.get(freeLayoutCore.WorkflowDocument);
|
|
370
|
+
const node = document.getNode(operation.value.node.id);
|
|
371
|
+
if (node) {
|
|
372
|
+
node.dispose();
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
getLabel: (op, ctx) => {
|
|
376
|
+
const config = ctx.get(exports.FreeHistoryConfig);
|
|
377
|
+
return `Delete Node ${config.getNodeLabel(op.value.node)}`;
|
|
378
|
+
},
|
|
379
|
+
getDescription: (op, ctx) => {
|
|
380
|
+
const config = ctx.get(exports.FreeHistoryConfig);
|
|
381
|
+
let desc = `Delete Node ${config.getNodeLabel(op.value.node)}`;
|
|
382
|
+
if (op.value.node.meta?.position) {
|
|
383
|
+
desc += ` at ${op.value.node.meta.position.x},${op.value.node.meta.position.y}`;
|
|
384
|
+
}
|
|
385
|
+
return desc;
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
var deleteLineOperationMeta = {
|
|
389
|
+
...baseOperationMeta,
|
|
390
|
+
type: "deleteLine" /* deleteLine */,
|
|
391
|
+
inverse: (op) => ({
|
|
392
|
+
...op,
|
|
393
|
+
type: "addLine" /* addLine */
|
|
394
|
+
}),
|
|
395
|
+
apply: (operation, ctx) => {
|
|
396
|
+
const document = ctx.get(freeLayoutCore.WorkflowDocument);
|
|
397
|
+
document.removeNode(operation.value.id);
|
|
398
|
+
},
|
|
399
|
+
getLabel: (op, ctx) => "Delete Line",
|
|
400
|
+
getDescription: (op, ctx) => {
|
|
401
|
+
const config = ctx.get(exports.FreeHistoryConfig);
|
|
402
|
+
const { value } = op;
|
|
403
|
+
if (!value.from || !value.to) {
|
|
404
|
+
return "Delete Line";
|
|
405
|
+
}
|
|
406
|
+
const fromName = config.getNodeLabelById(value.from);
|
|
407
|
+
const toName = config.getNodeLabelById(value.to);
|
|
408
|
+
return `Delete Line from ${fromName} to ${toName}`;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
var changeLineDataOperationMeta = {
|
|
412
|
+
...baseOperationMeta,
|
|
413
|
+
type: "changeLineData" /* changeLineData */,
|
|
414
|
+
inverse: (op) => ({
|
|
415
|
+
...op,
|
|
416
|
+
value: {
|
|
417
|
+
...op.value,
|
|
418
|
+
newValue: op.value.oldValue,
|
|
419
|
+
oldValue: op.value.newValue
|
|
420
|
+
}
|
|
421
|
+
}),
|
|
422
|
+
apply: (op, ctx) => {
|
|
423
|
+
const linesManager = ctx.get(freeLayoutCore.WorkflowLinesManager);
|
|
424
|
+
const line = linesManager.getLineById(op.value.id);
|
|
425
|
+
if (!line) {
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
line.lineData = op.value.newValue;
|
|
429
|
+
},
|
|
430
|
+
shouldMerge: (op, prev, element) => {
|
|
431
|
+
if (!prev) {
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
if (Date.now() - element.getTimestamp() < 500) {
|
|
435
|
+
if (op.type === prev.type && // 相同类型
|
|
436
|
+
op.value.id === prev.value.id) {
|
|
437
|
+
return {
|
|
438
|
+
type: op.type,
|
|
439
|
+
value: {
|
|
440
|
+
...op.value,
|
|
441
|
+
newValue: op.value.newValue,
|
|
442
|
+
oldValue: prev.value.oldValue
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
var addNodeOperationMeta = {
|
|
452
|
+
...baseOperationMeta,
|
|
453
|
+
type: "addNode" /* addNode */,
|
|
454
|
+
inverse: (op) => ({
|
|
455
|
+
...op,
|
|
456
|
+
type: "deleteNode" /* deleteNode */
|
|
457
|
+
}),
|
|
458
|
+
apply: async (operation, ctx) => {
|
|
459
|
+
const document = ctx.get(freeLayoutCore.WorkflowDocument);
|
|
460
|
+
await document.createWorkflowNode(
|
|
461
|
+
lodashEs.cloneDeep(operation.value.node),
|
|
462
|
+
false,
|
|
463
|
+
operation.value.parentID
|
|
464
|
+
);
|
|
465
|
+
},
|
|
466
|
+
getLabel: (op, ctx) => {
|
|
467
|
+
const config = ctx.get(exports.FreeHistoryConfig);
|
|
468
|
+
return `Create Node ${config.getNodeLabel(op.value.node)}`;
|
|
469
|
+
},
|
|
470
|
+
getDescription: (op, ctx) => {
|
|
471
|
+
const config = ctx.get(exports.FreeHistoryConfig);
|
|
472
|
+
let desc = `Create Node ${config.getNodeLabel(op.value.node)}`;
|
|
473
|
+
if (op.value.node.meta?.position) {
|
|
474
|
+
desc += ` at ${op.value.node.meta.position.x},${op.value.node.meta.position.y}`;
|
|
475
|
+
}
|
|
476
|
+
return desc;
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
var addLineOperationMeta = {
|
|
480
|
+
...baseOperationMeta,
|
|
481
|
+
type: "addLine" /* addLine */,
|
|
482
|
+
inverse: (op) => ({
|
|
483
|
+
...op,
|
|
484
|
+
type: "deleteLine" /* deleteLine */
|
|
485
|
+
}),
|
|
486
|
+
apply: (operation, ctx) => {
|
|
487
|
+
const linesManager = ctx.get(freeLayoutCore.WorkflowLinesManager);
|
|
488
|
+
linesManager.createLine({
|
|
489
|
+
...operation.value,
|
|
490
|
+
key: operation.value.id
|
|
491
|
+
});
|
|
492
|
+
},
|
|
493
|
+
getLabel: (op, ctx) => "Create Line",
|
|
494
|
+
getDescription: (op, ctx) => {
|
|
495
|
+
const config = ctx.get(exports.FreeHistoryConfig);
|
|
496
|
+
const { value } = op;
|
|
497
|
+
if (!value.from || !value.to) {
|
|
498
|
+
return "Create Line";
|
|
499
|
+
}
|
|
500
|
+
const fromName = config.getNodeLabelById(value.from);
|
|
501
|
+
const toName = config.getNodeLabelById(value.to);
|
|
502
|
+
return `Create Line from ${fromName} to ${toName}`;
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
// src/operation-metas/index.ts
|
|
507
|
+
var operationMetas = [
|
|
508
|
+
addLineOperationMeta,
|
|
509
|
+
deleteLineOperationMeta,
|
|
510
|
+
addNodeOperationMeta,
|
|
511
|
+
deleteNodeOperationMeta,
|
|
512
|
+
resetLayoutOperationMeta,
|
|
513
|
+
dragNodesOperationMeta,
|
|
514
|
+
moveChildNodesOperationMeta,
|
|
515
|
+
changeLineDataOperationMeta
|
|
516
|
+
];
|
|
517
|
+
|
|
518
|
+
// src/free-history-registers.ts
|
|
519
|
+
exports.FreeHistoryRegisters = class FreeHistoryRegisters {
|
|
520
|
+
registerOperationMeta(operationRegistry) {
|
|
521
|
+
operationMetas.forEach((operationMeta) => {
|
|
522
|
+
operationRegistry.registerOperationMeta(operationMeta);
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
exports.FreeHistoryRegisters = __decorateClass([
|
|
527
|
+
inversify.injectable()
|
|
528
|
+
], exports.FreeHistoryRegisters);
|
|
529
|
+
var FreeHistoryManager = class {
|
|
530
|
+
constructor() {
|
|
531
|
+
this._toDispose = new utils.DisposableCollection();
|
|
532
|
+
}
|
|
533
|
+
onInit(ctx, opts) {
|
|
534
|
+
const document$1 = ctx.get(freeLayoutCore.WorkflowDocument);
|
|
535
|
+
const historyService = ctx.get(history.HistoryService);
|
|
536
|
+
const dragService = ctx.get(freeLayoutCore.WorkflowDragService);
|
|
537
|
+
const resetLayoutService = ctx.get(freeLayoutCore.WorkflowResetLayoutService);
|
|
538
|
+
if (opts?.limit) {
|
|
539
|
+
historyService.limit(opts.limit);
|
|
540
|
+
}
|
|
541
|
+
historyService.context.source = ctx;
|
|
542
|
+
this._toDispose.pushAll([
|
|
543
|
+
dragService.onNodesDrag(async (event) => {
|
|
544
|
+
if (event.type !== "onDragEnd") {
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
this._dragNodesHandler.handle(event);
|
|
548
|
+
}),
|
|
549
|
+
document$1.onNodeCreate(({ node, data }) => {
|
|
550
|
+
const positionData = node.getData(core.PositionData);
|
|
551
|
+
if (positionData) {
|
|
552
|
+
this._entityManager.addEntityData(positionData);
|
|
553
|
+
}
|
|
554
|
+
}),
|
|
555
|
+
document$1.onContentChange((event) => {
|
|
556
|
+
this._changeContentHandler.handle(event, ctx);
|
|
557
|
+
}),
|
|
558
|
+
document$1.onReload((_event) => {
|
|
559
|
+
historyService.clear();
|
|
560
|
+
}),
|
|
561
|
+
resetLayoutService.onResetLayout((event) => {
|
|
562
|
+
historyService.pushOperation(
|
|
563
|
+
{
|
|
564
|
+
type: "resetLayout" /* resetLayout */,
|
|
565
|
+
value: {
|
|
566
|
+
ids: event.nodeIds,
|
|
567
|
+
value: event.positionMap,
|
|
568
|
+
oldValue: event.oldPositionMap
|
|
569
|
+
}
|
|
570
|
+
},
|
|
571
|
+
{ noApply: true }
|
|
572
|
+
);
|
|
573
|
+
}),
|
|
574
|
+
this._operationService.onNodeMove(({ node, fromParent, fromIndex, toParent, toIndex }) => {
|
|
575
|
+
historyService.pushOperation(
|
|
576
|
+
{
|
|
577
|
+
type: document.OperationType.moveChildNodes,
|
|
578
|
+
value: {
|
|
579
|
+
fromParentId: fromParent.id,
|
|
580
|
+
fromIndex,
|
|
581
|
+
nodeIds: [node.id],
|
|
582
|
+
toParentId: toParent.id,
|
|
583
|
+
toIndex
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
noApply: true
|
|
588
|
+
}
|
|
589
|
+
);
|
|
590
|
+
}),
|
|
591
|
+
this._operationService.onNodePostionUpdate((event) => {
|
|
592
|
+
const value = {
|
|
593
|
+
ids: [event.node.id],
|
|
594
|
+
value: [event.newPosition],
|
|
595
|
+
oldValue: [event.oldPosition]
|
|
596
|
+
};
|
|
597
|
+
historyService.pushOperation(
|
|
598
|
+
{
|
|
599
|
+
type: "dragNodes" /* dragNodes */,
|
|
600
|
+
value
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
noApply: true
|
|
604
|
+
}
|
|
605
|
+
);
|
|
606
|
+
})
|
|
607
|
+
]);
|
|
608
|
+
}
|
|
609
|
+
dispose() {
|
|
610
|
+
this._entityManager.dispose();
|
|
611
|
+
this._toDispose.dispose();
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
__decorateClass([
|
|
615
|
+
inversify.inject(DragNodesHandler)
|
|
616
|
+
], FreeHistoryManager.prototype, "_dragNodesHandler", 2);
|
|
617
|
+
__decorateClass([
|
|
618
|
+
inversify.inject(ChangeContentHandler)
|
|
619
|
+
], FreeHistoryManager.prototype, "_changeContentHandler", 2);
|
|
620
|
+
__decorateClass([
|
|
621
|
+
inversify.inject(HistoryEntityManager)
|
|
622
|
+
], FreeHistoryManager.prototype, "_entityManager", 2);
|
|
623
|
+
__decorateClass([
|
|
624
|
+
inversify.inject(freeLayoutCore.WorkflowOperationBaseService)
|
|
625
|
+
], FreeHistoryManager.prototype, "_operationService", 2);
|
|
626
|
+
FreeHistoryManager = __decorateClass([
|
|
627
|
+
inversify.injectable()
|
|
628
|
+
], FreeHistoryManager);
|
|
629
|
+
|
|
630
|
+
// src/create-free-history-plugin.ts
|
|
631
|
+
var createFreeHistoryPlugin = core.definePluginCreator({
|
|
632
|
+
onBind: ({ bind }) => {
|
|
633
|
+
core.bindContributions(bind, exports.FreeHistoryRegisters, [history.OperationContribution]);
|
|
634
|
+
bind(exports.FreeHistoryConfig).toSelf().inSingletonScope();
|
|
635
|
+
bind(FreeHistoryManager).toSelf().inSingletonScope();
|
|
636
|
+
bind(HistoryEntityManager).toSelf().inSingletonScope();
|
|
637
|
+
bind(DragNodesHandler).toSelf().inSingletonScope();
|
|
638
|
+
bind(ChangeContentHandler).toSelf().inSingletonScope();
|
|
639
|
+
},
|
|
640
|
+
onInit(ctx, opts) {
|
|
641
|
+
ctx.get(exports.FreeHistoryConfig).init(ctx, opts);
|
|
642
|
+
if (!opts.enable) {
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
ctx.get(FreeHistoryManager).onInit(ctx, opts);
|
|
646
|
+
},
|
|
647
|
+
onDispose(ctx) {
|
|
648
|
+
ctx.get(HistoryEntityManager).dispose();
|
|
649
|
+
},
|
|
650
|
+
containerModules: [history.HistoryContainerModule]
|
|
651
|
+
});
|
|
652
|
+
function useUndoRedo() {
|
|
653
|
+
const historyService = core.useService(history.HistoryService);
|
|
654
|
+
const canUndo = vue.ref(false);
|
|
655
|
+
const canRedo = vue.ref(false);
|
|
656
|
+
const toDispose = historyService.undoRedoService.onChange(() => {
|
|
657
|
+
canUndo.value = historyService.canUndo();
|
|
658
|
+
canRedo.value = historyService.canRedo();
|
|
659
|
+
});
|
|
660
|
+
vue.onBeforeUnmount(() => {
|
|
661
|
+
toDispose.dispose();
|
|
662
|
+
});
|
|
663
|
+
return {
|
|
664
|
+
canUndo,
|
|
665
|
+
canRedo,
|
|
666
|
+
undo: () => historyService.undo(),
|
|
667
|
+
redo: () => historyService.redo()
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
exports.FreeOperationType = FreeOperationType;
|
|
672
|
+
exports.createFreeHistoryPlugin = createFreeHistoryPlugin;
|
|
673
|
+
exports.useUndoRedo = useUndoRedo;
|
|
674
|
+
Object.keys(history).forEach(function (k) {
|
|
675
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
676
|
+
enumerable: true,
|
|
677
|
+
get: function () { return history[k]; }
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
//# sourceMappingURL=index.cjs.map
|
|
681
|
+
//# sourceMappingURL=index.cjs.map
|