@commmerce/ui 1.9.3 → 1.10.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.
- package/dist/cdn.js +503 -487
- package/dist/components/account-menu.d.ts +1 -1
- package/dist/components/account-menu.js +1 -1
- package/dist/components/action-menu.js +11 -58
- package/dist/components/combobox.js +14 -2
- package/dist/components/data-table.js +12 -2
- package/dist/components/date-picker.js +13 -3
- package/dist/components/date-range-picker.js +13 -3
- package/dist/components/global-search.js +14 -2
- package/dist/components/select.js +15 -2
- package/dist/components/sparkline.d.ts +68 -0
- package/dist/components/sparkline.js +134 -0
- package/dist/custom-elements.json +307 -87
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/top-layer.d.ts +31 -0
- package/dist/top-layer.js +133 -0
- package/package.json +3 -3
|
@@ -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.
|
|
3
|
+
"version": "1.10.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",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"test": "vitest run"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@commmerce/icons": "1.
|
|
54
|
-
"@commmerce/tokens": "1.
|
|
53
|
+
"@commmerce/icons": "1.10.1",
|
|
54
|
+
"@commmerce/tokens": "1.10.1",
|
|
55
55
|
"lit": "3.2.1"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|