sequential-workflow-designer-react 0.8.0 → 0.8.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.
@@ -0,0 +1,245 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+ var ReactDOM = require('react-dom/client');
6
+ var sequentialWorkflowDesigner = require('sequential-workflow-designer');
7
+
8
+ /******************************************************************************
9
+ Copyright (c) Microsoft Corporation.
10
+
11
+ Permission to use, copy, modify, and/or distribute this software for any
12
+ purpose with or without fee is hereby granted.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
+ PERFORMANCE OF THIS SOFTWARE.
21
+ ***************************************************************************** */
22
+
23
+ var __assign = function() {
24
+ __assign = Object.assign || function __assign(t) {
25
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
26
+ s = arguments[i];
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
28
+ }
29
+ return t;
30
+ };
31
+ return __assign.apply(this, arguments);
32
+ };
33
+
34
+ var globalEditorWrapperContext$1 = react.createContext(null);
35
+ function useGlobalEditor() {
36
+ var wrapper = react.useContext(globalEditorWrapperContext$1);
37
+ if (!wrapper) {
38
+ throw new Error('Cannot find global editor context');
39
+ }
40
+ return wrapper;
41
+ }
42
+ function GlobalEditorWrapperContext(props) {
43
+ var _a = react.useState(function () { return createWrapper(); }), wrapper = _a[0], setWrapper = _a[1];
44
+ function createWrapper() {
45
+ return {
46
+ properties: props.definition.properties,
47
+ setProperty: setProperty
48
+ };
49
+ }
50
+ function forward() {
51
+ setWrapper(createWrapper());
52
+ }
53
+ function setProperty(name, value) {
54
+ props.definition.properties[name] = value;
55
+ props.context.notifyPropertiesChanged();
56
+ forward();
57
+ }
58
+ return jsxRuntime.jsx(globalEditorWrapperContext$1.Provider, __assign({ value: wrapper }, { children: props.children }));
59
+ }
60
+
61
+ var globalEditorWrapperContext = react.createContext(null);
62
+ function useStepEditor() {
63
+ var wrapper = react.useContext(globalEditorWrapperContext);
64
+ if (!wrapper) {
65
+ throw new Error('Cannot find step editor context');
66
+ }
67
+ return wrapper;
68
+ }
69
+ function StepEditorWrapperContext(props) {
70
+ var _a = react.useState(function () { return createWrapper(); }), wrapper = _a[0], setWrapper = _a[1];
71
+ function createWrapper() {
72
+ return {
73
+ id: props.step.id,
74
+ type: props.step.type,
75
+ componentType: props.step.componentType,
76
+ name: props.step.name,
77
+ properties: props.step.properties,
78
+ step: props.step,
79
+ setName: setName,
80
+ setProperty: setProperty,
81
+ notifyPropertiesChanged: notifyPropertiesChanged,
82
+ notifyChildrenChanged: notifyChildrenChanged
83
+ };
84
+ }
85
+ function forward() {
86
+ setWrapper(createWrapper());
87
+ }
88
+ function setName(name) {
89
+ props.step.name = name;
90
+ notifyNameChanged();
91
+ }
92
+ function setProperty(name, value) {
93
+ props.step.properties[name] = value;
94
+ notifyPropertiesChanged();
95
+ }
96
+ function notifyNameChanged() {
97
+ props.context.notifyNameChanged();
98
+ forward();
99
+ }
100
+ function notifyPropertiesChanged() {
101
+ props.context.notifyPropertiesChanged();
102
+ forward();
103
+ }
104
+ function notifyChildrenChanged() {
105
+ props.context.notifyChildrenChanged();
106
+ forward();
107
+ }
108
+ return jsxRuntime.jsx(globalEditorWrapperContext.Provider, __assign({ value: wrapper }, { children: props.children }));
109
+ }
110
+
111
+ function wrapDefinition(value, isValid) {
112
+ return {
113
+ value: value,
114
+ isValid: isValid
115
+ };
116
+ }
117
+
118
+ function SequentialWorkflowDesigner(props) {
119
+ var _a = react.useState(null), placeholder = _a[0], setPlaceholder = _a[1];
120
+ var onDefinitionChangeRef = react.useRef(props.onDefinitionChange);
121
+ var onSelectedStepIdChangedRef = react.useRef(props.onSelectedStepIdChanged);
122
+ var globalEditorRef = react.useRef(props.globalEditor);
123
+ var stepEditorRef = react.useRef(props.stepEditor);
124
+ var designerRef = react.useRef(null);
125
+ var editorRootRef = react.useRef(null);
126
+ var definition = props.definition;
127
+ var selectedStepId = props.selectedStepId;
128
+ var isReadonly = props.isReadonly;
129
+ var theme = props.theme;
130
+ var undoStackSize = props.undoStackSize;
131
+ var stepsConfiguration = props.stepsConfiguration;
132
+ var toolboxConfiguration = props.toolboxConfiguration;
133
+ var extensions = props.extensions;
134
+ function forwardDefinition() {
135
+ if (designerRef.current) {
136
+ var def = wrapDefinition(designerRef.current.getDefinition(), designerRef.current.isValid());
137
+ onDefinitionChangeRef.current(def);
138
+ }
139
+ }
140
+ function globalEditorProvider(def, context) {
141
+ return editorProvider(editorRootRef, jsxRuntime.jsx(GlobalEditorWrapperContext, __assign({ definition: def, context: context }, { children: globalEditorRef.current })));
142
+ }
143
+ function stepEditorProvider(step, context) {
144
+ return editorProvider(editorRootRef, jsxRuntime.jsx(StepEditorWrapperContext, __assign({ step: step, context: context }, { children: stepEditorRef.current })));
145
+ }
146
+ react.useEffect(function () {
147
+ onDefinitionChangeRef.current = props.onDefinitionChange;
148
+ }, [props.onDefinitionChange]);
149
+ react.useEffect(function () {
150
+ onSelectedStepIdChangedRef.current = props.onSelectedStepIdChanged;
151
+ }, [props.onSelectedStepIdChanged]);
152
+ react.useEffect(function () {
153
+ globalEditorRef.current = props.globalEditor;
154
+ }, [props.globalEditor]);
155
+ react.useEffect(function () {
156
+ stepEditorRef.current = props.stepEditor;
157
+ }, [props.stepEditor]);
158
+ react.useEffect(function () {
159
+ if (!placeholder) {
160
+ return;
161
+ }
162
+ if (designerRef.current) {
163
+ var isNotChanged = definition.value === designerRef.current.getDefinition();
164
+ if (isNotChanged) {
165
+ if (selectedStepId !== undefined && selectedStepId !== designerRef.current.getSelectedStepId()) {
166
+ if (selectedStepId) {
167
+ designerRef.current.selectStepById(selectedStepId);
168
+ }
169
+ else {
170
+ designerRef.current.clearSelectedStep();
171
+ }
172
+ // console.log('sqd: selected step updated');
173
+ }
174
+ if (isReadonly !== undefined && isReadonly !== designerRef.current.isReadonly()) {
175
+ designerRef.current.setIsReadonly(isReadonly);
176
+ // console.log('sqd: readonly updated');
177
+ }
178
+ return;
179
+ }
180
+ designerRef.current.destroy();
181
+ designerRef.current = null;
182
+ }
183
+ var designer = sequentialWorkflowDesigner.Designer.create(placeholder, definition.value, {
184
+ theme: theme,
185
+ undoStackSize: undoStackSize,
186
+ toolbox: toolboxConfiguration,
187
+ steps: stepsConfiguration,
188
+ editors: {
189
+ isHidden: false,
190
+ globalEditorProvider: globalEditorProvider,
191
+ stepEditorProvider: stepEditorProvider
192
+ },
193
+ extensions: extensions
194
+ });
195
+ if (selectedStepId) {
196
+ designer.selectStepById(selectedStepId);
197
+ }
198
+ if (isReadonly) {
199
+ designer.setIsReadonly(isReadonly);
200
+ }
201
+ // console.log('sqd: designer rendered');
202
+ designer.onReady.subscribe(forwardDefinition);
203
+ designer.onDefinitionChanged.subscribe(forwardDefinition);
204
+ designer.onSelectedStepIdChanged.subscribe(function (stepId) {
205
+ if (onSelectedStepIdChangedRef.current) {
206
+ onSelectedStepIdChangedRef.current(stepId);
207
+ }
208
+ });
209
+ designerRef.current = designer;
210
+ }, [placeholder, definition, selectedStepId, isReadonly, theme, undoStackSize, toolboxConfiguration, stepsConfiguration, extensions]);
211
+ react.useEffect(function () {
212
+ return function () {
213
+ if (editorRootRef.current) {
214
+ var oldRoot_1 = editorRootRef.current;
215
+ editorRootRef.current = null;
216
+ setTimeout(function () { return oldRoot_1.unmount(); });
217
+ }
218
+ if (designerRef.current) {
219
+ designerRef.current.destroy();
220
+ designerRef.current = null;
221
+ // console.log('sqd: designer destroyed');
222
+ }
223
+ };
224
+ }, []);
225
+ 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
+ }
239
+
240
+ exports.GlobalEditorWrapperContext = GlobalEditorWrapperContext;
241
+ exports.SequentialWorkflowDesigner = SequentialWorkflowDesigner;
242
+ exports.StepEditorWrapperContext = StepEditorWrapperContext;
243
+ exports.useGlobalEditor = useGlobalEditor;
244
+ exports.useStepEditor = useStepEditor;
245
+ exports.wrapDefinition = wrapDefinition;
@@ -1,139 +1,238 @@
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";
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { createContext, useContext, useState, useRef, useEffect } from 'react';
13
3
  import ReactDOM from 'react-dom/client';
