From 596b0ad8585a734b338a622eda0d90d8d11ce009 Mon Sep 17 00:00:00 2001 From: Titouan Mathis Date: Tue, 10 Sep 2024 08:51:34 +0200 Subject: [PATCH 1/7] Add a failing test --- packages/tests/__utils__/h.ts | 15 +++++++++ packages/tests/atoms/DataBind.spec.ts | 44 +++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/packages/tests/__utils__/h.ts b/packages/tests/__utils__/h.ts index ed8fffba..0ee0d43c 100644 --- a/packages/tests/__utils__/h.ts +++ b/packages/tests/__utils__/h.ts @@ -32,3 +32,18 @@ export function h( return el; } + +/** + * Connect the given element to a document instance in order + * to set its `isConnected` property to `true`. + */ +export function connectElement(element:T):T { + const doc = new Document(); + doc.append(element); + return element; +} + +/** + * Create an HTMLElement and connect it to a document. + */ +export const hConnected: typeof h = (...args) => connectElement(h(...args)); diff --git a/packages/tests/atoms/DataBind.spec.ts b/packages/tests/atoms/DataBind.spec.ts index a3fc3172..687201bd 100644 --- a/packages/tests/atoms/DataBind.spec.ts +++ b/packages/tests/atoms/DataBind.spec.ts @@ -1,6 +1,6 @@ import { it, describe, expect, vi } from 'vitest'; import { DataBind, DataComputed, DataEffect } from '@studiometa/ui'; -import { destroy, h, mount } from '#test-utils'; +import { destroy, hConnected as h, mount } from '#test-utils'; describe('The DataBind component', () => { it('should set the textContent of the root element', () => { @@ -151,8 +151,12 @@ describe('The DataBind component', () => { it('should dispatch value to other instances', async () => { const instance1 = new DataBind(h('div', { dataOptionName: 'a' }, ['foo'])); const instance2 = new DataBind(h('div', { dataOptionName: 'a' }, ['foo'])); - const instance3 = new DataComputed(h('div', { dataOptionName: 'a', dataOptionCompute: 'value + value' }, ['foofoo'])); - const instance4 = new DataEffect(h('div', { dataOptionName: 'a', dataOptionEffect: 'target.id = value', id: 'foo' })); + const instance3 = new DataComputed( + h('div', { dataOptionName: 'a', dataOptionCompute: 'value + value' }, ['foofoo']), + ); + const instance4 = new DataEffect( + h('div', { dataOptionName: 'a', dataOptionEffect: 'target.id = value', id: 'foo' }), + ); await mount(instance1, instance2, instance3, instance4); @@ -166,4 +170,38 @@ describe('The DataBind component', () => { expect(instance3.value).toBe('barbar'); expect(instance4.$el.id).toBe('bar'); }); + + it('should forget related instances not in the DOM anymore', async () => { + const fragment = new Document(); + const inputA = h('input', { + type: 'checkbox', + value: 'foo', + checked: '', + dataOptionName: 'checkbox[]', + }); + const inputB = h('input', { + type: 'checkbox', + value: 'bar', + checked: '', + dataOptionName: 'checkbox[]', + }); + fragment.append(inputA, inputB); + + const instanceA = new DataBind(inputA); + const instanceB = new DataBind(inputB); + + await mount(instanceA, instanceB); + + expect(inputA.isConnected).toBe(true); + expect(inputB.isConnected).toBe(true); + expect(instanceA.value).toEqual(['foo', 'bar']); + + inputB.replaceWith( + h('input', { type: 'checkbox', value: 'bar', dataOptionName: 'checkbox[]' }), + ); + + expect(inputA.isConnected).toBe(true); + expect(inputB.isConnected).toBe(false); + expect(instanceA.value).toEqual(['foo']); + }); }); From de945b1cc3d11f500089eaa863dcdbf17c9a1cc2 Mon Sep 17 00:00:00 2001 From: Titouan Mathis Date: Tue, 10 Sep 2024 08:52:33 +0200 Subject: [PATCH 2/7] Fix inconsistencies with removed DOM elements Fix #293 --- packages/ui/atoms/Data/DataBind.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/ui/atoms/Data/DataBind.ts b/packages/ui/atoms/Data/DataBind.ts index 8fd23117..7e1c83c5 100644 --- a/packages/ui/atoms/Data/DataBind.ts +++ b/packages/ui/atoms/Data/DataBind.ts @@ -3,7 +3,7 @@ import type { BaseConfig, BaseProps } from '@studiometa/js-toolkit'; import { isArray } from '@studiometa/js-toolkit/utils'; import { isInput, isCheckbox, isSelect } from './utils.js'; -const instances = new Map>(); +const groups = new Map>(); export interface DataBindProps extends BaseProps { $options: { @@ -24,11 +24,15 @@ export class DataBind extends Base Date: Tue, 10 Sep 2024 08:55:54 +0200 Subject: [PATCH 3/7] Update the changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67f1cb8c..5e0dc5a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Fixed + +- Fix inconsistencies with removed DOM elements ([#293](https://github.com/studiometa/ui/issues/293), [#294](https://github.com/studiometa/ui/pull/294), [de945b1](https://github.com/studiometa/ui/commit/de945b1)) + ## [v1.0.0-alpha.6](https://github.com/studiometa/ui/compare/1.0.0-alpha.5..1.0.0-alpha.6) (2024-08-27) ### Added From 45dcd6710fa7e76b123459e288f2beca72baf967 Mon Sep 17 00:00:00 2001 From: Titouan Mathis Date: Tue, 10 Sep 2024 08:56:58 +0200 Subject: [PATCH 4/7] Fix tests --- packages/tests/atoms/DataComputed.spec.ts | 2 +- packages/tests/atoms/DataEffect.spec.ts | 2 +- packages/tests/atoms/DataModel.spec.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/tests/atoms/DataComputed.spec.ts b/packages/tests/atoms/DataComputed.spec.ts index 5a5ee5df..2652a695 100644 --- a/packages/tests/atoms/DataComputed.spec.ts +++ b/packages/tests/atoms/DataComputed.spec.ts @@ -1,7 +1,7 @@ import { it, describe, expect, vi } from 'vitest'; import { Base } from '@studiometa/js-toolkit'; import { DataComputed } from '@studiometa/ui'; -import { h } from '#test-utils'; +import { hConnected as h, } from '#test-utils'; describe('The DataModel component', () => { it('should set the value as the returned value from the compute option', () => { diff --git a/packages/tests/atoms/DataEffect.spec.ts b/packages/tests/atoms/DataEffect.spec.ts index 208cccd9..454b80bb 100644 --- a/packages/tests/atoms/DataEffect.spec.ts +++ b/packages/tests/atoms/DataEffect.spec.ts @@ -1,7 +1,7 @@ import { it, describe, expect, vi } from 'vitest'; import { Base } from '@studiometa/js-toolkit'; import { DataEffect } from '@studiometa/ui'; -import { h } from '#test-utils'; +import { hConnected as h } from '#test-utils'; describe('The DataModel component', () => { it('should execute the compute option without setting a value', () => { diff --git a/packages/tests/atoms/DataModel.spec.ts b/packages/tests/atoms/DataModel.spec.ts index 8618638b..a34f5fd8 100644 --- a/packages/tests/atoms/DataModel.spec.ts +++ b/packages/tests/atoms/DataModel.spec.ts @@ -1,6 +1,6 @@ import { it, describe, expect } from 'vitest'; import { DataModel } from '@studiometa/ui'; -import { h, mount } from '#test-utils'; +import { hConnected as h, mount } from '#test-utils'; function check(input: HTMLInputElement, checked = true) { input.checked = checked; From 3adbebc8691782b664f3de3a606b4b456e86ca96 Mon Sep 17 00:00:00 2001 From: Titouan Mathis Date: Tue, 10 Sep 2024 09:25:09 +0200 Subject: [PATCH 5/7] =?UTF-8?q?Update=20@studiometa/js-toolkit=203.0.0-alp?= =?UTF-8?q?ha.9=20=E2=86=92=203.0.0-alpha.10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 10 +++++----- packages/docs/package.json | 2 +- packages/ui/package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 970ecc53..355477cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2801,9 +2801,9 @@ } }, "node_modules/@studiometa/js-toolkit": { - "version": "3.0.0-alpha.9", - "resolved": "https://registry.npmjs.org/@studiometa/js-toolkit/-/js-toolkit-3.0.0-alpha.9.tgz", - "integrity": "sha512-kzli43BNCG3h8SAj+UO+Wv7OsUDenn9RVRTqJwQ50M8Agnak8g2RX1yAH8OqQohBQbQPECegM01S1CF9nMf57g==", + "version": "3.0.0-alpha.10", + "resolved": "https://registry.npmjs.org/@studiometa/js-toolkit/-/js-toolkit-3.0.0-alpha.10.tgz", + "integrity": "sha512-Iv/jEg7xMhWGrbt771qWiY8sjiUcGnFVhIViR0Js3ZMKIge+CjvCaFPijBMuijMfldr/r9Wf5mzG83gfP5/KwQ==", "license": "MIT", "dependencies": { "@motionone/easing": "^10.18.0", @@ -18768,7 +18768,7 @@ "name": "@studiometa/ui-docs", "version": "1.0.0-alpha.6", "dependencies": { - "@studiometa/js-toolkit": "^3.0.0-alpha.9" + "@studiometa/js-toolkit": "^3.0.0-alpha.10" }, "devDependencies": { "@iconify-json/octicon": "1.1.56", @@ -18808,7 +18808,7 @@ "version": "1.0.0-alpha.6", "license": "MIT", "dependencies": { - "@studiometa/js-toolkit": "^3.0.0-alpha.9", + "@studiometa/js-toolkit": "^3.0.0-alpha.10", "deepmerge": "^4.3.1" } } diff --git a/packages/docs/package.json b/packages/docs/package.json index 0e20ff3f..726c634a 100644 --- a/packages/docs/package.json +++ b/packages/docs/package.json @@ -11,7 +11,7 @@ "build": "vitepress build ." }, "dependencies": { - "@studiometa/js-toolkit": "^3.0.0-alpha.9" + "@studiometa/js-toolkit": "^3.0.0-alpha.10" }, "devDependencies": { "@iconify-json/octicon": "1.1.56", diff --git a/packages/ui/package.json b/packages/ui/package.json index 296bae2c..f5e414a4 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -29,7 +29,7 @@ }, "homepage": "https://github.com/studiometa/ui#readme", "dependencies": { - "@studiometa/js-toolkit": "^3.0.0-alpha.9", + "@studiometa/js-toolkit": "^3.0.0-alpha.10", "deepmerge": "^4.3.1" } } From 78d0697feee42fa7a60fbc092e785ccf724bb6c7 Mon Sep 17 00:00:00 2001 From: Titouan Mathis Date: Tue, 10 Sep 2024 09:25:38 +0200 Subject: [PATCH 6/7] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e0dc5a6..d03cf6c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fix inconsistencies with removed DOM elements ([#293](https://github.com/studiometa/ui/issues/293), [#294](https://github.com/studiometa/ui/pull/294), [de945b1](https://github.com/studiometa/ui/commit/de945b1)) +### Changed + +- Update @studiometa/js-toolkit 3.0.0-alpha.9 → 3.0.0-alpha.10 ([3adbebc](https://github.com/studiometa/ui/commit/3adbebc)) + ## [v1.0.0-alpha.6](https://github.com/studiometa/ui/compare/1.0.0-alpha.5..1.0.0-alpha.6) (2024-08-27) ### Added From 0cf0d1106d55769a529b07461339a15b8005d582 Mon Sep 17 00:00:00 2001 From: Titouan Mathis Date: Tue, 10 Sep 2024 09:27:15 +0200 Subject: [PATCH 7/7] Bump version number --- CHANGELOG.md | 4 +++- composer.json | 2 +- package-lock.json | 12 ++++++------ package.json | 2 +- packages/docs/package.json | 2 +- packages/playground/package.json | 2 +- packages/tests/package.json | 2 +- packages/ui/package.json | 2 +- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d03cf6c5..e4ca4a7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +## [v1.0.0-alpha.7](https://github.com/studiometa/ui/compare/1.0.0-alpha.6..1.0.0-alpha.7) (2024-09-10) + ### Fixed -- Fix inconsistencies with removed DOM elements ([#293](https://github.com/studiometa/ui/issues/293), [#294](https://github.com/studiometa/ui/pull/294), [de945b1](https://github.com/studiometa/ui/commit/de945b1)) +- **DataBind:** fix inconsistencies with removed DOM elements ([#293](https://github.com/studiometa/ui/issues/293), [#294](https://github.com/studiometa/ui/pull/294), [de945b1](https://github.com/studiometa/ui/commit/de945b1)) ### Changed diff --git a/composer.json b/composer.json index 7a88f269..9013125f 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "studiometa/ui", - "version": "1.0.0-alpha.6", + "version": "1.0.0-alpha.7", "description": "A set of opiniated, unstyled and accessible components.", "license": "MIT", "require": { diff --git a/package-lock.json b/package-lock.json index 355477cb..74a11b24 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@studiometa/ui-workspace", - "version": "1.0.0-alpha.6", + "version": "1.0.0-alpha.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@studiometa/ui-workspace", - "version": "1.0.0-alpha.6", + "version": "1.0.0-alpha.7", "hasInstallScript": true, "workspaces": [ "packages/*" @@ -18766,7 +18766,7 @@ }, "packages/docs": { "name": "@studiometa/ui-docs", - "version": "1.0.0-alpha.6", + "version": "1.0.0-alpha.7", "dependencies": { "@studiometa/js-toolkit": "^3.0.0-alpha.10" }, @@ -18786,7 +18786,7 @@ }, "packages/playground": { "name": "@studiometa/ui-playground", - "version": "1.0.0-alpha.6", + "version": "1.0.0-alpha.7", "dependencies": { "@studiometa/playground": "0.1.4", "copy-webpack-plugin": "^12.0.2" @@ -18794,7 +18794,7 @@ }, "packages/tests": { "name": "@studiometa/ui-tests", - "version": "1.0.0-alpha.6", + "version": "1.0.0-alpha.7", "license": "MIT", "dependencies": { "@studiometa/ui": "file:../ui", @@ -18805,7 +18805,7 @@ }, "packages/ui": { "name": "@studiometa/ui", - "version": "1.0.0-alpha.6", + "version": "1.0.0-alpha.7", "license": "MIT", "dependencies": { "@studiometa/js-toolkit": "^3.0.0-alpha.10", diff --git a/package.json b/package.json index 29584220..60e646da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@studiometa/ui-workspace", - "version": "1.0.0-alpha.6", + "version": "1.0.0-alpha.7", "private": true, "workspaces": [ "packages/*" diff --git a/packages/docs/package.json b/packages/docs/package.json index 726c634a..a326e113 100644 --- a/packages/docs/package.json +++ b/packages/docs/package.json @@ -1,6 +1,6 @@ { "name": "@studiometa/ui-docs", - "version": "1.0.0-alpha.6", + "version": "1.0.0-alpha.7", "private": true, "type": "module", "scripts": { diff --git a/packages/playground/package.json b/packages/playground/package.json index 348e58cf..b0765013 100644 --- a/packages/playground/package.json +++ b/packages/playground/package.json @@ -1,6 +1,6 @@ { "name": "@studiometa/ui-playground", - "version": "1.0.0-alpha.6", + "version": "1.0.0-alpha.7", "private": true, "type": "module", "scripts": { diff --git a/packages/tests/package.json b/packages/tests/package.json index b0d7dd82..1649b790 100644 --- a/packages/tests/package.json +++ b/packages/tests/package.json @@ -1,6 +1,6 @@ { "name": "@studiometa/ui-tests", - "version": "1.0.0-alpha.6", + "version": "1.0.0-alpha.7", "private": true, "type": "module", "scripts": { diff --git a/packages/ui/package.json b/packages/ui/package.json index f5e414a4..6723af90 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -1,6 +1,6 @@ { "name": "@studiometa/ui", - "version": "1.0.0-alpha.6", + "version": "1.0.0-alpha.7", "description": "A set of opiniated, unstyled and accessible components", "publishConfig": { "access": "public"