@commmerce/ui 1.1.1 → 1.3.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.
Files changed (45) hide show
  1. package/dist/calendar.d.ts +38 -0
  2. package/dist/calendar.js +109 -0
  3. package/dist/cdn.js +1010 -533
  4. package/dist/components/board.d.ts +338 -0
  5. package/dist/components/board.js +1017 -0
  6. package/dist/components/button.d.ts +10 -0
  7. package/dist/components/button.js +25 -0
  8. package/dist/components/card.d.ts +7 -1
  9. package/dist/components/card.js +58 -7
  10. package/dist/components/color-field.d.ts +153 -0
  11. package/dist/components/color-field.js +369 -0
  12. package/dist/components/combobox.d.ts +17 -4
  13. package/dist/components/combobox.js +55 -23
  14. package/dist/components/date-picker.d.ts +49 -5
  15. package/dist/components/date-picker.js +211 -48
  16. package/dist/components/empty-state.d.ts +19 -4
  17. package/dist/components/empty-state.js +59 -5
  18. package/dist/components/file-upload.d.ts +33 -0
  19. package/dist/components/file-upload.js +80 -9
  20. package/dist/components/global-search.js +2 -7
  21. package/dist/components/metric.d.ts +97 -0
  22. package/dist/components/metric.js +168 -0
  23. package/dist/components/nested-list.d.ts +33 -1
  24. package/dist/components/nested-list.js +197 -18
  25. package/dist/components/option-group.d.ts +15 -6
  26. package/dist/components/option-group.js +25 -6
  27. package/dist/components/page-header.js +3 -2
  28. package/dist/components/resource-list.d.ts +14 -2
  29. package/dist/components/resource-list.js +48 -6
  30. package/dist/components/select.d.ts +20 -3
  31. package/dist/components/select.js +35 -11
  32. package/dist/components/table-header.d.ts +14 -0
  33. package/dist/components/table-header.js +21 -0
  34. package/dist/components/text-field.d.ts +36 -2
  35. package/dist/components/text-field.js +86 -14
  36. package/dist/components/timeline.d.ts +210 -0
  37. package/dist/components/timeline.js +380 -0
  38. package/dist/custom-elements.json +9371 -4963
  39. package/dist/index.d.ts +10 -0
  40. package/dist/index.js +5 -0
  41. package/dist/move-model.d.ts +93 -0
  42. package/dist/move-model.js +169 -0
  43. package/dist/popover.d.ts +24 -0
  44. package/dist/popover.js +59 -0
  45. package/package.json +3 -3
package/dist/index.d.ts CHANGED
@@ -13,7 +13,10 @@ export { CmDatePicker } from './components/date-picker.js';
13
13
  export { CmDateRangePicker, resolvePreset } from './components/date-range-picker.js';
14
14
  export type { DateRangePreset, DateRangePresetKey } from './components/date-range-picker.js';
15
15
  export { CmFileUpload } from './components/file-upload.js';
16
+ export { CmColorField, normalizeHex } from './components/color-field.js';
17
+ export type { ColorSwatch } from './components/color-field.js';
16
18
  export { CmOptionGroup } from './components/option-group.js';
19
+ export type { OptionGroupOption } from './components/option-group.js';
17
20
  export { CmTag } from './components/tag.js';
18
21
  export { CmPageHeader } from './components/page-header.js';
19
22
  export type { Breadcrumb } from './components/page-header.js';
@@ -25,6 +28,7 @@ export { CmEmptyState } from './components/empty-state.js';
25
28
  export { CmSkeleton } from './components/skeleton.js';
26
29
  export { CmSkeletonDisplay } from './components/skeleton-display.js';
27
30
  export { CmComment, CmCommentBox } from './components/comment.js';
31
+ export { CmTimeline, CmTimelineItem } from './components/timeline.js';
28
32
  export { CmSmartTip, CmSmartTips } from './components/smart-tip.js';
29
33
  export { CmPagination } from './components/pagination.js';
