@commmerce/ui 1.10.0 → 1.11.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.
@@ -212,7 +212,7 @@ CmStatusTabs.styles = [
212
212
  }
213
213
  button:hover:not(:disabled) { color: var(--cm-text-default); }
214
214
  button[aria-selected='true'] { color: var(--cm-text-default); font-weight: 600; }
215
- button[aria-selected='true']::after { background: var(--cm-border-strong); }
215
+ button[aria-selected='true']::after { background: var(--cm-tab-indicator); }
216
216
  /* The chosen tab's bold label takes no extra room: each label reserves the width of its bold version. */
217
217
  .label { display: inline-grid; }
218
218
  .label::after { content: attr(data-text); content: attr(data-text) / ''; font-weight: 600; block-size: 0; overflow: hidden; visibility: hidden; }
@@ -728,58 +728,11 @@
728
728
  "module": "src/components/action-menu.ts"
729
729
  }
730
730
  },
731
- {
732
- "kind": "method",
733
- "name": "#place",
734
- "privacy": "private",
735
- "parameters": [
736
- {
737
- "name": "pop",
738
- "type": {
739
- "text": "HTMLElement"
740
- }
741
- }
742
- ],
743
- "description": "Puts the top-layer menu under the trigger (above it when there's no room below), aligned to its start or end edge.",
744
- "inheritedFrom": {
745
- "name": "CmActionMenu",
746
- "module": "src/components/action-menu.ts"
747
- }
748
- },
749
731
  {
750
732
  "kind": "field",
751
- "name": "#onMove",
733
+ "name": "#layer",
752
734
  "privacy": "private",
753
- "inheritedFrom": {
754
- "name": "CmActionMenu",
755
- "module": "src/components/action-menu.ts"
756
- }
757
- },
758
- {
759
- "kind": "field",
760
- "name": "#following",
761
- "privacy": "private",
762
- "type": {
763
- "text": "boolean"
764
- },
765
- "default": "false",
766
- "inheritedFrom": {
767
- "name": "CmActionMenu",
768
- "module": "src/components/action-menu.ts"
769
- }
770
- },
771
- {
772
- "kind": "method",
773
- "name": "#follow",
774
- "privacy": "private",
775
- "parameters": [
776
- {
777
- "name": "on",
778
- "type": {
779
- "text": "boolean"
780
- }
781
- }
782
- ],
735
+ "default": "new TopLayer()",
783
736
  "inheritedFrom": {
784
737
  "name": "CmActionMenu",
785
738
  "module": "src/components/action-menu.ts"
@@ -1884,46 +1837,11 @@
1884
1837
  "privacy": "private",
1885
1838
  "description": "Opens toward the other side when the menu would run off the screen (1.8.1: a More menu at the end of a page header)."
1886
1839
  },
1887
- {
1888
- "kind": "method",
1889
- "name": "#place",
1890
- "privacy": "private",
1891
- "parameters": [
1892
- {
1893
- "name": "pop",
1894
- "type": {
1895
- "text": "HTMLElement"
1896
- }
1897
- }
1898
- ],
1899
- "description": "Puts the top-layer menu under the trigger (above it when there's no room below), aligned to its start or end edge."
1900
- },
1901
1840
  {
1902
1841
  "kind": "field",
1903
- "name": "#onMove",
1904
- "privacy": "private"
1905
- },
1906
- {
1907
- "kind": "field",
1908
- "name": "#following",
1842
+ "name": "#layer",
1909
1843
  "privacy": "private",
1910
- "type": {
1911
- "text": "boolean"
1912
- },
1913
- "default": "false"
1914
- },
1915
- {
1916
- "kind": "method",
1917
- "name": "#follow",
1918
- "privacy": "private",
1919
- "parameters": [
1920
- {
1921
- "name": "on",
1922
- "type": {
1923
- "text": "boolean"
1924
- }
1925
- }
1926
- ]
1844
+ "default": "new TopLayer()"
1927
1845
  },
1928
1846
  {
1929
1847
  "kind": "field",
@@ -10889,6 +10807,12 @@
10889
10807
  },
10890
10808
  "description": "Rows in the list: the matching options, then the \"Add …\" row if offered."
10891
10809
  },
