@patternfly/pfe-core 2.4.0 → 3.0.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 +0 -1
- package/controllers/cascade-controller.d.ts +6 -0
- package/controllers/cascade-controller.js +5 -3
- package/controllers/cascade-controller.js.map +1 -1
- package/controllers/floating-dom-controller.d.ts +2 -2
- package/controllers/floating-dom-controller.js +84 -81
- package/controllers/floating-dom-controller.js.map +1 -1
- package/controllers/internals-controller.d.ts +86 -41
- package/controllers/internals-controller.js +322 -36
- package/controllers/internals-controller.js.map +1 -1
- package/controllers/light-dom-controller.js.map +1 -1
- package/controllers/listbox-controller.d.ts +58 -0
- package/controllers/listbox-controller.js +250 -0
- package/controllers/listbox-controller.js.map +1 -0
- package/controllers/logger.d.ts +27 -3
- package/controllers/logger.js +50 -9
- package/controllers/logger.js.map +1 -1
- package/controllers/overflow-controller.d.ts +10 -3
- package/controllers/overflow-controller.js +75 -44
- package/controllers/overflow-controller.js.map +1 -1
- package/controllers/perf-controller.js.map +1 -1
- package/controllers/property-observer-controller.js +2 -3
- package/controllers/property-observer-controller.js.map +1 -1
- package/controllers/roving-tabindex-controller.d.ts +42 -24
- package/controllers/roving-tabindex-controller.js +167 -140
- package/controllers/roving-tabindex-controller.js.map +1 -1
- package/controllers/scroll-spy-controller.js +91 -93
- package/controllers/scroll-spy-controller.js.map +1 -1
- package/controllers/slot-controller.d.ts +18 -20
- package/controllers/slot-controller.js +89 -91
- package/controllers/slot-controller.js.map +1 -1
- package/controllers/style-controller.js.map +1 -1
- package/controllers/tabs-aria-controller.d.ts +29 -0
- package/controllers/tabs-aria-controller.js +95 -0
- package/controllers/tabs-aria-controller.js.map +1 -0
- package/controllers/timestamp-controller.js +68 -70
- package/controllers/timestamp-controller.js.map +1 -1
- package/core.d.ts +3 -0
- package/core.js.map +1 -1
- package/custom-elements.json +3245 -1317
- package/decorators/bound.js.map +1 -1
- package/decorators/cascades.d.ts +1 -0
- package/decorators/cascades.js +1 -0
- package/decorators/cascades.js.map +1 -1
- package/decorators/deprecation.js.map +1 -1
- package/decorators/initializer.js.map +1 -1
- package/decorators/observed.js.map +1 -1
- package/decorators/time.js.map +1 -1
- package/decorators/trace.js.map +1 -1
- package/functions/containsDeep.d.ts +6 -0
- package/functions/containsDeep.js +21 -0
- package/functions/containsDeep.js.map +1 -0
- package/functions/context.d.ts +9 -0
- package/functions/context.js +17 -0
- package/functions/context.js.map +1 -0
- package/functions/debounce.js.map +1 -1
- package/functions/isElementInView.js.map +1 -1
- package/package.json +7 -4
- package/functions/deprecatedCustomEvent.d.ts +0 -5
- package/functions/deprecatedCustomEvent.js +0 -12
- package/functions/deprecatedCustomEvent.js.map +0 -1
|
@@ -1,80 +1,111 @@
|
|
|
1
|
+
var _OverflowController_instances, _a, _OverflowController_instances_1, _OverflowController_container, _OverflowController_items, _OverflowController_scrollTimeoutDelay, _OverflowController_scrollTimeout, _OverflowController_hideOverflowButtons, _OverflowController_mo, _OverflowController_ro, _OverflowController_setOverflowState;
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
1
3
|
import { isElementInView } from '@patternfly/pfe-core/functions/isElementInView.js';
|
|
2
4
|
export class OverflowController {
|
|
3
|
-
/** Overflow container */
|
|
4
|
-
#container;
|
|
5
|
-
/** Children that can overflow */
|
|
6
|
-
#items;
|
|
7
|
-
#scrollTimeoutDelay;
|
|
8
|
-
#scrollTimeout;
|
|
9
|
-
/** Default state */
|
|
10
|
-
#hideOverflowButtons;
|
|
11
5
|
get firstItem() {
|
|
12
|
-
return this
|
|
6
|
+
return __classPrivateFieldGet(this, _OverflowController_items, "f").at(0);
|
|
13
7
|
}
|
|
14
8
|
get lastItem() {
|
|
15
|
-
return this
|
|
9
|
+
return __classPrivateFieldGet(this, _OverflowController_items, "f").at(-1);
|
|
16
10
|
}
|
|
17
|
-
constructor(
|
|
11
|
+
constructor(
|
|
12
|
+
// TODO: widen this type to ReactiveControllerHost
|
|
13
|
+
host, options) {
|
|
14
|
+
_OverflowController_instances.add(this);
|
|
18
15
|
this.host = host;
|
|
19
16
|
this.options = options;
|
|
17
|
+
/** Overflow container */
|
|
18
|
+
_OverflowController_container.set(this, void 0);
|
|
20
19
|
/** Children that can overflow */
|
|
21
|
-
this
|
|
22
|
-
this
|
|
20
|
+
_OverflowController_items.set(this, []);
|
|
21
|
+
_OverflowController_scrollTimeoutDelay.set(this, void 0);
|
|
22
|
+
_OverflowController_scrollTimeout.set(this, void 0);
|
|
23
23
|
/** Default state */
|
|
24
|
-
this
|
|
24
|
+
_OverflowController_hideOverflowButtons.set(this, void 0);
|
|
25
|
+
_OverflowController_mo.set(this, new MutationObserver(mutations => {
|
|
26
|
+
for (const mutation of mutations) {
|
|
27
|
+
if (mutation.type === 'childList') {
|
|
28
|
+
__classPrivateFieldGet(this, _OverflowController_instances, "m", _OverflowController_setOverflowState).call(this);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
_OverflowController_ro.set(this, new ResizeObserver(() => {
|
|
33
|
+
__classPrivateFieldGet(this, _OverflowController_instances, "m", _OverflowController_setOverflowState).call(this);
|
|
34
|
+
}));
|
|
25
35
|
this.showScrollButtons = false;
|
|
26
36
|
this.overflowLeft = false;
|
|
27
37
|
this.overflowRight = false;
|
|
28
38
|
this.onScroll = () => {
|
|
29
|
-
clearTimeout(this
|
|
30
|
-
this
|
|
39
|
+
clearTimeout(__classPrivateFieldGet(this, _OverflowController_scrollTimeout, "f"));
|
|
40
|
+
__classPrivateFieldSet(this, _OverflowController_scrollTimeout, setTimeout(() => __classPrivateFieldGet(this, _OverflowController_instances, "m", _OverflowController_setOverflowState).call(this), __classPrivateFieldGet(this, _OverflowController_scrollTimeoutDelay, "f")), "f");
|
|
31
41
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
__classPrivateFieldSet(this, _OverflowController_hideOverflowButtons, options?.hideOverflowButtons ?? false, "f");
|
|
43
|
+
__classPrivateFieldSet(this, _OverflowController_scrollTimeoutDelay, options?.scrollTimeoutDelay ?? 0, "f");
|
|
44
|
+
if (host.isConnected) {
|
|
45
|
+
__classPrivateFieldGet(_a, _a, "f", _OverflowController_instances_1).add(this);
|
|
35
46
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
this.overflowLeft = !this.#hideOverflowButtons && !isElementInView(this.#container, this.firstItem);
|
|
42
|
-
this.overflowRight = !this.#hideOverflowButtons && !isElementInView(this.#container, this.lastItem);
|
|
43
|
-
let scrollButtonsWidth = 0;
|
|
44
|
-
if (this.overflowLeft || this.overflowRight) {
|
|
45
|
-
scrollButtonsWidth = (this.#container.parentElement?.querySelector('button')?.getBoundingClientRect().width || 0) * 2;
|
|
47
|
+
host.addController(this);
|
|
48
|
+
if (host.isConnected) {
|
|
49
|
+
this.hostConnected();
|
|
46
50
|
}
|
|
47
|
-
this.showScrollButtons = !this.#hideOverflowButtons &&
|
|
48
|
-
this.#container.scrollWidth > (this.#container.clientWidth + scrollButtonsWidth);
|
|
49
|
-
this.host.requestUpdate();
|
|
50
51
|
}
|
|
51
52
|
init(container, items) {
|
|
52
|
-
this
|
|
53
|
+
__classPrivateFieldSet(this, _OverflowController_container, container, "f");
|
|
53
54
|
// convert HTMLCollection to HTMLElement[]
|
|
54
|
-
this
|
|
55
|
+
__classPrivateFieldSet(this, _OverflowController_items, items, "f");
|
|
55
56
|
}
|
|
56
57
|
scrollLeft() {
|
|
57
|
-
if (!this
|
|
58
|
+
if (!__classPrivateFieldGet(this, _OverflowController_container, "f")) {
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
60
|
-
const leftScroll = this
|
|
61
|
-
this
|
|
62
|
-
this
|
|
61
|
+
const leftScroll = __classPrivateFieldGet(this, _OverflowController_container, "f").scrollLeft - __classPrivateFieldGet(this, _OverflowController_container, "f").clientWidth;
|
|
62
|
+
__classPrivateFieldGet(this, _OverflowController_container, "f").scroll({ left: leftScroll, behavior: 'smooth' });
|
|
63
|
+
__classPrivateFieldGet(this, _OverflowController_instances, "m", _OverflowController_setOverflowState).call(this);
|
|
63
64
|
}
|
|
64
65
|
scrollRight() {
|
|
65
|
-
if (!this
|
|
66
|
+
if (!__classPrivateFieldGet(this, _OverflowController_container, "f")) {
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
68
|
-
const leftScroll = this
|
|
69
|
-
this
|
|
70
|
-
this
|
|
69
|
+
const leftScroll = __classPrivateFieldGet(this, _OverflowController_container, "f").scrollLeft + __classPrivateFieldGet(this, _OverflowController_container, "f").clientWidth;
|
|
70
|
+
__classPrivateFieldGet(this, _OverflowController_container, "f").scroll({ left: leftScroll, behavior: 'smooth' });
|
|
71
|
+
__classPrivateFieldGet(this, _OverflowController_instances, "m", _OverflowController_setOverflowState).call(this);
|
|
71
72
|
}
|
|
72
73
|
update() {
|
|
73
|
-
this
|
|
74
|
+
__classPrivateFieldGet(this, _OverflowController_instances, "m", _OverflowController_setOverflowState).call(this);
|
|
74
75
|
}
|
|
75
76
|
hostConnected() {
|
|
77
|
+
__classPrivateFieldGet(this, _OverflowController_mo, "f").observe(this.host, { attributes: false, childList: true, subtree: true });
|
|
78
|
+
__classPrivateFieldGet(this, _OverflowController_ro, "f").observe(this.host);
|
|
76
79
|
this.onScroll();
|
|
77
|
-
this
|
|
80
|
+
__classPrivateFieldGet(this, _OverflowController_instances, "m", _OverflowController_setOverflowState).call(this);
|
|
78
81
|
}
|
|
79
82
|
}
|
|
83
|
+
_a = OverflowController, _OverflowController_container = new WeakMap(), _OverflowController_items = new WeakMap(), _OverflowController_scrollTimeoutDelay = new WeakMap(), _OverflowController_scrollTimeout = new WeakMap(), _OverflowController_hideOverflowButtons = new WeakMap(), _OverflowController_mo = new WeakMap(), _OverflowController_ro = new WeakMap(), _OverflowController_instances = new WeakSet(), _OverflowController_setOverflowState = function _OverflowController_setOverflowState() {
|
|
84
|
+
if (!this.firstItem || !this.lastItem || !__classPrivateFieldGet(this, _OverflowController_container, "f")) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const prevLeft = this.overflowLeft;
|
|
88
|
+
const prevRight = this.overflowRight;
|
|
89
|
+
this.overflowLeft = !__classPrivateFieldGet(this, _OverflowController_hideOverflowButtons, "f") && !isElementInView(__classPrivateFieldGet(this, _OverflowController_container, "f"), this.firstItem);
|
|
90
|
+
this.overflowRight = !__classPrivateFieldGet(this, _OverflowController_hideOverflowButtons, "f") && !isElementInView(__classPrivateFieldGet(this, _OverflowController_container, "f"), this.lastItem);
|
|
91
|
+
let scrollButtonsWidth = 0;
|
|
92
|
+
if (this.overflowLeft || this.overflowRight) {
|
|
93
|
+
scrollButtonsWidth = (__classPrivateFieldGet(this, _OverflowController_container, "f").parentElement?.querySelector('button')?.getBoundingClientRect().width || 0) * 2;
|
|
94
|
+
}
|
|
95
|
+
this.showScrollButtons = !__classPrivateFieldGet(this, _OverflowController_hideOverflowButtons, "f") &&
|
|
96
|
+
__classPrivateFieldGet(this, _OverflowController_container, "f").scrollWidth > (__classPrivateFieldGet(this, _OverflowController_container, "f").clientWidth + scrollButtonsWidth);
|
|
97
|
+
// only request update if there has been a change
|
|
98
|
+
if ((prevLeft !== this.overflowLeft) || (prevRight !== this.overflowRight)) {
|
|
99
|
+
this.host.requestUpdate();
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
_OverflowController_instances_1 = { value: new Set() };
|
|
103
|
+
(() => {
|
|
104
|
+
// on resize check for overflows to add or remove scroll buttons
|
|
105
|
+
window.addEventListener('resize', () => {
|
|
106
|
+
for (const instance of __classPrivateFieldGet(_a, _a, "f", _OverflowController_instances_1)) {
|
|
107
|
+
instance.onScroll();
|
|
108
|
+
}
|
|
109
|
+
}, { capture: false, passive: true });
|
|
110
|
+
})();
|
|
80
111
|
//# sourceMappingURL=overflow-controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overflow-controller.js","sourceRoot":"","sources":["overflow-controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,mDAAmD,CAAC;
|
|
1
|
+
{"version":3,"file":"overflow-controller.js","sourceRoot":"","sources":["overflow-controller.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,mDAAmD,CAAC;AAapF,MAAM,OAAO,kBAAkB;IAuC7B,IAAI,SAAS;QACX,OAAO,uBAAA,IAAI,iCAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,uBAAA,IAAI,iCAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAED;IACE,kDAAkD;IAC3C,IAAqB,EACpB,OAAiB;;QADlB,SAAI,GAAJ,IAAI,CAAiB;QACpB,YAAO,GAAP,OAAO,CAAU;QAtC3B,yBAAyB;QACzB,gDAAyB;QACzB,iCAAiC;QACjC,oCAAwB,EAAE,EAAC;QAE3B,yDAA4B;QAC5B,oDAA+C;QAE/C,oBAAoB;QACpB,0DAA8B;QAE9B,iCAAM,IAAI,gBAAgB,CAAC,SAAS,CAAC,EAAE;YACrC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBACjC,IAAI,QAAQ,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;oBAClC,uBAAA,IAAI,2EAAkB,MAAtB,IAAI,CAAoB,CAAC;gBAC3B,CAAC;YACH,CAAC;QACH,CAAC,CAAC,EAAC;QAEH,iCAAM,IAAI,cAAc,CAAC,GAAG,EAAE;YAC5B,uBAAA,IAAI,2EAAkB,MAAtB,IAAI,CAAoB,CAAC;QAC3B,CAAC,CAAC,EAAC;QAEH,sBAAiB,GAAG,KAAK,CAAC;QAC1B,iBAAY,GAAG,KAAK,CAAC;QACrB,kBAAa,GAAG,KAAK,CAAC;QAsDtB,aAAQ,GAAG,GAAG,EAAE;YACd,YAAY,CAAC,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AG,CAAC,CAAC;IAC3B,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;QAC5C,kBAAkB,GAAG,CAAC,uBAAA,IAAI,qCAAW,CAAC,aAAa,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,qBAAqB,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACxH,CAAC;IACD,IAAI,CAAC,iBAAiB,GAAG,CAAC,uBAAA,IAAI,+CAAqB;QACnD,uBAAA,IAAI,qCAAW,CAAC,WAAW,GAAG,CAAC,uBAAA,IAAI,qCAAW,CAAC,WAAW,GAAG,kBAAkB,CAAC,CAAC;IAEjF,iDAAiD;IACjD,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;QAC3E,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAC5B,CAAC;AACH,CAAC;AAlFM,2CAAa,IAAI,GAAG,EAAsB,EAAhC,CAAiC;AAElD;IACE,gEAAgE;IAChE,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE;QACrC,KAAK,MAAM,QAAQ,IAAI,oEAAe,EAAE,CAAC;YACvC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACtB,CAAC;IACH,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AACxC,CAAC,GAAA,CAAA","sourcesContent":["import type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { isElementInView } from '@patternfly/pfe-core/functions/isElementInView.js';\n\nexport interface Options {\n /**\n * Force hide the scroll buttons regardless of overflow\n */\n hideOverflowButtons?: boolean;\n /**\n * Delay in ms to wait before checking for overflow\n */\n scrollTimeoutDelay?: number;\n}\n\nexport class OverflowController implements ReactiveController {\n static #instances = new Set<OverflowController>();\n\n static {\n // on resize check for overflows to add or remove scroll buttons\n window.addEventListener('resize', () => {\n for (const instance of this.#instances) {\n instance.onScroll();\n }\n }, { capture: false, passive: true });\n }\n\n /** Overflow container */\n #container?: HTMLElement;\n /** Children that can overflow */\n #items: HTMLElement[] = [];\n\n #scrollTimeoutDelay: number;\n #scrollTimeout?: ReturnType<typeof setTimeout>;\n\n /** Default state */\n #hideOverflowButtons: boolean;\n\n #mo = new MutationObserver(mutations => {\n for (const mutation of mutations) {\n if (mutation.type === 'childList') {\n this.#setOverflowState();\n }\n }\n });\n\n #ro = new ResizeObserver(() => {\n this.#setOverflowState();\n });\n\n showScrollButtons = false;\n overflowLeft = false;\n overflowRight = false;\n\n get firstItem(): HTMLElement | undefined {\n return this.#items.at(0);\n }\n\n get lastItem(): HTMLElement | undefined {\n return this.#items.at(-1);\n }\n\n constructor(\n // TODO: widen this type to ReactiveControllerHost\n public host: ReactiveElement,\n private options?: Options,\n ) {\n this.#hideOverflowButtons = options?.hideOverflowButtons ?? false;\n this.#scrollTimeoutDelay = options?.scrollTimeoutDelay ?? 0;\n if (host.isConnected) {\n OverflowController.#instances.add(this);\n }\n host.addController(this);\n if (host.isConnected) {\n this.hostConnected();\n }\n }\n\n #setOverflowState(): void {\n if (!this.firstItem || !this.lastItem || !this.#container) {\n return;\n }\n const prevLeft = this.overflowLeft;\n const prevRight = this.overflowRight;\n\n this.overflowLeft = !this.#hideOverflowButtons && !isElementInView(this.#container, this.firstItem);\n this.overflowRight = !this.#hideOverflowButtons && !isElementInView(this.#container, this.lastItem);\n let scrollButtonsWidth = 0;\n if (this.overflowLeft || this.overflowRight) {\n scrollButtonsWidth = (this.#container.parentElement?.querySelector('button')?.getBoundingClientRect().width || 0) * 2;\n }\n this.showScrollButtons = !this.#hideOverflowButtons &&\n this.#container.scrollWidth > (this.#container.clientWidth + scrollButtonsWidth);\n\n // only request update if there has been a change\n if ((prevLeft !== this.overflowLeft) || (prevRight !== this.overflowRight)) {\n this.host.requestUpdate();\n }\n }\n\n init(container: HTMLElement, items: HTMLElement[]) {\n this.#container = container;\n // convert HTMLCollection to HTMLElement[]\n this.#items = items;\n }\n\n onScroll = () => {\n clearTimeout(this.#scrollTimeout);\n this.#scrollTimeout = setTimeout(() => this.#setOverflowState(), this.#scrollTimeoutDelay);\n };\n\n scrollLeft() {\n if (!this.#container) {\n return;\n }\n const leftScroll = this.#container.scrollLeft - this.#container.clientWidth;\n this.#container.scroll({ left: leftScroll, behavior: 'smooth' });\n this.#setOverflowState();\n }\n\n scrollRight() {\n if (!this.#container) {\n return;\n }\n const leftScroll = this.#container.scrollLeft + this.#container.clientWidth;\n this.#container.scroll({ left: leftScroll, behavior: 'smooth' });\n this.#setOverflowState();\n }\n\n update() {\n this.#setOverflowState();\n }\n\n hostConnected(): void {\n this.#mo.observe(this.host, { attributes: false, childList: true, subtree: true });\n this.#ro.observe(this.host);\n this.onScroll();\n this.#setOverflowState();\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perf-controller.js","sourceRoot":"","sources":["perf-controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,MAAM,OAAO,cAAc;IAKzB,YAAoB,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;QAJzC,gBAAW,GAAG,KAAK,CAAC;QAKlB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAEzB,oEAAoE;QACpE,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"perf-controller.js","sourceRoot":"","sources":["perf-controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,MAAM,OAAO,cAAc;IAKzB,YAAoB,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;QAJzC,gBAAW,GAAG,KAAK,CAAC;QAKlB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAEzB,oE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,CAAC;IACnC,CAAC;CACF","sourcesContent":["import type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { getRandomId } from '../functions/random.js';\n\nexport class PerfController implements ReactiveController {\n hasMeasured = false;\n\n markId: string;\n\n constructor(private host: ReactiveElement) {\n host.addController(this);\n\n // Set up the mark ID based on existing ID on component if it exists\n if (!host.id) {\n this.markId = getRandomId(host.localName);\n } else if (host.id.startsWith('pf-') && !host.id.startsWith(host.localName)) {\n this.markId = host.id.replace('pf', host.localName);\n } else {\n this.markId = `${host.localName}-${host.id}`;\n }\n\n performance.mark(`${this.markId}-defined`);\n }\n\n hostUpdate() {\n if (!this.hasMeasured) {\n this.measure();\n }\n }\n\n measure() {\n this.hasMeasured = true;\n\n performance.mark(`${this.markId}-rendered`);\n\n // Navigation start, i.e., the browser first sees that the user has navigated to the page\n performance.measure(`${this.markId}-from-navigation-to-first-render`, undefined, `${this.markId}-rendered`);\n\n // Render is run before connection unless delayRender is used\n performance.measure(\n `${this.markId}-from-defined-to-first-render`,\n `${this.markId}-defined`,\n `${this.markId}-rendered`\n );\n\n // Once we've measured time to render, we no longer need the controller,\n // so we allow it to be garbage-collected\n this.host.removeController(this);\n }\n}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export const observedController = Symbol('observed properties controller');
|
|
2
2
|
/** This controller holds a cache of observed property values which were set before the element updated */
|
|
3
|
-
class PropertyObserverController {
|
|
4
|
-
static { this.hosts = new WeakMap(); }
|
|
3
|
+
export class PropertyObserverController {
|
|
5
4
|
delete(key) {
|
|
6
5
|
this.values.delete(key);
|
|
7
6
|
}
|
|
@@ -30,5 +29,5 @@ class PropertyObserverController {
|
|
|
30
29
|
this.values.set(key, [methodName, vals]);
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
|
-
|
|
32
|
+
PropertyObserverController.hosts = new WeakMap();
|
|
34
33
|
//# sourceMappingURL=property-observer-controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"property-observer-controller.js","sourceRoot":"","sources":["property-observer-controller.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,gCAAgC,CAAC,CAAC;AAc3E,0GAA0G;AAC1G,
|
|
1
|
+
{"version":3,"file":"property-observer-controller.js","sourceRoot":"","sources":["property-observer-controller.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,gCAAgC,CAAC,CAAC;AAc3E,0GAA0G;AAC1G,MAAM,OAAO,0BAA0B;IAK7B,MAAM,CAAC,GAAW;QACxB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED,YAAoB,IAAqB;QAArB,SAAI,GAAJ,IAAI,CAAiB;QANjC,WAAM,GAAG,IAAI,GAAG,EAA4D,CAAC;QAOnF,IAAI,0BAA0B,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/C,OAAO,0BAA0B,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAA+B,CAAC;QAClF,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QACxB,IAA8C,CAAC,kBAAkB,CAAC,GAAG,IAAI,CAAC;IAC7E,CAAC;IAED,kFAAkF;IAClF,UAAU;QACR,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChE,wCAAwC;YACxC,IAAI,CAAC,IAAI,CAAC,UAAmC,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YACjE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IAED,uFAAuF;IACvF,WAAW;QACT,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,GAAW,EAAE,UAAkB,EAAE,GAAG,IAAwB;QAChE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;IAC3C,CAAC;;AAhCc,gCAAK,GAAqD,IAAI,OAAO,EAAE,AAAlE,CAAmE","sourcesContent":["import type { ReactiveController, ReactiveElement } from 'lit';\n\nexport const observedController = Symbol('observed properties controller');\n\nexport type ChangeCallback<T = ReactiveElement> = (\n this: T,\n old?: T[keyof T],\n newV?: T[keyof T],\n) => void;\n\nexport type ChangeCallbackName = `_${string}Changed`;\n\nexport type PropertyObserverHost<T> = T & Record<ChangeCallbackName, ChangeCallback<T>> & {\n [observedController]: PropertyObserverController;\n}\n\n/** This controller holds a cache of observed property values which were set before the element updated */\nexport class PropertyObserverController implements ReactiveController {\n private static hosts: WeakMap<HTMLElement, PropertyObserverController> = new WeakMap();\n\n private values = new Map<string, [methodName: string, values: [unknown, unknown]]>();\n\n private delete(key: string) {\n this.values.delete(key);\n }\n\n constructor(private host: ReactiveElement) {\n if (PropertyObserverController.hosts.get(host)) {\n return PropertyObserverController.hosts.get(host) as PropertyObserverController;\n }\n host.addController(this);\n (host as PropertyObserverHost<ReactiveElement>)[observedController] = this;\n }\n\n /** Set any cached valued accumulated between constructor and connectedCallback */\n hostUpdate() {\n for (const [key, [methodName, [oldVal, newVal]]] of this.values) {\n // @ts-expect-error: be cool, typescript\n this.host[methodName as keyof ReactiveElement]?.(oldVal, newVal);\n this.delete(key);\n }\n }\n\n /** Once the element has updated, we no longer need this controller, so we remove it */\n hostUpdated() {\n this.host.removeController(this);\n }\n\n cache(key: string, methodName: string, ...vals: [unknown, unknown]) {\n this.values.set(key, [methodName, vals]);\n }\n}\n"]}
|
|
@@ -1,55 +1,73 @@
|
|
|
1
1
|
import type { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
export interface RovingTabindexControllerOptions<Item extends HTMLElement> {
|
|
3
|
+
/** @deprecated use getHTMLElement */
|
|
4
|
+
getElement?: () => Element | null;
|
|
5
|
+
getHTMLElement?: () => HTMLElement | null;
|
|
6
|
+
getItems?: () => Item[];
|
|
7
|
+
getItemContainer?: () => HTMLElement;
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
10
|
* Implements roving tabindex, as described in WAI-ARIA practices, [Managing Focus Within
|
|
4
|
-
* Components Using a Roving
|
|
5
|
-
*
|
|
11
|
+
* Components Using a Roving tabindex][rti]
|
|
12
|
+
*
|
|
13
|
+
* [rti]: https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_roving_tabindex
|
|
6
14
|
*/
|
|
7
|
-
export declare class RovingTabindexController<
|
|
15
|
+
export declare class RovingTabindexController<Item extends HTMLElement = HTMLElement> implements ReactiveController {
|
|
8
16
|
#private;
|
|
9
|
-
host: ReactiveControllerHost
|
|
17
|
+
host: ReactiveControllerHost;
|
|
18
|
+
private static hosts;
|
|
19
|
+
static of<Item extends HTMLElement>(host: ReactiveControllerHost, options: RovingTabindexControllerOptions<Item> & {
|
|
20
|
+
getItems(): Item[];
|
|
21
|
+
}): RovingTabindexController<Item>;
|
|
22
|
+
/** @internal */
|
|
23
|
+
static elements: WeakMap<Element, RovingTabindexController<HTMLElement>>;
|
|
10
24
|
/**
|
|
11
25
|
* active item of array of items
|
|
12
26
|
*/
|
|
13
|
-
get activeItem():
|
|
27
|
+
get activeItem(): Item | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* all items from array
|
|
30
|
+
*/
|
|
31
|
+
get items(): Item[];
|
|
32
|
+
/**
|
|
33
|
+
* all focusable items from array
|
|
34
|
+
*/
|
|
35
|
+
get focusableItems(): Item[];
|
|
14
36
|
/**
|
|
15
37
|
* first item in array of focusable items
|
|
16
38
|
*/
|
|
17
|
-
get firstItem():
|
|
39
|
+
get firstItem(): Item | undefined;
|
|
18
40
|
/**
|
|
19
41
|
* last item in array of focusable items
|
|
20
42
|
*/
|
|
21
|
-
get lastItem():
|
|
43
|
+
get lastItem(): Item | undefined;
|
|
22
44
|
/**
|
|
23
45
|
* next item after active item in array of focusable items
|
|
24
46
|
*/
|
|
25
|
-
get nextItem():
|
|
47
|
+
get nextItem(): Item | undefined;
|
|
26
48
|
/**
|
|
27
49
|
* previous item after active item in array of focusable items
|
|
28
50
|
*/
|
|
29
|
-
get prevItem():
|
|
30
|
-
constructor(host: ReactiveControllerHost
|
|
51
|
+
get prevItem(): Item | undefined;
|
|
52
|
+
constructor(host: ReactiveControllerHost, options?: RovingTabindexControllerOptions<Item>);
|
|
53
|
+
hostUpdated(): void;
|
|
31
54
|
/**
|
|
32
|
-
*
|
|
55
|
+
* removes event listeners from items container
|
|
33
56
|
*/
|
|
34
|
-
|
|
57
|
+
hostDisconnected(): void;
|
|
35
58
|
/**
|
|
36
|
-
*
|
|
59
|
+
* Sets the active item and focuses it
|
|
37
60
|
*/
|
|
38
|
-
|
|
61
|
+
setActiveItem(item?: Item): void;
|
|
39
62
|
/**
|
|
40
63
|
* Focuses next focusable item
|
|
41
64
|
*/
|
|
42
|
-
updateItems(items
|
|
65
|
+
updateItems(items?: Item[]): void;
|
|
66
|
+
/** @deprecated use setActiveItem */
|
|
67
|
+
focusOnItem(item?: Item): void;
|
|
43
68
|
/**
|
|
44
69
|
* from array of HTML items, and sets active items
|
|
70
|
+
* @deprecated: use getItems and getItemContainer option functions
|
|
45
71
|
*/
|
|
46
|
-
initItems(items:
|
|
47
|
-
/**
|
|
48
|
-
* adds event listeners to items container
|
|
49
|
-
*/
|
|
50
|
-
hostConnected(): void;
|
|
51
|
-
/**
|
|
52
|
-
* removes event listeners from items container
|
|
53
|
-
*/
|
|
54
|
-
hostDisconnected(): void;
|
|
72
|
+
initItems(items: Item[], itemsContainer?: Element): void;
|
|
55
73
|
}
|