sequential-workflow-designer 0.18.3 → 0.18.5

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/lib/cjs/index.cjs CHANGED
@@ -2,94 +2,6 @@
2
2
 
3
3
  var sequentialWorkflowModel = require('sequential-workflow-model');
4
4
 
5
- class ControlBarApi {
6
- constructor(state, historyController, definitionModifier, viewportApi) {
7
- this.state = state;
8
- this.historyController = historyController;
9
- this.definitionModifier = definitionModifier;
10
- this.viewportApi = viewportApi;
11
- }
12
- /**
13
- * @deprecated Don't use this method
14
- */
15
- subscribe(handler) {
16
- // TODO: this should be refactored
17
- this.state.onIsReadonlyChanged.subscribe(handler);
18
- this.state.onSelectedStepIdChanged.subscribe(handler);
19
- this.state.onIsDragDisabledChanged.subscribe(handler);
20
- if (this.isUndoRedoSupported()) {
21
- this.state.onDefinitionChanged.subscribe(handler);
22
- }
23
- }
24
- resetViewport() {
25
- this.viewportApi.resetViewport();
26
- }
27
- zoomIn() {
28
- this.viewportApi.zoom(true);
29
- }
30
- zoomOut() {
31
- this.viewportApi.zoom(false);
32
- }
33
- isDragDisabled() {
34
- return this.state.isDragDisabled;
35
- }
36
- toggleIsDragDisabled() {
37
- this.state.toggleIsDragDisabled();
38
- }
39
- isUndoRedoSupported() {
40
- return !!this.historyController;
41
- }
42
- tryUndo() {
43
- if (this.canUndo() && this.historyController) {
44
- this.historyController.undo();
45
- return true;
46
- }
47
- return false;
48
- }
49
- canUndo() {
50
- return !!this.historyController && this.historyController.canUndo() && !this.state.isReadonly && !this.state.isDragging;
51
- }
52
- tryRedo() {
53
- if (this.canRedo() && this.historyController) {
54
- this.historyController.redo();
55
- return true;
56
- }
57
- return false;
58
- }
59
- canRedo() {
60
- return !!this.historyController && this.historyController.canRedo() && !this.state.isReadonly && !this.state.isDragging;
61
- }
62
- tryDelete() {
63
- if (this.canDelete() && this.state.selectedStepId) {
64
- this.definitionModifier.tryDelete(this.state.selectedStepId);
65
- return true;
66
- }
67
- return false;
68
- }
69
- canDelete() {
70
- return (!!this.state.selectedStepId &&
71
- !this.state.isReadonly &&
72
- !this.state.isDragging &&
73
- this.definitionModifier.isDeletable(this.state.selectedStepId));
74
- }
75
- }
76
-
77
- exports.KeyboardAction = void 0;
78
- (function (KeyboardAction) {
79
- KeyboardAction["delete"] = "delete";
80
- })(exports.KeyboardAction || (exports.KeyboardAction = {}));
81
- exports.DefinitionChangeType = void 0;
82
- (function (DefinitionChangeType) {
83
- DefinitionChangeType[DefinitionChangeType["stepNameChanged"] = 1] = "stepNameChanged";
84
- DefinitionChangeType[DefinitionChangeType["stepPropertyChanged"] = 2] = "stepPropertyChanged";
85
- DefinitionChangeType[DefinitionChangeType["stepChildrenChanged"] = 3] = "stepChildrenChanged";
86
- DefinitionChangeType[DefinitionChangeType["stepDeleted"] = 4] = "stepDeleted";
87
- DefinitionChangeType[DefinitionChangeType["stepMoved"] = 5] = "stepMoved";
88
- DefinitionChangeType[DefinitionChangeType["stepInserted"] = 6] = "stepInserted";
89
- DefinitionChangeType[DefinitionChangeType["rootPropertyChanged"] = 7] = "rootPropertyChanged";
90
- DefinitionChangeType[DefinitionChangeType["rootReplaced"] = 8] = "rootReplaced";
91
- })(exports.DefinitionChangeType || (exports.DefinitionChangeType = {}));
92
-
93
5
  class Dom {
94
6
  static svg(name, attributes) {
95
7
  const element = document.createElementNS('http://www.w3.org/2000/svg', name);
@@ -219,6 +131,11 @@ class Uid {
219
131
  class SimpleEvent {
220
132
  constructor() {
221
133
  this.listeners = [];
134
+ this.forward = (value) => {
135
+ if (this.listeners.length > 0) {
136
+ this.listeners.forEach(listener => listener(value));
137
+ }
138
+ };
222
139
  }
223
140
  subscribe(listener) {
224
141
  this.listeners.push(listener);
@@ -232,14 +149,18 @@ class SimpleEvent {
232
149
  throw new Error('Unknown listener');
233
150
  }
234
151
  }
235
- forward(value) {
236
- if (this.listeners.length > 0) {
237
- this.listeners.forEach(listener => listener(value));
238
- }
239
- }
240
152
  count() {
241
153
  return this.listeners.length;
242
154
  }
155
+ first() {
156
+ return new Promise(resolve => {
157
+ const handler = (value) => {
158
+ this.unsubscribe(handler);
159
+ resolve(value);
160
+ };
161
+ this.subscribe(handler);
162
+ });
163
+ }
243
164
  }
244
165
 
245
166
  function race(timeout, a, b, c) {
@@ -272,6 +193,99 @@ function race(timeout, a, b, c) {
272
193
  return result;
273
194
  }
274
195
 
196
+ class ControlBarApi {
197
+ static create(state, historyController, definitionModifier, viewportApi) {
198
+ const api = new ControlBarApi(state, historyController, definitionModifier, viewportApi);
199
+ state.onIsReadonlyChanged.subscribe(api.onStateChanged.forward);
200
+ state.onSelectedStepIdChanged.subscribe(api.onStateChanged.forward);
201
+ state.onIsDragDisabledChanged.subscribe(api.onStateChanged.forward);
202
+ if (api.isUndoRedoSupported()) {
203
+ state.onDefinitionChanged.subscribe(api.onStateChanged.forward);
204
+ }
205
+ return api;
206
+ }
207
+ constructor(state, historyController, definitionModifier, viewportApi) {
208
+ this.state = state;
209
+ this.historyController = historyController;
210
+ this.definitionModifier = definitionModifier;
211
+ this.viewportApi = viewportApi;
212
+ this.onStateChanged = new SimpleEvent();
213
+ }
214
+ /**
215
+ * @deprecated Don't use this method
216
+ */
217
+ subscribe(handler) {
218
+ this.onStateChanged.subscribe(handler);
219
+ }
220
+ resetViewport() {
221
+ this.viewportApi.resetViewport();
222
+ }
223
+ zoomIn() {
224
+ this.viewportApi.zoom(true);
225
+ }
226
+ zoomOut() {
227
+ this.viewportApi.zoom(false);
228
+ }
229
+ isDragDisabled() {
230
+ return this.state.isDragDisabled;
231
+ }
232
+ toggleIsDragDisabled() {
233
+ this.state.toggleIsDragDisabled();
234
+ }
235
+ isUndoRedoSupported() {
236
+ return !!this.historyController;
237
+ }
238
+ tryUndo() {
239
+ if (this.canUndo() && this.historyController) {
240
+ this.historyController.undo();
241
+ return true;
242
+ }
243
+ return false;
244
+ }
245
+ canUndo() {
246
+ return !!this.historyController && this.historyController.canUndo() && !this.state.isReadonly && !this.state.isDragging;
247
+ }
248
+ tryRedo() {
249
+ if (this.canRedo() && this.historyController) {
250
+ this.historyController.redo();
251
+ return true;
252
+ }
253
+ return false;
254
+ }
255
+ canRedo() {
256
+ return !!this.historyController && this.historyController.canRedo() && !this.state.isReadonly && !this.state.isDragging;
257
+ }
258
+ tryDelete() {
259
+ if (this.canDelete() && this.state.selectedStepId) {
260
+ this.definitionModifier.tryDelete(this.state.selectedStepId);
261
+ return true;
262
+ }
263
+ return false;
264
+ }
265
+ canDelete() {
266
+ return (!!this.state.selectedStepId &&
267
+ !this.state.isReadonly &&
268
+ !this.state.isDragging &&
269
+ this.definitionModifier.isDeletable(this.state.selectedStepId));
270
+ }
271
+ }
272
+
273
+ exports.KeyboardAction = void 0;
274
+ (function (KeyboardAction) {
275
+ KeyboardAction["delete"] = "delete";
276
+ })(exports.KeyboardAction || (exports.KeyboardAction = {}));
277
+ exports.DefinitionChangeType = void 0;
278
+ (function (DefinitionChangeType) {
279
+ DefinitionChangeType[DefinitionChangeType["stepNameChanged"] = 1] = "stepNameChanged";
280
+ DefinitionChangeType[DefinitionChangeType["stepPropertyChanged"] = 2] = "stepPropertyChanged";
281
+ DefinitionChangeType[DefinitionChangeType["stepChildrenChanged"] = 3] = "stepChildrenChanged";
282
+ DefinitionChangeType[DefinitionChangeType["stepDeleted"] = 4] = "stepDeleted";
283
+ DefinitionChangeType[DefinitionChangeType["stepMoved"] = 5] = "stepMoved";
284
+ DefinitionChangeType[DefinitionChangeType["stepInserted"] = 6] = "stepInserted";
285
+ DefinitionChangeType[DefinitionChangeType["rootPropertyChanged"] = 7] = "rootPropertyChanged";
286
+ DefinitionChangeType[DefinitionChangeType["rootReplaced"] = 8] = "rootReplaced";
287
+ })(exports.DefinitionChangeType || (exports.DefinitionChangeType = {}));
288
+
275
289
  class EditorRenderer {
276
290
  static create(state, definitionWalker, handler) {
277
291
  const raceEvent = race(0, state.onDefinitionChanged, state.onSelectedStepIdChanged, state.onIsReadonlyChanged);
@@ -372,13 +386,13 @@ class PathBarApi {
372
386
  constructor(state, definitionWalker) {
373
387
  this.state = state;
374
388
  this.definitionWalker = definitionWalker;
389
+ this.onStateChanged = race(0, this.state.onFolderPathChanged, this.state.onDefinitionChanged);
375
390
  }
376
391
  /**
377
392
  * @deprecated Don't use this method
378
393
  */
379
394
  subscribe(handler) {
380
- // TODO: this should be refactored
381
- race(0, this.state.onFolderPathChanged, this.state.onDefinitionChanged).subscribe(handler);
395
+ this.onStateChanged.subscribe(handler);
382
396
  }
383
397
  setFolderPath(path) {
384
398
  this.state.setFolderPath(path);
@@ -698,7 +712,7 @@ class DesignerApi {
698
712
  const viewportController = context.services.viewportController.create(workspace);
699
713
  const viewport = new ViewportApi(context.workspaceController, viewportController);
700
714
  const toolboxDataProvider = new ToolboxDataProvider(context.componentContext.iconProvider, context.configuration.toolbox);
701
- return new DesignerApi(new ControlBarApi(context.state, context.historyController, context.definitionModifier, viewport), new ToolboxApi(context.state, context, context.behaviorController, toolboxDataProvider, context.configuration.uidGenerator), new EditorApi(context.state, context.definitionWalker, context.definitionModifier), workspace, viewport, new PathBarApi(context.state, context.definitionWalker));
715
+ return new DesignerApi(ControlBarApi.create(context.state, context.historyController, context.definitionModifier, viewport), new ToolboxApi(context.state, context, context.behaviorController, toolboxDataProvider, context.configuration.uidGenerator), new EditorApi(context.state, context.definitionWalker, context.definitionModifier), workspace, viewport, new PathBarApi(context.state, context.definitionWalker));
702
716
  }
703
717
  constructor(controlBar, toolbox, editor, workspace, viewport, pathBar) {
704
718
  this.controlBar = controlBar;
@@ -2258,11 +2272,11 @@ class HistoryController {
2258
2272
  };
2259
2273
  const controller = new HistoryController(stack, state, definitionModifier, configuration.undoStackSize);
2260
2274
  if (!initialStack) {
2261
- controller.remember(exports.DefinitionChangeType.rootReplaced, null);
2275
+ controller.rememberCurrent(exports.DefinitionChangeType.rootReplaced, null);
2262
2276
  }
2263
2277
  state.onDefinitionChanged.subscribe(event => {
2264
2278
  if (event.changeType !== exports.DefinitionChangeType.rootReplaced) {
2265
- controller.remember(event.changeType, event.stepId);
2279
+ controller.rememberCurrent(event.changeType, event.stepId);
2266
2280
  }
2267
2281
  });
2268
2282
  return controller;
@@ -2290,8 +2304,18 @@ class HistoryController {
2290
2304
  dump() {
2291
2305
  return Object.assign({}, this.stack);
2292
2306
  }
2293
- remember(changeType, stepId) {
2294
- const definition = ObjectCloner.deepClone(this.state.definition);
2307
+ replaceDefinition(definition) {
2308
+ if (definition == this.state.definition) {
2309
+ throw new Error('Cannot use the same instance of definition');
2310
+ }
2311
+ this.remember(definition, exports.DefinitionChangeType.rootReplaced, null);
2312
+ this.commit();
2313
+ }
2314
+ rememberCurrent(changeType, stepId) {
2315
+ this.remember(this.state.definition, changeType, stepId);
2316
+ }
2317
+ remember(sourceDefinition, changeType, stepId) {
2318
+ const definition = ObjectCloner.deepClone(sourceDefinition);
2295
2319
  if (this.stack.items.length > 0 && this.stack.index === this.stack.items.length) {
2296
2320
  const lastItem = this.stack.items[this.stack.items.length - 1];
2297
2321
  if (areItemsEqual(lastItem, changeType, stepId)) {
@@ -2316,7 +2340,7 @@ class HistoryController {
2316
2340
  }
2317
2341
  }
2318
2342
  function areItemsEqual(item, changeType, stepId) {
2319
- return item.changeType === changeType && item.stepId === stepId;
2343
+ return changeType !== exports.DefinitionChangeType.rootReplaced && item.changeType === changeType && item.stepId === stepId;
2320
2344
  }
2321
2345
 
2322
2346
  class LayoutController {
@@ -2407,6 +2431,31 @@ class DesignerContext {
2407
2431
  }
2408
2432
  }
2409
2433
 
2434
+ /******************************************************************************
2435
+ Copyright (c) Microsoft Corporation.
2436
+
2437
+ Permission to use, copy, modify, and/or distribute this software for any
2438
+ purpose with or without fee is hereby granted.
2439
+
2440
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2441
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2442
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2443
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2444
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2445
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2446
+ PERFORMANCE OF THIS SOFTWARE.
2447
+ ***************************************************************************** */
2448
+
2449
+ function __awaiter(thisArg, _arguments, P, generator) {
2450
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2451
+ return new (P || (P = Promise))(function (resolve, reject) {
2452
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2453
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2454
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2455
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2456
+ });
2457
+ }
2458
+
2410
2459
  function isElementAttached(element) {
2411
2460
  return !(document.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_DISCONNECTED);
2412
2461
  }
@@ -2861,7 +2910,6 @@ class Workspace {
2861
2910
  setTimeout(() => {
2862
2911
  workspace.updateRootComponent();
2863
2912
  api.viewport.resetViewport();
2864
- workspace.onReady.forward();
2865
2913
  });
2866
2914
  designerContext.setWorkspaceController(workspace);
2867
2915
  designerContext.state.onViewportChanged.subscribe(vp => workspace.onViewportChanged(vp));
@@ -2884,7 +2932,7 @@ class Workspace {
2884
2932
  this.clickBehaviorResolver = clickBehaviorResolver;
2885
2933
  this.viewportApi = viewportApi;
2886
2934
  this.services = services;
2887
- this.onReady = new SimpleEvent();
2935
+ this.onRendered = new SimpleEvent();
2888
2936
  this.isValid = false;
2889
2937
  this.selectedStepComponent = null;
2890
2938
  this.validationErrorBadgeIndex = null;
@@ -2913,6 +2961,7 @@ class Workspace {
2913
2961
  this.view.render(sequence, parentSequencePlaceIndicator);
2914
2962
  this.trySelectStepComponent(this.state.selectedStepId);
2915
2963
  this.updateBadges();
2964
+ this.onRendered.forward();
2916
2965
  }
2917
2966
  updateBadges() {
2918
2967
  const result = BadgesResultFactory.create(this.services);
@@ -3208,7 +3257,7 @@ class ControlBar {
3208
3257
  view.bindZoomOutButtonClick(() => bar.onZoomOutButtonClicked());
3209
3258
  view.bindDisableDragButtonClick(() => bar.onMoveButtonClicked());
3210
3259
  view.bindDeleteButtonClick(() => bar.onDeleteButtonClicked());
3211
- api.controlBar.subscribe(() => bar.refreshButtons());
3260
+ api.controlBar.onStateChanged.subscribe(() => bar.refreshButtons());
3212
3261
  if (isUndoRedoSupported) {
3213
3262
  view.bindUndoButtonClick(() => bar.onUndoButtonClicked());
3214
3263
  view.bindRedoButtonClick(() => bar.onRedoButtonClicked());
@@ -4163,7 +4212,7 @@ class Designer {
4163
4212
  const designerApi = DesignerApi.create(designerContext);
4164
4213
  const view = DesignerView.create(placeholder, designerContext, designerApi);
4165
4214
  const designer = new Designer(view, designerContext.state, designerContext.definitionWalker, designerContext.historyController, designerApi);
4166
- view.workspace.onReady.subscribe(() => designer.onReady.forward());
4215
+ view.workspace.onRendered.first().then(designer.onReady.forward);
4167
4216
  race(0, designerContext.state.onDefinitionChanged, designerContext.state.onSelectedStepIdChanged).subscribe(([definition, selectedStepId]) => {
4168
4217
  if (definition !== undefined) {
4169
4218
  designer.onDefinitionChanged.forward(designerContext.state.definition);
@@ -4172,15 +4221,9 @@ class Designer {
4172
4221
  designer.onSelectedStepIdChanged.forward(designerContext.state.selectedStepId);
4173
4222
  }
4174
4223
  });
4175
- designerContext.state.onViewportChanged.subscribe(viewPort => {
4176
- designer.onViewportChanged.forward(viewPort);
4177
- });
4178
- designerContext.state.onIsToolboxCollapsedChanged.subscribe(isCollapsed => {
4179
- designer.onIsToolboxCollapsedChanged.forward(isCollapsed);
4180
- });
4181
- designerContext.state.onIsEditorCollapsedChanged.subscribe(isCollapsed => {
4182
- designer.onIsEditorCollapsedChanged.forward(isCollapsed);
4183
- });
4224
+ designerContext.state.onViewportChanged.subscribe(designer.onViewportChanged.forward);
4225
+ designerContext.state.onIsToolboxCollapsedChanged.subscribe(designer.onIsToolboxCollapsedChanged.forward);
4226
+ designerContext.state.onIsEditorCollapsedChanged.subscribe(designer.onIsEditorCollapsedChanged.forward);
4184
4227
  return designer;
4185
4228
  }
4186
4229
  constructor(view, state, walker, historyController, api) {
@@ -4321,10 +4364,20 @@ class Designer {
4321
4364
  * @description Dump the undo stack.
4322
4365
  */
4323
4366
  dumpUndoStack() {
4324
- if (!this.historyController) {
4325
- throw new Error('Undo feature is not activated');
4326
- }
4327
- return this.historyController.dump();
4367
+ return this.getHistoryController().dump();
4368
+ }
4369
+ /**
4370
+ * Replaces the current definition with a new one and adds the previous definition to the undo stack.
4371
+ * @param definition A new definition.
4372
+ */
4373
+ replaceDefinition(definition) {
4374
+ return __awaiter(this, void 0, void 0, function* () {
4375
+ this.getHistoryController().replaceDefinition(definition);
4376
+ yield Promise.all([
4377
+ this.view.workspace.onRendered.first(),
4378
+ this.onDefinitionChanged.first()
4379
+ ]);
4380
+ });
4328
4381
  }
4329
4382
  /**
4330
4383
  * @param needle A step, a sequence or a step id.
@@ -4345,6 +4398,12 @@ class Designer {
4345
4398
  destroy() {
4346
4399
  this.view.destroy();
4347
4400
  }
4401
+ getHistoryController() {
4402
+ if (!this.historyController) {
4403
+ throw new Error('Undo feature is not activated');
4404
+ }
4405
+ return this.historyController;
4406
+ }
4348
4407
  }
4349
4408
 
4350
4409
  class LineGridDesignerExtension {