10810
+ {
10811
+ "kind": "field",
10812
+ "name": "#layer",
10813
+ "privacy": "private",
10814
+ "default": "new TopLayer()"
10815
+ },
10892
10816
  {
10893
10817
  "kind": "method",
10894
10818
  "name": "#emit",
@@ -13635,6 +13559,12 @@
13635
13559
  }
13636
13560
  ]
13637
13561
  },
13562
+ {
13563
+ "kind": "field",
13564
+ "name": "#layer",
13565
+ "privacy": "private",
13566
+ "default": "new TopLayer()"
13567
+ },
13638
13568
  {
13639
13569
  "kind": "method",
13640
13570
  "name": "#togglePicker",
@@ -14758,6 +14688,12 @@
14758
14688
  ],
14759
14689
  "description": "Time mode checks, after the custom error and a bad typed date."
14760
14690
  },
14691
+ {
14692
+ "kind": "field",
14693
+ "name": "#layer",
14694
+ "privacy": "private",
14695
+ "default": "new TopLayer()"
14696
+ },
14761
14697
  {
14762
14698
  "kind": "method",
14763
14699
  "name": "#setValue",
@@ -15730,6 +15666,12 @@
15730
15666
  }
15731
15667
  ]
15732
15668
  },
15669
+ {
15670
+ "kind": "field",
15671
+ "name": "#layer",
15672
+ "privacy": "private",
15673
+ "default": "new TopLayer()"
15674
+ },
15733
15675
  {
15734
15676
  "kind": "method",
15735
15677
  "name": "#emit",
@@ -18434,6 +18376,12 @@
18434
18376
  "privacy": "private",
18435
18377
  "readonly": true
18436
18378
  },
18379
+ {
18380
+ "kind": "field",
18381
+ "name": "#layer",
18382
+ "privacy": "private",
18383
+ "default": "new TopLayer()"
18384
+ },
18437
18385
  {
18438
18386
  "kind": "method",
18439
18387
  "name": "#hide",
@@ -29223,6 +29171,12 @@
29223
29171
  "name": "#readChildren",
29224
29172
  "privacy": "private"
29225
29173
  },
