@commmerce/ui 0.0.0-stage → 1.0.0-rc.3
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/LICENSE.md +17 -0
- package/README.md +41 -2
- package/dist/base.d.ts +7 -0
- package/dist/base.js +22 -0
- package/dist/cdn.js +1958 -0
- package/dist/components/accordion.d.ts +43 -0
- package/dist/components/accordion.js +83 -0
- package/dist/components/action-bar.d.ts +42 -0
- package/dist/components/action-bar.js +84 -0
- package/dist/components/action-menu.d.ts +89 -0
- package/dist/components/action-menu.js +283 -0
- package/dist/components/app-card.d.ts +57 -0
- package/dist/components/app-card.js +100 -0
- package/dist/components/avatar.d.ts +48 -0
- package/dist/components/avatar.js +82 -0
- package/dist/components/badge.d.ts +23 -0
- package/dist/components/badge.js +35 -0
- package/dist/components/banner.d.ts +36 -0
- package/dist/components/banner.js +88 -0
- package/dist/components/bottom-navigation.d.ts +48 -0
- package/dist/components/bottom-navigation.js +98 -0
- package/dist/components/bottom-sheet.d.ts +54 -0
- package/dist/components/bottom-sheet.js +133 -0
- package/dist/components/button.d.ts +53 -0
- package/dist/components/button.js +101 -0
- package/dist/components/card.d.ts +37 -0
- package/dist/components/card.js +58 -0
- package/dist/components/checkbox.d.ts +68 -0
- package/dist/components/checkbox.js +114 -0
- package/dist/components/comment.d.ts +76 -0
- package/dist/components/comment.js +170 -0
- package/dist/components/data-table.d.ts +132 -0
- package/dist/components/data-table.js +331 -0
- package/dist/components/empty-state.d.ts +49 -0
- package/dist/components/empty-state.js +94 -0
- package/dist/components/file-upload.d.ts +102 -0
- package/dist/components/file-upload.js +243 -0
- package/dist/components/filter-panel.d.ts +86 -0
- package/dist/components/filter-panel.js +128 -0
- package/dist/components/flash-offer-bar.d.ts +34 -0
- package/dist/components/flash-offer-bar.js +73 -0
- package/dist/components/grid.d.ts +39 -0
- package/dist/components/grid.js +42 -0
- package/dist/components/header-bar.d.ts +48 -0
- package/dist/components/header-bar.js +121 -0
- package/dist/components/icon.d.ts +30 -0
- package/dist/components/icon.js +36 -0
- package/dist/components/info-panel.d.ts +63 -0
- package/dist/components/info-panel.js +108 -0
- package/dist/components/layout.d.ts +45 -0
- package/dist/components/layout.js +67 -0
- package/dist/components/link-tabs.d.ts +40 -0
- package/dist/components/link-tabs.js +85 -0
- package/dist/components/menu-item.d.ts +68 -0
- package/dist/components/menu-item.js +64 -0
- package/dist/components/mobile-menu.d.ts +69 -0
- package/dist/components/mobile-menu.js +184 -0
- package/dist/components/modal.d.ts +46 -0
- package/dist/components/modal.js +59 -0
- package/dist/components/nav-item.d.ts +98 -0
- package/dist/components/nav-item.js +84 -0
- package/dist/components/nested-list.d.ts +105 -0
- package/dist/components/nested-list.js +279 -0
- package/dist/components/notification-panel.d.ts +121 -0
- package/dist/components/notification-panel.js +174 -0
- package/dist/components/option-group.d.ts +74 -0
- package/dist/components/option-group.js +172 -0
- package/dist/components/page-header.d.ts +58 -0
- package/dist/components/page-header.js +121 -0
- package/dist/components/page.d.ts +34 -0
- package/dist/components/page.js +41 -0
- package/dist/components/pagination.d.ts +64 -0
- package/dist/components/pagination.js +160 -0
- package/dist/components/progress-bar.d.ts +45 -0
- package/dist/components/progress-bar.js +81 -0
- package/dist/components/radio.d.ts +131 -0
- package/dist/components/radio.js +252 -0
- package/dist/components/report-tile.d.ts +65 -0
- package/dist/components/report-tile.js +112 -0
- package/dist/components/resource-list.d.ts +143 -0
- package/dist/components/resource-list.js +335 -0
- package/dist/components/save-bar.d.ts +58 -0
- package/dist/components/save-bar.js +128 -0
- package/dist/components/search.d.ts +78 -0
- package/dist/components/search.js +144 -0
- package/dist/components/select.d.ts +106 -0
- package/dist/components/select.js +338 -0
- package/dist/components/side-navigation.d.ts +51 -0
- package/dist/components/side-navigation.js +194 -0
- package/dist/components/side-panel.d.ts +50 -0
- package/dist/components/side-panel.js +73 -0
- package/dist/components/skeleton-display.d.ts +32 -0
- package/dist/components/skeleton-display.js +70 -0
- package/dist/components/skeleton.d.ts +41 -0
- package/dist/components/skeleton.js +59 -0
- package/dist/components/smart-tip.d.ts +62 -0
- package/dist/components/smart-tip.js +128 -0
- package/dist/components/spinner.d.ts +27 -0
- package/dist/components/spinner.js +48 -0
- package/dist/components/stack.d.ts +45 -0
- package/dist/components/stack.js +49 -0
- package/dist/components/status-tabs.d.ts +65 -0
- package/dist/components/status-tabs.js +158 -0
- package/dist/components/table-header.d.ts +84 -0
- package/dist/components/table-header.js +151 -0
- package/dist/components/tag.d.ts +39 -0
- package/dist/components/tag.js +68 -0
- package/dist/components/text-field.d.ts +101 -0
- package/dist/components/text-field.js +162 -0
- package/dist/components/thumbnail.d.ts +40 -0
- package/dist/components/thumbnail.js +61 -0
- package/dist/components/toast.d.ts +108 -0
- package/dist/components/toast.js +268 -0
- package/dist/components/toggle.d.ts +60 -0
- package/dist/components/toggle.js +108 -0
- package/dist/components/tooltip.d.ts +56 -0
- package/dist/components/tooltip.js +267 -0
- package/dist/custom-elements.json +13222 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +56 -0
- package/dist/overlay.d.ts +57 -0
- package/dist/overlay.js +205 -0
- package/dist/spacing.d.ts +6 -0
- package/dist/spacing.js +7 -0
- package/package.json +59 -4
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { LitElement, css } from 'lit';
|
|
2
|
+
import { define } from '../base.js';
|
|
3
|
+
/**
|
|
4
|
+
* A navigation destination described in markup. It renders nothing itself: the navigation that contains it
|
|
5
|
+
* reads its attributes and children. Nest `cm-nav-item`s to make sub-items.
|
|
6
|
+
* @element cm-nav-item
|
|
7
|
+
* @slot - Child `cm-nav-item`s (sub-items).
|
|
8
|
+
*/
|
|
9
|
+
export class CmNavItem extends LitElement {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
/** Visible text. */
|
|
13
|
+
this.label = '';
|
|
14
|
+
/** Icon from @commmerce/icons. */
|
|
15
|
+
this.icon = '';
|
|
16
|
+
/** Where the item goes. Leave empty on a parent that only opens its sub-items. */
|
|
17
|
+
this.href = '';
|
|
18
|
+
/** Identifies the item in `cm-navigate` handlers. */
|
|
19
|
+
this.value = '';
|
|
20
|
+
/** The page the merchant is on. */
|
|
21
|
+
this.current = false;
|
|
22
|
+
/** Short text after the label, e.g. "New". */
|
|
23
|
+
this.badge = '';
|
|
24
|
+
/** Sub-items start open. */
|
|
25
|
+
this.expanded = false;
|
|
26
|
+
/** Bottom navigation only: the one main action, drawn as a black square (Quick add). */
|
|
27
|
+
this.primary = false;
|
|
28
|
+
}
|
|
29
|
+
render() { return null; }
|
|
30
|
+
/** This item and its sub-items as plain data. */
|
|
31
|
+
toItem() { return itemFrom(this); }
|
|
32
|
+
}
|
|
33
|
+
CmNavItem.properties = {
|
|
34
|
+
label: { reflect: true },
|
|
35
|
+
icon: { reflect: true },
|
|
36
|
+
href: { reflect: true },
|
|
37
|
+
value: { reflect: true },
|
|
38
|
+
current: { type: Boolean, reflect: true },
|
|
39
|
+
badge: { reflect: true },
|
|
40
|
+
expanded: { type: Boolean, reflect: true },
|
|
41
|
+
primary: { type: Boolean, reflect: true },
|
|
42
|
+
};
|
|
43
|
+
CmNavItem.styles = css `:host { display: none !important; }`;
|
|
44
|
+
define('cm-nav-item', CmNavItem);
|
|
45
|
+
// Reads attributes, so it works before the children are upgraded.
|
|
46
|
+
function itemFrom(el) {
|
|
47
|
+
const a = (n) => el.getAttribute(n);
|
|
48
|
+
const it = { label: a('label') || '' };
|
|
49
|
+
if (a('icon'))
|
|
50
|
+
it.icon = a('icon');
|
|
51
|
+
if (a('href'))
|
|
52
|
+
it.href = a('href');
|
|
53
|
+
if (a('value'))
|
|
54
|
+
it.value = a('value');
|
|
55
|
+
if (el.hasAttribute('current'))
|
|
56
|
+
it.current = true;
|
|
57
|
+
if (a('badge'))
|
|
58
|
+
it.badge = a('badge');
|
|
59
|
+
if (el.hasAttribute('expanded'))
|
|
60
|
+
it.expanded = true;
|
|
61
|
+
if (el.hasAttribute('primary'))
|
|
62
|
+
it.primary = true;
|
|
63
|
+
const kids = readNavItems(el);
|
|
64
|
+
if (kids.length)
|
|
65
|
+
it.items = kids;
|
|
66
|
+
return it;
|
|
67
|
+
}
|
|
68
|
+
/** Reads the direct `cm-nav-item` children of `host` as data. */
|
|
69
|
+
export const readNavItems = (host) => [...host.children].filter((c) => c.localName === 'cm-nav-item').map(itemFrom);
|
|
70
|
+
/** The value a `cm-navigate` handler sees for an item. */
|
|
71
|
+
export const navValue = (it) => it.value || it.href || it.label;
|
|
72
|
+
/** True when the item or any descendant is current. */
|
|
73
|
+
export const hasCurrent = (it) => !!it.current || !!it.items?.some(hasCurrent);
|
|
74
|
+
/** Watches `cm-nav-item` children (attributes and structure) and calls `cb` when they change. */
|
|
75
|
+
export const watchNavItems = (host, cb) => {
|
|
76
|
+
const o = new MutationObserver(cb);
|
|
77
|
+
o.observe(host, { childList: true, subtree: true, attributes: true, attributeFilter: ['label', 'icon', 'href', 'value', 'current', 'badge', 'expanded', 'primary'] });
|
|
78
|
+
return o;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Fires the cancelable `cm-navigate` event. Returns false when a handler called `preventDefault()`
|
|
82
|
+
* (the app routes itself), so the caller can stop the link.
|
|
83
|
+
*/
|
|
84
|
+
export const fireNavigate = (host, item) => host.dispatchEvent(new CustomEvent('cm-navigate', { bubbles: true, composed: true, cancelable: true, detail: { item, value: navValue(item), href: item.href ?? '' } }));
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import './icon.js';
|
|
3
|
+
/**
|
|
4
|
+
* One row in a `cm-nested-list`: a 60px bordered row with a label and actions (toggle, edit, delete).
|
|
5
|
+
* Put more `cm-nested-item`s inside it to nest them; each level is indented.
|
|
6
|
+
* @element cm-nested-item
|
|
7
|
+
* @slot - Child `cm-nested-item`s.
|
|
8
|
+
* @slot actions - Controls at the end of the row: a badge, a toggle, edit and delete buttons.
|
|
9
|
+
* @fires cm-reorder - Bubbles from the moved item: `detail: { item, from, to }` (positions among its siblings). Cancelable.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CmNestedItem extends LitElement {
|
|
12
|
+
#private;
|
|
13
|
+
static properties: {
|
|
14
|
+
label: {};
|
|
15
|
+
value: {
|
|
16
|
+
reflect: boolean;
|
|
17
|
+
};
|
|
18
|
+
sortable: {
|
|
19
|
+
type: BooleanConstructor;
|
|
20
|
+
reflect: boolean;
|
|
21
|
+
};
|
|
22
|
+
_hasChildren: {
|
|
23
|
+
state: boolean;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/** Row text, e.g. a menu link or category name. */
|
|
27
|
+
label: string;
|
|
28
|
+
/** Identifies the item in `cm-reorder` handlers. */
|
|
29
|
+
value: string;
|
|
30
|
+
/** Shows the drag handle. Set by the parent list from its own `sortable`. */
|
|
31
|
+
sortable: boolean;
|
|
32
|
+
_hasChildren: boolean;
|
|
33
|
+
constructor();
|
|
34
|
+
connectedCallback(): void;
|
|
35
|
+
static styles: import("lit").CSSResult[];
|
|
36
|
+
/** Sibling `cm-nested-item`s, including this one. */
|
|
37
|
+
get siblings(): CmNestedItem[];
|
|
38
|
+
/**
|
|
39
|
+
* Moves this item to a position among its siblings, firing a cancelable `cm-reorder` first.
|
|
40
|
+
* Returns false if nothing moved.
|
|
41
|
+
*/
|
|
42
|
+
moveTo(to: number): boolean;
|
|
43
|
+
static dragged: CmNestedItem | null;
|
|
44
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
45
|
+
updated(changed: Map<string, unknown>): void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A titled group of rows that nest inside each other, such as a navigation menu with links and
|
|
49
|
+
* sub-links, or categories and sub-categories. The heading sits in a 90px grey bar with its own
|
|
50
|
+
* actions; rows below are indented one step per level. With `sortable`, each row gets a drag
|
|
51
|
+
* handle that also works from the keyboard (↑/↓, Home/End). With `collapsible`, the bar gets a
|
|
52
|
+
* round button that shows and hides the rows.
|
|
53
|
+
* @element cm-nested-list
|
|
54
|
+
* @slot - `cm-nested-item` rows.
|
|
55
|
+
* @slot actions - Controls in the heading bar, e.g. an "Add links" button or a toggle.
|
|
56
|
+
* @fires cm-reorder - When a row is moved. See `cm-nested-item`.
|
|
57
|
+
* @fires cm-toggle - `detail: { open }` when a collapsible list is shown or hidden.
|
|
58
|
+
*/
|
|
59
|
+
export declare class CmNestedList extends LitElement {
|
|
60
|
+
#private;
|
|
61
|
+
static properties: {
|
|
62
|
+
heading: {};
|
|
63
|
+
headingLevel: {
|
|
64
|
+
type: NumberConstructor;
|
|
65
|
+
attribute: string;
|
|
66
|
+
};
|
|
67
|
+
sortable: {
|
|
68
|
+
type: BooleanConstructor;
|
|
69
|
+
reflect: boolean;
|
|
70
|
+
};
|
|
71
|
+
collapsible: {
|
|
72
|
+
type: BooleanConstructor;
|
|
73
|
+
reflect: boolean;
|
|
74
|
+
};
|
|
75
|
+
open: {
|
|
76
|
+
type: BooleanConstructor;
|
|
77
|
+
reflect: boolean;
|
|
78
|
+
};
|
|
79
|
+
_msg: {
|
|
80
|
+
state: boolean;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
/** Title in the grey bar, e.g. "Header" or "Clothing & accessories". */
|
|
84
|
+
heading: string;
|
|
85
|
+
/** Heading level for the title (1–6). */
|
|
86
|
+
headingLevel: number;
|
|
87
|
+
/** Rows get drag handles and can be reordered among their siblings. */
|
|
88
|
+
sortable: boolean;
|
|
89
|
+
/** Adds a show/hide button to the heading bar. */
|
|
90
|
+
collapsible: boolean;
|
|
91
|
+
/** Whether the rows are shown when `collapsible`. */
|
|
92
|
+
open: boolean;
|
|
93
|
+
_msg: string;
|
|
94
|
+
static styles: import("lit").CSSResult[];
|
|
95
|
+
/** Reads a message to screen readers, e.g. after a move. */
|
|
96
|
+
announce(msg: string): void;
|
|
97
|
+
updated(changed: Map<string, unknown>): void;
|
|
98
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
99
|
+
}
|
|
100
|
+
declare global {
|
|
101
|
+
interface HTMLElementTagNameMap {
|
|
102
|
+
'cm-nested-list': CmNestedList;
|
|
103
|
+
'cm-nested-item': CmNestedItem;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
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");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _CmNestedItem_instances, _a, _CmNestedItem_internals, _CmNestedItem_onHandleKey, _CmNestedItem_onDragStart, _CmNestedItem_onDragOver, _CmNestedItem_clearDrop, _CmNestedItem_onDrop, _CmNestedList_instances, _CmNestedList_id, _CmNestedList_toggle, _CmNestedList_syncSortable;
|
|
7
|
+
import { LitElement, html, css, nothing } from 'lit';
|
|
8
|
+
import { base, define, nextId } from '../base.js';
|
|
9
|
+
import './icon.js';
|
|
10
|
+
/**
|
|
11
|
+
* One row in a `cm-nested-list`: a 60px bordered row with a label and actions (toggle, edit, delete).
|
|
12
|
+
* Put more `cm-nested-item`s inside it to nest them; each level is indented.
|
|
13
|
+
* @element cm-nested-item
|
|
14
|
+
* @slot - Child `cm-nested-item`s.
|
|
15
|
+
* @slot actions - Controls at the end of the row: a badge, a toggle, edit and delete buttons.
|
|
16
|
+
* @fires cm-reorder - Bubbles from the moved item: `detail: { item, from, to }` (positions among its siblings). Cancelable.
|
|
17
|
+
*/
|
|
18
|
+
export class CmNestedItem extends LitElement {
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
_CmNestedItem_instances.add(this);
|
|
22
|
+
/** Row text, e.g. a menu link or category name. */
|
|
23
|
+
this.label = '';
|
|
24
|
+
/** Identifies the item in `cm-reorder` handlers. */
|
|
25
|
+
this.value = '';
|
|
26
|
+
/** Shows the drag handle. Set by the parent list from its own `sortable`. */
|
|
27
|
+
this.sortable = false;
|
|
28
|
+
this._hasChildren = false;
|
|
29
|
+
_CmNestedItem_internals.set(this, this.attachInternals());
|
|
30
|
+
__classPrivateFieldGet(this, _CmNestedItem_internals, "f").role = 'listitem';
|
|
31
|
+
}
|
|
32
|
+
connectedCallback() {
|
|
33
|
+
super.connectedCallback();
|
|
34
|
+
// Also as an attribute, so checkers that don't read ElementInternals (axe-core) see the list item too.
|
|
35
|
+
if (!this.hasAttribute('role'))
|
|
36
|
+
this.setAttribute('role', 'listitem');
|
|
37
|
+
}
|
|
38
|
+
/** Sibling `cm-nested-item`s, including this one. */
|
|
39
|
+
get siblings() {
|
|
40
|
+
return [...this.parentElement.children].filter((c) => c.localName === 'cm-nested-item');
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Moves this item to a position among its siblings, firing a cancelable `cm-reorder` first.
|
|
44
|
+
* Returns false if nothing moved.
|
|
45
|
+
*/
|
|
46
|
+
moveTo(to) {
|
|
47
|
+
const sibs = this.siblings;
|
|
48
|
+
const from = sibs.indexOf(this);
|
|
49
|
+
to = Math.max(0, Math.min(sibs.length - 1, to));
|
|
50
|
+
if (to === from)
|
|
51
|
+
return false;
|
|
52
|
+
const ev = new CustomEvent('cm-reorder', { detail: { item: this, from, to }, bubbles: true, composed: true, cancelable: true });
|
|
53
|
+
if (!this.dispatchEvent(ev))
|
|
54
|
+
return false;
|
|
55
|
+
const ref = sibs[to];
|
|
56
|
+
ref.parentElement.insertBefore(this, to > from ? ref.nextSibling : ref);
|
|
57
|
+
this.closest('cm-nested-list')?.announce(`${this.label} moved to position ${to + 1} of ${sibs.length}.`);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
render() {
|
|
61
|
+
return html `
|
|
62
|
+
<div class="row" part="row" @dragover=${__classPrivateFieldGet(this, _CmNestedItem_instances, "m", _CmNestedItem_onDragOver)} @dragleave=${__classPrivateFieldGet(this, _CmNestedItem_instances, "m", _CmNestedItem_clearDrop)} @drop=${__classPrivateFieldGet(this, _CmNestedItem_instances, "m", _CmNestedItem_onDrop)}>
|
|
63
|
+
${this.sortable
|
|
64
|
+
? html `<button class="handle" type="button" part="handle" draggable="true" aria-label=${`Reorder ${this.label}`}
|
|
65
|
+
aria-describedby="hint"
|
|
66
|
+
@keydown=${__classPrivateFieldGet(this, _CmNestedItem_instances, "m", _CmNestedItem_onHandleKey)} @dragstart=${__classPrivateFieldGet(this, _CmNestedItem_instances, "m", _CmNestedItem_onDragStart)}
|
|
67
|
+
@dragend=${() => { this.classList.remove('dragging'); _a.dragged = null; }}><cm-icon name="drag" size="18"></cm-icon></button>`
|
|
68
|
+
: nothing}
|
|
69
|
+
${this.sortable ? html `<span class="sr" id="hint">Press up or down arrow to move.</span>` : nothing}
|
|
70
|
+
<span class="label" part="label">${this.label}</span>
|
|
71
|
+
<span class="actions" part="actions"><slot name="actions"></slot></span>
|
|
72
|
+
</div>
|
|
73
|
+
<div class="children ${this._hasChildren ? 'has' : ''}" role="list" aria-label=${this.label}>
|
|
74
|
+
<slot @slotchange=${(e) => {
|
|
75
|
+
const kids = e.target.assignedElements().filter((k) => k.localName === 'cm-nested-item');
|
|
76
|
+
kids.forEach((k) => (k.sortable = this.sortable));
|
|
77
|
+
this._hasChildren = kids.length > 0;
|
|
78
|
+
}}></slot>
|
|
79
|
+
</div>
|
|
80
|
+
`;
|
|
81
|
+
}
|
|
82
|
+
updated(changed) {
|
|
83
|
+
if (changed.has('sortable')) {
|
|
84
|
+
[...this.children].forEach((k) => { if (k.localName === 'cm-nested-item')
|
|
85
|
+
k.sortable = this.sortable; });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
_a = CmNestedItem, _CmNestedItem_internals = new WeakMap(), _CmNestedItem_instances = new WeakSet(), _CmNestedItem_onHandleKey = function _CmNestedItem_onHandleKey(e) {
|
|
90
|
+
const i = this.siblings.indexOf(this);
|
|
91
|
+
let to;
|
|
92
|
+
if (e.key === 'ArrowUp')
|
|
93
|
+
to = i - 1;
|
|
94
|
+
else if (e.key === 'ArrowDown')
|
|
95
|
+
to = i + 1;
|
|
96
|
+
else if (e.key === 'Home')
|
|
97
|
+
to = 0;
|
|
98
|
+
else if (e.key === 'End')
|
|
99
|
+
to = this.siblings.length - 1;
|
|
100
|
+
else
|
|
101
|
+
return;
|
|
102
|
+
e.preventDefault();
|
|
103
|
+
if (this.moveTo(to)) {
|
|
104
|
+
// Moving the row re-inserts it, which drops focus. Restore it at once so a quick second key
|
|
105
|
+
// press (e.g. ↓ then End) still reaches the handle, and again after render as a fallback.
|
|
106
|
+
const refocus = () => this.renderRoot.querySelector('.handle')?.focus();
|
|
107
|
+
refocus();
|
|
108
|
+
requestAnimationFrame(refocus);
|
|
109
|
+
}
|
|
110
|
+
}, _CmNestedItem_onDragStart = function _CmNestedItem_onDragStart(e) {
|
|
111
|
+
e.stopPropagation();
|
|
112
|
+
_a.dragged = this;
|
|
113
|
+
this.classList.add('dragging');
|
|
114
|
+
e.dataTransfer?.setData('text/plain', this.label);
|
|
115
|
+
if (e.dataTransfer)
|
|
116
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
117
|
+
}, _CmNestedItem_onDragOver = function _CmNestedItem_onDragOver(e) {
|
|
118
|
+
const d = _a.dragged;
|
|
119
|
+
if (!d || d === this || d.parentElement !== this.parentElement)
|
|
120
|
+
return;
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
e.stopPropagation();
|
|
123
|
+
const r = this.renderRoot.querySelector('.row').getBoundingClientRect();
|
|
124
|
+
const after = e.clientY > r.top + r.height / 2;
|
|
125
|
+
this.classList.toggle('drop-after', after);
|
|
126
|
+
this.classList.toggle('drop-before', !after);
|
|
127
|
+
}, _CmNestedItem_clearDrop = function _CmNestedItem_clearDrop() { this.classList.remove('drop-before', 'drop-after'); }, _CmNestedItem_onDrop = function _CmNestedItem_onDrop(e) {
|
|
128
|
+
const d = _a.dragged;
|
|
129
|
+
if (!d || d === this || d.parentElement !== this.parentElement)
|
|
130
|
+
return;
|
|
131
|
+
e.preventDefault();
|
|
132
|
+
e.stopPropagation();
|
|
133
|
+
const after = this.classList.contains('drop-after');
|
|
134
|
+
__classPrivateFieldGet(this, _CmNestedItem_instances, "m", _CmNestedItem_clearDrop).call(this);
|
|
135
|
+
const sibs = this.siblings;
|
|
136
|
+
const from = sibs.indexOf(d);
|
|
137
|
+
let to = sibs.indexOf(this) + (after ? 1 : 0);
|
|
138
|
+
if (to > from)
|
|
139
|
+
to -= 1;
|
|
140
|
+
d.moveTo(to);
|
|
141
|
+
};
|
|
142
|
+
CmNestedItem.properties = {
|
|
143
|
+
label: {},
|
|
144
|
+
value: { reflect: true },
|
|
145
|
+
sortable: { type: Boolean, reflect: true },
|
|
146
|
+
_hasChildren: { state: true },
|
|
147
|
+
};
|
|
148
|
+
CmNestedItem.styles = [
|
|
149
|
+
base,
|
|
150
|
+
css `
|
|
151
|
+
:host { display: block; }
|
|
152
|
+
.row {
|
|
153
|
+
display: flex; align-items: center; gap: var(--cm-space-15); min-height: 60px; padding: 0 var(--cm-space-20);
|
|
154
|
+
background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-default); border-radius: var(--cm-radius-md);
|
|
155
|
+
font-size: 16px; font-weight: 500;
|
|
156
|
+
}
|
|
157
|
+
:host(.dragging) .row { opacity: 0.5; }
|
|
158
|
+
:host(.drop-before) .row { box-shadow: 0 -3px 0 var(--cm-border-strong); }
|
|
159
|
+
:host(.drop-after) .row { box-shadow: 0 3px 0 var(--cm-border-strong); }
|
|
160
|
+
.label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
|
|
161
|
+
.actions { display: flex; align-items: center; gap: var(--cm-space-15); }
|
|
162
|
+
.handle {
|
|
163
|
+
display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 34px; margin-left: -6px; padding: 0;
|
|
164
|
+
color: var(--cm-icon-selected); background: none; border: 0; border-radius: var(--cm-radius-xs); cursor: grab;
|
|
165
|
+
}
|
|
166
|
+
.handle:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
167
|
+
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
168
|
+
.children { margin: var(--cm-space-10) 0 0 50px; display: flex; flex-direction: column; gap: var(--cm-space-10); }
|
|
169
|
+
.children:not(.has) { display: none; }
|
|
170
|
+
@media (max-width: 640px) {
|
|
171
|
+
.row { min-height: 50px; padding: 0 var(--cm-space-10); gap: var(--cm-space-10); font-size: 14px; }
|
|
172
|
+
.actions { gap: var(--cm-space-10); }
|
|
173
|
+
.children { margin-left: var(--cm-space-20); }
|
|
174
|
+
}
|
|
175
|
+
`,
|
|
176
|
+
];
|
|
177
|
+
CmNestedItem.dragged = null;
|
|
178
|
+
define('cm-nested-item', CmNestedItem);
|
|
179
|
+
/**
|
|
180
|
+
* A titled group of rows that nest inside each other, such as a navigation menu with links and
|
|
181
|
+
* sub-links, or categories and sub-categories. The heading sits in a 90px grey bar with its own
|
|
182
|
+
* actions; rows below are indented one step per level. With `sortable`, each row gets a drag
|
|
183
|
+
* handle that also works from the keyboard (↑/↓, Home/End). With `collapsible`, the bar gets a
|
|
184
|
+
* round button that shows and hides the rows.
|
|
185
|
+
* @element cm-nested-list
|
|
186
|
+
* @slot - `cm-nested-item` rows.
|
|
187
|
+
* @slot actions - Controls in the heading bar, e.g. an "Add links" button or a toggle.
|
|
188
|
+
* @fires cm-reorder - When a row is moved. See `cm-nested-item`.
|
|
189
|
+
* @fires cm-toggle - `detail: { open }` when a collapsible list is shown or hidden.
|
|
190
|
+
*/
|
|
191
|
+
export class CmNestedList extends LitElement {
|
|
192
|
+
constructor() {
|
|
193
|
+
super(...arguments);
|
|
194
|
+
_CmNestedList_instances.add(this);
|
|
195
|
+
/** Title in the grey bar, e.g. "Header" or "Clothing & accessories". */
|
|
196
|
+
this.heading = '';
|
|
197
|
+
/** Heading level for the title (1–6). */
|
|
198
|
+
this.headingLevel = 2;
|
|
199
|
+
/** Rows get drag handles and can be reordered among their siblings. */
|
|
200
|
+
this.sortable = false;
|
|
201
|
+
/** Adds a show/hide button to the heading bar. */
|
|
202
|
+
this.collapsible = false;
|
|
203
|
+
/** Whether the rows are shown when `collapsible`. */
|
|
204
|
+
this.open = true;
|
|
205
|
+
this._msg = '';
|
|
206
|
+
_CmNestedList_id.set(this, nextId('cm-nl'));
|
|
207
|
+
}
|
|
208
|
+
/** Reads a message to screen readers, e.g. after a move. */
|
|
209
|
+
announce(msg) {
|
|
210
|
+
this._msg = '';
|
|
211
|
+
requestAnimationFrame(() => (this._msg = msg));
|
|
212
|
+
}
|
|
213
|
+
updated(changed) {
|
|
214
|
+
if (changed.has('sortable'))
|
|
215
|
+
__classPrivateFieldGet(this, _CmNestedList_instances, "m", _CmNestedList_syncSortable).call(this);
|
|
216
|
+
}
|
|
217
|
+
render() {
|
|
218
|
+
const level = Math.min(6, Math.max(1, this.headingLevel || 2));
|
|
219
|
+
const shown = !this.collapsible || this.open;
|
|
220
|
+
return html `
|
|
221
|
+
<div class="bar" part="bar">
|
|
222
|
+
<div class="title" part="heading" role="heading" aria-level=${level} id="${__classPrivateFieldGet(this, _CmNestedList_id, "f")}-h">${this.heading}</div>
|
|
223
|
+
<span class="actions"><slot name="actions"></slot></span>
|
|
224
|
+
${this.collapsible
|
|
225
|
+
? html `<button class="toggle" type="button" part="toggle" aria-expanded=${shown ? 'true' : 'false'} aria-controls="${__classPrivateFieldGet(this, _CmNestedList_id, "f")}-rows"
|
|
226
|
+
aria-label=${`${shown ? 'Hide' : 'Show'} ${this.heading}`} @click=${__classPrivateFieldGet(this, _CmNestedList_instances, "m", _CmNestedList_toggle)}>
|
|
227
|
+
<cm-icon name=${shown ? 'chevron-up' : 'chevron-down'} size="14"></cm-icon></button>`
|
|
228
|
+
: nothing}
|
|
229
|
+
</div>
|
|
230
|
+
<div class="rows" id="${__classPrivateFieldGet(this, _CmNestedList_id, "f")}-rows" role="list" aria-labelledby="${__classPrivateFieldGet(this, _CmNestedList_id, "f")}-h" ?hidden=${!shown}>
|
|
231
|
+
<slot @slotchange=${() => __classPrivateFieldGet(this, _CmNestedList_instances, "m", _CmNestedList_syncSortable).call(this)}></slot>
|
|
232
|
+
</div>
|
|
233
|
+
<span class="sr" role="status">${this._msg}</span>
|
|
234
|
+
`;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
_CmNestedList_id = new WeakMap(), _CmNestedList_instances = new WeakSet(), _CmNestedList_toggle = function _CmNestedList_toggle() {
|
|
238
|
+
this.open = !this.open;
|
|
239
|
+
this.dispatchEvent(new CustomEvent('cm-toggle', { detail: { open: this.open }, bubbles: true, composed: true }));
|
|
240
|
+
}, _CmNestedList_syncSortable = function _CmNestedList_syncSortable() {
|
|
241
|
+
[...this.children].forEach((k) => { if (k.localName === 'cm-nested-item')
|
|
242
|
+
k.sortable = this.sortable; });
|
|
243
|
+
};
|
|
244
|
+
CmNestedList.properties = {
|
|
245
|
+
heading: {},
|
|
246
|
+
headingLevel: { type: Number, attribute: 'heading-level' },
|
|
247
|
+
sortable: { type: Boolean, reflect: true },
|
|
248
|
+
collapsible: { type: Boolean, reflect: true },
|
|
249
|
+
open: { type: Boolean, reflect: true },
|
|
250
|
+
_msg: { state: true },
|
|
251
|
+
};
|
|
252
|
+
CmNestedList.styles = [
|
|
253
|
+
base,
|
|
254
|
+
css `
|
|
255
|
+
:host { display: block; }
|
|
256
|
+
.bar {
|
|
257
|
+
display: flex; align-items: center; gap: var(--cm-space-15); min-height: 90px; padding: 0 var(--cm-space-20);
|
|
258
|
+
background: var(--cm-bg-page); border-radius: var(--cm-radius-md);
|
|
259
|
+
}
|
|
260
|
+
.title { flex: 1; min-width: 0; margin: 0; font-size: 26px; font-weight: 500; line-height: 1.3; }
|
|
261
|
+
.actions { display: flex; align-items: center; gap: var(--cm-space-15); }
|
|
262
|
+
.toggle {
|
|
263
|
+
display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0; flex: none;
|
|
264
|
+
color: var(--cm-action-primary-text); background: var(--cm-action-primary); border: 0; border-radius: var(--cm-radius-full); cursor: pointer;
|
|
265
|
+
}
|
|
266
|
+
.toggle:hover { background: var(--cm-action-primary-hover); }
|
|
267
|
+
.toggle:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
268
|
+
.rows { display: flex; flex-direction: column; gap: var(--cm-space-10); margin: var(--cm-space-15) 0 0 50px; }
|
|
269
|
+
.rows[hidden] { display: none; }
|
|
270
|
+
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
|
271
|
+
@media (max-width: 640px) {
|
|
272
|
+
.bar { min-height: 60px; padding: 0 var(--cm-space-10); gap: var(--cm-space-10); }
|
|
273
|
+
.title { font-size: 18px; }
|
|
274
|
+
.rows { margin-left: var(--cm-space-10); }
|
|
275
|
+
.toggle { width: 30px; height: 30px; }
|
|
276
|
+
}
|
|
277
|
+
`,
|
|
278
|
+
];
|
|
279
|
+
define('cm-nested-list', CmNestedList);
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
import { type Tone } from '../base.js';
|
|
3
|
+
import { CmOverlay } from '../overlay.js';
|
|
4
|
+
import './icon.js';
|
|
5
|
+
/** One notification in `cm-notification-panel`. */
|
|
6
|
+
export interface NotificationItem {
|
|
7
|
+
/** What happened: "New order received". */
|
|
8
|
+
label: string;
|
|
9
|
+
/** When, as shown: "1 min ago". */
|
|
10
|
+
time?: string;
|
|
11
|
+
/** Colour and icon: `information` (default), `attention`, `success` or `critical`. */
|
|
12
|
+
tone?: Tone;
|
|
13
|
+
/** Where the notification leads. */
|
|
14
|
+
href?: string;
|
|
15
|
+
/** Not read yet: the label is bold and "Unread" is read out. */
|
|
16
|
+
unread?: boolean;
|
|
17
|
+
/** Identifies it in `cm-select`. Defaults to the href, then the label. */
|
|
18
|
+
value?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A notification in markup, read by `cm-notification-panel`. Its text is the label. Renders nothing itself.
|
|
22
|
+
* @element cm-notification-item
|
|
23
|
+
*/
|
|
24
|
+
export declare class CmNotificationItem extends LitElement {
|
|
25
|
+
static properties: {
|
|
26
|
+
time: {
|
|
27
|
+
reflect: boolean;
|
|
28
|
+
};
|
|
29
|
+
tone: {
|
|
30
|
+
reflect: boolean;
|
|
31
|
+
};
|
|
32
|
+
href: {
|
|
33
|
+
reflect: boolean;
|
|
34
|
+
};
|
|
35
|
+
unread: {
|
|
36
|
+
type: BooleanConstructor;
|
|
37
|
+
reflect: boolean;
|
|
38
|
+
};
|
|
39
|
+
value: {
|
|
40
|
+
reflect: boolean;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/** When, as shown: "1 min ago". */
|
|
44
|
+
time: string;
|
|
45
|
+
/** `information` (default), `attention`, `success` or `critical`. */
|
|
46
|
+
tone: Tone;
|
|
47
|
+
/** Where the notification leads. */
|
|
48
|
+
href: string;
|
|
49
|
+
/** Not read yet. */
|
|
50
|
+
unread: boolean;
|
|
51
|
+
/** Identifies it in `cm-select`. */
|
|
52
|
+
value: string;
|
|
53
|
+
static styles: import("lit").CSSResult;
|
|
54
|
+
render(): null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The list of recent notifications, opened from the bell in the header bar: a panel under the top-right corner
|
|
58
|
+
* of the page with a black "Notifications" header, one row per notification (a coloured icon for its kind,
|
|
59
|
+
* what happened, and when), and "See more notifications" at the bottom. On phones it spans the screen width.
|
|
60
|
+
*
|
|
61
|
+
* A native modal `<dialog>`: the page behind is dimmed and inert, Esc and the backdrop ask to close through
|
|
62
|
+
* `cm-close`, scrolling is locked, and focus returns to the bell.
|
|
63
|
+
* @element cm-notification-panel
|
|
64
|
+
* @slot - `cm-notification-item`s.
|
|
65
|
+
* @fires cm-select - When a notification is chosen. `detail: { value, item }`. Cancelable: `preventDefault()` stops a link, to route in your app.
|
|
66
|
+
* @fires cm-open - After the panel opens.
|
|
67
|
+
* @fires cm-close - Before it closes. `detail: { reason }`. Cancelable.
|
|
68
|
+
* @fires cm-closed - After it has closed.
|
|
69
|
+
*/
|
|
70
|
+
export declare class CmNotificationPanel extends CmOverlay {
|
|
71
|
+
#private;
|
|
72
|
+
static properties: {
|
|
73
|
+
items: {
|
|
74
|
+
type: ArrayConstructor;
|
|
75
|
+
};
|
|
76
|
+
moreHref: {
|
|
77
|
+
attribute: string;
|
|
78
|
+
};
|
|
79
|
+
moreLabel: {
|
|
80
|
+
attribute: string;
|
|
81
|
+
};
|
|
82
|
+
emptyText: {
|
|
83
|
+
attribute: string;
|
|
84
|
+
};
|
|
85
|
+
_slotted: {
|
|
86
|
+
state: boolean;
|
|
87
|
+
};
|
|
88
|
+
open: {
|
|
89
|
+
type: BooleanConstructor;
|
|
90
|
+
reflect: boolean;
|
|
91
|
+
};
|
|
92
|
+
heading: {};
|
|
93
|
+
label: {};
|
|
94
|
+
closeLabel: {
|
|
95
|
+
attribute: string;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
/** Title in the header. */
|
|
99
|
+
heading: string;
|
|
100
|
+
/** Notifications as data, used instead of children when set. */
|
|
101
|
+
items: NotificationItem[];
|
|
102
|
+
/** Link to all notifications. Empty hides it. */
|
|
103
|
+
moreHref: string;
|
|
104
|
+
/** Text of that link. */
|
|
105
|
+
moreLabel: string;
|
|
106
|
+
/** Shown when there are no notifications. */
|
|
107
|
+
emptyText: string;
|
|
108
|
+
_slotted: NotificationItem[];
|
|
109
|
+
static styles: import("lit").CSSResult[];
|
|
110
|
+
connectedCallback(): void;
|
|
111
|
+
disconnectedCallback(): void;
|
|
112
|
+
/** The notifications in use. */
|
|
113
|
+
get notifications(): NotificationItem[];
|
|
114
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
115
|
+
}
|
|
116
|
+
declare global {
|
|
117
|
+
interface HTMLElementTagNameMap {
|
|
118
|
+
'cm-notification-panel': CmNotificationPanel;
|
|
119
|
+
'cm-notification-item': CmNotificationItem;
|
|
120
|
+
}
|
|
121
|
+
}
|