sequential-workflow-designer-react 0.8.0 → 0.9.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/README.md +14 -1
- package/lib/cjs/index.cjs +270 -0
- package/lib/esm/index.js +262 -0
- package/lib/index.d.ts +77 -4
- package/package.json +33 -15
- package/lib/GlobalEditorWrapper.d.ts +0 -12
- package/lib/GlobalEditorWrapper.js +0 -39
- package/lib/SequentialWorkflowDesigner.d.ts +0 -18
- package/lib/SequentialWorkflowDesigner.js +0 -139
- package/lib/StepEditorWrapper.d.ts +0 -20
- package/lib/StepEditorWrapper.js +0 -62
- package/lib/WrappedDefinition.d.ts +0 -6
- package/lib/WrappedDefinition.js +0 -6
- package/lib/index.js +0 -4
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
|
|
@@ -0,0 +1,270 @@
|
|
|
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
|
+
|
|
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
|
+
if (!window.sqdGlobalEditorContext) {
|
|
56
|
+
window.sqdGlobalEditorContext = react.createContext(null);
|
|
57
|
+
}
|
|
58
|
+
var globalEditorContext = window.sqdGlobalEditorContext;
|
|
59
|
+
function useGlobalEditor() {
|
|
60
|
+
var wrapper = react.useContext(globalEditorContext);
|
|
61
|
+
if (!wrapper) {
|
|
62
|
+
throw new Error('Cannot find global editor context');
|
|
63
|
+
}
|
|
64
|
+
return wrapper;
|
|
65
|
+
}
|
|
66
|
+
function GlobalEditorWrapperContext(props) {
|
|
67
|
+
var _a = react.useState(function () { return createWrapper(); }), wrapper = _a[0], setWrapper = _a[1];
|
|
68
|
+
function createWrapper() {
|
|
69
|
+
return {
|
|
70
|
+
properties: props.definition.properties,
|
|
71
|
+
setProperty: setProperty
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function forward() {
|
|
75
|
+
setWrapper(createWrapper());
|
|
76
|
+
}
|
|
77
|
+
function setProperty(name, value) {
|
|
78
|
+
props.definition.properties[name] = value;
|
|
79
|
+
props.context.notifyPropertiesChanged();
|
|
80
|
+
forward();
|
|
81
|
+
}
|
|
82
|
+
return jsxRuntime.jsx(globalEditorContext.Provider, __assign({ value: wrapper }, { children: props.children }));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!window.sqdStepEditorContext) {
|
|
86
|
+
window.sqdStepEditorContext = react.createContext(null);
|
|
87
|
+
}
|
|
88
|
+
var stepEditorContext = window.sqdStepEditorContext;
|
|
89
|
+
function useStepEditor() {
|
|
90
|
+
var wrapper = react.useContext(stepEditorContext);
|
|
91
|
+
if (!wrapper) {
|
|
92
|
+
throw new Error('Cannot find step editor context');
|
|
93
|
+
}
|
|
94
|
+
return wrapper;
|
|
95
|
+
}
|
|
96
|
+
function StepEditorWrapperContext(props) {
|
|
97
|
+
var _a = react.useState(function () { return createWrapper(); }), wrapper = _a[0], setWrapper = _a[1];
|
|
98
|
+
function createWrapper() {
|
|
99
|
+
return {
|
|
100
|
+
id: props.step.id,
|
|
101
|
+
type: props.step.type,
|
|
102
|
+
componentType: props.step.componentType,
|
|
103
|
+
name: props.step.name,
|
|
104
|
+
properties: props.step.properties,
|
|
105
|
+
step: props.step,
|
|
106
|
+
setName: setName,
|
|
107
|
+
setProperty: setProperty,
|
|
108
|
+
notifyPropertiesChanged: notifyPropertiesChanged,
|
|
109
|
+
notifyChildrenChanged: notifyChildrenChanged
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function forward() {
|
|
113
|
+
setWrapper(createWrapper());
|
|
114
|
+
}
|
|
115
|
+
function setName(name) {
|
|
116
|
+
props.step.name = name;
|
|
117
|
+
notifyNameChanged();
|
|
118
|
+
}
|
|
119
|
+
function setProperty(name, value) {
|
|
120
|
+
props.step.properties[name] = value;
|
|
121
|
+
notifyPropertiesChanged();
|
|
122
|
+
}
|
|
123
|
+
function notifyNameChanged() {
|
|
124
|
+
props.context.notifyNameChanged();
|
|
125
|
+
forward();
|
|
126
|
+
}
|
|
127
|
+
function notifyPropertiesChanged() {
|
|
128
|
+
props.context.notifyPropertiesChanged();
|
|
129
|
+
forward();
|
|
130
|
+
}
|
|
131
|
+
function notifyChildrenChanged() {
|
|
132
|
+
props.context.notifyChildrenChanged();
|
|
133
|
+
forward();
|
|
134
|
+
}
|
|
135
|
+
return jsxRuntime.jsx(stepEditorContext.Provider, __assign({ value: wrapper }, { children: props.children }));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function wrapDefinition(value, isValid) {
|
|
139
|
+
return {
|
|
140
|
+
value: value,
|
|
141
|
+
isValid: isValid
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
var externalEditorClassName = 'sqd-editor-react';
|
|
146
|
+
function SequentialWorkflowDesigner(props) {
|
|
147
|
+
var _a = react.useState(null), placeholder = _a[0], setPlaceholder = _a[1];
|
|
148
|
+
var onDefinitionChangeRef = react.useRef(props.onDefinitionChange);
|
|
149
|
+
var onSelectedStepIdChangedRef = react.useRef(props.onSelectedStepIdChanged);
|
|
150
|
+
var globalEditorRef = react.useRef(props.globalEditor);
|
|
151
|
+
var stepEditorRef = react.useRef(props.stepEditor);
|
|
152
|
+
var designerRef = react.useRef(null);
|
|
153
|
+
var editorRootRef = react.useRef(null);
|
|
154
|
+
var definition = props.definition;
|
|
155
|
+
var selectedStepId = props.selectedStepId;
|
|
156
|
+
var isReadonly = props.isReadonly;
|
|
157
|
+
var theme = props.theme;
|
|
158
|
+
var undoStackSize = props.undoStackSize;
|
|
159
|
+
var steps = props.stepsConfiguration;
|
|
160
|
+
var toolbox = props.toolboxConfiguration;
|
|
161
|
+
var controlBar = props.controlBar;
|
|
162
|
+
var extensions = props.extensions;
|
|
163
|
+
if (props.controlBar === undefined) {
|
|
164
|
+
throw new Error('The "controlBar" property is not set');
|
|
165
|
+
}
|
|
166
|
+
function forwardDefinition() {
|
|
167
|
+
if (designerRef.current) {
|
|
168
|
+
var def = wrapDefinition(designerRef.current.getDefinition(), designerRef.current.isValid());
|
|
169
|
+
onDefinitionChangeRef.current(def);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function globalEditorProvider(def, context) {
|
|
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 })));
|
|
177
|
+
}
|
|
178
|
+
function stepEditorProvider(step, context) {
|
|
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 })));
|
|
183
|
+
}
|
|
184
|
+
react.useEffect(function () {
|
|
185
|
+
onDefinitionChangeRef.current = props.onDefinitionChange;
|
|
186
|
+
}, [props.onDefinitionChange]);
|
|
187
|
+
react.useEffect(function () {
|
|
188
|
+
onSelectedStepIdChangedRef.current = props.onSelectedStepIdChanged;
|
|
189
|
+
}, [props.onSelectedStepIdChanged]);
|
|
190
|
+
react.useEffect(function () {
|
|
191
|
+
globalEditorRef.current = props.globalEditor;
|
|
192
|
+
}, [props.globalEditor]);
|
|
193
|
+
react.useEffect(function () {
|
|
194
|
+
stepEditorRef.current = props.stepEditor;
|
|
195
|
+
}, [props.stepEditor]);
|
|
196
|
+
react.useEffect(function () {
|
|
197
|
+
if (!placeholder) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (designerRef.current) {
|
|
201
|
+
var isNotChanged = definition.value === designerRef.current.getDefinition();
|
|
202
|
+
if (isNotChanged) {
|
|
203
|
+
if (selectedStepId !== undefined && selectedStepId !== designerRef.current.getSelectedStepId()) {
|
|
204
|
+
if (selectedStepId) {
|
|
205
|
+
designerRef.current.selectStepById(selectedStepId);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
designerRef.current.clearSelectedStep();
|
|
209
|
+
}
|
|
210
|
+
// console.log('sqd: selected step updated');
|
|
211
|
+
}
|
|
212
|
+
if (isReadonly !== undefined && isReadonly !== designerRef.current.isReadonly()) {
|
|
213
|
+
designerRef.current.setIsReadonly(isReadonly);
|
|
214
|
+
// console.log('sqd: readonly updated');
|
|
215
|
+
}
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
designerRef.current.destroy();
|
|
219
|
+
designerRef.current = null;
|
|
220
|
+
}
|
|
221
|
+
var designer = sequentialWorkflowDesigner.Designer.create(placeholder, definition.value, {
|
|
222
|
+
theme: theme,
|
|
223
|
+
undoStackSize: undoStackSize,
|
|
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,
|
|
233
|
+
extensions: extensions
|
|
234
|
+
});
|
|
235
|
+
if (selectedStepId) {
|
|
236
|
+
designer.selectStepById(selectedStepId);
|
|
237
|
+
}
|
|
238
|
+
if (isReadonly) {
|
|
239
|
+
designer.setIsReadonly(isReadonly);
|
|
240
|
+
}
|
|
241
|
+
// console.log('sqd: designer rendered');
|
|
242
|
+
designer.onReady.subscribe(forwardDefinition);
|
|
243
|
+
designer.onDefinitionChanged.subscribe(forwardDefinition);
|
|
244
|
+
designer.onSelectedStepIdChanged.subscribe(function (stepId) {
|
|
245
|
+
if (onSelectedStepIdChangedRef.current) {
|
|
246
|
+
onSelectedStepIdChangedRef.current(stepId);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
designerRef.current = designer;
|
|
250
|
+
}, [placeholder, definition, selectedStepId, isReadonly, theme, undoStackSize, toolbox, controlBar, steps, extensions]);
|
|
251
|
+
react.useEffect(function () {
|
|
252
|
+
return function () {
|
|
253
|
+
Presenter.tryDestroy(editorRootRef);
|
|
254
|
+
if (designerRef.current) {
|
|
255
|
+
designerRef.current.destroy();
|
|
256
|
+
designerRef.current = null;
|
|
257
|
+
// console.log('sqd: designer destroyed');
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}, []);
|
|
261
|
+
return jsxRuntime.jsx("div", { ref: setPlaceholder, className: "sqd-designer-react" });
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
exports.GlobalEditorWrapperContext = GlobalEditorWrapperContext;
|
|
265
|
+
exports.Presenter = Presenter;
|
|
266
|
+
exports.SequentialWorkflowDesigner = SequentialWorkflowDesigner;
|
|
267
|
+
exports.StepEditorWrapperContext = StepEditorWrapperContext;
|
|
268
|
+
exports.useGlobalEditor = useGlobalEditor;
|
|
269
|
+
exports.useStepEditor = useStepEditor;
|
|
270
|
+
exports.wrapDefinition = wrapDefinition;
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import ReactDOM from 'react-dom/client';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { createContext, useContext, useState, useRef, useEffect } from 'react';
|
|
4
|
+
import { Designer } 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
|
+
|
|
42
|
+
var __assign = function() {
|
|
43
|
+
__assign = Object.assign || function __assign(t) {
|
|
44
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
45
|
+
s = arguments[i];
|
|
46
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
47
|
+
}
|
|
48
|
+
return t;
|
|
49
|
+
};
|
|
50
|
+
return __assign.apply(this, arguments);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
if (!window.sqdGlobalEditorContext) {
|
|
54
|
+
window.sqdGlobalEditorContext = createContext(null);
|
|
55
|
+
}
|
|
56
|
+
var globalEditorContext = window.sqdGlobalEditorContext;
|
|
57
|
+
function useGlobalEditor() {
|
|
58
|
+
var wrapper = useContext(globalEditorContext);
|
|
59
|
+
if (!wrapper) {
|
|
60
|
+
throw new Error('Cannot find global editor context');
|
|
61
|
+
}
|
|
62
|
+
return wrapper;
|
|
63
|
+
}
|
|
64
|
+
function GlobalEditorWrapperContext(props) {
|
|
65
|
+
var _a = useState(function () { return createWrapper(); }), wrapper = _a[0], setWrapper = _a[1];
|
|
66
|
+
function createWrapper() {
|
|
67
|
+
return {
|
|
68
|
+
properties: props.definition.properties,
|
|
69
|
+
setProperty: setProperty
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function forward() {
|
|
73
|
+
setWrapper(createWrapper());
|
|
74
|
+
}
|
|
75
|
+
function setProperty(name, value) {
|
|
76
|
+
props.definition.properties[name] = value;
|
|
77
|
+
props.context.notifyPropertiesChanged();
|
|
78
|
+
forward();
|
|
79
|
+
}
|
|
80
|
+
return jsx(globalEditorContext.Provider, __assign({ value: wrapper }, { children: props.children }));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!window.sqdStepEditorContext) {
|
|
84
|
+
window.sqdStepEditorContext = createContext(null);
|
|
85
|
+
}
|
|
86
|
+
var stepEditorContext = window.sqdStepEditorContext;
|
|
87
|
+
function useStepEditor() {
|
|
88
|
+
var wrapper = useContext(stepEditorContext);
|
|
89
|
+
if (!wrapper) {
|
|
90
|
+
throw new Error('Cannot find step editor context');
|
|
91
|
+
}
|
|
92
|
+
return wrapper;
|
|
93
|
+
}
|
|
94
|
+
function StepEditorWrapperContext(props) {
|
|
95
|
+
var _a = useState(function () { return createWrapper(); }), wrapper = _a[0], setWrapper = _a[1];
|
|
96
|
+
function createWrapper() {
|
|
97
|
+
return {
|
|
98
|
+
id: props.step.id,
|
|
99
|
+
type: props.step.type,
|
|
100
|
+
componentType: props.step.componentType,
|
|
101
|
+
name: props.step.name,
|
|
102
|
+
properties: props.step.properties,
|
|
103
|
+
step: props.step,
|
|
104
|
+
setName: setName,
|
|
105
|
+
setProperty: setProperty,
|
|
106
|
+
notifyPropertiesChanged: notifyPropertiesChanged,
|
|
107
|
+
notifyChildrenChanged: notifyChildrenChanged
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function forward() {
|
|
111
|
+
setWrapper(createWrapper());
|
|
112
|
+
}
|
|
113
|
+
function setName(name) {
|
|
114
|
+
props.step.name = name;
|
|
115
|
+
notifyNameChanged();
|
|
116
|
+
}
|
|
117
|
+
function setProperty(name, value) {
|
|
118
|
+
props.step.properties[name] = value;
|
|
119
|
+
notifyPropertiesChanged();
|
|
120
|
+
}
|
|
121
|
+
function notifyNameChanged() {
|
|
122
|
+
props.context.notifyNameChanged();
|
|
123
|
+
forward();
|
|
124
|
+
}
|
|
125
|
+
function notifyPropertiesChanged() {
|
|
126
|
+
props.context.notifyPropertiesChanged();
|
|
127
|
+
forward();
|
|
128
|
+
}
|
|
129
|
+
function notifyChildrenChanged() {
|
|
130
|
+
props.context.notifyChildrenChanged();
|
|
131
|
+
forward();
|
|
132
|
+
}
|
|
133
|
+
return jsx(stepEditorContext.Provider, __assign({ value: wrapper }, { children: props.children }));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function wrapDefinition(value, isValid) {
|
|
137
|
+
return {
|
|
138
|
+
value: value,
|
|
139
|
+
isValid: isValid
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
var externalEditorClassName = 'sqd-editor-react';
|
|
144
|
+
function SequentialWorkflowDesigner(props) {
|
|
145
|
+
var _a = useState(null), placeholder = _a[0], setPlaceholder = _a[1];
|
|
146
|
+
var onDefinitionChangeRef = useRef(props.onDefinitionChange);
|
|
147
|
+
var onSelectedStepIdChangedRef = useRef(props.onSelectedStepIdChanged);
|
|
148
|
+
var globalEditorRef = useRef(props.globalEditor);
|
|
149
|
+
var stepEditorRef = useRef(props.stepEditor);
|
|
150
|
+
var designerRef = useRef(null);
|
|
151
|
+
var editorRootRef = useRef(null);
|
|
152
|
+
var definition = props.definition;
|
|
153
|
+
var selectedStepId = props.selectedStepId;
|
|
154
|
+
var isReadonly = props.isReadonly;
|
|
155
|
+
var theme = props.theme;
|
|
156
|
+
var undoStackSize = props.undoStackSize;
|
|
157
|
+
var steps = props.stepsConfiguration;
|
|
158
|
+
var toolbox = props.toolboxConfiguration;
|
|
159
|
+
var controlBar = props.controlBar;
|
|
160
|
+
var extensions = props.extensions;
|
|
161
|
+
if (props.controlBar === undefined) {
|
|
162
|
+
throw new Error('The "controlBar" property is not set');
|
|
163
|
+
}
|
|
164
|
+
function forwardDefinition() {
|
|
165
|
+
if (designerRef.current) {
|
|
166
|
+
var def = wrapDefinition(designerRef.current.getDefinition(), designerRef.current.isValid());
|
|
167
|
+
onDefinitionChangeRef.current(def);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function globalEditorProvider(def, context) {
|
|
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 })));
|
|
175
|
+
}
|
|
176
|
+
function stepEditorProvider(step, context) {
|
|
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 })));
|
|
181
|
+
}
|
|
182
|
+
useEffect(function () {
|
|
183
|
+
onDefinitionChangeRef.current = props.onDefinitionChange;
|
|
184
|
+
}, [props.onDefinitionChange]);
|
|
185
|
+
useEffect(function () {
|
|
186
|
+
onSelectedStepIdChangedRef.current = props.onSelectedStepIdChanged;
|
|
187
|
+
}, [props.onSelectedStepIdChanged]);
|
|
188
|
+
useEffect(function () {
|
|
189
|
+
globalEditorRef.current = props.globalEditor;
|
|
190
|
+
}, [props.globalEditor]);
|
|
191
|
+
useEffect(function () {
|
|
192
|
+
stepEditorRef.current = props.stepEditor;
|
|
193
|
+
}, [props.stepEditor]);
|
|
194
|
+
useEffect(function () {
|
|
195
|
+
if (!placeholder) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (designerRef.current) {
|
|
199
|
+
var isNotChanged = definition.value === designerRef.current.getDefinition();
|
|
200
|
+
if (isNotChanged) {
|
|
201
|
+
if (selectedStepId !== undefined && selectedStepId !== designerRef.current.getSelectedStepId()) {
|
|
202
|
+
if (selectedStepId) {
|
|
203
|
+
designerRef.current.selectStepById(selectedStepId);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
designerRef.current.clearSelectedStep();
|
|
207
|
+
}
|
|
208
|
+
// console.log('sqd: selected step updated');
|
|
209
|
+
}
|
|
210
|
+
if (isReadonly !== undefined && isReadonly !== designerRef.current.isReadonly()) {
|
|
211
|
+
designerRef.current.setIsReadonly(isReadonly);
|
|
212
|
+
// console.log('sqd: readonly updated');
|
|
213
|
+
}
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
designerRef.current.destroy();
|
|
217
|
+
designerRef.current = null;
|
|
218
|
+
}
|
|
219
|
+
var designer = Designer.create(placeholder, definition.value, {
|
|
220
|
+
theme: theme,
|
|
221
|
+
undoStackSize: undoStackSize,
|
|
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,
|
|
231
|
+
extensions: extensions
|
|
232
|
+
});
|
|
233
|
+
if (selectedStepId) {
|
|
234
|
+
designer.selectStepById(selectedStepId);
|
|
235
|
+
}
|
|
236
|
+
if (isReadonly) {
|
|
237
|
+
designer.setIsReadonly(isReadonly);
|
|
238
|
+
}
|
|
239
|
+
// console.log('sqd: designer rendered');
|
|
240
|
+
designer.onReady.subscribe(forwardDefinition);
|
|
241
|
+
designer.onDefinitionChanged.subscribe(forwardDefinition);
|
|
242
|
+
designer.onSelectedStepIdChanged.subscribe(function (stepId) {
|
|
243
|
+
if (onSelectedStepIdChangedRef.current) {
|
|
244
|
+
onSelectedStepIdChangedRef.current(stepId);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
designerRef.current = designer;
|
|
248
|
+
}, [placeholder, definition, selectedStepId, isReadonly, theme, undoStackSize, toolbox, controlBar, steps, extensions]);
|
|
249
|
+
useEffect(function () {
|
|
250
|
+
return function () {
|
|
251
|
+
Presenter.tryDestroy(editorRootRef);
|
|
252
|
+
if (designerRef.current) {
|
|
253
|
+
designerRef.current.destroy();
|
|
254
|
+
designerRef.current = null;
|
|
255
|
+
// console.log('sqd: designer destroyed');
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
}, []);
|
|
259
|
+
return jsx("div", { ref: setPlaceholder, className: "sqd-designer-react" });
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export { GlobalEditorWrapperContext, Presenter, SequentialWorkflowDesigner, StepEditorWrapperContext, useGlobalEditor, useStepEditor, wrapDefinition };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { MutableRefObject, Context } from 'react';
|
|
3
|
+
import ReactDOM from 'react-dom/client';
|
|
4
|
+
import { Definition, GlobalEditorContext, StepsConfiguration, ToolboxConfiguration, DesignerExtension, 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
|
+
sqdGlobalEditorContext?: Context<GlobalEditorWrapper<Definition> | null>;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
interface GlobalEditorWrapper<TDefinition extends Definition> {
|
|
17
|
+
readonly properties: TDefinition['properties'];
|
|
18
|
+
setProperty(name: keyof TDefinition['properties'], value: TDefinition['properties'][typeof name]): void;
|
|
19
|
+
}
|
|
20
|
+
declare function useGlobalEditor<TDefinition extends Definition = Definition>(): GlobalEditorWrapper<TDefinition>;
|
|
21
|
+
declare function GlobalEditorWrapperContext(props: {
|
|
22
|
+
children: JSX.Element;
|
|
23
|
+
definition: Definition;
|
|
24
|
+
context: GlobalEditorContext;
|
|
25
|
+
}): JSX.Element;
|
|
26
|
+
|
|
27
|
+
interface WrappedDefinition<TDefinition extends Definition = Definition> {
|
|
28
|
+
readonly value: TDefinition;
|
|
29
|
+
readonly isValid: boolean | undefined;
|
|
30
|
+
}
|
|
31
|
+
declare function wrapDefinition<TDefinition extends Definition = Definition>(value: TDefinition, isValid?: boolean): WrappedDefinition<TDefinition>;
|
|
32
|
+
|
|
33
|
+
interface SequentialWorkflowDesignerProps<TDefinition extends Definition> {
|
|
34
|
+
definition: WrappedDefinition<TDefinition>;
|
|
35
|
+
onDefinitionChange: (state: WrappedDefinition<TDefinition>) => void;
|
|
36
|
+
selectedStepId?: string | null;
|
|
37
|
+
onSelectedStepIdChanged?: (stepId: string | null) => void;
|
|
38
|
+
isReadonly?: boolean;
|
|
39
|
+
globalEditor: false | JSX.Element;
|
|
40
|
+
stepEditor: false | JSX.Element;
|
|
41
|
+
theme?: string;
|
|
42
|
+
undoStackSize?: number;
|
|
43
|
+
stepsConfiguration: StepsConfiguration;
|
|
44
|
+
toolboxConfiguration: false | ToolboxConfiguration;
|
|
45
|
+
/**
|
|
46
|
+
* @description If true, the control bar will be displayed.
|
|
47
|
+
*/
|
|
48
|
+
controlBar: boolean;
|
|
49
|
+
extensions?: DesignerExtension[];
|
|
50
|
+
}
|
|
51
|
+
declare function SequentialWorkflowDesigner<TDefinition extends Definition>(props: SequentialWorkflowDesignerProps<TDefinition>): JSX.Element;
|
|
52
|
+
|
|
53
|
+
declare global {
|
|
54
|
+
interface Window {
|
|
55
|
+
sqdStepEditorContext?: Context<StepEditorWrapper<Step> | null>;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
interface StepEditorWrapper<TStep extends Step> {
|
|
59
|
+
readonly id: string;
|
|
60
|
+
readonly type: TStep['type'];
|
|
61
|
+
readonly componentType: TStep['componentType'];
|
|
62
|
+
readonly name: string;
|
|
63
|
+
readonly properties: TStep['properties'];
|
|
64
|
+
readonly step: TStep;
|
|
65
|
+
setName(name: string): void;
|
|
66
|
+
setProperty(name: keyof TStep['properties'], value: TStep['properties'][typeof name]): void;
|
|
67
|
+
notifyPropertiesChanged(): void;
|
|
68
|
+
notifyChildrenChanged(): void;
|
|
69
|
+
}
|
|
70
|
+
declare function useStepEditor<TStep extends Step = Step>(): StepEditorWrapper<TStep>;
|
|
71
|
+
declare function StepEditorWrapperContext(props: {
|
|
72
|
+
children: JSX.Element;
|
|
73
|
+
step: Step;
|
|
74
|
+
context: StepEditorContext;
|
|
75
|
+
}): JSX.Element;
|
|
76
|
+
|
|
77
|
+
export { GlobalEditorWrapper, GlobalEditorWrapperContext, Presenter, SequentialWorkflowDesigner, SequentialWorkflowDesignerProps, StepEditorWrapper, StepEditorWrapperContext, WrappedDefinition, useGlobalEditor, useStepEditor, wrapDefinition };
|
package/package.json
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sequential-workflow-designer-react",
|
|
3
3
|
"description": "React wrapper for Sequential Workflow Designer component.",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"
|
|
4
|
+
"version": "0.9.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/esm/index.js",
|
|
6
7
|
"types": "./lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": {
|
|
11
|
+
"require": "./lib/index.d.ts",
|
|
12
|
+
"default": "./lib/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"default": {
|
|
15
|
+
"require": "./lib/cjs/index.cjs",
|
|
16
|
+
"default": "./lib/esm/index.js"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
7
20
|
"author": {
|
|
8
21
|
"name": "NoCode JS",
|
|
9
22
|
"url": "https://nocode-js.com/"
|
|
@@ -23,33 +36,38 @@
|
|
|
23
36
|
"scripts": {
|
|
24
37
|
"prepare": "cp ../LICENSE LICENSE",
|
|
25
38
|
"clean": "rm -rf lib",
|
|
26
|
-
"start": "
|
|
27
|
-
"build": "yarn clean &&
|
|
39
|
+
"start": "rollup -c --watch",
|
|
40
|
+
"build": "yarn clean && rollup -c",
|
|
28
41
|
"prettier": "prettier --check ./src",
|
|
29
42
|
"prettier:fix": "prettier --write ./src",
|
|
30
43
|
"eslint": "eslint ./src --ext .ts",
|
|
31
44
|
"test:single": "jest",
|
|
32
|
-
"test": "jest --watchAll"
|
|
33
|
-
},
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"react": "^18.2.0",
|
|
36
|
-
"react-dom": "^18.2.0"
|
|
45
|
+
"test": "jest --clearCache && jest --watchAll"
|
|
37
46
|
},
|
|
38
47
|
"peerDependencies": {
|
|
39
|
-
"
|
|
48
|
+
"react": "^18.2.0",
|
|
49
|
+
"react-dom": "^18.2.0",
|
|
50
|
+
"sequential-workflow-designer": "^0.9.0"
|
|
40
51
|
},
|
|
41
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",
|
|
42
58
|
"@typescript-eslint/eslint-plugin": "^5.47.0",
|
|
43
59
|
"@typescript-eslint/parser": "^5.47.0",
|
|
44
60
|
"eslint": "^8.30.0",
|
|
45
|
-
"@types/react": "^18.0.26",
|
|
46
|
-
"@testing-library/react": "^13.4.0",
|
|
47
|
-
"@testing-library/jest-dom": "^5.16.5",
|
|
48
61
|
"jest": "^29.3.1",
|
|
49
62
|
"jest-environment-jsdom": "^29.3.1",
|
|
50
|
-
"@types/jest": "^29.2.5",
|
|
51
|
-
"ts-jest": "^29.0.3",
|
|
52
63
|
"prettier": "^2.8.2",
|
|
64
|
+
"react": "^18.2.0",
|
|
65
|
+
"react-dom": "^18.2.0",
|
|
66
|
+
"sequential-workflow-designer": "^0.9.0",
|
|
67
|
+
"rollup": "^3.18.0",
|
|
68
|
+
"rollup-plugin-dts": "^5.2.0",
|
|
69
|
+
"rollup-plugin-typescript2": "^0.34.1",
|
|
70
|
+
"ts-jest": "^29.0.3",
|
|
53
71
|
"typescript": "^4.9.4"
|
|
54
72
|
},
|
|
55
73
|
"keywords": [
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { Definition, GlobalEditorContext } from 'sequential-workflow-designer';
|
|
3
|
-
export interface GlobalEditorWrapper<TDefinition extends Definition> {
|
|
4
|
-
readonly properties: TDefinition['properties'];
|
|
5
|
-
setProperty(name: keyof TDefinition['properties'], value: TDefinition['properties'][typeof name]): void;
|
|
6
|
-
}
|
|
7
|
-
export declare function useGlobalEditor<TDefinition extends Definition = Definition>(): GlobalEditorWrapper<TDefinition>;
|
|
8
|
-
export declare function GlobalEditorWrapperContext(props: {
|
|
9
|
-
children: JSX.Element;
|
|
10
|
-
definition: Definition;
|
|
11
|
-
context: GlobalEditorContext;
|
|
12
|
-
}): JSX.Element;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import { createContext, useContext, useState } from 'react';
|
|
14
|
-
var globalEditorWrapperContext = createContext(null);
|
|
15
|
-
export function useGlobalEditor() {
|
|
16
|
-
var wrapper = useContext(globalEditorWrapperContext);
|
|
17
|
-
if (!wrapper) {
|
|
18
|
-
throw new Error('Cannot find global editor context');
|
|
19
|
-
}
|
|
20
|
-
return wrapper;
|
|
21
|
-
}
|
|
22
|
-
export function GlobalEditorWrapperContext(props) {
|
|
23
|
-
var _a = useState(function () { return createWrapper(); }), wrapper = _a[0], setWrapper = _a[1];
|
|
24
|
-
function createWrapper() {
|
|
25
|
-
return {
|
|
26
|
-
properties: props.definition.properties,
|
|
27
|
-
setProperty: setProperty
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function forward() {
|
|
31
|
-
setWrapper(createWrapper());
|
|
32
|
-
}
|
|
33
|
-
function setProperty(name, value) {
|
|
34
|
-
props.definition.properties[name] = value;
|
|
35
|
-
props.context.notifyPropertiesChanged();
|
|
36
|
-
forward();
|
|
37
|
-
}
|
|
38
|
-
return _jsx(globalEditorWrapperContext.Provider, __assign({ value: wrapper }, { children: props.children }));
|
|
39
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { Definition, ToolboxConfiguration, StepsConfiguration, DesignerExtension } from 'sequential-workflow-designer';
|
|
3
|
-
import { WrappedDefinition } from './WrappedDefinition';
|
|
4
|
-
export interface SequentialWorkflowDesignerProps<TDefinition extends Definition> {
|
|
5
|
-
definition: WrappedDefinition<TDefinition>;
|
|
6
|
-
onDefinitionChange: (state: WrappedDefinition<TDefinition>) => void;
|
|
7
|
-
selectedStepId?: string | null;
|
|
8
|
-
onSelectedStepIdChanged?: (stepId: string | null) => void;
|
|
9
|
-
isReadonly?: boolean;
|
|
10
|
-
globalEditor: JSX.Element;
|
|
11
|
-
stepEditor: JSX.Element;
|
|
12
|
-
theme?: string;
|
|
13
|
-
undoStackSize?: number;
|
|
14
|
-
stepsConfiguration: StepsConfiguration;
|
|
15
|
-
toolboxConfiguration: ToolboxConfiguration;
|
|
16
|
-
extensions?: DesignerExtension[];
|
|
17
|
-
}
|
|
18
|
-
export declare function SequentialWorkflowDesigner<TDefinition extends Definition>(props: SequentialWorkflowDesignerProps<TDefinition>): JSX.Element;
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import ReactDOM from 'react-dom/client';
|
|
14
|
-
import { useEffect, useRef, useState } from 'react';
|
|
15
|
-
import { Designer } from 'sequential-workflow-designer';
|
|
16
|
-
import { GlobalEditorWrapperContext } from './GlobalEditorWrapper';
|
|
17
|
-
import { StepEditorWrapperContext } from './StepEditorWrapper';
|
|
18
|
-
import { wrapDefinition } from './WrappedDefinition';
|
|
19
|
-
export function SequentialWorkflowDesigner(props) {
|
|
20
|
-
var _a = useState(null), placeholder = _a[0], setPlaceholder = _a[1];
|
|
21
|
-
var onDefinitionChangeRef = useRef(props.onDefinitionChange);
|
|
22
|
-
var onSelectedStepIdChangedRef = useRef(props.onSelectedStepIdChanged);
|
|
23
|
-
var globalEditorRef = useRef(props.globalEditor);
|
|
24
|
-
var stepEditorRef = useRef(props.stepEditor);
|
|
25
|
-
var designerRef = useRef(null);
|
|
26
|
-
var editorRootRef = useRef(null);
|
|
27
|
-
var definition = props.definition;
|
|
28
|
-
var selectedStepId = props.selectedStepId;
|
|
29
|
-
var isReadonly = props.isReadonly;
|
|
30
|
-
var theme = props.theme;
|
|
31
|
-
var undoStackSize = props.undoStackSize;
|
|
32
|
-
var stepsConfiguration = props.stepsConfiguration;
|
|
33
|
-
var toolboxConfiguration = props.toolboxConfiguration;
|
|
34
|
-
var extensions = props.extensions;
|
|
35
|
-
function forwardDefinition() {
|
|
36
|
-
if (designerRef.current) {
|
|
37
|
-
var def = wrapDefinition(designerRef.current.getDefinition(), designerRef.current.isValid());
|
|
38
|
-
onDefinitionChangeRef.current(def);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function globalEditorProvider(def, context) {
|
|
42
|
-
return editorProvider(editorRootRef, _jsx(GlobalEditorWrapperContext, __assign({ definition: def, context: context }, { children: globalEditorRef.current })));
|
|
43
|
-
}
|
|
44
|
-
function stepEditorProvider(step, context) {
|
|
45
|
-
return editorProvider(editorRootRef, _jsx(StepEditorWrapperContext, __assign({ step: step, context: context }, { children: stepEditorRef.current })));
|
|
46
|
-
}
|
|
47
|
-
useEffect(function () {
|
|
48
|
-
onDefinitionChangeRef.current = props.onDefinitionChange;
|
|
49
|
-
}, [props.onDefinitionChange]);
|
|
50
|
-
useEffect(function () {
|
|
51
|
-
onSelectedStepIdChangedRef.current = props.onSelectedStepIdChanged;
|
|
52
|
-
}, [props.onSelectedStepIdChanged]);
|
|
53
|
-
useEffect(function () {
|
|
54
|
-
globalEditorRef.current = props.globalEditor;
|
|
55
|
-
}, [props.globalEditor]);
|
|
56
|
-
useEffect(function () {
|
|
57
|
-
stepEditorRef.current = props.stepEditor;
|
|
58
|
-
}, [props.stepEditor]);
|
|
59
|
-
useEffect(function () {
|
|
60
|
-
if (!placeholder) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (designerRef.current) {
|
|
64
|
-
var isNotChanged = definition.value === designerRef.current.getDefinition();
|
|
65
|
-
if (isNotChanged) {
|
|
66
|
-
if (selectedStepId !== undefined && selectedStepId !== designerRef.current.getSelectedStepId()) {
|
|
67
|
-
if (selectedStepId) {
|
|
68
|
-
designerRef.current.selectStepById(selectedStepId);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
designerRef.current.clearSelectedStep();
|
|
72
|
-
}
|
|
73
|
-
// console.log('sqd: selected step updated');
|
|
74
|
-
}
|
|
75
|
-
if (isReadonly !== undefined && isReadonly !== designerRef.current.isReadonly()) {
|
|
76
|
-
designerRef.current.setIsReadonly(isReadonly);
|
|
77
|
-
// console.log('sqd: readonly updated');
|
|
78
|
-
}
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
designerRef.current.destroy();
|
|
82
|
-
designerRef.current = null;
|
|
83
|
-
}
|
|
84
|
-
var designer = Designer.create(placeholder, definition.value, {
|
|
85
|
-
theme: theme,
|
|
86
|
-
undoStackSize: undoStackSize,
|
|
87
|
-
toolbox: toolboxConfiguration,
|
|
88
|
-
steps: stepsConfiguration,
|
|
89
|
-
editors: {
|
|
90
|
-
isHidden: false,
|
|
91
|
-
globalEditorProvider: globalEditorProvider,
|
|
92
|
-
stepEditorProvider: stepEditorProvider
|
|
93
|
-
},
|
|
94
|
-
extensions: extensions
|
|
95
|
-
});
|
|
96
|
-
if (selectedStepId) {
|
|
97
|
-
designer.selectStepById(selectedStepId);
|
|
98
|
-
}
|
|
99
|
-
if (isReadonly) {
|
|
100
|
-
designer.setIsReadonly(isReadonly);
|
|
101
|
-
}
|
|
102
|
-
// console.log('sqd: designer rendered');
|
|
103
|
-
designer.onReady.subscribe(forwardDefinition);
|
|
104
|
-
designer.onDefinitionChanged.subscribe(forwardDefinition);
|
|
105
|
-
designer.onSelectedStepIdChanged.subscribe(function (stepId) {
|
|
106
|
-
if (onSelectedStepIdChangedRef.current) {
|
|
107
|
-
onSelectedStepIdChangedRef.current(stepId);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
designerRef.current = designer;
|
|
111
|
-
}, [placeholder, definition, selectedStepId, isReadonly, theme, undoStackSize, toolboxConfiguration, stepsConfiguration, extensions]);
|
|
112
|
-
useEffect(function () {
|
|
113
|
-
return function () {
|
|
114
|
-
if (editorRootRef.current) {
|
|
115
|
-
var oldRoot_1 = editorRootRef.current;
|
|
116
|
-
editorRootRef.current = null;
|
|
117
|
-
setTimeout(function () { return oldRoot_1.unmount(); });
|
|
118
|
-
}
|
|
119
|
-
if (designerRef.current) {
|
|
120
|
-
designerRef.current.destroy();
|
|
121
|
-
designerRef.current = null;
|
|
122
|
-
// console.log('sqd: designer destroyed');
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
}, []);
|
|
126
|
-
return _jsx("div", { ref: setPlaceholder, className: "sqd-designer-react" });
|
|
127
|
-
}
|
|
128
|
-
function editorProvider(rootRef, element) {
|
|
129
|
-
if (rootRef.current) {
|
|
130
|
-
var oldRoot_2 = rootRef.current;
|
|
131
|
-
rootRef.current = null;
|
|
132
|
-
setTimeout(function () { return oldRoot_2.unmount(); });
|
|
133
|
-
}
|
|
134
|
-
var container = document.createElement('div');
|
|
135
|
-
container.className = 'sqd-editor-react';
|
|
136
|
-
rootRef.current = ReactDOM.createRoot(container);
|
|
137
|
-
rootRef.current.render(element);
|
|
138
|
-
return container;
|
|
139
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { StepEditorContext, Step } from 'sequential-workflow-designer';
|
|
3
|
-
export interface StepEditorWrapper<TStep extends Step> {
|
|
4
|
-
readonly id: string;
|
|
5
|
-
readonly type: TStep['type'];
|
|
6
|
-
readonly componentType: TStep['componentType'];
|
|
7
|
-
readonly name: string;
|
|
8
|
-
readonly properties: TStep['properties'];
|
|
9
|
-
readonly step: TStep;
|
|
10
|
-
setName(name: string): void;
|
|
11
|
-
setProperty(name: keyof TStep['properties'], value: TStep['properties'][typeof name]): void;
|
|
12
|
-
notifyPropertiesChanged(): void;
|
|
13
|
-
notifyChildrenChanged(): void;
|
|
14
|
-
}
|
|
15
|
-
export declare function useStepEditor<TStep extends Step = Step>(): StepEditorWrapper<TStep>;
|
|
16
|
-
export declare function StepEditorWrapperContext(props: {
|
|
17
|
-
children: JSX.Element;
|
|
18
|
-
step: Step;
|
|
19
|
-
context: StepEditorContext;
|
|
20
|
-
}): JSX.Element;
|
package/lib/StepEditorWrapper.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import { createContext, useContext, useState } from 'react';
|
|
14
|
-
var globalEditorWrapperContext = createContext(null);
|
|
15
|
-
export function useStepEditor() {
|
|
16
|
-
var wrapper = useContext(globalEditorWrapperContext);
|
|
17
|
-
if (!wrapper) {
|
|
18
|
-
throw new Error('Cannot find step editor context');
|
|
19
|
-
}
|
|
20
|
-
return wrapper;
|
|
21
|
-
}
|
|
22
|
-
export function StepEditorWrapperContext(props) {
|
|
23
|
-
var _a = useState(function () { return createWrapper(); }), wrapper = _a[0], setWrapper = _a[1];
|
|
24
|
-
function createWrapper() {
|
|
25
|
-
return {
|
|
26
|
-
id: props.step.id,
|
|
27
|
-
type: props.step.type,
|
|
28
|
-
componentType: props.step.componentType,
|
|
29
|
-
name: props.step.name,
|
|
30
|
-
properties: props.step.properties,
|
|
31
|
-
step: props.step,
|
|
32
|
-
setName: setName,
|
|
33
|
-
setProperty: setProperty,
|
|
34
|
-
notifyPropertiesChanged: notifyPropertiesChanged,
|
|
35
|
-
notifyChildrenChanged: notifyChildrenChanged
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function forward() {
|
|
39
|
-
setWrapper(createWrapper());
|
|
40
|
-
}
|
|
41
|
-
function setName(name) {
|
|
42
|
-
props.step.name = name;
|
|
43
|
-
notifyNameChanged();
|
|
44
|
-
}
|
|
45
|
-
function setProperty(name, value) {
|
|
46
|
-
props.step.properties[name] = value;
|
|
47
|
-
notifyPropertiesChanged();
|
|
48
|
-
}
|
|
49
|
-
function notifyNameChanged() {
|
|
50
|
-
props.context.notifyNameChanged();
|
|
51
|
-
forward();
|
|
52
|
-
}
|
|
53
|
-
function notifyPropertiesChanged() {
|
|
54
|
-
props.context.notifyPropertiesChanged();
|
|
55
|
-
forward();
|
|
56
|
-
}
|
|
57
|
-
function notifyChildrenChanged() {
|
|
58
|
-
props.context.notifyChildrenChanged();
|
|
59
|
-
forward();
|
|
60
|
-
}
|
|
61
|
-
return _jsx(globalEditorWrapperContext.Provider, __assign({ value: wrapper }, { children: props.children }));
|
|
62
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Definition } from 'sequential-workflow-designer';
|
|
2
|
-
export interface WrappedDefinition<TDefinition extends Definition = Definition> {
|
|
3
|
-
readonly value: TDefinition;
|
|
4
|
-
readonly isValid: boolean | undefined;
|
|
5
|
-
}
|
|
6
|
-
export declare function wrapDefinition<TDefinition extends Definition = Definition>(value: TDefinition, isValid?: boolean): WrappedDefinition<TDefinition>;
|
package/lib/WrappedDefinition.js
DELETED
package/lib/index.js
DELETED