diff --git a/CHANGELOG.md b/CHANGELOG.md index 99627b6..ce6b2a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## O.14.7 + +Added an `index` argument to the `itemComponentFactory` callback in the `dynamicListComponent` function. + ## O.14.6 Added comments to describe the `BranchedStepModelBuilder`, `SequentialStepModelBuilder` and `RootModelBuilder` classes. diff --git a/README.md b/README.md index 68f2dda..cabc449 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Pro: * [📖 Pro Editors](https://nocode-js.com/examples/sequential-workflow-editor-pro/webpack-pro-app/public/editors.html) * [📫 Template System](https://nocode-js.com/examples/sequential-workflow-editor-pro/webpack-pro-app/public/template-system.html) +* [🎱 Dynamic Variables](https://nocode-js.com/examples/sequential-workflow-editor-pro/webpack-pro-app/public/dynamic-variables.html) ## 🚀 Installation diff --git a/demos/webpack-app/package.json b/demos/webpack-app/package.json index 56b5092..d7f9bde 100644 --- a/demos/webpack-app/package.json +++ b/demos/webpack-app/package.json @@ -18,8 +18,8 @@ "sequential-workflow-model": "^0.2.0", "sequential-workflow-designer": "^0.21.2", "sequential-workflow-machine": "^0.4.0", - "sequential-workflow-editor-model": "^0.14.6", - "sequential-workflow-editor": "^0.14.6" + "sequential-workflow-editor-model": "^0.14.7", + "sequential-workflow-editor": "^0.14.7" }, "devDependencies": { "ts-loader": "^9.4.2", diff --git a/editor/package.json b/editor/package.json index 2c0a550..ca83ae4 100644 --- a/editor/package.json +++ b/editor/package.json @@ -1,6 +1,6 @@ { "name": "sequential-workflow-editor", - "version": "0.14.6", + "version": "0.14.7", "type": "module", "main": "./lib/esm/index.js", "types": "./lib/index.d.ts", @@ -46,11 +46,11 @@ "prettier:fix": "prettier --write ./src ./css" }, "dependencies": { - "sequential-workflow-editor-model": "^0.14.6", + "sequential-workflow-editor-model": "^0.14.7", "sequential-workflow-model": "^0.2.0" }, "peerDependencies": { - "sequential-workflow-editor-model": "^0.14.6", + "sequential-workflow-editor-model": "^0.14.7", "sequential-workflow-model": "^0.2.0" }, "devDependencies": { diff --git a/editor/src/components/dynamic-list-component.spec.ts b/editor/src/components/dynamic-list-component.spec.ts index b7a2105..b97b004 100644 --- a/editor/src/components/dynamic-list-component.spec.ts +++ b/editor/src/components/dynamic-list-component.spec.ts @@ -1,4 +1,4 @@ -import { SimpleEvent, ValueContext } from 'sequential-workflow-editor-model'; +import { I18n, SimpleEvent, ValueContext } from 'sequential-workflow-editor-model'; import { Html } from '../core/html'; import { dynamicListComponent } from './dynamic-list-component'; @@ -6,11 +6,13 @@ interface TestItem { id: number; } -function testItemComponentFactory(item: TestItem) { +function testItemComponentFactory(item: TestItem, _: I18n, index: number) { + const view = Html.element('span', { + class: `test-item-${item.id}` + }); + view.setAttribute('data-index', String(index)); return { - view: Html.element('span', { - class: `test-item-${item.id}` - }), + view, onItemChanged: new SimpleEvent(), onDeleteClicked: new SimpleEvent(), validate: () => { @@ -32,7 +34,9 @@ describe('DynamicListComponent', () => { expect(children.length).toBe(3); expect(children[0].className).toBe('test-item-123'); + expect(children[0].getAttribute('data-index')).toBe('0'); expect(children[1].className).toBe('test-item-456'); + expect(children[1].getAttribute('data-index')).toBe('1'); expect(children[2].className).toBe('swe-validation-error'); }); @@ -47,13 +51,16 @@ describe('DynamicListComponent', () => { expect(children.length).toBe(2); expect(children[0].className).toBe('test-item-135'); + expect(children[0].getAttribute('data-index')).toBe('0'); expect(children[1].className).toBe('swe-validation-error'); component.add({ id: 246 }); expect(children.length).toBe(3); expect(children[0].className).toBe('test-item-135'); + expect(children[0].getAttribute('data-index')).toBe('0'); expect(children[1].className).toBe('test-item-246'); + expect(children[1].getAttribute('data-index')).toBe('1'); expect(children[2].className).toBe('swe-validation-error'); }); diff --git a/editor/src/components/dynamic-list-component.ts b/editor/src/components/dynamic-list-component.ts index 8ad0c10..0b19a78 100644 --- a/editor/src/components/dynamic-list-component.ts +++ b/editor/src/components/dynamic-list-component.ts @@ -23,7 +23,7 @@ export interface DynamicListItemComponent extends Component { export function dynamicListComponent = DynamicListItemComponent>( initialItems: TItem[], - itemComponentFactory: (item: TItem, i18n: I18n) => TItemComponent, + itemComponentFactory: (item: TItem, i18n: I18n, index: number) => TItemComponent, context: ValueContext, configuration?: DynamicListComponentConfiguration ): DynamicListComponent { @@ -74,7 +74,7 @@ export function dynamicListComponent 0) { items.forEach((item, index) => { - const component = itemComponentFactory(item, context.i18n); + const component = itemComponentFactory(item, context.i18n, index); component.onItemChanged.subscribe(item => onItemChanged(item, index)); component.onDeleteClicked.subscribe(() => onItemDeleted(index)); view.insertBefore(component.view, validation.view); diff --git a/model/package.json b/model/package.json index b0a4614..97bd892 100644 --- a/model/package.json +++ b/model/package.json @@ -1,6 +1,6 @@ { "name": "sequential-workflow-editor-model", - "version": "0.14.6", + "version": "0.14.7", "homepage": "https://nocode-js.com/", "author": { "name": "NoCode JS",