30
34
  export { CmStatusTabs } from './components/status-tabs.js';
@@ -35,7 +39,13 @@ export type { DataTableColumn, DataTableRow, SortDirection } from './components/
35
39
  export type { TableColumn } from './components/table-header.js';
36
40
  export { CmResourceList, CmResourceItem } from './components/resource-list.js';
37
41
  export { CmNestedList, CmNestedItem } from './components/nested-list.js';
42
+ export { CmBoard, CmBoardColumn, CmBoardCard } from './components/board.js';
43
+ export type { BoardMoveDetail, BoardMoveSource } from './components/board.js';
44
+ export { MoveModel, Announcer, listNavigation } from './move-model.js';
45
+ export type { MovePlace, MoveModelOptions } from './move-model.js';
38
46
  export { CmReportTile, CmReportTiles } from './components/report-tile.js';
47
+ export { CmMetric } from './components/metric.js';
48
+ export type { MetricTrend, MetricSentiment } from './components/metric.js';
39
49
  export { CmNavItem } from './components/nav-item.js';
40
50
  export type { NavItem } from './components/nav-item.js';
41
51
  export { CmSideNavigation } from './components/side-navigation.js';
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ export { CmGlobalSearch } from './components/global-search.js';
10
10
  export { CmDatePicker } from './components/date-picker.js';
11
11
  export { CmDateRangePicker, resolvePreset } from './components/date-range-picker.js';
12
12
  export { CmFileUpload } from './components/file-upload.js';
13
+ export { CmColorField, normalizeHex } from './components/color-field.js';
13
14
  export { CmOptionGroup } from './components/option-group.js';
14
15
  export { CmTag } from './components/tag.js';
15
16
  export { CmPageHeader } from './components/page-header.js';
@@ -21,6 +22,7 @@ export { CmEmptyState } from './components/empty-state.js';
21
22
  export { CmSkeleton } from './components/skeleton.js';
22
23
  export { CmSkeletonDisplay } from './components/skeleton-display.js';
23
24
  export { CmComment, CmCommentBox } from './components/comment.js';
25
+ export { CmTimeline, CmTimelineItem } from './components/timeline.js';
24
26
  export { CmSmartTip, CmSmartTips } from './components/smart-tip.js';
25
27
  export { CmPagination } from './components/pagination.js';
26
28
  export { CmStatusTabs } from './components/status-tabs.js';
@@ -28,7 +30,10 @@ export { CmTableHeader } from './components/table-header.js';
28
30
  export { CmDataTable } from './components/data-table.js';
29
31
  export { CmResourceList, CmResourceItem } from './components/resource-list.js';
30
32
  export { CmNestedList, CmNestedItem } from './components/nested-list.js';
33
+ export { CmBoard, CmBoardColumn, CmBoardCard } from './components/board.js';
34
+ export { MoveModel, Announcer, listNavigation } from './move-model.js';
31
35
  export { CmReportTile, CmReportTiles } from './components/report-tile.js';
36
+ export { CmMetric } from './components/metric.js';
32
37
  export { CmNavItem } from './components/nav-item.js';
33
38
  export { CmSideNavigation } from './components/side-navigation.js';
