@spectrum-web-components/shared 0.15.0-devmode.0 → 0.15.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.
Files changed (54) hide show
  1. package/package.json +4 -4
  2. package/src/first-focusable-in.dev.js +4 -1
  3. package/src/first-focusable-in.dev.js.map +1 -1
  4. package/src/first-focusable-in.js +1 -5
  5. package/src/first-focusable-in.js.map +2 -2
  6. package/src/focus-visible.dev.js +10 -2
  7. package/src/focus-visible.dev.js.map +1 -1
  8. package/src/focus-visible.js +1 -67
  9. package/src/focus-visible.js.map +2 -2
  10. package/src/focusable.d.ts +2 -0
  11. package/src/focusable.dev.js +36 -10
  12. package/src/focusable.dev.js.map +2 -2
  13. package/src/focusable.js +1 -189
  14. package/src/focusable.js.map +3 -3
  15. package/src/get-active-element.dev.js +1 -0
  16. package/src/get-active-element.dev.js.map +1 -1
  17. package/src/get-active-element.js +1 -3
  18. package/src/get-active-element.js.map +2 -2
  19. package/src/get-deep-element-from-point.dev.js +1 -0
  20. package/src/get-deep-element-from-point.dev.js.map +1 -1
  21. package/src/get-deep-element-from-point.js +1 -11
  22. package/src/get-deep-element-from-point.js.map +2 -2
  23. package/src/index.dev.js +1 -0
  24. package/src/index.dev.js.map +1 -1
  25. package/src/index.js +1 -9
  26. package/src/index.js.map +1 -1
  27. package/src/like-anchor.dev.js +1 -0
  28. package/src/like-anchor.dev.js.map +1 -1
  29. package/src/like-anchor.js +12 -57
  30. package/src/like-anchor.js.map +2 -2
  31. package/src/observe-slot-presence.dev.js +11 -3
  32. package/src/observe-slot-presence.dev.js.map +1 -1
  33. package/src/observe-slot-presence.js +1 -51
  34. package/src/observe-slot-presence.js.map +2 -2
  35. package/src/observe-slot-text.dev.js +8 -5
  36. package/src/observe-slot-text.dev.js.map +1 -1
  37. package/src/observe-slot-text.js +1 -78
  38. package/src/observe-slot-text.js.map +2 -2
  39. package/src/platform.dev.js +1 -0
  40. package/src/platform.dev.js.map +1 -1
  41. package/src/platform.js +1 -30
  42. package/src/platform.js.map +2 -2
  43. package/src/reparent-children.dev.js +9 -2
  44. package/src/reparent-children.dev.js.map +1 -1
  45. package/src/reparent-children.js +1 -49
  46. package/src/reparent-children.js.map +2 -2
  47. package/test/focusable.test.js +5 -2
  48. package/test/focusable.test.js.map +1 -1
  49. package/test/observe-slot-presence.test.js +9 -3
  50. package/test/observe-slot-presence.test.js.map +1 -1
  51. package/test/observe-slot-text.test.js +5 -2
  52. package/test/observe-slot-text.test.js.map +1 -1
  53. package/test/reparent-children.test.js +25 -8
  54. package/test/reparent-children.test.js.map +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/shared",
3
- "version": "0.15.0-devmode.0+7b0ea531e",
3
+ "version": "0.15.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -89,14 +89,14 @@
89
89
  ],
90
90
  "dependencies": {
91
91
  "@lit-labs/observers": "^1.0.1",
92
- "@spectrum-web-components/base": "^0.6.0",
92
+ "@spectrum-web-components/base": "^0.7.0",
93
93
  "focus-visible": "^5.1.0",
94
94
  "tslib": "^2.0.0"
95
95
  },
96
96
  "types": "./src/index.d.ts",
97
97
  "customElements": "custom-elements.json",
98
98
  "sideEffects": [
99
- "./**/*.dev.ts"
99
+ "./**/*.dev.js"
100
100
  ],
101
- "gitHead": "7b0ea531e9c7225c8964c5429bc5fd005618b80e"
101
+ "gitHead": "96da2eef637c5d50dd04a75d40a46353116787b4"
102
102
  }
@@ -1,6 +1,9 @@
1
+ "use strict";
1
2
  const firstFocusableSelector = 'button:not([tabindex="-1"]), [href]:not([tabindex="-1"]), input:not([tabindex="-1"]), select:not([tabindex="-1"]), textarea:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), [focusable]:not([tabindex="-1"])';
2
3
  export const firstFocusableIn = (root) => {
3
- const firstFocusable = root.querySelector(firstFocusableSelector);
4
+ const firstFocusable = root.querySelector(
5
+ firstFocusableSelector
6
+ );
4
7
  return firstFocusable;
5
8
  };
6
9
  //# sourceMappingURL=first-focusable-in.dev.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["first-focusable-in.ts"],
4
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 type { SpectrumElement } from '@spectrum-web-components/base';\n\nconst firstFocusableSelector =\n 'button:not([tabindex=\"-1\"]), [href]:not([tabindex=\"-1\"]), input:not([tabindex=\"-1\"]), select:not([tabindex=\"-1\"]), textarea:not([tabindex=\"-1\"]), [tabindex]:not([tabindex=\"-1\"]), [focusable]:not([tabindex=\"-1\"])';\n\nexport const firstFocusableIn = (\n root: HTMLElement | ShadowRoot\n): SpectrumElement | null => {\n const firstFocusable = root.querySelector(\n firstFocusableSelector\n ) as SpectrumElement;\n return firstFocusable;\n};\n"],
5
- "mappings": "AAcA,MAAM,yBACF;AAEG,aAAM,mBAAmB,CAC5B,SACyB;AACzB,QAAM,iBAAiB,KAAK,cACxB,sBACJ;AACA,SAAO;AACX;",
5
+ "mappings": ";AAcA,MAAM,yBACF;AAEG,aAAM,mBAAmB,CAC5B,SACyB;AACzB,QAAM,iBAAiB,KAAK;AAAA,IACxB;AAAA,EACJ;AACA,SAAO;AACX;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,2 @@
1
- const firstFocusableSelector = 'button:not([tabindex="-1"]), [href]:not([tabindex="-1"]), input:not([tabindex="-1"]), select:not([tabindex="-1"]), textarea:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), [focusable]:not([tabindex="-1"])';
2
- export const firstFocusableIn = (root) => {
3
- const firstFocusable = root.querySelector(firstFocusableSelector);
4
- return firstFocusable;
5
- };
1
+ "use strict";const e='button:not([tabindex="-1"]), [href]:not([tabindex="-1"]), input:not([tabindex="-1"]), select:not([tabindex="-1"]), textarea:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), [focusable]:not([tabindex="-1"])';export const firstFocusableIn=t=>t.querySelector(e);
6
2
  //# sourceMappingURL=first-focusable-in.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["first-focusable-in.ts"],
