|
| 1 | +<script lang="ts"> |
| 2 | + import type { Definition, StepsConfiguration, ToolboxConfiguration, ValidatorConfiguration } from 'sequential-workflow-designer'; |
| 3 | + import { SequentialWorkflowDesigner } from 'sequential-workflow-designer-svelte'; |
| 4 | + import StepEditor from './step-editor.svelte'; |
| 5 | + import RootEditor from './root-editor.svelte'; |
| 6 | + import './style.css'; |
| 7 | +
|
| 8 | + let definition = createDefinition(); |
| 9 | + let isReadonly = false; |
| 10 | + let isToolboxCollapsed = false; |
| 11 | + let isEditorCollapsed = false; |
| 12 | + let selectedStepId: string | null = null; |
| 13 | + let isValid: boolean | null = null; |
| 14 | + const steps: StepsConfiguration = {}; |
| 15 | + const validator: ValidatorConfiguration = { |
| 16 | + step: (step) => step.name.length > 0 |
| 17 | + }; |
| 18 | + const toolbox: ToolboxConfiguration = { |
| 19 | + groups: [ |
| 20 | + { |
| 21 | + name: 'Steps', |
| 22 | + steps: [createStep()] |
| 23 | + } |
| 24 | + ] |
| 25 | + }; |
| 26 | +
|
| 27 | + function randId() { |
| 28 | + return Math.round((Math.random() * 1000000)).toString(16); |
| 29 | + } |
| 30 | +
|
| 31 | + function createStep() { |
| 32 | + return { |
| 33 | + id: randId(), |
| 34 | + type: 'step', |
| 35 | + name: 'test', |
| 36 | + componentType: 'task', |
| 37 | + properties: { |
| 38 | + comment: 'Some comment' |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | +
|
| 43 | + function createDefinition(): Definition { |
| 44 | + return { |
| 45 | + properties: { |
| 46 | + velocity: 20 |
| 47 | + }, |
| 48 | + sequence: [ |
| 49 | + createStep(), |
| 50 | + createStep() |
| 51 | + ] |
| 52 | + }; |
| 53 | + } |
| 54 | +
|
| 55 | + function onDefinitionChanged({ detail }: { detail: { definition: Definition, isValid: boolean } }) { |
| 56 | + definition = detail.definition; |
| 57 | + isValid = detail.isValid; |
| 58 | + } |
| 59 | +
|
| 60 | + function onSelectedStepIdChanged({ detail }: { detail: { stepId: string | null } }) { |
| 61 | + selectedStepId = detail.stepId; |
| 62 | + } |
| 63 | +
|
| 64 | + function toggleReadonly() { |
| 65 | + isReadonly = !isReadonly; |
| 66 | + } |
| 67 | +
|
| 68 | + function toggleSelection() { |
| 69 | + if (selectedStepId) { |
| 70 | + selectedStepId = null; |
| 71 | + } else if (definition.sequence.length > 0) { |
| 72 | + selectedStepId = definition.sequence[0].id; |
| 73 | + } |
| 74 | + } |
| 75 | +
|
| 76 | + function toggleEditor() { |
| 77 | + isEditorCollapsed = !isEditorCollapsed; |
| 78 | + } |
| 79 | +
|
| 80 | + function toggleToolbox() { |
| 81 | + isToolboxCollapsed = !isToolboxCollapsed; |
| 82 | + } |
| 83 | +
|
| 84 | + function resetDefinition() { |
| 85 | + definition = createDefinition(); |
| 86 | + } |
| 87 | +</script> |
| 88 | + |
| 89 | +<SequentialWorkflowDesigner |
| 90 | + definition={definition} |
| 91 | + on:definitionChanged={onDefinitionChanged} |
| 92 | + steps={steps} |
| 93 | + validator={validator} |
| 94 | + toolbox={toolbox} |
| 95 | + stepEditor={StepEditor} |
| 96 | + rootEditor={RootEditor} |
| 97 | + selectedStepId={selectedStepId} |
| 98 | + on:selectedStepIdChanged={onSelectedStepIdChanged} |
| 99 | + isToolboxCollapsed={isToolboxCollapsed} |
| 100 | + isEditorCollapsed={isEditorCollapsed} |
| 101 | + isReadonly={isReadonly} /> |
| 102 | + |
| 103 | +<div class="block"> |
| 104 | + <button on:click={toggleReadonly}>Toggle readonly</button> |
| 105 | + |
| 106 | + <button on:click={toggleSelection}>Toggle selection</button> |
| 107 | + |
| 108 | + <button on:click={resetDefinition}>Reset definition</button> |
| 109 | + |
| 110 | + <button on:click={toggleEditor}>Toggle editor</button> |
| 111 | + |
| 112 | + <button on:click={toggleToolbox}>Toggle toolbox</button> |
| 113 | +</div> |
| 114 | + |
| 115 | +<div class="block"> |
| 116 | + Is valid: <strong>{isValid}</strong> |
| 117 | + Selected step: <strong>{selectedStepId}</strong> |
| 118 | +</div> |
| 119 | + |
| 120 | +<div class="block"> |
| 121 | + This demo uses Svelte and <a href="https://github.com/nocode-js/sequential-workflow-designer/tree/main/svelte">Sequential Workflow Designer for Svelte</a>. |
| 122 | +</div> |
0 commit comments