Skip to content

Commit

Permalink
0.13.2. (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz committed May 31, 2023
1 parent b7db804 commit e601031
Show file tree
Hide file tree
Showing 19 changed files with 276 additions and 139 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## 0.13.2

The react package supports two types of editor providers. Now it's possible to use a provider that returns native DOM elements. We don't want to depreciate the previous approach, this change increases flexibility of the react package.

```tsx
// 1. custom react component
<SequentialWorkflowDesigner stepEditor={<StepEditor />} ... />

// 2. native editor provider
function stepEditorProvider(step) {
const editor = document.createElement('div'); /* ... */
return editor;
}
<SequentialWorkflowDesigner stepEditor={stepEditorProvider}> ... />
```

## 0.13.1

The `canMoveStep` callback is not called when the step is moved to the same position.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ Add the below code to your head section in HTML document.
```html
<head>
...
<link href="https://cdn.jsdelivr.net/npm/sequential-workflow-designer@0.13.1/css/designer.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/sequential-workflow-designer@0.13.1/css/designer-light.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/sequential-workflow-designer@0.13.1/css/designer-dark.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/sequential-workflow-designer@0.13.1/dist/index.umd.js"></script>
<link href="https://cdn.jsdelivr.net/npm/sequential-workflow-designer@0.13.2/css/designer.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/sequential-workflow-designer@0.13.2/css/designer-light.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/sequential-workflow-designer@0.13.2/css/designer-dark.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/sequential-workflow-designer@0.13.2/dist/index.umd.js"></script>
```

Call the designer by:
Expand Down
4 changes: 2 additions & 2 deletions angular/designer/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sequential-workflow-designer-angular",
"description": "Angular wrapper for Sequential Workflow Designer component.",
"version": "0.13.1",
"version": "0.13.2",
"author": {
"name": "NoCode JS",
"url": "https://nocode-js.com/"
Expand All @@ -15,7 +15,7 @@
"peerDependencies": {
"@angular/common": "12 - 16",
"@angular/core": "12 - 16",
"sequential-workflow-designer": "^0.13.1"
"sequential-workflow-designer": "^0.13.2"
},
"dependencies": {
"tslib": "^2.3.0"
Expand Down
4 changes: 2 additions & 2 deletions demos/angular-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"@angular/platform-browser-dynamic": "^15.2.2",
"@angular/router": "^15.2.2",
"rxjs": "~7.8.0",
"sequential-workflow-designer": "^0.13.1",
"sequential-workflow-designer-angular": "^0.13.1",
"sequential-workflow-designer": "^0.13.2",
"sequential-workflow-designer-angular": "^0.13.2",
"tslib": "^2.3.0",
"zone.js": "~0.13.0"
},
Expand Down
16 changes: 8 additions & 8 deletions demos/angular-app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5180,17 +5180,17 @@ send@0.18.0:
range-parser "~1.2.1"
statuses "2.0.1"

sequential-workflow-designer-angular@^0.13.1:
version "0.13.1"
resolved "https://registry.yarnpkg.com/sequential-workflow-designer-angular/-/sequential-workflow-designer-angular-0.13.1.tgz#a8acbd9bd442a1260f7fe7840e3b97c576309bb6"
integrity sha512-p29YekTS5DIrl6ZmZpiLtvrhF5pqs3pilxzAXg++38RgjStU7wuCHbrQMO0wkGWVcuUHweMZV8Yw23PSHJhxUw==
sequential-workflow-designer-angular@^0.13.2:
version "0.13.2"
resolved "https://registry.yarnpkg.com/sequential-workflow-designer-angular/-/sequential-workflow-designer-angular-0.13.2.tgz#c61f23470390b46fa99c19fc02c8b0e7b3f44755"
integrity sha512-kWF4vLxlKI0CJPoATV9jrIfULBrLzLpbrSBYO2MgsSk6zLB5LmyBQ3c1qA/if11kn0MEAWbVBwgZubp5DduFLA==
dependencies:
tslib "^2.3.0"

sequential-workflow-designer@^0.13.1:
version "0.13.1"
resolved "https://registry.yarnpkg.com/sequential-workflow-designer/-/sequential-workflow-designer-0.13.1.tgz#332c5324895dd63c350a14a7de418d2f4b9a70ff"
integrity sha512-Jw/eFRC3GB4FVH6DbpRGqmQT1usQVP+s00uGcS5b+AozmhewTk/Hf1EJS9NTlknYchGbiQ3Dw6rUZqBav5/iaA==
sequential-workflow-designer@^0.13.2:
version "0.13.2"
resolved "https://registry.yarnpkg.com/sequential-workflow-designer/-/sequential-workflow-designer-0.13.2.tgz#db762be8f789a7765529c273f1533a3cdb4cd7ca"
integrity sha512-bhx5Pobi5WQ1mtvsqXwdE1+2Kn1t3PBrJz8NPtvTTL2AfdQHgKl/DHVmWxN8J1g7D4KbyhdfFXwYETldtO2EKg==
dependencies:
sequential-workflow-model "^0.1.3"

Expand Down
4 changes: 2 additions & 2 deletions demos/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sequential-workflow-designer": "^0.13.1",
"sequential-workflow-designer-react": "^0.13.1"
"sequential-workflow-designer": "^0.13.2",
"sequential-workflow-designer-react": "^0.13.2"
},
"devDependencies": {
"@types/jest": "^29.2.5",
Expand Down
116 changes: 20 additions & 96 deletions demos/react-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,107 +1,31 @@
import { useEffect, useState } from 'react';
import { ObjectCloner, Step, StepsConfiguration, ToolboxConfiguration, ValidatorConfiguration } from 'sequential-workflow-designer';
import { SequentialWorkflowDesigner, wrapDefinition } from 'sequential-workflow-designer-react';
import { GlobalEditor } from './GlobalEditor';
import { StepEditor } from './StepEditor';
import { createSwitchStep, createTaskStep } from './StepUtils';
import { WorkflowDefinition } from './model';
import { useSequentialWorkflowDesignerController } from 'sequential-workflow-designer-react';
import { useState } from 'react';
import { Playground } from './playground/Playground';
import { NativeEditors } from './nativeEditors/NativeEditors';

const startDefinition: WorkflowDefinition = {
properties: {
alfa: 'bravo'
},
sequence: [createTaskStep(), createSwitchStep()]
};

const toolboxConfiguration: ToolboxConfiguration = {
groups: [{ name: 'Steps', steps: [createTaskStep(), createSwitchStep()] }]
};

const stepsConfiguration: StepsConfiguration = {
iconUrlProvider: () => null
};

const validatorConfiguration: ValidatorConfiguration = {
step: (step: Step) => Boolean(step.name),
root: (definition: WorkflowDefinition) => Boolean(definition.properties.alfa)
};
const pathKey = 'swdReactPath';
type AppPath = 'playground' | 'nativeEditors';

export function App() {
const controller = useSequentialWorkflowDesignerController();
const [isVisible, setIsVisible] = useState(true);
const [definition, setDefinition] = useState(() => wrapDefinition(startDefinition));
const [selectedStepId, setSelectedStepId] = useState<string | null>(null);
const [isReadonly, setIsReadonly] = useState(false);
const definitionJson = JSON.stringify(definition.value, null, 2);

useEffect(() => {
console.log(`definition updated, isValid=${definition.isValid}`);
}, [definition]);

function toggleVisibilityClicked() {
setIsVisible(!isVisible);
}

function toggleSelectionClicked() {
const id = definition.value.sequence[0].id;
setSelectedStepId(selectedStepId ? null : id);
}
const [path, setPath] = useState<AppPath>((localStorage[pathKey] as AppPath) || 'playground');

function toggleIsReadonlyClicked() {
setIsReadonly(!isReadonly);
}

function moveViewportToFirstStepClicked() {
const fistStep = definition.value.sequence[0];
if (fistStep) {
controller.moveViewportToStep(fistStep.id);
}
}

function reloadDefinitionClicked() {
const newDefinition = ObjectCloner.deepClone(startDefinition);
setDefinition(wrapDefinition(newDefinition));
function changePath(path: AppPath) {
localStorage[pathKey] = path;
setPath(path);
}

return (
<>
{isVisible && (
<SequentialWorkflowDesigner
undoStackSize={10}
definition={definition}
onDefinitionChange={setDefinition}
selectedStepId={selectedStepId}
isReadonly={isReadonly}
onSelectedStepIdChanged={setSelectedStepId}
toolboxConfiguration={toolboxConfiguration}
stepsConfiguration={stepsConfiguration}
validatorConfiguration={validatorConfiguration}
controlBar={true}
globalEditor={<GlobalEditor />}
stepEditor={<StepEditor />}
controller={controller}
/>
)}

<ul>
<li>Definition: {definitionJson.length} bytes</li>
<li>Selected step: {selectedStepId}</li>
<li>Is readonly: {isReadonly ? '✅ Yes' : 'No'}</li>
<li>Is valid: {definition.isValid === undefined ? '?' : definition.isValid ? '✅ Yes' : '⛔ No'}</li>
</ul>

<div>
<button onClick={toggleVisibilityClicked}>Toggle visibility</button>
<button onClick={reloadDefinitionClicked}>Reload definition</button>
<button onClick={toggleSelectionClicked}>Toggle selection</button>
<button onClick={toggleIsReadonlyClicked}>Toggle readonly</button>
<button onClick={moveViewportToFirstStepClicked}>Move viewport to first step</button>
</div>

<div>
<textarea value={definitionJson} readOnly={true} cols={100} rows={15} />
</div>
<nav>
<h1>SWD for React Demo</h1>
<button onClick={() => changePath('playground')} className={path === 'playground' ? 'selected' : ''}>
Playground
</button>
<button onClick={() => changePath('nativeEditors')} className={path === 'nativeEditors' ? 'selected' : ''}>
Native editors
</button>
</nav>
{path === 'playground' && <Playground />}
{path === 'nativeEditors' && <NativeEditors />}
</>
);
}
29 changes: 28 additions & 1 deletion demos/react-app/src/index.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
body {
body,
h1 {
font: 13px/1.3em Arial, Verdana, Serif;
}
body {
margin: 0;
padding: 0;
}

nav {
padding: 10px 5px 0;
background: #333;
}
nav h1 {
display: inline-block;
margin: 0 15px;
padding: 0;
color: #fff;
}
nav button {
background: #999;
border: 0;
padding: 10px 15px;
margin: 0 5px;
cursor: pointer;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
nav button.selected {
background: #f9f9f9;
}
nav button:hover {
opacity: 0.8;
}

.sqd-designer-react {
width: 100vw;
height: 50vh;
Expand Down
55 changes: 55 additions & 0 deletions demos/react-app/src/nativeEditors/NativeEditors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { useState } from 'react';
import { Definition, Step, StepEditorContext } from 'sequential-workflow-designer';
import { SequentialWorkflowDesigner, wrapDefinition } from 'sequential-workflow-designer-react';

export const startDefinition: Definition = {
sequence: [
{
id: '0x1',
componentType: 'task',
name: 'Foo',
properties: {},
type: 'test'
}
],
properties: {}
};

function globalEditorProvider(): HTMLElement {
const editor = document.createElement('div');
editor.innerHTML = 'Global editor';
return editor;
}

function stepEditorProvider(step: Step, context: StepEditorContext): HTMLElement {
const editor = document.createElement('div');
const title = document.createElement('h2');
title.innerText = `Edit ${step.type} step`;
editor.appendChild(title);
const nameInput = document.createElement('input');
nameInput.value = step.name;
nameInput.addEventListener('input', () => {
step.name = nameInput.value;
context.notifyNameChanged();
});
editor.appendChild(nameInput);
return editor;
}

export function NativeEditors() {
const [definition, setDefinition] = useState(() => wrapDefinition(startDefinition));

return (
<>
<SequentialWorkflowDesigner
definition={definition}
onDefinitionChange={setDefinition}
toolboxConfiguration={false}
stepsConfiguration={{}}
controlBar={true}
globalEditor={globalEditorProvider}
stepEditor={stepEditorProvider}
/>
</>
);
}
File renamed without changes.
Loading

0 comments on commit e601031

Please sign in to comment.