4
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 type { SpectrumElement } from '@spectrum-web-components/base';\n\nconst firstFocusableSelector =\n 'button:not([tabindex=\"-1\"]), [href]:not([tabindex=\"-1\"]), input:not([tabindex=\"-1\"]), select:not([tabindex=\"-1\"]), textarea:not([tabindex=\"-1\"]), [tabindex]:not([tabindex=\"-1\"]), [focusable]:not([tabindex=\"-1\"])';\n\nexport const firstFocusableIn = (\n root: HTMLElement | ShadowRoot\n): SpectrumElement | null => {\n const firstFocusable = root.querySelector(\n firstFocusableSelector\n ) as SpectrumElement;\n return firstFocusable;\n};\n"],
5
- "mappings": "AAcA,MAAM,yBACF;AAEG,aAAM,mBAAmB,CAC5B,SACyB;AACzB,QAAM,iBAAiB,KAAK,cACxB,sBACJ;AACA,SAAO;AACX;",
6
- "names": []
5
+ "mappings": "aAcA,MAAMA,EACF,sNAEG,aAAM,iBACTC,GAEuBA,EAAK,cACxBD,CACJ",
6
+ "names": ["firstFocusableSelector", "root"]
7
7
  }
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  let hasFocusVisible = true;
2
3
  try {
3
4
  document.body.querySelector(":focus-visible");
@@ -26,9 +27,16 @@ export const FocusVisiblePolyfillMixin = (SuperClass) => {
26
27
  instance.manageAutoFocus();
27
28
  }
28
29
  };
29
- self.addEventListener("focus-visible-polyfill-ready", coordinationHandler, { once: true });
30
+ self.addEventListener(
31
+ "focus-visible-polyfill-ready",
32
+ coordinationHandler,
33
+ { once: true }
34
+ );
30
35
  return () => {
31
- self.removeEventListener("focus-visible-polyfill-ready", coordinationHandler);
36
+ self.removeEventListener(
37
+ "focus-visible-polyfill-ready",
38
+ coordinationHandler
39
+ );
32
40
  };
33
41
  }
