sequential-workflow-designer-react 0.33.1 → 0.34.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sequential-workflow-designer-react",
3
3
  "description": "React wrapper for Sequential Workflow Designer component.",
4
- "version": "0.33.1",
4
+ "version": "0.34.0",
5
5
  "type": "module",
6
6
  "main": "./lib/esm/index.js",
7
7
  "types": "./lib/index.d.ts",
@@ -47,7 +47,7 @@
47
47
  "peerDependencies": {
48
48
  "react": ">=18.2.0",
49
49
  "react-dom": ">=18.2.0",
50
- "sequential-workflow-designer": "^0.33.1"
50
+ "sequential-workflow-designer": "^0.34.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@rollup/plugin-node-resolve": "^16.0.1",
@@ -63,7 +63,7 @@
63
63
  "prettier": "^3.2.5",
64
64
  "react": "^18.2.0",
65
65
  "react-dom": "^18.2.0",
66
- "sequential-workflow-designer": "^0.33.1",
66
+ "sequential-workflow-designer": "^0.34.0",
67
67
  "rollup": "^4.40.0",
68
68
  "rollup-plugin-dts": "^6.2.1",
69
69
  "rollup-plugin-typescript2": "^0.36.0",
package/lib/cjs/index.cjs DELETED
@@ -1,440 +0,0 @@
1
- 'use strict';
2
-
3
- var ReactDOM = require('react-dom/client');
4
- var jsxRuntime = require('react/jsx-runtime');
5
- var react = require('react');
6
- var sequentialWorkflowDesigner = require('sequential-workflow-designer');
7
-
8
- var Presenter = /** @class */ (function () {
9
- function Presenter() {
10
- }
11
- Presenter.render = function (className, rootRef, element) {
12
- Presenter.tryDestroy(rootRef);
13
- var container = document.createElement('div');
14
- container.className = className;
15
- rootRef.current = ReactDOM.createRoot(container);
16
- rootRef.current.render(element);
17
- return container;
18
- };
19
- Presenter.tryDestroy = function (rootRef) {
20
- if (rootRef.current) {
21
- var oldRoot_1 = rootRef.current;
22
- rootRef.current = null;
23
- setTimeout(function () { return oldRoot_1.unmount(); });
24
- }
25
- };
26
- return Presenter;
27
- }());
28
-
29
- /******************************************************************************
30
- Copyright (c) Microsoft Corporation.
31
-
32
- Permission to use, copy, modify, and/or distribute this software for any
33
- purpose with or without fee is hereby granted.
34
-
35
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
36
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
37
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
38
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
39
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
40
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
41
- PERFORMANCE OF THIS SOFTWARE.
42
- ***************************************************************************** */
43
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
44
-
45
-
46
- var __assign = function() {
47
- __assign = Object.assign || function __assign(t) {
48
- for (var s, i = 1, n = arguments.length; i < n; i++) {
49
- s = arguments[i];
50
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
51
- }
52
- return t;
53
- };
54
- return __assign.apply(this, arguments);
55
- };
56
-
57
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
58
- var e = new Error(message);
59
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
60
- };
61
-
62
- if (!window.sqdRootEditorContext) {
63
- window.sqdRootEditorContext = react.createContext(null);
64
- }
65
- var rootEditorContext = window.sqdRootEditorContext;
66
- function useRootEditor() {
67
- var wrapper = react.useContext(rootEditorContext);
68
- if (!wrapper) {
69
- throw new Error('Cannot find root editor context');
70
- }
71
- return wrapper;
72
- }
73
- function RootEditorWrapperContext(props) {
74
- var _a = react.useState(function () { return createWrapper(); }), wrapper = _a[0], setWrapper = _a[1];
75
- function createWrapper() {
76
- return {
77
- properties: props.definition.properties,
78
- definition: props.definition,
79
- isReadonly: props.isReadonly,
80
- setProperty: setProperty
81
- };
82
- }
83
- function forward() {
84
- setWrapper(createWrapper());
85
- }
86
- function setProperty(name, value) {
87
- props.definition.properties[name] = value;
88
- props.context.notifyPropertiesChanged();
89
- forward();
90
- }
91
- return jsxRuntime.jsx(rootEditorContext.Provider, __assign({ value: wrapper }, { children: props.children }));
92
- }
93
-
94
- if (!window.sqdStepEditorContext) {
95
- window.sqdStepEditorContext = react.createContext(null);
96
- }
97
- var stepEditorContext = window.sqdStepEditorContext;
98
- function useStepEditor() {
99
- var wrapper = react.useContext(stepEditorContext);
100
- if (!wrapper) {
101
- throw new Error('Cannot find step editor context');
102
- }
103
- return wrapper;
104
- }
105
- function StepEditorWrapperContext(props) {
106
- var _a = react.useState(function () { return createWrapper(); }), wrapper = _a[0], setWrapper = _a[1];
107
- function createWrapper() {
108
- return {
109
- id: props.step.id,
110
- type: props.step.type,
111
- componentType: props.step.componentType,
112
- name: props.step.name,
113
- properties: props.step.properties,
114
- step: props.step,
115
- definition: props.definition,
116
- isReadonly: props.isReadonly,
117
- setName: setName,
118
- setProperty: setProperty,
119
- notifyPropertiesChanged: notifyPropertiesChanged,
120
- notifyChildrenChanged: notifyChildrenChanged
121
- };
122
- }
123
- function forward() {
124
- setWrapper(createWrapper());
125
- }
126
- function setName(name) {
127
- props.step.name = name;
128
- notifyNameChanged();
129
- }
130
- function setProperty(name, value) {
131
- props.step.properties[name] = value;
132
- notifyPropertiesChanged();
133
- }
134
- function notifyNameChanged() {
135
- props.context.notifyNameChanged();
136
- forward();
137
- }
138
- function notifyPropertiesChanged() {
139
- props.context.notifyPropertiesChanged();
140
- forward();
141
- }
142
- function notifyChildrenChanged() {
143
- props.context.notifyChildrenChanged();
144
- forward();
145
- }
146
- return jsxRuntime.jsx(stepEditorContext.Provider, __assign({ value: wrapper }, { children: props.children }));
147
- }
148
-
149
- function wrapDefinition(value, isValid) {
150
- return {
151
- value: value,
152
- isValid: isValid
153
- };
154
- }
155
-
156
- var externalEditorClassName = 'sqd-editor-react';
157
- function SequentialWorkflowDesigner(props) {
158
- var _a = react.useState(null), root = _a[0], setRoot = _a[1];
159
- var onDefinitionChangeRef = react.useRef(props.onDefinitionChange);
160
- var onSelectedStepIdChangedRef = react.useRef(props.onSelectedStepIdChanged);
161
- var onStepUnselectionBlockedRef = react.useRef(props.onStepUnselectionBlocked);
162
- var onIsEditorCollapsedChangedRef = react.useRef(props.onIsEditorCollapsedChanged);
163
- var onIsToolboxCollapsedChangedRef = react.useRef(props.onIsToolboxCollapsedChanged);
164
- var rootEditorRef = react.useRef(props.rootEditor);
165
- var stepEditorRef = react.useRef(props.stepEditor);
166
- var controllerRef = react.useRef(props.controller);
167
- var customActionHandlerRef = react.useRef(props.customActionHandler);
168
- var designerRef = react.useRef(null);
169
- var editorRootRef = react.useRef(null);
170
- var definition = props.definition;
171
- var selectedStepId = props.selectedStepId;
172
- var isReadonly = props.isReadonly;
173
- var theme = props.theme;
174
- var undoStackSize = props.undoStackSize;
175
- var steps = props.stepsConfiguration;
176
- var validator = props.validatorConfiguration;
177
- var placeholder = props.placeholderConfiguration;
178
- var toolbox = props.toolboxConfiguration;
179
- var isEditorCollapsed = props.isEditorCollapsed;
180
- var isToolboxCollapsed = props.isToolboxCollapsed;
181
- var controlBar = props.controlBar;
182
- var contextMenu = props.contextMenu;
183
- var keyboard = props.keyboard;
184
- var preferenceStorage = props.preferenceStorage;
185
- var extensions = props.extensions;
186
- var i18n = props.i18n;
187
- function forwardDefinition() {
188
- if (designerRef.current) {
189
- var wd = wrapDefinition(designerRef.current.getDefinition(), designerRef.current.isValid());
190
- onDefinitionChangeRef.current(wd);
191
- }
192
- }
193
- function rootEditorProvider(def, context, isReadonly) {
194
- if (!rootEditorRef.current) {
195
- throw new Error('Root editor is not provided');
196
- }
197
- if (react.isValidElement(rootEditorRef.current)) {
198
- return Presenter.render(externalEditorClassName, editorRootRef, jsxRuntime.jsx(RootEditorWrapperContext, __assign({ definition: def, context: context, isReadonly: isReadonly }, { children: rootEditorRef.current })));
199
- }
200
- return rootEditorRef.current(def, context, isReadonly);
201
- }
202
- function stepEditorProvider(step, context, def, isReadonly) {
203
- if (!stepEditorRef.current) {
204
- throw new Error('Step editor is not provided');
205
- }
206
- if (react.isValidElement(stepEditorRef.current)) {
207
- return Presenter.render(externalEditorClassName, editorRootRef, jsxRuntime.jsx(StepEditorWrapperContext, __assign({ step: step, definition: def, context: context, isReadonly: isReadonly }, { children: stepEditorRef.current })));
208
- }
209
- return stepEditorRef.current(step, context, def, isReadonly);
210
- }
211
- function customActionHandler(action, step, sequence, context) {
212
- if (customActionHandlerRef.current) {
213
- customActionHandlerRef.current(action, step, sequence, context);
214
- }
215
- }
216
- function tryDestroy() {
217
- Presenter.tryDestroy(editorRootRef);
218
- if (controllerRef.current) {
219
- controllerRef.current.setDesigner(null);
220
- }
221
- if (designerRef.current) {
222
- designerRef.current.destroy();
223
- designerRef.current = null;
224
- // console.log('sqd: designer destroyed');
225
- }
226
- }
227
- react.useEffect(function () {
228
- onDefinitionChangeRef.current = props.onDefinitionChange;
229
- }, [props.onDefinitionChange]);
230
- react.useEffect(function () {
231
- onSelectedStepIdChangedRef.current = props.onSelectedStepIdChanged;
232
- }, [props.onSelectedStepIdChanged]);
233
- react.useEffect(function () {
234
- onStepUnselectionBlockedRef.current = props.onStepUnselectionBlocked;
235
- }, [props.onStepUnselectionBlocked]);
236
- react.useEffect(function () {
237
- onIsEditorCollapsedChangedRef.current = props.onIsEditorCollapsedChanged;
238
- }, [props.onIsEditorCollapsedChanged]);
239
- react.useEffect(function () {
240
- onIsToolboxCollapsedChangedRef.current = props.onIsToolboxCollapsedChanged;
241
- }, [props.onIsToolboxCollapsedChanged]);
242
- react.useEffect(function () {
243
- rootEditorRef.current = props.rootEditor;
244
- }, [props.rootEditor]);
245
- react.useEffect(function () {
246
- stepEditorRef.current = props.stepEditor;
247
- }, [props.stepEditor]);
248
- react.useEffect(function () {
249
- customActionHandlerRef.current = props.customActionHandler;
250
- }, [props.customActionHandler]);
251
- react.useEffect(function () {
252
- if (!root) {
253
- return;
254
- }
255
- if (designerRef.current) {
256
- var isNotChanged = definition.value === designerRef.current.getDefinition();
257
- if (isNotChanged) {
258
- if (selectedStepId !== undefined && selectedStepId !== designerRef.current.getSelectedStepId()) {
259
- if (selectedStepId) {
260
- designerRef.current.selectStepById(selectedStepId);
261
- }
262
- else {
263
- designerRef.current.clearSelectedStep();
264
- }
265
- // console.log('sqd: selected step updated');
266
- }
267
- if (isReadonly !== undefined && isReadonly !== designerRef.current.isReadonly()) {
268
- designerRef.current.setIsReadonly(isReadonly);
269
- // console.log('sqd: isReadonly updated');
270
- }
271
- if (isToolboxCollapsed !== undefined && isToolboxCollapsed !== designerRef.current.isToolboxCollapsed()) {
272
- designerRef.current.setIsToolboxCollapsed(isToolboxCollapsed);
273
- // console.log('sqd: isToolboxCollapsed updated');
274
- }
275
- if (isEditorCollapsed !== undefined && isEditorCollapsed !== designerRef.current.isEditorCollapsed()) {
276
- designerRef.current.setIsEditorCollapsed(isEditorCollapsed);
277
- // console.log('sqd: isEditorCollapsed updated');
278
- }
279
- return;
280
- }
281
- tryDestroy();
282
- }
283
- var designer = sequentialWorkflowDesigner.Designer.create(root, definition.value, {
284
- theme: theme,
285
- undoStackSize: undoStackSize,
286
- toolbox: toolbox
287
- ? __assign(__assign({}, toolbox), { isCollapsed: isToolboxCollapsed }) : false,
288
- steps: steps,
289
- validator: validator,
290
- placeholder: placeholder,
291
- controlBar: controlBar,
292
- contextMenu: contextMenu,
293
- keyboard: keyboard,
294
- preferenceStorage: preferenceStorage,
295
- editors: rootEditorRef.current && stepEditorRef.current
296
- ? {
297
- isCollapsed: isEditorCollapsed,
298
- rootEditorProvider: rootEditorProvider,
299
- stepEditorProvider: stepEditorProvider
300
- }
301
- : false,
302
- customActionHandler: customActionHandlerRef.current && customActionHandler,
303
- extensions: extensions,
304
- i18n: i18n,
305
- isReadonly: isReadonly
306
- });
307
- if (controllerRef.current) {
308
- controllerRef.current.setDesigner(designer);
309
- }
310
- if (selectedStepId) {
311
- designer.selectStepById(selectedStepId);
312
- }
313
- // console.log('sqd: designer rendered');
314
- designer.onReady.subscribe(forwardDefinition);
315
- designer.onDefinitionChanged.subscribe(forwardDefinition);
316
- designer.onSelectedStepIdChanged.subscribe(function (stepId) {
317
- if (onSelectedStepIdChangedRef.current) {
318
- onSelectedStepIdChangedRef.current(stepId);
319
- }
320
- });
321
- designer.onStepUnselectionBlocked.subscribe(function (targetStepId) {
322
- if (onStepUnselectionBlockedRef.current) {
323
- onStepUnselectionBlockedRef.current(targetStepId);
324
- }
325
- });
326
- designer.onIsToolboxCollapsedChanged.subscribe(function (isCollapsed) {
327
- if (onIsToolboxCollapsedChangedRef.current) {
328
- onIsToolboxCollapsedChangedRef.current(isCollapsed);
329
- }
330
- });
331
- designer.onIsEditorCollapsedChanged.subscribe(function (isCollapsed) {
332
- if (onIsEditorCollapsedChangedRef.current) {
333
- onIsEditorCollapsedChangedRef.current(isCollapsed);
334
- }
335
- });
336
- designerRef.current = designer;
337
- }, [
338
- root,
339
- definition,
340
- selectedStepId,
341
- isReadonly,
342
- theme,
343
- undoStackSize,
344
- toolbox,
345
- isToolboxCollapsed,
346
- isEditorCollapsed,
347
- contextMenu,
348
- keyboard,
349
- preferenceStorage,
350
- controlBar,
351
- steps,
352
- validator,
353
- placeholder,
354
- extensions,
355
- i18n
356
- ]);
357
- react.useEffect(function () {
358
- return tryDestroy;
359
- }, []);
360
- return jsxRuntime.jsx("div", { ref: setRoot, "data-testid": "designer", className: "sqd-designer-react" });
361
- }
362
-
363
- var SequentialWorkflowDesignerController = /** @class */ (function () {
364
- function SequentialWorkflowDesignerController() {
365
- var _this = this;
366
- /**
367
- * @description Event that is raised when the controller is ready to be used.
368
- */
369
- this.onIsReadyChanged = new sequentialWorkflowDesigner.SimpleEvent();
370
- this.designer = null;
371
- /**
372
- * @description Moves the viewport to the step with the animation.
373
- */
374
- this.moveViewportToStep = function (stepId) {
375
- _this.getDesigner().moveViewportToStep(stepId);
376
- };
377
- /**
378
- * @description Updates all badges.
379
- */
380
- this.updateBadges = function () {
381
- _this.getDesigner().updateBadges();
382
- };
383
- /**
384
- * @description Rerender the root component and all its children.
385
- */
386
- this.updateRootComponent = function () {
387
- _this.getDesigner().updateRootComponent();
388
- };
389
- /**
390
- * @description Updates the layout of the designer.
391
- */
392
- this.updateLayout = function () {
393
- _this.getDesigner().updateLayout();
394
- };
395
- /**
396
- * Replaces the current definition with a new one and adds the previous definition to the undo stack.
397
- * @param definition A new definition.
398
- */
399
- this.replaceDefinition = function (definition) {
400
- return _this.getDesigner().replaceDefinition(definition);
401
- };
402
- // Nothing...
403
- }
404
- SequentialWorkflowDesignerController.create = function () {
405
- return new SequentialWorkflowDesignerController();
406
- };
407
- /**
408
- * @returns `true` if the controller is ready to be used, `false` otherwise.
409
- */
410
- SequentialWorkflowDesignerController.prototype.isReady = function () {
411
- return Boolean(this.designer);
412
- };
413
- SequentialWorkflowDesignerController.prototype.setDesigner = function (designer) {
414
- if (designer && this.designer) {
415
- throw new Error('Designer is already set');
416
- }
417
- this.designer = designer;
418
- this.onIsReadyChanged.forward();
419
- };
420
- SequentialWorkflowDesignerController.prototype.getDesigner = function () {
421
- if (!this.designer) {
422
- throw new Error('Designer is not ready yet');
423
- }
424
- return this.designer;
425
- };
426
- return SequentialWorkflowDesignerController;
427
- }());
428
- function useSequentialWorkflowDesignerController(deps) {
429
- return react.useMemo(function () { return SequentialWorkflowDesignerController.create(); }, deps || []);
430
- }
431
-
432
- exports.Presenter = Presenter;
433
- exports.RootEditorWrapperContext = RootEditorWrapperContext;
434
- exports.SequentialWorkflowDesigner = SequentialWorkflowDesigner;
435
- exports.SequentialWorkflowDesignerController = SequentialWorkflowDesignerController;
436
- exports.StepEditorWrapperContext = StepEditorWrapperContext;
437
- exports.useRootEditor = useRootEditor;
438
- exports.useSequentialWorkflowDesignerController = useSequentialWorkflowDesignerController;
439
- exports.useStepEditor = useStepEditor;
440
- exports.wrapDefinition = wrapDefinition;
package/lib/esm/index.js DELETED
@@ -1,430 +0,0 @@
1
- import ReactDOM from 'react-dom/client';
2
- import { jsx } from 'react/jsx-runtime';
3
- import { createContext, useContext, useState, useRef, useEffect, isValidElement, useMemo } from 'react';
4
- import { Designer, SimpleEvent } from 'sequential-workflow-designer';
5
-
6
- var Presenter = /** @class */ (function () {
7
- function Presenter() {
8
- }
9
- Presenter.render = function (className, rootRef, element) {
10
- Presenter.tryDestroy(rootRef);
11
- var container = document.createElement('div');
12
- container.className = className;
13
- rootRef.current = ReactDOM.createRoot(container);
14
- rootRef.current.render(element);
15
- return container;
16
- };
17
- Presenter.tryDestroy = function (rootRef) {
18
- if (rootRef.current) {
19
- var oldRoot_1 = rootRef.current;
20
- rootRef.current = null;
21
- setTimeout(function () { return oldRoot_1.unmount(); });
22
- }
23
- };
24
- return Presenter;
25
- }());
26
-
27
- /******************************************************************************
28
- Copyright (c) Microsoft Corporation.
29
-
30
- Permission to use, copy, modify, and/or distribute this software for any
31
- purpose with or without fee is hereby granted.
32
-
33
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
34
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
35
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
36
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
37
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
38
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39
- PERFORMANCE OF THIS SOFTWARE.
40
- ***************************************************************************** */
41
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
42
-
43
-
44
- var __assign = function() {
45
- __assign = Object.assign || function __assign(t) {
46
- for (var s, i = 1, n = arguments.length; i < n; i++) {
47
- s = arguments[i];
48
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
49
- }
50
- return t;
51
- };
52
- return __assign.apply(this, arguments);
53
- };
54
-
55
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
56
- var e = new Error(message);
57
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
58
- };
59
-
60
- if (!window.sqdRootEditorContext) {
61
- window.sqdRootEditorContext = createContext(null);
62
- }
63
- var rootEditorContext = window.sqdRootEditorContext;
64
- function useRootEditor() {
65
- var wrapper = useContext(rootEditorContext);
66
- if (!wrapper) {
67
- throw new Error('Cannot find root editor context');
68
- }
69
- return wrapper;
70
- }
71
- function RootEditorWrapperContext(props) {
72
- var _a = useState(function () { return createWrapper(); }), wrapper = _a[0], setWrapper = _a[1];
73
- function createWrapper() {
74
- return {
75
- properties: props.definition.properties,
76
- definition: props.definition,
77
- isReadonly: props.isReadonly,
78
- setProperty: setProperty
79
- };
80
- }
81
- function forward() {
82
- setWrapper(createWrapper());
83
- }
84
- function setProperty(name, value) {
85
- props.definition.properties[name] = value;
86
- props.context.notifyPropertiesChanged();
87
- forward();
88
- }
89
- return jsx(rootEditorContext.Provider, __assign({ value: wrapper }, { children: props.children }));
90
- }
91
-
92
- if (!window.sqdStepEditorContext) {
93
- window.sqdStepEditorContext = createContext(null);
94
- }
95
- var stepEditorContext = window.sqdStepEditorContext;
96
- function useStepEditor() {
97
- var wrapper = useContext(stepEditorContext);
98
- if (!wrapper) {
99
- throw new Error('Cannot find step editor context');
100
- }
101
- return wrapper;
102
- }
103
- function StepEditorWrapperContext(props) {
104
- var _a = useState(function () { return createWrapper(); }), wrapper = _a[0], setWrapper = _a[1];
105
- function createWrapper() {
106
- return {
107
- id: props.step.id,
108
- type: props.step.type,
109
- componentType: props.step.componentType,
110
- name: props.step.name,
111
- properties: props.step.properties,
112
- step: props.step,
113
- definition: props.definition,
114
- isReadonly: props.isReadonly,
115
- setName: setName,
116
- setProperty: setProperty,
117
- notifyPropertiesChanged: notifyPropertiesChanged,
118
- notifyChildrenChanged: notifyChildrenChanged
119
- };
120
- }
121
- function forward() {
122
- setWrapper(createWrapper());
123
- }
124
- function setName(name) {
125
- props.step.name = name;
126
- notifyNameChanged();
127
- }
128
- function setProperty(name, value) {
129
- props.step.properties[name] = value;
130
- notifyPropertiesChanged();
131
- }
132
- function notifyNameChanged() {
133
- props.context.notifyNameChanged();
134
- forward();
135
- }
136
- function notifyPropertiesChanged() {
137
- props.context.notifyPropertiesChanged();
138
- forward();
139
- }
140
- function notifyChildrenChanged() {
141
- props.context.notifyChildrenChanged();
142
- forward();
143
- }
144
- return jsx(stepEditorContext.Provider, __assign({ value: wrapper }, { children: props.children }));
145
- }
146
-
147
- function wrapDefinition(value, isValid) {
148
- return {
149
- value: value,
150
- isValid: isValid
151
- };
152
- }
153
-
154
- var externalEditorClassName = 'sqd-editor-react';
155
- function SequentialWorkflowDesigner(props) {
156
- var _a = useState(null), root = _a[0], setRoot = _a[1];
157
- var onDefinitionChangeRef = useRef(props.onDefinitionChange);
158
- var onSelectedStepIdChangedRef = useRef(props.onSelectedStepIdChanged);
159
- var onStepUnselectionBlockedRef = useRef(props.onStepUnselectionBlocked);
160
- var onIsEditorCollapsedChangedRef = useRef(props.onIsEditorCollapsedChanged);
161
- var onIsToolboxCollapsedChangedRef = useRef(props.onIsToolboxCollapsedChanged);
162
- var rootEditorRef = useRef(props.rootEditor);
163
- var stepEditorRef = useRef(props.stepEditor);
164
- var controllerRef = useRef(props.controller);
165
- var customActionHandlerRef = useRef(props.customActionHandler);
166
- var designerRef = useRef(null);
167
- var editorRootRef = useRef(null);
168
- var definition = props.definition;
169
- var selectedStepId = props.selectedStepId;
170
- var isReadonly = props.isReadonly;
171
- var theme = props.theme;
172
- var undoStackSize = props.undoStackSize;
173
- var steps = props.stepsConfiguration;
174
- var validator = props.validatorConfiguration;
175
- var placeholder = props.placeholderConfiguration;
176
- var toolbox = props.toolboxConfiguration;
177
- var isEditorCollapsed = props.isEditorCollapsed;
178
- var isToolboxCollapsed = props.isToolboxCollapsed;
179
- var controlBar = props.controlBar;
180
- var contextMenu = props.contextMenu;
181
- var keyboard = props.keyboard;
182
- var preferenceStorage = props.preferenceStorage;
183
- var extensions = props.extensions;
184
- var i18n = props.i18n;
185
- function forwardDefinition() {
186
- if (designerRef.current) {
187
- var wd = wrapDefinition(designerRef.current.getDefinition(), designerRef.current.isValid());
188
- onDefinitionChangeRef.current(wd);
189
- }
190
- }
191
- function rootEditorProvider(def, context, isReadonly) {
192
- if (!rootEditorRef.current) {
193
- throw new Error('Root editor is not provided');
194
- }
195
- if (isValidElement(rootEditorRef.current)) {
196
- return Presenter.render(externalEditorClassName, editorRootRef, jsx(RootEditorWrapperContext, __assign({ definition: def, context: context, isReadonly: isReadonly }, { children: rootEditorRef.current })));
197
- }
198
- return rootEditorRef.current(def, context, isReadonly);
199
- }
200
- function stepEditorProvider(step, context, def, isReadonly) {
201
- if (!stepEditorRef.current) {
202
- throw new Error('Step editor is not provided');
203
- }
204
- if (isValidElement(stepEditorRef.current)) {
205
- return Presenter.render(externalEditorClassName, editorRootRef, jsx(StepEditorWrapperContext, __assign({ step: step, definition: def, context: context, isReadonly: isReadonly }, { children: stepEditorRef.current })));
206
- }
207
- return stepEditorRef.current(step, context, def, isReadonly);
208
- }
209
- function customActionHandler(action, step, sequence, context) {
210
- if (customActionHandlerRef.current) {
211
- customActionHandlerRef.current(action, step, sequence, context);
212
- }
213
- }
214
- function tryDestroy() {
215
- Presenter.tryDestroy(editorRootRef);
216
- if (controllerRef.current) {
217
- controllerRef.current.setDesigner(null);
218
- }
219
- if (designerRef.current) {
220
- designerRef.current.destroy();
221
- designerRef.current = null;
222
- // console.log('sqd: designer destroyed');
223
- }
224
- }
225
- useEffect(function () {
226
- onDefinitionChangeRef.current = props.onDefinitionChange;
227
- }, [props.onDefinitionChange]);
228
- useEffect(function () {
229
- onSelectedStepIdChangedRef.current = props.onSelectedStepIdChanged;
230
- }, [props.onSelectedStepIdChanged]);
231
- useEffect(function () {
232
- onStepUnselectionBlockedRef.current = props.onStepUnselectionBlocked;
233
- }, [props.onStepUnselectionBlocked]);
234
- useEffect(function () {
235
- onIsEditorCollapsedChangedRef.current = props.onIsEditorCollapsedChanged;
236
- }, [props.onIsEditorCollapsedChanged]);
237
- useEffect(function () {
238
- onIsToolboxCollapsedChangedRef.current = props.onIsToolboxCollapsedChanged;
239
- }, [props.onIsToolboxCollapsedChanged]);
240
- useEffect(function () {
241
- rootEditorRef.current = props.rootEditor;
242
- }, [props.rootEditor]);
243
- useEffect(function () {
244
- stepEditorRef.current = props.stepEditor;
245
- }, [props.stepEditor]);
246
- useEffect(function () {
247
- customActionHandlerRef.current = props.customActionHandler;
248
- }, [props.customActionHandler]);
249
- useEffect(function () {
250
- if (!root) {
251
- return;
252
- }
253
- if (designerRef.current) {
254
- var isNotChanged = definition.value === designerRef.current.getDefinition();
255
- if (isNotChanged) {
256
- if (selectedStepId !== undefined && selectedStepId !== designerRef.current.getSelectedStepId()) {
257
- if (selectedStepId) {
258
- designerRef.current.selectStepById(selectedStepId);
259
- }
260
- else {
261
- designerRef.current.clearSelectedStep();
262
- }
263
- // console.log('sqd: selected step updated');
264
- }
265
- if (isReadonly !== undefined && isReadonly !== designerRef.current.isReadonly()) {
266
- designerRef.current.setIsReadonly(isReadonly);
267
- // console.log('sqd: isReadonly updated');
268
- }
269
- if (isToolboxCollapsed !== undefined && isToolboxCollapsed !== designerRef.current.isToolboxCollapsed()) {
270
- designerRef.current.setIsToolboxCollapsed(isToolboxCollapsed);
271
- // console.log('sqd: isToolboxCollapsed updated');
272
- }
273
- if (isEditorCollapsed !== undefined && isEditorCollapsed !== designerRef.current.isEditorCollapsed()) {
274
- designerRef.current.setIsEditorCollapsed(isEditorCollapsed);
275
- // console.log('sqd: isEditorCollapsed updated');
276
- }
277
- return;
278
- }
279
- tryDestroy();
280
- }
281
- var designer = Designer.create(root, definition.value, {
282
- theme: theme,
283
- undoStackSize: undoStackSize,
284
- toolbox: toolbox
285
- ? __assign(__assign({}, toolbox), { isCollapsed: isToolboxCollapsed }) : false,
286
- steps: steps,
287
- validator: validator,
288
- placeholder: placeholder,
289
- controlBar: controlBar,
290
- contextMenu: contextMenu,
291
- keyboard: keyboard,
292
- preferenceStorage: preferenceStorage,
293
- editors: rootEditorRef.current && stepEditorRef.current
294
- ? {
295
- isCollapsed: isEditorCollapsed,
296
- rootEditorProvider: rootEditorProvider,
297
- stepEditorProvider: stepEditorProvider
298
- }
299
- : false,
300
- customActionHandler: customActionHandlerRef.current && customActionHandler,
301
- extensions: extensions,
302
- i18n: i18n,
303
- isReadonly: isReadonly
304
- });
305
- if (controllerRef.current) {
306
- controllerRef.current.setDesigner(designer);
307
- }
308
- if (selectedStepId) {
309
- designer.selectStepById(selectedStepId);
310
- }
311
- // console.log('sqd: designer rendered');
312
- designer.onReady.subscribe(forwardDefinition);
313
- designer.onDefinitionChanged.subscribe(forwardDefinition);
314
- designer.onSelectedStepIdChanged.subscribe(function (stepId) {
315
- if (onSelectedStepIdChangedRef.current) {
316
- onSelectedStepIdChangedRef.current(stepId);
317
- }
318
- });
319
- designer.onStepUnselectionBlocked.subscribe(function (targetStepId) {
320
- if (onStepUnselectionBlockedRef.current) {
321
- onStepUnselectionBlockedRef.current(targetStepId);
322
- }
323
- });
324
- designer.onIsToolboxCollapsedChanged.subscribe(function (isCollapsed) {
325
- if (onIsToolboxCollapsedChangedRef.current) {
326
- onIsToolboxCollapsedChangedRef.current(isCollapsed);
327
- }
328
- });
329
- designer.onIsEditorCollapsedChanged.subscribe(function (isCollapsed) {
330
- if (onIsEditorCollapsedChangedRef.current) {
331
- onIsEditorCollapsedChangedRef.current(isCollapsed);
332
- }
333
- });
334
- designerRef.current = designer;
335
- }, [
336
- root,
337
- definition,
338
- selectedStepId,
339
- isReadonly,
340
- theme,
341
- undoStackSize,
342
- toolbox,
343
- isToolboxCollapsed,
344
- isEditorCollapsed,
345
- contextMenu,
346
- keyboard,
347
- preferenceStorage,
348
- controlBar,
349
- steps,
350
- validator,
351
- placeholder,
352
- extensions,
353
- i18n
354
- ]);
355
- useEffect(function () {
356
- return tryDestroy;
357
- }, []);
358
- return jsx("div", { ref: setRoot, "data-testid": "designer", className: "sqd-designer-react" });
359
- }
360
-
361
- var SequentialWorkflowDesignerController = /** @class */ (function () {
362
- function SequentialWorkflowDesignerController() {
363
- var _this = this;
364
- /**
365
- * @description Event that is raised when the controller is ready to be used.
366
- */
367
- this.onIsReadyChanged = new SimpleEvent();
368
- this.designer = null;
369
- /**
370
- * @description Moves the viewport to the step with the animation.
371
- */
372
- this.moveViewportToStep = function (stepId) {
373
- _this.getDesigner().moveViewportToStep(stepId);
374
- };
375
- /**
376
- * @description Updates all badges.
377
- */
378
- this.updateBadges = function () {
379
- _this.getDesigner().updateBadges();
380
- };
381
- /**
382
- * @description Rerender the root component and all its children.
383
- */
384
- this.updateRootComponent = function () {
385
- _this.getDesigner().updateRootComponent();
386
- };
387
- /**
388
- * @description Updates the layout of the designer.
389
- */
390
- this.updateLayout = function () {
391
- _this.getDesigner().updateLayout();
392
- };
393
- /**
394
- * Replaces the current definition with a new one and adds the previous definition to the undo stack.
395
- * @param definition A new definition.
396
- */
397
- this.replaceDefinition = function (definition) {
398
- return _this.getDesigner().replaceDefinition(definition);
399
- };
400
- // Nothing...
401
- }
402
- SequentialWorkflowDesignerController.create = function () {
403
- return new SequentialWorkflowDesignerController();
404
- };
405
- /**
406
- * @returns `true` if the controller is ready to be used, `false` otherwise.
407
- */
408
- SequentialWorkflowDesignerController.prototype.isReady = function () {
409
- return Boolean(this.designer);
410
- };
411
- SequentialWorkflowDesignerController.prototype.setDesigner = function (designer) {
412
- if (designer && this.designer) {
413
- throw new Error('Designer is already set');
414
- }
415
- this.designer = designer;
416
- this.onIsReadyChanged.forward();
417
- };
418
- SequentialWorkflowDesignerController.prototype.getDesigner = function () {
419
- if (!this.designer) {
420
- throw new Error('Designer is not ready yet');
421
- }
422
- return this.designer;
423
- };
424
- return SequentialWorkflowDesignerController;
425
- }());
426
- function useSequentialWorkflowDesignerController(deps) {
427
- return useMemo(function () { return SequentialWorkflowDesignerController.create(); }, deps || []);
428
- }
429
-
430
- export { Presenter, RootEditorWrapperContext, SequentialWorkflowDesigner, SequentialWorkflowDesignerController, StepEditorWrapperContext, useRootEditor, useSequentialWorkflowDesignerController, useStepEditor, wrapDefinition };
package/lib/index.d.ts DELETED
@@ -1,139 +0,0 @@
1
- /// <reference types="react" />
2
- import { MutableRefObject, Context, ReactNode, DependencyList } from 'react';
3
- import ReactDOM from 'react-dom/client';
4
- import { Definition, RootEditorContext, SimpleEvent, Designer, ToolboxConfiguration, RootEditorProvider, StepEditorProvider, StepsConfiguration, ValidatorConfiguration, PlaceholderConfiguration, KeyboardConfiguration, PreferenceStorage, CustomActionHandler, DesignerExtension, I18n, Step, StepEditorContext } from 'sequential-workflow-designer';
5
-
6
- declare class Presenter {
7
- static render(className: string, rootRef: MutableRefObject<ReactDOM.Root | null>, element: JSX.Element): HTMLElement;
8
- static tryDestroy(rootRef: MutableRefObject<ReactDOM.Root | null>): void;
9
- }
10
-
11
- declare global {
12
- interface Window {
13
- sqdRootEditorContext?: Context<RootEditorWrapper<Definition> | null>;
14
- }
15
- }
16
- interface RootEditorWrapper<TDefinition extends Definition> {
17
- readonly properties: TDefinition['properties'];
18
- readonly definition: TDefinition;
19
- readonly isReadonly: boolean;
20
- setProperty(name: keyof TDefinition['properties'], value: TDefinition['properties'][typeof name]): void;
21
- }
22
- declare function useRootEditor<TDefinition extends Definition = Definition>(): RootEditorWrapper<TDefinition>;
23
- interface RootEditorWrapperContextProps {
24
- children: ReactNode;
25
- definition: Definition;
26
- context: RootEditorContext;
27
- isReadonly: boolean;
28
- }
29
- declare function RootEditorWrapperContext(props: RootEditorWrapperContextProps): JSX.Element;
30
-
31
- interface WrappedDefinition<TDefinition extends Definition = Definition> {
32
- readonly value: TDefinition;
33
- readonly isValid: boolean | undefined;
34
- }
35
- declare function wrapDefinition<TDefinition extends Definition = Definition>(value: TDefinition, isValid?: boolean): WrappedDefinition<TDefinition>;
36
-
37
- declare class SequentialWorkflowDesignerController {
38
- static create(): SequentialWorkflowDesignerController;
39
- /**
40
- * @description Event that is raised when the controller is ready to be used.
41
- */
42
- readonly onIsReadyChanged: SimpleEvent<void>;
43
- private designer;
44
- private constructor();
45
- /**
46
- * @description Moves the viewport to the step with the animation.
47
- */
48
- readonly moveViewportToStep: (stepId: string) => void;
49
- /**
50
- * @description Updates all badges.
51
- */
52
- readonly updateBadges: () => void;
53
- /**
54
- * @description Rerender the root component and all its children.
55
- */
56
- readonly updateRootComponent: () => void;
57
- /**
58
- * @description Updates the layout of the designer.
59
- */
60
- readonly updateLayout: () => void;
61
- /**
62
- * Replaces the current definition with a new one and adds the previous definition to the undo stack.
63
- * @param definition A new definition.
64
- */
65
- readonly replaceDefinition: (definition: Definition) => Promise<void>;
66
- /**
67
- * @returns `true` if the controller is ready to be used, `false` otherwise.
68
- */
69
- isReady(): boolean;
70
- setDesigner(designer: Designer | null): void;
71
- private getDesigner;
72
- }
73
- declare function useSequentialWorkflowDesignerController(deps?: DependencyList): SequentialWorkflowDesignerController;
74
-
75
- type ReactToolboxConfiguration = Omit<ToolboxConfiguration, 'isCollapsed'>;
76
- interface SequentialWorkflowDesignerProps<TDefinition extends Definition> {
77
- definition: WrappedDefinition<TDefinition>;
78
- onDefinitionChange: (state: WrappedDefinition<TDefinition>) => void;
79
- selectedStepId?: string | null;
80
- onSelectedStepIdChanged?: (stepId: string | null) => void;
81
- onStepUnselectionBlocked?: (targetStepId: string | null) => void;
82
- isReadonly?: boolean;
83
- rootEditor: false | JSX.Element | RootEditorProvider;
84
- stepEditor: false | JSX.Element | StepEditorProvider;
85
- isEditorCollapsed?: boolean;
86
- onIsEditorCollapsedChanged?: (isCollapsed: boolean) => void;
87
- theme?: string;
88
- undoStackSize?: number;
89
- stepsConfiguration: StepsConfiguration;
90
- validatorConfiguration?: ValidatorConfiguration;
91
- placeholderConfiguration?: PlaceholderConfiguration;
92
- toolboxConfiguration: false | ReactToolboxConfiguration;
93
- isToolboxCollapsed?: boolean;
94
- onIsToolboxCollapsedChanged?: (isCollapsed: boolean) => void;
95
- /**
96
- * @description If true, the control bar will be displayed.
97
- */
98
- controlBar: boolean;
99
- contextMenu?: boolean;
100
- keyboard?: boolean | KeyboardConfiguration;
101
- preferenceStorage?: PreferenceStorage;
102
- controller?: SequentialWorkflowDesignerController;
103
- customActionHandler?: CustomActionHandler;
104
- extensions?: DesignerExtension[];
105
- i18n?: I18n;
106
- }
107
- declare function SequentialWorkflowDesigner<TDefinition extends Definition>(props: SequentialWorkflowDesignerProps<TDefinition>): JSX.Element;
108
-
109
- declare global {
110
- interface Window {
111
- sqdStepEditorContext?: Context<StepEditorWrapper | null>;
112
- }
113
- }
114
- interface StepEditorWrapper<TStep extends Step = Step, TDefinition extends Definition = Definition> {
115
- readonly id: string;
116
- readonly type: TStep['type'];
117
- readonly componentType: TStep['componentType'];
118
- readonly name: string;
119
- readonly properties: TStep['properties'];
120
- readonly step: TStep;
121
- readonly definition: TDefinition;
122
- readonly isReadonly: boolean;
123
- setName(name: string): void;
124
- setProperty(name: keyof TStep['properties'], value: TStep['properties'][typeof name]): void;
125
- notifyPropertiesChanged(): void;
126
- notifyChildrenChanged(): void;
127
- }
128
- declare function useStepEditor<TStep extends Step = Step, TDefinition extends Definition = Definition>(): StepEditorWrapper<TStep, TDefinition>;
129
- interface StepEditorWrapperContextProps {
130
- children: ReactNode;
131
- step: Step;
132
- definition: Definition;
133
- context: StepEditorContext;
134
- isReadonly: boolean;
135
- }
136
- declare function StepEditorWrapperContext(props: StepEditorWrapperContextProps): JSX.Element;
137
-
138
- export { Presenter, RootEditorWrapperContext, SequentialWorkflowDesigner, SequentialWorkflowDesignerController, StepEditorWrapperContext, useRootEditor, useSequentialWorkflowDesignerController, useStepEditor, wrapDefinition };
139
- export type { ReactToolboxConfiguration, RootEditorWrapper, RootEditorWrapperContextProps, SequentialWorkflowDesignerProps, StepEditorWrapper, StepEditorWrapperContextProps, WrappedDefinition };