@commmerce/ui 1.9.0 → 1.9.2

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.
@@ -0,0 +1,118 @@
1
+ import { CmActionMenu } from './action-menu.js';
2
+ import './avatar.js';
3
+ import './icon.js';
4
+ declare const strings: {
5
+ /** Accessible name of the avatar button. {name} is the signed-in person. */
6
+ trigger: string;
7
+ };
8
+ declare module '../localize.js' {
9
+ interface CmStrings {
10
+ accountMenu: typeof strings;
11
+ }
12
+ }
13
+ /**
14
+ * The signed-in person's menu at the end of a Commmerce product's header bar (since 1.9.2): a round avatar button that
15
+ * opens a panel with who is signed in (avatar, name, role and place), the business or store they're working in (its
16
+ * logo, name, kind and plan), then the choices: `cm-menu-item`s such as Settings, Lock screen and Log out. The panel
17
+ * is the action menu's: keyboard, outside click and Escape behave the same, and it opens in the top layer, aligned
18
+ * to the avatar's end edge. Put it in `cm-header-bar`'s `account` slot, so it is always last in the bar.
19
+ * For Commmerce products only, not for apps.
20
+ * @element cm-account-menu
21
+ * @slot - `cm-menu-item` elements (and `cm-menu-item divider`).
22
+ * @slot org-logo - The business's logo (an `<img>`, 40px round). Without it, a store icon on the brand tone is shown.
23
+ * @fires cm-select - When a choice is picked (as on `cm-action-menu`).
24
+ * @csspart trigger - The avatar button.
25
+ * @csspart profile - The signed-in person's row.
26
+ * @csspart org - The business row.
27
+ */
28
+ export declare class CmAccountMenu extends CmActionMenu {
29
+ static properties: {
30
+ name: {};
31
+ avatarSrc: {
32
+ attribute: string;
33
+ };
34
+ meta: {};
35
+ profileHref: {
36
+ attribute: string;
37
+ };
38
+ orgName: {
39
+ attribute: string;
40
+ };
41
+ orgMeta: {
42
+ attribute: string;
43
+ };
44
+ orgHref: {
45
+ attribute: string;
46
+ };
47
+ plan: {};
48
+ items: {
49
+ type: ArrayConstructor;
50
+ };
51
+ open: {
52
+ type: BooleanConstructor;
53
+ reflect: boolean;
54
+ };
55
+ label: {
56
+ string: string;
57
+ };
58
+ triggerLabel: {
59
+ attribute: string;
60
+ };
61
+ iconOnly: {
62
+ type: BooleanConstructor;
63
+ attribute: string;
64
+ };
65
+ icon: {};
66
+ align: {
67
+ reflect: boolean;
68
+ };
69
+ heading: {};
70
+ subheading: {};
71
+ density: {
72
+ reflect: boolean;
73
+ };
74
+ loading: {
75
+ type: BooleanConstructor;
76
+ reflect: boolean;
77
+ };
78
+ disabled: {
79
+ type: BooleanConstructor;
80
+ reflect: boolean;
81
+ };
82
+ _slotted: {
83
+ state: boolean;
84
+ };
85
+ _active: {
86
+ state: boolean;
87
+ };
88
+ _custom: {
89
+ state: boolean;
90
+ };
91
+ };
92
+ /** The signed-in person's name. Their initials show when there is no `avatar-src`. */
93
+ name: string;
94
+ /** Their photo. */
95
+ avatarSrc: string;
96
+ /** One line under the name: role and place ("Owner · Bangalore"). */
97
+ meta: string;
98
+ /** Their profile page; makes the row a link with a chevron. */
99
+ profileHref: string;
100
+ /** The business or store they're working in ("Bangalore"). Empty hides the business row. */
101
+ orgName: string;
102
+ /** One line under it ("POS store"). */
103
+ orgMeta: string;
104
+ /** The business's page or switcher; makes the row a link with a chevron. */
105
+ orgHref: string;
106
+ /** The plan, shown under the business with a check ("POS Standard"). */
107
+ plan: string;
108
+ constructor();
109
+ static styles: import("lit").CSSResult[];
110
+ protected triggerTemplate(click: (e: Event) => void, key: (e: KeyboardEvent) => void): import("lit-html").TemplateResult<1>;
111
+ protected headTemplate(): import("lit-html").TemplateResult<1>;
112
+ }
113
+ declare global {
114
+ interface HTMLElementTagNameMap {
115
+ 'cm-account-menu': CmAccountMenu;
116
+ }
117
+ }
118
+ export {};
@@ -0,0 +1,114 @@
1
+ import { html, css, nothing } from 'lit';
2
+ import { define } from '../base.js';
3
+ import { defineStrings } from '../localize.js';
4
+ import { CmActionMenu } from './action-menu.js';
5
+ import './avatar.js';
6
+ import './icon.js';
7
+ const strings = defineStrings('accountMenu', {
8
+ /** Accessible name of the avatar button. {name} is the signed-in person. */
9
+ trigger: 'Account: {name}',
10
+ });
11
+ /**
12
+ * The signed-in person's menu at the end of a Commmerce product's header bar (since 1.9.2): a round avatar button that
13
+ * opens a panel with who is signed in (avatar, name, role and place), the business or store they're working in (its
14
+ * logo, name, kind and plan), then the choices: `cm-menu-item`s such as Settings, Lock screen and Log out. The panel
15
+ * is the action menu's: keyboard, outside click and Escape behave the same, and it opens in the top layer, aligned
16
+ * to the avatar's end edge. Put it in `cm-header-bar`'s `account` slot, so it is always last in the bar.
17
+ * For Commmerce products only, not for apps.
18
+ * @element cm-account-menu
19
+ * @slot - `cm-menu-item` elements (and `cm-menu-item divider`).
20
+ * @slot org-logo - The business's logo (an `<img>`, 40px round). Without it, a store icon on the brand tone is shown.
21
+ * @fires cm-select - When a choice is picked (as on `cm-action-menu`).
22
+ * @csspart trigger - The avatar button.
23
+ * @csspart profile - The signed-in person's row.
24
+ * @csspart org - The business row.
25
+ */
26
+ export class CmAccountMenu extends CmActionMenu {
27
+ constructor() {
28
+ super();
29
+ /** The signed-in person's name. Their initials show when there is no `avatar-src`. */
30
+ this.name = '';
31
+ /** Their photo. */
32
+ this.avatarSrc = '';
33
+ /** One line under the name: role and place ("Owner · Bangalore"). */
34
+ this.meta = '';
35
+ /** Their profile page; makes the row a link with a chevron. */
36
+ this.profileHref = '';
37
+ /** The business or store they're working in ("Bangalore"). Empty hides the business row. */
38
+ this.orgName = '';
39
+ /** One line under it ("POS store"). */
40
+ this.orgMeta = '';
41
+ /** The business's page or switcher; makes the row a link with a chevron. */
42
+ this.orgHref = '';
43
+ /** The plan, shown under the business with a check ("POS Standard"). */
44
+ this.plan = '';
45
+ this.align = 'end';
46
+ }
47
+ triggerTemplate(click, key) {
48
+ return html `<button type="button" class="trigger account" part="trigger" aria-haspopup="menu" aria-expanded=${String(this.open)}
49
+ aria-label=${this.t('trigger', { name: this.name })} ?disabled=${this.disabled} @click=${click} @keydown=${key}>
50
+ <cm-avatar name=${this.name} src=${this.avatarSrc || nothing} decorative></cm-avatar></button>`;
51
+ }
52
+ headTemplate() {
53
+ const row = (href, part, lead, title, sub) => {
54
+ const inner = html `${lead}<span class="who"><strong>${title}</strong>${sub ? html `<span>${sub}</span>` : nothing}</span>${href
55
+ ? html `<cm-icon class="chev" name="chevron-right" size="16"></cm-icon>` : nothing}`;
56
+ return href ? html `<a class="row" part=${part} href=${href}>${inner}</a>` : html `<div class="row" part=${part}>${inner}</div>`;
57
+ };
58
+ return html `<div class="acct">
59
+ ${row(this.profileHref, 'profile', html `<span class="ring"><cm-avatar name=${this.name} src=${this.avatarSrc || nothing} decorative></cm-avatar></span>`, this.name, this.meta)}
60
+ ${this.orgName ? html `<div class="split"></div>
61
+ ${row(this.orgHref, 'org', html `<span class="logo"><slot name="org-logo"><cm-icon name="store" size="20"></cm-icon></slot></span>`, this.orgName, this.orgMeta)}
62
+ ${this.plan ? html `<div class="plan"><cm-icon name="check-circle" size="16"></cm-icon>${this.plan}</div>` : nothing}` : nothing}
63
+ </div>`;
64
+ }
65
+ }
66
+ CmAccountMenu.properties = {
67
+ ...CmActionMenu.properties,
68
+ name: {},
69
+ avatarSrc: { attribute: 'avatar-src' },
70
+ meta: {},
71
+ profileHref: { attribute: 'profile-href' },
72
+ orgName: { attribute: 'org-name' },
73
+ orgMeta: { attribute: 'org-meta' },
74
+ orgHref: { attribute: 'org-href' },
75
+ plan: {},
76
+ };
77
+ CmAccountMenu.styles = [
78
+ ...CmActionMenu.styles,
79
+ css `
80
+ /* The avatar button: 36px round with a ring (40 and a 44px hit area on touch screens). */
81
+ .trigger.account {
82
+ position: relative; width: var(--cm-control-height-md, 36px); height: var(--cm-control-height-md, 36px); min-height: 0; padding: 2px;
83
+ border: var(--cm-border-1) solid var(--cm-border-strong); border-radius: var(--cm-radius-full); background: var(--cm-bg-surface);
84
+ }
85
+ .trigger.account:hover { background: var(--cm-bg-hover); }
86
+ .trigger.account cm-avatar { --cm-avatar-size: 28px; } /* 36 less the 2px gap and 1px ring on each side */
87
+ @media (pointer: coarse) {
88
+ .trigger.account { width: var(--cm-control-height-lg, 40px); height: var(--cm-control-height-lg, 40px); }
89
+ .trigger.account cm-avatar { --cm-avatar-size: 32px; }
90
+ .trigger.account::after { content: ''; position: absolute; inset: -3px; }
91
+ }
92
+ .pop { width: min(320px, calc(100vw - 32px)); }
93
+ .acct { display: flex; flex-direction: column; padding: var(--cm-space-4) 0; margin-bottom: var(--cm-space-4); border-bottom: var(--cm-border-1) solid var(--cm-border-subtle); }
94
+ .row {
95
+ display: flex; align-items: center; gap: var(--cm-space-12); padding: var(--cm-space-8) var(--cm-space-12); border-radius: var(--cm-radius-sm);
96
+ color: var(--cm-text-default); text-decoration: none;
97
+ }
98
+ a.row:hover { background: var(--cm-bg-hover); }
99
+ a.row:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: -2px; }
100
+ .ring { flex: none; display: grid; place-items: center; width: 40px; height: 40px; box-sizing: border-box; padding: 2px; border: var(--cm-border-1) solid var(--cm-border-strong); border-radius: var(--cm-radius-full); }
101
+ .ring cm-avatar { --cm-avatar-size: 34px; }
102
+ .logo { flex: none; display: grid; place-items: center; width: 40px; height: 40px; overflow: hidden; border-radius: var(--cm-radius-full); background: var(--cm-bg-brand, var(--cm-action-primary)); color: var(--cm-text-on-brand, var(--cm-action-primary-text)); }
103
+ ::slotted([slot='org-logo']) { width: 40px; height: 40px; object-fit: cover; }
104
+ .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
105
+ .who strong { font-size: var(--cm-font-size-16); line-height: var(--cm-line-height-16); font-weight: 500; overflow-wrap: anywhere; }
106
+ .who span { font-size: var(--cm-font-size-13); line-height: var(--cm-line-height-13); color: var(--cm-text-tertiary); overflow-wrap: anywhere; }
107
+ .chev { flex: none; color: var(--cm-icon-default); }
108
+ .plan { display: flex; align-items: center; gap: var(--cm-space-8); padding: 0 var(--cm-space-12) var(--cm-space-8); font-size: var(--cm-font-size-13); line-height: var(--cm-line-height-13); color: var(--cm-text-tertiary); }
109
+ .plan cm-icon { color: var(--cm-text-success); }
110
+ .split { height: 0; margin: var(--cm-space-4) var(--cm-space-12); border-top: var(--cm-border-1) solid var(--cm-border-subtle); }
111
+ :host(:dir(rtl)) .chev { transform: scaleX(-1); }
112
+ `,
113
+ ];
114
+ define('cm-account-menu', CmAccountMenu);
@@ -119,6 +119,10 @@ export declare class CmActionMenu extends CmLocalizedElement {
119
119
  /** Closes the menu. With `returnFocus`, focus goes back to the trigger. */
120
120
  hide(returnFocus?: boolean): void;
121
121
  protected updated(changed: PropertyValues): void;
122
+ /** @internal A subclass's own trigger (it must carry class="trigger"); undefined keeps the standard one. */
123
+ protected triggerTemplate(_click: (e: Event) => void, _key: (e: KeyboardEvent) => void): unknown;
124
+ /** @internal A subclass's own content above the choices; undefined keeps the heading/subheading block. */
125
+ protected headTemplate(): unknown;
122
126
  render(): import("lit-html").TemplateResult<1>;
123
127
  }
