@patternfly/pfe-core 2.4.1 → 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 -7
- package/controllers/slot-controller.js +85 -71
- 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 +3120 -1110
- 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,3 +1,5 @@
|
|
|
1
|
+
var _TimestampController_instances, _a, _TimestampController_isTimestampOptionKey, _TimestampController_date, _TimestampController_options, _TimestampController_host, _TimestampController_getTimeRelative;
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
1
3
|
const defaults = {
|
|
2
4
|
dateFormat: undefined,
|
|
3
5
|
timeFormat: undefined,
|
|
@@ -9,100 +11,96 @@ const defaults = {
|
|
|
9
11
|
hour12: false,
|
|
10
12
|
};
|
|
11
13
|
export class TimestampController {
|
|
12
|
-
static #isTimestampOptionKey(prop) {
|
|
13
|
-
return prop in defaults;
|
|
14
|
-
}
|
|
15
|
-
#date = new Date();
|
|
16
|
-
#options = {};
|
|
17
|
-
#host;
|
|
18
14
|
get localeString() {
|
|
19
|
-
return this
|
|
15
|
+
return __classPrivateFieldGet(this, _TimestampController_date, "f").toLocaleString(__classPrivateFieldGet(this, _TimestampController_options, "f").locale);
|
|
20
16
|
}
|
|
21
17
|
get date() {
|
|
22
|
-
return this
|
|
18
|
+
return __classPrivateFieldGet(this, _TimestampController_date, "f");
|
|
23
19
|
}
|
|
24
20
|
set date(string) {
|
|
25
|
-
this
|
|
21
|
+
__classPrivateFieldSet(this, _TimestampController_date, new Date(string), "f");
|
|
26
22
|
}
|
|
27
23
|
get isoString() {
|
|
28
|
-
return this
|
|
24
|
+
return __classPrivateFieldGet(this, _TimestampController_date, "f").toISOString();
|
|
29
25
|
}
|
|
30
26
|
get time() {
|
|
31
|
-
if (this
|
|
32
|
-
return this
|
|
27
|
+
if (__classPrivateFieldGet(this, _TimestampController_options, "f").relative) {
|
|
28
|
+
return __classPrivateFieldGet(this, _TimestampController_instances, "m", _TimestampController_getTimeRelative).call(this);
|
|
33
29
|
}
|
|
34
30
|
else {
|
|
35
|
-
let { displaySuffix, locale } = this
|
|
36
|
-
if (this
|
|
37
|
-
displaySuffix
|
|
31
|
+
let { displaySuffix, locale } = __classPrivateFieldGet(this, _TimestampController_options, "f");
|
|
32
|
+
if (__classPrivateFieldGet(this, _TimestampController_options, "f").utc) {
|
|
33
|
+
displaySuffix || (displaySuffix = 'UTC');
|
|
38
34
|
}
|
|
39
|
-
const localeString = this
|
|
40
|
-
hour12: this
|
|
41
|
-
timeStyle: this
|
|
42
|
-
dateStyle: this
|
|
43
|
-
...this
|
|
35
|
+
const localeString = __classPrivateFieldGet(this, _TimestampController_date, "f").toLocaleString(locale, __classPrivateFieldGet(this, _TimestampController_options, "f").customFormat ?? {
|
|
36
|
+
hour12: __classPrivateFieldGet(this, _TimestampController_options, "f").hour12,
|
|
37
|
+
timeStyle: __classPrivateFieldGet(this, _TimestampController_options, "f").timeFormat,
|
|
38
|
+
dateStyle: __classPrivateFieldGet(this, _TimestampController_options, "f").dateFormat,
|
|
39
|
+
...__classPrivateFieldGet(this, _TimestampController_options, "f").utc && { timeZone: 'UTC' },
|
|
44
40
|
});
|
|
45
41
|
return `${localeString} ${displaySuffix ?? ''}`.trim();
|
|
46
42
|
}
|
|
47
43
|
}
|
|
48
44
|
constructor(host, options) {
|
|
49
|
-
this
|
|
45
|
+
_TimestampController_instances.add(this);
|
|
46
|
+
_TimestampController_date.set(this, new Date());
|
|
47
|
+
_TimestampController_options.set(this, {});
|
|
48
|
+
_TimestampController_host.set(this, void 0);
|
|
49
|
+
__classPrivateFieldSet(this, _TimestampController_host, host, "f");
|
|
50
50
|
host.addController(this);
|
|
51
|
-
for (const [name, value] of Object.entries(this
|
|
51
|
+
for (const [name, value] of Object.entries(__classPrivateFieldGet(this, _TimestampController_options, "f"))) {
|
|
52
52
|
// @ts-expect-error: seems typescript compiler isn't up to the task here
|
|
53
|
-
this
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Based off of Github Relative Time
|
|
58
|
-
* https://github.com/github/time-elements/blob/master/src/relative-time.js
|
|
59
|
-
*/
|
|
60
|
-
#getTimeRelative() {
|
|
61
|
-
const date = this.#date;
|
|
62
|
-
const { locale } = this.#options;
|
|
63
|
-
const rtf = new Intl.RelativeTimeFormat(locale, { localeMatcher: 'best fit', numeric: 'auto', style: 'long' });
|
|
64
|
-
const ms = date.getTime() - Date.now();
|
|
65
|
-
const tense = ms > 0 ? 1 : -1;
|
|
66
|
-
let qty = 0;
|
|
67
|
-
let units;
|
|
68
|
-
const s = Math.round(Math.abs(ms) / 1000);
|
|
69
|
-
const min = Math.round(s / 60);
|
|
70
|
-
const h = Math.round(min / 60);
|
|
71
|
-
const d = Math.round(h / 24);
|
|
72
|
-
const m = Math.round(d / 30);
|
|
73
|
-
const y = Math.round(m / 12);
|
|
74
|
-
if (m >= 12) {
|
|
75
|
-
qty = y;
|
|
76
|
-
units = 'year';
|
|
77
|
-
}
|
|
78
|
-
else if (d >= 30) {
|
|
79
|
-
qty = m;
|
|
80
|
-
units = 'month';
|
|
81
|
-
}
|
|
82
|
-
else if (h >= 24) {
|
|
83
|
-
qty = d;
|
|
84
|
-
units = 'day';
|
|
85
|
-
}
|
|
86
|
-
else if (min >= 45) {
|
|
87
|
-
qty = h;
|
|
88
|
-
units = 'hour';
|
|
89
|
-
}
|
|
90
|
-
else if (s >= 45) {
|
|
91
|
-
qty = min;
|
|
92
|
-
units = 'minute';
|
|
93
|
-
}
|
|
94
|
-
else if (s >= 10) {
|
|
95
|
-
qty = s;
|
|
96
|
-
units = 'second';
|
|
53
|
+
__classPrivateFieldGet(this, _TimestampController_options, "f")[name] = options?.[name] ?? value;
|
|
97
54
|
}
|
|
98
|
-
return typeof (units) !== 'undefined' ? rtf.format(tense * qty, units) : 'just now';
|
|
99
55
|
}
|
|
100
56
|
set(prop, value) {
|
|
101
|
-
if (
|
|
57
|
+
if (__classPrivateFieldGet(_a, _a, "m", _TimestampController_isTimestampOptionKey).call(_a, prop)) {
|
|
102
58
|
// @ts-expect-error: seems typescript compiler isn't up to the task here
|
|
103
|
-
this
|
|
104
|
-
this
|
|
59
|
+
__classPrivateFieldGet(this, _TimestampController_options, "f")[prop] = value;
|
|
60
|
+
__classPrivateFieldGet(this, _TimestampController_host, "f").requestUpdate();
|
|
105
61
|
}
|
|
106
62
|
}
|
|
107
63
|
}
|
|
64
|
+
_a = TimestampController, _TimestampController_date = new WeakMap(), _TimestampController_options = new WeakMap(), _TimestampController_host = new WeakMap(), _TimestampController_instances = new WeakSet(), _TimestampController_isTimestampOptionKey = function _TimestampController_isTimestampOptionKey(prop) {
|
|
65
|
+
return prop in defaults;
|
|
66
|
+
}, _TimestampController_getTimeRelative = function _TimestampController_getTimeRelative() {
|
|
67
|
+
const date = __classPrivateFieldGet(this, _TimestampController_date, "f");
|
|
68
|
+
const { locale } = __classPrivateFieldGet(this, _TimestampController_options, "f");
|
|
69
|
+
const rtf = new Intl.RelativeTimeFormat(locale, { localeMatcher: 'best fit', numeric: 'auto', style: 'long' });
|
|
70
|
+
const ms = date.getTime() - Date.now();
|
|
71
|
+
const tense = ms > 0 ? 1 : -1;
|
|
72
|
+
let qty = 0;
|
|
73
|
+
let units;
|
|
74
|
+
const s = Math.round(Math.abs(ms) / 1000);
|
|
75
|
+
const min = Math.round(s / 60);
|
|
76
|
+
const h = Math.round(min / 60);
|
|
77
|
+
const d = Math.round(h / 24);
|
|
78
|
+
const m = Math.round(d / 30);
|
|
79
|
+
const y = Math.round(m / 12);
|
|
80
|
+
if (m >= 12) {
|
|
81
|
+
qty = y;
|
|
82
|
+
units = 'year';
|
|
83
|
+
}
|
|
84
|
+
else if (d >= 30) {
|
|
85
|
+
qty = m;
|
|
86
|
+
units = 'month';
|
|
87
|
+
}
|
|
88
|
+
else if (h >= 24) {
|
|
89
|
+
qty = d;
|
|
90
|
+
units = 'day';
|
|
91
|
+
}
|
|
92
|
+
else if (min >= 45) {
|
|
93
|
+
qty = h;
|
|
94
|
+
units = 'hour';
|
|
95
|
+
}
|
|
96
|
+
else if (s >= 45) {
|
|
97
|
+
qty = min;
|
|
98
|
+
units = 'minute';
|
|
99
|
+
}
|
|
100
|
+
else if (s >= 10) {
|
|
101
|
+
qty = s;
|
|
102
|
+
units = 'second';
|
|
103
|
+
}
|
|
104
|
+
return typeof (units) !== 'undefined' ? rtf.format(tense * qty, units) : 'just now';
|
|
105
|
+
};
|
|
108
106
|
//# sourceMappingURL=timestamp-controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timestamp-controller.js","sourceRoot":"","sources":["timestamp-controller.ts"],"names":[],"mappings":"AAeA,MAAM,QAAQ,GAAG;IACf,UAAU,EAAE,SAAS;IACrB,UAAU,EAAE,SAAS;IACrB,YAAY,EAAE,SAAS;IACvB,aAAa,EAAE,EAAE;IACjB,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE,KAAK;IACf,GAAG,EAAE,KAAK;IACV,MAAM,EAAE,KAAK;CACL,CAAC;AAEX,MAAM,OAAO,mBAAmB;
|
|
1
|
+
{"version":3,"file":"timestamp-controller.js","sourceRoot":"","sources":["timestamp-controller.ts"],"names":[],"mappings":";;AAeA,MAAM,QAAQ,GAAG;IACf,UAAU,EAAE,SAAS;IACrB,UAAU,EAAE,SAAS;IACrB,YAAY,EAAE,SAAS;IACvB,aAAa,EAAE,EAAE;IACjB,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE,KAAK;IACf,GAAG,EAAE,KA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I,EAAE,EAAE,CAAC;QACnB,GAAG,GAAG,CAAC,CAAC;QACR,KAAK,GAAG,QAAQ,CAAC;IACnB,CAAC;IAED,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;AACtF,CAAC","sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\n\nexport type DateTimeFormat = 'full' | 'long' | 'medium' | 'short';\n\nexport interface TimestampOptions {\n dateFormat?: DateTimeFormat;\n timeFormat?: DateTimeFormat;\n customFormat?: Intl.DateTimeFormatOptions;\n displaySuffix: string;\n locale: Intl.LocalesArgument;\n relative: boolean;\n utc: boolean;\n hour12: boolean;\n}\n\nconst defaults = {\n dateFormat: undefined,\n timeFormat: undefined,\n customFormat: undefined,\n displaySuffix: '',\n locale: undefined,\n relative: false,\n utc: false,\n hour12: false,\n} as const;\n\nexport class TimestampController implements ReactiveController {\n static #isTimestampOptionKey(prop: PropertyKey): prop is keyof TimestampOptions {\n return prop in defaults;\n }\n\n #date = new Date();\n\n #options: TimestampOptions = {} as TimestampOptions;\n\n #host: ReactiveControllerHost;\n\n get localeString() {\n return this.#date.toLocaleString(this.#options.locale);\n }\n\n get date() {\n return this.#date;\n }\n\n set date(string) {\n this.#date = new Date(string);\n }\n\n get isoString() {\n return this.#date.toISOString();\n }\n\n get time() {\n if (this.#options.relative) {\n return this.#getTimeRelative();\n } else {\n let { displaySuffix, locale } = this.#options;\n if (this.#options.utc) {\n displaySuffix ||= 'UTC';\n }\n const localeString = this.#date.toLocaleString(locale, this.#options.customFormat ?? {\n hour12: this.#options.hour12,\n timeStyle: this.#options.timeFormat,\n dateStyle: this.#options.dateFormat,\n ...this.#options.utc && { timeZone: 'UTC' },\n });\n\n return `${localeString} ${displaySuffix ?? ''}`.trim();\n }\n }\n\n constructor(host: ReactiveControllerHost, options?: Partial<TimestampOptions>) {\n this.#host = host;\n host.addController(this);\n for (const [name, value] of Object.entries(this.#options)) {\n // @ts-expect-error: seems typescript compiler isn't up to the task here\n this.#options[name] = options?.[name] ?? value;\n }\n }\n\n hostConnected?(): void\n\n /**\n * Based off of Github Relative Time\n * https://github.com/github/time-elements/blob/master/src/relative-time.js\n */\n #getTimeRelative() {\n const date = this.#date;\n const { locale } = this.#options;\n const rtf = new Intl.RelativeTimeFormat(locale as string, { localeMatcher: 'best fit', numeric: 'auto', style: 'long' });\n const ms: number = date.getTime() - Date.now();\n const tense = ms > 0 ? 1 : -1;\n let qty = 0;\n let units: Intl.RelativeTimeFormatUnit | undefined;\n const s = Math.round(Math.abs(ms) / 1000);\n const min = Math.round(s / 60);\n const h = Math.round(min / 60);\n const d = Math.round(h / 24);\n const m = Math.round(d / 30);\n const y = Math.round(m / 12);\n if (m >= 12) {\n qty = y;\n units = 'year';\n } else if (d >= 30) {\n qty = m;\n units = 'month';\n } else if (h >= 24) {\n qty = d;\n units = 'day';\n } else if (min >= 45) {\n qty = h;\n units = 'hour';\n } else if (s >= 45) {\n qty = min;\n units = 'minute';\n } else if (s >= 10) {\n qty = s;\n units = 'second';\n }\n\n return typeof (units) !== 'undefined' ? rtf.format(tense * qty, units) : 'just now';\n }\n\n set(prop: PropertyKey, value: unknown) {\n if (TimestampController.#isTimestampOptionKey(prop)) {\n // @ts-expect-error: seems typescript compiler isn't up to the task here\n this.#options[prop] = value;\n this.#host.requestUpdate();\n }\n }\n}\n"]}
|
package/core.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ export interface PfeConfig {
|
|
|
8
8
|
/** Set to false to disable automatically removing `unresolved` attr from body */
|
|
9
9
|
autoReveal?: boolean;
|
|
10
10
|
}
|
|
11
|
+
export type RequireProps<T, Ps extends keyof T> = T & {
|
|
12
|
+
[P in Ps]-?: T[P];
|
|
13
|
+
};
|
|
11
14
|
declare const noPref: unique symbol;
|
|
12
15
|
/**
|
|
13
16
|
* A boolean value that indicates if the performance should be tracked.
|
package/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["core.ts"],"names":[],"mappings":"AAgBA,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;AAExB,qCAAqC;AACrC,SAAS,OAAO,CAAC,IAAY;IAC3B,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAkB,cAAc,IAAI,IAAI,CAAC,EAAE,OAAO,CAAC;AACvF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,aAAsC,MAAM;IAC3E,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC;QAC1B,MAAM,CAAC,SAAS,CAAC,gBAAgB,GAAG,CAAC,CAAC,UAAU,CAAC;IACnD,CAAC;IACD,OAAO,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC;AAC3C,CAAC;AAED,SAAS,aAAa,CAAI,CAAmC;IAC3D,OAAO;QACL,aAAa,CAAC,KAAa;YACzB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,OAAO,IAAI,CAAC;YACd,CAAC;iBAAM,CAAC;gBACN,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;QACD,WAAW,CAAC,KAAU;YACpB,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAC9B,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AAE9C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAC9B,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAE/B;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,IAAY,EAAE,IAAgB;QACxC,KAAK,CAAC,IAAI,EAAE;YACV,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;YACd,GAAG,IAAI;SACR,CAAC,CAAC;IACL,CAAC;CACF;AAWD,MAAM,gBAAgB,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;AAEtE,wCAAwC;AACxC,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,EAAE;IACvD,gBAAgB,EAAE,MAAM,CAAC,SAAS,EAAE,gBAAgB,IAAI,OAAO,CAAC,sBAAsB,CAAC,KAAK,MAAM;IAClG,qEAAqE;IACrE,0EAA0E;IAC1E,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC,SAAS,EAAE,UAAU,IAAI,CACxC,gBAAgB,CAAC,CAAC,CAAC,CAAC,gBAAgB;QACtC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,KAAK,MAAM,CACvC;IACD,IAAI,GAAG;QACL,OAAO,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC;IAC/B,CAAC;IACD,IAAI,GAAG,CAAC,CAAU;QAChB,IAAI,CAAC,EAAE,CAAC;YACN,YAAY,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { ComplexAttributeConverter } from 'lit';\n\n/** PatternFly Elements global config object */\nexport interface PfeConfig {\n /** Set to false to disable client-side page load performance tracking */\n trackPerformance?: boolean;\n /** Set to false to disable various debug logs */\n log?: boolean;\n /** Set to false to disable automatically removing `unresolved` attr from body */\n autoReveal?: boolean;\n}\n\nexport type RequireProps<T, Ps extends keyof T> = T & {\n [P in Ps]-?: T[P];\n}\n\nconst noPref = Symbol();\n\n/** Retrieve an HTML metadata item */\nfunction getMeta(name: string): string | undefined {\n return document.head.querySelector<HTMLMetaElement>(`meta[name=\"${name}\"]`)?.content;\n}\n\n/**\n * A boolean value that indicates if the performance should be tracked.\n * For use in a JS file or script tag; can also be added in the constructor of a component during development.\n * @example trackPerformance(true);\n */\nexport function trackPerformance(preference: boolean | typeof noPref = noPref) {\n if (preference !== noPref) {\n window.PfeConfig.trackPerformance = !!preference;\n }\n return window.PfeConfig.trackPerformance;\n}\n\nfunction makeConverter<T>(f: (x: string, type?: unknown) => T): ComplexAttributeConverter<null | T[]> {\n return {\n fromAttribute(value: string) {\n if (typeof value !== 'string') {\n return null;\n } else {\n return value.split(',').map(f);\n }\n },\n toAttribute(value: T[]) {\n return value.join(',');\n },\n };\n}\n\n/**\n * A LitElement property converter which represents a list of numbers as a comma separated string\n * @see https://lit.dev/docs/components/properties/#conversion-converter\n */\nexport const NumberListConverter =\n makeConverter(x => parseInt(x?.trim(), 10));\n\n/**\n * A LitElement property converter which represents a list of strings as a comma separated string\n * @see https://lit.dev/docs/components/properties/#conversion-converter\n */\nexport const StringListConverter =\n makeConverter(x => x.trim());\n\n/**\n * A composed, bubbling event for UI interactions\n * e.g. when an accordion panel opens.\n */\nexport class ComposedEvent extends Event {\n constructor(type: string, init?: EventInit) {\n super(type, {\n bubbles: true,\n composed: true,\n ...init\n });\n }\n}\n\n// 👇 SIDE EFFECTS 👇\n\ndeclare global {\n interface Window {\n /** Global configuration settings for PatternFly Elements */\n PfeConfig: PfeConfig;\n }\n}\n\nconst bodyNoAutoReveal = document.body.hasAttribute('no-auto-reveal');\n\n/** Global patternfly elements config */\nwindow.PfeConfig = Object.assign(window.PfeConfig ?? {}, {\n trackPerformance: window.PfeConfig?.trackPerformance ?? getMeta('pf-track-performance') === 'true',\n // if the body tag has `no-auto-reveal` attribute, reveal immediately\n // if `<meta name=\"pf-auto-reveal\">` exists, and it's `content` is 'true',\n // then auto-reveal the body\n autoReveal: window.PfeConfig?.autoReveal ?? (\n bodyNoAutoReveal ? !bodyNoAutoReveal\n : getMeta('pf-auto-reveal') === 'true'\n ),\n get log() {\n return !!localStorage.pfeLog;\n },\n set log(v: boolean) {\n if (v) {\n localStorage.setItem('pfeLog', `${true}`);\n } else {\n localStorage.removeItem('pfeLog');\n }\n },\n});\n"]}
|