@commmerce/ui 1.20.4 → 1.21.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.
|
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _CmAppFrame_instances, _CmAppFrame_ro, _CmAppFrame_returnFocus, _CmAppFrame_heights, _CmAppFrame_set, _CmAppFrame_slotOf, _CmAppFrame_onNavigate, _CmAppFrame_onKey;
|
|
12
|
+
var _CmAppFrame_instances, _CmAppFrame_ro, _CmAppFrame_returnFocus, _CmAppFrame_heights, _CmAppFrame_syncBottom, _CmAppFrame_set, _CmAppFrame_slotOf, _CmAppFrame_onNavigate, _CmAppFrame_onKey;
|
|
13
13
|
import { LitElement, html, css } from 'lit';
|
|
14
14
|
import { base, define } from '../base.js';
|
|
15
15
|
/** Frames at least this wide show the side navigation; narrower ones show the bottom navigation. */
|
|
@@ -128,6 +128,8 @@ export class CmAppFrame extends LitElement {
|
|
|
128
128
|
updated(changed) {
|
|
129
129
|
if (changed.has('_wide'))
|
|
130
130
|
__classPrivateFieldGet(this, _CmAppFrame_instances, "m", _CmAppFrame_heights).call(this);
|
|
131
|
+
if (changed.has('menuOpen') || changed.has('menuItem'))
|
|
132
|
+
__classPrivateFieldGet(this, _CmAppFrame_instances, "m", _CmAppFrame_syncBottom).call(this);
|
|
131
133
|
}
|
|
132
134
|
/** Opens the mobile menu and moves focus into it. */
|
|
133
135
|
openMenu() { __classPrivateFieldGet(this, _CmAppFrame_instances, "m", _CmAppFrame_set).call(this, true); }
|
|
@@ -147,7 +149,7 @@ export class CmAppFrame extends LitElement {
|
|
|
147
149
|
<main part="main" ?inert=${covered}><slot></slot></main>
|
|
148
150
|
</div>
|
|
149
151
|
<div class="menu" part="mobile-menu" ?hidden=${!covered}><slot name="mobile-menu" @slotchange=${() => this.requestUpdate()}></slot></div>
|
|
150
|
-
<div class="bottom" part="bottom-navigation" ?hidden=${wide}><slot name="bottom-navigation"></slot></div>
|
|
152
|
+
<div class="bottom" part="bottom-navigation" ?hidden=${wide}><slot name="bottom-navigation" @slotchange=${() => __classPrivateFieldGet(this, _CmAppFrame_instances, "m", _CmAppFrame_syncBottom).call(this)}></slot></div>
|
|
151
153
|
</div>`;
|
|
152
154
|
}
|
|
153
155
|
}
|
|
@@ -158,6 +160,14 @@ _CmAppFrame_ro = new WeakMap(), _CmAppFrame_returnFocus = new WeakMap(), _CmAppF
|
|
|
158
160
|
const h = (sel) => Math.round(this.renderRoot.querySelector(sel)?.getBoundingClientRect().height ?? 0);
|
|
159
161
|
frame.style.setProperty('--_header', `${h('.header')}px`);
|
|
160
162
|
frame.style.setProperty('--_bottom', `${this._wide ? 0 : h('.bottom')}px`);
|
|
163
|
+
}, _CmAppFrame_syncBottom = function _CmAppFrame_syncBottom() {
|
|
164
|
+
if (!this.menuItem)
|
|
165
|
+
return;
|
|
166
|
+
const bar = this.querySelector(':scope > [slot="bottom-navigation"]');
|
|
167
|
+
if (!bar)
|
|
168
|
+
return;
|
|
169
|
+
bar.menuItem = this.menuItem;
|
|
170
|
+
bar.menuOpen = this.menuOpen;
|
|
161
171
|
}, _CmAppFrame_set = function _CmAppFrame_set(open, restore = true) {
|
|
162
172
|
if (open === this.menuOpen)
|
|
163
173
|
return;
|
|
@@ -17,6 +17,10 @@ declare module '../localize.js' {
|
|
|
17
17
|
*
|
|
18
18
|
* Items come from `cm-nav-item` children or the `items` property. Mark the main action `primary`
|
|
19
19
|
* (Quick add) to draw its icon as a black square.
|
|
20
|
+
*
|
|
21
|
+
* Set `menu-item` to the value of the item that opens the Mobile menu, and `menu-open` while it is open: that item
|
|
22
|
+
* then shows as the current tab and reports `aria-expanded`. Inside `cm-app-frame` with its own `menu-item`, the
|
|
23
|
+
* frame sets both for you.
|
|
20
24
|
* @element cm-bottom-navigation
|
|
21
25
|
* @slot - `cm-nav-item` elements (no nesting).
|
|
22
26
|
* @fires cm-navigate - When an item is chosen. `detail: { item, value, href }`. Cancelable: call `preventDefault()` to route in your app. Items without `href` only fire this event (e.g. "More" opens the Mobile menu).
|
|
@@ -34,6 +38,14 @@ export declare class CmBottomNavigation extends CmLocalizedElement {
|
|
|
34
38
|
type: BooleanConstructor;
|
|
35
39
|
reflect: boolean;
|
|
36
40
|
};
|
|
41
|
+
menuItem: {
|
|
42
|
+
attribute: string;
|
|
43
|
+
};
|
|
44
|
+
menuOpen: {
|
|
45
|
+
type: BooleanConstructor;
|
|
46
|
+
attribute: string;
|
|
47
|
+
reflect: boolean;
|
|
48
|
+
};
|
|
37
49
|
_slotted: {
|
|
38
50
|
state: boolean;
|
|
39
51
|
};
|
|
@@ -44,6 +56,10 @@ export declare class CmBottomNavigation extends CmLocalizedElement {
|
|
|
44
56
|
label: string;
|
|
45
57
|
/** Pins the bar to the bottom of the viewport, above the device's home indicator. */
|
|
46
58
|
fixed: boolean;
|
|
59
|
+
/** Value of the item that opens the Mobile menu (usually `more`). It gets `aria-expanded`. */
|
|
60
|
+
menuItem: string;
|
|
61
|
+
/** The Mobile menu is open: the `menu-item` shows as the current tab instead of the page's own tab. */
|
|
62
|
+
menuOpen: boolean;
|
|
47
63
|
_slotted: NavItem[];
|
|
48
64
|
static styles: import("lit").CSSResult[];
|
|
49
65
|
connectedCallback(): void;
|
|
@@ -26,6 +26,10 @@ const strings = defineStrings('bottomNavigation', {
|
|
|
26
26
|
*
|
|
27
27
|
* Items come from `cm-nav-item` children or the `items` property. Mark the main action `primary`
|
|
28
28
|
* (Quick add) to draw its icon as a black square.
|
|
29
|
+
*
|
|
30
|
+
* Set `menu-item` to the value of the item that opens the Mobile menu, and `menu-open` while it is open: that item
|
|
31
|
+
* then shows as the current tab and reports `aria-expanded`. Inside `cm-app-frame` with its own `menu-item`, the
|
|
32
|
+
* frame sets both for you.
|
|
29
33
|
* @element cm-bottom-navigation
|
|
30
34
|
* @slot - `cm-nav-item` elements (no nesting).
|
|
31
35
|
* @fires cm-navigate - When an item is chosen. `detail: { item, value, href }`. Cancelable: call `preventDefault()` to route in your app. Items without `href` only fire this event (e.g. "More" opens the Mobile menu).
|
|
@@ -38,6 +42,10 @@ export class CmBottomNavigation extends CmLocalizedElement {
|
|
|
38
42
|
this.items = [];
|
|
39
43
|
/** Pins the bar to the bottom of the viewport, above the device's home indicator. */
|
|
40
44
|
this.fixed = false;
|
|
45
|
+
/** Value of the item that opens the Mobile menu (usually `more`). It gets `aria-expanded`. */
|
|
46
|
+
this.menuItem = '';
|
|
47
|
+
/** The Mobile menu is open: the `menu-item` shows as the current tab instead of the page's own tab. */
|
|
48
|
+
this.menuOpen = false;
|
|
41
49
|
this._slotted = [];
|
|
42
50
|
_CmBottomNavigation_observer.set(this, void 0);
|
|
43
51
|
}
|
|
@@ -60,18 +68,24 @@ export class CmBottomNavigation extends CmLocalizedElement {
|
|
|
60
68
|
}
|
|
61
69
|
}
|
|
62
70
|
_CmBottomNavigation_observer = new WeakMap(), _CmBottomNavigation_instances = new WeakSet(), _CmBottomNavigation_read = function _CmBottomNavigation_read() { this._slotted = readNavItems(this); }, _CmBottomNavigation_item = function _CmBottomNavigation_item(it) {
|
|
63
|
-
const
|
|
71
|
+
const isMenu = !!this.menuItem && it.value === this.menuItem;
|
|
72
|
+
// While the menu is open it covers the page, so its tab is the one shown as current (aria-current stays on the page).
|
|
73
|
+
const on = this.menuOpen && this.menuItem ? isMenu : !!it.current;
|
|
74
|
+
const cls = `item ${it.primary ? 'primary' : ''} ${on ? 'on' : ''}`;
|
|
64
75
|
const inner = html `<span class="icon">${it.icon ? html `<cm-icon name=${it.icon} size=${it.primary ? 16 : 20}></cm-icon>` : nothing}</span><span class="label">${it.label}</span>`;
|
|
65
76
|
const go = (e) => { if (!fireNavigate(this, it))
|
|
66
77
|
e.preventDefault(); };
|
|
67
78
|
return it.href
|
|
68
79
|
? html `<a class=${cls} part="item" href=${it.href} aria-current=${it.current ? 'page' : nothing} @click=${go}>${inner}</a>`
|
|
69
|
-
: html `<button type="button" class=${cls} part="item" aria-current=${it.current ? 'page' : nothing}
|
|
80
|
+
: html `<button type="button" class=${cls} part="item" aria-current=${it.current ? 'page' : nothing}
|
|
81
|
+
aria-expanded=${isMenu ? String(this.menuOpen) : nothing} @click=${go}>${inner}</button>`;
|
|
70
82
|
};
|
|
71
83
|
CmBottomNavigation.properties = {
|
|
72
84
|
items: { type: Array },
|
|
73
85
|
label: { string: 'label' },
|
|
74
86
|
fixed: { type: Boolean, reflect: true },
|
|
87
|
+
menuItem: { attribute: 'menu-item' },
|
|
88
|
+
menuOpen: { type: Boolean, attribute: 'menu-open', reflect: true },
|
|
75
89
|
_slotted: { state: true },
|
|
76
90
|
};
|
|
77
91
|
CmBottomNavigation.styles = [
|
|
@@ -92,10 +106,10 @@ CmBottomNavigation.styles = [
|
|
|
92
106
|
font: inherit; font-size: var(--cm-font-size-12); line-height: var(--cm-line-height-12); font-weight: 500;
|
|
93
107
|
color: var(--cm-text-tertiary); text-decoration: none; background: none; border: 0; border-radius: var(--cm-radius-sm); cursor: pointer;
|
|
94
108
|
}
|
|
95
|
-
.item:hover, .item
|
|
109
|
+
.item:hover, .item.on { color: var(--cm-text-default); }
|
|
96
110
|
/* The current tab (1.19, from the CRM): bold label and a tinted pill behind the icon, so it shows in every look. */
|
|
97
|
-
.item
|
|
98
|
-
.item
|
|
111
|
+
.item.on { font-weight: 600; }
|
|
112
|
+
.item.on:not(.primary) .icon { background: var(--cm-bg-selected); color: var(--cm-icon-selected); }
|
|
99
113
|
.item:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 0; }
|
|
100
114
|
.icon { display: grid; place-items: center; width: calc(var(--cm-space-48) + var(--cm-space-8)); height: calc(var(--cm-space-24) + var(--cm-space-4)); border-radius: var(--cm-radius-full); }
|
|
101
115
|
.primary .icon { width: var(--cm-icon-size-lg); height: var(--cm-icon-size-lg); }
|
|
@@ -668,6 +668,7 @@ _CmCalendar_localeProp = new WeakMap(), _CmCalendar_id = new WeakMap(), _CmCalen
|
|
|
668
668
|
return Array.from({ length: n }, (_, i) => addDays(s, i));
|
|
669
669
|
}, _CmCalendar_parse = function _CmCalendar_parse(el) {
|
|
670
670
|
const name = el.name;
|
|
671
|
+
const text = el.heading || (el.textContent ?? '').replace(/\s+/g, ' ').trim() || name;
|
|
671
672
|
const dateOnly = !!fromISO(el.start);
|
|
672
673
|
const allDay = el.allDay || dateOnly;
|
|
673
674
|
if (allDay) {
|
|
@@ -678,7 +679,7 @@ _CmCalendar_localeProp = new WeakMap(), _CmCalendar_id = new WeakMap(), _CmCalen
|
|
|
678
679
|
if (e < s)
|
|
679
680
|
e = s;
|
|
680
681
|
const n = Math.min(dayDiff(s, e), 366);
|
|
681
|
-
return { el, key: el.key, name, allDay, start: s, end: e, min: 0, dur: 1440, days: Array.from({ length: n + 1 }, (_, i) => toISO(addDays(s, i))) };
|
|
682
|
+
return { el, key: el.key, name, text, allDay, start: s, end: e, min: 0, dur: 1440, days: Array.from({ length: n + 1 }, (_, i) => toISO(addDays(s, i))) };
|
|
682
683
|
}
|
|
683
684
|
const s = fromISODateTime(el.start);
|
|
684
685
|
if (!s)
|
|
@@ -687,7 +688,7 @@ _CmCalendar_localeProp = new WeakMap(), _CmCalendar_id = new WeakMap(), _CmCalen
|
|
|
687
688
|
if (!e || e <= s)
|
|
688
689
|
e = new Date(s.getTime() + 30 * 60000);
|
|
689
690
|
const dur = Math.max(1, Math.round((e.getTime() - s.getTime()) / 60000));
|
|
690
|
-
return { el, key: el.key, name, allDay, start: s, end: e, min: s.getHours() * 60 + s.getMinutes(), dur, days: [toISO(s)] };
|
|
691
|
+
return { el, key: el.key, name, text, allDay, start: s, end: e, min: s.getHours() * 60 + s.getMinutes(), dur, days: [toISO(s)] };
|
|
691
692
|
}, _CmCalendar_parsed = function _CmCalendar_parsed() {
|
|
692
693
|
return this.events.map((e) => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_parse).call(this, e)).filter((e) => !!e);
|
|
693
694
|
}, _CmCalendar_byDay = function _CmCalendar_byDay(evs) {
|
|
@@ -1119,8 +1120,8 @@ _CmCalendar_localeProp = new WeakMap(), _CmCalendar_id = new WeakMap(), _CmCalen
|
|
|
1119
1120
|
const kind = el.kind && (where !== 'month' || !el.icon) ? html `<span class="k">${el.kind}</span>` : nothing;
|
|
1120
1121
|
const spin = busy ? html `<span class="spin" aria-hidden="true"></span>` : nothing;
|
|
1121
1122
|
const body = where === 'time'
|
|
1122
|
-
? html `<span class="lead">${icon}${time}${spin}</span><span class="h">${ev.
|
|
1123
|
-
: html `${icon}${time}<span class="h">${ev.
|
|
1123
|
+
? html `<span class="lead">${icon}${time}${spin}</span><span class="h">${ev.text}</span>${kind}`
|
|
1124
|
+
: html `${icon}${time}<span class="h">${ev.text}</span>${kind}${spin}`;
|
|
1124
1125
|
const label = busy ? `${name}, ${this.t('saving')}` : name;
|
|
1125
1126
|
const desc = movable ? `${__classPrivateFieldGet(this, _CmCalendar_id, "f")}-mv` : `${__classPrivateFieldGet(this, _CmCalendar_id, "f")}-op`;
|
|
1126
1127
|
const k = `ev:${ev.key}:${iso}`;
|
|
@@ -1134,7 +1135,7 @@ _CmCalendar_localeProp = new WeakMap(), _CmCalendar_id = new WeakMap(), _CmCalen
|
|
|
1134
1135
|
data-row=${extra.row ?? nothing} aria-label=${label} aria-describedby=${desc} aria-roledescription=${role}
|
|
1135
1136
|
@click=${(e) => __classPrivateFieldGet(this, _CmCalendar_instances, "m", _CmCalendar_open).call(this, e, ev)}>${body}</button>`;
|
|
1136
1137
|
}, _CmCalendar_placeholder = function _CmCalendar_placeholder(ev, cls = '', style) {
|
|
1137
|
-
return html `<div class="ph ${cls}" style=${style ?? nothing} aria-hidden="true">${ev.
|
|
1138
|
+
return html `<div class="ph ${cls}" style=${style ?? nothing} aria-hidden="true">${ev.text}</div>`;
|
|
1138
1139
|
}, _CmCalendar_header = function _CmCalendar_header(days) {
|
|
1139
1140
|
const v = __classPrivateFieldGet(this, _CmCalendar_instances, "a", _CmCalendar_view_get);
|
|
1140
1141
|
const narrowWeek = v === 'week' && this._narrow;
|
|
@@ -2646,6 +2646,12 @@
|
|
|
2646
2646
|
"name": "#heights",
|
|
2647
2647
|
"privacy": "private"
|
|
2648
2648
|
},
|
|
2649
|
+
{
|
|
2650
|
+
"kind": "method",
|
|
2651
|
+
"name": "#syncBottom",
|
|
2652
|
+
"privacy": "private",
|
|
2653
|
+
"description": "Tells the bottom navigation which item opens the menu and whether it is open, so that item shows as current."
|
|
2654
|
+
},
|
|
2649
2655
|
{
|
|
2650
2656
|
"kind": "method",
|
|
2651
2657
|
"name": "openMenu",
|
|
@@ -4885,7 +4891,7 @@
|
|
|
4885
4891
|
"declarations": [
|
|
4886
4892
|
{
|
|
4887
4893
|
"kind": "class",
|
|
4888
|
-
"description": "The admin's tab bar on phones and small tablets: up to five destinations with an icon over a short\nlabel, in a white bar with rounded top corners. The last item (\"More\") usually opens the Mobile menu.\nFor Commmerce products only, not for apps.\n\nItems come from `cm-nav-item` children or the `items` property. Mark the main action `primary`\n(Quick add) to draw its icon as a black square.",
|
|
4894
|
+
"description": "The admin's tab bar on phones and small tablets: up to five destinations with an icon over a short\nlabel, in a white bar with rounded top corners. The last item (\"More\") usually opens the Mobile menu.\nFor Commmerce products only, not for apps.\n\nItems come from `cm-nav-item` children or the `items` property. Mark the main action `primary`\n(Quick add) to draw its icon as a black square.\n\nSet `menu-item` to the value of the item that opens the Mobile menu, and `menu-open` while it is open: that item\nthen shows as the current tab and reports `aria-expanded`. Inside `cm-app-frame` with its own `menu-item`, the\nframe sets both for you.",
|
|
4889
4895
|
"name": "CmBottomNavigation",
|
|
4890
4896
|
"slots": [
|
|
4891
4897
|
{
|
|
@@ -4927,6 +4933,29 @@
|
|
|
4927
4933
|
"attribute": "fixed",
|
|
4928
4934
|
"reflects": true
|
|
4929
4935
|
},
|
|
4936
|
+
{
|
|
4937
|
+
"kind": "field",
|
|
4938
|
+
"name": "menuItem",
|
|
4939
|
+
"privacy": "public",
|
|
4940
|
+
"type": {
|
|
4941
|
+
"text": "string"
|
|
4942
|
+
},
|
|
4943
|
+
"default": "''",
|
|
4944
|
+
"description": "Value of the item that opens the Mobile menu (usually `more`). It gets `aria-expanded`.",
|
|
4945
|
+
"attribute": "menu-item"
|
|
4946
|
+
},
|
|
4947
|
+
{
|
|
4948
|
+
"kind": "field",
|
|
4949
|
+
"name": "menuOpen",
|
|
4950
|
+
"privacy": "public",
|
|
4951
|
+
"type": {
|
|
4952
|
+
"text": "boolean"
|
|
4953
|
+
},
|
|
4954
|
+
"default": "false",
|
|
4955
|
+
"description": "The Mobile menu is open: the `menu-item` shows as the current tab instead of the page's own tab.",
|
|
4956
|
+
"attribute": "menu-open",
|
|
4957
|
+
"reflects": true
|
|
4958
|
+
},
|
|
4930
4959
|
{
|
|
4931
4960
|
"kind": "field",
|
|
4932
4961
|
"name": "_slotted",
|
|
@@ -5102,6 +5131,24 @@
|
|
|
5102
5131
|
"description": "Pins the bar to the bottom of the viewport, above the device's home indicator.",
|
|
5103
5132
|
"fieldName": "fixed"
|
|
5104
5133
|
},
|
|
5134
|
+
{
|
|
5135
|
+
"name": "menu-item",
|
|
5136
|
+
"type": {
|
|
5137
|
+
"text": "string"
|
|
5138
|
+
},
|
|
5139
|
+
"default": "''",
|
|
5140
|
+
"description": "Value of the item that opens the Mobile menu (usually `more`). It gets `aria-expanded`.",
|
|
5141
|
+
"fieldName": "menuItem"
|
|
5142
|
+
},
|
|
5143
|
+
{
|
|
5144
|
+
"name": "menu-open",
|
|
5145
|
+
"type": {
|
|
5146
|
+
"text": "boolean"
|
|
5147
|
+
},
|
|
5148
|
+
"default": "false",
|
|
5149
|
+
"description": "The Mobile menu is open: the `menu-item` shows as the current tab instead of the page's own tab.",
|
|
5150
|
+
"fieldName": "menuOpen"
|
|
5151
|
+
},
|
|
5105
5152
|
{
|
|
5106
5153
|
"name": "_slotted",
|
|
5107
5154
|
"type": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commmerce/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.1",
|
|
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",
|
|
@@ -128,8 +128,8 @@
|
|
|
128
128
|
"test": "vitest run"
|
|
129
129
|
},
|
|
130
130
|
"dependencies": {
|
|
131
|
-
"@commmerce/icons": "1.
|
|
132
|
-
"@commmerce/tokens": "1.
|
|
131
|
+
"@commmerce/icons": "1.21.1",
|
|
132
|
+
"@commmerce/tokens": "1.21.1",
|
|
133
133
|
"lit": "3.2.1"
|
|
134
134
|
},
|
|
135
135
|
"devDependencies": {
|