@patternfly/pfe-core 2.3.1 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/controllers/cascade-controller.js +1 -1
- package/controllers/cascade-controller.js.map +1 -1
- package/controllers/floating-dom-controller.d.ts +1 -1
- package/controllers/floating-dom-controller.js +81 -83
- package/controllers/floating-dom-controller.js.map +1 -1
- package/controllers/internals-controller.js +17 -20
- package/controllers/internals-controller.js.map +1 -1
- package/controllers/logger.js +1 -1
- package/controllers/logger.js.map +1 -1
- package/controllers/overflow-controller.js +42 -40
- package/controllers/overflow-controller.js.map +1 -1
- package/controllers/property-observer-controller.js +1 -1
- package/controllers/property-observer-controller.js.map +1 -1
- package/controllers/roving-tabindex-controller.js +114 -106
- package/controllers/roving-tabindex-controller.js.map +1 -1
- package/controllers/scroll-spy-controller.js +93 -91
- package/controllers/scroll-spy-controller.js.map +1 -1
- package/controllers/slot-controller.d.ts +2 -15
- package/controllers/slot-controller.js +47 -63
- package/controllers/slot-controller.js.map +1 -1
- package/controllers/timestamp-controller.d.ts +23 -0
- package/controllers/timestamp-controller.js +108 -0
- package/controllers/timestamp-controller.js.map +1 -0
- package/custom-elements.json +728 -627
- package/package.json +2 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const defaults = {
|
|
2
|
+
dateFormat: undefined,
|
|
3
|
+
timeFormat: undefined,
|
|
4
|
+
customFormat: undefined,
|
|
5
|
+
displaySuffix: '',
|
|
6
|
+
locale: undefined,
|
|
7
|
+
relative: false,
|
|
8
|
+
utc: false,
|
|
9
|
+
hour12: false,
|
|
10
|
+
};
|
|
11
|
+
export class TimestampController {
|
|
12
|
+
static #isTimestampOptionKey(prop) {
|
|
13
|
+
return prop in defaults;
|
|
14
|
+
}
|
|
15
|
+
#date = new Date();
|
|
16
|
+
#options = {};
|
|
17
|
+
#host;
|
|
18
|
+
get localeString() {
|
|
19
|
+
return this.#date.toLocaleString(this.#options.locale);
|
|
20
|
+
}
|
|
21
|
+
get date() {
|
|
22
|
+
return this.#date;
|
|
23
|
+
}
|
|
24
|
+
set date(string) {
|
|
25
|
+
this.#date = new Date(string);
|
|
26
|
+
}
|
|
27
|
+
get isoString() {
|
|
28
|
+
return this.#date.toISOString();
|
|
29
|
+
}
|
|
30
|
+
get time() {
|
|
31
|
+
if (this.#options.relative) {
|
|
32
|
+
return this.#getTimeRelative();
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
let { displaySuffix, locale } = this.#options;
|
|
36
|
+
if (this.#options.utc) {
|
|
37
|
+
displaySuffix ||= 'UTC';
|
|
38
|
+
}
|
|
39
|
+
const localeString = this.#date.toLocaleString(locale, this.#options.customFormat ?? {
|
|
40
|
+
hour12: this.#options.hour12,
|
|
41
|
+
timeStyle: this.#options.timeFormat,
|
|
42
|
+
dateStyle: this.#options.dateFormat,
|
|
43
|
+
...this.#options.utc && { timeZone: 'UTC' },
|
|
44
|
+
});
|
|
45
|
+
return `${localeString} ${displaySuffix ?? ''}`.trim();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
constructor(host, options) {
|
|
49
|
+
this.#host = host;
|
|
50
|
+
host.addController(this);
|
|
51
|
+
for (const [name, value] of Object.entries(this.#options)) {
|
|
52
|
+
// @ts-expect-error: seems typescript compiler isn't up to the task here
|
|
53
|
+
this.#options[name] = options?.[name] ?? value;
|
|
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';
|
|
97
|
+
}
|
|
98
|
+
return typeof (units) !== 'undefined' ? rtf.format(tense * qty, units) : 'just now';
|
|
99
|
+
}
|
|
100
|
+
set(prop, value) {
|
|
101
|
+
if (TimestampController.#isTimestampOptionKey(prop)) {
|
|
102
|
+
// @ts-expect-error: seems typescript compiler isn't up to the task here
|
|
103
|
+
this.#options[prop] = value;
|
|
104
|
+
this.#host.requestUpdate();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=timestamp-controller.js.map
|
|
@@ -0,0 +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,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I,CAAC,EAAE;YACnD,wEAAwE;YACxE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;YAC5B,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;SAC5B;IACH,CAAC;CACF","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"]}
|