@gemboss/ui 0.64.0 → 0.65.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.
- package/CHANGELOG.md +48 -0
- package/README.md +43 -5
- package/catalog/editor.html +1 -1
- package/catalog/index.html +1 -1
- package/gemboss-ui.css +2 -2
- package/package.json +3 -1
- package/parts/components.css +1 -1
- package/parts/core.css +1 -1
- package/parts/shell.css +1 -1
- package/src/editor/color-choices.ts +9 -0
- package/src/editor/controls.tsx +5 -2
- package/src/editor/field-control.tsx +453 -0
- package/src/editor/field-frame.tsx +182 -0
- package/src/editor/field-spec.ts +345 -0
- package/src/editor/index.ts +16 -0
- package/src/editor.css +1 -1
- package/src/email-editor/editor.tsx +37 -9
- package/src/email-editor/model.ts +5 -1
- package/src/email-editor.css +1 -1
- package/src/gem-at-work.css +1 -1
- package/src/gem-at-work.ts +223 -11
- package/src/list-page.tsx +87 -4
package/src/list-page.tsx
CHANGED
|
@@ -27,11 +27,52 @@
|
|
|
27
27
|
* `ui-empty--no-match` lives in collections.css (the parts gate holds a component to the CSS it imports).
|
|
28
28
|
*/
|
|
29
29
|
import "./list-page.css";
|
|
30
|
-
import React, { useId } from "react";
|
|
30
|
+
import React, { useEffect, useId, useLayoutEffect, useRef, useSyncExternalStore } from "react";
|
|
31
31
|
import { PageTabs } from "./page-tabs";
|
|
32
32
|
import { Icon } from "./icons";
|
|
33
33
|
import { Menu, MenuGroup, MenuItem, MenuSeparator } from "./menu";
|
|
34
34
|
|
|
35
|
+
// WHERE THE CARD STOOD (02/11/2026). A page's notices, toolbar and the line under its title often come with its read, so they
|
|
36
|
+
// appear above the loading card and push it down: the admin's layout shifts measured in RUM (gemboss_admin_vitals.cls_on), the
|
|
37
|
+
// card of GemSeel's Orders moved 271px on 19 of 96 visits with a CLS of 0.1 or more. With `holdKey` the card's place once read is
|
|
38
|
+
// kept on this device (per key and page width), and while the list loads again the card waits there, the room above it held;
|
|
39
|
+
// what comes with the read fills that room instead of moving the card. A first visit, or one where nothing can be kept, is as
|
|
40
|
+
// before. The place is taken once, as the read lands (what the next read will draw), not later: a banner that comes and goes
|
|
41
|
+
// after (a change made, a failed re-read) would hold room the next visit does not fill (review of #6432).
|
|
42
|
+
const useBeforePaint = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
43
|
+
const HOLDS = "gb.list-hold";
|
|
44
|
+
/** At most this many places are kept, the oldest dropped first. */
|
|
45
|
+
const HOLDS_KEPT = 200;
|
|
46
|
+
// The page's own width (the admin's rail takes some) and which side of 768px it is on: the header's spacing changes there.
|
|
47
|
+
const holdSlot = (key: string, page: Element) => {
|
|
48
|
+
const w = page.getBoundingClientRect().width;
|
|
49
|
+
return `${key}@${window.matchMedia("(min-width: 48em)").matches ? "w" : "n"}${Math.round(w / 40)}`;
|
|
50
|
+
};
|
|
51
|
+
function readHolds(): Record<string, number> {
|
|
52
|
+
try {
|
|
53
|
+
const v = JSON.parse(localStorage.getItem(HOLDS) ?? "{}");
|
|
54
|
+
return v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
55
|
+
} catch {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function readHold(slot: string): number {
|
|
60
|
+
const v = Number(readHolds()[slot]);
|
|
61
|
+
return Number.isFinite(v) && v > 0 ? v : 0;
|
|
62
|
+
}
|
|
63
|
+
function writeHold(slot: string, top: number): void {
|
|
64
|
+
try {
|
|
65
|
+
const holds = readHolds();
|
|
66
|
+
if (holds[slot] === top) return;
|
|
67
|
+
delete holds[slot];
|
|
68
|
+
holds[slot] = top;
|
|
69
|
+
const slots = Object.keys(holds);
|
|
70
|
+
for (const old of slots.slice(0, Math.max(0, slots.length - HOLDS_KEPT))) delete holds[old];
|
|
71
|
+
localStorage.setItem(HOLDS, JSON.stringify(holds));
|
|
72
|
+
} catch { /* a private window keeps nothing: no hold */ }
|
|
73
|
+
}
|
|
74
|
+
const noSubscription = () => () => {};
|
|
75
|
+
|
|
35
76
|
export interface ListPageAction {
|
|
36
77
|
content: string;
|
|
37
78
|
onAction?: () => void;
|
|
@@ -57,7 +98,7 @@ const WIDE_SECONDARY = 2;
|
|
|
57
98
|
|
|
58
99
|
export function ListPage({
|
|
59
100
|
title, subtitle, back, titleMeta, primaryAction, secondaryActions = [], actionGroups = [], notices, toolbar,
|
|
60
|
-
state = "ready", empty, noMatch, error, loadingRows = 3, loadingText = "Loading…", cardTitle, cardMeta, cardLead, card = true, cardProps, after, children, linkAs = "a",
|
|
101
|
+
state = "ready", empty, noMatch, error, loadingRows = 3, loadingText = "Loading…", cardTitle, cardMeta, cardLead, card = true, cardProps, after, children, linkAs = "a", holdKey,
|
|
61
102
|
}: {
|
|
62
103
|
title: React.ReactNode;
|
|
63
104
|
/** One line under the title: what the page holds, with its count first when it has one ("12 rules · 9 on."). */
|
|
@@ -111,9 +152,18 @@ export function ListPage({
|
|
|
111
152
|
children?: React.ReactNode;
|
|
112
153
|
/** The app's link (Next's Link), as IndexTable takes it. */
|
|
113
154
|
linkAs?: React.ElementType;
|
|
155
|
+
/** Keep the card's place once read under this key (the page and its shop, `gemseel:orders:<shop>`), and while the list loads
|
|
156
|
+
* again hold the room above the card, so what comes with the read does not push it down (WHERE THE CARD STOOD, above). */
|
|
157
|
+
holdKey?: string;
|
|
114
158
|
}) {
|
|
115
159
|
const Link = linkAs;
|
|
116
160
|
const uid = useId();
|
|
161
|
+
const pageRef = useRef<HTMLDivElement>(null);
|
|
162
|
+
const cardRef = useRef<HTMLElement>(null);
|
|
163
|
+
// A page the server drew was painted before this code ran: holding its card now would move it, the shift this is for. True only
|
|
164
|
+
// on the render that hydrates it (and on the server); its first loading is left as drawn, later ones are held.
|
|
165
|
+
const hydrating = useSyncExternalStore(noSubscription, () => false, () => true);
|
|
166
|
+
const paintedByServer = useRef(hydrating);
|
|
117
167
|
const wide = secondaryActions.slice(0, WIDE_SECONDARY);
|
|
118
168
|
const overflow = secondaryActions.slice(WIDE_SECONDARY);
|
|
119
169
|
const hasActions = Boolean(primaryAction) || secondaryActions.length > 0 || actionGroups.length > 0;
|
|
@@ -194,8 +244,41 @@ export function ListPage({
|
|
|
194
244
|
// A lead is card content, and a card that came and went would remount it (review of 3d).
|
|
195
245
|
const boxed = card || (cardLead != null && cardLead !== false) || (state !== "ready" && !(state === "empty" && empty != null));
|
|
196
246
|
|
|
247
|
+
// Loading: the card waits where it stood once read. Its margin is set on the element before the first paint, on top of its own,
|
|
248
|
+
// and set again whenever the page changes height while it loads (a band above it that reads on its own), so its top stays the
|
|
249
|
+
// kept one; it is put back before the paint that shows the read.
|
|
250
|
+
useBeforePaint(() => {
|
|
251
|
+
if (state !== "loading") { paintedByServer.current = false; return; }
|
|
252
|
+
const page = pageRef.current;
|
|
253
|
+
const box = cardRef.current;
|
|
254
|
+
if (!holdKey || paintedByServer.current || !page || !box) return;
|
|
255
|
+
const want = readHold(holdSlot(holdKey, page));
|
|
256
|
+
if (!want) return;
|
|
257
|
+
const own = box.style.marginTop;
|
|
258
|
+
const base = parseFloat(getComputedStyle(box).marginTop) || 0;
|
|
259
|
+
let added = 0;
|
|
260
|
+
const place = () => {
|
|
261
|
+
const top = box.getBoundingClientRect().top - page.getBoundingClientRect().top;
|
|
262
|
+
const next = Math.max(0, added + want - top);
|
|
263
|
+
if (Math.abs(next - added) >= 1) { added = next; box.style.marginTop = `${base + added}px`; }
|
|
264
|
+
};
|
|
265
|
+
place();
|
|
266
|
+
const watch = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(place);
|
|
267
|
+
watch?.observe(page);
|
|
268
|
+
return () => { watch?.disconnect(); box.style.marginTop = own; };
|
|
269
|
+
}, [holdKey, state]);
|
|
270
|
+
// Read (a list, an empty one, or none matching; not a failed read): keep where the card stands as the read lands.
|
|
271
|
+
useBeforePaint(() => {
|
|
272
|
+
if (!holdKey || state === "loading" || state === "error" || !boxed) return;
|
|
273
|
+
const page = pageRef.current;
|
|
274
|
+
const box = cardRef.current;
|
|
275
|
+
if (!page || !box) return;
|
|
276
|
+
const top = Math.round(box.getBoundingClientRect().top - page.getBoundingClientRect().top);
|
|
277
|
+
if (top > 0) writeHold(holdSlot(holdKey, page), top);
|
|
278
|
+
}, [holdKey, state, boxed]);
|
|
279
|
+
|
|
197
280
|
return (
|
|
198
|
-
<div className="ui-list-page">
|
|
281
|
+
<div className="ui-list-page" ref={pageRef}>
|
|
199
282
|
<header className={`ui-list-page__head${back ? " ui-list-page__head--back" : ""}`}>
|
|
200
283
|
{back ? (
|
|
201
284
|
<Link href={back.href} className="ui-btn ui-btn--icon ui-list-page__back" aria-label={`Back to ${back.label}`} title={back.label}>
|
|
@@ -224,7 +307,7 @@ export function ListPage({
|
|
|
224
307
|
{notices ? <div className="ui-list-page__notices">{notices}</div> : null}
|
|
225
308
|
{toolbar ? <div className="ui-list-page__toolbar">{toolbar}</div> : null}
|
|
226
309
|
{boxed ? (
|
|
227
|
-
<section {...cardProps} className={["ui-card ui-list-page__card", cardProps?.className].filter(Boolean).join(" ")}>
|
|
310
|
+
<section {...cardProps} ref={cardRef} className={["ui-card ui-list-page__card", cardProps?.className].filter(Boolean).join(" ")}>
|
|
228
311
|
{cardTitle ? <div className="ui-list-page__card-head"><h2 className="ui-list-page__card-title">{cardTitle}</h2>{cardMeta}</div> : null}
|
|
229
312
|
{cardLead}
|
|
230
313
|
{body}
|