124
128
  declare global {
@@ -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 _CmActionMenu_instances, _CmActionMenu_observer, _CmActionMenu_id, _CmActionMenu_typed, _CmActionMenu_typedAt, _CmActionMenu_read, _CmActionMenu_outside, _CmActionMenu_trigger, _CmActionMenu_enabled, _CmActionMenu_setOpen, _CmActionMenu_focusActive, _CmActionMenu_fit, _CmActionMenu_triggerKey, _CmActionMenu_triggerClick, _CmActionMenu_move, _CmActionMenu_menuKey, _CmActionMenu_choose, _CmActionMenu_item, _CmActionMenu_rows;
12
+ var _CmActionMenu_instances, _CmActionMenu_observer, _CmActionMenu_id, _CmActionMenu_typed, _CmActionMenu_typedAt, _CmActionMenu_read, _CmActionMenu_outside, _CmActionMenu_trigger, _CmActionMenu_enabled, _CmActionMenu_setOpen, _CmActionMenu_focusActive, _CmActionMenu_fit, _CmActionMenu_place, _CmActionMenu_onMove, _CmActionMenu_following, _CmActionMenu_follow, _CmActionMenu_triggerKey, _CmActionMenu_triggerClick, _CmActionMenu_move, _CmActionMenu_menuKey, _CmActionMenu_choose, _CmActionMenu_item, _CmActionMenu_rows;
13
13
  import { html, css, nothing } from 'lit';
14
14
  import { base, define, nextId } from '../base.js';
15
15
  import { CmLocalizedElement, defineStrings } from '../localize.js';
@@ -76,6 +76,9 @@ export class CmActionMenu extends CmLocalizedElement {
76
76
  _CmActionMenu_typedAt.set(this, 0);
77
77
  _CmActionMenu_outside.set(this, (e) => { if (this.open && !e.composedPath().includes(this))
78
78
  __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_setOpen).call(this, false); });
79
+ _CmActionMenu_onMove.set(this, () => { const pop = this.renderRoot.querySelector('.pop'); if (pop && this.open)
80
+ __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_place).call(this, pop); });
81
+ _CmActionMenu_following.set(this, false);
79
82
  _CmActionMenu_triggerKey.set(this, (e) => {
80
83
  if (this.disabled)
81
84
  return;
@@ -151,6 +154,7 @@ export class CmActionMenu extends CmLocalizedElement {
151
154
  super.disconnectedCallback();
152
155
  __classPrivateFieldGet(this, _CmActionMenu_observer, "f")?.disconnect();
153
156
  document.removeEventListener('pointerdown', __classPrivateFieldGet(this, _CmActionMenu_outside, "f"), true);
157
+ __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_follow).call(this, false);
154
158
  }
155
159
  /** The choices in use. */
156
160
  get menuItems() { return this.items.length ? this.items : this._slotted; }
@@ -170,6 +174,15 @@ export class CmActionMenu extends CmLocalizedElement {
170
174
  updated(changed) {
171
175
  if (changed.has('open') && this.open)
172
176
  __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_fit).call(this);
177
+ if (changed.has('open') && !this.open) {
178
+ __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_follow).call(this, false);
179
+ const pop = this.renderRoot.querySelector('.pop');
180
+ try {
181
+ if (pop?.matches(':popover-open'))
182
+ pop.hidePopover();
183
+ }
184
+ catch { /* already hidden */ }
185
+ }
173
186
  if (this._custom) {
174
187
  const t = __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_trigger).call(this);
175
188
  if (t) {
@@ -187,19 +200,23 @@ export class CmActionMenu extends CmLocalizedElement {
187
200
  this.updateComplete.then(() => __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_focusActive).call(this));
188
201
  }
189
202
  }