14
- import { useEffect, useRef, useState } from 'react';
15
4
  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" });
5
+
6
+ /******************************************************************************
7
+ Copyright (c) Microsoft Corporation.
8
+
9
+ Permission to use, copy, modify, and/or distribute this software for any
10
+ purpose with or without fee is hereby granted.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
+ PERFORMANCE OF THIS SOFTWARE.
19
+ ***************************************************************************** */
20
+
21
+ var __assign = function() {
22
+ __assign = Object.assign || function __assign(t) {
23
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
24
+ s = arguments[i];
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
26
+ }
27
+ return t;
28
+ };
29
+ return __assign.apply(this, arguments);
30
+ };
31
+
32
+ var globalEditorWrapperContext$1 = createContext(null);
33
+ function useGlobalEditor() {
34
+ var wrapper = useContext(globalEditorWrapperContext$1);
35
+ if (!wrapper) {
36
+ throw new Error('Cannot find global editor context');
37
+ }
38
+ return wrapper;
39
+ }
40
+ function GlobalEditorWrapperContext(props) {
41
+ var _a = useState(function () { return createWrapper(); }), wrapper = _a[0], setWrapper = _a[1];
42
+ function createWrapper() {
43
+ return {
44
+ properties: props.definition.properties,
45
+ setProperty: setProperty
46
+ };
47
+ }
48
+ function forward() {
49
+ setWrapper(createWrapper());
50
+ }
51
+ function setProperty(name, value) {
52
+ props.definition.properties[name] = value;
53
+ props.context.notifyPropertiesChanged();
54
+ forward();
55
+ }
56
+ return jsx(globalEditorWrapperContext$1.Provider, __assign({ value: wrapper }, { children: props.children }));
57
+ }
58
+
59
+ var globalEditorWrapperContext = createContext(null);
60
+ function useStepEditor() {
61
+ var wrapper = useContext(globalEditorWrapperContext);
62
+ if (!wrapper) {
63
+ throw new Error('Cannot find step editor context');
64
+ }
65
+ return wrapper;
66
+ }
67
+ function StepEditorWrapperContext(props) {
68
+ var _a = useState(function () { return createWrapper(); }), wrapper = _a[0], setWrapper = _a[1];
69
+ function createWrapper() {
70
+ return {
71
+ id: props.step.id,
72
+ type: props.step.type,
73
+ componentType: props.step.componentType,
74
+ name: props.step.name,
75
+ properties: props.step.properties,
76
+ step: props.step,
77
+ setName: setName,
78
+ setProperty: setProperty,
79
+ notifyPropertiesChanged: notifyPropertiesChanged,
80
+ notifyChildrenChanged: notifyChildrenChanged
81
+ };
82
+ }
83
+ function forward() {
84
+ setWrapper(createWrapper());
85
+ }
86
+ function setName(name) {
87
+ props.step.name = name;
88
+ notifyNameChanged();
89
+ }
90
+ function setProperty(name, value) {
91
+ props.step.properties[name] = value;
92
+ notifyPropertiesChanged();
93
+ }
94
+ function notifyNameChanged() {
95
+ props.context.notifyNameChanged();
96
+ forward();
97
+ }
98
+ function notifyPropertiesChanged() {
99
+ props.context.notifyPropertiesChanged();
100
+ forward();
101
+ }
102
+ function notifyChildrenChanged() {
103
+ props.context.notifyChildrenChanged();
104
+ forward();
105
+ }
106
+ return jsx(globalEditorWrapperContext.Provider, __assign({ value: wrapper }, { children: props.children }));
107
+ }
108
+
109
+ function wrapDefinition(value, isValid) {
110
+ return {
111
+ value: value,
112
+ isValid: isValid
113
+ };
127
114
  }
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;
115
+
116
+ function SequentialWorkflowDesigner(props) {
117
+ var _a = useState(null), placeholder = _a[0], setPlaceholder = _a[1];
118
+ var onDefinitionChangeRef = useRef(props.onDefinitionChange);
119
+ var onSelectedStepIdChangedRef = useRef(props.onSelectedStepIdChanged);
120
+ var globalEditorRef = useRef(props.globalEditor);
121
+ var stepEditorRef = useRef(props.stepEditor);
122
+ var designerRef = useRef(null);
123
+ var editorRootRef = useRef(null);
124
+ var definition = props.definition;
125
+ var selectedStepId = props.selectedStepId;
126
+ var isReadonly = props.isReadonly;
127
+ var theme = props.theme;
128
+ var undoStackSize = props.undoStackSize;
129
+ var stepsConfiguration = props.stepsConfiguration;
130
+ var toolboxConfiguration = props.toolboxConfiguration;
131
+ var extensions = props.extensions;
132
+ function forwardDefinition() {
133
+ if (designerRef.current) {
134
+ var def = wrapDefinition(designerRef.current.getDefinition(), designerRef.current.isValid());
135
+ onDefinitionChangeRef.current(def);
136
+ }
137
+ }
138
+ function globalEditorProvider(def, context) {
139
+ return editorProvider(editorRootRef, jsx(GlobalEditorWrapperContext, __assign({ definition: def, context: context }, { children: globalEditorRef.current })));
140
+ }
141
+ function stepEditorProvider(step, context) {
142
+ return editorProvider(editorRootRef, jsx(StepEditorWrapperContext, __assign({ step: step, context: context }, { children: stepEditorRef.current })));
143
+ }
144
+ useEffect(function () {
145
+ onDefinitionChangeRef.current = props.onDefinitionChange;
146
+ }, [props.onDefinitionChange]);
147
+ useEffect(function () {
148
+ onSelectedStepIdChangedRef.current = props.onSelectedStepIdChanged;
149
+ }, [props.onSelectedStepIdChanged]);
150
+ useEffect(function () {
151
+ globalEditorRef.current = props.globalEditor;
152
+ }, [props.globalEditor]);
153
+ useEffect(function () {
154
+ stepEditorRef.current = props.stepEditor;
155
+ }, [props.stepEditor]);
156
+ useEffect(function () {
157
+ if (!placeholder) {
158
+ return;
159
+ }
160
+ if (designerRef.current) {
161
+ var isNotChanged = definition.value === designerRef.current.getDefinition();
162
+ if (isNotChanged) {
163
+ if (selectedStepId !== undefined && selectedStepId !== designerRef.current.getSelectedStepId()) {
164
+ if (selectedStepId) {
165
+ designerRef.current.selectStepById(selectedStepId);
166
+ }
167
+ else {
168
+ designerRef.current.clearSelectedStep();
169
+ }
170
+ // console.log('sqd: selected step updated');
171
+ }
172
+ if (isReadonly !== undefined && isReadonly !== designerRef.current.isReadonly()) {
173
+ designerRef.current.setIsReadonly(isReadonly);
174
+ // console.log('sqd: readonly updated');
175
+ }
176
+ return;
177
+ }
178
+ designerRef.current.destroy();
179
+ designerRef.current = null;
180
+ }
181
+ var designer = Designer.create(placeholder, definition.value, {
182
+ theme: theme,
183
+ undoStackSize: undoStackSize,
184
+ toolbox: toolboxConfiguration,
185
+ steps: stepsConfiguration,
186
+ editors: {
187
+ isHidden: false,
188
+ globalEditorProvider: globalEditorProvider,
189
+ stepEditorProvider: stepEditorProvider
190
+ },
191
+ extensions: extensions
192
+ });
193
+ if (selectedStepId) {
194
+ designer.selectStepById(selectedStepId);
195
+ }
196
+ if (isReadonly) {
197
+ designer.setIsReadonly(isReadonly);
198
+ }
199
+ // console.log('sqd: designer rendered');
200
+ designer.onReady.subscribe(forwardDefinition);
201
+ designer.onDefinitionChanged.subscribe(forwardDefinition);
202
+ designer.onSelectedStepIdChanged.subscribe(function (stepId) {
203
+ if (onSelectedStepIdChangedRef.current) {
204
+ onSelectedStepIdChangedRef.current(stepId);
205
+ }
206
+ });
207
+ designerRef.current = designer;
208
+ }, [placeholder, definition, selectedStepId, isReadonly, theme, undoStackSize, toolboxConfiguration, stepsConfiguration, extensions]);
209
+ useEffect(function () {
210
+ return function () {
211
+ if (editorRootRef.current) {
212
+ var oldRoot_1 = editorRootRef.current;
213
+ editorRootRef.current = null;
214
+ setTimeout(function () { return oldRoot_1.unmount(); });
215
+ }
216
+ if (designerRef.current) {
217
+ designerRef.current.destroy();
218
+ designerRef.current = null;
219
+ // console.log('sqd: designer destroyed');
220
+ }
221
+ };
222
+ }, []);
223
+ 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;
139
236
  }
