|
| 1 | + |
| 2 | + |
| 3 | +# Sequential Workflow Designer for Angular |
| 4 | + |
| 5 | +[](https://actions-badge.atrox.dev/b4rtaz/sequential-workflow-designer/goto?ref=main) [](/LICENSE) [](https://npmjs.org/package/sequential-workflow-designer-angular) |
| 6 | + |
| 7 | +Angular wrapper for the [Sequential Workflow Designer](https://github.com/nocode-js/sequential-workflow-designer) component. |
| 8 | + |
| 9 | +## 🚀 Installation |
| 10 | + |
| 11 | +Install the following packages by [NPM](https://www.npmjs.com/) command: |
| 12 | + |
| 13 | +`npm i sequential-workflow-designer sequential-workflow-designer-angular` |
| 14 | + |
| 15 | +Add CSS files to your `angular.json` file. |
| 16 | + |
| 17 | +```json |
| 18 | +{ |
| 19 | + "projects": { |
| 20 | + "YOUR_APP": { |
| 21 | + "architect": { |
| 22 | + "build": { |
| 23 | + "styles": [ |
| 24 | + "./node_modules/sequential-workflow-designer/css/designer.css", |
| 25 | + "./node_modules/sequential-workflow-designer/css/designer-light.css", |
| 26 | + "./node_modules/sequential-workflow-designer/css/designer-dark.css" |
| 27 | + ] |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +## 🎬 Usage |
| 36 | + |
| 37 | +Import the module: |
| 38 | + |
| 39 | +```ts |
| 40 | +import { SequentialWorkflowDesignerModule } from 'sequential-workflow-designer-angular'; |
| 41 | + |
| 42 | +@NgModule({ |
| 43 | + imports: [ |
| 44 | + SequentialWorkflowDesignerModule, |
| 45 | + // ... |
| 46 | + ], |
| 47 | + // ... |
| 48 | +}) |
| 49 | +export class AppModule {} |
| 50 | +``` |
| 51 | + |
| 52 | +Define a definition and a configuration. |
| 53 | + |
| 54 | +```ts |
| 55 | +export class AppComponent { |
| 56 | + private designer?: Designer; |
| 57 | + public definition: Definition = { /* ... */ }; |
| 58 | + public toolboxConfiguration: ToolboxConfiguration = { /* ... */ }; |
| 59 | + public stepsConfiguration: StepsConfiguration = { /* ... */ }; |
| 60 | + // ... |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +Define the following methods to handle the designer's events. |
| 65 | + |
| 66 | +```ts |
| 67 | +export class AppComponent { |
| 68 | + //... |
| 69 | + public onDesignerReady(designer: Designer) { |
| 70 | + this.designer = designer; |
| 71 | + } |
| 72 | + |
| 73 | + public onDefinitionChanged(definition: Definition) { |
| 74 | + this.definition = definition; |
| 75 | + } |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +Additionally we need to define a few utils methods to handle the editor's logic. |
| 80 | + |
| 81 | +```ts |
| 82 | +export class AppComponent { |
| 83 | + // ... |
| 84 | + public updateName(step: Step, event: Event, context: StepEditorContext) { |
| 85 | + step.name = (event.target as HTMLInputElement).value; |
| 86 | + context.notifyNameChanged(); |
| 87 | + } |
| 88 | + |
| 89 | + public updateProperty(properties: Properties, name: string, event: Event, context: GlobalEditorContext | StepEditorContext) { |
| 90 | + properties[name] = (event.target as HTMLInputElement).value; |
| 91 | + context.notifyPropertiesChanged(); |
| 92 | + } |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +Create a template for the global editor. The value of the `editor` variable implements the `GlobalEditorWrapper` interface. |
| 97 | + |
| 98 | +```html |
| 99 | +<ng-template #globalEditor let-editor> |
| 100 | + <h2>Global Editor</h2> |
| 101 | + |
| 102 | + <h3>Velocity</h3> |
| 103 | + <input type="number" |
| 104 | + [value]="editor.definition.properties.velocity" |
| 105 | + (input)="updateProperty(editor.definition.properties, 'velocity', $event, editor.context)" /> |
| 106 | +</ng-template> |
| 107 | +``` |
| 108 | + |
| 109 | +```ts |
| 110 | +interface GlobalEditorWrapper { |
| 111 | + definition: Definition; |
| 112 | + context: GlobalEditorContext; |
| 113 | +} |
| 114 | +``` |
| 115 | + |
| 116 | +Create a template for the step editor. The value of the `editor` variable implements the `StepEditorWrapper` interface. |
| 117 | + |
| 118 | +```html |
| 119 | +<ng-template #stepEditor let-editor> |
| 120 | + <h2>Step Editor</h2> |
| 121 | + |
| 122 | + <h3>Name</h3> |
| 123 | + <input type="text" |
| 124 | + [value]="editor.step.name" |
| 125 | + (input)="updateName(editor.step, $event, editor.context)" /> |
| 126 | + |
| 127 | + <h3>Velocity</h3> |
| 128 | + <input type="number" |
| 129 | + [value]="editor.step.properties.velocity" |
| 130 | + (input)="updateProperty(editor.step.properties, 'velocity', $event, editor.context)" /> |
| 131 | +</ng-template> |
| 132 | +``` |
| 133 | + |
| 134 | +```ts |
| 135 | +interface StepEditorWrapper { |
| 136 | + step: Step; |
| 137 | + context: StepEditorContext; |
| 138 | +} |
| 139 | +``` |
| 140 | + |
| 141 | +At the end attach the designer: |
| 142 | + |
| 143 | +```html |
| 144 | +<sqd-designer |
| 145 | + theme="light" |
| 146 | + [undoStackSize]="10" |
| 147 | + [definition]="startDefinition" |
| 148 | + [toolboxConfiguration]="toolboxConfiguration" |
| 149 | + [stepsConfiguration]="stepsConfiguration" |
| 150 | + [areEditorsHidden]="false" |
| 151 | + [globalEditor]="globalEditor" |
| 152 | + [stepEditor]="stepEditor" |
| 153 | + (onReady)="onDesignerReady($event)" |
| 154 | + (onDefinitionChanged)="onDefinitionChanged($event)"> |
| 155 | +</sqd-designer> |
| 156 | +``` |
| 157 | + |
| 158 | +Check the [demo project](https://github.com/nocode-js/sequential-workflow-designer/tree/main/demos/angular-app). |
| 159 | + |
| 160 | +## 💡 License |
| 161 | + |
| 162 | +This project is released under the MIT license. |
0 commit comments