@spectrum-web-components/shared 0.14.2 → 0.14.5-devmode.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/package.json +53 -6
- package/src/first-focusable-in.dev.js +6 -0
- package/src/first-focusable-in.dev.js.map +7 -0
- package/src/first-focusable-in.js +3 -14
- package/src/first-focusable-in.js.map +7 -1
- package/src/focus-visible.dev.js +68 -0
- package/src/focus-visible.dev.js.map +7 -0
- package/src/focus-visible.js +59 -105
- package/src/focus-visible.js.map +7 -1
- package/src/focusable.dev.js +190 -0
- package/src/focusable.dev.js.map +7 -0
- package/src/focusable.js +185 -244
- package/src/focusable.js.map +7 -1
- package/src/get-active-element.dev.js +4 -0
- package/src/get-active-element.dev.js.map +7 -0
- package/src/get-active-element.js +2 -14
- package/src/get-active-element.js.map +7 -1
- package/src/get-deep-element-from-point.d.ts +1 -0
- package/src/get-deep-element-from-point.dev.js +12 -0
- package/src/get-deep-element-from-point.dev.js.map +7 -0
- package/src/get-deep-element-from-point.js +12 -0
- package/src/get-deep-element-from-point.js.map +7 -0
- package/src/index.dev.js +10 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +10 -21
- package/src/index.js.map +7 -1
- package/src/like-anchor.dev.js +58 -0
- package/src/like-anchor.dev.js.map +7 -0
- package/src/like-anchor.js +45 -40
- package/src/like-anchor.js.map +7 -1
- package/src/observe-slot-presence.dev.js +52 -0
- package/src/observe-slot-presence.dev.js.map +7 -0
- package/src/observe-slot-presence.js +47 -52
- package/src/observe-slot-presence.js.map +7 -1
- package/src/observe-slot-text.d.ts +1 -1
- package/src/observe-slot-text.dev.js +79 -0
- package/src/observe-slot-text.dev.js.map +7 -0
- package/src/observe-slot-text.js +74 -57
- package/src/observe-slot-text.js.map +7 -1
- package/src/platform.dev.js +31 -0
- package/src/platform.dev.js.map +7 -0
- package/src/platform.js +11 -32
- package/src/platform.js.map +7 -1
- package/src/reparent-children.dev.js +50 -0
- package/src/reparent-children.dev.js.map +7 -0
- package/src/reparent-children.js +44 -52
- package/src/reparent-children.js.map +7 -1
- package/test/focusable.test.js +19 -31
- package/test/focusable.test.js.map +7 -1
- package/test/observe-slot-presence.test.js +17 -27
- package/test/observe-slot-presence.test.js.map +7 -1
- package/test/observe-slot-text.test.js +17 -28
- package/test/observe-slot-text.test.js.map +7 -1
- package/test/reparent-children.test.js +151 -162
- package/test/reparent-children.test.js.map +7 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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,KAAK,aAAa,UAAU,CAAC,IACpC;AACN,aAAO,CAAC,MAAM,QAAQ,IAAI,WAAW;AAAA,IACzC;AACA,UAAM,oBAAoB,WACtB,KAAK,aAAa,UAAU,IACrB,KAAK,aAAa,UAAU,KAAgB,MAC7C,GACV;AAGA,QAAI,KAAK,YAAY,oBAAoB,GAAG;AACxC,aAAO;AAAA,IACX;AAGA,QAAI,CAAC,KAAK,cAAc;AACpB,aAAO;AAAA,IACX;AAGA,WAAO,KAAK,aAAa;AAAA,EAC7B;AAAA,MACoB,SAAS,UAAkB;AAG3C,QAAI,KAAK,sBAAsB;AAC3B,WAAK,uB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
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { FocusVisiblePolyfillMixin } from './focus-visible.js';
|
|
16
|
-
/**
|
|
17
|
-
* Focusable base class handles tabindex setting into shadowed elements automatically.
|
|
18
|
-
*
|
|
19
|
-
* This implementation is based heavily on the aybolit delegate-focus-mixin at
|
|
20
|
-
* https://github.com/web-padawan/aybolit/blob/master/packages/core/src/mixins/delegate-focus-mixin.js
|
|
21
|
-
*/
|
|
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";
|
|
22
15
|
export class Focusable extends FocusVisiblePolyfillMixin(SpectrumElement) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
set tabIndex(tabIndex) {
|
|
68
|
-
// Flipping `manipulatingTabindex` to true before a change
|
|
69
|
-
// allows for that change NOT to effect the cached value of tabindex
|
|
70
|
-
if (this.manipulatingTabindex) {
|
|
71
|
-
this.manipulatingTabindex = false;
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (this.focusElement === this) {
|
|
75
|
-
if (tabIndex !== this.tabIndex) {
|
|
76
|
-
this._tabIndex = tabIndex;
|
|
77
|
-
const tabindex = this.disabled ? '-1' : '' + tabIndex;
|
|
78
|
-
this.setAttribute('tabindex', tabindex);
|
|
79
|
-
}
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
if (tabIndex === -1) {
|
|
83
|
-
this.addEventListener('pointerdown', this.onPointerdownManagementOfTabIndex);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
// All code paths are about to address the host tabindex without side effect.
|
|
87
|
-
this.manipulatingTabindex = true;
|
|
88
|
-
this.removeEventListener('pointerdown', this.onPointerdownManagementOfTabIndex);
|
|
89
|
-
}
|
|
90
|
-
if (tabIndex === -1 || this.disabled) {
|
|
91
|
-
// Do not cange the tabindex of `focusElement` as it is the "old" value cache.
|
|
92
|
-
// Make element NOT focusable.
|
|
93
|
-
this.setAttribute('tabindex', '-1');
|
|
94
|
-
this.removeAttribute('focusable');
|
|
95
|
-
if (tabIndex !== -1) {
|
|
96
|
-
// Cache all NON-`-1` values on the `focusElement`.
|
|
97
|
-
this.manageFocusElementTabindex(tabIndex);
|
|
98
|
-
}
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
this.setAttribute('focusable', '');
|
|
102
|
-
if (this.hasAttribute('tabindex')) {
|
|
103
|
-
this.removeAttribute('tabindex');
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
// You can't remove an attribute that isn't there,
|
|
107
|
-
// manually end the `manipulatingTabindex` guard.
|
|
108
|
-
this.manipulatingTabindex = false;
|
|
109
|
-
}
|
|
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) {
|
|
110
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();
|
|
111
144
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (this.disabled || !this.focusElement) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
if (this.focusElement !== this) {
|
|
141
|
-
this.focusElement.focus(options);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
HTMLElement.prototype.focus.apply(this, [options]);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
blur() {
|
|
148
|
-
const focusElement = this.focusElement || this;
|
|
149
|
-
if (focusElement !== this) {
|
|
150
|
-
focusElement.blur();
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
HTMLElement.prototype.blur.apply(this);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
click() {
|
|
157
|
-
if (this.disabled) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const focusElement = this.focusElement || this;
|
|
161
|
-
if (focusElement !== this) {
|
|
162
|
-
focusElement.click();
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
HTMLElement.prototype.click.apply(this);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
manageAutoFocus() {
|
|
169
|
-
if (this.autofocus) {
|
|
170
|
-
/**
|
|
171
|
-
* Trick :focus-visible polyfill into thinking keyboard based focus
|
|
172
|
-
*
|
|
173
|
-
* @private
|
|
174
|
-
**/
|
|
175
|
-
this.dispatchEvent(new KeyboardEvent('keydown', {
|
|
176
|
-
code: 'Tab',
|
|
177
|
-
}));
|
|
178
|
-
this.focusElement.focus();
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
firstUpdated(changes) {
|
|
182
|
-
super.firstUpdated(changes);
|
|
183
|
-
if (!this.hasAttribute('tabindex') ||
|
|
184
|
-
this.getAttribute('tabindex') !== '-1') {
|
|
185
|
-
this.setAttribute('focusable', '');
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
update(changedProperties) {
|
|
189
|
-
if (changedProperties.has('disabled')) {
|
|
190
|
-
this.handleDisabledChanged(this.disabled, changedProperties.get('disabled'));
|
|
191
|
-
}
|
|
192
|
-
super.update(changedProperties);
|
|
193
|
-
}
|
|
194
|
-
updated(changedProperties) {
|
|
195
|
-
super.updated(changedProperties);
|
|
196
|
-
if (changedProperties.has('disabled') && this.disabled) {
|
|
197
|
-
this.blur();
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
async handleDisabledChanged(disabled, oldDisabled) {
|
|
201
|
-
const canSetDisabled = () => this.focusElement !== this &&
|
|
202
|
-
typeof this.focusElement.disabled !== 'undefined';
|
|
203
|
-
if (disabled) {
|
|
204
|
-
this.manipulatingTabindex = true;
|
|
205
|
-
this.setAttribute('tabindex', '-1');
|
|
206
|
-
await this.updateComplete;
|
|
207
|
-
if (canSetDisabled()) {
|
|
208
|
-
this.focusElement.disabled = true;
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
this.setAttribute('aria-disabled', 'true');
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
else if (oldDisabled) {
|
|
215
|
-
this.manipulatingTabindex = true;
|
|
216
|
-
if (this.focusElement === this) {
|
|
217
|
-
this.setAttribute('tabindex', '' + this._tabIndex);
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
this.removeAttribute('tabindex');
|
|
221
|
-
}
|
|
222
|
-
await this.updateComplete;
|
|
223
|
-
if (canSetDisabled()) {
|
|
224
|
-
this.focusElement.disabled = false;
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
this.removeAttribute('aria-disabled');
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
connectedCallback() {
|
|
232
|
-
super.connectedCallback();
|
|
233
|
-
this.updateComplete.then(() => {
|
|
234
|
-
requestAnimationFrame(() => {
|
|
235
|
-
this.manageAutoFocus();
|
|
236
|
-
});
|
|
237
|
-
});
|
|
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
|
+
}
|
|
238
170
|
}
|
|
171
|
+
}
|
|
172
|
+
connectedCallback() {
|
|
173
|
+
super.connectedCallback();
|
|
174
|
+
this.updateComplete.then(() => {
|
|
175
|
+
requestAnimationFrame(() => {
|
|
176
|
+
this.manageAutoFocus();
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
}
|
|
239
180
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
], Focusable.prototype, "disabled",
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
], Focusable.prototype, "autofocus",
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
], Focusable.prototype, "tabIndex",
|
|
249
|
-
//# sourceMappingURL=focusable.js.map
|
|
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);
|
|
190
|
+
//# sourceMappingURL=focusable.js.map
|
package/src/focusable.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"file":"focusable.js","sourceRoot":"","sources":["focusable.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAkB,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAE3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAI/D;;;;;GAKG;AACH,MAAM,OAAO,SAAU,SAAQ,yBAAyB,CAAC,eAAe,CAAC;IAAzE;;QACI;;WAEG;QAEI,aAAQ,GAAG,KAAK,CAAC;QAExB;;;WAGG;QAEa,cAAS,GAAG,KAAK,CAAC;QAoF1B,cAAS,GAAG,CAAC,CAAC;QAqBd,yBAAoB,GAAG,KAAK,CAAC;IAgIzC,CAAC;IAvOG;;;;;OAKG;IAEH,IAAoB,QAAQ;QACxB,IAAI,IAAI,CAAC,YAAY,KAAK,IAAI,EAAE;YAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC;gBAC1C,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;gBACvC,CAAC,CAAC,GAAG,CAAC;YACV,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3C;QACD,MAAM,iBAAiB,GAAG,UAAU,CAChC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC;YACzB,CAAC,CAAE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAY,IAAI,GAAG;YAClD,CAAC,CAAC,GAAG,CACZ,CAAC;QACF,kCAAkC;QAClC,gDAAgD;QAChD,IAAI,IAAI,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gBACH,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;aACpC;YACD,MAAM,IAAI,CAAC,cAAc,CAAC;YAC1B,IAAI,cAAc,EAAE,EAAE;gBAClB,IAAI,CAAC,YAAY,CAAC,QAAQ,GAAG,KAAK,CAAC;aACtC;iBAAM;gBACH,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;aACzC;SACJ;IACL,CAAC;IAEe,iBAAiB;QAC7B,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE;YAC1B,qBAAqB,CAAC,GAAG,EAAE;gBACvB,IAAI,CAAC,eAAe,EAAE,CAAC;YAC3B,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAhPG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;2CACnB;AAOxB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;4CACM;AASlC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yCA0B1B","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.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"]}
|
|
1
|
+
{
|
|
2
|
+
"version": 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.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,0BAA0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AK,eAAe,KAAK,MAAM;AAC3B,4BAAsB,MAAM;AACxB,aAAK,gBAAgB;AAAA,MACzB,CAAC;AAAA,IACL,CAAC;AAAA,EACL;AACJ;AAhPW;AAAA,EADP,AAAC,SAAS,EAAE,MAAM,SAAS,SAAS,KAAK,CAAC;AAAA,GACnC,AALJ,UAKI;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;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["get-active-element.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\n/* c8 ignore next 3 */\nexport const getActiveElement = (el: Node): Element | null => {\n return (el.getRootNode() as Document).activeElement;\n};\n"],
|
|
5
|
+
"mappings": "AAaO,aAAM,mBAAmB,CAAC,OAA6B;AAC1D,SAAQ,GAAG,YAAY,EAAe;AAC1C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
/* c8 ignore next 3 */
|
|
13
1
|
export const getActiveElement = (el) => {
|
|
14
|
-
|
|
2
|
+
return el.getRootNode().activeElement;
|
|
15
3
|
};
|
|
16
|
-
//# sourceMappingURL=get-active-element.js.map
|
|
4
|
+
//# sourceMappingURL=get-active-element.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["get-active-element.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\n/* c8 ignore next 3 */\nexport const getActiveElement = (el: Node): Element | null => {\n return (el.getRootNode() as Document).activeElement;\n};\n"],
|
|
5
|
+
"mappings": "AAaO,aAAM,mBAAmB,CAAC,OAA6B;AAC1D,SAAQ,GAAG,YAAY,EAAe;AAC1C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getDeepElementFromPoint: (x: number, y: number) => Element | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const getDeepElementFromPoint = (x, y) => {
|
|
2
|
+
let target = document.elementFromPoint(x, y);
|
|
3
|
+
while (target == null ? void 0 : target.shadowRoot) {
|
|
4
|
+
const innerTarget = target.shadowRoot.elementFromPoint(x, y);
|
|
5
|
+
if (!innerTarget || innerTarget === target) {
|
|
6
|
+
break;
|
|
7
|
+
}
|
|
8
|
+
target = innerTarget;
|
|
9
|
+
}
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=get-deep-element-from-point.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["get-deep-element-from-point.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\nexport const getDeepElementFromPoint = (\n x: number,\n y: number\n): Element | null => {\n let target = document.elementFromPoint(x, y);\n while (target?.shadowRoot) {\n const innerTarget = (\n target.shadowRoot as unknown as {\n elementFromPoint: (x: number, y: number) => Element | null;\n }\n ).elementFromPoint(x, y);\n if (!innerTarget || innerTarget === target) {\n break;\n }\n target = innerTarget;\n }\n return target;\n};\n"],
|
|
5
|
+
"mappings": "AAYO,aAAM,0BAA0B,CACnC,GACA,MACiB;AACjB,MAAI,SAAS,SAAS,iBAAiB,GAAG,CAAC;AAC3C,SAAO,iCAAQ,YAAY;AACvB,UAAM,cACF,OAAO,WAGT,iBAAiB,GAAG,CAAC;AACvB,QAAI,CAAC,eAAe,gBAAgB,QAAQ;AACxC;AAAA,IACJ;AACA,aAAS;AAAA,EACb;AACA,SAAO;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const getDeepElementFromPoint = (x, y) => {
|
|
2
|
+
let target = document.elementFromPoint(x, y);
|
|
3
|
+
while (target == null ? void 0 : target.shadowRoot) {
|
|
4
|
+
const innerTarget = target.shadowRoot.elementFromPoint(x, y);
|
|
5
|
+
if (!innerTarget || innerTarget === target) {
|
|
6
|
+
break;
|
|
7
|
+
}
|
|
8
|
+
target = innerTarget;
|
|
9
|
+
}
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=get-deep-element-from-point.js.map
|