@patternfly/pfe-core 2.4.1 → 4.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/activedescendant-controller.d.ts +99 -0
- package/controllers/activedescendant-controller.js +230 -0
- package/controllers/activedescendant-controller.js.map +1 -0
- package/controllers/at-focus-controller.d.ts +56 -0
- package/controllers/at-focus-controller.js +168 -0
- package/controllers/at-focus-controller.js.map +1 -0
- package/controllers/cascade-controller.d.ts +11 -0
- package/controllers/cascade-controller.js +10 -3
- package/controllers/cascade-controller.js.map +1 -1
- package/controllers/combobox-controller.d.ts +117 -0
- package/controllers/combobox-controller.js +611 -0
- package/controllers/combobox-controller.js.map +1 -0
- package/controllers/css-variable-controller.js +1 -1
- package/controllers/css-variable-controller.js.map +1 -1
- package/controllers/floating-dom-controller.d.ts +10 -3
- package/controllers/floating-dom-controller.js +93 -83
- package/controllers/floating-dom-controller.js.map +1 -1
- package/controllers/internals-controller.d.ts +104 -42
- package/controllers/internals-controller.js +354 -36
- package/controllers/internals-controller.js.map +1 -1
- package/controllers/light-dom-controller.js +2 -2
- package/controllers/light-dom-controller.js.map +1 -1
- package/controllers/listbox-controller.d.ts +143 -0
- package/controllers/listbox-controller.js +443 -0
- package/controllers/listbox-controller.js.map +1 -0
- package/controllers/logger.d.ts +33 -6
- package/controllers/logger.js +58 -13
- package/controllers/logger.js.map +1 -1
- package/controllers/overflow-controller.d.ts +10 -3
- package/controllers/overflow-controller.js +79 -44
- package/controllers/overflow-controller.js.map +1 -1
- package/controllers/perf-controller.js.map +1 -1
- package/controllers/property-observer-controller.d.ts +13 -16
- package/controllers/property-observer-controller.js +55 -27
- package/controllers/property-observer-controller.js.map +1 -1
- package/controllers/roving-tabindex-controller.d.ts +19 -50
- package/controllers/roving-tabindex-controller.js +64 -183
- package/controllers/roving-tabindex-controller.js.map +1 -1
- package/controllers/scroll-spy-controller.d.ts +4 -1
- package/controllers/scroll-spy-controller.js +94 -93
- package/controllers/scroll-spy-controller.js.map +1 -1
- package/controllers/slot-controller.d.ts +26 -19
- package/controllers/slot-controller.js +94 -83
- package/controllers/slot-controller.js.map +1 -1
- package/controllers/style-controller.js +3 -1
- package/controllers/style-controller.js.map +1 -1
- package/controllers/tabs-aria-controller.d.ts +31 -0
- package/controllers/tabs-aria-controller.js +97 -0
- package/controllers/tabs-aria-controller.js.map +1 -0
- package/controllers/test/combobox-controller.spec.d.ts +1 -0
- package/controllers/test/combobox-controller.spec.js +282 -0
- package/controllers/test/combobox-controller.spec.js.map +1 -0
- package/controllers/timestamp-controller.js +73 -70
- package/controllers/timestamp-controller.js.map +1 -1
- package/core.d.ts +3 -23
- package/core.js +1 -38
- package/core.js.map +1 -1
- package/custom-elements.json +7302 -2817
- package/decorators/bound.d.ts +3 -1
- package/decorators/bound.js +3 -1
- package/decorators/bound.js.map +1 -1
- package/decorators/cascades.d.ts +2 -0
- package/decorators/cascades.js +2 -0
- package/decorators/cascades.js.map +1 -1
- package/decorators/deprecation.d.ts +6 -5
- package/decorators/deprecation.js +6 -5
- package/decorators/deprecation.js.map +1 -1
- package/decorators/initializer.js.map +1 -1
- package/decorators/listen.d.ts +8 -0
- package/decorators/listen.js +22 -0
- package/decorators/listen.js.map +1 -0
- package/decorators/observed.d.ts +12 -16
- package/decorators/observed.js +39 -44
- package/decorators/observed.js.map +1 -1
- package/decorators/observes.d.ts +15 -0
- package/decorators/observes.js +30 -0
- package/decorators/observes.js.map +1 -0
- package/decorators/time.d.ts +1 -0
- package/decorators/time.js +6 -9
- package/decorators/time.js.map +1 -1
- package/decorators/trace.d.ts +4 -1
- package/decorators/trace.js +4 -1
- package/decorators/trace.js.map +1 -1
- package/decorators.d.ts +2 -0
- package/decorators.js +2 -0
- package/decorators.js.map +1 -1
- package/functions/arraysAreEquivalent.d.ts +9 -0
- package/functions/arraysAreEquivalent.js +28 -0
- package/functions/arraysAreEquivalent.js.map +1 -0
- package/functions/containsDeep.d.ts +8 -0
- package/functions/containsDeep.js +23 -0
- package/functions/containsDeep.js.map +1 -0
- package/functions/context.d.ts +8 -0
- package/functions/context.js +21 -0
- package/functions/context.js.map +1 -0
- package/functions/debounce.js.map +1 -1
- package/functions/isElementInView.d.ts +4 -6
- package/functions/isElementInView.js +9 -11
- package/functions/isElementInView.js.map +1 -1
- package/package.json +10 -4
- package/functions/deprecatedCustomEvent.d.ts +0 -5
- package/functions/deprecatedCustomEvent.js +0 -12
- package/functions/deprecatedCustomEvent.js.map +0 -1
package/controllers/logger.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { isServer } from 'lit';
|
|
2
|
+
export class Logger {
|
|
3
3
|
get prefix() {
|
|
4
|
-
|
|
4
|
+
if (!isServer && this.host instanceof HTMLElement) {
|
|
5
|
+
return `[${this.host.localName}${this.host.id ? `#${this.host.id}` : ''}]`;
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
return `[${this.host.constructor.name}]`;
|
|
9
|
+
}
|
|
5
10
|
}
|
|
6
11
|
/**
|
|
7
12
|
* A boolean value that indicates if the logging should be printed to the console; used for debugging.
|
|
8
13
|
* For use in a JS file or script tag; can also be added in the constructor of a component during development.
|
|
9
14
|
* @example Logger.debugLog(true);
|
|
10
|
-
* @
|
|
15
|
+
* @param [preference=null]
|
|
11
16
|
*/
|
|
12
17
|
static debugLog(preference = null) {
|
|
13
18
|
// wrap localStorage references in a try/catch; merely referencing it can
|
|
@@ -19,41 +24,79 @@ class Logger {
|
|
|
19
24
|
}
|
|
20
25
|
return localStorage.pfeLog === 'true';
|
|
21
26
|
}
|
|
22
|
-
catch
|
|
27
|
+
catch {
|
|
23
28
|
return Logger.logDebug;
|
|
24
29
|
}
|
|
25
30
|
}
|
|
31
|
+
/* eslint-disable no-console */
|
|
32
|
+
/**
|
|
33
|
+
* A logging wrapper which checks the debugLog boolean and prints to the console if true.
|
|
34
|
+
* @example Logger.debug("Hello");
|
|
35
|
+
* @param msgs console.log params
|
|
36
|
+
*/
|
|
37
|
+
static debug(...msgs) {
|
|
38
|
+
if (Logger.debugLog()) {
|
|
39
|
+
console.debug(...msgs);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A logging wrapper which checks the debugLog boolean and prints to the console if true.
|
|
44
|
+
* @example Logger.info("Hello");
|
|
45
|
+
* @param msgs console.log params
|
|
46
|
+
*/
|
|
47
|
+
static info(...msgs) {
|
|
48
|
+
if (Logger.debugLog()) {
|
|
49
|
+
console.info(...msgs);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
26
52
|
/**
|
|
27
53
|
* A logging wrapper which checks the debugLog boolean and prints to the console if true.
|
|
28
|
-
*
|
|
29
54
|
* @example Logger.log("Hello");
|
|
55
|
+
* @param msgs console.log params
|
|
30
56
|
*/
|
|
31
57
|
static log(...msgs) {
|
|
32
58
|
if (Logger.debugLog()) {
|
|
33
|
-
// eslint-disable-next-line no-console
|
|
34
59
|
console.log(...msgs);
|
|
35
60
|
}
|
|
36
61
|
}
|
|
37
62
|
/**
|
|
38
63
|
* A console warning wrapper which formats your output with useful debugging information.
|
|
39
|
-
*
|
|
40
64
|
* @example Logger.warn("Hello");
|
|
65
|
+
* @param msgs console.log params
|
|
41
66
|
*/
|
|
42
67
|
static warn(...msgs) {
|
|
43
|
-
console.warn(...msgs);
|
|
68
|
+
console.warn(...msgs);
|
|
44
69
|
}
|
|
45
70
|
/**
|
|
46
71
|
* A console error wrapper which formats your output with useful debugging information.
|
|
47
72
|
* For use inside a component's function.
|
|
48
73
|
* @example Logger.error("Hello");
|
|
74
|
+
* @param msgs console.log params
|
|
49
75
|
*/
|
|
50
76
|
static error(...msgs) {
|
|
51
|
-
console.error([...msgs].join(' '));
|
|
77
|
+
console.error([...msgs].join(' '));
|
|
78
|
+
}
|
|
79
|
+
/* eslint-enable no-console */
|
|
80
|
+
/**
|
|
81
|
+
* Debug logging that outputs the tag name as a prefix automatically
|
|
82
|
+
* @example this.logger.log("Hello");
|
|
83
|
+
* @param msgs console.log params
|
|
84
|
+
*/
|
|
85
|
+
debug(...msgs) {
|
|
86
|
+
Logger.debug(this.prefix, ...msgs);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Info logging that outputs the tag name as a prefix automatically
|
|
90
|
+
* @example this.logger.log("Hello");
|
|
91
|
+
* @param msgs console.log params
|
|
92
|
+
*/
|
|
93
|
+
info(...msgs) {
|
|
94
|
+
Logger.info(this.prefix, ...msgs);
|
|
52
95
|
}
|
|
53
96
|
/**
|
|
54
97
|
* Local logging that outputs the tag name as a prefix automatically
|
|
55
|
-
*
|
|
56
98
|
* @example this.logger.log("Hello");
|
|
99
|
+
* @param msgs console.log params
|
|
57
100
|
*/
|
|
58
101
|
log(...msgs) {
|
|
59
102
|
Logger.log(this.prefix, ...msgs);
|
|
@@ -62,6 +105,7 @@ class Logger {
|
|
|
62
105
|
* Local warning wrapper that outputs the tag name as a prefix automatically.
|
|
63
106
|
* For use inside a component's function.
|
|
64
107
|
* @example this.logger.warn("Hello");
|
|
108
|
+
* @param msgs console.log params
|
|
65
109
|
*/
|
|
66
110
|
warn(...msgs) {
|
|
67
111
|
Logger.warn(this.prefix, ...msgs);
|
|
@@ -70,6 +114,7 @@ class Logger {
|
|
|
70
114
|
* Local error wrapper that outputs the tag name as a prefix automatically.
|
|
71
115
|
* For use inside a component's function.
|
|
72
116
|
* @example this.logger.error("Hello");
|
|
117
|
+
* @param msgs console.log params
|
|
73
118
|
*/
|
|
74
119
|
error(...msgs) {
|
|
75
120
|
Logger.error(this.prefix, ...msgs);
|
|
@@ -84,8 +129,8 @@ class Logger {
|
|
|
84
129
|
Logger.instances.set(host, this);
|
|
85
130
|
}
|
|
86
131
|
hostConnected() {
|
|
87
|
-
this.
|
|
132
|
+
this.debug('connected');
|
|
88
133
|
}
|
|
89
134
|
}
|
|
90
|
-
|
|
135
|
+
Logger.instances = new WeakMap();
|
|
91
136
|
//# sourceMappingURL=logger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAwD,MAAM,KAAK,CAAC;AAErF,MAAM,OAAO,MAAM;IAKjB,IAAY,MAAM;QAChB,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,YAAY,WAAW,EAAE,CAAC;YAClD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC;QAC7E,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,GAAG,CAAC;QAC3C,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,UAAU,GAAG,IAAI;QAC/B,yEAAyE;QACzE,gDAAgD;QAChD,IAAI,CAAC;YACH,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;gBACxB,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,UAAU,CAAC;gBAC/B,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC;YACrC,CAAC;YACD,OAAO,YAAY,CAAC,MAAM,KAAK,MAAM,CAAC;QACxC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,MAAM,CAAC,QAAQ,CAAC;QACzB,CAAC;IACH,CAAC;IAED,+BAA+B;IAE/B;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,GAAG,IAAe;QAC7B,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;YACtB,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;QACzB,CA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KG;IACH,KAAK,CAAC,GAAG,IAAe;QACtB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,YAAoB,IAA4B;QAA5B,SAAI,GAAJ,IAAI,CAAwB;QAC9C,4CAA4C;QAC5C,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,OAAO,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAW,CAAC;QAC9C,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QACzB,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,aAAa;QACX,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC1B,CAAC;;AAhJc,gBAAS,GAAG,IAAI,OAAO,EAAkC,CAAC","sourcesContent":["import { isServer, type ReactiveController, type ReactiveControllerHost } from 'lit';\n\nexport class Logger implements ReactiveController {\n private static logDebug: boolean;\n\n private static instances = new WeakMap<ReactiveControllerHost, Logger>();\n\n private get prefix() {\n if (!isServer && this.host instanceof HTMLElement) {\n return `[${this.host.localName}${this.host.id ? `#${this.host.id}` : ''}]`;\n } else {\n return `[${this.host.constructor.name}]`;\n }\n }\n\n /**\n * A boolean value that indicates if the logging should be printed to the console; used for debugging.\n * For use in a JS file or script tag; can also be added in the constructor of a component during development.\n * @example Logger.debugLog(true);\n * @param [preference=null]\n */\n static debugLog(preference = null): boolean {\n // wrap localStorage references in a try/catch; merely referencing it can\n // throw errors in some locked down environments\n try {\n if (preference !== null) {\n Logger.logDebug = !!preference;\n localStorage.pfeLog = !!preference;\n }\n return localStorage.pfeLog === 'true';\n } catch {\n return Logger.logDebug;\n }\n }\n\n /* eslint-disable no-console */\n\n /**\n * A logging wrapper which checks the debugLog boolean and prints to the console if true.\n * @example Logger.debug(\"Hello\");\n * @param msgs console.log params\n */\n static debug(...msgs: unknown[]): void {\n if (Logger.debugLog()) {\n console.debug(...msgs);\n }\n }\n\n /**\n * A logging wrapper which checks the debugLog boolean and prints to the console if true.\n * @example Logger.info(\"Hello\");\n * @param msgs console.log params\n */\n static info(...msgs: unknown[]): void {\n if (Logger.debugLog()) {\n console.info(...msgs);\n }\n }\n\n /**\n * A logging wrapper which checks the debugLog boolean and prints to the console if true.\n * @example Logger.log(\"Hello\");\n * @param msgs console.log params\n */\n static log(...msgs: unknown[]): void {\n if (Logger.debugLog()) {\n console.log(...msgs);\n }\n }\n\n /**\n * A console warning wrapper which formats your output with useful debugging information.\n * @example Logger.warn(\"Hello\");\n * @param msgs console.log params\n */\n static warn(...msgs: unknown[]): void {\n console.warn(...msgs);\n }\n\n /**\n * A console error wrapper which formats your output with useful debugging information.\n * For use inside a component's function.\n * @example Logger.error(\"Hello\");\n * @param msgs console.log params\n */\n static error(...msgs: unknown[]): void {\n console.error([...msgs].join(' '));\n }\n\n /* eslint-enable no-console */\n\n /**\n * Debug logging that outputs the tag name as a prefix automatically\n * @example this.logger.log(\"Hello\");\n * @param msgs console.log params\n */\n debug(...msgs: unknown[]): void {\n Logger.debug(this.prefix, ...msgs);\n }\n\n /**\n * Info logging that outputs the tag name as a prefix automatically\n * @example this.logger.log(\"Hello\");\n * @param msgs console.log params\n */\n info(...msgs: unknown[]): void {\n Logger.info(this.prefix, ...msgs);\n }\n\n /**\n * Local logging that outputs the tag name as a prefix automatically\n * @example this.logger.log(\"Hello\");\n * @param msgs console.log params\n */\n log(...msgs: unknown[]): void {\n Logger.log(this.prefix, ...msgs);\n }\n\n /**\n * Local warning wrapper that outputs the tag name as a prefix automatically.\n * For use inside a component's function.\n * @example this.logger.warn(\"Hello\");\n * @param msgs console.log params\n */\n warn(...msgs: unknown[]): void {\n Logger.warn(this.prefix, ...msgs);\n }\n\n /**\n * Local error wrapper that outputs the tag name as a prefix automatically.\n * For use inside a component's function.\n * @example this.logger.error(\"Hello\");\n * @param msgs console.log params\n */\n error(...msgs: unknown[]): void {\n Logger.error(this.prefix, ...msgs);\n }\n\n constructor(private host: ReactiveControllerHost) {\n // We only need one logger instance per host\n if (Logger.instances.get(host)) {\n return Logger.instances.get(host) as Logger;\n }\n host.addController(this);\n Logger.instances.set(host, this);\n }\n\n hostConnected(): void {\n this.debug('connected');\n }\n}\n"]}
|
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
import type { ReactiveController,
|
|
1
|
+
import type { ReactiveController, ReactiveElement } from 'lit';
|
|
2
2
|
export interface Options {
|
|
3
|
+
/**
|
|
4
|
+
* Force hide the scroll buttons regardless of overflow
|
|
5
|
+
*/
|
|
3
6
|
hideOverflowButtons?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Delay in ms to wait before checking for overflow
|
|
9
|
+
*/
|
|
10
|
+
scrollTimeoutDelay?: number;
|
|
4
11
|
}
|
|
5
12
|
export declare class OverflowController implements ReactiveController {
|
|
6
13
|
#private;
|
|
7
|
-
host:
|
|
14
|
+
host: ReactiveElement;
|
|
8
15
|
private options?;
|
|
9
16
|
showScrollButtons: boolean;
|
|
10
17
|
overflowLeft: boolean;
|
|
11
18
|
overflowRight: boolean;
|
|
12
19
|
get firstItem(): HTMLElement | undefined;
|
|
13
20
|
get lastItem(): HTMLElement | undefined;
|
|
14
|
-
constructor(host:
|
|
21
|
+
constructor(host: ReactiveElement, options?: Options | undefined);
|
|
15
22
|
init(container: HTMLElement, items: HTMLElement[]): void;
|
|
16
23
|
onScroll: () => void;
|
|
17
24
|
scrollLeft(): void;
|
|
@@ -1,80 +1,115 @@
|
|
|
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")
|
|
90
|
+
&& !isElementInView(__classPrivateFieldGet(this, _OverflowController_container, "f"), this.firstItem);
|
|
91
|
+
this.overflowRight = !__classPrivateFieldGet(this, _OverflowController_hideOverflowButtons, "f")
|
|
92
|
+
&& !isElementInView(__classPrivateFieldGet(this, _OverflowController_container, "f"), this.lastItem);
|
|
93
|
+
let scrollButtonsWidth = 0;
|
|
94
|
+
if (this.overflowLeft || this.overflowRight) {
|
|
95
|
+
scrollButtonsWidth =
|
|
96
|
+
(__classPrivateFieldGet(this, _OverflowController_container, "f").parentElement?.querySelector('button')?.getBoundingClientRect().width || 0)
|
|
97
|
+
* 2;
|
|
98
|
+
}
|
|
99
|
+
this.showScrollButtons = !__classPrivateFieldGet(this, _OverflowController_hideOverflowButtons, "f")
|
|
100
|
+
&& __classPrivateFieldGet(this, _OverflowController_container, "f").scrollWidth > (__classPrivateFieldGet(this, _OverflowController_container, "f").clientWidth + scrollButtonsWidth);
|
|
101
|
+
// only request update if there has been a change
|
|
102
|
+
if ((prevLeft !== this.overflowLeft) || (prevRight !== this.overflowRight)) {
|
|
103
|
+
this.host.requestUpdate();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
_OverflowController_instances_1 = { value: new Set() };
|
|
107
|
+
(() => {
|
|
108
|
+
// on resize check for overflows to add or remove scroll buttons
|
|
109
|
+
globalThis.addEventListener?.('resize', () => {
|
|
110
|
+
for (const instance of __classPrivateFieldGet(_a, _a, "f", _OverflowController_instances_1)) {
|
|
111
|
+
instance.onScroll();
|
|
112
|
+
}
|
|
113
|
+
}, { capture: false, passive: true });
|
|
114
|
+
})();
|
|
80
115
|
//# 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,OAA6B;;QAD9B,SAAI,GAAJ,IAAI,CAAiB;QACpB,YAAO,GAAP,OAAO,CAAsB;QAtCvC,yBAAyB;QACzB,gDAAyB;QACzB,iCAAiC;QACjC,oCAAwB,EAAE,EAAC;QAE3B,yDAA4B;Q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AG,EAAsB,EAAhC,CAAiC;AAElD;IACE,gEAAgE;IAChE,UAAU,CAAC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QAC3C,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 globalThis.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 | undefined,\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\n && !isElementInView(this.#container, this.firstItem);\n this.overflowRight = !this.#hideOverflowButtons\n && !isElementInView(this.#container, this.lastItem);\n let scrollButtonsWidth = 0;\n if (this.overflowLeft || this.overflowRight) {\n scrollButtonsWidth =\n (this.#container.parentElement?.querySelector('button')?.getBoundingClientRect().width || 0)\n * 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[]): void {\n this.#container = container;\n // convert HTMLCollection to HTMLElement[]\n this.#items = items;\n }\n\n onScroll = (): void => {\n clearTimeout(this.#scrollTimeout);\n this.#scrollTimeout = setTimeout(() => this.#setOverflowState(), this.#scrollTimeoutDelay);\n };\n\n scrollLeft(): void {\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(): void {\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(): void {\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,oEAAoE;QACpE,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5C,CAAC;aAAM,IAAI,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAC5E,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACtD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;QAC/C,CAAC;QAED,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,UAAU,CAAC,CAAC;IAC7C,CAAC;IAED,UAAU;QACR,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAExB,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,WAAW,CAAC,CAAC;QAE5C,yFAAyF;QACzF,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,kCAAkC,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,MAAM,WAAW,CAAC,CAAC;QAE5G,6DAA6D;QAC7D,WAAW,CAAC,OAAO,CACjB,GAAG,IAAI,CAAC,MAAM,+BAA+B,EAC7C,GAAG,IAAI,CAAC,MAAM,UAAU,EACxB,GAAG,IAAI,CAAC,MAAM,WAAW,CAC1B,CAAC;QAEF,wEAAwE;QACxE,yCAAyC;QACzC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,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(): void {\n if (!this.hasMeasured) {\n this.measure();\n }\n }\n\n measure(): void {\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,20 +1,17 @@
|
|
|
1
1
|
import type { ReactiveController, ReactiveElement } from 'lit';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
export type ChangeCallback<T extends ReactiveElement, V = T[keyof T]> = (this: T, old?: V, newV?: V) => void;
|
|
3
|
+
export interface PropertyObserverOptions<T extends ReactiveElement> {
|
|
4
|
+
propertyName: string & keyof T;
|
|
5
|
+
callback: ChangeCallback<T>;
|
|
6
|
+
waitFor?: 'connected' | 'updated' | 'firstUpdated';
|
|
7
|
+
}
|
|
8
|
+
export declare class PropertyObserverController<T extends ReactiveElement> implements ReactiveController {
|
|
9
|
+
#private;
|
|
10
10
|
private host;
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
private options;
|
|
12
|
+
private oldVal;
|
|
13
|
+
constructor(host: T, options: PropertyObserverOptions<T>);
|
|
14
|
+
hostConnected(): void;
|
|
15
15
|
/** Set any cached valued accumulated between constructor and connectedCallback */
|
|
16
|
-
hostUpdate(): void
|
|
17
|
-
/** Once the element has updated, we no longer need this controller, so we remove it */
|
|
18
|
-
hostUpdated(): void;
|
|
19
|
-
cache(key: string, methodName: string, ...vals: [unknown, unknown]): void;
|
|
16
|
+
hostUpdate(): Promise<void>;
|
|
20
17
|
}
|
|
@@ -1,34 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
constructor(host) {
|
|
1
|
+
var _PropertyObserverController_instances, _PropertyObserverController_neverRan, _PropertyObserverController_init;
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import { notEqual } from 'lit';
|
|
4
|
+
const UNINITIALIZED = Symbol('uninitialized');
|
|
5
|
+
export class PropertyObserverController {
|
|
6
|
+
constructor(host, options) {
|
|
7
|
+
_PropertyObserverController_instances.add(this);
|
|
9
8
|
this.host = host;
|
|
10
|
-
this.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
this.options = options;
|
|
10
|
+
this.oldVal = UNINITIALIZED;
|
|
11
|
+
_PropertyObserverController_neverRan.set(this, true);
|
|
12
|
+
}
|
|
13
|
+
hostConnected() {
|
|
14
|
+
__classPrivateFieldGet(this, _PropertyObserverController_instances, "m", _PropertyObserverController_init).call(this);
|
|
16
15
|
}
|
|
17
16
|
/** Set any cached valued accumulated between constructor and connectedCallback */
|
|
18
|
-
hostUpdate() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
async hostUpdate() {
|
|
18
|
+
__classPrivateFieldGet(this, _PropertyObserverController_instances, "m", _PropertyObserverController_init).call(this);
|
|
19
|
+
const { oldVal, options: { waitFor, propertyName, callback } } = this;
|
|
20
|
+
if (!callback) {
|
|
21
|
+
throw new Error(`no callback for ${propertyName}`);
|
|
22
|
+
}
|
|
23
|
+
const newVal = this.host[propertyName];
|
|
24
|
+
this.oldVal = newVal;
|
|
25
|
+
if (newVal !== oldVal) {
|
|
26
|
+
switch (waitFor) {
|
|
27
|
+
case 'connected':
|
|
28
|
+
if (!this.host.isConnected) {
|
|
29
|
+
const origConnected = this.host.connectedCallback;
|
|
30
|
+
await new Promise(resolve => {
|
|
31
|
+
this.host.connectedCallback = function () {
|
|
32
|
+
resolve(origConnected?.call(this));
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
case 'firstUpdated':
|
|
38
|
+
if (!this.host.hasUpdated) {
|
|
39
|
+
await this.host.updateComplete;
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
case 'updated':
|
|
43
|
+
await this.host.updateComplete;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const Class = this.host.constructor;
|
|
48
|
+
const hasChanged = Class
|
|
49
|
+
.getPropertyOptions(this.options.propertyName)
|
|
50
|
+
.hasChanged ?? notEqual;
|
|
51
|
+
if (__classPrivateFieldGet(this, _PropertyObserverController_neverRan, "f") || hasChanged(oldVal, newVal)) {
|
|
52
|
+
callback.call(this.host, oldVal, newVal);
|
|
53
|
+
__classPrivateFieldSet(this, _PropertyObserverController_neverRan, false, "f");
|
|
23
54
|
}
|
|
24
|
-
}
|
|
25
|
-
/** Once the element has updated, we no longer need this controller, so we remove it */
|
|
26
|
-
hostUpdated() {
|
|
27
|
-
this.host.removeController(this);
|
|
28
|
-
}
|
|
29
|
-
cache(key, methodName, ...vals) {
|
|
30
|
-
this.values.set(key, [methodName, vals]);
|
|
31
55
|
}
|
|
32
56
|
}
|
|
33
|
-
|
|
57
|
+
_PropertyObserverController_neverRan = new WeakMap(), _PropertyObserverController_instances = new WeakSet(), _PropertyObserverController_init = function _PropertyObserverController_init() {
|
|
58
|
+
if (this.oldVal === UNINITIALIZED) {
|
|
59
|
+
this.oldVal = this.host[this.options.propertyName];
|
|
60
|
+
}
|
|
61
|
+
};
|
|
34
62
|
//# 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,
|
|
1
|
+
{"version":3,"file":"property-observer-controller.js","sourceRoot":"","sources":["property-observer-controller.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAc/B,MAAM,aAAa,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAE9C,MAAM,OAAO,0BAA0B;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;oBACjC,CAAC;oBACD,MAAM;gBACR,KAAK,SAAS;oBACZ,MAAM,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;oBAC/B,MAAM;YACV,CAAC;QACH,CAAC;QACD,MAAM,KAAK,GAAI,IAAI,CAAC,IAAI,CAAC,WAAsC,CAAC;QAChE,MAAM,UAAU,GAAG,KAAK;aACnB,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;aAC7C,UAAU,IAAI,QAAQ,CAAC;QAC5B,IAAI,uBAAA,IAAI,4CAAU,IAAI,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;YACjD,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAoB,EAAE,MAAM,CAAC,CAAC;YACvD,uBAAA,IAAI,wCAAa,KAAK,MAAA,CAAC;QACzB,CAAC;IACH,CAAC;CACF;;IA7CG,IAAI,IAAI,CAAC,MAAM,KAAK,aAAa,EAAE,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACrD,CAAC;AACH,CAAC","sourcesContent":["import type { ReactiveController, ReactiveElement } from 'lit';\n\nimport { notEqual } from 'lit';\n\nexport type ChangeCallback<T extends ReactiveElement, V = T[keyof T]> = (\n this: T,\n old?: V,\n newV?: V,\n) => void;\n\nexport interface PropertyObserverOptions<T extends ReactiveElement> {\n propertyName: string & keyof T;\n callback: ChangeCallback<T>;\n waitFor?: 'connected' | 'updated' | 'firstUpdated';\n}\n\nconst UNINITIALIZED = Symbol('uninitialized');\n\nexport class PropertyObserverController<\n T extends ReactiveElement\n> implements ReactiveController {\n private oldVal: T[keyof T] = UNINITIALIZED as T[keyof T];\n\n constructor(\n private host: T,\n private options: PropertyObserverOptions<T>\n ) {\n }\n\n #neverRan = true;\n\n hostConnected(): void {\n this.#init();\n }\n\n /**\n * Because of how typescript transpiles private fields,\n * the __accessPrivate helper might not be entirely initialized\n * by the time this constructor runs (in `addInitializer`'s instance callback')\n * Therefore, we pull this shtick.\n *\n * When browser support improves to the point we can ship decorated private fields,\n * we'll be able to get rid of this.\n */\n #init() {\n if (this.oldVal === UNINITIALIZED) {\n this.oldVal = this.host[this.options.propertyName];\n }\n }\n\n /** Set any cached valued accumulated between constructor and connectedCallback */\n async hostUpdate(): Promise<void> {\n this.#init();\n const { oldVal, options: { waitFor, propertyName, callback } } = this;\n if (!callback) {\n throw new Error(`no callback for ${propertyName}`);\n }\n const newVal = this.host[propertyName];\n this.oldVal = newVal;\n if (newVal !== oldVal) {\n switch (waitFor) {\n case 'connected':\n if (!this.host.isConnected) {\n const origConnected = this.host.connectedCallback;\n await new Promise<void>(resolve => {\n this.host.connectedCallback = function() {\n resolve(origConnected?.call(this));\n };\n });\n }\n break;\n case 'firstUpdated':\n if (!this.host.hasUpdated) {\n await this.host.updateComplete;\n }\n break;\n case 'updated':\n await this.host.updateComplete;\n break;\n }\n }\n const Class = (this.host.constructor as typeof ReactiveElement);\n const hasChanged = Class\n .getPropertyOptions(this.options.propertyName)\n .hasChanged ?? notEqual;\n if (this.#neverRan || hasChanged(oldVal, newVal)) {\n callback.call(this.host, oldVal as T[keyof T], newVal);\n this.#neverRan = false;\n }\n }\n}\n"]}
|