34
42
  return () => {
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["focus-visible.ts"],
4
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\ndeclare global {\n interface Window {\n applyFocusVisiblePolyfill?: (scope: Document | ShadowRoot) => void;\n }\n}\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\ninterface OptionalLifecycleCallbacks {\n connectedCallback?(): void;\n disconnectedCallback?(): void;\n manageAutoFocus?(): void;\n}\n\ntype MixableBaseClass = HTMLElement & OptionalLifecycleCallbacks;\n\ntype EndPolyfillCoordinationCallback = () => void;\n\nlet hasFocusVisible = true;\n\ntry {\n document.body.querySelector(':focus-visible');\n} catch (error) {\n hasFocusVisible = false;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n import('focus-visible');\n}\n\n/**\n * This mixin function is designed to be applied to a class that inherits\n * from HTMLElement. It makes it easy for a custom element to coordinate with\n * the :focus-visible polyfill.\n *\n * NOTE(cdata): The code here was adapted from an example proposed with the\n * introduction of ShadowDOM support in the :focus-visible polyfill.\n *\n * @see https://github.com/WICG/focus-visible/pull/196\n * @param {Function} SuperClass The base class implementation to decorate with\n * implementation that coordinates with the :focus-visible polyfill\n */\nexport const FocusVisiblePolyfillMixin = <\n T extends Constructor<MixableBaseClass>\n>(\n SuperClass: T\n): T => {\n const coordinateWithPolyfill = (\n instance: MixableBaseClass\n ): EndPolyfillCoordinationCallback => {\n // If there is no shadow root, there is no need to coordinate with\n // the polyfill. If we already coordinated with the polyfill, we can\n // skip subsequent invokcations:\n if (\n instance.shadowRoot == null ||\n instance.hasAttribute('data-js-focus-visible')\n ) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n }\n\n // The polyfill might already be loaded. If so, we can apply it to\n // the shadow root immediately:\n if (self.applyFocusVisiblePolyfill) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n } else {\n const coordinationHandler = (): void => {\n if (self.applyFocusVisiblePolyfill && instance.shadowRoot) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n }\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n };\n // Otherwise, wait for the polyfill to be loaded lazily. It might\n // never be loaded, but if it is then we can apply it to the\n // shadow root at the appropriate time by waiting for the ready\n // event:\n self.addEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler,\n { once: true }\n );\n\n return () => {\n self.removeEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler\n );\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n };\n\n const $endPolyfillCoordination = Symbol('endPolyfillCoordination');\n\n // IE11 doesn't natively support custom elements or JavaScript class\n // syntax The mixin implementation assumes that the user will take the\n // appropriate steps to support both:\n class FocusVisibleCoordinator extends SuperClass {\n private [$endPolyfillCoordination]: EndPolyfillCoordinationCallback | null =\n null;\n\n // Attempt to coordinate with the polyfill when connected to the\n // document:\n override connectedCallback(): void {\n super.connectedCallback && super.connectedCallback();\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] == null) {\n this[$endPolyfillCoordination] =\n coordinateWithPolyfill(this);\n }\n });\n }\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback && super.disconnectedCallback();\n // It's important to remove the polyfill event listener when we\n // disconnect, otherwise we will leak the whole element via window:\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] != null) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this[$endPolyfillCoordination]!();\n this[$endPolyfillCoordination] = null;\n }\n });\n }\n }\n }\n\n return FocusVisibleCoordinator;\n};\n"],
5
- "mappings": "AAkCA,IAAI,kBAAkB;AAEtB,IAAI;AACA,WAAS,KAAK,cAAc,gBAAgB;AAChD,SAAS,OAAP;AACE,oBAAkB;AAGlB,SAAO;AACX;AAcO,aAAM,4BAA4B,CAGrC,eACI;AA7DR;AA8DI,QAAM,yBAAyB,CAC3B,aACkC;AAIlC,QACI,SAAS,cAAc,QACvB,SAAS,aAAa,uBAAuB,GAC/C;AAEE,aAAO,MAAM;AAAA,MAAC;AAAA,IAClB;AAIA,QAAI,KAAK,2BAA2B;AAChC,WAAK,0BAA0B,SAAS,UAAU;AAElD,UAAI,SAAS,iBAAiB;AAC1B,iBAAS,gBAAgB;AAAA,MAC7B;AAAA,IACJ,OAAO;AACH,YAAM,sBAAsB,MAAY;AACpC,YAAI,KAAK,6BAA6B,SAAS,YAAY;AACvD,eAAK,0BAA0B,SAAS,UAAU;AAAA,QACtD;AAEA,YAAI,SAAS,iBAAiB;AAC1B,mBAAS,gBAAgB;AAAA,QAC7B;AAAA,MACJ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,MAAY;AACpC,YAAI,KAAK,6BAA6B,SAAS,YAAY;AACvD,eAAK,0BAA0B,SAAS,UAAU;AAAA,QACtD;AAEA,YAAI,SAAS,iBAAiB;AAC1B,mBAAS,gBAAgB;AAAA,QAC7B;AAAA,MACJ;AAKA,WAAK;AAAA,QACD;AAAA,QACA;AAAA,QACA,EAAE,MAAM,KAAK;AAAA,MACjB;AAEA,aAAO,MAAM;AACT,aAAK;AAAA,UACD;AAAA,UACA;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAGA,WAAO,MAAM;AAAA,IAAC;AAAA,EAClB;AAEA,QAAM,2BAA2B,OAAO,yBAAyB;AAKjE,QAAM,gCAAgC,WAAW;AAAA,IAAjD;AAAA;AACI,WAAS,MACL;AAAA;AAAA,IAIK,oBAA0B;AAC/B,YAAM,qBAAqB,MAAM,kBAAkB;AACnD,UAAI,CAAC,iBAAiB;AAClB,8BAAsB,MAAM;AACxB,cAAI,KAAK,6BAA6B,MAAM;AACxC,iBAAK,4BACD,uBAAuB,IAAI;AAAA,UACnC;AAAA,QACJ,CAAC;AAAA,MACL;AAAA,IACJ;AAAA,IAES,uBAA6B;AAClC,YAAM,wBAAwB,MAAM,qBAAqB;AAGzD,UAAI,CAAC,iBAAiB;AAClB,8BAAsB,MAAM;AACxB,cAAI,KAAK,6BAA6B,MAAM;AAExC,iBAAK,0BAA2B;AAChC,iBAAK,4BAA4B;AAAA,UACrC;AAAA,QACJ,CAAC;AAAA,MACL;AAAA,IACJ;AAAA,EACJ;AAzJJ,EA0HiB;AAiCb,SAAO;AACX;",
6
6
  "names": []
7
7
  }
@@ -1,68 +1,2 @@
1
- let hasFocusVisible = true;
2
- try {
3
- document.body.querySelector(":focus-visible");
4
- } catch (error) {
5
- hasFocusVisible = false;
6
- import("focus-visible");
7
- }
8
- export const FocusVisiblePolyfillMixin = (SuperClass) => {
9
- var _a;
10
- const coordinateWithPolyfill = (instance) => {
11
- if (instance.shadowRoot == null || instance.hasAttribute("data-js-focus-visible")) {
12
- return () => {
13
- };
14
- }
15
- if (self.applyFocusVisiblePolyfill) {
16
- self.applyFocusVisiblePolyfill(instance.shadowRoot);
17
- if (instance.manageAutoFocus) {
18
- instance.manageAutoFocus();
19
- }
20
- } else {
21
- const coordinationHandler = () => {
22
- if (self.applyFocusVisiblePolyfill && instance.shadowRoot) {
23
- self.applyFocusVisiblePolyfill(instance.shadowRoot);
24
- }
25
- if (instance.manageAutoFocus) {
26
- instance.manageAutoFocus();
27
- }
28
- };
29
- self.addEventListener("focus-visible-polyfill-ready", coordinationHandler, { once: true });
30
- return () => {
31
- self.removeEventListener("focus-visible-polyfill-ready", coordinationHandler);
32
- };
33
- }
34
- return () => {
35
- };
36
- };
37
- const $endPolyfillCoordination = Symbol("endPolyfillCoordination");
38
- class FocusVisibleCoordinator extends SuperClass {
39
- constructor() {
40
- super(...arguments);
41
- this[_a] = null;
42
- }
43
- connectedCallback() {
44
- super.connectedCallback && super.connectedCallback();
45
- if (!hasFocusVisible) {
46
- requestAnimationFrame(() => {
47
- if (this[$endPolyfillCoordination] == null) {
48
- this[$endPolyfillCoordination] = coordinateWithPolyfill(this);
49
- }
50
- });
51
- }
52
- }
53
- disconnectedCallback() {
54
- super.disconnectedCallback && super.disconnectedCallback();
55
- if (!hasFocusVisible) {
56
- requestAnimationFrame(() => {
57
- if (this[$endPolyfillCoordination] != null) {
58
- this[$endPolyfillCoordination]();
59
- this[$endPolyfillCoordination] = null;
60
- }
61
- });
62
- }
63
- }
64
- }
65
- _a = $endPolyfillCoordination;
66
- return FocusVisibleCoordinator;
67
- };
1
+ "use strict";let i=!0;try{document.body.querySelector(":focus-visible")}catch(a){i=!1,import("focus-visible")}export const FocusVisiblePolyfillMixin=a=>{var n;const s=l=>{if(l.shadowRoot==null||l.hasAttribute("data-js-focus-visible"))return()=>{};if(self.applyFocusVisiblePolyfill)self.applyFocusVisiblePolyfill(l.shadowRoot),l.manageAutoFocus&&l.manageAutoFocus();else{const e=()=>{self.applyFocusVisiblePolyfill&&l.shadowRoot&&self.applyFocusVisiblePolyfill(l.shadowRoot),l.manageAutoFocus&&l.manageAutoFocus()};return self.addEventListener("focus-visible-polyfill-ready",e,{once:!0}),()=>{self.removeEventListener("focus-visible-polyfill-ready",e)}}return()=>{}},o=Symbol("endPolyfillCoordination");class t extends a{constructor(){super(...arguments);this[n]=null}connectedCallback(){super.connectedCallback&&super.connectedCallback(),i||requestAnimationFrame(()=>{this[o]==null&&(this[o]=s(this))})}disconnectedCallback(){super.disconnectedCallback&&super.disconnectedCallback(),i||requestAnimationFrame(()=>{this[o]!=null&&(this[o](),this[o]=null)})}}return n=o,t};
68
2
  //# sourceMappingURL=focus-visible.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["focus-visible.ts"],
4
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\ndeclare global {\n interface Window {\n applyFocusVisiblePolyfill?: (scope: Document | ShadowRoot) => void;\n }\n}\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\ninterface OptionalLifecycleCallbacks {\n connectedCallback?(): void;\n disconnectedCallback?(): void;\n manageAutoFocus?(): void;\n}\n\ntype MixableBaseClass = HTMLElement & OptionalLifecycleCallbacks;\n\ntype EndPolyfillCoordinationCallback = () => void;\n\nlet hasFocusVisible = true;\n\ntry {\n document.body.querySelector(':focus-visible');\n} catch (error) {\n hasFocusVisible = false;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n import('focus-visible');\n}\n\n/**\n * This mixin function is designed to be applied to a class that inherits\n * from HTMLElement. It makes it easy for a custom element to coordinate with\n * the :focus-visible polyfill.\n *\n * NOTE(cdata): The code here was adapted from an example proposed with the\n * introduction of ShadowDOM support in the :focus-visible polyfill.\n *\n * @see https://github.com/WICG/focus-visible/pull/196\n * @param {Function} SuperClass The base class implementation to decorate with\n * implementation that coordinates with the :focus-visible polyfill\n */\nexport const FocusVisiblePolyfillMixin = <\n T extends Constructor<MixableBaseClass>\n>(\n SuperClass: T\n): T => {\n const coordinateWithPolyfill = (\n instance: MixableBaseClass\n ): EndPolyfillCoordinationCallback => {\n // If there is no shadow root, there is no need to coordinate with\n // the polyfill. If we already coordinated with the polyfill, we can\n // skip subsequent invokcations:\n if (\n instance.shadowRoot == null ||\n instance.hasAttribute('data-js-focus-visible')\n ) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n }\n\n // The polyfill might already be loaded. If so, we can apply it to\n // the shadow root immediately:\n if (self.applyFocusVisiblePolyfill) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n } else {\n const coordinationHandler = (): void => {\n if (self.applyFocusVisiblePolyfill && instance.shadowRoot) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n }\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n };\n // Otherwise, wait for the polyfill to be loaded lazily. It might\n // never be loaded, but if it is then we can apply it to the\n // shadow root at the appropriate time by waiting for the ready\n // event:\n self.addEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler,\n { once: true }\n );\n\n return () => {\n self.removeEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler\n );\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n };\n\n const $endPolyfillCoordination = Symbol('endPolyfillCoordination');\n\n // IE11 doesn't natively support custom elements or JavaScript class\n // syntax The mixin implementation assumes that the user will take the\n // appropriate steps to support both:\n class FocusVisibleCoordinator extends SuperClass {\n private [$endPolyfillCoordination]: EndPolyfillCoordinationCallback | null =\n null;\n\n // Attempt to coordinate with the polyfill when connected to the\n // document:\n override connectedCallback(): void {\n super.connectedCallback && super.connectedCallback();\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] == null) {\n this[$endPolyfillCoordination] =\n coordinateWithPolyfill(this);\n }\n });\n }\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback && super.disconnectedCallback();\n // It's important to remove the polyfill event listener when we\n // disconnect, otherwise we will leak the whole element via window:\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] != null) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this[$endPolyfillCoordination]!();\n this[$endPolyfillCoordination] = null;\n }\n });\n }\n }\n }\n\n return FocusVisibleCoordinator;\n};\n"],
5
- "mappings": "AAkCA,IAAI,kBAAkB;AAEtB,IAAI;AACA,WAAS,KAAK,cAAc,gBAAgB;AAChD,SAAS,OAAP;AACE,oBAAkB;AAGlB,SAAO;AACX;AAcO,aAAM,4BAA4B,CAGrC,eACI;AA7DR;AA8DI,QAAM,yBAAyB,CAC3B,aACkC;AAIlC,QACI,SAAS,cAAc,QACvB,SAAS,aAAa,uBAAuB,GAC/C;AAEE,aAAO,MAAM;AAAA,MAAC;AAAA,IAClB;AAIA,QAAI,KAAK,2BAA2B;AAChC,WAAK,0BAA0B,SAAS,UAAU;AAElD,UAAI,SAAS,iBAAiB;AAC1B,iBAAS,gBAAgB;AAAA,MAC7B;AAAA,IACJ,OAAO;AACH,YAAM,sBAAsB,MAAY;AACpC,YAAI,KAAK,6BAA6B,SAAS,YAAY;AACvD,eAAK,0BAA0B,SAAS,UAAU;AAAA,QACtD;AAEA,YAAI,SAAS,iBAAiB;AAC1B,mBAAS,gBAAgB;AAAA,QAC7B;AAAA,MACJ;AAKA,WAAK,iBACD,gCACA,qBACA,EA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BAAgB,CAEjC,EAKA,YAAK,iBACD,+BACAC,EACA,CAAE,KAAM,EAAK,CACjB,EAEO,IAAM,CACT,KAAK,oBACD,+BACAA,CACJ,CACJ,CACJ,CAGA,MAAO,IAAM,CAAC,CAClB,EAEMC,EAA2B,OAAO,yBAAyB,EAKjE,MAAMC,UAAgCN,CAAW,CAAjD,kCACI,KAASC,GACL,KAIK,mBAA0B,CAC/B,MAAM,mBAAqB,MAAM,kBAAkB,EAC9CH,GACD,sBAAsB,IAAM,CACpB,KAAKO,IAA6B,OAClC,KAAKA,GACDH,EAAuB,IAAI,EAEvC,CAAC,CAET,CAES,sBAA6B,CAClC,MAAM,sBAAwB,MAAM,qBAAqB,EAGpDJ,GACD,sBAAsB,IAAM,CACpB,KAAKO,IAA6B,OAElC,KAAKA,GAA2B,EAChC,KAAKA,GAA4B,KAEzC,CAAC,CAET,CACJ,CAzJJ,OA0HiBJ,EAAAI,EAiCNC,CACX",
6
+ "names": ["hasFocusVisible", "error", "SuperClass", "_a", "coordinateWithPolyfill", "instance", "coordinationHandler", "$endPolyfillCoordination", "FocusVisibleCoordinator"]
7
7
  }
@@ -43,6 +43,8 @@ export declare class Focusable extends Focusable_base {
43
43
  protected update(changedProperties: PropertyValues): void;
44
44
  protected updated(changedProperties: PropertyValues): void;
45
45
  private handleDisabledChanged;
46
+ protected getUpdateComplete(): Promise<boolean>;
47
+ private _recentlyConnected;
46
48
  connectedCallback(): void;
47
49
  }
48
50
  export {};
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __decorateClass = (decorators, target, key, kind) => {
@@ -12,6 +13,9 @@ var __decorateClass = (decorators, target, key, kind) => {
12
13
  import { SpectrumElement } from "@spectrum-web-components/base";
13
14
  import { property } from "@spectrum-web-components/base/src/decorators.js";
14
15
  import { FocusVisiblePolyfillMixin } from "./focus-visible.dev.js";
16
+ function nextFrame() {
17
+ return new Promise((res) => requestAnimationFrame(() => res()));
18
+ }
15
19
  export class Focusable extends FocusVisiblePolyfillMixin(SpectrumElement) {
16
20
  constructor() {
17
21
  super(...arguments);
@@ -19,13 +23,16 @@ export class Focusable extends FocusVisiblePolyfillMixin(SpectrumElement) {
19
23
  this.autofocus = false;
20
24
  this._tabIndex = 0;
21
25
  this.manipulatingTabindex = false;
26
+ this._recentlyConnected = false;
22
27
  }
23
28
  get tabIndex() {
24
29
  if (this.focusElement === this) {
25
30
  const tabindex = this.hasAttribute("tabindex") ? Number(this.getAttribute("tabindex")) : NaN;
26
31
  return !isNaN(tabindex) ? tabindex : -1;
27
32
  }
28
- const tabIndexAttribute = parseFloat(this.hasAttribute("tabindex") ? this.getAttribute("tabindex") || "0" : "0");
33
+ const tabIndexAttribute = parseFloat(
34
+ this.hasAttribute("tabindex") ? this.getAttribute("tabindex") || "0" : "0"
35
+ );
29
36
  if (this.disabled || tabIndexAttribute < 0) {
30
37
  return -1;
31
38
  }
@@ -48,10 +55,16 @@ export class Focusable extends FocusVisiblePolyfillMixin(SpectrumElement) {
48
55
  return;
49
56
  }
50
57
  if (tabIndex === -1) {
51
- this.addEventListener("pointerdown", this.onPointerdownManagementOfTabIndex);
58
+ this.addEventListener(
59
+ "pointerdown",
60
+ this.onPointerdownManagementOfTabIndex
61
+ );
52
62
  } else {
53
63
  this.manipulatingTabindex = true;
54
- this.removeEventListener("pointerdown", this.onPointerdownManagementOfTabIndex);
64
+ this.removeEventListener(
65
+ "pointerdown",
66
+ this.onPointerdownManagementOfTabIndex
67
+ );
55
68
  }
56
69
  if (tabIndex === -1 || this.disabled) {
57
70
  this.setAttribute("tabindex", "-1");
@@ -119,9 +132,11 @@ export class Focusable extends FocusVisiblePolyfillMixin(SpectrumElement) {
119
132
  }
120
133
  manageAutoFocus() {
121
134
  if (this.autofocus) {
122
- this.dispatchEvent(new KeyboardEvent("keydown", {
123
- code: "Tab"
124
- }));
135
+ this.dispatchEvent(
136
+ new KeyboardEvent("keydown", {
137
+ code: "Tab"
138
+ })
139
+ );
125
140
  this.focusElement.focus();
126
141
  }
127
142
  }
@@ -133,7 +148,10 @@ export class Focusable extends FocusVisiblePolyfillMixin(SpectrumElement) {
133
148
  }
134
149
  update(changedProperties) {
135
150
  if (changedProperties.has("disabled")) {
136
- this.handleDisabledChanged(this.disabled, changedProperties.get("disabled"));
151
+ this.handleDisabledChanged(
152
+ this.disabled,
153
+ changedProperties.get("disabled")
154
+ );
137
155
  }
138
156
  super.update(changedProperties);
139
157
  }
@@ -169,12 +187,20 @@ export class Focusable extends FocusVisiblePolyfillMixin(SpectrumElement) {
169
187
  }
170
188
  }
171
189
  }
190
+ async getUpdateComplete() {
191
+ const complete = await super.getUpdateComplete();
192
+ if (this._recentlyConnected) {
193
+ this._recentlyConnected = false;
194
+ await nextFrame();
195
+ await nextFrame();
196
+ }
197
+ return complete;
198
+ }
172
199
  connectedCallback() {
173
200
  super.connectedCallback();
201
+ this._recentlyConnected = true;
174
202
  this.updateComplete.then(() => {
175
- requestAnimationFrame(() => {
176
- this.manageAutoFocus();
177
- });
203
+ this.manageAutoFocus();
178
204
  });
179
205
  }
180
206
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["focusable.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 { PropertyValues, SpectrumElement } from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\n\nimport { FocusVisiblePolyfillMixin } from './focus-visible.dev.js'\n\ntype DisableableElement = HTMLElement & { disabled?: boolean };\n\n/**\n * Focusable base class handles tabindex setting into shadowed elements automatically.\n *\n * This implementation is based heavily on the aybolit delegate-focus-mixin at\n * https://github.com/web-padawan/aybolit/blob/master/packages/core/src/mixins/delegate-focus-mixin.js\n */\nexport class Focusable extends FocusVisiblePolyfillMixin(SpectrumElement) {\n /**\n * Disable this control. It will not receive focus or events\n */\n @property({ type: Boolean, reflect: true })\n public disabled = false;\n\n /**\n * When this control is rendered, focus it automatically\n * @private\n */\n @property({ type: Boolean })\n public override autofocus = false;\n\n /**\n * The tab index to apply to this control. See general documentation about\n * the tabindex HTML property\n *\n * @private\n */\n @property({ type: Number })\n public override get tabIndex(): number {\n if (this.focusElement === this) {\n const tabindex = this.hasAttribute('tabindex')\n ? Number(this.getAttribute('tabindex'))\n : NaN;\n return !isNaN(tabindex) ? tabindex : -1;\n }\n const tabIndexAttribute = parseFloat(\n this.hasAttribute('tabindex')\n ? (this.getAttribute('tabindex') as string) || '0'\n : '0'\n );\n // When `disabled` tabindex is -1.\n // When host tabindex -1, use that as the cache.\n if (this.disabled || tabIndexAttribute < 0) {\n return -1;\n }\n // When `focusElement` isn't available yet,\n // use host tabindex as the cache.\n if (!this.focusElement) {\n return tabIndexAttribute;\n }\n // All other times, use the tabindex of `focusElement`\n // as the cache for this value.\n return this.focusElement.tabIndex;\n }\n public override set tabIndex(tabIndex: number) {\n // Flipping `manipulatingTabindex` to true before a change\n // allows for that change NOT to effect the cached value of tabindex\n if (this.manipulatingTabindex) {\n this.manipulatingTabindex = false;\n return;\n }\n if (this.focusElement === this) {\n if (tabIndex !== this.tabIndex) {\n this._tabIndex = tabIndex;\n const tabindex = this.disabled ? '-1' : '' + tabIndex;\n this.setAttribute('tabindex', tabindex);\n }\n return;\n }\n if (tabIndex === -1) {\n this.addEventListener(\n 'pointerdown',\n this.onPointerdownManagementOfTabIndex\n );\n } else {\n // All code paths are about to address the host tabindex without side effect.\n this.manipulatingTabindex = true;\n this.removeEventListener(\n 'pointerdown',\n this.onPointerdownManagementOfTabIndex\n );\n }\n if (tabIndex === -1 || this.disabled) {\n // Do not cange the tabindex of `focusElement` as it is the \"old\" value cache.\n // Make element NOT focusable.\n this.setAttribute('tabindex', '-1');\n this.removeAttribute('focusable');\n if (tabIndex !== -1) {\n // Cache all NON-`-1` values on the `focusElement`.\n this.manageFocusElementTabindex(tabIndex);\n }\n return;\n }\n this.setAttribute('focusable', '');\n if (this.hasAttribute('tabindex')) {\n this.removeAttribute('tabindex');\n } else {\n // You can't remove an attribute that isn't there,\n // manually end the `manipulatingTabindex` guard.\n this.manipulatingTabindex = false;\n }\n this.manageFocusElementTabindex(tabIndex);\n }\n private _tabIndex = 0;\n\n private onPointerdownManagementOfTabIndex(): void {\n if (this.tabIndex === -1) {\n this.tabIndex = 0;\n this.focus({ preventScroll: true });\n }\n }\n\n private async manageFocusElementTabindex(tabIndex: number): Promise<void> {\n if (!this.focusElement) {\n // allow setting these values to be async when needed.\n await this.updateComplete;\n }\n if (tabIndex === null) {\n this.focusElement.removeAttribute('tabindex');\n } else {\n this.focusElement.tabIndex = tabIndex;\n }\n }\n\n private manipulatingTabindex = false;\n\n /**\n * @private\n */\n public get focusElement(): DisableableElement {\n throw new Error('Must implement focusElement getter!');\n }\n\n public override focus(options?: FocusOptions): void {\n if (this.disabled || !this.focusElement) {\n return;\n }\n\n if (this.focusElement !== this) {\n this.focusElement.focus(options);\n } else {\n HTMLElement.prototype.focus.apply(this, [options]);\n }\n }\n\n public override blur(): void {\n const focusElement = this.focusElement || this;\n if (focusElement !== this) {\n focusElement.blur();\n } else {\n HTMLElement.prototype.blur.apply(this);\n }\n }\n\n public override click(): void {\n if (this.disabled) {\n return;\n }\n\n const focusElement = this.focusElement || this;\n if (focusElement !== this) {\n focusElement.click();\n } else {\n HTMLElement.prototype.click.apply(this);\n }\n }\n\n protected manageAutoFocus(): void {\n if (this.autofocus) {\n /**\n * Trick :focus-visible polyfill into thinking keyboard based focus\n *\n * @private\n **/\n this.dispatchEvent(\n new KeyboardEvent('keydown', {\n code: 'Tab',\n })\n );\n this.focusElement.focus();\n }\n }\n\n protected override firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n if (\n !this.hasAttribute('tabindex') ||\n this.getAttribute('tabindex') !== '-1'\n ) {\n this.setAttribute('focusable', '');\n }\n }\n\n protected override update(changedProperties: PropertyValues): void {\n if (changedProperties.has('disabled')) {\n this.handleDisabledChanged(\n this.disabled,\n changedProperties.get('disabled') as boolean\n );\n }\n\n super.update(changedProperties);\n }\n\n protected override updated(changedProperties: PropertyValues): void {\n super.updated(changedProperties);\n\n if (changedProperties.has('disabled') && this.disabled) {\n this.blur();\n }\n }\n\n private async handleDisabledChanged(\n disabled: boolean,\n oldDisabled: boolean\n ): Promise<void> {\n const canSetDisabled = (): boolean =>\n this.focusElement !== this &&\n typeof this.focusElement.disabled !== 'undefined';\n if (disabled) {\n this.manipulatingTabindex = true;\n this.setAttribute('tabindex', '-1');\n await this.updateComplete;\n if (canSetDisabled()) {\n this.focusElement.disabled = true;\n } else {\n this.setAttribute('aria-disabled', 'true');\n }\n } else if (oldDisabled) {\n this.manipulatingTabindex = true;\n if (this.focusElement === this) {\n this.setAttribute('tabindex', '' + this._tabIndex);\n } else {\n this.removeAttribute('tabindex');\n }\n await this.updateComplete;\n if (canSetDisabled()) {\n this.focusElement.disabled = false;\n } else {\n this.removeAttribute('aria-disabled');\n }\n }\n }\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this.updateComplete.then(() => {\n requestAnimationFrame(() => {\n this.manageAutoFocus();\n });\n });\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;AAWA;AACA;AAEA;AAUO,aAAM,kBAAkB,0BAA0B,eAAe,EAAE;AAAA,EAAnE;AAAA;AAKI,oBAAW;AAOF,qBAAY;AAoFpB,qBAAY;AAqBZ,gCAAuB;AAAA;AAAA,MAhGX,WAAmB;AACnC,QAAI,KAAK,iBAAiB,MAAM;AAC5B,YAAM,WAAW,KAAK,aAAa,UAAU,IACvC,OAAO,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AKI;AAOS;AAAA,EADhB,AAAC,SAAS,EAAE,MAAM,QAAQ,CAAC;AAAA,GACX,AAZb,UAYa;AASI;AAAA,EADpB,AAAC,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GACN,AArBjB,UAqBiB;",
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 { PropertyValues, SpectrumElement } from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\n\nimport { FocusVisiblePolyfillMixin } from './focus-visible.dev.js'\n\ntype DisableableElement = HTMLElement & { disabled?: boolean };\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\n/**\n * Focusable base class handles tabindex setting into shadowed elements automatically.\n *\n * This implementation is based heavily on the aybolit delegate-focus-mixin at\n * https://github.com/web-padawan/aybolit/blob/master/packages/core/src/mixins/delegate-focus-mixin.js\n */\nexport class Focusable extends FocusVisiblePolyfillMixin(SpectrumElement) {\n /**\n * Disable this control. It will not receive focus or events\n */\n @property({ type: Boolean, reflect: true })\n public disabled = false;\n\n /**\n * When this control is rendered, focus it automatically\n * @private\n */\n @property({ type: Boolean })\n public override autofocus = false;\n\n /**\n * The tab index to apply to this control. See general documentation about\n * the tabindex HTML property\n *\n * @private\n */\n @property({ type: Number })\n public override get tabIndex(): number {\n if (this.focusElement === this) {\n const tabindex = this.hasAttribute('tabindex')\n ? Number(this.getAttribute('tabindex'))\n : NaN;\n return !isNaN(tabindex) ? tabindex : -1;\n }\n const tabIndexAttribute = parseFloat(\n this.hasAttribute('tabindex')\n ? (this.getAttribute('tabindex') as string) || '0'\n : '0'\n );\n // When `disabled` tabindex is -1.\n // When host tabindex -1, use that as the cache.\n if (this.disabled || tabIndexAttribute < 0) {\n return -1;\n }\n // When `focusElement` isn't available yet,\n // use host tabindex as the cache.\n if (!this.focusElement) {\n return tabIndexAttribute;\n }\n // All other times, use the tabindex of `focusElement`\n // as the cache for this value.\n return this.focusElement.tabIndex;\n }\n public override set tabIndex(tabIndex: number) {\n // Flipping `manipulatingTabindex` to true before a change\n // allows for that change NOT to effect the cached value of tabindex\n if (this.manipulatingTabindex) {\n this.manipulatingTabindex = false;\n return;\n }\n if (this.focusElement === this) {\n if (tabIndex !== this.tabIndex) {\n this._tabIndex = tabIndex;\n const tabindex = this.disabled ? '-1' : '' + tabIndex;\n this.setAttribute('tabindex', tabindex);\n }\n return;\n }\n if (tabIndex === -1) {\n this.addEventListener(\n 'pointerdown',\n this.onPointerdownManagementOfTabIndex\n );\n } else {\n // All code paths are about to address the host tabindex without side effect.\n this.manipulatingTabindex = true;\n this.removeEventListener(\n 'pointerdown',\n this.onPointerdownManagementOfTabIndex\n );\n }\n if (tabIndex === -1 || this.disabled) {\n // Do not cange the tabindex of `focusElement` as it is the \"old\" value cache.\n // Make element NOT focusable.\n this.setAttribute('tabindex', '-1');\n this.removeAttribute('focusable');\n if (tabIndex !== -1) {\n // Cache all NON-`-1` values on the `focusElement`.\n this.manageFocusElementTabindex(tabIndex);\n }\n return;\n }\n this.setAttribute('focusable', '');\n if (this.hasAttribute('tabindex')) {\n this.removeAttribute('tabindex');\n } else {\n // You can't remove an attribute that isn't there,\n // manually end the `manipulatingTabindex` guard.\n this.manipulatingTabindex = false;\n }\n this.manageFocusElementTabindex(tabIndex);\n }\n private _tabIndex = 0;\n\n private onPointerdownManagementOfTabIndex(): void {\n if (this.tabIndex === -1) {\n this.tabIndex = 0;\n this.focus({ preventScroll: true });\n }\n }\n\n private async manageFocusElementTabindex(tabIndex: number): Promise<void> {\n if (!this.focusElement) {\n // allow setting these values to be async when needed.\n await this.updateComplete;\n }\n if (tabIndex === null) {\n this.focusElement.removeAttribute('tabindex');\n } else {\n this.focusElement.tabIndex = tabIndex;\n }\n }\n\n private manipulatingTabindex = false;\n\n /**\n * @private\n */\n public get focusElement(): DisableableElement {\n throw new Error('Must implement focusElement getter!');\n }\n\n public override focus(options?: FocusOptions): void {\n if (this.disabled || !this.focusElement) {\n return;\n }\n\n if (this.focusElement !== this) {\n this.focusElement.focus(options);\n } else {\n HTMLElement.prototype.focus.apply(this, [options]);\n }\n }\n\n public override blur(): void {\n const focusElement = this.focusElement || this;\n if (focusElement !== this) {\n focusElement.blur();\n } else {\n HTMLElement.prototype.blur.apply(this);\n }\n }\n\n public override click(): void {\n if (this.disabled) {\n return;\n }\n\n const focusElement = this.focusElement || this;\n if (focusElement !== this) {\n focusElement.click();\n } else {\n HTMLElement.prototype.click.apply(this);\n }\n }\n\n protected manageAutoFocus(): void {\n if (this.autofocus) {\n /**\n * Trick :focus-visible polyfill into thinking keyboard based focus\n *\n * @private\n **/\n this.dispatchEvent(\n new KeyboardEvent('keydown', {\n code: 'Tab',\n })\n );\n this.focusElement.focus();\n }\n }\n\n protected override firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n if (\n !this.hasAttribute('tabindex') ||\n this.getAttribute('tabindex') !== '-1'\n ) {\n this.setAttribute('focusable', '');\n }\n }\n\n protected override update(changedProperties: PropertyValues): void {\n if (changedProperties.has('disabled')) {\n this.handleDisabledChanged(\n this.disabled,\n changedProperties.get('disabled') as boolean\n );\n }\n\n super.update(changedProperties);\n }\n\n protected override updated(changedProperties: PropertyValues): void {\n super.updated(changedProperties);\n\n if (changedProperties.has('disabled') && this.disabled) {\n this.blur();\n }\n }\n\n private async handleDisabledChanged(\n disabled: boolean,\n oldDisabled: boolean\n ): Promise<void> {\n const canSetDisabled = (): boolean =>\n this.focusElement !== this &&\n typeof this.focusElement.disabled !== 'undefined';\n if (disabled) {\n this.manipulatingTabindex = true;\n this.setAttribute('tabindex', '-1');\n await this.updateComplete;\n if (canSetDisabled()) {\n this.focusElement.disabled = true;\n } else {\n this.setAttribute('aria-disabled', 'true');\n }\n } else if (oldDisabled) {\n this.manipulatingTabindex = true;\n if (this.focusElement === this) {\n this.setAttribute('tabindex', '' + this._tabIndex);\n } else {\n this.removeAttribute('tabindex');\n }\n await this.updateComplete;\n if (canSetDisabled()) {\n this.focusElement.disabled = false;\n } else {\n this.removeAttribute('aria-disabled');\n }\n }\n }\n\n protected override async getUpdateComplete(): Promise<boolean> {\n const complete = (await super.getUpdateComplete()) as boolean;\n if (this._recentlyConnected) {\n this._recentlyConnected = false;\n // If at connect time the [autofocus] content is placed within\n // content that needs to be \"hidden\" by default, it would need to wait\n // two rAFs for animations to be triggered on that content in\n // order for the [autofocus] to become \"visisble\" and have its\n // focus() capabilities enabled.\n //\n // Await this with `getUpdateComplete` so that the element cannot\n // become \"ready\" until `manageFocus` has occured.\n await nextFrame();\n await nextFrame();\n }\n return complete;\n }\n\n private _recentlyConnected = false;\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this._recentlyConnected = true;\n this.updateComplete.then(() => {\n this.manageAutoFocus();\n });\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;AAWA,SAAyB,uBAAuB;AAChD,SAAS,gBAAgB;AAEzB,SAAS,iCAAiC;AAI1C,SAAS,YAA2B;AAChC,SAAO,IAAI,QAAQ,CAAC,QAAQ,sBAAsB,MAAM,IAAI,CAAC,CAAC;AAClE;AAQO,aAAM,kBAAkB,0BAA0B,eAAe,EAAE;AAAA,EAAnE;AAAA;AAKH,SAAO,WAAW;AAOlB,SAAgB,YAAY;AAoF5B,SAAQ,YAAY;AAqBpB,SAAQ,uBAAuB;AA0I/B,SAAQ,qBAAqB;AAAA;AAAA,EA1O7B,IAAoB,WAAmB;AACnC,QAAI,KAAK,iBAAiB,MAAM;AAC5B,YAAM,WAAW,KAAK,aAAa,UAAU,IACvC,OAAO,KAAK,aAAa,UAAU,CAAC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A,EACX;AAAA,EAIgB,oBAA0B;AACtC,UAAM,kBAAkB;AACxB,SAAK,qBAAqB;AAC1B,SAAK,eAAe,KAAK,MAAM;AAC3B,WAAK,gBAAgB;AAAA,IACzB,CAAC;AAAA,EACL;AACJ;AAnQW;AAAA,EADN,SAAS,EAAE,MAAM,SAAS,SAAS,KAAK,CAAC;AAAA,GAJjC,UAKF;AAOS;AAAA,EADf,SAAS,EAAE,MAAM,QAAQ,CAAC;AAAA,GAXlB,UAYO;AASI;AAAA,EADnB,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GApBjB,UAqBW;",
6
6
  "names": []
7
7
  }
package/src/focusable.js CHANGED
@@ -1,190 +1,2 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __decorateClass = (decorators, target, key, kind) => {
4
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
- if (decorator = decorators[i])
7
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
- if (kind && result)
9
- __defProp(target, key, result);
10
- return result;
11
- };
12
- import { SpectrumElement } from "@spectrum-web-components/base";
13
- import { property } from "@spectrum-web-components/base/src/decorators.js";
14
- import { FocusVisiblePolyfillMixin } from "./focus-visible.js";
15
- export class Focusable extends FocusVisiblePolyfillMixin(SpectrumElement) {
16
- constructor() {
17
- super(...arguments);
18
- this.disabled = false;
19
- this.autofocus = false;
20
- this._tabIndex = 0;
21
- this.manipulatingTabindex = false;
22
- }
23
- get tabIndex() {
24
- if (this.focusElement === this) {
25
- const tabindex = this.hasAttribute("tabindex") ? Number(this.getAttribute("tabindex")) : NaN;
26
- return !isNaN(tabindex) ? tabindex : -1;
27
- }
28
- const tabIndexAttribute = parseFloat(this.hasAttribute("tabindex") ? this.getAttribute("tabindex") || "0" : "0");
29
- if (this.disabled || tabIndexAttribute < 0) {
30
- return -1;
31
- }
32
- if (!this.focusElement) {
33
- return tabIndexAttribute;
34
- }
35
- return this.focusElement.tabIndex;
36
- }
37
- set tabIndex(tabIndex) {
38
- if (this.manipulatingTabindex) {
39
- this.manipulatingTabindex = false;
40
- return;
41
- }
42
- if (this.focusElement === this) {
43
- if (tabIndex !== this.tabIndex) {
44
- this._tabIndex = tabIndex;
45
- const tabindex = this.disabled ? "-1" : "" + tabIndex;
46
- this.setAttribute("tabindex", tabindex);
47
- }
48
- return;
49
- }
50
- if (tabIndex === -1) {
51
- this.addEventListener("pointerdown", this.onPointerdownManagementOfTabIndex);
52
- } else {
53
- this.manipulatingTabindex = true;
54
- this.removeEventListener("pointerdown", this.onPointerdownManagementOfTabIndex);
55
- }
56
- if (tabIndex === -1 || this.disabled) {
57
- this.setAttribute("tabindex", "-1");
58
- this.removeAttribute("focusable");
59
- if (tabIndex !== -1) {
60
- this.manageFocusElementTabindex(tabIndex);
61
- }
62
- return;
63
- }
64
- this.setAttribute("focusable", "");
65
- if (this.hasAttribute("tabindex")) {
66
- this.removeAttribute("tabindex");
67
- } else {
68
- this.manipulatingTabindex = false;
69
- }
70
- this.manageFocusElementTabindex(tabIndex);
71
- }
72
- onPointerdownManagementOfTabIndex() {
73
- if (this.tabIndex === -1) {
74
- this.tabIndex = 0;
75
- this.focus({ preventScroll: true });
76
- }
77
- }
78
- async manageFocusElementTabindex(tabIndex) {
79
- if (!this.focusElement) {
80
- await this.updateComplete;
81
- }
82
- if (tabIndex === null) {
83
- this.focusElement.removeAttribute("tabindex");
84
- } else {
85
- this.focusElement.tabIndex = tabIndex;
86
- }
87
- }
88
- get focusElement() {
89
- throw new Error("Must implement focusElement getter!");
90
- }
91
- focus(options) {
92
- if (this.disabled || !this.focusElement) {
93
- return;
94
- }
95
- if (this.focusElement !== this) {
96
- this.focusElement.focus(options);
97
- } else {
98
- HTMLElement.prototype.focus.apply(this, [options]);
99
- }
100
- }
101
- blur() {
102
- const focusElement = this.focusElement || this;
103
- if (focusElement !== this) {
104
- focusElement.blur();
105
- } else {
106
- HTMLElement.prototype.blur.apply(this);
107
- }
108
- }
109
- click() {
110
- if (this.disabled) {
111
- return;
112
- }
113
- const focusElement = this.focusElement || this;
114
- if (focusElement !== this) {
115
- focusElement.click();
116
- } else {
117
- HTMLElement.prototype.click.apply(this);
118
- }
119
- }
120
- manageAutoFocus() {
121
- if (this.autofocus) {
122
- this.dispatchEvent(new KeyboardEvent("keydown", {
123
- code: "Tab"
124
- }));
125
- this.focusElement.focus();
126
- }
127
- }
128
- firstUpdated(changes) {
129
- super.firstUpdated(changes);
130
- if (!this.hasAttribute("tabindex") || this.getAttribute("tabindex") !== "-1") {
131
- this.setAttribute("focusable", "");
132
- }
133
- }
134
- update(changedProperties) {
135
- if (changedProperties.has("disabled")) {
136
- this.handleDisabledChanged(this.disabled, changedProperties.get("disabled"));
137
- }
138
- super.update(changedProperties);
139
- }
140
- updated(changedProperties) {
141
- super.updated(changedProperties);
142
- if (changedProperties.has("disabled") && this.disabled) {
143
- this.blur();
144
- }
145
- }
146
- async handleDisabledChanged(disabled, oldDisabled) {
147
- const canSetDisabled = () => this.focusElement !== this && typeof this.focusElement.disabled !== "undefined";
148
- if (disabled) {
149
- this.manipulatingTabindex = true;
150
- this.setAttribute("tabindex", "-1");
151
- await this.updateComplete;
152
- if (canSetDisabled()) {
153
- this.focusElement.disabled = true;
154
- } else {
155
- this.setAttribute("aria-disabled", "true");
156
- }
157
- } else if (oldDisabled) {
158
- this.manipulatingTabindex = true;
159
- if (this.focusElement === this) {
160
- this.setAttribute("tabindex", "" + this._tabIndex);
161
- } else {
162
- this.removeAttribute("tabindex");
163
- }
164
- await this.updateComplete;
165
- if (canSetDisabled()) {
166
- this.focusElement.disabled = false;
167
- } else {
168
- this.removeAttribute("aria-disabled");
169
- }
170
- }
171
- }
172
- connectedCallback() {
173
- super.connectedCallback();
174
- this.updateComplete.then(() => {
175
- requestAnimationFrame(() => {
176
- this.manageAutoFocus();
177
- });
178
- });
179
- }
180
- }
181
- __decorateClass([
182
- property({ type: Boolean, reflect: true })
183
- ], Focusable.prototype, "disabled", 2);
184
- __decorateClass([
185
- property({ type: Boolean })
186
- ], Focusable.prototype, "autofocus", 2);
187
- __decorateClass([
188
- property({ type: Number })
189
- ], Focusable.prototype, "tabIndex", 1);
1
+ "use strict";var u=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var n=(s,a,e,t)=>{for(var i=t>1?void 0:t?b(a,e):a,o=s.length-1,r;o>=0;o--)(r=s[o])&&(i=(t?r(a,e,i):r(i))||i);return t&&i&&u(a,e,i),i};import{SpectrumElement as h}from"@spectrum-web-components/base";import{property as l}from"@spectrum-web-components/base/src/decorators.js";import{FocusVisiblePolyfillMixin as c}from"./focus-visible.js";function d(){return new Promise(s=>requestAnimationFrame(()=>s()))}export class Focusable extends c(h){constructor(){super(...arguments);this.disabled=!1;this.autofocus=!1;this._tabIndex=0;this.manipulatingTabindex=!1;this._recentlyConnected=!1}get tabIndex(){if(this.focusElement===this){const t=this.hasAttribute("tabindex")?Number(this.getAttribute("tabindex")):NaN;return isNaN(t)?-1:t}const e=parseFloat(this.hasAttribute("tabindex")&&this.getAttribute("tabindex")||"0");return this.disabled||e<0?-1:this.focusElement?this.focusElement.tabIndex:e}set tabIndex(e){if(this.manipulatingTabindex){this.manipulatingTabindex=!1;return}if(this.focusElement===this){if(e!==this.tabIndex){this._tabIndex=e;const t=this.disabled?"-1":""+e;this.setAttribute("tabindex",t)}return}if(e===-1?this.addEventListener("pointerdown",this.onPointerdownManagementOfTabIndex):(this.manipulatingTabindex=!0,this.removeEventListener("pointerdown",this.onPointerdownManagementOfTabIndex)),e===-1||this.disabled){this.setAttribute("tabindex","-1"),this.removeAttribute("focusable"),e!==-1&&this.manageFocusElementTabindex(e);return}this.setAttribute("focusable",""),this.hasAttribute("tabindex")?this.removeAttribute("tabindex"):this.manipulatingTabindex=!1,this.manageFocusElementTabindex(e)}onPointerdownManagementOfTabIndex(){this.tabIndex===-1&&(this.tabIndex=0,this.focus({preventScroll:!0}))}async manageFocusElementTabindex(e){this.focusElement||await this.updateComplete,e===null?this.focusElement.removeAttribute("tabindex"):this.focusElement.tabIndex=e}get focusElement(){throw new Error("Must implement focusElement getter!")}focus(e){this.disabled||!this.focusElement||(this.focusElement!==this?this.focusElement.focus(e):HTMLElement.prototype.focus.apply(this,[e]))}blur(){const e=this.focusElement||this;e!==this?e.blur():HTMLElement.prototype.blur.apply(this)}click(){if(this.disabled)return;const e=this.focusElement||this;e!==this?e.click():HTMLElement.prototype.click.apply(this)}manageAutoFocus(){this.autofocus&&(this.dispatchEvent(new KeyboardEvent("keydown",{code:"Tab"})),this.focusElement.focus())}firstUpdated(e){super.firstUpdated(e),(!this.hasAttribute("tabindex")||this.getAttribute("tabindex")!=="-1")&&this.setAttribute("focusable","")}update(e){e.has("disabled")&&this.handleDisabledChanged(this.disabled,e.get("disabled")),super.update(e)}updated(e){super.updated(e),e.has("disabled")&&this.disabled&&this.blur()}async handleDisabledChanged(e,t){const i=()=>this.focusElement!==this&&typeof this.focusElement.disabled!="undefined";e?(this.manipulatingTabindex=!0,this.setAttribute("tabindex","-1"),await this.updateComplete,i()?this.focusElement.disabled=!0:this.setAttribute("aria-disabled","true")):t&&(this.manipulatingTabindex=!0,this.focusElement===this?this.setAttribute("tabindex",""+this._tabIndex):this.removeAttribute("tabindex"),await this.updateComplete,i()?this.focusElement.disabled=!1:this.removeAttribute("aria-disabled"))}async getUpdateComplete(){const e=await super.getUpdateComplete();return this._recentlyConnected&&(this._recentlyConnected=!1,await d(),await d()),e}connectedCallback(){super.connectedCallback(),this._recentlyConnected=!0,this.updateComplete.then(()=>{this.manageAutoFocus()})}}n([l({type:Boolean,reflect:!0})],Focusable.prototype,"disabled",2),n([l({type:Boolean})],Focusable.prototype,"autofocus",2),n([l({type:Number})],Focusable.prototype,"tabIndex",1);
190
2
  //# sourceMappingURL=focusable.js.map