diff --git a/CHANGELOG.md b/CHANGELOG.md index 59b8cdb4..b4f1ea2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,22 @@ +# 0.33.0 + +This version introduces a new restriction callback: `canUnselectStep`. You can now prevent a step from being unselected based on your custom logic. When an unselection is blocked, the `onStepUnselectionBlocked` event is triggered. + +```ts +const configuration = { + steps: { + canUnselectStep: (step, parentSequence) => { + return areChangesSaved() === true; + }, + }, + // ... +}; + +designer.onStepUnselectionBlocked((targetStepId) => { /* ... */ }); +``` + +Please note that you should NOT use `window.confirm()` or other blocking functions inside the `canUnselectStep` callback, as this callback may be invoked multiple times during drag operations. To handle this correctly, implement your own UI logic to notify the user about any required actions before unselection can proceed. Please check [this example](https://nocode-js.github.io/sequential-workflow-designer/react-app/#save-required-editor). + # 0.32.0 This introduces internal changes related to the dragged component. diff --git a/README.md b/README.md index c26fdf8f..a031221c 100644 --- a/README.md +++ b/README.md @@ -106,10 +106,10 @@ Add the below code to your head section in HTML document. ```html ... - - - - + + + + ``` Call the designer by: diff --git a/angular/designer/package.json b/angular/designer/package.json index 354f1a60..c70b1dde 100644 --- a/angular/designer/package.json +++ b/angular/designer/package.json @@ -1,7 +1,7 @@ { "name": "sequential-workflow-designer-angular", "description": "Angular wrapper for Sequential Workflow Designer component.", - "version": "0.32.0", + "version": "0.33.0", "author": { "name": "NoCode JS", "url": "https://nocode-js.com/" @@ -15,7 +15,7 @@ "peerDependencies": { "@angular/common": "12 - 19", "@angular/core": "12 - 19", - "sequential-workflow-designer": "^0.32.0" + "sequential-workflow-designer": "^0.33.0" }, "dependencies": { "tslib": "^2.3.0" diff --git a/angular/designer/src/designer.component.ts b/angular/designer/src/designer.component.ts index 64dc9a6e..9c394c4e 100644 --- a/angular/designer/src/designer.component.ts +++ b/angular/designer/src/designer.component.ts @@ -113,6 +113,8 @@ export class DesignerComponent implements AfterViewInit, OnChanges, OnDestroy { @Output() public readonly onSelectedStepIdChanged = new EventEmitter(); @Output() + public readonly onStepUnselectionBlocked = new EventEmitter(); + @Output() public readonly onIsToolboxCollapsedChanged = new EventEmitter(); @Output() public readonly onIsEditorCollapsedChanged = new EventEmitter(); @@ -243,6 +245,9 @@ export class DesignerComponent implements AfterViewInit, OnChanges, OnDestroy { designer.onSelectedStepIdChanged.subscribe(stepId => { this.ngZone.run(() => this.onSelectedStepIdChanged.emit(stepId)); }); + designer.onStepUnselectionBlocked.subscribe(targetStepId => { + this.ngZone.run(() => this.onStepUnselectionBlocked.emit(targetStepId)); + }); designer.onIsToolboxCollapsedChanged.subscribe(isCollapsed => { this.ngZone.run(() => this.onIsToolboxCollapsedChanged.emit(isCollapsed)); }); diff --git a/demos/angular-app/package.json b/demos/angular-app/package.json index d7d078ef..5359fe5a 100644 --- a/demos/angular-app/package.json +++ b/demos/angular-app/package.json @@ -26,8 +26,8 @@ "@angular/platform-browser-dynamic": "^17.3.9", "@angular/router": "^17.3.9", "rxjs": "~7.8.0", - "sequential-workflow-designer": "^0.32.0", - "sequential-workflow-designer-angular": "^0.32.0", + "sequential-workflow-designer": "^0.33.0", + "sequential-workflow-designer-angular": "^0.33.0", "tslib": "^2.3.0", "zone.js": "~0.14.6" }, diff --git a/demos/react-app/package.json b/demos/react-app/package.json index 61257693..1e47bf71 100644 --- a/demos/react-app/package.json +++ b/demos/react-app/package.json @@ -6,8 +6,8 @@ "dependencies": { "react": "^18.2.0", "react-dom": "^18.2.0", - "sequential-workflow-designer": "^0.32.0", - "sequential-workflow-designer-react": "^0.32.0" + "sequential-workflow-designer": "^0.33.0", + "sequential-workflow-designer-react": "^0.33.0" }, "devDependencies": { "@types/jest": "^29.2.5", diff --git a/demos/react-app/src/App.tsx b/demos/react-app/src/App.tsx index 4b156654..3979298e 100644 --- a/demos/react-app/src/App.tsx +++ b/demos/react-app/src/App.tsx @@ -1,34 +1,53 @@ import { useState } from 'react'; import { Playground } from './playground/Playground'; import { NativeEditors } from './nativeEditors/NativeEditors'; +import { SaveRequiredEditor } from './saveRequiredEditor/SaveRequiredEditor'; -const pathKey = 'swdReactPath'; -type AppPath = 'playground' | 'nativeEditors'; +const TABS = [ + { + label: '🍭 Playground', + path: 'playground' + }, + { + label: 'πŸ”Œ Native Editors', + path: 'native-editors' + }, + { + label: 'πŸ”΄ Save Required Editor', + path: 'save-required-editor' + } +]; export function App() { - const [path, setPath] = useState((localStorage[pathKey] as AppPath) || 'playground'); + const [path, setPath] = useState(window.location.hash?.substring(1) || 'playground'); - function changePath(path: AppPath) { - localStorage[pathKey] = path; + function changePath(path: string) { + window.location.hash = path; setPath(path); } return ( <> -