From 79c4ad4053fb688f6f309fc448c40e8cc6bd9405 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Tue, 24 Oct 2023 00:49:51 -0700 Subject: [PATCH 01/17] update README build status badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb13978..e061721 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/matthewp/custom-attributes.svg?branch=master)](https://travis-ci.org/matthewp/custom-attributes) +[![Build status](https://github.com/lume/custom-attributes/actions/workflows/tests.yml/badge.svg)](https://github.com/lume/custom-attributes/actions/workflows/tests.yml) [![npm version](https://badge.fury.io/js/custom-attributes.svg)](http://badge.fury.io/js/custom-attributes) # custom-attributes From 18942d76ea8198408f79bf102151baea511392ce Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Tue, 24 Oct 2023 00:50:15 -0700 Subject: [PATCH 02/17] v0.2.1 --- dist/index.d.ts | 2 +- dist/index.js | 2 +- package.json | 2 +- src/index.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index 43449f0..2d2ebff 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -10,5 +10,5 @@ declare global { customAttributes: CustomAttributeRegistry; } } -export declare const version = "0.2.0"; +export declare const version = "0.2.1"; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index a783354..e4b8de8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4,5 +4,5 @@ export * from './CustomAttributeRegistry.js'; export let customAttributes; if ((_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.document) customAttributes = globalThis.customAttributes = new CustomAttributeRegistry(document); -export const version = '0.2.0'; +export const version = '0.2.1'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/package.json b/package.json index 42b4bd3..40aa62e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lume/custom-attributes", - "version": "0.2.0", + "version": "0.2.1", "description": "Custom attributes: like custom elements, but for attributes", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 9accf31..50620d5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,4 +28,4 @@ declare global { } } -export const version = '0.2.0' +export const version = '0.2.1' From 33dad3ffce8d3ae30ffe76a1907506bb4ed96e30 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Mon, 30 Oct 2023 16:54:14 -0700 Subject: [PATCH 03/17] infra: lume cli update: update tests to run in @web/test-runner (replaced Karma in lume cli), update GitHub Actions yml to run clean/build/test separately as they are no longer coupled in lume cli, update build output with changes from the updated target:esnext option in lume cli tsconfig. Note, the dev process in the repo, when standalone and not a git submodule in the lume repo, will not work for now and needs to be developed as part of the lume supermodule repo using the link script for bootstrapping and linking of packages. Once we finish the stage-3-decorators and classy-solid migration in Lume (soon) we will get the lume cli working in standalone repos again. --- .github/workflows/tests.yml | 4 ++++ dist/CustomAttributeRegistry.js | 12 +++++------- dist/CustomAttributeRegistry.js.map | 2 +- dist/index.js | 3 +-- dist/index.js.map | 2 +- package.json | 4 ++-- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 642896c..39623a7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,6 +21,10 @@ jobs: - name: npm install, build, and test run: | npm i + npm run clean + npm run build npm test + - name: ensure no modifications + run: git add . && git diff --quiet && git diff --cached --quiet env: CI: true diff --git a/dist/CustomAttributeRegistry.js b/dist/CustomAttributeRegistry.js index 04194f2..d21b0fb 100644 --- a/dist/CustomAttributeRegistry.js +++ b/dist/CustomAttributeRegistry.js @@ -1,4 +1,3 @@ -var _a; const forEach = Array.prototype.forEach; export class CustomAttributeRegistry { constructor(ownerDocument) { @@ -31,7 +30,7 @@ export class CustomAttributeRegistry { const map = this._elementMap.get(element); if (!map) return; - map.forEach(inst => { var _a; return (_a = inst.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(inst); }, this); + map.forEach(inst => inst.disconnectedCallback?.(), this); this._elementMap.delete(element); }; if (!ownerDocument) @@ -72,7 +71,6 @@ export class CustomAttributeRegistry { forEach.call(matches, (element) => this._handleChange(attrName, element, null)); } _handleChange(attrName, el, oldVal) { - var _a, _b, _c; let map = this._elementMap.get(el); if (!map) this._elementMap.set(el, (map = new Map())); @@ -87,22 +85,22 @@ export class CustomAttributeRegistry { if (newVal == null) throw new Error('Not possible!'); inst.value = newVal; - (_a = inst.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(inst); + inst.connectedCallback?.(); return; } if (newVal == null) { - (_b = inst.disconnectedCallback) === null || _b === void 0 ? void 0 : _b.call(inst); + inst.disconnectedCallback?.(); map.delete(attrName); } else if (newVal !== inst.value) { inst.value = newVal; if (oldVal == null) throw new Error('Not possible!'); - (_c = inst.changedCallback) === null || _c === void 0 ? void 0 : _c.call(inst, oldVal, newVal); + inst.changedCallback?.(oldVal, newVal); } } } -if ((_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.document) { +if (globalThis.window?.document) { const _attachShadow = Element.prototype.attachShadow; Element.prototype.attachShadow = function attachShadow(options) { const root = _attachShadow.call(this, options); diff --git a/dist/CustomAttributeRegistry.js.map b/dist/CustomAttributeRegistry.js.map index 3beace2..d856f3a 100644 --- a/dist/CustomAttributeRegistry.js.map +++ b/dist/CustomAttributeRegistry.js.map @@ -1 +1 @@ -{"version":3,"file":"CustomAttributeRegistry.js","sourceRoot":"","sources":["../src/CustomAttributeRegistry.ts"],"names":[],"mappings":";AAEA,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,OAAO,CAAA;AAEvC,MAAM,OAAO,uBAAuB;IAmBnC,YAAmB,aAAoC;QAApC,kBAAa,GAAb,aAAa,CAAuB;QAlB/C,aAAQ,GAAG,IAAI,GAAG,EAAuB,CAAA;QACzC,gBAAW,GAAG,IAAI,OAAO,EAAyC,CAAA;QAElE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G,MAAM,CAAA;YACnB,IAAI,CAAC,iBAAiB,EAAE,EAAE,CAAA;YAC1B,OAAM;SACN;QAGD,IAAI,MAAM,IAAI,IAAI,EAAE;YACnB,IAAI,CAAC,oBAAoB,EAAE,EAAE,CAAA;YAC7B,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;SACpB;aAGI,IAAI,MAAM,KAAK,IAAI,CAAC,KAAK,EAAE;YAC/B,IAAI,CAAC,KAAK,GAAG,MAAM,CAAA;YACnB,IAAI,MAAM,IAAI,IAAI;gBAAE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;YACpD,IAAI,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;SACtC;IACF,CAAC;CACD;AAaD,IAAI,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE;IAChC,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,YAAY,CAAA;IAEpD,OAAO,CAAC,SAAS,CAAC,YAAY,GAAG,SAAS,YAAY,CAAC,OAAO;QAC7D,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAE9C,IAAI,CAAC,IAAI,CAAC,gBAAgB;YAAE,IAAI,CAAC,gBAAgB,GAAG,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAA;QAErF,OAAO,IAAI,CAAA;IACZ,CAAC,CAAA;CACD"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index e4b8de8..5488360 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,8 +1,7 @@ -var _a; import { CustomAttributeRegistry } from './CustomAttributeRegistry.js'; export * from './CustomAttributeRegistry.js'; export let customAttributes; -if ((_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.document) +if (globalThis.window?.document) customAttributes = globalThis.customAttributes = new CustomAttributeRegistry(document); export const version = '0.2.1'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map index 1ae9217..17edb27 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAIA,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAA;AAEpE,cAAc,8BAA8B,CAAA;AAE5C,MAAM,CAAC,IAAI,gBAAyC,CAAA;AAGpD,IAAI,MAAA,UAAU,CAAC,MAAM,0CAAE,QAAQ;IAAE,gBAAgB,GAAG,UAAU,CAAC,gBAAgB,GAAG,IAAI,uBAAuB,CAAC,QAAQ,CAAC,CAAA;AAmBvH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAA;AAEpE,cAAc,8BAA8B,CAAA;AAE5C,MAAM,CAAC,IAAI,gBAAyC,CAAA;AAGpD,IAAI,UAAU,CAAC,MAAM,EAAE,QAAQ;IAAE,gBAAgB,GAAG,UAAU,CAAC,gBAAgB,GAAG,IAAI,uBAAuB,CAAC,QAAQ,CAAC,CAAA;AAmBvH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA"} \ No newline at end of file diff --git a/package.json b/package.json index 40aa62e..1e67f68 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ "dev": "lume dev", "typecheck": "lume typecheck", "typecheck:watch": "lume typecheckWatch", - "test": "npm run prettier:check && npm run build && echo TODO use 'lume test'", - "test:debug": "lume testDebug", + "test": "echo TODO use 'lume test'", + "test:watch": "lume test --watch", "prettier": "lume prettier", "prettier:check": "lume prettierCheck", "release:patch": "lume releasePatch", From 17e172c25296b8ab6679a10a2b83663eb27d27c5 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Mon, 30 Oct 2023 19:31:53 -0700 Subject: [PATCH 04/17] infra: update GitHub Actions config to avoid checking for unexpected build output modifications in Windows, we still need a few more fixes for Windows --- .github/workflows/tests.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 39623a7..b5a4539 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,13 +18,23 @@ jobs: uses: actions/setup-node@v3 with: node-version: latest - - name: npm install, build, and test + - name: install run: | npm i + - name: check formatting + run: | + npm run prettier:check + - name: build + run: | npm run clean npm run build + - name: test + run: | npm test - - name: ensure no modifications - run: git add . && git diff --quiet && git diff --cached --quiet + - name: check repo is clean + # skip this check in windows for now, as the build outputs may get slightly modified in Windows, which we want to fix. + if: runner.os != 'Windows' + run: | + git add . && git diff --quiet && git diff --cached --quiet env: CI: true From 7b9d94b142fb8a5214595fb9ef99a7c00b021676 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Mon, 6 Nov 2023 20:49:30 -0800 Subject: [PATCH 05/17] update lume cli version, update typescript version --- dist/CustomAttributeRegistry.js | 63 +++++++++++++++-------------- dist/CustomAttributeRegistry.js.map | 2 +- package.json | 4 +- tsconfig.json | 4 +- 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/dist/CustomAttributeRegistry.js b/dist/CustomAttributeRegistry.js index d21b0fb..d5a154d 100644 --- a/dist/CustomAttributeRegistry.js +++ b/dist/CustomAttributeRegistry.js @@ -1,38 +1,23 @@ const forEach = Array.prototype.forEach; export class CustomAttributeRegistry { + ownerDocument; + _attrMap = new Map(); + _elementMap = new WeakMap(); + _observer = new MutationObserver(mutations => { + forEach.call(mutations, (m) => { + if (m.type === 'attributes') { + const attr = this._getConstructor(m.attributeName); + if (attr) + this._handleChange(m.attributeName, m.target, m.oldValue); + } + else { + forEach.call(m.removedNodes, this._elementDisconnected); + forEach.call(m.addedNodes, this._elementConnected); + } + }); + }); constructor(ownerDocument) { this.ownerDocument = ownerDocument; - this._attrMap = new Map(); - this._elementMap = new WeakMap(); - this._observer = new MutationObserver(mutations => { - forEach.call(mutations, (m) => { - if (m.type === 'attributes') { - const attr = this._getConstructor(m.attributeName); - if (attr) - this._handleChange(m.attributeName, m.target, m.oldValue); - } - else { - forEach.call(m.removedNodes, this._elementDisconnected); - forEach.call(m.addedNodes, this._elementConnected); - } - }); - }); - this._elementConnected = (element) => { - if (element.nodeType !== 1) - return; - forEach.call(element.attributes, (attr) => { - if (this._getConstructor(attr.name)) - this._handleChange(attr.name, element, null); - }); - this._attrMap.forEach((_constructor, attr) => this._upgradeAttr(attr, element)); - }; - this._elementDisconnected = (element) => { - const map = this._elementMap.get(element); - if (!map) - return; - map.forEach(inst => inst.disconnectedCallback?.(), this); - this._elementMap.delete(element); - }; if (!ownerDocument) throw new Error('Must be given a document'); } @@ -70,6 +55,22 @@ export class CustomAttributeRegistry { const matches = node.querySelectorAll('[' + attrName + ']'); forEach.call(matches, (element) => this._handleChange(attrName, element, null)); } + _elementConnected = (element) => { + if (element.nodeType !== 1) + return; + forEach.call(element.attributes, (attr) => { + if (this._getConstructor(attr.name)) + this._handleChange(attr.name, element, null); + }); + this._attrMap.forEach((_constructor, attr) => this._upgradeAttr(attr, element)); + }; + _elementDisconnected = (element) => { + const map = this._elementMap.get(element); + if (!map) + return; + map.forEach(inst => inst.disconnectedCallback?.(), this); + this._elementMap.delete(element); + }; _handleChange(attrName, el, oldVal) { let map = this._elementMap.get(el); if (!map) diff --git a/dist/CustomAttributeRegistry.js.map b/dist/CustomAttributeRegistry.js.map index d856f3a..2af642a 100644 --- a/dist/CustomAttributeRegistry.js.map +++ b/dist/CustomAttributeRegistry.js.map @@ -1 +1 @@ -{"version":3,"file":"CustomAttributeRegistry.js","sourceRoot":"","sources":["../src/CustomAttributeRegistry.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,OAAO,CAAA;AAEvC,MAAM,OAAO,uBAAuB;IAmBnC,YAAmB,aAAoC;QAApC,kBAAa,GAAb,aAAa,CAAuB;QAl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AK,CAAC,eAAe,CAAC,CAAA;YACpD,IAAI,CAAC,KAAK,GAAG,MAAM,CAAA;YACnB,IAAI,CAAC,iBAAiB,EAAE,EAAE,CAAA;YAC1B,OAAM;SACN;QAGD,IAAI,MAAM,IAAI,IAAI,EAAE;YACnB,IAAI,CAAC,oBAAoB,EAAE,EAAE,CAAA;YAC7B,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;SACpB;aAGI,IAAI,MAAM,KAAK,IAAI,CAAC,KAAK,EAAE;YAC/B,IAAI,CAAC,KAAK,GAAG,MAAM,CAAA;YACnB,IAAI,MAAM,IAAI,IAAI;gBAAE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;YACpD,IAAI,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;SACtC;IACF,CAAC;CACD;AAaD,IAAI,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE;IAChC,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,YAAY,CAAA;IAEpD,OAAO,CAAC,SAAS,CAAC,YAAY,GAAG,SAAS,YAAY,CAAC,OAAO;QAC7D,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAE9C,IAAI,CAAC,IAAI,CAAC,gBAAgB;YAAE,IAAI,CAAC,gBAAgB,GAAG,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAA;QAErF,OAAO,IAAI,CAAA;IACZ,CAAC,CAAA;CACD"} \ No newline at end of file diff --git a/package.json b/package.json index 1e67f68..8c3e33c 100644 --- a/package.json +++ b/package.json @@ -37,10 +37,10 @@ }, "homepage": "https://github.com/matthewp/custom-attributes#readme", "devDependencies": { - "@lume/cli": "^0.9.0", + "@lume/cli": "^0.10.0", "prettier": "3.0.3", "rollup": "^0.41.4", - "typescript": "4.4.3" + "typescript": "^5.0.0" }, "dependencies": { "lowclass": "^5.0.0" diff --git a/tsconfig.json b/tsconfig.json index 9838b4b..d7b73b0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,3 @@ { - "extends": "./node_modules/@lume/cli/config/ts.config.json", - "include": ["./src/**/*"], - "exclude": ["./src/globals.d.ts"] + "extends": "./node_modules/@lume/cli/config/ts.config.json" } From 7cf76cf9519d39a7404b3d9432810b8d5e9dc952 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Fri, 17 Nov 2023 15:19:57 -0800 Subject: [PATCH 06/17] update lowclass --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8c3e33c..ff11cd4 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,6 @@ "typescript": "^5.0.0" }, "dependencies": { - "lowclass": "^5.0.0" + "lowclass": "^7.0.0" } } From 8c2d8d6d4d628dc14664a6dde03c056e846c5b27 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Fri, 17 Nov 2023 15:20:12 -0800 Subject: [PATCH 07/17] v0.2.2 --- dist/index.d.ts | 2 +- dist/index.js | 2 +- package.json | 2 +- src/index.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index 2d2ebff..78e10bc 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -10,5 +10,5 @@ declare global { customAttributes: CustomAttributeRegistry; } } -export declare const version = "0.2.1"; +export declare const version = "0.2.2"; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 5488360..d1b9e6a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3,5 +3,5 @@ export * from './CustomAttributeRegistry.js'; export let customAttributes; if (globalThis.window?.document) customAttributes = globalThis.customAttributes = new CustomAttributeRegistry(document); -export const version = '0.2.1'; +export const version = '0.2.2'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/package.json b/package.json index ff11cd4..ef5cfe9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lume/custom-attributes", - "version": "0.2.1", + "version": "0.2.2", "description": "Custom attributes: like custom elements, but for attributes", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 50620d5..226836d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,4 +28,4 @@ declare global { } } -export const version = '0.2.1' +export const version = '0.2.2' From b0b58b97905f0b4481a75abd337f17f23842d364 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Tue, 21 Nov 2023 00:45:56 -0800 Subject: [PATCH 08/17] infra: update build to include comments so that intellisense in consumer IDEs is more useful --- dist/CustomAttributeRegistry.js | 12 ++++++++++++ dist/CustomAttributeRegistry.js.map | 2 +- dist/index.js | 4 ++++ dist/index.js.map | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/dist/CustomAttributeRegistry.js b/dist/CustomAttributeRegistry.js index d5a154d..192bd1d 100644 --- a/dist/CustomAttributeRegistry.js +++ b/dist/CustomAttributeRegistry.js @@ -10,6 +10,7 @@ export class CustomAttributeRegistry { if (attr) this._handleChange(m.attributeName, m.target, m.oldValue); } + // chlidList else { forEach.call(m.removedNodes, this._elementDisconnected); forEach.call(m.addedNodes, this._elementConnected); @@ -42,6 +43,8 @@ export class CustomAttributeRegistry { attributes: true, attributeOldValue: true, attributeFilter: Array.from(this._attrMap.keys()), + // attributeFilter: [...this._attrMap.keys()], // Broken in Oculus + // attributeFilter: this._attrMap.keys(), // This works in Chrome, but TS complains, and not clear if it should work in all browsers yet: https://github.com/whatwg/dom/issues/1092 }); } _unobserve() { @@ -53,15 +56,20 @@ export class CustomAttributeRegistry { } _upgradeAttr(attrName, node = this.ownerDocument) { const matches = node.querySelectorAll('[' + attrName + ']'); + // Possibly create custom attributes that may be in the given 'node' tree. + // Use a forEach as Edge doesn't support for...of on a NodeList forEach.call(matches, (element) => this._handleChange(attrName, element, null)); } _elementConnected = (element) => { if (element.nodeType !== 1) return; + // For each of the connected element's attribute, possibly instantiate the custom attributes. + // Use a forEach as Safari 10 doesn't support for...of on NamedNodeMap (attributes) forEach.call(element.attributes, (attr) => { if (this._getConstructor(attr.name)) this._handleChange(attr.name, element, null); }); + // Possibly instantiate custom attributes that may be in the subtree of the connected element. this._attrMap.forEach((_constructor, attr) => this._upgradeAttr(attr, element)); }; _elementDisconnected = (element) => { @@ -77,6 +85,7 @@ export class CustomAttributeRegistry { this._elementMap.set(el, (map = new Map())); let inst = map.get(attrName); const newVal = el.getAttribute(attrName); + // Attribute is being created if (!inst) { const Constructor = this._getConstructor(attrName); inst = new Constructor(); @@ -89,10 +98,12 @@ export class CustomAttributeRegistry { inst.connectedCallback?.(); return; } + // Attribute was removed if (newVal == null) { inst.disconnectedCallback?.(); map.delete(attrName); } + // Attribute changed else if (newVal !== inst.value) { inst.value = newVal; if (oldVal == null) @@ -101,6 +112,7 @@ export class CustomAttributeRegistry { } } } +// Avoid errors trying to use DOM APIs in non-DOM environments (f.e. server-side rendering). if (globalThis.window?.document) { const _attachShadow = Element.prototype.attachShadow; Element.prototype.attachShadow = function attachShadow(options) { diff --git a/dist/CustomAttributeRegistry.js.map b/dist/CustomAttributeRegistry.js.map index 2af642a..5ea27c7 100644 --- a/dist/CustomAttributeRegistry.js.map +++ b/dist/CustomAttributeRegistry.js.map @@ -1 +1 @@ -{"version":3,"file":"CustomAttributeRegistry.js","sourceRoot":"","sources":["../src/CustomAttributeRegistry.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,OAAO,CAAA;AAEvC,MAAM,OAAO,uBAAuB;IAmBhB;IAlBX,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAA;IACzC,WAAW,GAAG,IAAI,OAAO,EAAyC,CAAA;IAElE,SAAS,GAAqB,IAAI,gBAAgB,CAAC,SAAS,CAAC,EAAE;QACtE,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAiB,EAAE,EAAE;YAC7C,IAAI,CAAC,CAAC,IAAI,KAAK,YAAY,EAAE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AAiB,EAAE,EAAE,CAAA;YAC1B,OAAM;SACN;QAED,wBAAwB;QACxB,IAAI,MAAM,IAAI,IAAI,EAAE;YACnB,IAAI,CAAC,oBAAoB,EAAE,EAAE,CAAA;YAC7B,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;SACpB;QAED,oBAAoB;aACf,IAAI,MAAM,KAAK,IAAI,CAAC,KAAK,EAAE;YAC/B,IAAI,CAAC,KAAK,GAAG,MAAM,CAAA;YACnB,IAAI,MAAM,IAAI,IAAI;gBAAE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;YACpD,IAAI,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;SACtC;IACF,CAAC;CACD;AAYD,4FAA4F;AAC5F,IAAI,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE;IAChC,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,YAAY,CAAA;IAEpD,OAAO,CAAC,SAAS,CAAC,YAAY,GAAG,SAAS,YAAY,CAAC,OAAO;QAC7D,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAE9C,IAAI,CAAC,IAAI,CAAC,gBAAgB;YAAE,IAAI,CAAC,gBAAgB,GAAG,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAA;QAErF,OAAO,IAAI,CAAA;IACZ,CAAC,CAAA;CACD"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index d1b9e6a..e8e661d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,6 +1,10 @@ +// TODO We don't know when a ShadowRoot is no longer referenced, hence we cannot +// unobserve them. Verify that MOs are cleaned up once ShadowRoots are no longer +// referenced. import { CustomAttributeRegistry } from './CustomAttributeRegistry.js'; export * from './CustomAttributeRegistry.js'; export let customAttributes; +// Avoid errors trying to use DOM APIs in non-DOM environments (f.e. server-side rendering). if (globalThis.window?.document) customAttributes = globalThis.customAttributes = new CustomAttributeRegistry(document); export const version = '0.2.2'; diff --git a/dist/index.js.map b/dist/index.js.map index 17edb27..2a47348 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAA;AAEpE,cAAc,8BAA8B,CAAA;AAE5C,MAAM,CAAC,IAAI,gBAAyC,CAAA;AAGpD,IAAI,UAAU,CAAC,MAAM,EAAE,QAAQ;IAAE,gBAAgB,GAAG,UAAU,CAAC,gBAAgB,GAAG,IAAI,uBAAuB,CAAC,QAAQ,CAAC,CAAA;AAmBvH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,gFAAgF;AAChF,cAAc;AAEd,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAA;AAEpE,cAAc,8BAA8B,CAAA;AAE5C,MAAM,CAAC,IAAI,gBAAyC,CAAA;AAEpD,4FAA4F;AAC5F,IAAI,UAAU,CAAC,MAAM,EAAE,QAAQ;IAAE,gBAAgB,GAAG,UAAU,CAAC,gBAAgB,GAAG,IAAI,uBAAuB,CAAC,QAAQ,CAAC,CAAA;AAmBvH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA"} \ No newline at end of file From a52d02202588e4e6b8f0fc4b89b1b771c013a00c Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Tue, 21 Nov 2023 00:46:09 -0800 Subject: [PATCH 09/17] v0.2.3 --- dist/index.d.ts | 2 +- dist/index.js | 2 +- package.json | 2 +- src/index.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index 78e10bc..5487829 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -10,5 +10,5 @@ declare global { customAttributes: CustomAttributeRegistry; } } -export declare const version = "0.2.2"; +export declare const version = "0.2.3"; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index e8e661d..6fa4583 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7,5 +7,5 @@ export let customAttributes; // Avoid errors trying to use DOM APIs in non-DOM environments (f.e. server-side rendering). if (globalThis.window?.document) customAttributes = globalThis.customAttributes = new CustomAttributeRegistry(document); -export const version = '0.2.2'; +export const version = '0.2.3'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/package.json b/package.json index ef5cfe9..bd4e8cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lume/custom-attributes", - "version": "0.2.2", + "version": "0.2.3", "description": "Custom attributes: like custom elements, but for attributes", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 226836d..83eb5ff 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,4 +28,4 @@ declare global { } } -export const version = '0.2.2' +export const version = '0.2.3' From 2c2139a6ddaa70a3684af4cd5bd7c4286f276118 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Tue, 21 Nov 2023 19:49:20 -0800 Subject: [PATCH 10/17] update lume/cli --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bd4e8cc..7fe1096 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ }, "homepage": "https://github.com/matthewp/custom-attributes#readme", "devDependencies": { - "@lume/cli": "^0.10.0", + "@lume/cli": "^0.11.0", "prettier": "3.0.3", "rollup": "^0.41.4", "typescript": "^5.0.0" From c576682cd42051f1ee59eddb5e97bba22e2631a7 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Thu, 12 Sep 2024 12:56:16 -0400 Subject: [PATCH 11/17] Update `lowclass` version. --- dist/CustomAttributeRegistry.d.ts | 2 +- dist/CustomAttributeRegistry.d.ts.map | 2 +- package.json | 2 +- src/CustomAttributeRegistry.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/CustomAttributeRegistry.d.ts b/dist/CustomAttributeRegistry.d.ts index 884e61b..a55f9a3 100644 --- a/dist/CustomAttributeRegistry.d.ts +++ b/dist/CustomAttributeRegistry.d.ts @@ -1,4 +1,4 @@ -import type { Constructor } from 'lowclass'; +import type { Constructor } from 'lowclass/dist/Constructor.js'; export declare class CustomAttributeRegistry { ownerDocument: Document | ShadowRoot; private _attrMap; diff --git a/dist/CustomAttributeRegistry.d.ts.map b/dist/CustomAttributeRegistry.d.ts.map index 7139a91..1921e7a 100644 --- a/dist/CustomAttributeRegistry.d.ts.map +++ b/dist/CustomAttributeRegistry.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"CustomAttributeRegistry.d.ts","sourceRoot":"","sources":["../src/CustomAttributeRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,UAAU,CAAA;AAIzC,qBAAa,uBAAuB;IAmBhB,aAAa,EAAE,QAAQ,GAAG,UAAU;IAlBvD,OAAO,CAAC,QAAQ,CAAiC;IACjD,OAAO,CAAC,WAAW,CAAuD;IAE1E,OAAO,CAAC,SAAS,CAaf;gBAEiB,aAAa,EAAE,QAAQ,GAAG,UAAU;IAIvD,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW;IAM3C,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM;IAMtC,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,QAAQ;IAYhB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,iBAAiB,CAWxB;IAED,OAAO,CAAC,oBAAoB,CAO3B;IAED,OAAO,CAAC,aAAa;CAiCrB;AAGD,MAAM,WAAW,eAAe;IAC/B,YAAY,EAAE,OAAO,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,iBAAiB,CAAC,IAAI,IAAI,CAAA;IAC1B,oBAAoB,CAAC,IAAI,IAAI,CAAA;IAC7B,eAAe,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1D"} \ No newline at end of file +{"version":3,"file":"CustomAttributeRegistry.d.ts","sourceRoot":"","sources":["../src/CustomAttributeRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAA;AAI7D,qBAAa,uBAAuB;IAmBhB,aAAa,EAAE,QAAQ,GAAG,UAAU;IAlBvD,OAAO,CAAC,QAAQ,CAAiC;IACjD,OAAO,CAAC,WAAW,CAAuD;IAE1E,OAAO,CAAC,SAAS,CAaf;gBAEiB,aAAa,EAAE,QAAQ,GAAG,UAAU;IAIvD,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW;IAM3C,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM;IAMtC,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,QAAQ;IAYhB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,iBAAiB,CAWxB;IAED,OAAO,CAAC,oBAAoB,CAO3B;IAED,OAAO,CAAC,aAAa;CAiCrB;AAGD,MAAM,WAAW,eAAe;IAC/B,YAAY,EAAE,OAAO,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,iBAAiB,CAAC,IAAI,IAAI,CAAA;IAC1B,oBAAoB,CAAC,IAAI,IAAI,CAAA;IAC7B,eAAe,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1D"} \ No newline at end of file diff --git a/package.json b/package.json index 7fe1096..ca72c29 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,6 @@ "typescript": "^5.0.0" }, "dependencies": { - "lowclass": "^7.0.0" + "lowclass": "^8.0.0" } } diff --git a/src/CustomAttributeRegistry.ts b/src/CustomAttributeRegistry.ts index 4408571..f3755d3 100644 --- a/src/CustomAttributeRegistry.ts +++ b/src/CustomAttributeRegistry.ts @@ -1,4 +1,4 @@ -import type {Constructor} from 'lowclass' +import type {Constructor} from 'lowclass/dist/Constructor.js' const forEach = Array.prototype.forEach From c2369432b45b0ac3fd7494a9f2877beb224e5275 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Mon, 16 Sep 2024 15:54:24 -0400 Subject: [PATCH 12/17] update lume/cli --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ca72c29..85ccb78 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ }, "homepage": "https://github.com/matthewp/custom-attributes#readme", "devDependencies": { - "@lume/cli": "^0.11.0", + "@lume/cli": "^0.13.0", "prettier": "3.0.3", "rollup": "^0.41.4", "typescript": "^5.0.0" From b400c044af0b8da759ea53cfa2e36c4a7f907e4a Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Tue, 17 Sep 2024 11:31:22 -0700 Subject: [PATCH 13/17] update build for updated lume/cli --- dist/CustomAttributeRegistry.js.map | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/CustomAttributeRegistry.js.map b/dist/CustomAttributeRegistry.js.map index 5ea27c7..a5a129c 100644 --- a/dist/CustomAttributeRegistry.js.map +++ b/dist/CustomAttributeRegistry.js.map @@ -1 +1 @@ -{"version":3,"file":"CustomAttributeRegistry.js","sourceRoot":"","sources":["../src/CustomAttributeRegistry.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,OAAO,CAAA;AAEvC,MAAM,OAAO,uBAAuB;IAmBhB;IAlBX,Q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,CAAC,IAAI,CAAC,gBAAgB;YAAE,IAAI,CAAC,gBAAgB,GAAG,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAA;QAErF,OAAO,IAAI,CAAA;IACZ,CAAC,CAAA;AACF,CAAC"} \ No newline at end of file From 6e9e670f00a467f592a65dc0c18d4b8401df773e Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Thu, 26 Sep 2024 21:27:55 -0700 Subject: [PATCH 14/17] get tests working --- dist/CustomAttributeRegistry.d.ts | 12 +--- dist/CustomAttributeRegistry.d.ts.map | 2 +- dist/CustomAttributeRegistry.js | 72 +++++++++++----------- dist/CustomAttributeRegistry.js.map | 2 +- dist/test/change.test.d.ts | 2 + dist/test/change.test.d.ts.map | 1 + dist/test/change.test.js | 37 ++++++++++++ dist/test/change.test.js.map | 1 + dist/test/connect.test.d.ts | 5 ++ dist/test/connect.test.d.ts.map | 1 + dist/test/connect.test.js | 47 +++++++++++++++ dist/test/connect.test.js.map | 1 + dist/test/disconnect.test.d.ts | 2 + dist/test/disconnect.test.d.ts.map | 1 + dist/test/disconnect.test.js | 45 ++++++++++++++ dist/test/disconnect.test.js.map | 1 + dist/test/get.test.d.ts | 2 + dist/test/get.test.d.ts.map | 1 + dist/test/get.test.js | 37 ++++++++++++ dist/test/get.test.js.map | 1 + package.json | 2 +- src/CustomAttributeRegistry.ts | 70 ++++++++++----------- src/test/change.test.ts | 51 ++++++++++++++++ src/test/connect.test.ts | 70 +++++++++++++++++++++ src/test/disconnect.test.ts | 63 +++++++++++++++++++ src/test/get.test.ts | 50 +++++++++++++++ test/all.html | 31 ---------- test/change.html | 66 -------------------- test/connect.html | 87 --------------------------- test/disconnect.html | 77 ------------------------ test/get.html | 62 ------------------- 31 files changed, 494 insertions(+), 408 deletions(-) create mode 100644 dist/test/change.test.d.ts create mode 100644 dist/test/change.test.d.ts.map create mode 100644 dist/test/change.test.js create mode 100644 dist/test/change.test.js.map create mode 100644 dist/test/connect.test.d.ts create mode 100644 dist/test/connect.test.d.ts.map create mode 100644 dist/test/connect.test.js create mode 100644 dist/test/connect.test.js.map create mode 100644 dist/test/disconnect.test.d.ts create mode 100644 dist/test/disconnect.test.d.ts.map create mode 100644 dist/test/disconnect.test.js create mode 100644 dist/test/disconnect.test.js.map create mode 100644 dist/test/get.test.d.ts create mode 100644 dist/test/get.test.d.ts.map create mode 100644 dist/test/get.test.js create mode 100644 dist/test/get.test.js.map create mode 100644 src/test/change.test.ts create mode 100644 src/test/connect.test.ts create mode 100644 src/test/disconnect.test.ts create mode 100644 src/test/get.test.ts delete mode 100644 test/all.html delete mode 100644 test/change.html delete mode 100644 test/connect.html delete mode 100644 test/disconnect.html delete mode 100644 test/get.html diff --git a/dist/CustomAttributeRegistry.d.ts b/dist/CustomAttributeRegistry.d.ts index a55f9a3..a41f936 100644 --- a/dist/CustomAttributeRegistry.d.ts +++ b/dist/CustomAttributeRegistry.d.ts @@ -1,20 +1,10 @@ import type { Constructor } from 'lowclass/dist/Constructor.js'; export declare class CustomAttributeRegistry { + #private; ownerDocument: Document | ShadowRoot; - private _attrMap; - private _elementMap; - private _observer; constructor(ownerDocument: Document | ShadowRoot); define(attrName: string, Class: Constructor): void; get(element: Element, attrName: string): CustomAttribute | undefined; - private _getConstructor; - private _observe; - private _unobserve; - private _reobserve; - private _upgradeAttr; - private _elementConnected; - private _elementDisconnected; - private _handleChange; } export interface CustomAttribute { ownerElement: Element; diff --git a/dist/CustomAttributeRegistry.d.ts.map b/dist/CustomAttributeRegistry.d.ts.map index 1921e7a..f52c6d1 100644 --- a/dist/CustomAttributeRegistry.d.ts.map +++ b/dist/CustomAttributeRegistry.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"CustomAttributeRegistry.d.ts","sourceRoot":"","sources":["../src/CustomAttributeRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAA;AAI7D,qBAAa,uBAAuB;IAmBhB,aAAa,EAAE,QAAQ,GAAG,UAAU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I,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,iBAAiB,CAAC,IAAI,IAAI,CAAA;IAC1B,oBAAoB,CAAC,IAAI,IAAI,CAAA;IAC7B,eAAe,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1D"} \ No newline at end of file diff --git a/dist/CustomAttributeRegistry.js b/dist/CustomAttributeRegistry.js index 192bd1d..55c0bdd 100644 --- a/dist/CustomAttributeRegistry.js +++ b/dist/CustomAttributeRegistry.js @@ -1,19 +1,19 @@ const forEach = Array.prototype.forEach; export class CustomAttributeRegistry { ownerDocument; - _attrMap = new Map(); - _elementMap = new WeakMap(); - _observer = new MutationObserver(mutations => { + #attrMap = new Map(); + #elementMap = new WeakMap(); + #observer = new MutationObserver(mutations => { forEach.call(mutations, (m) => { if (m.type === 'attributes') { - const attr = this._getConstructor(m.attributeName); + const attr = this.#getConstructor(m.attributeName); if (attr) - this._handleChange(m.attributeName, m.target, m.oldValue); + this.#handleChange(m.attributeName, m.target, m.oldValue); } // chlidList else { - forEach.call(m.removedNodes, this._elementDisconnected); - forEach.call(m.addedNodes, this._elementConnected); + forEach.call(m.removedNodes, this.#elementDisconnected); + forEach.call(m.addedNodes, this.#elementConnected); } }); }); @@ -23,71 +23,71 @@ export class CustomAttributeRegistry { throw new Error('Must be given a document'); } define(attrName, Class) { - this._attrMap.set(attrName, Class); - this._upgradeAttr(attrName); - this._reobserve(); + this.#attrMap.set(attrName, Class); + this.#upgradeAttr(attrName); + this.#reobserve(); } get(element, attrName) { - const map = this._elementMap.get(element); + const map = this.#elementMap.get(element); if (!map) return; return map.get(attrName); } - _getConstructor(attrName) { - return this._attrMap.get(attrName); + #getConstructor(attrName) { + return this.#attrMap.get(attrName); } - _observe() { - this._observer.observe(this.ownerDocument, { + #observe() { + this.#observer.observe(this.ownerDocument, { childList: true, subtree: true, attributes: true, attributeOldValue: true, - attributeFilter: Array.from(this._attrMap.keys()), + attributeFilter: Array.from(this.#attrMap.keys()), // attributeFilter: [...this._attrMap.keys()], // Broken in Oculus // attributeFilter: this._attrMap.keys(), // This works in Chrome, but TS complains, and not clear if it should work in all browsers yet: https://github.com/whatwg/dom/issues/1092 }); } - _unobserve() { - this._observer.disconnect(); + #unobserve() { + this.#observer.disconnect(); } - _reobserve() { - this._unobserve(); - this._observe(); + #reobserve() { + this.#unobserve(); + this.#observe(); } - _upgradeAttr(attrName, node = this.ownerDocument) { + #upgradeAttr(attrName, node = this.ownerDocument) { const matches = node.querySelectorAll('[' + attrName + ']'); // Possibly create custom attributes that may be in the given 'node' tree. // Use a forEach as Edge doesn't support for...of on a NodeList - forEach.call(matches, (element) => this._handleChange(attrName, element, null)); + forEach.call(matches, (element) => this.#handleChange(attrName, element, null)); } - _elementConnected = (element) => { + #elementConnected = (element) => { if (element.nodeType !== 1) return; // For each of the connected element's attribute, possibly instantiate the custom attributes. // Use a forEach as Safari 10 doesn't support for...of on NamedNodeMap (attributes) forEach.call(element.attributes, (attr) => { - if (this._getConstructor(attr.name)) - this._handleChange(attr.name, element, null); + if (this.#getConstructor(attr.name)) + this.#handleChange(attr.name, element, null); }); // Possibly instantiate custom attributes that may be in the subtree of the connected element. - this._attrMap.forEach((_constructor, attr) => this._upgradeAttr(attr, element)); + this.#attrMap.forEach((_constructor, attr) => this.#upgradeAttr(attr, element)); }; - _elementDisconnected = (element) => { - const map = this._elementMap.get(element); + #elementDisconnected = (element) => { + const map = this.#elementMap.get(element); if (!map) return; map.forEach(inst => inst.disconnectedCallback?.(), this); - this._elementMap.delete(element); + this.#elementMap.delete(element); }; - _handleChange(attrName, el, oldVal) { - let map = this._elementMap.get(el); + #handleChange(attrName, el, oldVal) { + let map = this.#elementMap.get(el); if (!map) - this._elementMap.set(el, (map = new Map())); + this.#elementMap.set(el, (map = new Map())); let inst = map.get(attrName); const newVal = el.getAttribute(attrName); // Attribute is being created if (!inst) { - const Constructor = this._getConstructor(attrName); + const Constructor = this.#getConstructor(attrName); inst = new Constructor(); map.set(attrName, inst); inst.ownerElement = el; @@ -114,9 +114,9 @@ export class CustomAttributeRegistry { } // Avoid errors trying to use DOM APIs in non-DOM environments (f.e. server-side rendering). if (globalThis.window?.document) { - const _attachShadow = Element.prototype.attachShadow; + const original = Element.prototype.attachShadow; Element.prototype.attachShadow = function attachShadow(options) { - const root = _attachShadow.call(this, options); + const root = original.call(this, options); if (!root.customAttributes) root.customAttributes = new CustomAttributeRegistry(root); return root; diff --git a/dist/CustomAttributeRegistry.js.map b/dist/CustomAttributeRegistry.js.map index a5a129c..e450257 100644 --- a/dist/CustomAttributeRegistry.js.map +++ b/dist/CustomAttributeRegistry.js.map @@ -1 +1 @@ -{"version":3,"file":"CustomAttributeRegistry.js","sourceRoot":"","sources":["../src/CustomAttributeRegistry.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,OAAO,CAAA;AAEvC,MAAM,OAAO,uBAAuB;IAmBhB;IAlBX,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAA;IACzC,WAAW,GAAG,IAAI,OAAO,EAAyC,CAAA;IAElE,SAAS,GAAqB,IAAI,gBAAgB,CAAC,SAAS,CAAC,EAAE;QACtE,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAiB,EAAE,EAAE;YAC7C,IAAI,CAAC,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;gBAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,aAAc,CAAC,CAAA;gBACnD,IAAI,IAAI;oBAAE,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,aAAc,EAAE,CAAC,CAAC,MAAiB,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAA;YAChF,CAAC;YAED,YAAY;iBACP,CAAC;gBACL,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAA;gBACv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AI,EAAE,CAAC;YACpB,IAAI,CAAC,oBAAoB,EAAE,EAAE,CAAA;YAC7B,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QACrB,CAAC;QAED,oBAAoB;aACf,IAAI,MAAM,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;YAChC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAA;YACnB,IAAI,MAAM,IAAI,IAAI;gBAAE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;YACpD,IAAI,CAAC,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACvC,CAAC;IACF,CAAC;CACD;AAYD,4FAA4F;AAC5F,IAAI,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;IACjC,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,YAAY,CAAA;IAE/C,OAAO,CAAC,SAAS,CAAC,YAAY,GAAG,SAAS,YAAY,CAAC,OAAO;QAC7D,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAEzC,IAAI,CAAC,IAAI,CAAC,gBAAgB;YAAE,IAAI,CAAC,gBAAgB,GAAG,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAA;QAErF,OAAO,IAAI,CAAA;IACZ,CAAC,CAAA;AACF,CAAC"} \ No newline at end of file diff --git a/dist/test/change.test.d.ts b/dist/test/change.test.d.ts new file mode 100644 index 0000000..67a7576 --- /dev/null +++ b/dist/test/change.test.d.ts @@ -0,0 +1,2 @@ +import '../index.js'; +//# sourceMappingURL=change.test.d.ts.map \ No newline at end of file diff --git a/dist/test/change.test.d.ts.map b/dist/test/change.test.d.ts.map new file mode 100644 index 0000000..361162b --- /dev/null +++ b/dist/test/change.test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"change.test.d.ts","sourceRoot":"","sources":["../../src/test/change.test.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA"} \ No newline at end of file diff --git a/dist/test/change.test.js b/dist/test/change.test.js new file mode 100644 index 0000000..ba7b8b5 --- /dev/null +++ b/dist/test/change.test.js @@ -0,0 +1,37 @@ +import '../index.js'; +describe('changedCallback()', function () { + async function later() { + await new Promise(r => setTimeout(r, 4)); + } + it('Is called when an attribute changes value', async function () { + const { resolve, promise: changedPromise } = Promise.withResolvers(); + class SomeAttr { + changedCallback() { + resolve(); + } + } + customAttributes.define('some-attr', SomeAttr); + const el = document.createElement('article'); + el.setAttribute('some-attr', 'foo'); + document.body.append(el); + queueMicrotask(() => el.setAttribute('some-attr', 'bar')); + await changedPromise; + el.remove(); + }); + it("Is not called when an attribute's value remains the same", async function () { + let count = 0; + class AnotherAttr { + changedCallback() { + count++; + } + } + customAttributes.define('another-attr', AnotherAttr); + const el = document.createElement('span'); + el.setAttribute('another-attr', 'foo'); + document.body.append(el); + el.setAttribute('another-attr', 'foo'); + await later(); + expect(count).toBe(0); + }); +}); +//# sourceMappingURL=change.test.js.map \ No newline at end of file diff --git a/dist/test/change.test.js.map b/dist/test/change.test.js.map new file mode 100644 index 0000000..4cc3d48 --- /dev/null +++ b/dist/test/change.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"change.test.js","sourceRoot":"","sources":["../../src/test/change.test.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AAEpB,QAAQ,CAAC,mBAAmB,EAAE;IAC7B,KAAK,UAAU,KAAK;QACnB,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACzC,CAAC;IAED,EAAE,CAAC,2CAA2C,EAAE,KAAK;QACpD,MAAM,EAAC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAC,GAAG,OAAO,CAAC,aAAa,EAAQ,CAAA;QAExE,MAAM,QAAQ;YACb,eAAe;gBACd,OAAO,EAAE,CAAA;YACV,CAAC;SACD;QAED,gBAAgB,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAA;QAE9C,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,SAAS,CAAC,CAAA;QAC5C,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,KAAK,CAAC,CAAA;QACnC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAExB,cAAc,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAA;QAEzD,MAAM,cAAc,CAAA;QAEpB,EAAE,CAAC,MAAM,EAAE,CAAA;IACZ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0DAA0D,EAAE,KAAK;QACnE,IAAI,KAAK,GAAG,CAAC,CAAA;QAEb,MAAM,WAAW;YAChB,eAAe;gBACd,KAAK,EAAE,CAAA;YACR,CAAC;SACD;QAED,gBAAgB,CAAC,MAAM,CAAC,cAAc,EAAE,WAAW,CAAC,CAAA;QAEpD,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QACzC,EAAE,CAAC,YAAY,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;QACtC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAExB,EAAE,CAAC,YAAY,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;QAEtC,MAAM,KAAK,EAAE,CAAA;QAEb,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACtB,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/test/connect.test.d.ts b/dist/test/connect.test.d.ts new file mode 100644 index 0000000..dc81e37 --- /dev/null +++ b/dist/test/connect.test.d.ts @@ -0,0 +1,5 @@ +import '../index.js'; +declare global { + function expect(...args: any[]): any; +} +//# sourceMappingURL=connect.test.d.ts.map \ No newline at end of file diff --git a/dist/test/connect.test.d.ts.map b/dist/test/connect.test.d.ts.map new file mode 100644 index 0000000..3be0049 --- /dev/null +++ b/dist/test/connect.test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"connect.test.d.ts","sourceRoot":"","sources":["../../src/test/connect.test.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AAEpB,OAAO,CAAC,MAAM,CAAC;IACd,SAAS,MAAM,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;CACpC"} \ No newline at end of file diff --git a/dist/test/connect.test.js b/dist/test/connect.test.js new file mode 100644 index 0000000..b708d64 --- /dev/null +++ b/dist/test/connect.test.js @@ -0,0 +1,47 @@ +import '../index.js'; +class BgColorAttr { + connectedCallback() { + this.setColor(); + } + changedCallback(_oldValue, _newValue) { + this.setColor(); + } + setColor() { + const color = this.value || ''; + this.ownerElement.style.backgroundColor = color; + } +} +document.body.insertAdjacentHTML('beforeend', +/*html*/ ` +
+

This article is static

+
+`); +customAttributes.define('bg-color', BgColorAttr); +describe('connectedCallback()', function () { + it('Is called when element is already in the DOM', function () { + const article = document.querySelector('article'); + expect(article.style.backgroundColor).toBe('red'); + article.remove(); + }); + it('Is called when an attribute is dynamically created', async function () { + const article = document.createElement('article'); + article.textContent = 'hello world'; + document.body.append(article); + article.setAttribute('bg-color', 'blue'); + await new Promise(r => setTimeout(r, 4)); + expect(article.style.backgroundColor).toBe('blue'); + article.remove(); + }); + it('Is called on nested elements when root element is added to the DOM', async function () { + const article = document.createElement('article'); + const header = document.createElement('header'); + header.setAttribute('bg-color', 'blue'); + article.append(header); + document.body.append(article); + await new Promise(r => setTimeout(r, 4)); + expect(header.style.backgroundColor).toBe('blue'); + article.remove(); + }); +}); +//# sourceMappingURL=connect.test.js.map \ No newline at end of file diff --git a/dist/test/connect.test.js.map b/dist/test/connect.test.js.map new file mode 100644 index 0000000..df26525 --- /dev/null +++ b/dist/test/connect.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"connect.test.js","s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CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAClD,OAAO,CAAC,MAAM,EAAE,CAAA;IACjB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,oEAAoE,EAAE,KAAK;QAC7E,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,SAAS,CAAC,CAAA;QACjD,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;QAE/C,MAAM,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;QACvC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAEtB,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAE7B,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAExC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACjD,OAAO,CAAC,MAAM,EAAE,CAAA;IACjB,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/test/disconnect.test.d.ts b/dist/test/disconnect.test.d.ts new file mode 100644 index 0000000..1cd5e91 --- /dev/null +++ b/dist/test/disconnect.test.d.ts @@ -0,0 +1,2 @@ +import '../index.js'; +//# sourceMappingURL=disconnect.test.d.ts.map \ No newline at end of file diff --git a/dist/test/disconnect.test.d.ts.map b/dist/test/disconnect.test.d.ts.map new file mode 100644 index 0000000..5b603d8 --- /dev/null +++ b/dist/test/disconnect.test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"disconnect.test.d.ts","sourceRoot":"","sources":["../../src/test/disconnect.test.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA"} \ No newline at end of file diff --git a/dist/test/disconnect.test.js b/dist/test/disconnect.test.js new file mode 100644 index 0000000..f38108b --- /dev/null +++ b/dist/test/disconnect.test.js @@ -0,0 +1,45 @@ +import '../index.js'; +describe('disconnectedCallback()', function () { + async function later() { + await new Promise(r => setTimeout(r, 4)); + } + it('Is called when removeAttribute() is used', async function () { + const { resolve, promise: disconnectedPromise } = Promise.withResolvers(); + let count = 0; + class MyAttr { + async connectedCallback() { + await later().then(() => el.removeAttribute('my-attr')); + } + changedCallback() { + count++; + } + disconnectedCallback() { + resolve(); + } + } + customAttributes.define('my-attr', MyAttr); + const el = document.createElement('span'); + document.body.append(el); + queueMicrotask(() => el.setAttribute('my-attr', 'test')); + await disconnectedPromise; + expect(count).toBe(0); + }); + it('Is called when the element is removed', async function () { + const { resolve, promise: disconnectedPromise } = Promise.withResolvers(); + class SomeAttr { + async connectedCallback() { + await later(); + el.remove(); + } + disconnectedCallback() { + resolve(); + } + } + customAttributes.define('some-attr', SomeAttr); + const el = document.createElement('span'); + document.body.append(el); + queueMicrotask(() => el.setAttribute('some-attr', 'test')); + await disconnectedPromise; + }); +}); +//# sourceMappingURL=disconnect.test.js.map \ No newline at end of file diff --git a/dist/test/disconnect.test.js.map b/dist/test/disconnect.test.js.map new file mode 100644 index 0000000..987ea8e --- /dev/null +++ b/dist/test/disconnect.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"disconnect.test.js","sourceRoot":"","sources":["../../src/test/disconnect.test.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AAEpB,QAAQ,CAAC,wBAAwB,EAAE;IAClC,KAAK,UAAU,KAAK;QACnB,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACzC,CAAC;IAED,EAAE,CAAC,0CAA0C,EAAE,KAAK;QACnD,MAAM,EAAC,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAC,GAAG,OAAO,CAAC,aAAa,EAAQ,CAAA;QAE7E,IAAI,KAAK,GAAG,CAAC,CA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,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAA;QAE1D,MAAM,mBAAmB,CAAA;IAC1B,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"} \ No newline at end of file diff --git a/dist/test/get.test.d.ts b/dist/test/get.test.d.ts new file mode 100644 index 0000000..1c06818 --- /dev/null +++ b/dist/test/get.test.d.ts @@ -0,0 +1,2 @@ +import '../index.js'; +//# sourceMappingURL=get.test.d.ts.map \ No newline at end of file diff --git a/dist/test/get.test.d.ts.map b/dist/test/get.test.d.ts.map new file mode 100644 index 0000000..132c6d0 --- /dev/null +++ b/dist/test/get.test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"get.test.d.ts","sourceRoot":"","sources":["../../src/test/get.test.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA"} \ No newline at end of file diff --git a/dist/test/get.test.js b/dist/test/get.test.js new file mode 100644 index 0000000..925937f --- /dev/null +++ b/dist/test/get.test.js @@ -0,0 +1,37 @@ +import '../index.js'; +describe('get()', function () { + async function later() { + await new Promise(r => setTimeout(r, 4)); + } + it('gets the attribute instance', async function () { + class Foobar { + } + customAttributes.define('foo-bar', Foobar); + const el = document.createElement('span'); + el.setAttribute('foo-bar', 'baz'); + document.body.append(el); + await later(); + const fooBar = customAttributes.get(el, 'foo-bar'); + expect(fooBar).toBeInstanceOf(Foobar); + }); + it('allows passing more complex data types', async function () { + const { resolve, promise: bazSetPromise } = Promise.withResolvers(); + class Foobar { + set baz(val) { + expect(val).toBe('hello world'); + resolve(); + } + } + customAttributes.define('foo-bar', Foobar); + const el = document.createElement('span'); + el.setAttribute('foo-bar', 'bam'); + document.body.append(el); + await later(); + const fooBar = customAttributes.get(el, 'foo-bar'); + queueMicrotask(() => + // @ts-expect-error TODO make a CustomAttributes map for registering global attribute types. + (fooBar.baz = 'hello world')); + await bazSetPromise; + }); +}); +//# sourceMappingURL=get.test.js.map \ No newline at end of file diff --git a/dist/test/get.test.js.map b/dist/test/get.test.js.map new file mode 100644 index 0000000..7bf7fd3 --- /dev/null +++ b/dist/test/get.test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"get.test.js","sourceRoot":"","sources":["../../src/test/get.test.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAA;AAEpB,QAAQ,CAAC,OAAO,EAAE;IACjB,KAAK,UAAU,KAAK;QACnB,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACzC,CAAC;IAED,EAAE,CAAC,6BAA6B,EAAE,KAAK;QACtC,MAAM,MAAM;SAAG;QACf,gBAAgB,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAE1C,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QACzC,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;QACjC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAExB,MAAM,KAAK,EAAE,CAAA;QAEb,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,CAAC,CAAA;QAClD,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;IACtC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,wCAAwC,EAAE,KAAK;QACjD,MAAM,EAAC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAC,GAAG,OAAO,CAAC,aAAa,EAAQ,CAAA;QAEvE,MAAM,MAAM;YACX,IAAI,GAAG,CAAC,GAAQ;gBACf,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;gBAC/B,OAAO,EAAE,CAAA;YACV,CAAC;SACD;QAED,gBAAgB,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAE1C,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QACzC,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;QACjC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAExB,MAAM,KAAK,EAAE,CAAA;QAEb,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,CAAC,CAAA;QAElD,cAAc,CACb,GAAG,EAAE;QACJ,4FAA4F;QAC5F,CAAC,MAAO,CAAC,GAAG,GAAG,aAAa,CAAC,CAC9B,CAAA;QAED,MAAM,aAAa,CAAA;IACpB,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"} \ No newline at end of file diff --git a/package.json b/package.json index 85ccb78..81a2347 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "dev": "lume dev", "typecheck": "lume typecheck", "typecheck:watch": "lume typecheckWatch", - "test": "echo TODO use 'lume test'", + "test": "lume test", "test:watch": "lume test --watch", "prettier": "lume prettier", "prettier:check": "lume prettierCheck", diff --git a/src/CustomAttributeRegistry.ts b/src/CustomAttributeRegistry.ts index f3755d3..ee3d277 100644 --- a/src/CustomAttributeRegistry.ts +++ b/src/CustomAttributeRegistry.ts @@ -3,20 +3,20 @@ import type {Constructor} from 'lowclass/dist/Constructor.js' const forEach = Array.prototype.forEach export class CustomAttributeRegistry { - private _attrMap = new Map() - private _elementMap = new WeakMap>() + #attrMap = new Map() + #elementMap = new WeakMap>() - private _observer: MutationObserver = new MutationObserver(mutations => { + #observer: MutationObserver = new MutationObserver(mutations => { forEach.call(mutations, (m: MutationRecord) => { if (m.type === 'attributes') { - const attr = this._getConstructor(m.attributeName!) - if (attr) this._handleChange(m.attributeName!, m.target as Element, m.oldValue) + const attr = this.#getConstructor(m.attributeName!) + if (attr) this.#handleChange(m.attributeName!, m.target as Element, m.oldValue) } // chlidList else { - forEach.call(m.removedNodes, this._elementDisconnected) - forEach.call(m.addedNodes, this._elementConnected) + forEach.call(m.removedNodes, this.#elementDisconnected) + forEach.call(m.addedNodes, this.#elementConnected) } }) }) @@ -26,82 +26,82 @@ export class CustomAttributeRegistry { } define(attrName: string, Class: Constructor) { - this._attrMap.set(attrName, Class) - this._upgradeAttr(attrName) - this._reobserve() + this.#attrMap.set(attrName, Class) + this.#upgradeAttr(attrName) + this.#reobserve() } get(element: Element, attrName: string) { - const map = this._elementMap.get(element) + const map = this.#elementMap.get(element) if (!map) return return map.get(attrName) } - private _getConstructor(attrName: string) { - return this._attrMap.get(attrName) + #getConstructor(attrName: string) { + return this.#attrMap.get(attrName) } - private _observe() { - this._observer.observe(this.ownerDocument, { + #observe() { + this.#observer.observe(this.ownerDocument, { childList: true, subtree: true, attributes: true, attributeOldValue: true, - attributeFilter: Array.from(this._attrMap.keys()), + attributeFilter: Array.from(this.#attrMap.keys()), // attributeFilter: [...this._attrMap.keys()], // Broken in Oculus // attributeFilter: this._attrMap.keys(), // This works in Chrome, but TS complains, and not clear if it should work in all browsers yet: https://github.com/whatwg/dom/issues/1092 }) } - private _unobserve() { - this._observer.disconnect() + #unobserve() { + this.#observer.disconnect() } - private _reobserve() { - this._unobserve() - this._observe() + #reobserve() { + this.#unobserve() + this.#observe() } - private _upgradeAttr(attrName: string, node: Element | Document | ShadowRoot = this.ownerDocument) { + #upgradeAttr(attrName: string, node: Element | Document | ShadowRoot = this.ownerDocument) { const matches = node.querySelectorAll('[' + attrName + ']') // Possibly create custom attributes that may be in the given 'node' tree. // Use a forEach as Edge doesn't support for...of on a NodeList - forEach.call(matches, (element: Element) => this._handleChange(attrName, element, null)) + forEach.call(matches, (element: Element) => this.#handleChange(attrName, element, null)) } - private _elementConnected = (element: Element) => { + #elementConnected = (element: Element) => { if (element.nodeType !== 1) return // For each of the connected element's attribute, possibly instantiate the custom attributes. // Use a forEach as Safari 10 doesn't support for...of on NamedNodeMap (attributes) forEach.call(element.attributes, (attr: Attr) => { - if (this._getConstructor(attr.name)) this._handleChange(attr.name, element, null) + if (this.#getConstructor(attr.name)) this.#handleChange(attr.name, element, null) }) // Possibly instantiate custom attributes that may be in the subtree of the connected element. - this._attrMap.forEach((_constructor, attr) => this._upgradeAttr(attr, element)) + this.#attrMap.forEach((_constructor, attr) => this.#upgradeAttr(attr, element)) } - private _elementDisconnected = (element: Element) => { - const map = this._elementMap.get(element) + #elementDisconnected = (element: Element) => { + const map = this.#elementMap.get(element) if (!map) return map.forEach(inst => inst.disconnectedCallback?.(), this) - this._elementMap.delete(element) + this.#elementMap.delete(element) } - private _handleChange(attrName: string, el: Element, oldVal: string | null) { - let map = this._elementMap.get(el) - if (!map) this._elementMap.set(el, (map = new Map())) + #handleChange(attrName: string, el: Element, oldVal: string | null) { + let map = this.#elementMap.get(el) + if (!map) this.#elementMap.set(el, (map = new Map())) let inst = map.get(attrName) const newVal = el.getAttribute(attrName) // Attribute is being created if (!inst) { - const Constructor = this._getConstructor(attrName)! + const Constructor = this.#getConstructor(attrName)! inst = new Constructor() as CustomAttribute map.set(attrName, inst) inst.ownerElement = el @@ -139,10 +139,10 @@ export interface CustomAttribute { // Avoid errors trying to use DOM APIs in non-DOM environments (f.e. server-side rendering). if (globalThis.window?.document) { - const _attachShadow = Element.prototype.attachShadow + const original = Element.prototype.attachShadow Element.prototype.attachShadow = function attachShadow(options) { - const root = _attachShadow.call(this, options) + const root = original.call(this, options) if (!root.customAttributes) root.customAttributes = new CustomAttributeRegistry(root) diff --git a/src/test/change.test.ts b/src/test/change.test.ts new file mode 100644 index 0000000..d30b024 --- /dev/null +++ b/src/test/change.test.ts @@ -0,0 +1,51 @@ +import '../index.js' + +describe('changedCallback()', function () { + async function later() { + await new Promise(r => setTimeout(r, 4)) + } + + it('Is called when an attribute changes value', async function () { + const {resolve, promise: changedPromise} = Promise.withResolvers() + + class SomeAttr { + changedCallback() { + resolve() + } + } + + customAttributes.define('some-attr', SomeAttr) + + const el = document.createElement('article') + el.setAttribute('some-attr', 'foo') + document.body.append(el) + + queueMicrotask(() => el.setAttribute('some-attr', 'bar')) + + await changedPromise + + el.remove() + }) + + it("Is not called when an attribute's value remains the same", async function () { + let count = 0 + + class AnotherAttr { + changedCallback() { + count++ + } + } + + customAttributes.define('another-attr', AnotherAttr) + + const el = document.createElement('span') + el.setAttribute('another-attr', 'foo') + document.body.append(el) + + el.setAttribute('another-attr', 'foo') + + await later() + + expect(count).toBe(0) + }) +}) diff --git a/src/test/connect.test.ts b/src/test/connect.test.ts new file mode 100644 index 0000000..23b0f7d --- /dev/null +++ b/src/test/connect.test.ts @@ -0,0 +1,70 @@ +import '../index.js' + +declare global { + function expect(...args: any[]): any +} + +class BgColorAttr { + declare value: any + declare ownerElement: any + + connectedCallback() { + this.setColor() + } + + changedCallback(_oldValue: any, _newValue: any) { + this.setColor() + } + + setColor() { + const color = this.value || '' + this.ownerElement.style.backgroundColor = color + } +} + +document.body.insertAdjacentHTML( + 'beforeend', + /*html*/ ` +
+

This article is static

+
+`, +) + +customAttributes.define('bg-color', BgColorAttr) + +describe('connectedCallback()', function () { + it('Is called when element is already in the DOM', function () { + const article = document.querySelector('article')! + expect(article!.style.backgroundColor).toBe('red') + article.remove() + }) + + it('Is called when an attribute is dynamically created', async function () { + const article = document.createElement('article') + article.textContent = 'hello world' + document.body.append(article) + + article.setAttribute('bg-color', 'blue') + + await new Promise(r => setTimeout(r, 4)) + + expect(article.style.backgroundColor).toBe('blue') + article.remove() + }) + + it('Is called on nested elements when root element is added to the DOM', async function () { + const article = document.createElement('article') + const header = document.createElement('header') + + header.setAttribute('bg-color', 'blue') + article.append(header) + + document.body.append(article) + + await new Promise(r => setTimeout(r, 4)) + + expect(header.style.backgroundColor).toBe('blue') + article.remove() + }) +}) diff --git a/src/test/disconnect.test.ts b/src/test/disconnect.test.ts new file mode 100644 index 0000000..56977aa --- /dev/null +++ b/src/test/disconnect.test.ts @@ -0,0 +1,63 @@ +import '../index.js' + +describe('disconnectedCallback()', function () { + async function later() { + await new Promise(r => setTimeout(r, 4)) + } + + it('Is called when removeAttribute() is used', async function () { + const {resolve, promise: disconnectedPromise} = Promise.withResolvers() + + let count = 0 + + class MyAttr { + async connectedCallback() { + await later().then(() => el.removeAttribute('my-attr')) + } + + changedCallback() { + count++ + } + + disconnectedCallback() { + resolve() + } + } + + customAttributes.define('my-attr', MyAttr) + + const el = document.createElement('span') + document.body.append(el) + + queueMicrotask(() => el.setAttribute('my-attr', 'test')) + + await disconnectedPromise + + expect(count).toBe(0) + }) + + it('Is called when the element is removed', async function () { + const {resolve, promise: disconnectedPromise} = Promise.withResolvers() + + class SomeAttr { + async connectedCallback() { + await later() + + el.remove() + } + + disconnectedCallback() { + resolve() + } + } + + customAttributes.define('some-attr', SomeAttr) + + const el = document.createElement('span') + document.body.append(el) + + queueMicrotask(() => el.setAttribute('some-attr', 'test')) + + await disconnectedPromise + }) +}) diff --git a/src/test/get.test.ts b/src/test/get.test.ts new file mode 100644 index 0000000..6889291 --- /dev/null +++ b/src/test/get.test.ts @@ -0,0 +1,50 @@ +import '../index.js' + +describe('get()', function () { + async function later() { + await new Promise(r => setTimeout(r, 4)) + } + + it('gets the attribute instance', async function () { + class Foobar {} + customAttributes.define('foo-bar', Foobar) + + const el = document.createElement('span') + el.setAttribute('foo-bar', 'baz') + document.body.append(el) + + await later() + + const fooBar = customAttributes.get(el, 'foo-bar') + expect(fooBar).toBeInstanceOf(Foobar) + }) + + it('allows passing more complex data types', async function () { + const {resolve, promise: bazSetPromise} = Promise.withResolvers() + + class Foobar { + set baz(val: any) { + expect(val).toBe('hello world') + resolve() + } + } + + customAttributes.define('foo-bar', Foobar) + + const el = document.createElement('span') + el.setAttribute('foo-bar', 'bam') + document.body.append(el) + + await later() + + const fooBar = customAttributes.get(el, 'foo-bar') + + queueMicrotask( + () => + // @ts-expect-error TODO make a CustomAttributes map for registering global attribute types. + (fooBar!.baz = 'hello world'), + ) + + await bazSetPromise + }) +}) diff --git a/test/all.html b/test/all.html deleted file mode 100644 index 59da15f..0000000 --- a/test/all.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - Codestin Search App - - - -
- - -
-
- - -
- - diff --git a/test/change.html b/test/change.html deleted file mode 100644 index 751033d..0000000 --- a/test/change.html +++ /dev/null @@ -1,66 +0,0 @@ - - - - Codestin Search App - - - - - - -
- - - - - diff --git a/test/connect.html b/test/connect.html deleted file mode 100644 index f35f8cd..0000000 --- a/test/connect.html +++ /dev/null @@ -1,87 +0,0 @@ - - - - Codestin Search App - - - - - - -
-

This article is static

-
- -
- - - - - - - - diff --git a/test/disconnect.html b/test/disconnect.html deleted file mode 100644 index e455cf6..0000000 --- a/test/disconnect.html +++ /dev/null @@ -1,77 +0,0 @@ - - - - Codestin Search App - - - - - - -
- - - - - - diff --git a/test/get.html b/test/get.html deleted file mode 100644 index 5d1e39c..0000000 --- a/test/get.html +++ /dev/null @@ -1,62 +0,0 @@ - - - - Codestin Search App - - - - - - -
- - - - - From 99733ea047d84dc4c5304b1a816cc051187a4248 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Thu, 26 Sep 2024 21:41:43 -0700 Subject: [PATCH 15/17] run tests in windows --- .github/workflows/tests.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b5a4539..927f363 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,9 +8,7 @@ jobs: strategy: matrix: - # TODO get tests working in Windows too - # windows-latest - operating-system: [ubuntu-latest, macos-latest] + operating-system: [ubuntu-latest, windows-latest, macos-latest] steps: - uses: actions/checkout@v1 From 12f23bc31cca233cd628b0cfefa286d6f5c96a68 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Thu, 26 Sep 2024 21:47:05 -0700 Subject: [PATCH 16/17] update comment --- dist/CustomAttributeRegistry.js | 4 ++-- src/CustomAttributeRegistry.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/CustomAttributeRegistry.js b/dist/CustomAttributeRegistry.js index 55c0bdd..af4033d 100644 --- a/dist/CustomAttributeRegistry.js +++ b/dist/CustomAttributeRegistry.js @@ -43,8 +43,8 @@ export class CustomAttributeRegistry { attributes: true, attributeOldValue: true, attributeFilter: Array.from(this.#attrMap.keys()), - // attributeFilter: [...this._attrMap.keys()], // Broken in Oculus - // attributeFilter: this._attrMap.keys(), // This works in Chrome, but TS complains, and not clear if it should work in all browsers yet: https://github.com/whatwg/dom/issues/1092 + // attributeFilter: [...this.#attrMap.keys()], // Broken in Oculus + // attributeFilter: this.#attrMap.keys(), // This works in Chrome, but TS complains, and not clear if it should work in all browsers yet: https://github.com/whatwg/dom/issues/1092 }); } #unobserve() { diff --git a/src/CustomAttributeRegistry.ts b/src/CustomAttributeRegistry.ts index ee3d277..05644c1 100644 --- a/src/CustomAttributeRegistry.ts +++ b/src/CustomAttributeRegistry.ts @@ -48,8 +48,8 @@ export class CustomAttributeRegistry { attributes: true, attributeOldValue: true, attributeFilter: Array.from(this.#attrMap.keys()), - // attributeFilter: [...this._attrMap.keys()], // Broken in Oculus - // attributeFilter: this._attrMap.keys(), // This works in Chrome, but TS complains, and not clear if it should work in all browsers yet: https://github.com/whatwg/dom/issues/1092 + // attributeFilter: [...this.#attrMap.keys()], // Broken in Oculus + // attributeFilter: this.#attrMap.keys(), // This works in Chrome, but TS complains, and not clear if it should work in all browsers yet: https://github.com/whatwg/dom/issues/1092 }) } From b70ce993e55b8153e13caa50e1e1c52f1cfd6bc0 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Sun, 29 Sep 2024 12:31:48 -0700 Subject: [PATCH 17/17] v0.2.4 --- dist/index.d.ts | 2 +- dist/index.js | 2 +- package.json | 2 +- src/index.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index 5487829..afd94ab 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -10,5 +10,5 @@ declare global { customAttributes: CustomAttributeRegistry; } } -export declare const version = "0.2.3"; +export declare const version = "0.2.4"; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 6fa4583..d2b1e36 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7,5 +7,5 @@ export let customAttributes; // Avoid errors trying to use DOM APIs in non-DOM environments (f.e. server-side rendering). if (globalThis.window?.document) customAttributes = globalThis.customAttributes = new CustomAttributeRegistry(document); -export const version = '0.2.3'; +export const version = '0.2.4'; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/package.json b/package.json index 81a2347..6276cde 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lume/custom-attributes", - "version": "0.2.3", + "version": "0.2.4", "description": "Custom attributes: like custom elements, but for attributes", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 83eb5ff..5d766f1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,4 +28,4 @@ declare global { } } -export const version = '0.2.3' +export const version = '0.2.4'