@spectrum-web-components/reactive-controllers 0.41.2 → 0.42.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/reactive-controllers",
3
- "version": "0.41.2",
3
+ "version": "0.42.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -29,6 +29,10 @@
29
29
  "development": "./src/Color.dev.js",
30
30
  "default": "./src/Color.js"
31
31
  },
32
+ "./src/DependencyManger.js": {
33
+ "development": "./src/DependencyManger.dev.js",
34
+ "default": "./src/DependencyManger.js"
35
+ },
32
36
  "./src/ElementResolution.js": {
33
37
  "development": "./src/ElementResolution.dev.js",
34
38
  "default": "./src/ElementResolution.js"
@@ -79,5 +83,5 @@
79
83
  "sideEffects": [
80
84
  "./**/*.dev.js"
81
85
  ],
82
- "gitHead": "78c3f16b08c9133c9e5ca88d0c9fef5ea7d2ab87"
86
+ "gitHead": "c7ab5516e86d20194e92114afd04affa490b7248"
83
87
  }
@@ -0,0 +1,26 @@
1
+ import type { ReactiveElement } from 'lit';
2
+ export declare const dependencyManagerLoadedSymbol: unique symbol;
3
+ /**
4
+ * Manage the availability of custom element dependencies of a host element
5
+ * to gate render and functional behavior before and after their presence
6
+ */
7
+ export declare class DependencyManagerController {
8
+ private dependencies;
9
+ private host;
10
+ /**
11
+ * Whether all of the provided dependencies have been registered.
12
+ * This will be `false` when no dependencies have been listed for management.
13
+ * Changes to this value will trigger `requestUpdate()` on the host.
14
+ */
15
+ get loaded(): boolean;
16
+ private set loaded(value);
17
+ private _loaded;
18
+ constructor(host: ReactiveElement);
19
+ /**
20
+ * Submit a custom element tag name to be managed as a dependency.
21
+ *
22
+ * @param dependency {string} - the custom element tag to manage
23
+ * @param alreadyLoaded {boolean} - force the managemented custom element to be listed as loaded
24
+ */
25
+ add(dependency: string, alreadyLoaded?: boolean): void;
26
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ export const dependencyManagerLoadedSymbol = Symbol(
3
+ "dependency manager loaded"
4
+ );
5
+ export class DependencyManagerController {
6
+ constructor(host) {
7
+ this.dependencies = {};
8
+ this._loaded = false;
9
+ this.host = host;
10
+ }
11
+ /**
12
+ * Whether all of the provided dependencies have been registered.
13
+ * This will be `false` when no dependencies have been listed for management.
14
+ * Changes to this value will trigger `requestUpdate()` on the host.
15
+ */
16
+ get loaded() {
17
+ return this._loaded;
18
+ }
19
+ set loaded(loaded) {
20
+ if (loaded === this.loaded)
21
+ return;
22
+ this._loaded = loaded;
23
+ this.host.requestUpdate(dependencyManagerLoadedSymbol, !this.loaded);
24
+ }
25
+ /**
26
+ * Submit a custom element tag name to be managed as a dependency.
27
+ *
28
+ * @param dependency {string} - the custom element tag to manage
29
+ * @param alreadyLoaded {boolean} - force the managemented custom element to be listed as loaded
30
+ */
31
+ add(dependency, alreadyLoaded) {
32
+ const loaded = !!alreadyLoaded || !!customElements.get(dependency) || this.dependencies[dependency];
33
+ if (!loaded) {
34
+ customElements.whenDefined(dependency).then(() => {
35
+ this.add(dependency, true);
36
+ });
37
+ }
38
+ this.dependencies = {
39
+ ...this.dependencies,
40
+ [dependency]: loaded
41
+ };
42
+ this.loaded = Object.values(this.dependencies).every(
43
+ (loaded2) => loaded2
44
+ );
45
+ }
46
+ }
47
+ //# sourceMappingURL=DependencyManger.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["DependencyManger.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { ReactiveElement } from 'lit';\nexport const dependencyManagerLoadedSymbol = Symbol(\n 'dependency manager loaded'\n);\n\n/**\n * Manage the availability of custom element dependencies of a host element\n * to gate render and functional behavior before and after their presence\n */\nexport class DependencyManagerController {\n private dependencies: Record<string, boolean> = {};\n\n private host!: ReactiveElement;\n\n /**\n * Whether all of the provided dependencies have been registered.\n * This will be `false` when no dependencies have been listed for management.\n * Changes to this value will trigger `requestUpdate()` on the host.\n */\n public get loaded(): boolean {\n return this._loaded;\n }\n\n private set loaded(loaded: boolean) {\n if (loaded === this.loaded) return;\n this._loaded = loaded;\n this.host.requestUpdate(dependencyManagerLoadedSymbol, !this.loaded);\n }\n\n private _loaded = false;\n\n constructor(host: ReactiveElement) {\n this.host = host;\n }\n\n /**\n * Submit a custom element tag name to be managed as a dependency.\n *\n * @param dependency {string} - the custom element tag to manage\n * @param alreadyLoaded {boolean} - force the managemented custom element to be listed as loaded\n */\n public add(dependency: string, alreadyLoaded?: boolean): void {\n const loaded =\n !!alreadyLoaded ||\n !!customElements.get(dependency) ||\n this.dependencies[dependency];\n if (!loaded) {\n customElements.whenDefined(dependency).then(() => {\n this.add(dependency, true);\n });\n }\n this.dependencies = {\n ...this.dependencies,\n [dependency]: loaded,\n };\n // Update the loaded property based on the new loaded state of all dependencies\n this.loaded = Object.values(this.dependencies).every(\n (loaded) => loaded\n );\n }\n}\n"],
5
+ "mappings": ";AAaO,aAAM,gCAAgC;AAAA,EACzC;AACJ;AAMO,aAAM,4BAA4B;AAAA,EAsBrC,YAAY,MAAuB;AArBnC,SAAQ,eAAwC,CAAC;AAmBjD,SAAQ,UAAU;AAGd,SAAK,OAAO;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAdA,IAAW,SAAkB;AACzB,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAY,OAAO,QAAiB;AAChC,QAAI,WAAW,KAAK;AAAQ;AAC5B,SAAK,UAAU;AACf,SAAK,KAAK,cAAc,+BAA+B,CAAC,KAAK,MAAM;AAAA,EACvE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcO,IAAI,YAAoB,eAA+B;AAC1D,UAAM,SACF,CAAC,CAAC,iBACF,CAAC,CAAC,eAAe,IAAI,UAAU,KAC/B,KAAK,aAAa,UAAU;AAChC,QAAI,CAAC,QAAQ;AACT,qBAAe,YAAY,UAAU,EAAE,KAAK,MAAM;AAC9C,aAAK,IAAI,YAAY,IAAI;AAAA,MAC7B,CAAC;AAAA,IACL;AACA,SAAK,eAAe;AAAA,MAChB,GAAG,KAAK;AAAA,MACR,CAAC,UAAU,GAAG;AAAA,IAClB;AAEA,SAAK,SAAS,OAAO,OAAO,KAAK,YAAY,EAAE;AAAA,MAC3C,CAACA,YAAWA;AAAA,IAChB;AAAA,EACJ;AACJ;",
6
+ "names": ["loaded"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";export const dependencyManagerLoadedSymbol=Symbol("dependency manager loaded");export class DependencyManagerController{constructor(e){this.dependencies={};this._loaded=!1;this.host=e}get loaded(){return this._loaded}set loaded(e){e!==this.loaded&&(this._loaded=e,this.host.requestUpdate(dependencyManagerLoadedSymbol,!this.loaded))}add(e,o){const t=!!o||!!customElements.get(e)||this.dependencies[e];t||customElements.whenDefined(e).then(()=>{this.add(e,!0)}),this.dependencies={...this.dependencies,[e]:t},this.loaded=Object.values(this.dependencies).every(d=>d)}}
2
+ //# sourceMappingURL=DependencyManger.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["DependencyManger.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { ReactiveElement } from 'lit';\nexport const dependencyManagerLoadedSymbol = Symbol(\n 'dependency manager loaded'\n);\n\n/**\n * Manage the availability of custom element dependencies of a host element\n * to gate render and functional behavior before and after their presence\n */\nexport class DependencyManagerController {\n private dependencies: Record<string, boolean> = {};\n\n private host!: ReactiveElement;\n\n /**\n * Whether all of the provided dependencies have been registered.\n * This will be `false` when no dependencies have been listed for management.\n * Changes to this value will trigger `requestUpdate()` on the host.\n */\n public get loaded(): boolean {\n return this._loaded;\n }\n\n private set loaded(loaded: boolean) {\n if (loaded === this.loaded) return;\n this._loaded = loaded;\n this.host.requestUpdate(dependencyManagerLoadedSymbol, !this.loaded);\n }\n\n private _loaded = false;\n\n constructor(host: ReactiveElement) {\n this.host = host;\n }\n\n /**\n * Submit a custom element tag name to be managed as a dependency.\n *\n * @param dependency {string} - the custom element tag to manage\n * @param alreadyLoaded {boolean} - force the managemented custom element to be listed as loaded\n */\n public add(dependency: string, alreadyLoaded?: boolean): void {\n const loaded =\n !!alreadyLoaded ||\n !!customElements.get(dependency) ||\n this.dependencies[dependency];\n if (!loaded) {\n customElements.whenDefined(dependency).then(() => {\n this.add(dependency, true);\n });\n }\n this.dependencies = {\n ...this.dependencies,\n [dependency]: loaded,\n };\n // Update the loaded property based on the new loaded state of all dependencies\n this.loaded = Object.values(this.dependencies).every(\n (loaded) => loaded\n );\n }\n}\n"],
5
+ "mappings": "aAaO,aAAM,8BAAgC,OACzC,2BACJ,EAMO,aAAM,2BAA4B,CAsBrC,YAAYA,EAAuB,CArBnC,KAAQ,aAAwC,CAAC,EAmBjD,KAAQ,QAAU,GAGd,KAAK,KAAOA,CAChB,CAdA,IAAW,QAAkB,CACzB,OAAO,KAAK,OAChB,CAEA,IAAY,OAAOC,EAAiB,CAC5BA,IAAW,KAAK,SACpB,KAAK,QAAUA,EACf,KAAK,KAAK,cAAc,8BAA+B,CAAC,KAAK,MAAM,EACvE,CAcO,IAAIC,EAAoBC,EAA+B,CAC1D,MAAMF,EACF,CAAC,CAACE,GACF,CAAC,CAAC,eAAe,IAAID,CAAU,GAC/B,KAAK,aAAaA,CAAU,EAC3BD,GACD,eAAe,YAAYC,CAAU,EAAE,KAAK,IAAM,CAC9C,KAAK,IAAIA,EAAY,EAAI,CAC7B,CAAC,EAEL,KAAK,aAAe,CAChB,GAAG,KAAK,aACR,CAACA,CAAU,EAAGD,CAClB,EAEA,KAAK,OAAS,OAAO,OAAO,KAAK,YAAY,EAAE,MAC1CA,GAAWA,CAChB,CACJ,CACJ",
6
+ "names": ["host", "loaded", "dependency", "alreadyLoaded"]
7
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ import { expect, nextFrame } from "@open-wc/testing";
3
+ import { DependencyManagerController } from "@spectrum-web-components/reactive-controllers/src/DependencyManger.js";
4
+ import { spy } from "sinon";
5
+ describe("Dependency Manager", () => {
6
+ it("manages dependencies", async function() {
7
+ this.retries(0);
8
+ const tagName = "some-heavy-element";
9
+ const requestUpdateSpy = spy();
10
+ const manager = new DependencyManagerController({
11
+ requestUpdate: () => requestUpdateSpy()
12
+ });
13
+ expect(manager.loaded).to.be.false;
14
+ manager.add(tagName);
15
+ expect(manager.loaded).to.be.false;
16
+ expect(requestUpdateSpy.notCalled).to.be.true;
17
+ customElements.define(tagName, class extends HTMLElement {
18
+ });
19
+ await nextFrame();
20
+ expect(manager.loaded).to.be.true;
21
+ expect(requestUpdateSpy.notCalled).to.be.false;
22
+ });
23
+ });
24
+ //# sourceMappingURL=dependency-manager.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["dependency-manager.test.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { ReactiveElement } from 'lit';\nimport { expect, nextFrame } from '@open-wc/testing';\nimport { DependencyManagerController } from '@spectrum-web-components/reactive-controllers/src/DependencyManger.js';\nimport { spy } from 'sinon';\n\ndescribe('Dependency Manager', () => {\n it('manages dependencies', async function () {\n this.retries(0);\n const tagName = 'some-heavy-element';\n const requestUpdateSpy = spy();\n const manager = new DependencyManagerController({\n requestUpdate: () => requestUpdateSpy(),\n } as unknown as ReactiveElement);\n expect(manager.loaded).to.be.false;\n manager.add(tagName);\n expect(manager.loaded).to.be.false;\n expect(requestUpdateSpy.notCalled).to.be.true;\n customElements.define(tagName, class extends HTMLElement {});\n // Allow time for the registration to propagate.\n await nextFrame();\n expect(manager.loaded).to.be.true;\n expect(requestUpdateSpy.notCalled).to.be.false;\n });\n});\n"],
5
+ "mappings": ";AAaA,SAAS,QAAQ,iBAAiB;AAClC,SAAS,mCAAmC;AAC5C,SAAS,WAAW;AAEpB,SAAS,sBAAsB,MAAM;AACjC,KAAG,wBAAwB,iBAAkB;AACzC,SAAK,QAAQ,CAAC;AACd,UAAM,UAAU;AAChB,UAAM,mBAAmB,IAAI;AAC7B,UAAM,UAAU,IAAI,4BAA4B;AAAA,MAC5C,eAAe,MAAM,iBAAiB;AAAA,IAC1C,CAA+B;AAC/B,WAAO,QAAQ,MAAM,EAAE,GAAG,GAAG;AAC7B,YAAQ,IAAI,OAAO;AACnB,WAAO,QAAQ,MAAM,EAAE,GAAG,GAAG;AAC7B,WAAO,iBAAiB,SAAS,EAAE,GAAG,GAAG;AACzC,mBAAe,OAAO,SAAS,cAAc,YAAY;AAAA,IAAC,CAAC;AAE3D,UAAM,UAAU;AAChB,WAAO,QAAQ,MAAM,EAAE,GAAG,GAAG;AAC7B,WAAO,iBAAiB,SAAS,EAAE,GAAG,GAAG;AAAA,EAC7C,CAAC;AACL,CAAC;",
6
+ "names": []
7
+ }