@gemboss/ui 0.65.0 → 0.67.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 +349 -2
- package/README.md +33 -4
- package/catalog/editor.html +21 -13
- package/catalog/index.html +6 -6
- package/gemboss-ui.css +3 -3
- package/package.json +10 -1
- package/parts/components.css +2 -2
- package/parts/core.css +1 -1
- package/parts/shell.css +1 -1
- package/src/assistant/engine.tsx +2 -18
- package/src/auth.tsx +1 -15
- package/src/board-auto-more.tsx +168 -0
- package/src/collections.tsx +10 -1
- package/src/confirm-buttons.ts +37 -0
- package/src/confirm-dialog.css +1 -0
- package/src/confirm-dialog.tsx +128 -0
- package/src/copy-field.css +1 -0
- package/src/copy-field.tsx +48 -0
- package/src/copy-text.ts +20 -0
- package/src/create-shell.css +1 -1
- package/src/create-shell.tsx +7 -4
- package/src/dialog.css +1 -0
- package/src/dialog.tsx +46 -7
- package/src/editor/choice-cards.tsx +71 -0
- package/src/editor/controls.tsx +61 -19
- package/src/editor/field-control.tsx +146 -58
- package/src/editor/field-frame.tsx +20 -10
- package/src/editor/field-spec.ts +43 -8
- package/src/editor/index.ts +16 -5
- package/src/editor/items-field.tsx +185 -0
- package/src/editor/items.ts +126 -0
- package/src/editor/label-side.ts +11 -4
- package/src/editor/panel.tsx +39 -12
- package/src/editor/repeater.tsx +37 -7
- package/src/editor/secret-field.tsx +118 -0
- package/src/editor/switch.tsx +34 -0
- package/src/editor-color.css +1 -1
- package/src/editor-grow.css +1 -0
- package/src/editor-insert.css +1 -1
- package/src/editor-plain.js +1 -1
- package/src/editor-repeater.css +1 -1
- package/src/editor-switch.css +1 -0
- package/src/editor.css +1 -1
- package/src/eye-icon.tsx +14 -0
- package/src/gemboss-field.css +1 -1
- package/src/icons-plain.js +1 -0
- package/src/icons.tsx +9 -0
- package/src/index.ts +7 -1
- package/src/kit-plain.css +1 -1
- package/src/list-page.css +1 -1
- package/src/list-page.tsx +94 -51
- package/src/list-toolbar.css +1 -0
- package/src/list-toolbar.tsx +85 -0
- package/src/menu-keys.ts +3 -1
- package/src/search-dialog.tsx +4 -1
- package/src/segmented.tsx +24 -6
- package/src/service-switcher.tsx +2 -2
- package/src/settings-dialog.tsx +2 -2
- package/src/ui.css +1 -1
package/src/collections.tsx
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* without React writes these classes by hand and gets the same thing.
|
|
17
17
|
*/
|
|
18
18
|
import "./collections.css"; // its own stylesheet travels with it (0.23.0): a surface that never renders it never loads it
|
|
19
|
+
import { BoardAutoMore, type BoardAutoMoreOptions } from "./board-auto-more";
|
|
19
20
|
import React from "react";
|
|
20
21
|
import { attachBoardMove } from "./board-move";
|
|
21
22
|
|
|
@@ -417,6 +418,12 @@ export type BoardProps = {
|
|
|
417
418
|
* narrower than that, the board scrolls sideways as before. For a board whose stages are read side by side (Plan's four).
|
|
418
419
|
* Without it a column is at least 240 and the board scrolls past what fits. The phone's 78% columns are unchanged. */
|
|
419
420
|
minColumn?: number;
|
|
421
|
+
/** 09/11/2026: a server-paged column (`moreHref` / `hasMore` + `onLoadMore`) loads its next page as it is scrolled: when its
|
|
422
|
+
* "Show more" row comes within `margin` (400px) of the bottom of the scrolling area, the row's own control is pressed, at most
|
|
423
|
+
* `max` (4) times a column, then the button is left for the reader. Only a press handled in place counts (onLoadMore, a router
|
|
424
|
+
* link with `scroll: false`); a plain `<a>` and kit-plain's `fetchMore` link are left to the reader. `true` = the defaults.
|
|
425
|
+
* A client island inside the board (board-auto-more.tsx); the board itself stays plain. */
|
|
426
|
+
autoMore?: boolean | BoardAutoMoreOptions;
|
|
420
427
|
className?: string;
|
|
421
428
|
};
|
|
422
429
|
|
|
@@ -426,7 +433,7 @@ export const BOARD_MOVE_HELP = "Press Space to pick the card up, arrow keys to m
|
|
|
426
433
|
/** 12 cards a column, then "Show 24 more" (nested `<details>`, no script): the GemFactory rule, now everyone's. With
|
|
427
434
|
* `hasMore` (0.18.0) the server pages instead; with `onMove` cards move between columns. */
|
|
428
435
|
export function Board({ columns, label, id, pageSize = 12, step = 24, moreLabel = (n) => `Show ${n} more`, emptyLabel = "Nothing here",
|
|
429
|
-
onLoadMore, linkAs: Link = "a", moreLinkProps, fetchMore, onMove, columnHeading, minColumn, className }: BoardProps) {
|
|
436
|
+
onLoadMore, linkAs: Link = "a", moreLinkProps, fetchMore, onMove, columnHeading, minColumn, autoMore, className }: BoardProps) {
|
|
430
437
|
const Name = (columnHeading ? `h${columnHeading}` : "span") as "span";
|
|
431
438
|
const movable = !!onMove;
|
|
432
439
|
// A floor that is not a positive number is no floor: the board keeps the stylesheet's 240 (review of #5922).
|
|
@@ -472,6 +479,8 @@ export function Board({ columns, label, id, pageSize = 12, step = 24, moreLabel
|
|
|
472
479
|
style={fit ? ({ "--ui-board-col": `max(${minColumn}px, calc((100% - ${columns.length - 1} * var(--ui-space-4)) / ${columns.length}))` } as React.CSSProperties) : undefined}>
|
|
473
480
|
{movable ? <p id={help} hidden>{BOARD_MOVE_HELP}</p> : null}
|
|
474
481
|
{movable ? <div className="ui-sr-only" aria-live="assertive" data-gb-live="" /> : null}
|
|
482
|
+
{autoMore && columns.some((c) => c.hasMore != null || c.moreHref != null)
|
|
483
|
+
? <BoardAutoMore {...(typeof autoMore === "object" ? autoMore : {})} /> : null}
|
|
475
484
|
{columns.map((col) => {
|
|
476
485
|
const cards = entries(col);
|
|
477
486
|
const server = col.hasMore != null || col.moreHref != null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// The state of ConfirmDialog's buttons, from what the caller says (busy, error, …) and which button was pressed last. Pure, so
|
|
2
|
+
// confirm-buttons.test.ts holds it without a browser (review of #5178: the dialog's rules were checked only as source text).
|
|
3
|
+
|
|
4
|
+
export interface ConfirmButtonsInput {
|
|
5
|
+
action: string;
|
|
6
|
+
/** The second way through ("Archive instead"), when there is one. */
|
|
7
|
+
alternative?: string;
|
|
8
|
+
cancelLabel: string;
|
|
9
|
+
/** While busy, the way out stays open under this name ("Close"): the work goes on and reports where the caller says. */
|
|
10
|
+
busyCloseLabel?: string;
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
alternativeDisabled: boolean;
|
|
13
|
+
busy: boolean;
|
|
14
|
+
error: boolean;
|
|
15
|
+
/** False when pressing again cannot change the answer (a refusal before anything ran): no Try again, only the way out. */
|
|
16
|
+
canRetry: boolean;
|
|
17
|
+
last: "main" | "alternative";
|
|
18
|
+
/** The pressed button's words once the server has refused it (default "Try again"): a surface in another language says its own. */
|
|
19
|
+
retryLabel?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ConfirmButton { content: string; loading: boolean; disabled: boolean }
|
|
23
|
+
|
|
24
|
+
export function confirmButtons(s: ConfirmButtonsInput): { main: ConfirmButton; alternative: ConfirmButton | null; cancel: { content: string; disabled: boolean } } {
|
|
25
|
+
// The busy state and the refusal belong to the button pressed last: a refused Archive must not turn Delete into Try again.
|
|
26
|
+
const failed = s.error && s.canRetry ? s.last : null;
|
|
27
|
+
const stuck = s.error && !s.canRetry;
|
|
28
|
+
return {
|
|
29
|
+
main: { content: failed === "main" ? (s.retryLabel ?? "Try again") : s.action, loading: s.busy && s.last === "main", disabled: s.disabled || stuck || (s.busy && s.last !== "main") },
|
|
30
|
+
alternative: s.alternative === undefined ? null : {
|
|
31
|
+
content: failed === "alternative" ? (s.retryLabel ?? "Try again") : s.alternative,
|
|
32
|
+
loading: s.busy && s.last === "alternative",
|
|
33
|
+
disabled: s.alternativeDisabled || stuck || (s.busy && s.last !== "alternative"),
|
|
34
|
+
},
|
|
35
|
+
cancel: { content: s.busy && s.busyCloseLabel ? s.busyCloseLabel : s.cancelLabel, disabled: s.busy && !s.busyCloseLabel },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.ui-confirm__words{margin:0}.ui-confirm .ui-modal__foot .ui-spinner{display:inline-block;flex:none;width:14px;height:14px;margin-right:6px;box-sizing:border-box;border:2px solid currentColor;border-right-color:transparent;border-radius:50%;vertical-align:-2px;animation:ui-confirm-busy .8s linear infinite}@keyframes ui-confirm-busy{to{transform:rotate(360deg)}}@media (prefers-reduced-motion: reduce){.ui-confirm .ui-modal__foot .ui-spinner{animation-duration:2s}}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// THE QUESTION BEFORE AN ACT THE SERVER DOES (Gems/CLAUDE.md §13), ONE FOR EVERY APP (09/11/2026). It was the admin's own
|
|
4
|
+
// (components/ui/ConfirmDialog.tsx) drawn in a Polaris Modal: a portal under the browser's top layer, so a confirm asked from a kit
|
|
5
|
+
// Sheet or Dialog (an offer's Delete, Delete images, a calendar date's Remove) opened BEHIND it and could not be pressed, and those
|
|
6
|
+
// screens drew a red button of their own instead. Now it is the kit's, drawn in the kit's Dialog, so it opens over anything; the
|
|
7
|
+
// admin's path re-exports it, and GemCommunity and the toolkits can ask the same way.
|
|
8
|
+
//
|
|
9
|
+
// What it does, as before: it stays open while the server answers (Cancel, Escape, ✕ and the backdrop wait too, unless the caller
|
|
10
|
+
// lets a long batch be closed: `busyCloseLabel`), says a refusal in place where the seller is looking, and offers Try again when
|
|
11
|
+
// pressing again can change the answer (`canRetry`). It closes only when the caller says the thing is done (`open` turns false). An
|
|
12
|
+
// act that can be undone asks through it too, not in red (`destructive={false}`). The buttons' rules: confirm-buttons.ts.
|
|
13
|
+
|
|
14
|
+
import "./confirm-dialog.css";
|
|
15
|
+
import { useCallback, useRef, useState, type ReactNode } from "react";
|
|
16
|
+
import { Dialog } from "./dialog";
|
|
17
|
+
import { confirmButtons } from "./confirm-buttons";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* One question about one thing (a row's Delete), as a screen asks it (review of #7039: four screens wrote this state by hand).
|
|
21
|
+
* `ask(item)` opens it about that item, with no refusal from last time. `confirm(act)` runs the act for the item asked about: busy
|
|
22
|
+
* while it runs, a refusal (the string `act` returns) stays in the question with Try again, and nothing (null) closes it. The item
|
|
23
|
+
* is kept after it closes, so its title does not go blank while the dialog shuts.
|
|
24
|
+
* const del = useConfirmAsk<Section>();
|
|
25
|
+
* <ConfirmDialog open={del.open} busy={del.busy} error={del.error} onClose={del.close} title={`Delete “${del.item?.title ?? ""}”?`}
|
|
26
|
+
* action="Delete section" onConfirm={() => void del.confirm(async (s) => (await remove(s)).ok ? null : "It was not deleted.")}>…
|
|
27
|
+
*/
|
|
28
|
+
export function useConfirmAsk<T>() {
|
|
29
|
+
const [asked, setAsked] = useState<{ item: T; open: boolean } | null>(null);
|
|
30
|
+
const [busy, setBusy] = useState(false);
|
|
31
|
+
const [error, setError] = useState<string | null>(null);
|
|
32
|
+
const ask = useCallback((item: T) => { setError(null); setAsked({ item, open: true }); }, []);
|
|
33
|
+
const close = useCallback(() => setAsked((a) => (a ? { ...a, open: false } : a)), []);
|
|
34
|
+
const confirm = useCallback(async (act: (item: T) => Promise<string | null | undefined>) => {
|
|
35
|
+
if (!asked) return;
|
|
36
|
+
setBusy(true);
|
|
37
|
+
setError(null);
|
|
38
|
+
let refusal: string | null | undefined;
|
|
39
|
+
try { refusal = await act(asked.item); } catch (e) { refusal = e instanceof Error && e.message ? e.message : "That did not go through."; }
|
|
40
|
+
setBusy(false);
|
|
41
|
+
if (refusal) setError(refusal); else close();
|
|
42
|
+
}, [asked, close]);
|
|
43
|
+
return { item: asked ? asked.item : null, open: Boolean(asked?.open), busy, error, ask, close, confirm };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A sentence, or a sentence in pieces (`“{name}” will be…`): drawn as a paragraph. Anything else is the caller's own blocks. */
|
|
47
|
+
const isWords = (c: ReactNode): boolean =>
|
|
48
|
+
typeof c === "string" || typeof c === "number" || (Array.isArray(c) && c.every((x) => x == null || typeof x === "string" || typeof x === "number"));
|
|
49
|
+
|
|
50
|
+
export interface ConfirmDialogProps {
|
|
51
|
+
open: boolean;
|
|
52
|
+
title: string;
|
|
53
|
+
/** The main button's words ("Remove", "Revoke"); "Try again" once the server has refused it. */
|
|
54
|
+
action: string;
|
|
55
|
+
/** False for a question about something that can be undone (Take off sale): the main button is not red. */
|
|
56
|
+
destructive?: boolean;
|
|
57
|
+
/** A second way through that also asks the server ("Archive instead"). It waits like the main button, and a refusal of it
|
|
58
|
+
* offers Try again on IT, not on the main button. `disabled` while it can't be pressed yet. */
|
|
59
|
+
alternative?: { content: string; onAction: () => void; disabled?: boolean };
|
|
60
|
+
/** The way out, in this question's words ("Keep it running", "Keep editing"). */
|
|
61
|
+
cancelLabel?: string;
|
|
62
|
+
/** A batch that can take minutes: while busy the way out stays open under this name ("Close") and the caller says the outcome
|
|
63
|
+
* elsewhere. Without it, nothing closes the dialog while busy. */
|
|
64
|
+
busyCloseLabel?: string;
|
|
65
|
+
/** The main button can't be pressed now (a run is going, a check is still reading); the body says why. */
|
|
66
|
+
disabled?: boolean;
|
|
67
|
+
busy: boolean;
|
|
68
|
+
error: string | null;
|
|
69
|
+
/** False when the refusal can't change by pressing again (not connected, not allowed): the buttons stay but are off, the notice
|
|
70
|
+
* says why, and Cancel is the way out. */
|
|
71
|
+
canRetry?: boolean;
|
|
72
|
+
onConfirm: () => void;
|
|
73
|
+
onClose: () => void;
|
|
74
|
+
/** What happens: a sentence (drawn as a paragraph), or the caller's own blocks. */
|
|
75
|
+
children: ReactNode;
|
|
76
|
+
/** 620 wide (Polaris' default Modal) instead of the kit's 460: a question that lists what goes (images, photos). */
|
|
77
|
+
wide?: boolean;
|
|
78
|
+
/** The refused button's words (default "Try again") and the ✕'s name (default "Close"), for a surface in the viewer's language
|
|
79
|
+
* (GemCommunity: en / vi / zh; 09/11/2026). */
|
|
80
|
+
retryLabel?: string;
|
|
81
|
+
closeLabel?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function ConfirmDialog({ open, title, action, destructive = true, alternative, cancelLabel = "Cancel", busyCloseLabel, disabled = false, busy, error, canRetry = true, onConfirm, onClose, children, wide = false, retryLabel, closeLabel }: ConfirmDialogProps) {
|
|
85
|
+
const closable = !busy || Boolean(busyCloseLabel);
|
|
86
|
+
// onClose is the person closing it. The kit's Dialog also reports the close that `open` turning false makes (the caller closing
|
|
87
|
+
// it when the thing is done): not forwarded, so a caller hears one close, as with the Polaris Modal this replaced.
|
|
88
|
+
const openNow = useRef(open);
|
|
89
|
+
openNow.current = open;
|
|
90
|
+
const close = () => { if (closable && openNow.current) onClose(); };
|
|
91
|
+
// Which button the busy state and the refusal belong to: the last one pressed, from this opening (a caller that keeps the
|
|
92
|
+
// dialog mounted must not carry the last opening's press into the next one).
|
|
93
|
+
const [last, setLast] = useState<"main" | "alternative">("main");
|
|
94
|
+
// The body is mounted only while it is shown, as the Polaris Modal's was (review of #7039): the kit's Dialog keeps its <dialog> in
|
|
95
|
+
// the page, and 50 callers' fields (fixed ids, their own state, effects) were written for mount-on-open. Mounted on opening,
|
|
96
|
+
// let go once the dialog has closed, so it never empties on screen.
|
|
97
|
+
const [shown, setShown] = useState(open);
|
|
98
|
+
const [wasOpen, setWasOpen] = useState(open);
|
|
99
|
+
if (open !== wasOpen) { setWasOpen(open); if (open) { setLast("main"); setShown(true); } }
|
|
100
|
+
const closed = () => { setShown(false); close(); };
|
|
101
|
+
const b = confirmButtons({ action, alternative: alternative?.content, cancelLabel, busyCloseLabel, disabled, alternativeDisabled: Boolean(alternative?.disabled),
|
|
102
|
+
busy, error: error !== null, canRetry, last, retryLabel });
|
|
103
|
+
const spinner = <span className="ui-spinner" aria-hidden="true" />;
|
|
104
|
+
// An off button stays focusable (aria-disabled, never disabled: the kit's rule, Gems/CLAUDE.md §13), so the focus stays in the
|
|
105
|
+
// question while the server answers, and its press does nothing.
|
|
106
|
+
const off = (o: boolean) => (o ? { "aria-disabled": true as const } : {});
|
|
107
|
+
return (
|
|
108
|
+
<Dialog open={open} onClose={closed} title={title} dismissible={closable} wide={wide} className="ui-confirm" closeLabel={closeLabel} footer={(
|
|
109
|
+
<>
|
|
110
|
+
{alternative && b.alternative ? (
|
|
111
|
+
<button type="button" className="ui-btn" {...off(b.alternative.disabled || b.alternative.loading)} aria-busy={b.alternative.loading || undefined}
|
|
112
|
+
onClick={() => { if (b.alternative!.disabled || b.alternative!.loading) return; setLast("alternative"); alternative.onAction(); }}>{b.alternative.loading ? spinner : null}{b.alternative.content}</button>
|
|
113
|
+
) : null}
|
|
114
|
+
{/* Focus starts on the way out, as the kit's plain confirm (README "confirm"): an Enter pressed too soon does not delete. */}
|
|
115
|
+
<button type="button" className="ui-btn" data-autofocus {...off(b.cancel.disabled)} onClick={() => { if (!b.cancel.disabled) close(); }}>{b.cancel.content}</button>
|
|
116
|
+
<button type="button" className={destructive ? "ui-btn ui-btn--primary ui-btn--critical" : "ui-btn ui-btn--primary"} {...off(b.main.disabled || b.main.loading)}
|
|
117
|
+
aria-busy={b.main.loading || undefined} onClick={() => { if (b.main.disabled || b.main.loading) return; setLast("main"); onConfirm(); }}>{b.main.loading ? spinner : null}{b.main.content}</button>
|
|
118
|
+
</>
|
|
119
|
+
)}>
|
|
120
|
+
{shown ? (
|
|
121
|
+
<div className="ui-stack ui-stack--tight">
|
|
122
|
+
{error ? <p className="ui-notice ui-notice--danger" role="alert">{error}</p> : null}
|
|
123
|
+
{isWords(children) ? <p className="ui-confirm__words">{children}</p> : children}
|
|
124
|
+
</div>
|
|
125
|
+
) : null}
|
|
126
|
+
</Dialog>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.ui-copy-field{display:flex;flex-wrap:wrap;align-items:center;gap:8px;min-width:0}.ui-copy-field__value{flex:1 1 220px;min-width:0;background:var(--gemboss-divider-soft)}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// A VALUE TO TAKE AWAY (09/11/2026; Chris 08/11: one control set). A link to send traffic to, a review link, a code: the value in a box the
|
|
3
|
+
// seller can select but not change (focus selects it whole), and Copy beside it, which says Copied for two seconds, or "Copy it by hand"
|
|
4
|
+
// when the browser refuses the clipboard (the box is selected then, so ⌘C / Ctrl+C takes it). More actions on the same row come after
|
|
5
|
+
// Copy (`children`: an Open). The admin drew this by hand on several screens (Go live's link, a share-for-review link), each its own box.
|
|
6
|
+
import "./copy-field.css"; // its own stylesheet travels with it: a surface that never draws it never loads it
|
|
7
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
8
|
+
import { copyText } from "./copy-text";
|
|
9
|
+
|
|
10
|
+
export interface CopyFieldProps {
|
|
11
|
+
value: string;
|
|
12
|
+
/** The box's accessible name ("Link for your traffic"). */
|
|
13
|
+
label: string;
|
|
14
|
+
/** The button's words. Default "Copy link". */
|
|
15
|
+
copyLabel?: string;
|
|
16
|
+
/** More actions on the row, after Copy (an Open). */
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
/** Told after a press: copied (true), or the browser refused (false). */
|
|
19
|
+
onCopied?: (ok: boolean) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function CopyField({ value, label, copyLabel = "Copy link", children, onCopied }: CopyFieldProps) {
|
|
23
|
+
const [said, setSaid] = useState<"idle" | "done" | "failed">("idle");
|
|
24
|
+
const box = useRef<HTMLInputElement>(null);
|
|
25
|
+
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
26
|
+
useEffect(() => () => { if (timer.current) clearTimeout(timer.current); }, []);
|
|
27
|
+
const say = (s: "done" | "failed") => {
|
|
28
|
+
setSaid(s);
|
|
29
|
+
if (timer.current) clearTimeout(timer.current);
|
|
30
|
+
timer.current = setTimeout(() => { timer.current = null; setSaid("idle"); }, 2000);
|
|
31
|
+
};
|
|
32
|
+
// The kit's one copy (copyText: the Clipboard API, else the old way). Refused both ways, the box takes the focus with its text selected,
|
|
33
|
+
// so ⌘C / Ctrl+C is the next key.
|
|
34
|
+
const copy = () => {
|
|
35
|
+
void copyText(value).then((ok) => {
|
|
36
|
+
if (!ok) box.current?.focus(); // its onFocus selects it whole
|
|
37
|
+
say(ok ? "done" : "failed");
|
|
38
|
+
onCopied?.(ok);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
return (
|
|
42
|
+
<div className="ui-copy-field">
|
|
43
|
+
<input ref={box} className="gemboss-field ui-copy-field__value" value={value} readOnly aria-label={label} onFocus={(e) => e.currentTarget.select()} />
|
|
44
|
+
<button type="button" className="ui-btn" onClick={copy}>{said === "done" ? "Copied" : said === "failed" ? "Copy it by hand" : copyLabel}</button>
|
|
45
|
+
{children}
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
package/src/copy-text.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Text onto the clipboard: the Clipboard API, else (an http:// page, a refused permission, an old Safari) a selected text area and
|
|
2
|
+
// execCommand. True when it got there. Its own module (09/11/2026, CopyField): the assistant's engine re-exports it.
|
|
3
|
+
/** Copies through the async clipboard, else through a selected textarea (an http:// page, an old Safari). */
|
|
4
|
+
export async function copyText(text: string): Promise<boolean> {
|
|
5
|
+
try {
|
|
6
|
+
if (navigator.clipboard?.writeText) { await navigator.clipboard.writeText(text); return true; }
|
|
7
|
+
} catch { /* permission refused: try the old way */ }
|
|
8
|
+
try {
|
|
9
|
+
const ta = document.createElement("textarea");
|
|
10
|
+
ta.value = text;
|
|
11
|
+
ta.setAttribute("readonly", "");
|
|
12
|
+
ta.style.position = "fixed";
|
|
13
|
+
ta.style.opacity = "0";
|
|
14
|
+
document.body.appendChild(ta);
|
|
15
|
+
ta.select();
|
|
16
|
+
const ok = document.execCommand("copy");
|
|
17
|
+
ta.remove();
|
|
18
|
+
return ok;
|
|
19
|
+
} catch { return false; }
|
|
20
|
+
}
|
package/src/create-shell.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.ui-create-icon{display:grid;place-items:center;width:100%;height:100%;min-width:30px;min-height:30px;border-radius:var(--gemboss-radius-md, 8px);background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent, #5661f5)}.ui-create-steps{display:flex;align-items:center;gap:8px;margin:0;padding:0;list-style:none;font-size:var(--gemboss-fs-caption, 12px);color:var(--ui-text-muted)}.ui-create-step{display:flex;align-items:center;gap:6px;white-space:nowrap}.ui-create-step+.ui-create-step:before{content:"";width:24px;height:1px;margin-right:2px;background:var(--ui-border)}.ui-create-step__n{display:grid;place-items:center;width:20px;height:20px;box-sizing:border-box;border:1px solid var(--ui-border);border-radius:999px;font-size:var(--gemboss-fs-micro, 11px)}.ui-create-step--on{font-weight:600;color:var(--ui-text)}.ui-create-step--on .ui-create-step__n{border-color:var(--ui-text);background:var(--ui-text);color:var(--gemboss-surface, #fff)}.ui-create-step--done .ui-create-step__n{border-color:transparent;background:var(--gemboss-success-soft, #e6f4ee);color:var(--gemboss-success, #007f5f)}.ui-create-rail{display:flex;flex-direction:column;gap:20px;min-height:100%;box-sizing:border-box;padding:20px;background:var(--ui-surface)}.ui-create-rail__foot{margin:auto 0 0;font-size:var(--gemboss-fs-caption, 12px);line-height:1.5;color:var(--ui-text-muted)}.ui-create-group{display:flex;flex-direction:column;gap:8px}.ui-create-label{font-size:var(--gemboss-fs-micro, 11px);font-weight:600;letter-spacing:.08em;text-transform:uppercase;color:var(--ui-text-muted)}.ui-create-door{display:flex;align-items:center;gap:12px;width:100%;min-height:56px;padding:8px 12px;text-align:left;cursor:pointer;border:1px solid var(--ui-border);border-radius:var(--gemboss-radius-lg, 12px);background:var(--gemboss-surface, #fff);color:var(--ui-text);font:inherit}.ui-create-door:hover{border-color:var(--ui-text-muted)}.ui-create-door--on{border-color:var(--ui-text);box-shadow:inset 0 0 0 1px var(--ui-text)}.ui-create-door:disabled{opacity:.5;cursor:default}.ui-create-door__art{flex:none;display:grid;place-items:center;width:32px;height:32px;border-radius:var(--gemboss-radius-md, 8px);background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent, #5661f5)}.ui-create-door__col{display:flex;flex-direction:column;gap:2px;min-width:0}.ui-create-door__col b{font-size:var(--gemboss-fs-body, 14px);font-weight:600}.ui-create-door__col span{font-size:var(--gemboss-fs-caption, 12px);line-height:1.4;color:var(--ui-text-muted)}.ui-create-chips{display:flex;flex-wrap:wrap;gap:6px}.ui-create-chip{display:inline-flex;align-items:center;gap:6px;min-height:32px;padding:0 12px;cursor:pointer;border:1px solid var(--ui-border);border-radius:999px;background:var(--gemboss-surface, #fff);color:var(--ui-text);font:inherit;font-size:var(--gemboss-fs-caption, 12px)}.ui-create-chip--on{border-color:var(--ui-text);background:var(--ui-text);color:var(--gemboss-surface, #fff);font-weight:600}.ui-create-chip__n{opacity:.6}.ui-create-dot{flex:none;width:8px;height:8px;border-radius:999px;background:#a4a6ad}.ui-create-dot--cold{background:#5661f5}.ui-create-dot--warm{background:#c27c0e}.ui-create-dot--ready{background:#d9480f}.ui-create-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(240px,100%),1fr));gap:16px}.ui-create-card{display:flex;flex-direction:column;min-width:0;overflow:hidden;border:1px solid var(--ui-border);border-radius:var(--gemboss-radius-xl, 16px);background:var(--gemboss-surface, #fff)}.ui-create-card--on{border-color:var(--ui-text);box-shadow:inset 0 0 0 1px var(--ui-text)}.ui-create-card--dashed{border-style:dashed}.ui-create-card__pic{position:relative;height:150px}.ui-create-card__pic>.ui-stage{height:100%;box-sizing:border-box;border-radius:0}.ui-create-card__badge{position:absolute;top:8px;left:8px;z-index:1;padding:2px 8px;border-radius:999px;background:var(--gemboss-surface, #fff);color:var(--ui-text);font-size:var(--gemboss-fs-micro, 11px);font-weight:600}.ui-create-card__body{display:flex;flex:1 1 auto;flex-direction:column;gap:6px;padding:12px 16px 16px}.ui-create-card__eyebrow{display:flex;align-items:center;gap:6px;font-size:var(--gemboss-fs-micro, 11px);font-weight:600;letter-spacing:.06em;text-transform:uppercase;color:var(--ui-text-muted)}.ui-create-card__eyebrow--cold{color:#5661f5}.ui-create-card__eyebrow--warm{color:#a86a0a}.ui-create-card__eyebrow--ready{color:#c2410c}.ui-create-card__title{margin:0;font-size:var(--gemboss-fs-body-lg, 16px);font-weight:600;color:var(--ui-text)}.ui-create-card__line{margin:0;font-size:var(--gemboss-fs-body, 14px);line-height:1.45;color:var(--ui-text-muted)}.ui-create-card__inside{margin:0;font-size:var(--gemboss-fs-caption, 12px);line-height:1.5;color:var(--ui-text)}.ui-create-card__note{margin:0;font-size:var(--gemboss-fs-caption, 12px);line-height:1.5;color:var(--ui-text-muted)}.ui-create-card__act{display:flex;flex-wrap:wrap;gap:8px;margin-top:auto;padding-top:8px}.ui-stage.ui-create-pic{justify-content:center;gap:6px;padding:16px 20%}.ui-create-pic .ui-stage__tile{padding:6px 12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ui-create-pic__more{align-self:center;color:var(--ui-stage-ink-dim)}.ui-create-pic--path{display:flex;align-items:center;justify-content:center;height:100%;box-sizing:border-box;padding:16px;background:radial-gradient(rgba(86,97,245,.13) 1px,transparent 1.5px) 0 0 / 16px 16px,linear-gradient(180deg,var(--gemboss-accent-wash, #f7f8ff),#f2f3fe);border-bottom:1px solid var(--gemboss-accent-tint, #dfe2ff);color:var(--ui-text);font-size:var(--gemboss-fs-caption, 12px)}.ui-create-path{display:flex;align-items:center;justify-content:center;flex-wrap:wrap;gap:6px}.ui-create-path__step{display:flex;align-items:center;gap:6px}.ui-create-path__arrow{color:#8b93ff}.ui-create-path__tile{display:flex;flex-direction:column;align-items:center;gap:4px;max-width:76px;padding:6px;text-align:center;border:1px solid var(--gemboss-accent-tint, #dfe2ff);border-radius:var(--gemboss-radius-md, 8px);background:var(--gemboss-surface, #fff);box-shadow:0 1px 2px #1b1c1e0f;font-size:var(--gemboss-fs-micro, 11px);line-height:1.2}.ui-create-path__tile img{width:40px;height:40px;object-fit:cover;border-radius:var(--gemboss-radius-sm, 6px);background:#f2f3fe}@media (max-width: 47.9975em){.ui-create-step:not(.ui-create-step--on){display:none}.ui-create-step+.ui-create-step:before{display:none}}@media (pointer: coarse){.ui-create-chip{min-height:44px}}
|
|
1
|
+
.ui-create-icon{display:grid;place-items:center;width:100%;height:100%;min-width:30px;min-height:30px;border-radius:var(--gemboss-radius-md, 8px);background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent, #5661f5)}.ui-create-steps{display:flex;align-items:center;gap:8px;margin:0;padding:0;list-style:none;font-size:var(--gemboss-fs-caption, 12px);color:var(--ui-text-muted)}.ui-create-step{display:flex;align-items:center;gap:6px;white-space:nowrap}.ui-create-step+.ui-create-step:before{content:"";width:24px;height:1px;margin-right:2px;background:var(--ui-border)}.ui-create-step__n{display:grid;place-items:center;width:20px;height:20px;box-sizing:border-box;border:1px solid var(--ui-border);border-radius:999px;font-size:var(--gemboss-fs-micro, 11px)}.ui-create-step--on{font-weight:600;color:var(--ui-text)}.ui-create-step--on .ui-create-step__n{border-color:var(--ui-text);background:var(--ui-text);color:var(--gemboss-surface, #fff)}.ui-create-step--done .ui-create-step__n{border-color:transparent;background:var(--gemboss-success-soft, #e6f4ee);color:var(--gemboss-success, #007f5f)}.ui-create-rail{display:flex;flex-direction:column;gap:20px;min-height:100%;box-sizing:border-box;padding:20px;background:var(--ui-surface)}.ui-create-rail__foot{margin:auto 0 0;font-size:var(--gemboss-fs-caption, 12px);line-height:1.5;color:var(--ui-text-muted)}.ui-create-group{display:flex;flex-direction:column;gap:8px}.ui-create-label{font-size:var(--gemboss-fs-micro, 11px);font-weight:600;letter-spacing:.08em;text-transform:uppercase;color:var(--ui-text-muted)}.ui-create-door{display:flex;align-items:center;gap:12px;width:100%;min-height:56px;padding:8px 12px;text-align:left;cursor:pointer;border:1px solid var(--ui-border);border-radius:var(--gemboss-radius-lg, 12px);background:var(--gemboss-surface, #fff);color:var(--ui-text);font:inherit}.ui-create-door:hover{border-color:var(--ui-text-muted)}.ui-create-door--on{border-color:var(--ui-text);box-shadow:inset 0 0 0 1px var(--ui-text)}.ui-create-door:disabled{opacity:.5;cursor:default}.ui-create-door__art{flex:none;display:grid;place-items:center;width:32px;height:32px;border-radius:var(--gemboss-radius-md, 8px);background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent, #5661f5)}.ui-create-door__col{display:flex;flex-direction:column;gap:2px;min-width:0}.ui-create-door__col b{font-size:var(--gemboss-fs-body, 14px);font-weight:600}.ui-create-door__col span{font-size:var(--gemboss-fs-caption, 12px);line-height:1.4;color:var(--ui-text-muted)}.ui-create-chips{display:flex;flex-wrap:wrap;gap:6px}.ui-create-chip{display:inline-flex;align-items:center;gap:6px;min-height:32px;padding:0 12px;cursor:pointer;border:1px solid var(--ui-border);border-radius:999px;background:var(--gemboss-surface, #fff);color:var(--ui-text);font:inherit;font-size:var(--gemboss-fs-caption, 12px)}.ui-create-chip--on{border-color:var(--ui-text);background:var(--ui-text);color:var(--gemboss-surface, #fff);font-weight:600}.ui-create-chip__n{opacity:.6}.ui-create-dot{flex:none;width:8px;height:8px;border-radius:999px;background:#a4a6ad}.ui-create-dot--cold{background:#5661f5}.ui-create-dot--warm{background:#c27c0e}.ui-create-dot--ready{background:#d9480f}.ui-create-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(240px,100%),1fr));gap:16px}.ui-create-grid--wide{grid-template-columns:repeat(auto-fill,minmax(min(340px,100%),1fr));gap:20px}.ui-create-card{display:flex;flex-direction:column;min-width:0;overflow:hidden;border:1px solid var(--ui-border);border-radius:var(--gemboss-radius-xl, 16px);background:var(--gemboss-surface, #fff)}.ui-create-card--on{border-color:var(--ui-text);box-shadow:inset 0 0 0 1px var(--ui-text)}.ui-create-card--dashed{border-style:dashed}.ui-create-card__pic{position:relative;height:150px}.ui-create-card__pic>.ui-stage{height:100%;box-sizing:border-box;border-radius:0}.ui-create-card__pic--wide{height:auto;aspect-ratio:16 / 9;overflow:hidden;border-bottom:1px solid var(--ui-border);background:var(--gemboss-surface, #fff)}.ui-create-card__badge{position:absolute;top:8px;left:8px;z-index:1;padding:2px 8px;border-radius:999px;background:var(--gemboss-surface, #fff);color:var(--ui-text);font-size:var(--gemboss-fs-micro, 11px);font-weight:600}.ui-create-card__body{display:flex;flex:1 1 auto;flex-direction:column;gap:6px;padding:12px 16px 16px}.ui-create-card__eyebrow{display:flex;align-items:center;gap:6px;font-size:var(--gemboss-fs-micro, 11px);font-weight:600;letter-spacing:.06em;text-transform:uppercase;color:var(--ui-text-muted)}.ui-create-card__eyebrow--cold{color:#5661f5}.ui-create-card__eyebrow--warm{color:#a86a0a}.ui-create-card__eyebrow--ready{color:#c2410c}.ui-create-card__title{margin:0;font-size:var(--gemboss-fs-body-lg, 16px);font-weight:600;color:var(--ui-text)}.ui-create-card__line{margin:0;font-size:var(--gemboss-fs-body, 14px);line-height:1.45;color:var(--ui-text-muted)}.ui-create-card__inside{margin:0;font-size:var(--gemboss-fs-caption, 12px);line-height:1.5;color:var(--ui-text)}.ui-create-card__note{margin:0;font-size:var(--gemboss-fs-caption, 12px);line-height:1.5;color:var(--ui-text-muted)}.ui-create-card__act{display:flex;flex-wrap:wrap;gap:8px;margin-top:auto;padding-top:8px}.ui-stage.ui-create-pic{justify-content:center;gap:6px;padding:16px 20%}.ui-create-pic .ui-stage__tile{padding:6px 12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ui-create-pic__more{align-self:center;color:var(--ui-stage-ink-dim)}.ui-create-pic--path{display:flex;align-items:center;justify-content:center;height:100%;box-sizing:border-box;padding:16px;background:radial-gradient(rgba(86,97,245,.13) 1px,transparent 1.5px) 0 0 / 16px 16px,linear-gradient(180deg,var(--gemboss-accent-wash, #f7f8ff),#f2f3fe);border-bottom:1px solid var(--gemboss-accent-tint, #dfe2ff);color:var(--ui-text);font-size:var(--gemboss-fs-caption, 12px)}.ui-create-path{display:flex;align-items:center;justify-content:center;flex-wrap:wrap;gap:6px}.ui-create-path__step{display:flex;align-items:center;gap:6px}.ui-create-path__arrow{color:#8b93ff}.ui-create-path__tile{display:flex;flex-direction:column;align-items:center;gap:4px;max-width:76px;padding:6px;text-align:center;border:1px solid var(--gemboss-accent-tint, #dfe2ff);border-radius:var(--gemboss-radius-md, 8px);background:var(--gemboss-surface, #fff);box-shadow:0 1px 2px #1b1c1e0f;font-size:var(--gemboss-fs-micro, 11px);line-height:1.2}.ui-create-path__tile img{width:40px;height:40px;object-fit:cover;border-radius:var(--gemboss-radius-sm, 6px);background:#f2f3fe}@media (max-width: 47.9975em){.ui-create-step:not(.ui-create-step--on){display:none}.ui-create-step+.ui-create-step:before{display:none}}@media (pointer: coarse){.ui-create-chip{min-height:44px}}
|
package/src/create-shell.tsx
CHANGED
|
@@ -150,17 +150,20 @@ export function CreateFilter<K extends string>({ label, options, value, onChange
|
|
|
150
150
|
);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
/** `wide`: cards whose picture IS the thing chosen (the Section Library's sections): columns of at least 400px, two in a popup. */
|
|
154
|
+
export function CreateGrid({ children, label, wide }: { children?: ReactNode; label?: string; wide?: boolean }) {
|
|
155
|
+
return <div className={cx("ui-create-grid", wide && "ui-create-grid--wide")} role="list" aria-label={label}>{children}</div>;
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
/**
|
|
158
159
|
* One way to start: a picture on the Stage, who it is for (its colour's dot and word, then what it does), its name, one line,
|
|
159
160
|
* what is inside, and the picker's own button. `on`: the one picked (or Gem's pick); `badge` sits on the picture.
|
|
160
161
|
*/
|
|
161
|
-
export function CreateCard({ picture, audience, eyebrow, title, line, inside, note, badge, on, action, dashed, className, data }: {
|
|
162
|
+
export function CreateCard({ picture, pictureShape, audience, eyebrow, title, line, inside, note, badge, on, action, dashed, className, data }: {
|
|
162
163
|
/** `null`: a card with no picture (a way out of the grid, "Not sure which one?"). */
|
|
163
164
|
picture: ReactNode;
|
|
165
|
+
/** `wide`: the picture is a 16:9 shot of the thing itself (a section as a store draws it), not an illustration on the Stage. */
|
|
166
|
+
pictureShape?: "wide";
|
|
164
167
|
audience?: CreateAudience;
|
|
165
168
|
/** What it does, after the temperature: "One product", "Deciding to trust". */
|
|
166
169
|
eyebrow?: string;
|
|
@@ -184,7 +187,7 @@ export function CreateCard({ picture, audience, eyebrow, title, line, inside, no
|
|
|
184
187
|
return (
|
|
185
188
|
<div className={cx("ui-create-card", on && "ui-create-card--on", dashed && "ui-create-card--dashed", className)} role="listitem" {...data}>
|
|
186
189
|
{picture === null ? null : (
|
|
187
|
-
<div className="ui-create-card__pic">
|
|
190
|
+
<div className={cx("ui-create-card__pic", pictureShape === "wide" && "ui-create-card__pic--wide")}>
|
|
188
191
|
{picture}
|
|
189
192
|
{badge ? <span className="ui-create-card__badge">{badge}</span> : null}
|
|
190
193
|
</div>
|
package/src/dialog.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dialog.ui-modal{padding:0;max-width:calc(100% - 40px);max-height:calc(100dvh - 40px);color:var(--ui-text)}dialog.ui-modal[open]{display:flex;flex-direction:column}dialog.ui-modal::backdrop{background:#00000080}dialog.ui-modal>.ui-modal__head,dialog.ui-modal>.ui-modal__foot{flex:none}dialog.ui-modal>.ui-modal__body{flex:1 1 auto;min-height:0;overflow:auto}
|
package/src/dialog.tsx
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* surface that only opens a Dialog should not download it. `Sheet` (sheet.tsx, 0.35.0) is this same Dialog docked
|
|
14
14
|
* to the right edge: it renders `Dialog` and brings sheet.css, so the markup and the behaviour each have one owner.
|
|
15
15
|
*/
|
|
16
|
+
import "./dialog.css"; // its frame travels with it (09/11/2026): a surface that loads ui.css alone (the admin) draws it too
|
|
16
17
|
import React, { useEffect, useId, useRef } from "react";
|
|
17
18
|
import { flushSync } from "react-dom";
|
|
18
19
|
import { Icon } from "./icons";
|
|
@@ -35,6 +36,9 @@ const cx = (...p: Array<string | false | null | undefined>) => p.filter(Boolean)
|
|
|
35
36
|
* - `returnFocusTo`: a selector focused instead when the opener is gone or hidden by then (a menu item, a palette row: both
|
|
36
37
|
* leave the screen as they act, and focusing them does nothing). SettingsDialog's default is `[data-settings-trigger]`.
|
|
37
38
|
* - The page behind holds still while any kit popup is modal: `html:has(dialog.ui-modal:modal)` (kit-plain.css).
|
|
39
|
+
* - `dismissible: false` (08/11/2026, ConfirmDialog while the server answers): Escape, the backdrop and ✕ do not close it. The
|
|
40
|
+
* browser's `cancel` is prevented, and when it closes anyway (Chrome lets a second Escape with no press between go through) it
|
|
41
|
+
* opens again at once; only `open` turning false closes it then.
|
|
38
42
|
*/
|
|
39
43
|
// The control a press last landed on (24/10/2026). Polaris' buttons blur themselves on mouseup (UnstyledButton's
|
|
40
44
|
// handleMouseUpByBlurring), so a popup opened by a click on one found <body> focused and gave the focus back to <body> on Escape:
|
|
@@ -54,8 +58,26 @@ const openerNow = (): Element | null => {
|
|
|
54
58
|
return lastPressed && lastPressed.el.isConnected && Date.now() - lastPressed.at < 2000 ? lastPressed.el : a;
|
|
55
59
|
};
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Tab belongs to the open popup (09/11/2026). The browser walks the focus through it alone (the page under it is inert), but a
|
|
63
|
+
* dialog of the page it was opened from still hears the key on the document: Polaris' Modal and the admin's own Modal trap Tab
|
|
64
|
+
* there, and at their last control they prevented it and focused their first, which the browser refuses (inert). Tab was stuck on
|
|
65
|
+
* the last button of a kit Dialog or Sheet opened from one (measured: a ConfirmDialog in a Polaris Modal). Stopped once everything
|
|
66
|
+
* inside has had it, so a field's own Tab still works, and only when the key comes from this popup's own content: a dialog drawn
|
|
67
|
+
* INSIDE it (an admin Modal in a Sheet, its window listener a Tab trap of its own) keeps its key (review of #7039).
|
|
68
|
+
*/
|
|
69
|
+
export function holdTab(e: React.KeyboardEvent<HTMLElement>): void {
|
|
70
|
+
if (e.key !== "Tab") return;
|
|
71
|
+
const own = (e.target as Element | null)?.closest?.('dialog, [role="dialog"][aria-modal="true"]');
|
|
72
|
+
if (own === e.currentTarget) e.stopPropagation();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function useModalDialog(open: boolean, onClose: () => void, { focusPanel = false, returnFocusTo, dismissible = true }: { focusPanel?: boolean; returnFocusTo?: string; dismissible?: boolean } = {}) {
|
|
58
76
|
const ref = useRef<HTMLDialogElement>(null);
|
|
77
|
+
const dismiss = useRef(dismissible);
|
|
78
|
+
dismiss.current = dismissible;
|
|
79
|
+
const openNow = useRef(open);
|
|
80
|
+
openNow.current = open;
|
|
59
81
|
const opener = useRef<Element | null>(null);
|
|
60
82
|
const shown = useRef(false);
|
|
61
83
|
const pressOnBackdrop = useRef(false);
|
|
@@ -83,26 +105,39 @@ export function useModalDialog(open: boolean, onClose: () => void, { focusPanel
|
|
|
83
105
|
useEffect(() => {
|
|
84
106
|
const d = ref.current;
|
|
85
107
|
if (!d) return undefined;
|
|
108
|
+
// Not dismissible: Escape does nothing (the browser's cancel is prevented)…
|
|
109
|
+
const onCancel = (e: Event) => { if (!dismiss.current) e.preventDefault(); };
|
|
86
110
|
const onNativeClose = () => {
|
|
111
|
+
// …and a close the browser made anyway (a second Escape) is undone while the caller still has it open.
|
|
112
|
+
if (!dismiss.current && openNow.current) { try { d.showModal(); } catch { /* not connected: it is going anyway */ } return; }
|
|
87
113
|
shown.current = false;
|
|
88
114
|
// What closing changes is on the page before the focus goes back: a picker's typed handle, saved as it closes, replaces its
|
|
89
115
|
// "Choose a product" with the chosen row, and the focus went to that button an instant before it left (measured, 24/10/2026).
|
|
90
116
|
flushSync(() => close.current());
|
|
91
117
|
giveFocusBack();
|
|
92
118
|
};
|
|
119
|
+
d.addEventListener("cancel", onCancel);
|
|
93
120
|
d.addEventListener("close", onNativeClose);
|
|
94
121
|
return () => {
|
|
122
|
+
d.removeEventListener("cancel", onCancel);
|
|
95
123
|
d.removeEventListener("close", onNativeClose);
|
|
96
124
|
// Passive cleanups run after React removed the node; StrictMode's rehearsal leaves it in the document.
|
|
97
125
|
if (shown.current && !d.isConnected) { shown.current = false; giveFocusBack(); }
|
|
98
126
|
};
|
|
99
127
|
}, []);
|
|
128
|
+
// Not dismissible and open: Escape pressed anywhere (the focus may have left the popup) makes no close request.
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (!open || dismissible) return undefined;
|
|
131
|
+
const hold = (e: KeyboardEvent) => { if (e.key === "Escape") e.preventDefault(); };
|
|
132
|
+
document.addEventListener("keydown", hold, true);
|
|
133
|
+
return () => document.removeEventListener("keydown", hold, true);
|
|
134
|
+
}, [open, dismissible]);
|
|
100
135
|
const onPointerDown = (e: React.PointerEvent<HTMLDialogElement>) => { pressOnBackdrop.current = e.target === e.currentTarget; };
|
|
101
136
|
const onClick = (e: React.MouseEvent<HTMLDialogElement>) => {
|
|
102
|
-
if (e.target === e.currentTarget && pressOnBackdrop.current) e.currentTarget.close();
|
|
137
|
+
if (e.target === e.currentTarget && pressOnBackdrop.current && dismiss.current) e.currentTarget.close();
|
|
103
138
|
pressOnBackdrop.current = false;
|
|
104
139
|
};
|
|
105
|
-
return { ref, onClick, onPointerDown };
|
|
140
|
+
return { ref, onClick, onPointerDown, onKeyDown: holdTab };
|
|
106
141
|
}
|
|
107
142
|
|
|
108
143
|
export interface DialogProps {
|
|
@@ -126,10 +161,12 @@ export interface DialogProps {
|
|
|
126
161
|
/** A selector focused on close when what opened it is gone by then (useModalDialog's `returnFocusTo`): a picker's first pick
|
|
127
162
|
* replaces its "Choose" with the chosen row's Change. */
|
|
128
163
|
returnFocusTo?: string;
|
|
164
|
+
/** False while it must stay (ConfirmDialog waiting for the server): Escape, the backdrop and ✕ do not close it. Default true. */
|
|
165
|
+
dismissible?: boolean;
|
|
129
166
|
}
|
|
130
167
|
|
|
131
|
-
export function Dialog({ open, onClose, title, subtitle, actions, children, footer, wide = false, closeLabel = "Close", className, focusPanel = false, returnFocusTo, lead }: DialogProps) {
|
|
132
|
-
const { ref, onClick, onPointerDown } = useModalDialog(open, onClose, { focusPanel, returnFocusTo });
|
|
168
|
+
export function Dialog({ open, onClose, title, subtitle, actions, children, footer, wide = false, closeLabel = "Close", className, focusPanel = false, returnFocusTo, lead, dismissible = true }: DialogProps) {
|
|
169
|
+
const { ref, onClick, onPointerDown, onKeyDown } = useModalDialog(open, onClose, { focusPanel, returnFocusTo, dismissible });
|
|
133
170
|
const titleId = useId();
|
|
134
171
|
const subId = useId();
|
|
135
172
|
return (
|
|
@@ -138,14 +175,16 @@ export function Dialog({ open, onClose, title, subtitle, actions, children, foot
|
|
|
138
175
|
// Its Escape closes it and only it, as the kit's Popover: the browser closes the <dialog>, and neither the keydown nor the keyup
|
|
139
176
|
// goes further out, where a Polaris Modal it was opened from closed as well (on the keyup; escape.ts). A box that clears its
|
|
140
177
|
// words on Escape (PickerList's) consumes the key before it gets here.
|
|
141
|
-
|
|
178
|
+
// Not dismissible: the key's default is prevented too, so the browser makes no close request at all (a prevented `cancel`
|
|
179
|
+
// only holds once: Chrome lets a second Escape with no press between close it).
|
|
180
|
+
onKeyDown={(e) => { onKeyDown(e); if (e.key === "Escape" && !e.nativeEvent.isComposing) { consumeEscape(e); if (!dismissible) e.preventDefault(); } }}>
|
|
142
181
|
<div className="ui-modal__head">
|
|
143
182
|
{lead}
|
|
144
183
|
{subtitle
|
|
145
184
|
? <div className="ui-modal__title"><span id={titleId}>{title}</span><span className="ui-modal__subtitle" id={subId}>{subtitle}</span></div>
|
|
146
185
|
: <div className="ui-modal__title" id={titleId}>{title}</div>}
|
|
147
186
|
{actions ? <div className="ui-modal__actions">{actions}</div> : null}
|
|
148
|
-
<button type="button" className="ui-modal__close" aria-label={closeLabel} onClick={() => ref.current?.close()}>
|
|
187
|
+
<button type="button" className="ui-modal__close" aria-label={closeLabel} disabled={!dismissible} onClick={() => ref.current?.close()}>
|
|
149
188
|
<Icon name="close" size={20} />
|
|
150
189
|
</button>
|
|
151
190
|
</div>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// CHOICE CARDS (09/11/2026, one control set: Chris 08/11 "các control phải có bộ control và kiểu có sự tái sử dụng dùng chung shared
|
|
3
|
+
// component… đừng mỗi cho mỗi kiểu"). One choice of a few where each needs its words and a picture to be told apart BEFORE it is picked:
|
|
4
|
+
// Global styles' form set (a sample field drawn from each set's values, what it suits) and its style pack (four swatches, its fonts and
|
|
5
|
+
// buttons). A list or chips would show the names only; choice tiles (tiles.tsx) a picture and a name. The admin drew both by hand, each
|
|
6
|
+
// with its own radio card.
|
|
7
|
+
//
|
|
8
|
+
// · `.gemboss-ei-choices[role=radiogroup]` › one `label.gemboss-ei-choice` per option (the whole card is the radio's label, so it is
|
|
9
|
+
// one target, at least 44px tall at every width) › `input[type=radio].gemboss-ei-choice-input` · the words (`-name`, `-line`s) ·
|
|
10
|
+
// the picture (`-pic`), before the words or after them (`pictureAt`);
|
|
11
|
+
// · real radios in one group (`name`): Tab enters at the one picked, the arrow keys move the pick and Space picks, as the browser's own
|
|
12
|
+
// radios do; a pick calls `onChange` (a host that applies on a button of its own keeps the pick until then);
|
|
13
|
+
// · the caller owns the value: a value no card has (a set of the theme's own) checks none.
|
|
14
|
+
// Its look is editor.css's (the harnesses that draw a settings panel already load it).
|
|
15
|
+
import "../editor.css";
|
|
16
|
+
import { forwardRef, type CSSProperties, type ReactNode } from "react";
|
|
17
|
+
|
|
18
|
+
export interface ChoiceCard {
|
|
19
|
+
value: string;
|
|
20
|
+
/** Its name: the card's first line, in bold. */
|
|
21
|
+
label: ReactNode;
|
|
22
|
+
/** Lines under the name, muted (what it suits, its fonts and buttons). */
|
|
23
|
+
lines?: readonly ReactNode[];
|
|
24
|
+
/** Its picture (a sample, swatches): drawn at the group's `pictureAt`. Decorative: the words name the choice. */
|
|
25
|
+
picture?: ReactNode;
|
|
26
|
+
/** Shown but not choosable (Erase my data for a member who is not the store's Owner): its radio off, the card faded. Its `lines` say
|
|
27
|
+
* why. */
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ChoiceCardsProps {
|
|
32
|
+
/** The radios' name, one group on the page. */
|
|
33
|
+
name: string;
|
|
34
|
+
/** The group's accessible name (the setting's). */
|
|
35
|
+
label: string;
|
|
36
|
+
options: readonly ChoiceCard[];
|
|
37
|
+
/** The card that is checked; null or a value no card has: none. */
|
|
38
|
+
value: string | null;
|
|
39
|
+
onChange: (value: string) => void;
|
|
40
|
+
disabled?: boolean;
|
|
41
|
+
/** Where each card's picture goes: before its words (`start`, default) or after them (`end`). */
|
|
42
|
+
pictureAt?: "start" | "end";
|
|
43
|
+
/** The group's id (a button that shows it points at it: `aria-controls`). */
|
|
44
|
+
id?: string;
|
|
45
|
+
/** On the group: a host's layout (a long list held to a height that scrolls). Never a look. */
|
|
46
|
+
style?: CSSProperties;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const ChoiceCards = forwardRef<HTMLDivElement, ChoiceCardsProps>(function ChoiceCards({ name, label, options, value, onChange, disabled, pictureAt = "start", id, style }, ref) {
|
|
50
|
+
return (
|
|
51
|
+
<div ref={ref} id={id} className="gemboss-ei-choices" role="radiogroup" aria-label={label} style={style}>
|
|
52
|
+
{options.map((o) => {
|
|
53
|
+
const checked = value === o.value;
|
|
54
|
+
const off = disabled || o.disabled;
|
|
55
|
+
const pic = o.picture != null ? <span className="gemboss-ei-choice-pic" aria-hidden="true">{o.picture}</span> : null;
|
|
56
|
+
return (
|
|
57
|
+
<label key={o.value} className="gemboss-ei-choice" data-checked={checked ? "" : undefined} data-disabled={off ? "" : undefined}>
|
|
58
|
+
<input type="radio" className="gemboss-ei-choice-input" name={name} value={o.value} checked={checked} disabled={off}
|
|
59
|
+
onChange={() => onChange(o.value)} />
|
|
60
|
+
{pictureAt === "start" ? pic : null}
|
|
61
|
+
<span className="gemboss-ei-choice-words">
|
|
62
|
+
<span className="gemboss-ei-choice-name">{o.label}</span>
|
|
63
|
+
{(o.lines ?? []).map((line, i) => <span key={i} className="gemboss-ei-choice-line">{line}</span>)}
|
|
64
|
+
</span>
|
|
65
|
+
{pictureAt === "end" ? pic : null}
|
|
66
|
+
</label>
|
|
67
|
+
);
|
|
68
|
+
})}
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
});
|