34
39
  export { CmHeaderBar } from './components/header-bar.js';
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Moving an item between groups without dragging: pick it up, choose a group and a position with the arrow keys,
3
+ * drop it or cancel, with every step announced through a live region.
4
+ *
5
+ * It holds no DOM of its own beyond the live region and knows nothing about boards: a group is a board column
6
+ * today and a calendar day (or hour) later. The component tells it how many groups there are and how many
7
+ * positions each one offers; it calls back when the target changes (draw a placeholder, scroll it into view) and
8
+ * on drop or cancel (commit or restore), and asks the component for the words to announce, so all text stays
9
+ * translatable in the component's own string table.
10
+ *
11
+ * Keys (the default `navigate`, used by `cm-board`): Left/Right the previous/next group (pass the key through
12
+ * `logicalKey()` first, so they follow the reading direction), Up/Down the previous/next position, Home/End the
13
+ * first/last position, Space or Enter drop, Escape cancels. Tab cancels and lets focus move on.
14
+ */
15
+ /** A place an item can be dropped: a group (board column, calendar day) and a position in it, both from 0. */
16
+ export interface MovePlace {
17
+ group: number;
18
+ index: number;
19
+ }
20
+ export interface MoveModelOptions {
21
+ /** How many groups there are now. */
22
+ groupCount(): number;
23
+ /**
24
+ * How many positions a group offers the moving item: the items already in it (not counting the moving item)
25
+ * plus one. A group the item can't go into returns 0 and is skipped.
26
+ */
27
+ slotCount(group: number): number;
28
+ /**
29
+ * Where a key takes the item from `at`: a place, or `null` when the key does nothing. Defaults to
30
+ * `listNavigation` (groups side by side, positions top to bottom). A calendar month grid would map Up/Down to the
31
+ * same weekday a week before/after instead.
32
+ */
33
+ navigate?(key: string, at: MovePlace, model: MoveModel): MovePlace | null;
34
+ /** The target changed (also called on pick up, and with `null` when the move ends): draw the placeholder. */
35
+ onTarget?(at: MovePlace | null): void;
36
+ /** Dropped on a place: commit the move. Called with the starting place and the chosen one, also when they are the same. */
37
+ onDrop(from: MovePlace, to: MovePlace): void;
38
+ /** Cancelled (Escape, Tab, focus left, `cancel()`): the item stays where it was. */
39
+ onCancel?(from: MovePlace): void;
40
+ /** Words to announce, in the component's language. */
41
+ messages: {
42
+ /** Just picked up, at its starting place. */
43
+ pickedUp(at: MovePlace): string;
44
+ /** Moved over a new place. */
45
+ over(at: MovePlace): string;
46
+ /** Cancelled: back where it started. */
47
+ cancelled(from: MovePlace): string;
48
+ };
49
+ /** Speaks a message: usually `Announcer.announce`. */
50
+ announce(text: string): void;
51
+ }
52
+ /** Groups side by side (Left/Right), positions top to bottom (Up/Down, Home/End). Groups with no positions are skipped. */
53
+ export declare function listNavigation(key: string, at: MovePlace, model: MoveModel): MovePlace | null;
54
+ /** The keyboard move of one item at a time. */
55
+ export declare class MoveModel {
56
+ #private;
57
+ constructor(options: MoveModelOptions);
58
+ /** An item is picked up. */
59
+ get active(): boolean;
60
+ /** Where the item started, while picked up. */
61
+ get from(): MovePlace | null;
62
+ /** Where it would be dropped now, while picked up. */
63
+ get target(): MovePlace | null;
64
+ groupCount(): number;
65
+ slotCount(group: number): number;
66
+ /** Picks up the item at `from` and announces it. A move already under way is cancelled first. */
67
+ pickUp(from: MovePlace): void;
68
+ /** Moves the target to `to` (clamped to the group's positions) and announces it. */
69
+ moveTo(to: MovePlace): void;
70
+ /** Drops at the current target. */
71
+ drop(): void;
72
+ /** Puts the item back without moving it, and announces that. Does nothing when nothing is picked up. */
73
+ cancel(silent?: boolean): void;
74
+ /**
75
+ * Handles a key while an item is picked up. Pass `logicalKey(e, host)` as `key` so Left/Right follow the
76
+ * reading direction. Returns true when the key was used: call `preventDefault()` then. Tab cancels but returns
77
+ * false, so focus moves on as usual.
78
+ */
79
+ handleKey(e: KeyboardEvent, key?: string): boolean;
80
+ }
81
+ /**
82
+ * A visually hidden live region for move announcements. Repeating the same words is announced again (the text is
83
+ * cleared first). `assertive`, because each message answers a key the person just pressed.
84
+ */
85
+ export declare class Announcer {
86
+ #private;
87
+ readonly element: HTMLElement;
88
+ constructor(doc?: Document, politeness?: 'assertive' | 'polite');
89
+ /** The last message, as it is (or will be) in the live region. */
90
+ get text(): string;
91
+ /** Speaks `text`. Text set twice in a row is still announced twice. */
92
+ announce(text: string): void;
93
+ }
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Moving an item between groups without dragging: pick it up, choose a group and a position with the arrow keys,
3
+ * drop it or cancel, with every step announced through a live region.
4
+ *
5
+ * It holds no DOM of its own beyond the live region and knows nothing about boards: a group is a board column
6
+ * today and a calendar day (or hour) later. The component tells it how many groups there are and how many
7
+ * positions each one offers; it calls back when the target changes (draw a placeholder, scroll it into view) and
8
+ * on drop or cancel (commit or restore), and asks the component for the words to announce, so all text stays
9
+ * translatable in the component's own string table.
10
+ *
11
+ * Keys (the default `navigate`, used by `cm-board`): Left/Right the previous/next group (pass the key through
12
+ * `logicalKey()` first, so they follow the reading direction), Up/Down the previous/next position, Home/End the
13
+ * first/last position, Space or Enter drop, Escape cancels. Tab cancels and lets focus move on.
14
+ */
15
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
16
+ if (kind === "m") throw new TypeError("Private method is not writable");
17
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
18
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
19
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
20
+ };
21
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
22
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
23
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
24
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
25
+ };
26
+ var _MoveModel_o, _MoveModel_from, _MoveModel_to, _Announcer_timer, _Announcer_pending;
27
+ /** Groups side by side (Left/Right), positions top to bottom (Up/Down, Home/End). Groups with no positions are skipped. */
28
+ export function listNavigation(key, at, model) {
29
+ const slots = (g) => model.slotCount(g);
30
+ const last = (g) => Math.max(0, slots(g) - 1);
31
+ const step = (dir) => {
32
+ for (let g = at.group + dir; g >= 0 && g < model.groupCount(); g += dir) {
33
+ if (slots(g) > 0)
34
+ return { group: g, index: Math.min(at.index, last(g)) };
35
+ }
36
+ return { ...at };
37
+ };
38
+ switch (key) {
39
+ case 'ArrowRight': return step(1);
40
+ case 'ArrowLeft': return step(-1);
41
+ case 'ArrowDown': return { group: at.group, index: Math.min(at.index + 1, last(at.group)) };
42
+ case 'ArrowUp': return { group: at.group, index: Math.max(at.index - 1, 0) };
43
+ case 'Home': return { group: at.group, index: 0 };
44
+ case 'End': return { group: at.group, index: last(at.group) };
45
+ default: return null;
46
+ }
47
+ }
48
+ /** The keyboard move of one item at a time. */
49
+ export class MoveModel {
50
+ constructor(options) {
51
+ _MoveModel_o.set(this, void 0);
52
+ _MoveModel_from.set(this, null);
53
+ _MoveModel_to.set(this, null);
54
+ __classPrivateFieldSet(this, _MoveModel_o, options, "f");
55
+ }
56
+ /** An item is picked up. */
57
+ get active() { return __classPrivateFieldGet(this, _MoveModel_from, "f") !== null; }
58
+ /** Where the item started, while picked up. */
59
+ get from() { return __classPrivateFieldGet(this, _MoveModel_from, "f") && { ...__classPrivateFieldGet(this, _MoveModel_from, "f") }; }
60
+ /** Where it would be dropped now, while picked up. */
61
+ get target() { return __classPrivateFieldGet(this, _MoveModel_to, "f") && { ...__classPrivateFieldGet(this, _MoveModel_to, "f") }; }
62
+ groupCount() { return __classPrivateFieldGet(this, _MoveModel_o, "f").groupCount(); }
63
+ slotCount(group) { return group >= 0 && group < __classPrivateFieldGet(this, _MoveModel_o, "f").groupCount() ? __classPrivateFieldGet(this, _MoveModel_o, "f").slotCount(group) : 0; }
64
+ /** Picks up the item at `from` and announces it. A move already under way is cancelled first. */
65
+ pickUp(from) {
66
+ if (this.active)
67
+ this.cancel();
68
+ __classPrivateFieldSet(this, _MoveModel_from, { ...from }, "f");
69
+ __classPrivateFieldSet(this, _MoveModel_to, { ...from }, "f");
70
+ __classPrivateFieldGet(this, _MoveModel_o, "f").onTarget?.(this.target);
71
+ __classPrivateFieldGet(this, _MoveModel_o, "f").announce(__classPrivateFieldGet(this, _MoveModel_o, "f").messages.pickedUp(this.target));
72
+ }
73
+ /** Moves the target to `to` (clamped to the group's positions) and announces it. */
74
+ moveTo(to) {
75
+ if (!__classPrivateFieldGet(this, _MoveModel_to, "f"))
76
+ return;
77
+ const g = Math.max(0, Math.min(to.group, __classPrivateFieldGet(this, _MoveModel_o, "f").groupCount() - 1));
78
+ const n = this.slotCount(g);
79
+ if (n <= 0)
80
+ return;
81
+ __classPrivateFieldSet(this, _MoveModel_to, { group: g, index: Math.max(0, Math.min(to.index, n - 1)) }, "f");
82
+ __classPrivateFieldGet(this, _MoveModel_o, "f").onTarget?.(this.target);
83
+ __classPrivateFieldGet(this, _MoveModel_o, "f").announce(__classPrivateFieldGet(this, _MoveModel_o, "f").messages.over(this.target));
84
+ }
85
+ /** Drops at the current target. */
86
+ drop() {
87
+ if (!__classPrivateFieldGet(this, _MoveModel_from, "f") || !__classPrivateFieldGet(this, _MoveModel_to, "f"))
88
+ return;
89
+ const from = __classPrivateFieldGet(this, _MoveModel_from, "f"), to = __classPrivateFieldGet(this, _MoveModel_to, "f");
90
+ __classPrivateFieldSet(this, _MoveModel_from, __classPrivateFieldSet(this, _MoveModel_to, null, "f"), "f");
91
+ __classPrivateFieldGet(this, _MoveModel_o, "f").onTarget?.(null);
92
+ __classPrivateFieldGet(this, _MoveModel_o, "f").onDrop(from, to);
93
+ }
94
+ /** Puts the item back without moving it, and announces that. Does nothing when nothing is picked up. */
95
+ cancel(silent = false) {
96
+ if (!__classPrivateFieldGet(this, _MoveModel_from, "f"))
97
+ return;
98
+ const from = __classPrivateFieldGet(this, _MoveModel_from, "f");
99
+ // The words first: the component may forget the item in onCancel.
100
+ const message = silent ? '' : __classPrivateFieldGet(this, _MoveModel_o, "f").messages.cancelled(from);
101
+ __classPrivateFieldSet(this, _MoveModel_from, __classPrivateFieldSet(this, _MoveModel_to, null, "f"), "f");
102
+ __classPrivateFieldGet(this, _MoveModel_o, "f").onTarget?.(null);
103
+ __classPrivateFieldGet(this, _MoveModel_o, "f").onCancel?.(from);
104
+ if (message)
105
+ __classPrivateFieldGet(this, _MoveModel_o, "f").announce(message);
106
+ }
107
+ /**
108
+ * Handles a key while an item is picked up. Pass `logicalKey(e, host)` as `key` so Left/Right follow the
109
+ * reading direction. Returns true when the key was used: call `preventDefault()` then. Tab cancels but returns
110
+ * false, so focus moves on as usual.
111
+ */
112
+ handleKey(e, key = e.key) {
113
+ if (!this.active || e.altKey || e.ctrlKey || e.metaKey)
114
+ return false;
115
+ if (key === ' ' || key === 'Enter') {
116
+ this.drop();
117
+ return true;
118
+ }
119
+ if (key === 'Escape') {
120
+ this.cancel();
121
+ return true;
122
+ }
123
+ if (key === 'Tab') {
124
+ this.cancel();
125
+ return false;
126
+ }
127
+ const next = (__classPrivateFieldGet(this, _MoveModel_o, "f").navigate ?? listNavigation)(key, __classPrivateFieldGet(this, _MoveModel_to, "f"), this);
128
+ if (!next)
129
+ return false;
130
+ this.moveTo(next);
131
+ return true;
132
+ }
133
+ }
134
+ _MoveModel_o = new WeakMap(), _MoveModel_from = new WeakMap(), _MoveModel_to = new WeakMap();
135
+ /**
136
+ * A visually hidden live region for move announcements. Repeating the same words is announced again (the text is
137
+ * cleared first). `assertive`, because each message answers a key the person just pressed.
138
+ */
139
+ export class Announcer {
140
+ constructor(doc = document, politeness = 'assertive') {
141
+ _Announcer_timer.set(this, void 0);
142
+ _Announcer_pending.set(this, void 0);
143
+ const el = doc.createElement('div');
144
+ el.setAttribute('aria-live', politeness);
145
+ el.setAttribute('aria-atomic', 'true');
146
+ el.className = 'cm-announcer';
147
+ Object.assign(el.style, {
148
+ position: 'absolute', width: '1px', height: '1px', margin: '-1px', padding: '0', overflow: 'hidden',
149
+ clip: 'rect(0 0 0 0)', clipPath: 'inset(50%)', whiteSpace: 'nowrap', border: '0',
150
+ });
151
+ this.element = el;
152
+ }
153
+ /** The last message, as it is (or will be) in the live region. */
154
+ get text() { return __classPrivateFieldGet(this, _Announcer_pending, "f") ?? this.element.textContent ?? ''; }
155
+ /** Speaks `text`. Text set twice in a row is still announced twice. */
156
+ announce(text) {
157
+ clearTimeout(__classPrivateFieldGet(this, _Announcer_timer, "f"));
158
+ if (this.element.textContent === text) {
159
+ this.element.textContent = '';
160
+ __classPrivateFieldSet(this, _Announcer_pending, text, "f");
161
+ __classPrivateFieldSet(this, _Announcer_timer, setTimeout(() => { this.element.textContent = text; __classPrivateFieldSet(this, _Announcer_pending, undefined, "f"); }, 50), "f");
162
+ }
163
+ else {
164
+ __classPrivateFieldSet(this, _Announcer_pending, undefined, "f");
165
+ this.element.textContent = text;
166
+ }
167
+ }
168
+ }
169
+ _Announcer_timer = new WeakMap(), _Announcer_pending = new WeakMap();
package/dist/popover.d.ts CHANGED
@@ -6,3 +6,27 @@
6
6
  export declare const popoverStyles: import("lit").CSSResult;
