@spectrum-web-components/reactive-controllers 1.1.0 → 1.1.2

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.
Files changed (65) hide show
  1. package/package.json +3 -3
  2. package/src/Color.d.ts +46 -0
  3. package/src/Color.dev.js +198 -0
  4. package/src/Color.dev.js.map +7 -0
  5. package/src/Color.js +2 -0
  6. package/src/Color.js.map +7 -0
  7. package/src/DependencyManger.d.ts +26 -0
  8. package/src/DependencyManger.dev.js +46 -0
  9. package/src/DependencyManger.dev.js.map +7 -0
  10. package/src/DependencyManger.js +2 -0
  11. package/src/DependencyManger.js.map +7 -0
  12. package/src/ElementResolution.d.ts +23 -0
  13. package/src/ElementResolution.dev.js +85 -0
  14. package/src/ElementResolution.dev.js.map +7 -0
  15. package/src/ElementResolution.js +2 -0
  16. package/src/ElementResolution.js.map +7 -0
  17. package/src/FocusGroup.d.ts +62 -0
  18. package/src/FocusGroup.dev.js +308 -0
  19. package/src/FocusGroup.dev.js.map +7 -0
  20. package/src/FocusGroup.js +2 -0
  21. package/src/FocusGroup.js.map +7 -0
  22. package/src/LanguageResolution.d.ts +11 -0
  23. package/src/LanguageResolution.dev.js +41 -0
  24. package/src/LanguageResolution.dev.js.map +7 -0
  25. package/src/LanguageResolution.js +2 -0
  26. package/src/LanguageResolution.js.map +7 -0
  27. package/src/MatchMedia.d.ts +13 -0
  28. package/src/MatchMedia.dev.js +29 -0
  29. package/src/MatchMedia.dev.js.map +7 -0
  30. package/src/MatchMedia.js +2 -0
  31. package/src/MatchMedia.js.map +7 -0
  32. package/src/PendingState.d.ts +40 -0
  33. package/src/PendingState.dev.js +57 -0
  34. package/src/PendingState.dev.js.map +7 -0
  35. package/src/PendingState.js +10 -0
  36. package/src/PendingState.js.map +7 -0
  37. package/src/RovingTabindex.d.ts +19 -0
  38. package/src/RovingTabindex.dev.js +72 -0
  39. package/src/RovingTabindex.dev.js.map +7 -0
  40. package/src/RovingTabindex.js +2 -0
  41. package/src/RovingTabindex.js.map +7 -0
  42. package/src/SystemContextResolution.d.ts +15 -0
  43. package/src/SystemContextResolution.dev.js +39 -0
  44. package/src/SystemContextResolution.dev.js.map +7 -0
  45. package/src/SystemContextResolution.js +2 -0
  46. package/src/SystemContextResolution.js.map +7 -0
  47. package/src/index.d.ts +2 -0
  48. package/src/index.dev.js +4 -0
  49. package/src/index.dev.js.map +7 -0
  50. package/src/index.js +2 -0
  51. package/src/index.js.map +7 -0
  52. package/test/dependency-manager.test.js +24 -0
  53. package/test/dependency-manager.test.js.map +7 -0
  54. package/test/element-resolution.test.js +40 -0
  55. package/test/element-resolution.test.js.map +7 -0
  56. package/test/helpers.js +23 -0
  57. package/test/helpers.js.map +7 -0
  58. package/test/match-media.test.js +29 -0
  59. package/test/match-media.test.js.map +7 -0
  60. package/test/pending-state.test.js +128 -0
  61. package/test/pending-state.test.js.map +7 -0
  62. package/test/roving-tabindex-integration.test.js +244 -0
  63. package/test/roving-tabindex-integration.test.js.map +7 -0
  64. package/test/roving-tabindex.test.js +19 -0
  65. package/test/roving-tabindex.test.js.map +7 -0
