sequential-workflow-designer-react 0.8.1 → 0.9.1

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/README.md CHANGED
@@ -101,13 +101,26 @@ At the end attach the designer.
101
101
  <SequentialWorkflowDesigner
102
102
  definition={definition}
103
103
  onDefinitionChange={setDefinition}
104
- toolboxConfiguration={toolboxConfiguration}
105
104
  stepsConfiguration={stepsConfiguration}
105
+ toolboxConfiguration={toolboxConfiguration}
106
+ controlBar={true}
106
107
  globalEditor={<GlobalEditor />}
107
108
  stepEditor={<StepEditor />}>
108
109
  />
109
110
  ```
110
111
 
112
+ You can hide any UI component.
113
+
114
+ ```tsx
115
+ <SequentialWorkflowDesigner
116
+ // ...
117
+ toolboxConfiguration={false}
118
+ controlBar={false}
119
+ globalEditor={false}
120
+ stepEditor={false}>
121
+ />
122
+ ```
123
+
111
124
  Check the [demo project](https://github.com/nocode-js/sequential-workflow-designer/tree/main/demos/react-app).
112
125
 
113
126
  ## 💡 License
package/lib/cjs/index.cjs CHANGED
@@ -1,10 +1,31 @@
1
1
  'use strict';
2
2
 
3
+ var ReactDOM = require('react-dom/client');
3
4
  var jsxRuntime = require('react/jsx-runtime');
4
5
  var react = require('react');
5
- var ReactDOM = require('react-dom/client');
6
6
  var sequentialWorkflowDesigner = require('sequential-workflow-designer');
7
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
+
8
29
  /******************************************************************************
9
30
  Copyright (c) Microsoft Corporation.
10
31
 
@@ -31,9 +52,12 @@ var __assign = function() {
31
52
  return __assign.apply(this, arguments);
32
53
  };
33
54
 
34
- var globalEditorWrapperContext$1 = react.createContext(null);
55
+ if (!window.sqdGlobalEditorContext) {
56
+ window.sqdGlobalEditorContext = react.createContext(null);
57
+ }
58
+ var globalEditorContext = window.sqdGlobalEditorContext;
35
59
  function useGlobalEditor() {
36
- var wrapper = react.useContext(globalEditorWrapperContext$1);
60
+ var wrapper = react.useContext(globalEditorContext);
37
61
  if (!wrapper) {
38
62
  throw new Error('Cannot find global editor context');
39
63
  }
@@ -55,12 +79,15 @@ function GlobalEditorWrapperContext(props) {
55
79
  props.context.notifyPropertiesChanged();
56
80
  forward();
57
81
  }
58
- return jsxRuntime.jsx(globalEditorWrapperContext$1.Provider, __assign({ value: wrapper }, { children: props.children }));
82
+ return jsxRuntime.jsx(globalEditorContext.Provider, __assign({ value: wrapper }, { children: props.children }));
59
83
  }
60
84
 
61
- var globalEditorWrapperContext = react.createContext(null);
85
+ if (!window.sqdStepEditorContext) {
86
+ window.sqdStepEditorContext = react.createContext(null);
87
+ }
88
+ var stepEditorContext = window.sqdStepEditorContext;
62
89
  function useStepEditor() {
63
- var wrapper = react.useContext(globalEditorWrapperContext);
90
+ var wrapper = react.useContext(stepEditorContext);
64
91
  if (!wrapper) {
65
92
  throw new Error('Cannot find step editor context');
66
93
  }
@@ -105,7 +132,7 @@ function StepEditorWrapperContext(props) {
105
132
  props.context.notifyChildrenChanged();
106
133
  forward();
107
134
  }
108
- return jsxRuntime.jsx(globalEditorWrapperContext.Provider, __assign({ value: wrapper }, { children: props.children }));
135
+ return jsxRuntime.jsx(stepEditorContext.Provider, __assign({ value: wrapper }, { children: props.children }));
109
136
  }
110
137
 
111
138
  function wrapDefinition(value, isValid) {
@@ -115,6 +142,7 @@ function wrapDefinition(value, isValid) {
115
142
  };
116
143
  }
117
144
 
145
+ var externalEditorClassName = 'sqd-editor-react';
118
146
  function SequentialWorkflowDesigner(props) {
119
147
  var _a = react.useState(null), placeholder = _a[0], setPlaceholder = _a[1];
120
148
  var onDefinitionChangeRef = react.useRef(props.onDefinitionChange);
@@ -128,9 +156,13 @@ function SequentialWorkflowDesigner(props) {
128
156
  var isReadonly = props.isReadonly;
129
157
  var theme = props.theme;
130
158
  var undoStackSize = props.undoStackSize;
131
- var stepsConfiguration = props.stepsConfiguration;
132
- var toolboxConfiguration = props.toolboxConfiguration;
159
+ var steps = props.stepsConfiguration;
160
+ var toolbox = props.toolboxConfiguration;
161
+ var controlBar = props.controlBar;
133
162
  var extensions = props.extensions;
163
+ if (props.controlBar === undefined) {
164
+ throw new Error('The "controlBar" property is not set');
165
+ }
134
166
  function forwardDefinition() {
135
167
  if (designerRef.current) {
136
168
  var def = wrapDefinition(designerRef.current.getDefinition(), designerRef.current.isValid());
@@ -138,10 +170,16 @@ function SequentialWorkflowDesigner(props) {
138
170
  }
139
171
  }
140
172
  function globalEditorProvider(def, context) {
141
- return editorProvider(editorRootRef, jsxRuntime.jsx(GlobalEditorWrapperContext, __assign({ definition: def, context: context }, { children: globalEditorRef.current })));
173
+ if (!globalEditorRef.current) {
174
+ throw new Error('Global editor is not provided');
175
+ }
176
+ return Presenter.render(externalEditorClassName, editorRootRef, jsxRuntime.jsx(GlobalEditorWrapperContext, __assign({ definition: def, context: context }, { children: globalEditorRef.current })));
142
177
  }
143
178
  function stepEditorProvider(step, context) {
144
- return editorProvider(editorRootRef, jsxRuntime.jsx(StepEditorWrapperContext, __assign({ step: step, context: context }, { children: stepEditorRef.current })));
179
+ if (!stepEditorRef.current) {
180
+ throw new Error('Step editor is not provided');
181
+ }
182
+ return Presenter.render(externalEditorClassName, editorRootRef, jsxRuntime.jsx(StepEditorWrapperContext, __assign({ step: step, context: context }, { children: stepEditorRef.current })));
145
183
  }
146
184
  react.useEffect(function () {
147
185
  onDefinitionChangeRef.current = props.onDefinitionChange;
@@ -183,13 +221,15 @@ function SequentialWorkflowDesigner(props) {
183
221
  var designer = sequentialWorkflowDesigner.Designer.create(placeholder, definition.value, {
184
222
  theme: theme,
185
223
  undoStackSize: undoStackSize,
186
- toolbox: toolboxConfiguration,
187
- steps: stepsConfiguration,
188
- editors: {
189
- isHidden: false,
190
- globalEditorProvider: globalEditorProvider,
191
- stepEditorProvider: stepEditorProvider
192
- },
224
+ toolbox: toolbox,
225
+ steps: steps,
226
+ controlBar: controlBar,
227
+ editors: globalEditorRef.current && stepEditorRef.current
228
+ ? {
229
+ globalEditorProvider: globalEditorProvider,
230
+ stepEditorProvider: stepEditorProvider
231
+ }
232
+ : false,
193
233
  extensions: extensions
194
234
  });
195
235
  if (selectedStepId) {
@@ -207,14 +247,10 @@ function SequentialWorkflowDesigner(props) {
207
247
  }
208
248
  });
209
249
  designerRef.current = designer;
210
- }, [placeholder, definition, selectedStepId, isReadonly, theme, undoStackSize, toolboxConfiguration, stepsConfiguration, extensions]);
250
+ }, [placeholder, definition, selectedStepId, isReadonly, theme, undoStackSize, toolbox, controlBar, steps, extensions]);
211
251
  react.useEffect(function () {
212
252
  return function () {
213
- if (editorRootRef.current) {
214
- var oldRoot_1 = editorRootRef.current;
215
- editorRootRef.current = null;
216
- setTimeout(function () { return oldRoot_1.unmount(); });
217
- }
253
+ Presenter.tryDestroy(editorRootRef);
218
254
  if (designerRef.current) {
219
255
  designerRef.current.destroy();
220
256
  designerRef.current = null;
@@ -223,21 +259,10 @@ function SequentialWorkflowDesigner(props) {
223
259
  };
224
260
  }, []);
225
261
  return jsxRuntime.jsx("div", { ref: setPlaceholder, className: "sqd-designer-react" });
226
- }
227
- function editorProvider(rootRef, element) {
228
- if (rootRef.current) {
229
- var oldRoot_2 = rootRef.current;
230
- rootRef.current = null;
231
- setTimeout(function () { return oldRoot_2.unmount(); });
232
- }
233
- var container = document.createElement('div');
234
- container.className = 'sqd-editor-react';
235
- rootRef.current = ReactDOM.createRoot(container);
236
- rootRef.current.render(element);
237
- return container;
238
262
  }
239
263
 
240
264
  exports.GlobalEditorWrapperContext = GlobalEditorWrapperContext;
265
+ exports.Presenter = Presenter;
241
266
  exports.SequentialWorkflowDesigner = SequentialWorkflowDesigner;
242
267
  exports.StepEditorWrapperContext = StepEditorWrapperContext;
243
268
  exports.useGlobalEditor = useGlobalEditor;
package/lib/esm/index.js CHANGED
@@ -1,8 +1,29 @@
1
+ import ReactDOM from 'react-dom/client';
1
2
  import { jsx } from 'react/jsx-runtime';
2
3
  import { createContext, useContext, useState, useRef, useEffect } from 'react';
3
- import ReactDOM from 'react-dom/client';
4
4
  import { Designer } from 'sequential-workflow-designer';
5
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
+
6
27
  /******************************************************************************
7
28
  Copyright (c) Microsoft Corporation.
8
29
 
@@ -29,9 +50,12 @@ var __assign = function() {
29
50
  return __assign.apply(this, arguments);
30
51
  };
31
52
 
32
- var globalEditorWrapperContext$1 = createContext(null);
53
+ if (!window.sqdGlobalEditorContext) {
54
+ window.sqdGlobalEditorContext = createContext(null);
55
+ }
56
+ var globalEditorContext = window.sqdGlobalEditorContext;
33
57
  function useGlobalEditor() {
34
- var wrapper = useContext(globalEditorWrapperContext$1);
58
+ var wrapper = useContext(globalEditorContext);
35
59
  if (!wrapper) {
36
60
  throw new Error('Cannot find global editor context');
37
61
  }
@@ -53,12 +77,15 @@ function GlobalEditorWrapperContext(props) {
53
77
  props.context.notifyPropertiesChanged();
54
78
  forward();
55
79
  }
56
- return jsx(globalEditorWrapperContext$1.Provider, __assign({ value: wrapper }, { children: props.children }));
80
+ return jsx(globalEditorContext.Provider, __assign({ value: wrapper }, { children: props.children }));
57
81
  }
58
82
 
59
- var globalEditorWrapperContext = createContext(null);
83
+ if (!window.sqdStepEditorContext) {
84
+ window.sqdStepEditorContext = createContext(null);
85
+ }
86
+ var stepEditorContext = window.sqdStepEditorContext;
60
87
  function useStepEditor() {
61
- var wrapper = useContext(globalEditorWrapperContext);
88
+ var wrapper = useContext(stepEditorContext);
62
89
  if (!wrapper) {
63
90
  throw new Error('Cannot find step editor context');
64
91
  }
@@ -103,7 +130,7 @@ function StepEditorWrapperContext(props) {
103
130
  props.context.notifyChildrenChanged();
104
131
  forward();
105
132
  }
106
- return jsx(globalEditorWrapperContext.Provider, __assign({ value: wrapper }, { children: props.children }));
133
+ return jsx(stepEditorContext.Provider, __assign({ value: wrapper }, { children: props.children }));
107
134
  }
108
135
 
109
136
  function wrapDefinition(value, isValid) {
@@ -113,6 +140,7 @@ function wrapDefinition(value, isValid) {
113
140
  };
114
141
  }
115
142
 
143
+ var externalEditorClassName = 'sqd-editor-react';
116
144
  function SequentialWorkflowDesigner(props) {
117
145
  var _a = useState(null), placeholder = _a[0], setPlaceholder = _a[1];
118
146
  var onDefinitionChangeRef = useRef(props.onDefinitionChange);
@@ -126,9 +154,13 @@ function SequentialWorkflowDesigner(props) {
126
154
  var isReadonly = props.isReadonly;
127
155
  var theme = props.theme;
128
156
  var undoStackSize = props.undoStackSize;
129
- var stepsConfiguration = props.stepsConfiguration;
130
- var toolboxConfiguration = props.toolboxConfiguration;
157
+ var steps = props.stepsConfiguration;
158
+ var toolbox = props.toolboxConfiguration;
159
+ var controlBar = props.controlBar;
131
160
  var extensions = props.extensions;
161
+ if (props.controlBar === undefined) {
162
+ throw new Error('The "controlBar" property is not set');
163
+ }
132
164
  function forwardDefinition() {
133
165
  if (designerRef.current) {
134
166
  var def = wrapDefinition(designerRef.current.getDefinition(), designerRef.current.isValid());
@@ -136,10 +168,16 @@ function SequentialWorkflowDesigner(props) {
136
168
  }
137
169
  }
138
170
  function globalEditorProvider(def, context) {
139
- return editorProvider(editorRootRef, jsx(GlobalEditorWrapperContext, __assign({ definition: def, context: context }, { children: globalEditorRef.current })));
171
+ if (!globalEditorRef.current) {
172
+ throw new Error('Global editor is not provided');
173
+ }
174
+ return Presenter.render(externalEditorClassName, editorRootRef, jsx(GlobalEditorWrapperContext, __assign({ definition: def, context: context }, { children: globalEditorRef.current })));
140
175
  }
141
176
  function stepEditorProvider(step, context) {
142
- return editorProvider(editorRootRef, jsx(StepEditorWrapperContext, __assign({ step: step, context: context }, { children: stepEditorRef.current })));
177
+ if (!stepEditorRef.current) {
178
+ throw new Error('Step editor is not provided');
179
+ }
180
+ return Presenter.render(externalEditorClassName, editorRootRef, jsx(StepEditorWrapperContext, __assign({ step: step, context: context }, { children: stepEditorRef.current })));
143
181
  }
144
182
  useEffect(function () {
145
183
  onDefinitionChangeRef.current = props.onDefinitionChange;
@@ -181,13 +219,15 @@ function SequentialWorkflowDesigner(props) {
181
219
  var designer = Designer.create(placeholder, definition.value, {
182
220
  theme: theme,
183
221
  undoStackSize: undoStackSize,
184
- toolbox: toolboxConfiguration,
185
- steps: stepsConfiguration,
186
- editors: {
187
- isHidden: false,
188
- globalEditorProvider: globalEditorProvider,
189
- stepEditorProvider: stepEditorProvider
190
- },
222
+ toolbox: toolbox,
223
+ steps: steps,
224
+ controlBar: controlBar,
225
+ editors: globalEditorRef.current && stepEditorRef.current
226
+ ? {
227
+ globalEditorProvider: globalEditorProvider,
228
+ stepEditorProvider: stepEditorProvider
229
+ }
230
+ : false,
191
231
  extensions: extensions
192
232
  });
193
233
  if (selectedStepId) {
@@ -205,14 +245,10 @@ function SequentialWorkflowDesigner(props) {
205
245
  }
206
246
  });
207
247
  designerRef.current = designer;
208
- }, [placeholder, definition, selectedStepId, isReadonly, theme, undoStackSize, toolboxConfiguration, stepsConfiguration, extensions]);
248
+ }, [placeholder, definition, selectedStepId, isReadonly, theme, undoStackSize, toolbox, controlBar, steps, extensions]);
209
249
  useEffect(function () {
210
250
  return function () {
211
- if (editorRootRef.current) {
212
- var oldRoot_1 = editorRootRef.current;
213
- editorRootRef.current = null;
214
- setTimeout(function () { return oldRoot_1.unmount(); });
215
- }
251
+ Presenter.tryDestroy(editorRootRef);
216
252
  if (designerRef.current) {
217
253
  designerRef.current.destroy();
218
254
  designerRef.current = null;
@@ -221,18 +257,6 @@ function SequentialWorkflowDesigner(props) {
221
257
  };
222
258
  }, []);
223
259
  return jsx("div", { ref: setPlaceholder, className: "sqd-designer-react" });
224
- }
225
- function editorProvider(rootRef, element) {
226
- if (rootRef.current) {
227
- var oldRoot_2 = rootRef.current;
228
- rootRef.current = null;
229
- setTimeout(function () { return oldRoot_2.unmount(); });
230
- }
231
- var container = document.createElement('div');
232
- container.className = 'sqd-editor-react';
233
- rootRef.current = ReactDOM.createRoot(container);
234
- rootRef.current.render(element);
235
- return container;
236
260
  }
237
261
 
238
- export { GlobalEditorWrapperContext, SequentialWorkflowDesigner, StepEditorWrapperContext, useGlobalEditor, useStepEditor, wrapDefinition };
262
+ export { GlobalEditorWrapperContext, Presenter, SequentialWorkflowDesigner, StepEditorWrapperContext, useGlobalEditor, useStepEditor, wrapDefinition };
package/lib/index.d.ts CHANGED
@@ -1,6 +1,18 @@
1
1
  /// <reference types="react" />
2
+ import { MutableRefObject, Context } from 'react';
3
+ import ReactDOM from 'react-dom/client';
2
4
  import { Definition, GlobalEditorContext, StepsConfiguration, ToolboxConfiguration, DesignerExtension, Step, StepEditorContext } from 'sequential-workflow-designer';
3
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
+ sqdGlobalEditorContext?: Context<GlobalEditorWrapper<Definition> | null>;
14
+ }
15
+ }
4
16
  interface GlobalEditorWrapper<TDefinition extends Definition> {
5
17
  readonly properties: TDefinition['properties'];
6
18
  setProperty(name: keyof TDefinition['properties'], value: TDefinition['properties'][typeof name]): void;
@@ -24,16 +36,25 @@ interface SequentialWorkflowDesignerProps<TDefinition extends Definition> {
24
36
  selectedStepId?: string | null;
25
37
  onSelectedStepIdChanged?: (stepId: string | null) => void;
26
38
  isReadonly?: boolean;
27
- globalEditor: JSX.Element;
28
- stepEditor: JSX.Element;
39
+ globalEditor: false | JSX.Element;
40
+ stepEditor: false | JSX.Element;
29
41
  theme?: string;
30
42
  undoStackSize?: number;
31
43
  stepsConfiguration: StepsConfiguration;
32
- toolboxConfiguration: ToolboxConfiguration;
44
+ toolboxConfiguration: false | ToolboxConfiguration;
45
+ /**
46
+ * @description If true, the control bar will be displayed.
47
+ */
48
+ controlBar: boolean;
33
49
  extensions?: DesignerExtension[];
34
50
  }
35
51
  declare function SequentialWorkflowDesigner<TDefinition extends Definition>(props: SequentialWorkflowDesignerProps<TDefinition>): JSX.Element;
36
52
 
53
+ declare global {
54
+ interface Window {
55
+ sqdStepEditorContext?: Context<StepEditorWrapper<Step> | null>;
56
+ }
57
+ }
37
58
  interface StepEditorWrapper<TStep extends Step> {
38
59
  readonly id: string;
39
60
  readonly type: TStep['type'];
@@ -53,4 +74,4 @@ declare function StepEditorWrapperContext(props: {
53
74
  context: StepEditorContext;
54
75
  }): JSX.Element;
55
76
 
56
- export { GlobalEditorWrapper, GlobalEditorWrapperContext, SequentialWorkflowDesigner, SequentialWorkflowDesignerProps, StepEditorWrapper, StepEditorWrapperContext, WrappedDefinition, useGlobalEditor, useStepEditor, wrapDefinition };
77
+ export { GlobalEditorWrapper, GlobalEditorWrapperContext, Presenter, SequentialWorkflowDesigner, SequentialWorkflowDesignerProps, StepEditorWrapper, StepEditorWrapperContext, WrappedDefinition, useGlobalEditor, 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.8.1",
4
+ "version": "0.9.1",
5
5
  "type": "module",
6
6
  "main": "./lib/esm/index.js",
7
7
  "types": "./lib/index.d.ts",
@@ -42,29 +42,32 @@
42
42
  "prettier:fix": "prettier --write ./src",
43
43
  "eslint": "eslint ./src --ext .ts",
44
44
  "test:single": "jest",
45
- "test": "jest --watchAll"
45
+ "test": "jest --clearCache && jest --watchAll"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "react": "^18.2.0",
49
49
  "react-dom": "^18.2.0",
50
- "sequential-workflow-designer": "^0.8.1"
50
+ "sequential-workflow-designer": "^0.9.1"
51
51
  },
52
52
  "devDependencies": {
53
+ "@rollup/plugin-node-resolve": "^15.0.1",
54
+ "@testing-library/jest-dom": "^5.16.5",
55
+ "@testing-library/react": "^14.0.0",
56
+ "@types/jest": "^29.2.5",
57
+ "@types/react": "^18.0.26",
53
58
  "@typescript-eslint/eslint-plugin": "^5.47.0",
54
59
  "@typescript-eslint/parser": "^5.47.0",
55
60
  "eslint": "^8.30.0",
56
- "@types/react": "^18.0.26",
57
- "@testing-library/react": "^13.4.0",
58
- "@testing-library/jest-dom": "^5.16.5",
59
61
  "jest": "^29.3.1",
60
62
  "jest-environment-jsdom": "^29.3.1",
61
- "@types/jest": "^29.2.5",
62
- "ts-jest": "^29.0.3",
63
63
  "prettier": "^2.8.2",
64
+ "react": "^18.2.0",
65
+ "react-dom": "^18.2.0",
66
+ "sequential-workflow-designer": "^0.9.1",
64
67
  "rollup": "^3.18.0",
65
68
  "rollup-plugin-dts": "^5.2.0",
66
69
  "rollup-plugin-typescript2": "^0.34.1",
67
- "@rollup/plugin-node-resolve": "^15.0.1",
70
+ "ts-jest": "^29.0.3",
68
71
  "typescript": "^4.9.4"
69
72
  },
70
73
  "keywords": [
@@ -77,4 +80,4 @@
77
80
  "react",
78
81
  "reactjs"
79
82
  ]
80
- }
83
+ }