7
7
  /** Calls `close` when a pointer goes down outside `host` (through shadow roots). Returns the function that stops listening. */
8
8
  export declare function closeOnOutsidePointer(host: HTMLElement, isOpen: () => boolean, close: () => void): () => void;
9
+ /**
10
+ * Group headings inside a listbox, shared by `cm-global-search`, `cm-select` and `cm-combobox`: each group is a
11
+ * `role="group"` element labelled (`aria-labelledby`) by its `.gh` heading, which is `role="presentation"` so it
12
+ * is never an option. Groups after another group, or after an ungrouped option, get a line above them.
13
+ */
14
+ export declare const groupStyles: import("lit").CSSResult;
15
+ /**
16
+ * Puts options of the same `group` together, in the order the groups first appear. Options without a group stay
17
+ * where they are (as in a native select, where options can come before or after an `<optgroup>`). Returns the
18
+ * same array when no option has a group.
19
+ */
20
+ export declare function sortByGroup<T extends {
21
+ group?: string;
22
+ }>(items: T[]): T[];
23
+ /** Splits rows (already in group order) into runs: `group` is '' for options outside any group. `index` is the row's position. */
24
+ export declare function groupRuns<T extends {
25
+ group?: string;
26
+ }>(rows: T[]): Array<{
27
+ group: string;
28
+ rows: Array<{
29
+ row: T;
30
+ index: number;
31
+ }>;
32
+ }>;
package/dist/popover.js CHANGED
@@ -24,3 +24,62 @@ export function closeOnOutsidePointer(host, isOpen, close) {
24
24
  document.addEventListener('pointerdown', listener, true);
25
25
  return () => document.removeEventListener('pointerdown', listener, true);
26
26
  }