203
+ /** @internal A subclass's own trigger (it must carry class="trigger"); undefined keeps the standard one. */
204
+ triggerTemplate(_click, _key) { return undefined; }
205
+ /** @internal A subclass's own content above the choices; undefined keeps the heading/subheading block. */
206
+ headTemplate() { return undefined; }
190
207
  render() {
191
208
  const items = this.menuItems;
192
209
  const name = this.triggerLabel || this.label;
193
210
  const trigger = this._custom
194
211
  ? html `<slot name="trigger" @click=${__classPrivateFieldGet(this, _CmActionMenu_triggerClick, "f")} @keydown=${__classPrivateFieldGet(this, _CmActionMenu_triggerKey, "f")} @slotchange=${() => __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_read).call(this)}></slot>`
195
- : html `<button type="button" class="trigger ${this.iconOnly ? 'icon' : ''}" part="trigger" aria-haspopup="menu"
212
+ : this.triggerTemplate(__classPrivateFieldGet(this, _CmActionMenu_triggerClick, "f"), __classPrivateFieldGet(this, _CmActionMenu_triggerKey, "f")) ?? html `<button type="button" class="trigger ${this.iconOnly ? 'icon' : ''}" part="trigger" aria-haspopup="menu"
196
213
  aria-expanded=${String(this.open)} aria-controls="${__classPrivateFieldGet(this, _CmActionMenu_id, "f")}-m" aria-label=${this.iconOnly ? name : nothing}
197
214
  ?disabled=${this.disabled} @click=${__classPrivateFieldGet(this, _CmActionMenu_triggerClick, "f")} @keydown=${__classPrivateFieldGet(this, _CmActionMenu_triggerKey, "f")}>${this.iconOnly
198
215
  ? html `<cm-icon name=${this.icon} size="18"></cm-icon>`
199
216
  : html `<span>${name}</span><cm-icon name="chevron-down" size="14"></cm-icon>`}</button>`;
200
217
  return html `${trigger}
201
- <div class="pop" part="menu" ?hidden=${!this.open}>
202
- ${this.heading ? html `<div class="head" part="heading"><strong>${this.heading}</strong>${this.subheading ? html `<span>${this.subheading}</span>` : nothing}</div>` : nothing}
218
+ <div class="pop" part="menu" popover="manual" ?hidden=${!this.open}>
219
+ ${this.headTemplate() ?? (this.heading ? html `<div class="head" part="heading"><strong>${this.heading}</strong>${this.subheading ? html `<span>${this.subheading}</span>` : nothing}</div>` : nothing)}
203
220
  <div role="menu" id="${__classPrivateFieldGet(this, _CmActionMenu_id, "f")}-m" aria-label=${this.heading || this.label} aria-busy=${this.loading ? 'true' : nothing} @keydown=${__classPrivateFieldGet(this, _CmActionMenu_menuKey, "f")}>
204
221
  ${this.loading
205
222
  ? html `<div class="loading" role="presentation"><cm-spinner size="small" aria-hidden="true"></cm-spinner><span>${this.t('loading')}</span></div>`
@@ -209,7 +226,7 @@ export class CmActionMenu extends CmLocalizedElement {
209
226
  <slot hidden></slot>`;
210
227
  }
211
228
  }
212
- _CmActionMenu_observer = new WeakMap(), _CmActionMenu_id = new WeakMap(), _CmActionMenu_typed = new WeakMap(), _CmActionMenu_typedAt = new WeakMap(), _CmActionMenu_outside = new WeakMap(), _CmActionMenu_triggerKey = new WeakMap(), _CmActionMenu_triggerClick = new WeakMap(), _CmActionMenu_menuKey = new WeakMap(), _CmActionMenu_instances = new WeakSet(), _CmActionMenu_read = function _CmActionMenu_read() {
229
+ _CmActionMenu_observer = new WeakMap(), _CmActionMenu_id = new WeakMap(), _CmActionMenu_typed = new WeakMap(), _CmActionMenu_typedAt = new WeakMap(), _CmActionMenu_outside = new WeakMap(), _CmActionMenu_onMove = new WeakMap(), _CmActionMenu_following = new WeakMap(), _CmActionMenu_triggerKey = new WeakMap(), _CmActionMenu_triggerClick = new WeakMap(), _CmActionMenu_menuKey = new WeakMap(), _CmActionMenu_instances = new WeakSet(), _CmActionMenu_read = function _CmActionMenu_read() {
213
230
  this._slotted = readMenuItems(this);
214
231
  this._custom = !!this.querySelector(':scope > [slot="trigger"]');
215
232
  }, _CmActionMenu_trigger = function _CmActionMenu_trigger() {
@@ -231,6 +248,18 @@ _CmActionMenu_observer = new WeakMap(), _CmActionMenu_id = new WeakMap(), _CmAct
231
248
  const pop = this.renderRoot.querySelector('.pop');
232
249
  if (!pop)
233
250
  return;
251
+ if (typeof pop.showPopover === 'function') {
252
+ try {
253
+ if (!pop.matches(':popover-open'))
254
+ pop.showPopover();
255
+ }
256
+ catch { /* not connected yet */ }
257
+ if (pop.matches(':popover-open')) {
258
+ __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_place).call(this, pop);
259
+ __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_follow).call(this, true);
260
+ return;
261
+ }
262
+ }
234
263
  pop.classList.remove('to-end', 'to-start');
235
264
  const r = pop.getBoundingClientRect(), vw = document.documentElement.clientWidth, m = 8;
236
265
  const rtl = getComputedStyle(this).direction === 'rtl';
@@ -240,6 +269,36 @@ _CmActionMenu_observer = new WeakMap(), _CmActionMenu_id = new WeakMap(), _CmAct
240
269
  pop.classList.add('to-end');
241
270
  else if (this.align === 'end' && startOverflow)
242
271
  pop.classList.add('to-start');
272
+ }, _CmActionMenu_place = function _CmActionMenu_place(pop) {
273
+ const t = __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_trigger).call(this) ?? this;
274
+ const r = t.getBoundingClientRect();
275
+ const vw = document.documentElement.clientWidth, vh = document.documentElement.clientHeight, m = 8, gap = 4;
276
+ pop.style.maxHeight = '';
277
+ const w = pop.offsetWidth, h = pop.offsetHeight;
278
+ const rtl = getComputedStyle(this).direction === 'rtl';
279
+ const startEdge = rtl ? r.right - w : r.left, endEdge = rtl ? r.left : r.right - w;
280
+ let left = this.align === 'end' ? endEdge : startEdge;
281
+ if (left + w > vw - m)
282
+ left = rtl ? startEdge : endEdge;
283
+ if (left < m)
284
+ left = this.align === 'end' ? startEdge : (rtl ? r.left : left);
285
+ left = Math.max(m, Math.min(left, vw - m - w));
286
+ let top = r.bottom + gap;
287
+ if (top + h > vh - m) {
288
+ if (r.top - gap - h >= m)
289
+ top = r.top - gap - h;
290
+ else
291
+ pop.style.maxHeight = `${Math.max(120, vh - top - m)}px`;
292
+ }
293
+ pop.style.left = `${Math.round(left)}px`;
294
+ pop.style.top = `${Math.round(top)}px`;
295
+ }, _CmActionMenu_follow = function _CmActionMenu_follow(on) {
296
+ if (on === __classPrivateFieldGet(this, _CmActionMenu_following, "f"))
297
+ return;
298
+ __classPrivateFieldSet(this, _CmActionMenu_following, on, "f");
299
+ const f = on ? 'addEventListener' : 'removeEventListener';
300
+ window[f]('scroll', __classPrivateFieldGet(this, _CmActionMenu_onMove, "f"), true);
301
+ window[f]('resize', __classPrivateFieldGet(this, _CmActionMenu_onMove, "f"));
243
302
  }, _CmActionMenu_move = function _CmActionMenu_move(to) {
244
303
  this._active = to;
245
304
  this.updateComplete.then(() => __classPrivateFieldGet(this, _CmActionMenu_instances, "m", _CmActionMenu_focusActive).call(this));
@@ -335,6 +394,9 @@ CmActionMenu.styles = [
335
394
  :host([align='end']) .pop, .pop.to-end { inset-inline-start: auto; inset-inline-end: 0; }
336
395
  :host([align='end']) .pop.to-start { inset-inline-start: 0; inset-inline-end: auto; }
337
396
  .pop[hidden] { display: none; }
397
+ /* 1.9.2: the open menu is a popover in the top layer, so a scrolling ancestor (a board column, a table, a card
398
+ body) can't clip it; #place() puts it beside the trigger. Browsers without popovers keep the absolute menu. */
399
+ .pop:popover-open { position: fixed; inset: auto; margin: 0; overflow: auto; color: var(--cm-text-default); }
338
400
  .head { padding: var(--cm-space-4) var(--cm-space-12) var(--cm-space-8); margin-bottom: 4px; border-bottom: var(--cm-border-1) solid var(--cm-border-subtle); overflow-wrap: anywhere; }
339
401
  .head strong { display: block; font-size: 14px; font-weight: 500; }
340
402
  .head span { display: block; font-size: var(--cm-font-size-12); color: var(--cm-text-tertiary); }
@@ -29,7 +29,8 @@ declare module '../localize.js' {
29
29
  * @element cm-header-bar
30
30
  * @slot logo - The product logo (an `<img>` or `<svg>`), linked to the dashboard if you wrap it in `<a>`.
31
31
  * @slot actions - Buttons such as "Hire an Expert" (secondary) and "My Subscription" (primary).
32
- * @slot end - Anything after the user pill, e.g. a notifications button.
32
+ * @slot end - Controls before the signed-in person, in this order: refresh, then notifications (1.9.2: the user comes last).
33
+ * @slot account - The signed-in person's menu, last in the bar: a `cm-account-menu` (since 1.9.2). Use it instead of `user-name`.
33
34
  * @slot search - One search box for the whole product, usually `cm-global-search`. Inline on wide bars; behind a search button that opens a full-screen layer at 900px or narrower.
34
35
  * @fires cm-store-switch - When the store switcher is pressed. Open your store list in response.
35
36
  * @fires cm-wallet - When the wallet balance is pressed.
@@ -38,7 +38,8 @@ const strings = defineStrings('headerBar', {
38
38
  * @element cm-header-bar
39
39
  * @slot logo - The product logo (an `<img>` or `<svg>`), linked to the dashboard if you wrap it in `<a>`.
40
40
  * @slot actions - Buttons such as "Hire an Expert" (secondary) and "My Subscription" (primary).
41
- * @slot end - Anything after the user pill, e.g. a notifications button.
41
+ * @slot end - Controls before the signed-in person, in this order: refresh, then notifications (1.9.2: the user comes last).
42
+ * @slot account - The signed-in person's menu, last in the bar: a `cm-account-menu` (since 1.9.2). Use it instead of `user-name`.
42
43
  * @slot search - One search box for the whole product, usually `cm-global-search`. Inline on wide bars; behind a search button that opens a full-screen layer at 900px or narrower.
43
44
  * @fires cm-store-switch - When the store switcher is pressed. Open your store list in response.
44
45
  * @fires cm-wallet - When the wallet balance is pressed.
@@ -151,10 +152,11 @@ export class CmHeaderBar extends CmLocalizedElement {
151
152
  <div class="actions"><slot name="actions"></slot></div>
152
153
  ${this.balance ? html `<button type="button" class="pill" part="balance" aria-label=${this.t('balance', { balance: this.balance })}
153
154
  @click=${() => __classPrivateFieldGet(this, _CmHeaderBar_instances, "m", _CmHeaderBar_fire).call(this, 'cm-wallet')}>${this.balance}</button>` : nothing}
155
+ <slot name="end"></slot>
154
156
  ${this.userName ? html `<button type="button" class="user" part="user" aria-haspopup="true" aria-label=${this.t('account', { name: this.userName })}
155
157
  @click=${() => __classPrivateFieldGet(this, _CmHeaderBar_instances, "m", _CmHeaderBar_fire).call(this, 'cm-account')}><span class="name">${this.userName}</span>
156
158
  <cm-avatar class="avatar" name=${this.userName} src=${this.avatarSrc} decorative></cm-avatar></button>` : nothing}
157
- <slot name="end"></slot>
159
+ <slot name="account"></slot>
158
160
  </div>
159
161
  </header>
160
162
  ${this._narrow ? html `<dialog class="layer" part="search-layer" aria-label=${this.searchLabel}
@@ -1,4 +1,15 @@
1
1
  import { LitElement } from 'lit';
2
+ import { CmLocalizedElement } from '../localize.js';
3
+ import './icon.js';
4
+ declare const strings: {
5
+ /** Accessible name of an editable fact's edit button (`editable`). {label} is the fact's label. */
6
+ edit: string;
7
+ };
8
+ declare module '../localize.js' {
9
+ interface CmStrings {
10
+ infoItem: typeof strings;
11
+ }
12
+ }
2
13
  /**
3
14
  * Side card on detail pages that lists facts as label/value pairs (order details, SKU, tags).
4
15
  * Put `cm-info-item` elements inside. The Figma file calls this the "Additional Info Card".
@@ -54,21 +65,36 @@ export declare class CmInfoPanel extends LitElement {
54
65
  }
55
66
  /**
56
67
  * One fact in an info panel: a label (13px) and its value (14px): text, a link, a badge or tags.
68
+ * With `editable` (since 1.9.1) a light pencil button follows the value, centred on its first line, for editing one
69
+ * field in place on a record page; it fires `cm-edit`. Use it instead of an outlined button beside each value.
57
70
  * @element cm-info-item
58
71
  * @slot - The value.
72
+ * @fires cm-edit - When the pencil of an `editable` fact is pressed.
73
+ * @csspart edit - The pencil button.
59
74
  */
60
- export declare class CmInfoItem extends LitElement {
75
+ export declare class CmInfoItem extends CmLocalizedElement {
61
76
  static properties: {
62
77
  label: {};
63
78
  half: {
64
79
  type: BooleanConstructor;
65
80
  reflect: boolean;
66
81
  };
82
+ editable: {
83
+ type: BooleanConstructor;
84
+ reflect: boolean;
85
+ };
86
+ editLabel: {
87
+ attribute: string;
88
+ };
67
89
  };
68
90
  /** What the value is ("Ordered on", "SKU"). */
69
91
  label: string;
70
92
  /** Takes half the width, so two short facts share a line. */
71
93
  half: boolean;
94
+ /** Shows a pencil button after the value that fires `cm-edit`. Since 1.9.1. */
95
+ editable: boolean;
96
+ /** Accessible name of the pencil; default "Edit {label}". Since 1.9.1. */
97
+ editLabel: string;
72
98
  static styles: import("lit").CSSResult[];
73
99
  connectedCallback(): void;
74
100
  render(): import("lit-html").TemplateResult<1>;
@@ -79,3 +105,4 @@ declare global {
79
105
  'cm-info-item': CmInfoItem;
80
106
  }
81
107
  }
108
+ export {};
@@ -1,5 +1,11 @@
1
1
  import { LitElement, html, css, nothing } from 'lit';
2
2
  import { base, define } from '../base.js';
3
+ import { CmLocalizedElement, defineStrings } from '../localize.js';
4
+ import './icon.js';
5
+ const strings = defineStrings('infoItem', {
6
+ /** Accessible name of an editable fact's edit button (`editable`). {label} is the fact's label. */
7
+ edit: 'Edit {label}',
8
+ });
3
9
  /**
4
10
  * Side card on detail pages that lists facts as label/value pairs (order details, SKU, tags).
5
11
  * Put `cm-info-item` elements inside. The Figma file calls this the "Additional Info Card".
@@ -92,16 +98,24 @@ CmInfoPanel.styles = [
92
98
  define('cm-info-panel', CmInfoPanel);
93
99
  /**
94
100
  * One fact in an info panel: a label (13px) and its value (14px): text, a link, a badge or tags.
101
+ * With `editable` (since 1.9.1) a light pencil button follows the value, centred on its first line, for editing one
102
+ * field in place on a record page; it fires `cm-edit`. Use it instead of an outlined button beside each value.
95
103
  * @element cm-info-item
96
104
  * @slot - The value.
105
+ * @fires cm-edit - When the pencil of an `editable` fact is pressed.
106
+ * @csspart edit - The pencil button.
97
107
  */
98
- export class CmInfoItem extends LitElement {
108
+ export class CmInfoItem extends CmLocalizedElement {
99
109
  constructor() {
100
110
  super(...arguments);
101
111
  /** What the value is ("Ordered on", "SKU"). */
102
112
  this.label = '';
103
113
  /** Takes half the width, so two short facts share a line. */
104
114
  this.half = false;
115
+ /** Shows a pencil button after the value that fires `cm-edit`. Since 1.9.1. */
116
+ this.editable = false;
117
+ /** Accessible name of the pencil; default "Edit {label}". Since 1.9.1. */
118
+ this.editLabel = '';
105
119
  }
106
120
  connectedCallback() {
107
121
  super.connectedCallback();
@@ -109,12 +123,19 @@ export class CmInfoItem extends LitElement {
109
123
  this.setAttribute('role', 'listitem');
110
124
  }
111
125
  render() {
112
- return html `<div class="label" part="label">${this.label}</div><div class="value" part="value"><slot></slot></div>`;
126
+ const value = html `<div class="value" part="value"><slot></slot></div>`;
127
+ if (!this.editable)
128
+ return html `<div class="label" part="label">${this.label}</div>${value}`;
129
+ return html `<div class="label" part="label">${this.label}</div><div class="row">${value}<button class="edit" part="edit" type="button"
130
+ aria-label=${this.editLabel || this.t('edit', { label: this.label })}
131
+ @click=${() => this.dispatchEvent(new CustomEvent('cm-edit', { bubbles: true, composed: true }))}><cm-icon name="edit" size="16"></cm-icon></button></div>`;
113
132
  }
114
133
  }
115
134
  CmInfoItem.properties = {
116
135
  label: {},
117
136
  half: { type: Boolean, reflect: true },
137
+ editable: { type: Boolean, reflect: true },
138
+ editLabel: { attribute: 'edit-label' },
118
139
  };
119
140
  CmInfoItem.styles = [
120
141
  base,
@@ -127,6 +148,16 @@ CmInfoItem.styles = [
127
148
  margin-top: var(--_cm-info-value-gap, var(--cm-space-4)); font-size: var(--cm-font-size-14); line-height: var(--cm-line-height-14); font-weight: 500; overflow-wrap: anywhere;
128
149
 
129
150
  }
151
+ /* Editable (1.9.1): the value and a 28px pencil on one row, the pencil centred on the value's first 20px line. */
152
+ .row { display: flex; align-items: flex-start; gap: var(--cm-space-4); margin-top: var(--_cm-info-value-gap, var(--cm-space-4)); }
153
+ .row .value { margin-top: 0; min-width: 0; }
154
+ .edit {
155
+ position: relative; flex: none; display: inline-grid; place-items: center; width: 28px; height: 28px; margin-block: -4px; padding: 0;
156
+ background: none; border: 0; border-radius: var(--cm-radius-sm); color: var(--cm-icon-default); cursor: pointer;
157
+ }
158
+ .edit:hover { background: var(--cm-bg-hover); color: var(--cm-icon-selected); }
159
+ .edit:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
160
+ @media (pointer: coarse) { .edit::after { content: ''; position: absolute; inset: -8px; } }
130
161
  `,
131
162
  ];
132
163
  define('cm-info-item', CmInfoItem);