29174
+ {
29175
+ "kind": "field",
29176
+ "name": "#layer",
29177
+ "privacy": "private",
29178
+ "default": "new TopLayer()"
29179
+ },
29226
29180
  {
29227
29181
  "kind": "method",
29228
29182
  "name": "#enabledIndexes",
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Floating lists and menus in the top layer (since 1.10.1, issue #35). A dropdown drawn with `position: absolute`
3
+ * inside a component is covered by later rows that make their own stacking context (a `cm-resource-item`'s actions)
4
+ * and clipped by any ancestor with `overflow: hidden` / `auto` (a card, a board column, a table's scroll area). In
5
+ * the top layer nothing can cover or clip it. `TopLayer` shows the element as a manual popover, puts it beside its
6
+ * anchor (below, or above when there is more room there), keeps it inside the window and follows scrolling and
7
+ * resizing while it is open. Browsers without popovers, or a list styled `position: static` (the header bar's
8
+ * full-screen search), keep the in-place layout.
9
+ */
10
+ /** Neutralises the browser's own popover styles (border, padding, colours) so each component's styles apply as before. */
11
+ export declare const topLayerStyles: import("lit").CSSResult;
12
+ export interface TopLayerOptions {
13
+ /** `start` / `end`: aligned to the anchor's start or end edge. `stretch`: at least as wide as the anchor. */
14
+ align?: 'start' | 'end' | 'stretch';
15
+ /** Space between anchor and list (default 4). */
16
+ gap?: number;
17
+ }
18
+ export declare class TopLayer {
19
+ #private;
20
+ /** Whether the list is currently shown in the top layer. */
21
+ get active(): boolean;
22
+ /**
23
+ * Shows `pop` in the top layer beside `anchor`. Returns false (and leaves the in-place layout) when the browser
24
+ * has no popovers or the list is laid out statically.
25
+ */
26
+ open(pop: HTMLElement | null | undefined, anchor: HTMLElement | null | undefined, opts?: TopLayerOptions): boolean;
27
+ /** Puts the list beside its anchor again (call after its content changes size). */
28
+ place(): void;
29
+ /** Hides the list and puts back its in-place styles. */
30
+ close(): void;
31
+ }
@@ -0,0 +1,133 @@
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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
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
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _TopLayer_pop, _TopLayer_anchor, _TopLayer_opts, _TopLayer_maxHeight, _TopLayer_onMove;
13
+ import { css } from 'lit';
14
+ /**
15
+ * Floating lists and menus in the top layer (since 1.10.1, issue #35). A dropdown drawn with `position: absolute`
16
+ * inside a component is covered by later rows that make their own stacking context (a `cm-resource-item`'s actions)
17
+ * and clipped by any ancestor with `overflow: hidden` / `auto` (a card, a board column, a table's scroll area). In
18
+ * the top layer nothing can cover or clip it. `TopLayer` shows the element as a manual popover, puts it beside its
19
+ * anchor (below, or above when there is more room there), keeps it inside the window and follows scrolling and
20
+ * resizing while it is open. Browsers without popovers, or a list styled `position: static` (the header bar's
21
+ * full-screen search), keep the in-place layout.
22
+ */
23
+ /** Neutralises the browser's own popover styles (border, padding, colours) so each component's styles apply as before. */
24
+ export const topLayerStyles = css `
25
+ :where([popover]) { margin: 0; padding: 0; border: 0; color: inherit; background: none; overflow: visible; }
26
+ `;
27
+ const MARGIN = 8;
28
+ export class TopLayer {
29
+ constructor() {
30
+ _TopLayer_pop.set(this, null);
31
+ _TopLayer_anchor.set(this, null);
32
+ _TopLayer_opts.set(this, {});
33
+ _TopLayer_maxHeight.set(this, '');
34
+ _TopLayer_onMove.set(this, () => this.place());
35
+ }
36
+ /** Whether the list is currently shown in the top layer. */
37
+ get active() { return !!__classPrivateFieldGet(this, _TopLayer_pop, "f"); }
38
+ /**
39
+ * Shows `pop` in the top layer beside `anchor`. Returns false (and leaves the in-place layout) when the browser
40
+ * has no popovers or the list is laid out statically.
41
+ */
42
+ open(pop, anchor, opts = {}) {
43
+ if (!pop || !anchor || typeof pop.showPopover !== 'function')
44
+ return false;
45
+ if (__classPrivateFieldGet(this, _TopLayer_pop, "f") && __classPrivateFieldGet(this, _TopLayer_pop, "f") !== pop)
46
+ this.close();
47
+ if (!pop.hasAttribute('popover'))
48
+ pop.setAttribute('popover', 'manual');
49
+ const wasOpen = pop.matches(':popover-open');
50
+ if (!wasOpen) {
51
+ // A list laid out in place on purpose (position: static) stays where it is.
52
+ if (getComputedStyle(pop).position === 'static') {
53
+ pop.removeAttribute('popover');
54
+ return false;
55
+ }
56
+ try {
57
+ pop.showPopover();
58
+ }
59
+ catch {
60
+ return false;
61
+ }
62
+ }
63
+ if (!pop.matches(':popover-open'))
64
+ return false;
65
+ if (!__classPrivateFieldGet(this, _TopLayer_pop, "f"))
66
+ __classPrivateFieldSet(this, _TopLayer_maxHeight, pop.style.maxHeight, "f");
67
+ __classPrivateFieldSet(this, _TopLayer_pop, pop, "f");
68
+ __classPrivateFieldSet(this, _TopLayer_anchor, anchor, "f");
69
+ __classPrivateFieldSet(this, _TopLayer_opts, opts, "f");
70
+ Object.assign(pop.style, { position: 'fixed', inset: 'auto', margin: '0' });
71
+ this.place();
72
+ if (!wasOpen) {
73
+ window.addEventListener('scroll', __classPrivateFieldGet(this, _TopLayer_onMove, "f"), true);
74
+ window.addEventListener('resize', __classPrivateFieldGet(this, _TopLayer_onMove, "f"));
75
+ }
76
+ return true;
77
+ }
78
+ /** Puts the list beside its anchor again (call after its content changes size). */
79
+ place() {
80
+ const pop = __classPrivateFieldGet(this, _TopLayer_pop, "f"), anchor = __classPrivateFieldGet(this, _TopLayer_anchor, "f");
81
+ if (!pop || !anchor)
82
+ return;
83
+ const r = anchor.getBoundingClientRect();
84
+ const vw = document.documentElement.clientWidth, vh = document.documentElement.clientHeight;
85
+ const gap = __classPrivateFieldGet(this, _TopLayer_opts, "f").gap ?? 4, align = __classPrivateFieldGet(this, _TopLayer_opts, "f").align ?? 'start';
86
+ pop.style.maxHeight = __classPrivateFieldGet(this, _TopLayer_maxHeight, "f");
87
+ if (align === 'stretch')
88
+ pop.style.minWidth = `${Math.round(r.width)}px`;
89
+ const pr = pop.getBoundingClientRect(), w = pr.width, natural = pr.height; // fractional: offsetWidth rounds
90
+ const rtl = getComputedStyle(anchor).direction === 'rtl';
91
+ const startEdge = rtl ? r.right - w : r.left, endEdge = rtl ? r.left : r.right - w;
92
+ let left = align === 'end' ? endEdge : startEdge;
93
+ if (left + w > vw - MARGIN)
94
+ left = rtl ? startEdge : endEdge;
95
+ // Keep 8px from the window's edges, except where the anchor itself is closer: then line up with the anchor.
96
+ const lo = Math.max(0, Math.min(MARGIN, r.left)), hi = Math.min(vw, Math.max(vw - MARGIN, r.right)) - w;
97
+ left = Math.max(lo, Math.min(left, hi));
98
+ const below = vh - r.bottom - gap - MARGIN, above = r.top - gap - MARGIN;
99
+ let top;
100
+ if (natural <= below || below >= above) {
101
+ top = r.bottom + gap;
102
+ if (natural > below)
103
+ pop.style.maxHeight = `${Math.max(80, Math.floor(below))}px`;
104
+ }
105
+ else {
106
+ const h = Math.min(natural, Math.floor(above));
107
+ if (natural > above)
108
+ pop.style.maxHeight = `${Math.max(80, h)}px`;
109
+ top = r.top - gap - h;
110
+ }
111
+ pop.style.left = `${left}px`;
112
+ pop.style.top = `${top}px`;
113
+ }
114
+ /** Hides the list and puts back its in-place styles. */
115
+ close() {
116
+ const pop = __classPrivateFieldGet(this, _TopLayer_pop, "f");
117
+ window.removeEventListener('scroll', __classPrivateFieldGet(this, _TopLayer_onMove, "f"), true);
118
+ window.removeEventListener('resize', __classPrivateFieldGet(this, _TopLayer_onMove, "f"));
119
+ __classPrivateFieldSet(this, _TopLayer_pop, null, "f");
120
+ __classPrivateFieldSet(this, _TopLayer_anchor, null, "f");
121
+ if (!pop)
122
+ return;
123
+ try {
124
+ if (pop.matches(':popover-open'))
125
+ pop.hidePopover();
126
+ }
127
+ catch { /* already hidden */ }
128
+ for (const k of ['position', 'inset', 'margin', 'left', 'top', 'minWidth'])
129
+ pop.style[k] = '';
130
+ pop.style.maxHeight = __classPrivateFieldGet(this, _TopLayer_maxHeight, "f");
131
+ }
132
+ }
133
+ _TopLayer_pop = new WeakMap(), _TopLayer_anchor = new WeakMap(), _TopLayer_opts = new WeakMap(), _TopLayer_maxHeight = new WeakMap(), _TopLayer_onMove = new WeakMap();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commmerce/ui",
3
- "version": "1.10.0",
3
+ "version": "1.11.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.10.0",
54
- "@commmerce/tokens": "1.10.0",
53
+ "@commmerce/icons": "1.11.0",
54
+ "@commmerce/tokens": "1.11.0",
55
55
  "lit": "3.2.1"
56
56
  },
57
57
  "devDependencies": {