27
+ /**
28
+ * Group headings inside a listbox, shared by `cm-global-search`, `cm-select` and `cm-combobox`: each group is a
29
+ * `role="group"` element labelled (`aria-labelledby`) by its `.gh` heading, which is `role="presentation"` so it
30
+ * is never an option. Groups after another group, or after an ungrouped option, get a line above them.
31
+ */
32
+ export const groupStyles = css `
33
+ [role='group'] + [role='group'] { margin-block-start: 6px; padding-block-start: 6px; border-top: var(--cm-border-1) solid var(--cm-border-default); }
34
+ [role='option'] + [role='group'], [role='group'] + [role='option'] { margin-block-start: 6px; padding-block-start: 6px; border-top: var(--cm-border-1) solid var(--cm-border-default); }
35
+ .gh {
36
+ display: flex; align-items: baseline; gap: var(--cm-space-10); padding: 6px var(--cm-space-20) 2px;
37
+ font-size: 12px; line-height: 16px; font-weight: 600; color: var(--cm-text-default);
38
+ }
39
+ .gh .count { font-weight: 400; color: var(--cm-text-tertiary); }
40
+ .gopts { list-style: none; margin: 0; padding: 0; }
41
+ `;
42
+ /**
43
+ * Puts options of the same `group` together, in the order the groups first appear. Options without a group stay
44
+ * where they are (as in a native select, where options can come before or after an `<optgroup>`). Returns the
45
+ * same array when no option has a group.
46
+ */
47
+ export function sortByGroup(items) {
48
+ if (!items.some((o) => o.group))
49
+ return items;
50
+ const buckets = [];
51
+ const byKey = new Map();
52
+ for (const o of items) {
53
+ if (o.group) {
54
+ const b = byKey.get(o.group);
55
+ if (b)
56
+ b.push(o);
57
+ else {
58
+ const n = [o];
59
+ byKey.set(o.group, n);
60
+ buckets.push({ key: o.group, items: n });
61
+ }
62
+ }
63
+ else {
64
+ const last = buckets[buckets.length - 1];
65
+ if (last && !last.key)
66
+ last.items.push(o);
67
+ else
68
+ buckets.push({ key: '', items: [o] });
69
+ }
70
+ }
71
+ return buckets.flatMap((b) => b.items);
72
+ }
73
+ /** Splits rows (already in group order) into runs: `group` is '' for options outside any group. `index` is the row's position. */
74
+ export function groupRuns(rows) {
75
+ const runs = [];
76
+ rows.forEach((row, index) => {
77
+ const g = row.group || '';
78
+ const last = runs[runs.length - 1];
79
+ if (last && last.group === g)
80
+ last.rows.push({ row, index });
81
+ else
82
+ runs.push({ group: g, rows: [{ row, index }] });
83
+ });
84
+ return runs;
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commmerce/ui",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "description": "Commmerce UI web components: build apps that feel native to the Commmerce admin. Works in plain HTML, React, Vue and server-rendered pages.",
5
5
  "keywords": [
6
6
  "web-components",
@@ -50,8 +50,8 @@
50
50
  "test": "vitest run"
51
51
  },
52
52
  "dependencies": {
53
- "@commmerce/icons": "1.1.1",
54
- "@commmerce/tokens": "1.1.1",
53
+ "@commmerce/icons": "1.3.0",
54
+ "@commmerce/tokens": "1.3.0",
55
55
  "lit": "3.2.1"
56
56
  },
57
57
  "devDependencies": {