sequential-workflow-designer-react 0.9.2 → 0.10.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/lib/cjs/index.cjs +75 -11
- package/lib/esm/index.js +75 -13
- package/lib/index.d.ts +26 -3
- package/package.json +3 -3
package/lib/cjs/index.cjs
CHANGED
|
@@ -149,6 +149,8 @@ function SequentialWorkflowDesigner(props) {
|
|
|
149
149
|
var onSelectedStepIdChangedRef = react.useRef(props.onSelectedStepIdChanged);
|
|
150
150
|
var globalEditorRef = react.useRef(props.globalEditor);
|
|
151
151
|
var stepEditorRef = react.useRef(props.stepEditor);
|
|
152
|
+
var controllerRef = react.useRef(props.controller);
|
|
153
|
+
var customActionHandlerRef = react.useRef(props.customActionHandler);
|
|
152
154
|
var designerRef = react.useRef(null);
|
|
153
155
|
var editorRootRef = react.useRef(null);
|
|
154
156
|
var definition = props.definition;
|
|
@@ -181,6 +183,22 @@ function SequentialWorkflowDesigner(props) {
|
|
|
181
183
|
}
|
|
182
184
|
return Presenter.render(externalEditorClassName, editorRootRef, jsxRuntime.jsx(StepEditorWrapperContext, __assign({ step: step, context: context }, { children: stepEditorRef.current })));
|
|
183
185
|
}
|
|
186
|
+
function customActionHandler(action, step) {
|
|
187
|
+
if (customActionHandlerRef.current) {
|
|
188
|
+
customActionHandlerRef.current(action, step);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function tryDestroy() {
|
|
192
|
+
Presenter.tryDestroy(editorRootRef);
|
|
193
|
+
if (controllerRef.current) {
|
|
194
|
+
controllerRef.current.setDesigner(null);
|
|
195
|
+
}
|
|
196
|
+
if (designerRef.current) {
|
|
197
|
+
designerRef.current.destroy();
|
|
198
|
+
designerRef.current = null;
|
|
199
|
+
// console.log('sqd: designer destroyed');
|
|
200
|
+
}
|
|
201
|
+
}
|
|
184
202
|
react.useEffect(function () {
|
|
185
203
|
onDefinitionChangeRef.current = props.onDefinitionChange;
|
|
186
204
|
}, [props.onDefinitionChange]);
|
|
@@ -193,6 +211,9 @@ function SequentialWorkflowDesigner(props) {
|
|
|
193
211
|
react.useEffect(function () {
|
|
194
212
|
stepEditorRef.current = props.stepEditor;
|
|
195
213
|
}, [props.stepEditor]);
|
|
214
|
+
react.useEffect(function () {
|
|
215
|
+
customActionHandlerRef.current = props.customActionHandler;
|
|
216
|
+
}, [props.customActionHandler]);
|
|
196
217
|
react.useEffect(function () {
|
|
197
218
|
if (!placeholder) {
|
|
198
219
|
return;
|
|
@@ -215,8 +236,7 @@ function SequentialWorkflowDesigner(props) {
|
|
|
215
236
|
}
|
|
216
237
|
return;
|
|
217
238
|
}
|
|
218
|
-
|
|
219
|
-
designerRef.current = null;
|
|
239
|
+
tryDestroy();
|
|
220
240
|
}
|
|
221
241
|
var designer = sequentialWorkflowDesigner.Designer.create(placeholder, definition.value, {
|
|
222
242
|
theme: theme,
|
|
@@ -230,8 +250,12 @@ function SequentialWorkflowDesigner(props) {
|
|
|
230
250
|
stepEditorProvider: stepEditorProvider
|
|
231
251
|
}
|
|
232
252
|
: false,
|
|
253
|
+
customActionHandler: customActionHandlerRef.current && customActionHandler,
|
|
233
254
|
extensions: extensions
|
|
234
255
|
});
|
|
256
|
+
if (controllerRef.current) {
|
|
257
|
+
controllerRef.current.setDesigner(designer);
|
|
258
|
+
}
|
|
235
259
|
if (selectedStepId) {
|
|
236
260
|
designer.selectStepById(selectedStepId);
|
|
237
261
|
}
|
|
@@ -249,22 +273,62 @@ function SequentialWorkflowDesigner(props) {
|
|
|
249
273
|
designerRef.current = designer;
|
|
250
274
|
}, [placeholder, definition, selectedStepId, isReadonly, theme, undoStackSize, toolbox, controlBar, steps, extensions]);
|
|
251
275
|
react.useEffect(function () {
|
|
252
|
-
return
|
|
253
|
-
Presenter.tryDestroy(editorRootRef);
|
|
254
|
-
if (designerRef.current) {
|
|
255
|
-
designerRef.current.destroy();
|
|
256
|
-
designerRef.current = null;
|
|
257
|
-
// console.log('sqd: designer destroyed');
|
|
258
|
-
}
|
|
259
|
-
};
|
|
276
|
+
return tryDestroy;
|
|
260
277
|
}, []);
|
|
261
|
-
return jsxRuntime.jsx("div", { ref: setPlaceholder, className: "sqd-designer-react" });
|
|
278
|
+
return jsxRuntime.jsx("div", { ref: setPlaceholder, "data-testid": "designer", className: "sqd-designer-react" });
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
var SequentialWorkflowDesignerController = /** @class */ (function () {
|
|
282
|
+
function SequentialWorkflowDesignerController() {
|
|
283
|
+
var _this = this;
|
|
284
|
+
this.designer = null;
|
|
285
|
+
/**
|
|
286
|
+
* @description Moves the viewport to the step with the animation.
|
|
287
|
+
*/
|
|
288
|
+
this.moveViewportToStep = function (stepId) {
|
|
289
|
+
_this.getDesigner().moveViewportToStep(stepId);
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* @description Updates all badges.
|
|
293
|
+
*/
|
|
294
|
+
this.updateBadges = function () {
|
|
295
|
+
_this.getDesigner().updateBadges();
|
|
296
|
+
};
|
|
297
|
+
// Nothing...
|
|
298
|
+
}
|
|
299
|
+
SequentialWorkflowDesignerController.create = function () {
|
|
300
|
+
return new SequentialWorkflowDesignerController();
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* @returns `true` if the controller is ready to be used, `false` otherwise.
|
|
304
|
+
*/
|
|
305
|
+
SequentialWorkflowDesignerController.prototype.isReady = function () {
|
|
306
|
+
return !!this.designer;
|
|
307
|
+
};
|
|
308
|
+
SequentialWorkflowDesignerController.prototype.setDesigner = function (designer) {
|
|
309
|
+
if (designer && this.designer) {
|
|
310
|
+
throw new Error('Designer is already set');
|
|
311
|
+
}
|
|
312
|
+
this.designer = designer;
|
|
313
|
+
};
|
|
314
|
+
SequentialWorkflowDesignerController.prototype.getDesigner = function () {
|
|
315
|
+
if (!this.designer) {
|
|
316
|
+
throw new Error('Designer is not ready yet');
|
|
317
|
+
}
|
|
318
|
+
return this.designer;
|
|
319
|
+
};
|
|
320
|
+
return SequentialWorkflowDesignerController;
|
|
321
|
+
}());
|
|
322
|
+
function useSequentialWorkflowDesignerController(deps) {
|
|
323
|
+
return react.useMemo(function () { return SequentialWorkflowDesignerController.create(); }, deps || []);
|
|
262
324
|
}
|
|
263
325
|
|
|
264
326
|
exports.GlobalEditorWrapperContext = GlobalEditorWrapperContext;
|
|
265
327
|
exports.Presenter = Presenter;
|
|
266
328
|
exports.SequentialWorkflowDesigner = SequentialWorkflowDesigner;
|
|
329
|
+
exports.SequentialWorkflowDesignerController = SequentialWorkflowDesignerController;
|
|
267
330
|
exports.StepEditorWrapperContext = StepEditorWrapperContext;
|
|
268
331
|
exports.useGlobalEditor = useGlobalEditor;
|
|
332
|
+
exports.useSequentialWorkflowDesignerController = useSequentialWorkflowDesignerController;
|
|
269
333
|
exports.useStepEditor = useStepEditor;
|
|
270
334
|
exports.wrapDefinition = wrapDefinition;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ReactDOM from 'react-dom/client';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { createContext, useContext, useState, useRef, useEffect } from 'react';
|
|
3
|
+
import { createContext, useContext, useState, useRef, useEffect, useMemo } from 'react';
|
|
4
4
|
import { Designer } from 'sequential-workflow-designer';
|
|
5
5
|
|
|
6
6
|
var Presenter = /** @class */ (function () {
|
|
@@ -147,6 +147,8 @@ function SequentialWorkflowDesigner(props) {
|
|
|
147
147
|
var onSelectedStepIdChangedRef = useRef(props.onSelectedStepIdChanged);
|
|
148
148
|
var globalEditorRef = useRef(props.globalEditor);
|
|
149
149
|
var stepEditorRef = useRef(props.stepEditor);
|
|
150
|
+
var controllerRef = useRef(props.controller);
|
|
151
|
+
var customActionHandlerRef = useRef(props.customActionHandler);
|
|
150
152
|
var designerRef = useRef(null);
|
|
151
153
|
var editorRootRef = useRef(null);
|
|
152
154
|
var definition = props.definition;
|
|
@@ -179,6 +181,22 @@ function SequentialWorkflowDesigner(props) {
|
|
|
179
181
|
}
|
|
180
182
|
return Presenter.render(externalEditorClassName, editorRootRef, jsx(StepEditorWrapperContext, __assign({ step: step, context: context }, { children: stepEditorRef.current })));
|
|
181
183
|
}
|
|
184
|
+
function customActionHandler(action, step) {
|
|
185
|
+
if (customActionHandlerRef.current) {
|
|
186
|
+
customActionHandlerRef.current(action, step);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function tryDestroy() {
|
|
190
|
+
Presenter.tryDestroy(editorRootRef);
|
|
191
|
+
if (controllerRef.current) {
|
|
192
|
+
controllerRef.current.setDesigner(null);
|
|
193
|
+
}
|
|
194
|
+
if (designerRef.current) {
|
|
195
|
+
designerRef.current.destroy();
|
|
196
|
+
designerRef.current = null;
|
|
197
|
+
// console.log('sqd: designer destroyed');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
182
200
|
useEffect(function () {
|
|
183
201
|
onDefinitionChangeRef.current = props.onDefinitionChange;
|
|
184
202
|
}, [props.onDefinitionChange]);
|
|
@@ -191,6 +209,9 @@ function SequentialWorkflowDesigner(props) {
|
|
|
191
209
|
useEffect(function () {
|
|
192
210
|
stepEditorRef.current = props.stepEditor;
|
|
193
211
|
}, [props.stepEditor]);
|
|
212
|
+
useEffect(function () {
|
|
213
|
+
customActionHandlerRef.current = props.customActionHandler;
|
|
214
|
+
}, [props.customActionHandler]);
|
|
194
215
|
useEffect(function () {
|
|
195
216
|
if (!placeholder) {
|
|
196
217
|
return;
|
|
@@ -213,8 +234,7 @@ function SequentialWorkflowDesigner(props) {
|
|
|
213
234
|
}
|
|
214
235
|
return;
|
|
215
236
|
}
|
|
216
|
-
|
|
217
|
-
designerRef.current = null;
|
|
237
|
+
tryDestroy();
|
|
218
238
|
}
|
|
219
239
|
var designer = Designer.create(placeholder, definition.value, {
|
|
220
240
|
theme: theme,
|
|
@@ -228,8 +248,12 @@ function SequentialWorkflowDesigner(props) {
|
|
|
228
248
|
stepEditorProvider: stepEditorProvider
|
|
229
249
|
}
|
|
230
250
|
: false,
|
|
251
|
+
customActionHandler: customActionHandlerRef.current && customActionHandler,
|
|
231
252
|
extensions: extensions
|
|
232
253
|
});
|
|
254
|
+
if (controllerRef.current) {
|
|
255
|
+
controllerRef.current.setDesigner(designer);
|
|
256
|
+
}
|
|
233
257
|
if (selectedStepId) {
|
|
234
258
|
designer.selectStepById(selectedStepId);
|
|
235
259
|
}
|
|
@@ -247,16 +271,54 @@ function SequentialWorkflowDesigner(props) {
|
|
|
247
271
|
designerRef.current = designer;
|
|
248
272
|
}, [placeholder, definition, selectedStepId, isReadonly, theme, undoStackSize, toolbox, controlBar, steps, extensions]);
|
|
249
273
|
useEffect(function () {
|
|
250
|
-
return
|
|
251
|
-
Presenter.tryDestroy(editorRootRef);
|
|
252
|
-
if (designerRef.current) {
|
|
253
|
-
designerRef.current.destroy();
|
|
254
|
-
designerRef.current = null;
|
|
255
|
-
// console.log('sqd: designer destroyed');
|
|
256
|
-
}
|
|
257
|
-
};
|
|
274
|
+
return tryDestroy;
|
|
258
275
|
}, []);
|
|
259
|
-
return jsx("div", { ref: setPlaceholder, className: "sqd-designer-react" });
|
|
276
|
+
return jsx("div", { ref: setPlaceholder, "data-testid": "designer", className: "sqd-designer-react" });
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
var SequentialWorkflowDesignerController = /** @class */ (function () {
|
|
280
|
+
function SequentialWorkflowDesignerController() {
|
|
281
|
+
var _this = this;
|
|
282
|
+
this.designer = null;
|
|
283
|
+
/**
|
|
284
|
+
* @description Moves the viewport to the step with the animation.
|
|
285
|
+
*/
|
|
286
|
+
this.moveViewportToStep = function (stepId) {
|
|
287
|
+
_this.getDesigner().moveViewportToStep(stepId);
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* @description Updates all badges.
|
|
291
|
+
*/
|
|
292
|
+
this.updateBadges = function () {
|
|
293
|
+
_this.getDesigner().updateBadges();
|
|
294
|
+
};
|
|
295
|
+
// Nothing...
|
|
296
|
+
}
|
|
297
|
+
SequentialWorkflowDesignerController.create = function () {
|
|
298
|
+
return new SequentialWorkflowDesignerController();
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* @returns `true` if the controller is ready to be used, `false` otherwise.
|
|
302
|
+
*/
|
|
303
|
+
SequentialWorkflowDesignerController.prototype.isReady = function () {
|
|
304
|
+
return !!this.designer;
|
|
305
|
+
};
|
|
306
|
+
SequentialWorkflowDesignerController.prototype.setDesigner = function (designer) {
|
|
307
|
+
if (designer && this.designer) {
|
|
308
|
+
throw new Error('Designer is already set');
|
|
309
|
+
}
|
|
310
|
+
this.designer = designer;
|
|
311
|
+
};
|
|
312
|
+
SequentialWorkflowDesignerController.prototype.getDesigner = function () {
|
|
313
|
+
if (!this.designer) {
|
|
314
|
+
throw new Error('Designer is not ready yet');
|
|
315
|
+
}
|
|
316
|
+
return this.designer;
|
|
317
|
+
};
|
|
318
|
+
return SequentialWorkflowDesignerController;
|
|
319
|
+
}());
|
|
320
|
+
function useSequentialWorkflowDesignerController(deps) {
|
|
321
|
+
return useMemo(function () { return SequentialWorkflowDesignerController.create(); }, deps || []);
|
|
260
322
|
}
|
|
261
323
|
|
|
262
|
-
export { GlobalEditorWrapperContext, Presenter, SequentialWorkflowDesigner, StepEditorWrapperContext, useGlobalEditor, useStepEditor, wrapDefinition };
|
|
324
|
+
export { GlobalEditorWrapperContext, Presenter, SequentialWorkflowDesigner, SequentialWorkflowDesignerController, StepEditorWrapperContext, useGlobalEditor, useSequentialWorkflowDesignerController, useStepEditor, wrapDefinition };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { MutableRefObject, Context } from 'react';
|
|
2
|
+
import { MutableRefObject, Context, DependencyList } from 'react';
|
|
3
3
|
import ReactDOM from 'react-dom/client';
|
|
4
|
-
import { Definition, GlobalEditorContext, StepsConfiguration, ToolboxConfiguration, DesignerExtension, Step, StepEditorContext } from 'sequential-workflow-designer';
|
|
4
|
+
import { Definition, GlobalEditorContext, Designer, StepsConfiguration, ToolboxConfiguration, CustomActionHandler, DesignerExtension, Step, StepEditorContext } from 'sequential-workflow-designer';
|
|
5
5
|
|
|
6
6
|
declare class Presenter {
|
|
7
7
|
static render(className: string, rootRef: MutableRefObject<ReactDOM.Root | null>, element: JSX.Element): HTMLElement;
|
|
@@ -30,6 +30,27 @@ interface WrappedDefinition<TDefinition extends Definition = Definition> {
|
|
|
30
30
|
}
|
|
31
31
|
declare function wrapDefinition<TDefinition extends Definition = Definition>(value: TDefinition, isValid?: boolean): WrappedDefinition<TDefinition>;
|
|
32
32
|
|
|
33
|
+
declare class SequentialWorkflowDesignerController {
|
|
34
|
+
static create(): SequentialWorkflowDesignerController;
|
|
35
|
+
private designer;
|
|
36
|
+
private constructor();
|
|
37
|
+
/**
|
|
38
|
+
* @description Moves the viewport to the step with the animation.
|
|
39
|
+
*/
|
|
40
|
+
readonly moveViewportToStep: (stepId: string) => void;
|
|
41
|
+
/**
|
|
42
|
+
* @description Updates all badges.
|
|
43
|
+
*/
|
|
44
|
+
readonly updateBadges: () => void;
|
|
45
|
+
/**
|
|
46
|
+
* @returns `true` if the controller is ready to be used, `false` otherwise.
|
|
47
|
+
*/
|
|
48
|
+
isReady(): boolean;
|
|
49
|
+
setDesigner(designer: Designer | null): void;
|
|
50
|
+
private getDesigner;
|
|
51
|
+
}
|
|
52
|
+
declare function useSequentialWorkflowDesignerController(deps?: DependencyList): SequentialWorkflowDesignerController;
|
|
53
|
+
|
|
33
54
|
interface SequentialWorkflowDesignerProps<TDefinition extends Definition> {
|
|
34
55
|
definition: WrappedDefinition<TDefinition>;
|
|
35
56
|
onDefinitionChange: (state: WrappedDefinition<TDefinition>) => void;
|
|
@@ -46,6 +67,8 @@ interface SequentialWorkflowDesignerProps<TDefinition extends Definition> {
|
|
|
46
67
|
* @description If true, the control bar will be displayed.
|
|
47
68
|
*/
|
|
48
69
|
controlBar: boolean;
|
|
70
|
+
controller?: SequentialWorkflowDesignerController;
|
|
71
|
+
customActionHandler?: CustomActionHandler;
|
|
49
72
|
extensions?: DesignerExtension[];
|
|
50
73
|
}
|
|
51
74
|
declare function SequentialWorkflowDesigner<TDefinition extends Definition>(props: SequentialWorkflowDesignerProps<TDefinition>): JSX.Element;
|
|
@@ -74,4 +97,4 @@ declare function StepEditorWrapperContext(props: {
|
|
|
74
97
|
context: StepEditorContext;
|
|
75
98
|
}): JSX.Element;
|
|
76
99
|
|
|
77
|
-
export { GlobalEditorWrapper, GlobalEditorWrapperContext, Presenter, SequentialWorkflowDesigner, SequentialWorkflowDesignerProps, StepEditorWrapper, StepEditorWrapperContext, WrappedDefinition, useGlobalEditor, useStepEditor, wrapDefinition };
|
|
100
|
+
export { GlobalEditorWrapper, GlobalEditorWrapperContext, Presenter, SequentialWorkflowDesigner, SequentialWorkflowDesignerController, SequentialWorkflowDesignerProps, StepEditorWrapper, StepEditorWrapperContext, WrappedDefinition, useGlobalEditor, useSequentialWorkflowDesignerController, useStepEditor, wrapDefinition };
|
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.
|
|
4
|
+
"version": "0.10.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.
|
|
50
|
+
"sequential-workflow-designer": "^0.10.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"prettier": "^2.8.2",
|
|
64
64
|
"react": "^18.2.0",
|
|
65
65
|
"react-dom": "^18.2.0",
|
|
66
|
-
"sequential-workflow-designer": "^0.
|
|
66
|
+
"sequential-workflow-designer": "^0.10.0",
|
|
67
67
|
"rollup": "^3.18.0",
|
|
68
68
|
"rollup-plugin-dts": "^5.2.0",
|
|
69
69
|
"rollup-plugin-typescript2": "^0.34.1",
|