@commmerce/ui 1.1.0 → 1.2.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/dist/calendar.d.ts +38 -0
- package/dist/calendar.js +109 -0
- package/dist/cdn.js +682 -453
- package/dist/components/button.d.ts +10 -0
- package/dist/components/button.js +25 -0
- package/dist/components/card.d.ts +5 -0
- package/dist/components/card.js +44 -5
- package/dist/components/date-picker.d.ts +49 -5
- package/dist/components/date-picker.js +211 -48
- package/dist/components/empty-state.d.ts +19 -4
- package/dist/components/empty-state.js +59 -5
- package/dist/components/header-bar.js +4 -2
- package/dist/components/metric.d.ts +97 -0
- package/dist/components/metric.js +168 -0
- package/dist/components/page-header.js +3 -2
- package/dist/components/resource-list.d.ts +14 -2
- package/dist/components/resource-list.js +48 -6
- package/dist/components/table-header.d.ts +14 -0
- package/dist/components/table-header.js +21 -0
- package/dist/components/text-field.d.ts +36 -2
- package/dist/components/text-field.js +86 -14
- package/dist/components/timeline.d.ts +210 -0
- package/dist/components/timeline.js +380 -0
- package/dist/custom-elements.json +5102 -3386
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/package.json +3 -3
package/dist/calendar.d.ts
CHANGED
|
@@ -10,6 +10,44 @@ export declare function addMonths(d: Date, n: number): Date;
|
|
|
10
10
|
export declare const startOfMonth: (d: Date) => Date;
|
|
11
11
|
export declare const endOfMonth: (d: Date) => Date;
|
|
12
12
|
export declare const sameMonth: (a: Date, b: Date) => boolean;
|
|
13
|
+
/** Minutes since midnight for an ISO time `hh:mm` (seconds are ignored), or null. */
|
|
14
|
+
export declare function timeToMinutes(s: string | null | undefined): number | null;
|
|
15
|
+
/** ISO time `hh:mm` for minutes since midnight (wraps round the day). */
|
|
16
|
+
export declare const minutesToTime: (n: number) => string;
|
|
17
|
+
/** `yyyy-mm-ddThh:mm` (or just a date) split into its ISO date and `hh:mm` time; a part is '' when missing or not real. */
|
|
18
|
+
export declare function splitDateTime(s: string | null | undefined): {
|
|
19
|
+
date: string;
|
|
20
|
+
time: string;
|
|
21
|
+
};
|
|
22
|
+
/** The local Date of `yyyy-mm-ddThh:mm`, or of a date alone at `dayEnd` ? 23:59 : 00:00; null if there is no real date. */
|
|
23
|
+
export declare function fromISODateTime(s: string | null | undefined, dayEnd?: boolean): Date | null;
|
|
24
|
+
/** The current local time as `yyyy-mm-ddThh:mm`. */
|
|
25
|
+
export declare const nowISO: () => string;
|
|
26
|
+
export interface TimeFormat {
|
|
27
|
+
/** Formats minutes since midnight for the time box, e.g. "3:30 pm" (en-IN) or "15:30" (en-GB). */
|
|
28
|
+
format(minutes: number): string;
|
|
29
|
+
/** A date and time for messages and screen readers, e.g. "16 Nov 2026, 3:30 pm". */
|
|
30
|
+
dateTime(d: Date): string;
|
|
31
|
+
/** "{h}:{m} am": the locale's order, separators and day period; fill it with `timePattern()`. */
|
|
32
|
+
pattern: string;
|
|
33
|
+
/** True when the locale (or the hour cycle asked for) uses a 12-hour clock. */
|
|
34
|
+
hour12: boolean;
|
|
35
|
+
/** Lowercase words for before and after noon (the locale's and English), for reading typed times. */
|
|
36
|
+
am: string[];
|
|
37
|
+
pm: string[];
|
|
38
|
+
}
|
|
39
|
+
/** Intl time formatters for a locale, cached. `hourCycle` 'h12' or 'h23' overrides the locale's clock. */
|
|
40
|
+
export declare function timeFormat(locale: string, hourCycle?: string): TimeFormat;
|
|
41
|
+
/** The typed-time pattern with the component's letters for hours and minutes, e.g. "hh:mm am" or "hh:mm". */
|
|
42
|
+
export declare const timePattern: (tf: TimeFormat, letters: {
|
|
43
|
+
h: string;
|
|
44
|
+
m: string;
|
|
45
|
+
}) => string;
|
|
46
|
+
/**
|
|
47
|
+
* Reads a typed time: `15:30`, `3:30 pm`, `3.30pm`, `3 pm`, `1530`, `330pm`, with the locale's words for am and pm
|
|
48
|
+
* as well as English. Without am/pm the hours are read on a 24-hour clock. Returns ISO `hh:mm`, or null.
|
|
49
|
+
*/
|
|
50
|
+
export declare function parseTime(text: string, tf: TimeFormat): string | null;
|
|
13
51
|
/** Splits a list attribute (`"2026-12-25, 2026-12-31"` or `"today last-7-days"`) into an array. */
|
|
14
52
|
export declare const listConverter: {
|
|
15
53
|
fromAttribute: (v: string | null) => string[];
|
package/dist/calendar.js
CHANGED
|
@@ -28,6 +28,111 @@ export function addMonths(d, n) {
|
|
|
28
28
|
export const startOfMonth = (d) => new Date(d.getFullYear(), d.getMonth(), 1);
|
|
29
29
|
export const endOfMonth = (d) => new Date(d.getFullYear(), d.getMonth() + 1, 0);
|
|
30
30
|
export const sameMonth = (a, b) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
|
|
31
|
+
/* ---------- Times (cm-date-picker `time`) ---------- */
|
|
32
|
+
const TIME = /^([01]\d|2[0-3]):([0-5]\d)(?::[0-5]\d(?:\.\d{1,3})?)?$/;
|
|
33
|
+
/** Minutes since midnight for an ISO time `hh:mm` (seconds are ignored), or null. */
|
|
34
|
+
export function timeToMinutes(s) {
|
|
35
|
+
const m = TIME.exec(s ?? '');
|
|
36
|
+
return m ? +m[1] * 60 + +m[2] : null;
|
|
37
|
+
}
|
|
38
|
+
/** ISO time `hh:mm` for minutes since midnight (wraps round the day). */
|
|
39
|
+
export const minutesToTime = (n) => { const v = ((Math.round(n) % 1440) + 1440) % 1440; return `${pad(Math.floor(v / 60))}:${pad(v % 60)}`; };
|
|
40
|
+
/** `yyyy-mm-ddThh:mm` (or just a date) split into its ISO date and `hh:mm` time; a part is '' when missing or not real. */
|
|
41
|
+
export function splitDateTime(s) {
|
|
42
|
+
const [d = '', t = ''] = (s ?? '').split('T');
|
|
43
|
+
const minutes = timeToMinutes(t);
|
|
44
|
+
return { date: fromISO(d) ? d : '', time: minutes === null ? '' : minutesToTime(minutes) };
|
|
45
|
+
}
|
|
46
|
+
/** The local Date of `yyyy-mm-ddThh:mm`, or of a date alone at `dayEnd` ? 23:59 : 00:00; null if there is no real date. */
|
|
47
|
+
export function fromISODateTime(s, dayEnd = false) {
|
|
48
|
+
const { date, time } = splitDateTime(s);
|
|
49
|
+
const d = fromISO(date);
|
|
50
|
+
if (!d)
|
|
51
|
+
return null;
|
|
52
|
+
const minutes = time ? timeToMinutes(time) : dayEnd ? 1439 : 0;
|
|
53
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate(), Math.floor(minutes / 60), minutes % 60);
|
|
54
|
+
}
|
|
55
|
+
/** The current local time as `yyyy-mm-ddThh:mm`. */
|
|
56
|
+
export const nowISO = () => { const n = new Date(); return `${toISO(n)}T${pad(n.getHours())}:${pad(n.getMinutes())}`; };
|
|
57
|
+
const timeFormats = new Map();
|
|
58
|
+
/** Intl time formatters for a locale, cached. `hourCycle` 'h12' or 'h23' overrides the locale's clock. */
|
|
59
|
+
export function timeFormat(locale, hourCycle) {
|
|
60
|
+
const hc = hourCycle === 'h12' || hourCycle === 'h23' ? hourCycle : undefined;
|
|
61
|
+
const key = `${locale}|${hc ?? ''}`;
|
|
62
|
+
const hit = timeFormats.get(key);
|
|
63
|
+
if (hit)
|
|
64
|
+
return hit;
|
|
65
|
+
const opts = { hour: 'numeric', minute: '2-digit', numberingSystem: 'latn', ...(hc ? { hourCycle: hc } : {}) };
|
|
66
|
+
const time = new Intl.DateTimeFormat(locale, opts);
|
|
67
|
+
const cycle = time.resolvedOptions().hourCycle;
|
|
68
|
+
const at = (h) => new Date(2000, 0, 1, h, 30);
|
|
69
|
+
const period = (h) => (new Intl.DateTimeFormat(locale, { hour: 'numeric', hourCycle: 'h12' })
|
|
70
|
+
.formatToParts(at(h)).find((p) => p.type === 'dayPeriod')?.value ?? '').toLowerCase().replace(/[^\p{L}]/gu, '');
|
|
71
|
+
const words = (local, en) => [...new Set([local, ...en].filter(Boolean))];
|
|
72
|
+
// Intl puts a narrow no-break space before am/pm in some engines; a plain space is what merchants type.
|
|
73
|
+
const spaces = (t) => t.replace(/[\u202f\u00a0]/g, ' ');
|
|
74
|
+
const pattern = spaces(time.formatToParts(at(9))
|
|
75
|
+
.map((p) => (p.type === 'hour' ? '{h}' : p.type === 'minute' ? '{m}' : p.value)).join(''));
|
|
76
|
+
const fmt = {
|
|
77
|
+
format: (minutes) => spaces(time.format(new Date(2000, 0, 1, Math.floor(minutes / 60), minutes % 60))),
|
|
78
|
+
dateTime: (d) => formatDate(d, { day: 'numeric', month: 'short', year: 'numeric', hour: 'numeric', minute: '2-digit', ...(hc ? { hourCycle: hc } : {}) }, locale),
|
|
79
|
+
pattern,
|
|
80
|
+
hour12: cycle === 'h12' || cycle === 'h11',
|
|
81
|
+
am: words(period(9), ['am', 'a']),
|
|
82
|
+
pm: words(period(15), ['pm', 'p']),
|
|
83
|
+
};
|
|
84
|
+
timeFormats.set(key, fmt);
|
|
85
|
+
return fmt;
|
|
86
|
+
}
|
|
87
|
+
/** The typed-time pattern with the component's letters for hours and minutes, e.g. "hh:mm am" or "hh:mm". */
|
|
88
|
+
export const timePattern = (tf, letters) => tf.pattern.replace(/\{([hm])\}/g, (_, k) => letters[k]);
|
|
89
|
+
/**
|
|
90
|
+
* Reads a typed time: `15:30`, `3:30 pm`, `3.30pm`, `3 pm`, `1530`, `330pm`, with the locale's words for am and pm
|
|
91
|
+
* as well as English. Without am/pm the hours are read on a 24-hour clock. Returns ISO `hh:mm`, or null.
|
|
92
|
+
*/
|
|
93
|
+
export function parseTime(text, tf) {
|
|
94
|
+
const s = text.trim().toLowerCase().normalize('NFKC');
|
|
95
|
+
if (!s)
|
|
96
|
+
return null;
|
|
97
|
+
const word = s.replace(/[^\p{L}]/gu, '');
|
|
98
|
+
const pm = !!word && tf.pm.includes(word);
|
|
99
|
+
const am = !!word && tf.am.includes(word);
|
|
100
|
+
if (word && !pm && !am)
|
|
101
|
+
return null;
|
|
102
|
+
const nums = s.match(/\d+/g) ?? [];
|
|
103
|
+
let h, m;
|
|
104
|
+
if (nums.length === 1) {
|
|
105
|
+
const g = nums[0];
|
|
106
|
+
if (g.length <= 2) {
|
|
107
|
+
h = +g;
|
|
108
|
+
m = 0;
|
|
109
|
+
}
|
|
110
|
+
else if (g.length <= 4) {
|
|
111
|
+
h = +g.slice(0, -2);
|
|
112
|
+
m = +g.slice(-2);
|
|
113
|
+
}
|
|
114
|
+
else
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
else if (nums.length === 2 || nums.length === 3) {
|
|
118
|
+
if (nums[0].length > 2 || nums[1].length !== 2)
|
|
119
|
+
return null;
|
|
120
|
+
h = +nums[0];
|
|
121
|
+
m = +nums[1];
|
|
122
|
+
}
|
|
123
|
+
else
|
|
124
|
+
return null;
|
|
125
|
+
if (m > 59)
|
|
126
|
+
return null;
|
|
127
|
+
if (am || pm) {
|
|
128
|
+
if (h < 1 || h > 12)
|
|
129
|
+
return null;
|
|
130
|
+
h = (h % 12) + (pm ? 12 : 0);
|
|
131
|
+
}
|
|
132
|
+
else if (h > 23)
|
|
133
|
+
return null;
|
|
134
|
+
return minutesToTime(h * 60 + m);
|
|
135
|
+
}
|
|
31
136
|
/** Splits a list attribute (`"2026-12-25, 2026-12-31"` or `"today last-7-days"`) into an array. */
|
|
32
137
|
export const listConverter = {
|
|
33
138
|
fromAttribute: (v) => (v ? v.split(/[\s,]+/).filter(Boolean) : []),
|
|
@@ -277,4 +382,8 @@ export const dateFieldStyles = css `
|
|
|
277
382
|
:host([size='small']) .field { gap: 6px; }
|
|
278
383
|
:host([size='small']) .label { font-size: 12px; }
|
|
279
384
|
:host([size='small']) input { font-size: 14px; }
|
|
385
|
+
/* cm-date-picker with \`time\`: the date box and a time box side by side, wrapping onto two rows when narrow. */
|
|
386
|
+
.wrap.timed { display: flex; flex-wrap: wrap; gap: var(--cm-space-10); }
|
|
387
|
+
.wrap.timed .box { width: auto; min-inline-size: 0; flex: 2 1 10.5rem; }
|
|
388
|
+
.wrap.timed .box.time { flex: 1 1 7.5rem; padding-inline: var(--cm-space-10); }
|
|
280
389
|
`;
|