@@ -0,0 +1,40 @@
1
+ import { LitElement, ReactiveController, TemplateResult } from 'lit';
2
+ import '@spectrum-web-components/progress-circle/sp-progress-circle.js';
3
+ /**
4
+ * Represents a host element with pending state.
5
+ */
6
+ export interface HostWithPendingState extends LitElement {
7
+ pendingLabel?: string;
8
+ pending: boolean;
9
+ disabled: boolean;
10
+ pendingStateController: PendingStateController<HostWithPendingState>;
11
+ }
12
+ /**
13
+ * Represents a controller for managing the pending state of a reactive element.
14
+ *
15
+ * @template T - The type of the reactive element.
16
+ */
17
+ export declare class PendingStateController<T extends HostWithPendingState> implements ReactiveController {
18
+ /**
19
+ * The host element that this controller is attached to.
20
+ */
21
+ host: T;
22
+ /**
23
+ * Creates an instance of PendingStateController.
24
+ * @param host - The host element that this controller is attached to.
25
+ */
26
+ constructor(host: T);
27
+ cachedAriaLabel: string | null;
28
+ /**
29
+ * Renders the pending state UI.
30
+ * @returns A TemplateResult representing the pending state UI.
31
+ */
32
+ renderPendingState(): TemplateResult;
33
+ /**
34
+ * Updates the ARIA label of the host element based on the pending state.
35
+ * Manages Cached Aria Label
36
+ */
37
+ private updateAriaLabel;
38
+ hostConnected(): void;
39
+ hostUpdated(): void;
40
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ import { html } from "lit";
3
+ import "@spectrum-web-components/progress-circle/sp-progress-circle.js";
4
+ export class PendingStateController {
5
+ /**
6
+ * Creates an instance of PendingStateController.
7
+ * @param host - The host element that this controller is attached to.
8
+ */
9
+ constructor(host) {
10
+ this.cachedAriaLabel = null;
11
+ this.host = host;
12
+ this.host.addController(this);
13
+ }
14
+ /**
15
+ * Renders the pending state UI.
16
+ * @returns A TemplateResult representing the pending state UI.
17
+ */
18
+ renderPendingState() {
19
+ const pendingLabel = this.host.pendingLabel || "Pending";
20
+ return this.host.pending ? html`
21
+ <sp-progress-circle
22
+ id="loader"
23
+ size="s"
24
+ indeterminate
25
+ aria-valuetext=${pendingLabel}
26
+ class="progress-circle"
27
+ ></sp-progress-circle>
28
+ ` : html``;
29
+ }
30
+ /**
31
+ * Updates the ARIA label of the host element based on the pending state.
32
+ * Manages Cached Aria Label
33
+ */
34
+ updateAriaLabel() {
35
+ const { pending, disabled, pendingLabel } = this.host;
36
+ const currentAriaLabel = this.host.getAttribute("aria-label");
37
+ if (pending && !disabled && currentAriaLabel !== pendingLabel) {
38
+ this.cachedAriaLabel = currentAriaLabel;
39
+ this.host.setAttribute("aria-label", pendingLabel || "Pending");
40
+ } else if (!pending || disabled) {
41
+ if (this.cachedAriaLabel) {
42
+ this.host.setAttribute("aria-label", this.cachedAriaLabel);
43
+ } else if (!pending) {
44
+ this.host.removeAttribute("aria-label");
45
+ }
46
+ }
47
+ }
48
+ hostConnected() {
49
+ if (!this.cachedAriaLabel)
50
+ this.cachedAriaLabel = this.host.getAttribute("aria-label");
51
+ this.updateAriaLabel();
52
+ }
53
+ hostUpdated() {
54
+ this.updateAriaLabel();
55
+ }
56
+ }
57
+ //# sourceMappingURL=PendingState.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["PendingState.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2024 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 { html, LitElement, ReactiveController, TemplateResult } from 'lit';\nimport '@spectrum-web-components/progress-circle/sp-progress-circle.js';\n\n/**\n * Represents a host element with pending state.\n */\nexport interface HostWithPendingState extends LitElement {\n pendingLabel?: string;\n pending: boolean;\n disabled: boolean;\n pendingStateController: PendingStateController<HostWithPendingState>;\n}\n\n/**\n * Represents a controller for managing the pending state of a reactive element.\n *\n * @template T - The type of the reactive element.\n */\nexport class PendingStateController<T extends HostWithPendingState>\n implements ReactiveController\n{\n /**\n * The host element that this controller is attached to.\n */\n public host: T;\n\n /**\n * Creates an instance of PendingStateController.\n * @param host - The host element that this controller is attached to.\n */\n constructor(host: T) {\n this.host = host;\n this.host.addController(this);\n }\n\n public cachedAriaLabel: string | null = null;\n /**\n * Renders the pending state UI.\n * @returns A TemplateResult representing the pending state UI.\n */\n public renderPendingState(): TemplateResult {\n const pendingLabel = this.host.pendingLabel || 'Pending';\n return this.host.pending\n ? html`\n <sp-progress-circle\n id=\"loader\"\n size=\"s\"\n indeterminate\n aria-valuetext=${pendingLabel}\n class=\"progress-circle\"\n ></sp-progress-circle>\n `\n : html``;\n }\n\n /**\n * Updates the ARIA label of the host element based on the pending state.\n * Manages Cached Aria Label\n */\n private updateAriaLabel(): void {\n const { pending, disabled, pendingLabel } = this.host;\n const currentAriaLabel = this.host.getAttribute('aria-label');\n\n if (pending && !disabled && currentAriaLabel !== pendingLabel) {\n // Cache the current `aria-label` to be restored when no longer `pending`\n this.cachedAriaLabel = currentAriaLabel;\n // Since it is pending, we set the aria-label to `pendingLabel` or \"Pending\"\n this.host.setAttribute('aria-label', pendingLabel || 'Pending');\n } else if (!pending || disabled) {\n // Restore the cached `aria-label` if it exists\n if (this.cachedAriaLabel) {\n this.host.setAttribute('aria-label', this.cachedAriaLabel);\n } else if (!pending) {\n // If no cached `aria-label` and not `pending`, remove the `aria-label`\n this.host.removeAttribute('aria-label');\n }\n }\n }\n\n hostConnected(): void {\n if (!this.cachedAriaLabel)\n this.cachedAriaLabel = this.host.getAttribute('aria-label');\n this.updateAriaLabel();\n }\n\n hostUpdated(): void {\n this.updateAriaLabel();\n }\n}\n"],
5
+ "mappings": ";AAYA,SAAS,YAA4D;AACrE,OAAO;AAiBA,aAAM,uBAEb;AAAA;AAAA;AAAA;AAAA;AAAA,EAUI,YAAY,MAAS;AAKrB,SAAO,kBAAiC;AAJpC,SAAK,OAAO;AACZ,SAAK,KAAK,cAAc,IAAI;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,qBAAqC;AACxC,UAAM,eAAe,KAAK,KAAK,gBAAgB;AAC/C,WAAO,KAAK,KAAK,UACX;AAAA;AAAA;AAAA;AAAA;AAAA,uCAKyB,YAAY;AAAA;AAAA;AAAA,kBAIrC;AAAA,EACV;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,kBAAwB;AAC5B,UAAM,EAAE,SAAS,UAAU,aAAa,IAAI,KAAK;AACjD,UAAM,mBAAmB,KAAK,KAAK,aAAa,YAAY;AAE5D,QAAI,WAAW,CAAC,YAAY,qBAAqB,cAAc;AAE3D,WAAK,kBAAkB;AAEvB,WAAK,KAAK,aAAa,cAAc,gBAAgB,SAAS;AAAA,IAClE,WAAW,CAAC,WAAW,UAAU;AAE7B,UAAI,KAAK,iBAAiB;AACtB,aAAK,KAAK,aAAa,cAAc,KAAK,eAAe;AAAA,MAC7D,WAAW,CAAC,SAAS;AAEjB,aAAK,KAAK,gBAAgB,YAAY;AAAA,MAC1C;AAAA,IACJ;AAAA,EACJ;AAAA,EAEA,gBAAsB;AAClB,QAAI,CAAC,KAAK;AACN,WAAK,kBAAkB,KAAK,KAAK,aAAa,YAAY;AAC9D,SAAK,gBAAgB;AAAA,EACzB;AAAA,EAEA,cAAoB;AAChB,SAAK,gBAAgB;AAAA,EACzB;AACJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";import{html as s}from"lit";import"@spectrum-web-components/progress-circle/sp-progress-circle.js";export class PendingStateController{constructor(e){this.cachedAriaLabel=null;this.host=e,this.host.addController(this)}renderPendingState(){const e=this.host.pendingLabel||"Pending";return this.host.pending?s`
2
+ <sp-progress-circle
3
+ id="loader"
4
+ size="s"
5
+ indeterminate
6
+ aria-valuetext=${e}
7
+ class="progress-circle"
8
+ ></sp-progress-circle>
9
+ `:s``}updateAriaLabel(){const{pending:e,disabled:t,pendingLabel:i}=this.host,a=this.host.getAttribute("aria-label");e&&!t&&a!==i?(this.cachedAriaLabel=a,this.host.setAttribute("aria-label",i||"Pending")):(!e||t)&&(this.cachedAriaLabel?this.host.setAttribute("aria-label",this.cachedAriaLabel):e||this.host.removeAttribute("aria-label"))}hostConnected(){this.cachedAriaLabel||(this.cachedAriaLabel=this.host.getAttribute("aria-label")),this.updateAriaLabel()}hostUpdated(){this.updateAriaLabel()}}
10
+ //# sourceMappingURL=PendingState.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["PendingState.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2024 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 { html, LitElement, ReactiveController, TemplateResult } from 'lit';\nimport '@spectrum-web-components/progress-circle/sp-progress-circle.js';\n\n/**\n * Represents a host element with pending state.\n */\nexport interface HostWithPendingState extends LitElement {\n pendingLabel?: string;\n pending: boolean;\n disabled: boolean;\n pendingStateController: PendingStateController<HostWithPendingState>;\n}\n\n/**\n * Represents a controller for managing the pending state of a reactive element.\n *\n * @template T - The type of the reactive element.\n */\nexport class PendingStateController<T extends HostWithPendingState>\n implements ReactiveController\n{\n /**\n * The host element that this controller is attached to.\n */\n public host: T;\n\n /**\n * Creates an instance of PendingStateController.\n * @param host - The host element that this controller is attached to.\n */\n constructor(host: T) {\n this.host = host;\n this.host.addController(this);\n }\n\n public cachedAriaLabel: string | null = null;\n /**\n * Renders the pending state UI.\n * @returns A TemplateResult representing the pending state UI.\n */\n public renderPendingState(): TemplateResult {\n const pendingLabel = this.host.pendingLabel || 'Pending';\n return this.host.pending\n ? html`\n <sp-progress-circle\n id=\"loader\"\n size=\"s\"\n indeterminate\n aria-valuetext=${pendingLabel}\n class=\"progress-circle\"\n ></sp-progress-circle>\n `\n : html``;\n }\n\n /**\n * Updates the ARIA label of the host element based on the pending state.\n * Manages Cached Aria Label\n */\n private updateAriaLabel(): void {\n const { pending, disabled, pendingLabel } = this.host;\n const currentAriaLabel = this.host.getAttribute('aria-label');\n\n if (pending && !disabled && currentAriaLabel !== pendingLabel) {\n // Cache the current `aria-label` to be restored when no longer `pending`\n this.cachedAriaLabel = currentAriaLabel;\n // Since it is pending, we set the aria-label to `pendingLabel` or \"Pending\"\n this.host.setAttribute('aria-label', pendingLabel || 'Pending');\n } else if (!pending || disabled) {\n // Restore the cached `aria-label` if it exists\n if (this.cachedAriaLabel) {\n this.host.setAttribute('aria-label', this.cachedAriaLabel);\n } else if (!pending) {\n // If no cached `aria-label` and not `pending`, remove the `aria-label`\n this.host.removeAttribute('aria-label');\n }\n }\n }\n\n hostConnected(): void {\n if (!this.cachedAriaLabel)\n this.cachedAriaLabel = this.host.getAttribute('aria-label');\n this.updateAriaLabel();\n }\n\n hostUpdated(): void {\n this.updateAriaLabel();\n }\n}\n"],
5
+ "mappings": "aAYA,OAAS,QAAAA,MAA4D,MACrE,MAAO,iEAiBA,aAAM,sBAEb,CAUI,YAAYC,EAAS,CAKrB,KAAO,gBAAiC,KAJpC,KAAK,KAAOA,EACZ,KAAK,KAAK,cAAc,IAAI,CAChC,CAOO,oBAAqC,CACxC,MAAMC,EAAe,KAAK,KAAK,cAAgB,UAC/C,OAAO,KAAK,KAAK,QACXF;AAAA;AAAA;AAAA;AAAA;AAAA,uCAKyBE,CAAY;AAAA;AAAA;AAAA,gBAIrCF,GACV,CAMQ,iBAAwB,CAC5B,KAAM,CAAE,QAAAG,EAAS,SAAAC,EAAU,aAAAF,CAAa,EAAI,KAAK,KAC3CG,EAAmB,KAAK,KAAK,aAAa,YAAY,EAExDF,GAAW,CAACC,GAAYC,IAAqBH,GAE7C,KAAK,gBAAkBG,EAEvB,KAAK,KAAK,aAAa,aAAcH,GAAgB,SAAS,IACvD,CAACC,GAAWC,KAEf,KAAK,gBACL,KAAK,KAAK,aAAa,aAAc,KAAK,eAAe,EACjDD,GAER,KAAK,KAAK,gBAAgB,YAAY,EAGlD,CAEA,eAAsB,CACb,KAAK,kBACN,KAAK,gBAAkB,KAAK,KAAK,aAAa,YAAY,GAC9D,KAAK,gBAAgB,CACzB,CAEA,aAAoB,CAChB,KAAK,gBAAgB,CACzB,CACJ",
6
+ "names": ["html", "host", "pendingLabel", "pending", "disabled", "currentAriaLabel"]
7
+ }
@@ -0,0 +1,19 @@
1
+ import { FocusGroupConfig, FocusGroupController } from './FocusGroup.js';
2
+ export type RovingTabindexConfig<T> = FocusGroupConfig<T>;
3
+ interface UpdateTabIndexes {
4
+ tabIndex: number;
5
+ removeTabIndex?: boolean;
6
+ }
7
+ export declare class RovingTabindexController<T extends HTMLElement> extends FocusGroupController<T> {
8
+ protected set focused(focused: boolean);
9
+ protected get focused(): boolean;
10
+ private managed;
11
+ private manageIndexesAnimationFrame;
12
+ clearElementCache(offset?: number): void;
13
+ manageTabindexes(): void;
14
+ updateTabindexes(getTabIndex: (el: HTMLElement) => UpdateTabIndexes): void;
15
+ manage(): void;
16
+ unmanage(): void;
17
+ hostUpdated(): void;
18
+ }
19
+ export {};
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ import { FocusGroupController } from "./FocusGroup.dev.js";
3
+ export class RovingTabindexController extends FocusGroupController {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.managed = true;
7
+ this.manageIndexesAnimationFrame = 0;
8
+ }
9
+ set focused(focused) {
10
+ if (focused === this.focused) return;
11
+ super.focused = focused;
12
+ this.manageTabindexes();
13
+ }
14
+ get focused() {
15
+ return super.focused;
16
+ }
17
+ clearElementCache(offset = 0) {
18
+ cancelAnimationFrame(this.manageIndexesAnimationFrame);
19
+ super.clearElementCache(offset);
20
+ if (!this.managed) return;
21
+ this.manageIndexesAnimationFrame = requestAnimationFrame(
22
+ () => this.manageTabindexes()
23
+ );
24
+ }
25
+ manageTabindexes() {
26
+ if (this.focused) {
27
+ this.updateTabindexes(() => ({ tabIndex: -1 }));
28
+ } else {
29
+ this.updateTabindexes((el) => {
30
+ return {
31
+ removeTabIndex: el.contains(this.focusInElement) && el !== this.focusInElement,
32
+ tabIndex: el === this.focusInElement ? 0 : -1
33
+ };
34
+ });
35
+ }
36
+ }
37
+ updateTabindexes(getTabIndex) {
38
+ this.elements.forEach((el) => {
39
+ const { tabIndex, removeTabIndex } = getTabIndex(el);
40
+ if (!removeTabIndex) {
41
+ if (this.focused) {
42
+ if (el !== this.elements[this.currentIndex]) {
43
+ el.tabIndex = tabIndex;
44
+ }
45
+ } else {
46
+ el.tabIndex = tabIndex;
47
+ }
48
+ return;
49
+ }
50
+ el.removeAttribute("tabindex");
51
+ const updatable = el;
52
+ if (updatable.requestUpdate) updatable.requestUpdate();
53
+ });
54
+ }
55
+ manage() {
56
+ this.managed = true;
57
+ this.manageTabindexes();
58
+ super.manage();
59
+ }
60
+ unmanage() {
61
+ this.managed = false;
62
+ this.updateTabindexes(() => ({ tabIndex: 0 }));
63
+ super.unmanage();
64
+ }
65
+ hostUpdated() {
66
+ super.hostUpdated();
67
+ if (!this.host.hasUpdated) {
68
+ this.manageTabindexes();
69
+ }
70
+ }
71
+ }
72
+ //# sourceMappingURL=RovingTabindex.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["RovingTabindex.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 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*/\nimport { FocusGroupConfig, FocusGroupController } from './FocusGroup.dev.js'\n\nexport type RovingTabindexConfig<T> = FocusGroupConfig<T>;\ninterface UpdateTabIndexes {\n tabIndex: number;\n removeTabIndex?: boolean;\n}\n\nexport class RovingTabindexController<\n T extends HTMLElement,\n> extends FocusGroupController<T> {\n protected override set focused(focused: boolean) {\n if (focused === this.focused) return;\n super.focused = focused;\n this.manageTabindexes();\n }\n\n protected override get focused(): boolean {\n return super.focused;\n }\n\n private managed = true;\n\n private manageIndexesAnimationFrame = 0;\n\n override clearElementCache(offset = 0): void {\n cancelAnimationFrame(this.manageIndexesAnimationFrame);\n super.clearElementCache(offset);\n if (!this.managed) return;\n\n this.manageIndexesAnimationFrame = requestAnimationFrame(() =>\n this.manageTabindexes()\n );\n }\n\n manageTabindexes(): void {\n if (this.focused) {\n this.updateTabindexes(() => ({ tabIndex: -1 }));\n } else {\n this.updateTabindexes((el: HTMLElement): UpdateTabIndexes => {\n return {\n removeTabIndex:\n el.contains(this.focusInElement) &&\n el !== this.focusInElement,\n tabIndex: el === this.focusInElement ? 0 : -1,\n };\n });\n }\n }\n\n updateTabindexes(getTabIndex: (el: HTMLElement) => UpdateTabIndexes): void {\n this.elements.forEach((el) => {\n const { tabIndex, removeTabIndex } = getTabIndex(el);\n if (!removeTabIndex) {\n if (this.focused) {\n if (el !== this.elements[this.currentIndex]) {\n el.tabIndex = tabIndex;\n }\n } else {\n el.tabIndex = tabIndex;\n }\n return;\n }\n el.removeAttribute('tabindex');\n const updatable = el as unknown as {\n requestUpdate?: () => void;\n };\n if (updatable.requestUpdate) updatable.requestUpdate();\n });\n }\n\n override manage(): void {\n this.managed = true;\n this.manageTabindexes();\n super.manage();\n }\n\n override unmanage(): void {\n this.managed = false;\n this.updateTabindexes(() => ({ tabIndex: 0 }));\n super.unmanage();\n }\n\n override hostUpdated(): void {\n super.hostUpdated();\n if (!this.host.hasUpdated) {\n this.manageTabindexes();\n }\n }\n}\n"],
5
+ "mappings": ";AAWA,SAA2B,4BAA4B;AAQhD,aAAM,iCAEH,qBAAwB;AAAA,EAF3B;AAAA;AAaH,SAAQ,UAAU;AAElB,SAAQ,8BAA8B;AAAA;AAAA,EAZtC,IAAuB,QAAQ,SAAkB;AAC7C,QAAI,YAAY,KAAK,QAAS;AAC9B,UAAM,UAAU;AAChB,SAAK,iBAAiB;AAAA,EAC1B;AAAA,EAEA,IAAuB,UAAmB;AACtC,WAAO,MAAM;AAAA,EACjB;AAAA,EAMS,kBAAkB,SAAS,GAAS;AACzC,yBAAqB,KAAK,2BAA2B;AACrD,UAAM,kBAAkB,MAAM;AAC9B,QAAI,CAAC,KAAK,QAAS;AAEnB,SAAK,8BAA8B;AAAA,MAAsB,MACrD,KAAK,iBAAiB;AAAA,IAC1B;AAAA,EACJ;AAAA,EAEA,mBAAyB;AACrB,QAAI,KAAK,SAAS;AACd,WAAK,iBAAiB,OAAO,EAAE,UAAU,GAAG,EAAE;AAAA,IAClD,OAAO;AACH,WAAK,iBAAiB,CAAC,OAAsC;AACzD,eAAO;AAAA,UACH,gBACI,GAAG,SAAS,KAAK,cAAc,KAC/B,OAAO,KAAK;AAAA,UAChB,UAAU,OAAO,KAAK,iBAAiB,IAAI;AAAA,QAC/C;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,EACJ;AAAA,EAEA,iBAAiB,aAA0D;AACvE,SAAK,SAAS,QAAQ,CAAC,OAAO;AAC1B,YAAM,EAAE,UAAU,eAAe,IAAI,YAAY,EAAE;AACnD,UAAI,CAAC,gBAAgB;AACjB,YAAI,KAAK,SAAS;AACd,cAAI,OAAO,KAAK,SAAS,KAAK,YAAY,GAAG;AACzC,eAAG,WAAW;AAAA,UAClB;AAAA,QACJ,OAAO;AACH,aAAG,WAAW;AAAA,QAClB;AACA;AAAA,MACJ;AACA,SAAG,gBAAgB,UAAU;AAC7B,YAAM,YAAY;AAGlB,UAAI,UAAU,cAAe,WAAU,cAAc;AAAA,IACzD,CAAC;AAAA,EACL;AAAA,EAES,SAAe;AACpB,SAAK,UAAU;AACf,SAAK,iBAAiB;AACtB,UAAM,OAAO;AAAA,EACjB;AAAA,EAES,WAAiB;AACtB,SAAK,UAAU;AACf,SAAK,iBAAiB,OAAO,EAAE,UAAU,EAAE,EAAE;AAC7C,UAAM,SAAS;AAAA,EACnB;AAAA,EAES,cAAoB;AACzB,UAAM,YAAY;AAClB,QAAI,CAAC,KAAK,KAAK,YAAY;AACvB,WAAK,iBAAiB;AAAA,IAC1B;AAAA,EACJ;AACJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";import{FocusGroupController as i}from"./FocusGroup.js";export class RovingTabindexController extends i{constructor(){super(...arguments);this.managed=!0;this.manageIndexesAnimationFrame=0}set focused(e){e!==this.focused&&(super.focused=e,this.manageTabindexes())}get focused(){return super.focused}clearElementCache(e=0){cancelAnimationFrame(this.manageIndexesAnimationFrame),super.clearElementCache(e),this.managed&&(this.manageIndexesAnimationFrame=requestAnimationFrame(()=>this.manageTabindexes()))}manageTabindexes(){this.focused?this.updateTabindexes(()=>({tabIndex:-1})):this.updateTabindexes(e=>({removeTabIndex:e.contains(this.focusInElement)&&e!==this.focusInElement,tabIndex:e===this.focusInElement?0:-1}))}updateTabindexes(e){this.elements.forEach(a=>{const{tabIndex:n,removeTabIndex:s}=e(a);if(!s){this.focused?a!==this.elements[this.currentIndex]&&(a.tabIndex=n):a.tabIndex=n;return}a.removeAttribute("tabindex");const t=a;t.requestUpdate&&t.requestUpdate()})}manage(){this.managed=!0,this.manageTabindexes(),super.manage()}unmanage(){this.managed=!1,this.updateTabindexes(()=>({tabIndex:0})),super.unmanage()}hostUpdated(){super.hostUpdated(),this.host.hasUpdated||this.manageTabindexes()}}
2
+ //# sourceMappingURL=RovingTabindex.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["RovingTabindex.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 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*/\nimport { FocusGroupConfig, FocusGroupController } from './FocusGroup.js';\n\nexport type RovingTabindexConfig<T> = FocusGroupConfig<T>;\ninterface UpdateTabIndexes {\n tabIndex: number;\n removeTabIndex?: boolean;\n}\n\nexport class RovingTabindexController<\n T extends HTMLElement,\n> extends FocusGroupController<T> {\n protected override set focused(focused: boolean) {\n if (focused === this.focused) return;\n super.focused = focused;\n this.manageTabindexes();\n }\n\n protected override get focused(): boolean {\n return super.focused;\n }\n\n private managed = true;\n\n private manageIndexesAnimationFrame = 0;\n\n override clearElementCache(offset = 0): void {\n cancelAnimationFrame(this.manageIndexesAnimationFrame);\n super.clearElementCache(offset);\n if (!this.managed) return;\n\n this.manageIndexesAnimationFrame = requestAnimationFrame(() =>\n this.manageTabindexes()\n );\n }\n\n manageTabindexes(): void {\n if (this.focused) {\n this.updateTabindexes(() => ({ tabIndex: -1 }));\n } else {\n this.updateTabindexes((el: HTMLElement): UpdateTabIndexes => {\n return {\n removeTabIndex:\n el.contains(this.focusInElement) &&\n el !== this.focusInElement,\n tabIndex: el === this.focusInElement ? 0 : -1,\n };\n });\n }\n }\n\n updateTabindexes(getTabIndex: (el: HTMLElement) => UpdateTabIndexes): void {\n this.elements.forEach((el) => {\n const { tabIndex, removeTabIndex } = getTabIndex(el);\n if (!removeTabIndex) {\n if (this.focused) {\n if (el !== this.elements[this.currentIndex]) {\n el.tabIndex = tabIndex;\n }\n } else {\n el.tabIndex = tabIndex;\n }\n return;\n }\n el.removeAttribute('tabindex');\n const updatable = el as unknown as {\n requestUpdate?: () => void;\n };\n if (updatable.requestUpdate) updatable.requestUpdate();\n });\n }\n\n override manage(): void {\n this.managed = true;\n this.manageTabindexes();\n super.manage();\n }\n\n override unmanage(): void {\n this.managed = false;\n this.updateTabindexes(() => ({ tabIndex: 0 }));\n super.unmanage();\n }\n\n override hostUpdated(): void {\n super.hostUpdated();\n if (!this.host.hasUpdated) {\n this.manageTabindexes();\n }\n }\n}\n"],
5
+ "mappings": "aAWA,OAA2B,wBAAAA,MAA4B,kBAQhD,aAAM,iCAEHA,CAAwB,CAF3B,kCAaH,KAAQ,QAAU,GAElB,KAAQ,4BAA8B,EAZtC,IAAuB,QAAQC,EAAkB,CACzCA,IAAY,KAAK,UACrB,MAAM,QAAUA,EAChB,KAAK,iBAAiB,EAC1B,CAEA,IAAuB,SAAmB,CACtC,OAAO,MAAM,OACjB,CAMS,kBAAkBC,EAAS,EAAS,CACzC,qBAAqB,KAAK,2BAA2B,EACrD,MAAM,kBAAkBA,CAAM,EACzB,KAAK,UAEV,KAAK,4BAA8B,sBAAsB,IACrD,KAAK,iBAAiB,CAC1B,EACJ,CAEA,kBAAyB,CACjB,KAAK,QACL,KAAK,iBAAiB,KAAO,CAAE,SAAU,EAAG,EAAE,EAE9C,KAAK,iBAAkBC,IACZ,CACH,eACIA,EAAG,SAAS,KAAK,cAAc,GAC/BA,IAAO,KAAK,eAChB,SAAUA,IAAO,KAAK,eAAiB,EAAI,EAC/C,EACH,CAET,CAEA,iBAAiBC,EAA0D,CACvE,KAAK,SAAS,QAASD,GAAO,CAC1B,KAAM,CAAE,SAAAE,EAAU,eAAAC,CAAe,EAAIF,EAAYD,CAAE,EACnD,GAAI,CAACG,EAAgB,CACb,KAAK,QACDH,IAAO,KAAK,SAAS,KAAK,YAAY,IACtCA,EAAG,SAAWE,GAGlBF,EAAG,SAAWE,EAElB,MACJ,CACAF,EAAG,gBAAgB,UAAU,EAC7B,MAAMI,EAAYJ,EAGdI,EAAU,eAAeA,EAAU,cAAc,CACzD,CAAC,CACL,CAES,QAAe,CACpB,KAAK,QAAU,GACf,KAAK,iBAAiB,EACtB,MAAM,OAAO,CACjB,CAES,UAAiB,CACtB,KAAK,QAAU,GACf,KAAK,iBAAiB,KAAO,CAAE,SAAU,CAAE,EAAE,EAC7C,MAAM,SAAS,CACnB,CAES,aAAoB,CACzB,MAAM,YAAY,EACb,KAAK,KAAK,YACX,KAAK,iBAAiB,CAE9B,CACJ",
6
+ "names": ["FocusGroupController", "focused", "offset", "el", "getTabIndex", "tabIndex", "removeTabIndex", "updatable"]
7
+ }
@@ -0,0 +1,15 @@
1
+ import type { ReactiveController, ReactiveElement } from 'lit';
2
+ import type { SystemVariant } from '@spectrum-web-components/theme';
3
+ export declare const systemResolverUpdatedSymbol: unique symbol;
4
+ export type ProvideSystem = {
5
+ callback: (system: SystemVariant, unsubscribe: () => void) => void;
6
+ };
7
+ export declare class SystemResolutionController implements ReactiveController {
8
+ private host;
9
+ system: SystemVariant;
10
+ private unsubscribe?;
11
+ constructor(host: ReactiveElement);
12
+ hostConnected(): void;
13
+ hostDisconnected(): void;
14
+ private resolveSystem;
15
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ export const systemResolverUpdatedSymbol = Symbol("system resolver updated");
3
+ export class SystemResolutionController {
4
+ constructor(host) {
5
+ this.system = "spectrum";
6
+ this.host = host;
7
+ this.host.addController(this);
8
+ }
9
+ hostConnected() {
10
+ this.resolveSystem();
11
+ }
12
+ hostDisconnected() {
13
+ var _a;
14
+ (_a = this.unsubscribe) == null ? void 0 : _a.call(this);
15
+ }
16
+ resolveSystem() {
17
+ const querySystemEvent = new CustomEvent(
18
+ "sp-system-context",
19
+ {
20
+ bubbles: true,
21
+ composed: true,
22
+ detail: {
23
+ callback: (system, unsubscribe) => {
24
+ const previous = this.system;
25
+ this.system = system;
26
+ this.unsubscribe = unsubscribe;
27
+ this.host.requestUpdate(
28
+ systemResolverUpdatedSymbol,
29
+ previous
30
+ );
31
+ }
32
+ },
33
+ cancelable: true
34
+ }
35
+ );
36
+ this.host.dispatchEvent(querySystemEvent);
37
+ }
38
+ }
39
+ //# sourceMappingURL=SystemContextResolution.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["SystemContextResolution.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2024 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*/\nimport type { ReactiveController, ReactiveElement } from 'lit';\nimport type { SystemVariant } from '@spectrum-web-components/theme';\n\nexport const systemResolverUpdatedSymbol = Symbol('system resolver updated');\n\nexport type ProvideSystem = {\n callback: (system: SystemVariant, unsubscribe: () => void) => void;\n};\n\nexport class SystemResolutionController implements ReactiveController {\n private host: ReactiveElement;\n public system: SystemVariant = 'spectrum';\n private unsubscribe?: () => void;\n\n constructor(host: ReactiveElement) {\n this.host = host;\n this.host.addController(this);\n }\n\n public hostConnected(): void {\n this.resolveSystem();\n }\n\n public hostDisconnected(): void {\n this.unsubscribe?.();\n }\n\n private resolveSystem(): void {\n const querySystemEvent = new CustomEvent<ProvideSystem>(\n 'sp-system-context',\n {\n bubbles: true,\n composed: true,\n detail: {\n callback: (\n system: SystemVariant,\n unsubscribe: () => void\n ) => {\n const previous = this.system;\n this.system = system;\n this.unsubscribe = unsubscribe;\n this.host.requestUpdate(\n systemResolverUpdatedSymbol,\n previous\n );\n },\n },\n cancelable: true,\n }\n );\n this.host.dispatchEvent(querySystemEvent);\n }\n}\n"],
5
+ "mappings": ";AAcO,aAAM,8BAA8B,OAAO,yBAAyB;AAMpE,aAAM,2BAAyD;AAAA,EAKlE,YAAY,MAAuB;AAHnC,SAAO,SAAwB;AAI3B,SAAK,OAAO;AACZ,SAAK,KAAK,cAAc,IAAI;AAAA,EAChC;AAAA,EAEO,gBAAsB;AACzB,SAAK,cAAc;AAAA,EACvB;AAAA,EAEO,mBAAyB;AAlCpC;AAmCQ,eAAK,gBAAL;AAAA,EACJ;AAAA,EAEQ,gBAAsB;AAC1B,UAAM,mBAAmB,IAAI;AAAA,MACzB;AAAA,MACA;AAAA,QACI,SAAS;AAAA,QACT,UAAU;AAAA,QACV,QAAQ;AAAA,UACJ,UAAU,CACN,QACA,gBACC;AACD,kBAAM,WAAW,KAAK;AACtB,iBAAK,SAAS;AACd,iBAAK,cAAc;AACnB,iBAAK,KAAK;AAAA,cACN;AAAA,cACA;AAAA,YACJ;AAAA,UACJ;AAAA,QACJ;AAAA,QACA,YAAY;AAAA,MAChB;AAAA,IACJ;AACA,SAAK,KAAK,cAAc,gBAAgB;AAAA,EAC5C;AACJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";export const systemResolverUpdatedSymbol=Symbol("system resolver updated");export class SystemResolutionController{constructor(e){this.system="spectrum";this.host=e,this.host.addController(this)}hostConnected(){this.resolveSystem()}hostDisconnected(){var e;(e=this.unsubscribe)==null||e.call(this)}resolveSystem(){const e=new CustomEvent("sp-system-context",{bubbles:!0,composed:!0,detail:{callback:(t,s)=>{const o=this.system;this.system=t,this.unsubscribe=s,this.host.requestUpdate(systemResolverUpdatedSymbol,o)}},cancelable:!0});this.host.dispatchEvent(e)}}
2
+ //# sourceMappingURL=SystemContextResolution.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["SystemContextResolution.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2024 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*/\nimport type { ReactiveController, ReactiveElement } from 'lit';\nimport type { SystemVariant } from '@spectrum-web-components/theme';\n\nexport const systemResolverUpdatedSymbol = Symbol('system resolver updated');\n\nexport type ProvideSystem = {\n callback: (system: SystemVariant, unsubscribe: () => void) => void;\n};\n\nexport class SystemResolutionController implements ReactiveController {\n private host: ReactiveElement;\n public system: SystemVariant = 'spectrum';\n private unsubscribe?: () => void;\n\n constructor(host: ReactiveElement) {\n this.host = host;\n this.host.addController(this);\n }\n\n public hostConnected(): void {\n this.resolveSystem();\n }\n\n public hostDisconnected(): void {\n this.unsubscribe?.();\n }\n\n private resolveSystem(): void {\n const querySystemEvent = new CustomEvent<ProvideSystem>(\n 'sp-system-context',\n {\n bubbles: true,\n composed: true,\n detail: {\n callback: (\n system: SystemVariant,\n unsubscribe: () => void\n ) => {\n const previous = this.system;\n this.system = system;\n this.unsubscribe = unsubscribe;\n this.host.requestUpdate(\n systemResolverUpdatedSymbol,\n previous\n );\n },\n },\n cancelable: true,\n }\n );\n this.host.dispatchEvent(querySystemEvent);\n }\n}\n"],
5
+ "mappings": "aAcO,aAAM,4BAA8B,OAAO,yBAAyB,EAMpE,aAAM,0BAAyD,CAKlE,YAAYA,EAAuB,CAHnC,KAAO,OAAwB,WAI3B,KAAK,KAAOA,EACZ,KAAK,KAAK,cAAc,IAAI,CAChC,CAEO,eAAsB,CACzB,KAAK,cAAc,CACvB,CAEO,kBAAyB,CAlCpC,IAAAC,GAmCQA,EAAA,KAAK,cAAL,MAAAA,EAAA,UACJ,CAEQ,eAAsB,CAC1B,MAAMC,EAAmB,IAAI,YACzB,oBACA,CACI,QAAS,GACT,SAAU,GACV,OAAQ,CACJ,SAAU,CACNC,EACAC,IACC,CACD,MAAMC,EAAW,KAAK,OACtB,KAAK,OAASF,EACd,KAAK,YAAcC,EACnB,KAAK,KAAK,cACN,4BACAC,CACJ,CACJ,CACJ,EACA,WAAY,EAChB,CACJ,EACA,KAAK,KAAK,cAAcH,CAAgB,CAC5C,CACJ",
6
+ "names": ["host", "_a", "querySystemEvent", "system", "unsubscribe", "previous"]
7
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './MatchMedia.js';
2
+ export * from './RovingTabindex.js';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ export * from "./MatchMedia.dev.js";
3
+ export * from "./RovingTabindex.dev.js";
4
+ //# sourceMappingURL=index.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["index.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 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\nexport * from './MatchMedia.dev.js'\nexport * from './RovingTabindex.dev.js'\n"],
5
+ "mappings": ";AAYA,cAAc;AACd,cAAc;",
6
+ "names": []
7
+ }
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";export*from"./MatchMedia.js";export*from"./RovingTabindex.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["index.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 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\nexport * from './MatchMedia.js';\nexport * from './RovingTabindex.js';\n"],
5
+ "mappings": "aAYA,WAAc,kBACd,WAAc",
6
+ "names": []
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
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ import { html, LitElement } from "lit";
3
+ import { elementUpdated, expect, fixture } from "@open-wc/testing";
4
+ import { ElementResolutionController } from "@spectrum-web-components/reactive-controllers/src/ElementResolution.js";
5
+ describe("Element Resolution", () => {
6
+ it("responds to DOM changes", async () => {
7
+ class TestEl extends LitElement {
8
+ }
9
+ if (!customElements.get("test-element-resolution-el")) {
10
+ customElements.define("test-element-resolution-el", TestEl);
11
+ }
12
+ const test = await fixture(
13
+ html`
14
+ <div>
15
+ <test-element-resolution-el></test-element-resolution-el>
16
+ <div class="target" id="one"></div>
17
+ <div class="target" id="two"></div>
18
+ </div>
19
+ `
20
+ );
21
+ const el = test.querySelector("test-element-resolution-el");
22
+ const target1 = test.querySelector("#one");
23
+ const target2 = test.querySelector("#two");
24
+ const controller = new ElementResolutionController(el);
25
+ expect(controller.element).to.be.null;
26
+ controller.selector = ".target";
27
+ await elementUpdated(el);
28
+ expect(controller.element === target1).to.be.true;
29
+ test.insertAdjacentElement("afterbegin", target2);
30
+ await elementUpdated(el);
31
+ expect(controller.element === target2).to.be.true;
32
+ target2.setAttribute("class", "not-target");
33
+ await elementUpdated(el);
34
+ expect(controller.element === target1).to.be.true;
35
+ target2.setAttribute("class", "target");
36
+ await elementUpdated(el);
37
+ expect(controller.element === target2).to.be.true;
38
+ });
39
+ });
40
+ //# sourceMappingURL=element-resolution.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["element-resolution.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 { html, LitElement } from 'lit';\nimport { elementUpdated, expect, fixture } from '@open-wc/testing';\nimport { ElementResolutionController } from '@spectrum-web-components/reactive-controllers/src/ElementResolution.js';\n\ndescribe('Element Resolution', () => {\n it('responds to DOM changes', async () => {\n class TestEl extends LitElement {}\n if (!customElements.get('test-element-resolution-el')) {\n customElements.define('test-element-resolution-el', TestEl);\n }\n const test = await fixture(\n html`\n <div>\n <test-element-resolution-el></test-element-resolution-el>\n <div class=\"target\" id=\"one\"></div>\n <div class=\"target\" id=\"two\"></div>\n </div>\n `\n );\n const el = test.querySelector('test-element-resolution-el') as TestEl;\n const target1 = test.querySelector('#one') as HTMLDivElement;\n const target2 = test.querySelector('#two') as HTMLDivElement;\n const controller = new ElementResolutionController(el as LitElement);\n expect(controller.element).to.be.null;\n controller.selector = '.target';\n await elementUpdated(el);\n expect(controller.element === target1).to.be.true;\n test.insertAdjacentElement('afterbegin', target2);\n await elementUpdated(el);\n expect(controller.element === target2).to.be.true;\n target2.setAttribute('class', 'not-target');\n await elementUpdated(el);\n expect(controller.element === target1).to.be.true;\n target2.setAttribute('class', 'target');\n await elementUpdated(el);\n expect(controller.element === target2).to.be.true;\n });\n});\n"],
5
+ "mappings": ";AAYA,SAAS,MAAM,kBAAkB;AACjC,SAAS,gBAAgB,QAAQ,eAAe;AAChD,SAAS,mCAAmC;AAE5C,SAAS,sBAAsB,MAAM;AACjC,KAAG,2BAA2B,YAAY;AAAA,IACtC,MAAM,eAAe,WAAW;AAAA,IAAC;AACjC,QAAI,CAAC,eAAe,IAAI,4BAA4B,GAAG;AACnD,qBAAe,OAAO,8BAA8B,MAAM;AAAA,IAC9D;AACA,UAAM,OAAO,MAAM;AAAA,MACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOJ;AACA,UAAM,KAAK,KAAK,cAAc,4BAA4B;AAC1D,UAAM,UAAU,KAAK,cAAc,MAAM;AACzC,UAAM,UAAU,KAAK,cAAc,MAAM;AACzC,UAAM,aAAa,IAAI,4BAA4B,EAAgB;AACnE,WAAO,WAAW,OAAO,EAAE,GAAG,GAAG;AACjC,eAAW,WAAW;AACtB,UAAM,eAAe,EAAE;AACvB,WAAO,WAAW,YAAY,OAAO,EAAE,GAAG,GAAG;AAC7C,SAAK,sBAAsB,cAAc,OAAO;AAChD,UAAM,eAAe,EAAE;AACvB,WAAO,WAAW,YAAY,OAAO,EAAE,GAAG,GAAG;AAC7C,YAAQ,aAAa,SAAS,YAAY;AAC1C,UAAM,eAAe,EAAE;AACvB,WAAO,WAAW,YAAY,OAAO,EAAE,GAAG,GAAG;AAC7C,YAAQ,aAAa,SAAS,QAAQ;AACtC,UAAM,eAAe,EAAE;AACvB,WAAO,WAAW,YAAY,OAAO,EAAE,GAAG,GAAG;AAAA,EACjD,CAAC;AACL,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ export const createLanguageContext = (lang) => {
3
+ let language = lang;
4
+ const updateLanguage = (lang2) => {
5
+ language = lang2;
6
+ resolveLanguage();
7
+ };
8
+ const langResolvers = [];
9
+ const createLangResolver = (event) => {
10
+ langResolvers.push([
11
+ event.detail.callback,
12
+ () => langResolvers.splice(langResolvers.length, 1)
13
+ ]);
14
+ resolveLanguage();
15
+ };
16
+ const resolveLanguage = () => {
17
+ langResolvers.forEach(
18
+ ([resolver, unsubscribe]) => resolver(language, unsubscribe)
19
+ );
20
+ };
21
+ return [createLangResolver, updateLanguage];
22
+ };
23
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["helpers.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 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 { ProvideLang } from '@spectrum-web-components/theme';\n\nexport const createLanguageContext = (\n lang: string\n): [(event: CustomEvent<ProvideLang>) => void, (lang: string) => void] => {\n let language = lang;\n const updateLanguage = (lang: string): void => {\n language = lang;\n resolveLanguage();\n };\n const langResolvers: [ProvideLang['callback'], () => void][] = [];\n const createLangResolver = (event: CustomEvent<ProvideLang>): void => {\n langResolvers.push([\n event.detail.callback,\n () => langResolvers.splice(langResolvers.length, 1),\n ]);\n resolveLanguage();\n };\n const resolveLanguage = (): void => {\n langResolvers.forEach(([resolver, unsubscribe]) =>\n resolver(language, unsubscribe)\n );\n };\n return [createLangResolver, updateLanguage];\n};\n"],
5
+ "mappings": ";AAcO,aAAM,wBAAwB,CACjC,SACsE;AACtE,MAAI,WAAW;AACf,QAAM,iBAAiB,CAACA,UAAuB;AAC3C,eAAWA;AACX,oBAAgB;AAAA,EACpB;AACA,QAAM,gBAAyD,CAAC;AAChE,QAAM,qBAAqB,CAAC,UAA0C;AAClE,kBAAc,KAAK;AAAA,MACf,MAAM,OAAO;AAAA,MACb,MAAM,cAAc,OAAO,cAAc,QAAQ,CAAC;AAAA,IACtD,CAAC;AACD,oBAAgB;AAAA,EACpB;AACA,QAAM,kBAAkB,MAAY;AAChC,kBAAc;AAAA,MAAQ,CAAC,CAAC,UAAU,WAAW,MACzC,SAAS,UAAU,WAAW;AAAA,IAClC;AAAA,EACJ;AACA,SAAO,CAAC,oBAAoB,cAAc;AAC9C;",
6
+ "names": ["lang"]
7
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ import { html, LitElement } from "lit";
3
+ import { expect, fixture, nextFrame } from "@open-wc/testing";
4
+ import { setViewport } from "@web/test-runner-commands";
5
+ import { MatchMediaController } from "@spectrum-web-components/reactive-controllers/src/MatchMedia.js";
6
+ class TestEl extends LitElement {
7
+ }
8
+ customElements.define("test-match-media-el", TestEl);
9
+ describe("Match Media", () => {
10
+ it("responds to media changes", async () => {
11
+ const el = await fixture(
12
+ html`
13
+ <test-match-media-el></test-match-media-el>
14
+ `
15
+ );
16
+ const controller = new MatchMediaController(
17
+ el,
18
+ "(min-width: 500px)"
19
+ );
20
+ await nextFrame();
21
+ await nextFrame();
22
+ expect(controller.matches).to.be.true;
23
+ await setViewport({ width: 360, height: 640 });
24
+ await nextFrame();
25
+ await nextFrame();
26
+ expect(controller.matches).to.be.false;
27
+ });
28
+ });
29
+ //# sourceMappingURL=match-media.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["match-media.test.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 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 { html, LitElement } from 'lit';\nimport { expect, fixture, nextFrame } from '@open-wc/testing';\nimport { setViewport } from '@web/test-runner-commands';\nimport { MatchMediaController } from '@spectrum-web-components/reactive-controllers/src/MatchMedia.js';\n\nclass TestEl extends LitElement {}\ncustomElements.define('test-match-media-el', TestEl);\n\ndescribe('Match Media', () => {\n it('responds to media changes', async () => {\n const el = await fixture(\n html`\n <test-match-media-el></test-match-media-el>\n `\n );\n const controller = new MatchMediaController(\n el as LitElement & { shadowRoot: ShadowRoot },\n '(min-width: 500px)'\n );\n // Allow Controller to initialize\n await nextFrame();\n await nextFrame();\n expect(controller.matches).to.be.true;\n\n await setViewport({ width: 360, height: 640 });\n // Allow viewport update to propagate.\n await nextFrame();\n await nextFrame();\n expect(controller.matches).to.be.false;\n });\n});\n"],
5
+ "mappings": ";AAYA,SAAS,MAAM,kBAAkB;AACjC,SAAS,QAAQ,SAAS,iBAAiB;AAC3C,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AAErC,MAAM,eAAe,WAAW;AAAC;AACjC,eAAe,OAAO,uBAAuB,MAAM;AAEnD,SAAS,eAAe,MAAM;AAC1B,KAAG,6BAA6B,YAAY;AACxC,UAAM,KAAK,MAAM;AAAA,MACb;AAAA;AAAA;AAAA,IAGJ;AACA,UAAM,aAAa,IAAI;AAAA,MACnB;AAAA,MACA;AAAA,IACJ;AAEA,UAAM,UAAU;AAChB,UAAM,UAAU;AAChB,WAAO,WAAW,OAAO,EAAE,GAAG,GAAG;AAEjC,UAAM,YAAY,EAAE,OAAO,KAAK,QAAQ,IAAI,CAAC;AAE7C,UAAM,UAAU;AAChB,UAAM,UAAU;AAChB,WAAO,WAAW,OAAO,EAAE,GAAG,GAAG;AAAA,EACrC,CAAC;AACL,CAAC;",
6
+ "names": []
7
+ }