237
+
238
+ export { GlobalEditorWrapperContext, SequentialWorkflowDesigner, StepEditorWrapperContext, useGlobalEditor, useStepEditor, wrapDefinition };
package/lib/index.d.ts CHANGED
@@ -1,4 +1,56 @@
1
- export * from './GlobalEditorWrapper';
2
- export * from './SequentialWorkflowDesigner';
3
- export * from './StepEditorWrapper';
4
- export * from './WrappedDefinition';
1
+ /// <reference types="react" />
2
+ import { Definition, GlobalEditorContext, StepsConfiguration, ToolboxConfiguration, DesignerExtension, Step, StepEditorContext } from 'sequential-workflow-designer';
3
+
4
+ interface GlobalEditorWrapper<TDefinition extends Definition> {
5
+ readonly properties: TDefinition['properties'];
6
+ setProperty(name: keyof TDefinition['properties'], value: TDefinition['properties'][typeof name]): void;
7
+ }
8
+ declare function useGlobalEditor<TDefinition extends Definition = Definition>(): GlobalEditorWrapper<TDefinition>;
9
+ declare function GlobalEditorWrapperContext(props: {
10
+ children: JSX.Element;
11
+ definition: Definition;
12
+ context: GlobalEditorContext;
13
+ }): JSX.Element;
14
+
15
+ interface WrappedDefinition<TDefinition extends Definition = Definition> {
16
+ readonly value: TDefinition;
17
+ readonly isValid: boolean | undefined;
18
+ }
19
+ declare function wrapDefinition<TDefinition extends Definition = Definition>(value: TDefinition, isValid?: boolean): WrappedDefinition<TDefinition>;
20
+
21
+ interface SequentialWorkflowDesignerProps<TDefinition extends Definition> {
22
+ definition: WrappedDefinition<TDefinition>;
23
+ onDefinitionChange: (state: WrappedDefinition<TDefinition>) => void;
24
+ selectedStepId?: string | null;
25
+ onSelectedStepIdChanged?: (stepId: string | null) => void;
26
+ isReadonly?: boolean;
27
+ globalEditor: JSX.Element;
28
+ stepEditor: JSX.Element;
29
+ theme?: string;
30
+ undoStackSize?: number;
31
+ stepsConfiguration: StepsConfiguration;
32
+ toolboxConfiguration: ToolboxConfiguration;
33
+ extensions?: DesignerExtension[];
34
+ }
35
+ declare function SequentialWorkflowDesigner<TDefinition extends Definition>(props: SequentialWorkflowDesignerProps<TDefinition>): JSX.Element;
36
+
37
+ interface StepEditorWrapper<TStep extends Step> {
38
+ readonly id: string;
39
+ readonly type: TStep['type'];
40
+ readonly componentType: TStep['componentType'];
41
+ readonly name: string;
42
+ readonly properties: TStep['properties'];
43
+ readonly step: TStep;
44
+ setName(name: string): void;
45
+ setProperty(name: keyof TStep['properties'], value: TStep['properties'][typeof name]): void;
46
+ notifyPropertiesChanged(): void;
47
+ notifyChildrenChanged(): void;
48
+ }
49
+ declare function useStepEditor<TStep extends Step = Step>(): StepEditorWrapper<TStep>;
50
+ declare function StepEditorWrapperContext(props: {
51
+ children: JSX.Element;
52
+ step: Step;
53
+ context: StepEditorContext;
54
+ }): JSX.Element;
55
+
56
+ export { GlobalEditorWrapper, GlobalEditorWrapperContext, 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.8.0",
5
- "main": "./lib/index.js",
4
+ "version": "0.8.1",
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,20 +36,18 @@
23
36
  "scripts": {
24
37
  "prepare": "cp ../LICENSE LICENSE",
25
38
  "clean": "rm -rf lib",
26
- "start": "tsc --watch",
27
- "build": "yarn clean && tsc",
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
45
  "test": "jest --watchAll"
33
46
  },
34
- "dependencies": {
35
- "react": "^18.2.0",
36
- "react-dom": "^18.2.0"
37
- },
38
47
  "peerDependencies": {
39
- "sequential-workflow-designer": "^0.8.0"
48
+ "react": "^18.2.0",
49
+ "react-dom": "^18.2.0",
50
+ "sequential-workflow-designer": "^0.8.1"
40
51
  },
41
52
  "devDependencies": {
42
53
  "@typescript-eslint/eslint-plugin": "^5.47.0",
@@ -50,6 +61,10 @@
50
61
  "@types/jest": "^29.2.5",
51
62
  "ts-jest": "^29.0.3",
52
63
  "prettier": "^2.8.2",
64
+ "rollup": "^3.18.0",
65
+ "rollup-plugin-dts": "^5.2.0",
66
+ "rollup-plugin-typescript2": "^0.34.1",
67
+ "@rollup/plugin-node-resolve": "^15.0.1",
53
68
  "typescript": "^4.9.4"
54
69
  },
55
70
  "keywords": [
@@ -62,4 +77,4 @@
62
77
  "react",
63
78
  "reactjs"
64
79
  ]
65
- }
80
+ }
@@ -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,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;
@@ -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>;
@@ -1,6 +0,0 @@
1
- export function wrapDefinition(value, isValid) {
2
- return {
3
- value: value,
4
- isValid: isValid
5
- };
6
- }
package/lib/index.js DELETED
@@ -1,4 +0,0 @@
1
- export * from './GlobalEditorWrapper';
2
- export * from './SequentialWorkflowDesigner';
3
- export * from './StepEditorWrapper';
4
- export * from './WrappedDefinition';