@gemboss/ui 0.58.0 → 0.60.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.
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Kind art (unreleased, 04/11/2026). The picture across the top of a "pick a kind" card: a cream strip with one bold drawing of the
3
+ * kind, so a person tells the kinds apart before reading a word. Drawn from the UI book's New offer (OF-2, `of-art` / `of-k*`), at
4
+ * its size: Chris on prod 04/11/2026, "mấy cái icon design từ artifact đẹp hơn mà cái này bé tí hin chả nhìn ra gì" (the board's
5
+ * drawings are nicer; ours, the real widget shrunk into a 76 × 56 tile with 4px words, are too tiny to make out). Before this, each
6
+ * picker drew its own miniature; a popup, plugin or funnel picker that wants the same card adds its kinds here, in the same grammar.
7
+ *
8
+ * One grammar, painted by tokens (so `data-theme="dark"` follows): white boxes with a hairline, grey lines where words would be,
9
+ * ink for what the shopper presses or has picked (a button, the chosen row, a tick), iris for a saving, a bar that fills toward
10
+ * round stops, products as small tiles (a jar, a moon, a gummy), "+" and "→" in muted ink. Nothing in a drawing is text. Each is
11
+ * drawn at the board's size in px and only scales down, with the strip, never up.
12
+ *
13
+ * signup a window with a field and a black button (a signup discount, any page)
14
+ * quantity-break three rows, the picked one outlined, a saving on two (product page)
15
+ * bundle three products joined by "+"
16
+ * upgrade a small box, an arrow, a bigger box outlined
17
+ * cross-sell a row of products to add
18
+ * cart-add-on a cart line, and a dashed line under it with an ink "add" (cart drawer)
19
+ * gift a bar filling toward one stop
20
+ * reward-tiers a bar with three stops, the first reached
21
+ * bought-together products with a tick before each
22
+ * post-purchase a window holding a product and a black button (after payment)
23
+ * order-bump a ticked row above a black pay bar (checkout)
24
+ *
25
+ * Decorative by default (`aria-hidden`): the card's name says what it is. Pass `title` where the picture is the only thing that
26
+ * says it, and it becomes an image with that name. Server-renderable (no state, no effect, no inline style).
27
+ */
28
+ import "./kind-art.css";
29
+ import React, { type ReactNode } from "react";
30
+
31
+ const cx = (...p: Array<string | false | null | undefined>) => p.filter(Boolean).join(" ");
32
+
33
+ export type KindGlyph =
34
+ | "signup" | "quantity-break" | "bundle" | "upgrade" | "cross-sell" | "cart-add-on" | "gift" | "reward-tiers" | "bought-together"
35
+ | "post-purchase" | "order-bump";
36
+ export const KIND_GLYPHS: readonly KindGlyph[] = [
37
+ "signup", "quantity-break", "bundle", "upgrade", "cross-sell", "cart-add-on", "gift", "reward-tiers", "bought-together",
38
+ "post-purchase", "order-bump",
39
+ ];
40
+
41
+ // The board's parts, in px. A box's edge is drawn inside its size, as a CSS border-box draws it (a 1px stroke on the half pixel).
42
+ /** A white box with a hairline; `on` is the picked one, a 1.5px ink edge; `dash` one not there yet. Whole class names, never a
43
+ * built one: the admin's orphan-class gate reads every class a component can write (a-tap-target-rule-outlived-its-markup). */
44
+ const LOOK = { paper: "ui-kind-art__paper", on: "ui-kind-art__on", dash: "ui-kind-art__dash" } as const;
45
+ const box = (x: number, y: number, w: number, h: number, r: number, look: keyof typeof LOOK = "paper") => {
46
+ const e = look === "on" ? 0.75 : 0.5;
47
+ return <rect className={LOOK[look]} x={x + e} y={y + e} width={w - 2 * e} height={h - 2 * e} rx={r - e} />;
48
+ };
49
+ /** A line of words, 3px: grey, or ink when it is the one that matters. */
50
+ const line = (x: number, y: number, w: number, ink = false) => <rect className={ink ? "ui-kind-art__ink" : "ui-kind-art__line"} x={x} y={y} width={w} height={3} rx={1.5} />;
51
+ /** A saving, 14 × 6: iris, or ink when it is an action ("add"). */
52
+ const tag = (x: number, y: number, ink = false) => <rect className={ink ? "ui-kind-art__ink" : "ui-kind-art__tag"} x={x} y={y} width={14} height={6} rx={3} />;
53
+ const button = (x: number, y: number, w: number) => <rect className="ui-kind-art__ink" x={x} y={y} width={w} height={10} rx={5} />;
54
+ const tick = (x: number, y: number) => <rect className="ui-kind-art__ink" x={x} y={y} width={8} height={8} rx={2} />;
55
+ const plus = (x: number, cy: number) => <path className="ui-kind-art__mark" d={`M${x} ${cy}h7M${x + 3.5} ${cy - 3.5}v7`} />;
56
+ const arrow = (x: number, cy: number) => <path className="ui-kind-art__mark" d={`M${x} ${cy}h10M${x + 6.5} ${cy - 3.5}l3.5 3.5-3.5 3.5`} />;
57
+
58
+ type Goods = "jar" | "moon" | "gummy";
59
+ /** A product in a 12 × 16 box at (x, y): a jar with its ink lid, a moon, a gummy. */
60
+ const goods = (kind: Goods, x: number, y: number) => {
61
+ if (kind === "jar") return <><rect className="ui-kind-art__ink" x={x + 2.5} y={y + 1} width={7} height={3} rx={1} /><rect className="ui-kind-art__goods" x={x + 1.5} y={y + 4.5} width={9} height={11} rx={2.5} /></>;
62
+ if (kind === "moon") return <path className="ui-kind-art__goods" transform={`translate(${x} ${y + 2}) scale(.5)`} d="M15.5 3.2a9 9 0 1 0 5.6 13.9A7.3 7.3 0 0 1 15.5 3.2z" />;
63
+ return (
64
+ <g transform={`translate(${x} ${y + 2}) scale(.6)`}>
65
+ <path className="ui-kind-art__goods" d="M4 9c0-4 2.5-6 6-6s6 2 6 6-1 8-6 8-6-4-6-8z" />
66
+ <path className="ui-kind-art__shine" d="M7 7c1-1.5 3-2 4-1.5" />
67
+ </g>
68
+ );
69
+ };
70
+ /** A product tile, 24 × 28, its product in the middle (none: an empty slot). */
71
+ const tile = (x: number, y: number, kind?: Goods) => <>{box(x, y, 24, 28, 6)}{kind ? goods(kind, x + 6, y + 6) : null}</>;
72
+ /** The cart's progress bar, 6px, filled `fill` px, with round stops (12px) at `stops` px; the first `reached` are ink. */
73
+ const progress = (y: number, fill: number, stops: readonly number[], reached: number) => (
74
+ <>
75
+ <rect className="ui-kind-art__track" x={0} y={y} width={128} height={6} rx={3} />
76
+ <rect className="ui-kind-art__ink" x={0} y={y} width={fill} height={6} rx={3} />
77
+ {stops.map((s, i) => <circle key={s} className={cx("ui-kind-art__stop", i >= reached && "ui-kind-art__stop--off")} cx={s} cy={y + 3} r={5.25} />)}
78
+ </>
79
+ );
80
+ /** A row of a list, 128 × 12. */
81
+ const row = (y: number, look: keyof typeof LOOK = "paper") => box(0, y, 128, 12, 4, look);
82
+
83
+ const GLYPH: Record<KindGlyph, { w: number; h: number; body: ReactNode }> = {
84
+ signup: { w: 84, h: 43, body: <>{box(0, 0, 84, 43, 6)}{line(6, 6, 16, true)}{box(6, 12, 72, 12, 4)}{line(11, 16.5, 16)}{button(6, 27, 72)}</> },
85
+ "quantity-break": {
86
+ w: 128, h: 42,
87
+ body: (
88
+ <>
89
+ {row(0)}{line(5, 4.5, 16)}{line(107, 4.5, 16)}
90
+ {row(15)}{line(5, 19.5, 30)}{tag(109, 18)}
91
+ {row(30, "on")}{line(5, 34.5, 30, true)}{tag(109, 33)}
92
+ </>
93
+ ),
94
+ },
95
+ bundle: { w: 106, h: 28, body: <>{tile(0, 0, "jar")}{plus(29, 14)}{tile(41, 0, "moon")}{plus(70, 14)}{tile(82, 0, "gummy")}</> },
96
+ // The board drew two boxes of one size; the second is a size up here, so the drawing says "the bigger size" without its words.
97
+ upgrade: {
98
+ w: 116, h: 25,
99
+ body: <>{box(0, 2, 44, 21, 6)}{line(6, 8, 16)}{line(6, 14, 30)}{arrow(49, 12.5)}{box(64, 0, 52, 25, 6, "on")}{line(71, 8, 20, true)}{line(71, 14, 36)}</>,
100
+ },
101
+ "cross-sell": { w: 111, h: 28, body: <>{tile(0, 0, "moon")}{tile(29, 0, "gummy")}{tile(58, 0, "jar")}{tile(87, 0)}</> },
102
+ "cart-add-on": {
103
+ w: 128, h: 27,
104
+ body: <>{row(0)}{line(5, 4.5, 56, true)}{line(107, 4.5, 16)}{row(15, "dash")}{line(5, 19.5, 30)}{tag(109, 18, true)}</>,
105
+ },
106
+ // The last stop's circle stands half past the bar's end, as on the board: the box is 6px wider than the bar.
107
+ gift: { w: 134, h: 20, body: <>{line(0, 0, 56)}{progress(11, 89.6, [128], 0)}</> },
108
+ "reward-tiers": { w: 134, h: 20, body: <>{line(0, 0, 56)}{progress(11, 57.6, [38.4, 83.2, 128], 1)}</> },
109
+ "bought-together": { w: 79, h: 28, body: <>{tick(0, 10)}{tile(13, 0, "jar")}{tick(42, 10)}{tile(55, 0, "moon")}</> },
110
+ "post-purchase": { w: 96, h: 42, body: <>{box(0, 0, 96, 42, 6)}{tile(7, 7, "jar")}{line(37, 12.5, 30)}{button(37, 19.5, 52)}</> },
111
+ "order-bump": { w: 128, h: 40, body: <>{row(0)}{line(5, 4.5, 56)}{row(15, "on")}{tick(5, 17)}{line(17, 19.5, 30)}{button(0, 30, 128)}</> },
112
+ };
113
+
114
+ export interface KindArtProps {
115
+ glyph: KindGlyph;
116
+ /** Makes the strip an image with this name, for the rare place where it is the only thing that says it. */
117
+ title?: string;
118
+ className?: string;
119
+ }
120
+
121
+ /** The strip, 50px tall and as wide as its card, its drawing in the middle. A glyph that got past the type (plain JS) draws the
122
+ * strip alone, so the cards of a grid still line up. */
123
+ export function KindArt({ glyph, title, className }: KindArtProps) {
124
+ const g = GLYPH[glyph];
125
+ return (
126
+ <span className={cx("ui-kind-art", className)} data-glyph={glyph} {...(title ? { role: "img", "aria-label": title } : { "aria-hidden": true })}>
127
+ {g ? (
128
+ <svg className="ui-kind-art__glyph" viewBox={`0 0 ${g.w} ${g.h}`} width={g.w} height={g.h} fill="none">{g.body}</svg>
129
+ ) : null}
130
+ </span>
131
+ );
132
+ }
package/src/list-page.css CHANGED
@@ -1 +1 @@
1
- .ui-list-page{box-sizing:border-box;max-width:var(--ui-content-max, 900px);margin-inline:auto;padding-inline:24px;display:flex;flex-direction:column;gap:16px;padding-bottom:24px;container:ui-list-page / inline-size;--ui-list-page-text: var(--p-color-text, var(--ui-text-strong));--ui-list-page-muted: var(--p-color-text-secondary, var(--ui-text-muted));--ui-list-page-fill: var(--p-color-bg-fill-tertiary, #e3e3e3);--ui-list-page-fill-hover: var(--p-color-bg-fill-tertiary-hover, #d4d4d4);--ui-list-page-fill-active: var(--p-color-bg-fill-tertiary-active, #cccccc)}@media (max-width: 30.6225em){.ui-list-page{padding-inline:0}}.ui-list-page__head{display:grid;grid-template-columns:minmax(0,1fr) auto;grid-template-areas:"title actions" "sub .";align-items:start;column-gap:16px;padding-top:24px;margin-bottom:8px}.ui-list-page__head--back{grid-template-columns:auto minmax(0,1fr) auto;grid-template-areas:"back title actions" ". sub ."}.ui-list-page__head--back>:is(.ui-list-page__title-row,.ui-list-page__subtitle){margin-left:-12px}.ui-list-page__back{grid-area:back;color:var(--ui-list-page-text);border-color:transparent}.ui-list-page__back:hover{background:var(--ui-list-page-fill-hover)}.ui-list-page__back svg{width:20px;height:20px}.ui-list-page__title-row{grid-area:title;display:flex;flex-wrap:wrap;align-items:center;gap:8px;min-width:0;min-height:28px}.ui-list-page__title{margin:0;color:var(--ui-list-page-text);font-size:20px;line-height:24px;font-weight:700;letter-spacing:-.01em;overflow-wrap:anywhere}.ui-list-page__subtitle{grid-area:sub;min-width:0;margin:2px 0 0;color:var(--ui-list-page-muted);font-size:12px;line-height:16px;overflow-wrap:anywhere}.ui-list-page__actions{grid-area:actions;display:flex;align-items:center;justify-content:flex-end;gap:8px;white-space:nowrap}.ui-list-page__action{background:var(--ui-list-page-fill);border-color:transparent;color:var(--ui-list-page-text)}.ui-list-page__action:not([aria-disabled=true]):hover{background:var(--ui-list-page-fill-hover)}.ui-list-page__action:not([aria-disabled=true]):active{background:var(--ui-list-page-fill-active)}.ui-list-page__action--danger{color:var(--gemboss-danger-strong, #8e0b21)}.ui-list-page__more>summary{background:var(--ui-list-page-fill);border-color:transparent;color:var(--ui-list-page-text)}.ui-list-page__more>summary:hover{background:var(--ui-list-page-fill-hover)}.ui-list-page__narrow{display:none}.ui-list-page__notices:empty,.ui-list-page__toolbar:empty,.ui-list-page__notices:has(>:only-child:empty),.ui-list-page__toolbar:has(>:only-child:empty){display:none}@container ui-list-page (max-width: 559.98px){.ui-list-page__wide{display:none}.ui-list-page__narrow{display:inline-flex}}@media (max-width: 47.9975em){.ui-list-page__head{padding-top:16px;margin-bottom:0;grid-template-areas:"title actions" "sub sub"}.ui-list-page__head--back{grid-template-columns:auto minmax(0,1fr) auto;grid-template-areas:"back . actions" "title title title" "sub sub sub"}.ui-list-page__head--back>:is(.ui-list-page__title-row,.ui-list-page__subtitle){margin-left:0}.ui-list-page__head--back>.ui-list-page__title-row{margin-top:12px}.ui-list-page__head:not(.ui-list-page__head--back):has(>.ui-list-page__actions)>.ui-list-page__title-row{min-height:44px}.ui-list-page__wide{display:none}.ui-list-page__narrow{display:inline-flex}}.ui-list-page__card{padding:0;overflow:hidden}@media (max-width: 30.6225em){.ui-list-page__card{border-radius:0}}.ui-list-page__card-head{display:flex;flex-wrap:wrap;align-items:center;gap:4px 8px;padding:16px;border-bottom:1px solid var(--ui-border)}.ui-list-page__card-title{margin:0;color:var(--ui-list-page-text);font-size:14px;line-height:20px;font-weight:650}.ui-list-page__skeleton{display:grid;gap:8px;padding:16px}.ui-list-page__skeleton+.ui-list-page__skeleton{border-top:1px solid var(--ui-border)}.ui-list-page__skeleton .ui-skeleton__line:last-child{width:60%}.ui-list-page__error{padding:16px}.ui-list-page__error .ui-notice{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px 16px}.ui-list-page__no-match{padding:32px 16px}.ui-list-page__section-title{margin-bottom:-8px}
1
+ .ui-list-page{box-sizing:border-box;max-width:var(--ui-content-max, 900px);margin-inline:auto;padding-inline:24px;display:flex;flex-direction:column;gap:16px;padding-bottom:24px;container:ui-list-page / inline-size;--ui-list-page-text: var(--p-color-text, var(--ui-text-strong));--ui-list-page-muted: var(--p-color-text-secondary, var(--ui-text-muted));--ui-list-page-fill: var(--p-color-bg-fill-tertiary, var(--gemboss-fill-tertiary, #e3e3e3));--ui-list-page-fill-hover: var(--p-color-bg-fill-tertiary-hover, var(--gemboss-fill-tertiary-hover, #d4d4d4));--ui-list-page-fill-active: var(--p-color-bg-fill-tertiary-active, var(--gemboss-fill-tertiary-active, #cccccc))}@media (max-width: 30.6225em){.ui-list-page{padding-inline:0}}.ui-list-page__head{display:grid;grid-template-columns:minmax(0,1fr) auto;grid-template-areas:"title actions" "sub .";align-items:start;column-gap:16px;padding-top:24px;margin-bottom:8px}.ui-list-page__head--back{grid-template-columns:auto minmax(0,1fr) auto;grid-template-areas:"back title actions" ". sub ."}.ui-list-page__head--back>:is(.ui-list-page__title-row,.ui-list-page__subtitle){margin-left:-12px}.ui-list-page__back{grid-area:back;color:var(--ui-list-page-text);border-color:transparent}.ui-list-page__back:hover{background:var(--ui-list-page-fill-hover)}.ui-list-page__back svg{width:20px;height:20px}.ui-list-page__title-row{grid-area:title;display:flex;flex-wrap:wrap;align-items:center;gap:8px;min-width:0;min-height:28px}.ui-list-page__title{margin:0;color:var(--ui-list-page-text);font-size:20px;line-height:24px;font-weight:700;letter-spacing:-.01em;overflow-wrap:anywhere}.ui-list-page__subtitle{grid-area:sub;min-width:0;margin:2px 0 0;color:var(--ui-list-page-muted);font-size:12px;line-height:16px;overflow-wrap:anywhere}.ui-list-page__actions{grid-area:actions;display:flex;align-items:center;justify-content:flex-end;gap:8px;white-space:nowrap}.ui-list-page__action{background:var(--ui-list-page-fill);border-color:transparent;color:var(--ui-list-page-text)}.ui-list-page__action:not([aria-disabled=true]):hover{background:var(--ui-list-page-fill-hover)}.ui-list-page__action:not([aria-disabled=true]):active{background:var(--ui-list-page-fill-active)}.ui-list-page__action--danger{color:var(--gemboss-danger-strong, #8e0b21)}.ui-list-page__more>summary{background:var(--ui-list-page-fill);border-color:transparent;color:var(--ui-list-page-text)}.ui-list-page__more>summary:hover{background:var(--ui-list-page-fill-hover)}.ui-list-page__narrow{display:none}.ui-list-page__notices:empty,.ui-list-page__toolbar:empty,.ui-list-page__notices:has(>:only-child:empty),.ui-list-page__toolbar:has(>:only-child:empty){display:none}@container ui-list-page (max-width: 559.98px){.ui-list-page__wide{display:none}.ui-list-page__narrow{display:inline-flex}}@media (max-width: 47.9975em){.ui-list-page__head{padding-top:16px;margin-bottom:0;grid-template-areas:"title actions" "sub sub"}.ui-list-page__head--back{grid-template-columns:auto minmax(0,1fr) auto;grid-template-areas:"back . actions" "title title title" "sub sub sub"}.ui-list-page__head--back>:is(.ui-list-page__title-row,.ui-list-page__subtitle){margin-left:0}.ui-list-page__head--back>.ui-list-page__title-row{margin-top:12px}.ui-list-page__head:not(.ui-list-page__head--back):has(>.ui-list-page__actions)>.ui-list-page__title-row{min-height:44px}.ui-list-page__wide{display:none}.ui-list-page__narrow{display:inline-flex}}.ui-list-page__card{padding:0;overflow:hidden}@media (max-width: 30.6225em){.ui-list-page__card{border-radius:0}}.ui-list-page__card-head{display:flex;flex-wrap:wrap;align-items:center;gap:4px 8px;padding:16px;border-bottom:1px solid var(--ui-border)}.ui-list-page__card-title{margin:0;color:var(--ui-list-page-text);font-size:14px;line-height:20px;font-weight:650}.ui-list-page__skeleton{display:grid;gap:8px;padding:16px}.ui-list-page__skeleton+.ui-list-page__skeleton{border-top:1px solid var(--ui-border)}.ui-list-page__skeleton .ui-skeleton__line:last-child{width:60%}.ui-list-page__error{padding:16px}.ui-list-page__error .ui-notice{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px 16px}.ui-list-page__no-match{padding:32px 16px}.ui-list-page__section-title{margin-bottom:-8px}
@@ -0,0 +1,278 @@
1
+ /**
2
+ * The Members pattern's data side (@gemboss/ui, unreleased, 04/11/2026): no React, no stylesheet, so a server can check an import
3
+ * with the same rules the page shows, and a plain-HTML surface (GemCare) can count and filter its rows the same way.
4
+ *
5
+ * What a person is to the pattern (MemberPerson), the roles and scopes an app declares, the fixed filter group (All · Team ·
6
+ * Pending) and its counts, the search (accents folded: "le" finds "Lê"), the step machine of a role change on a row (choose →
7
+ * confirm or cancel → saving → done), the last-holder guard (the last admin of a scope keeps the role), and the CSV an Invite ›
8
+ * Many paste is read with. members.tsx draws it; README "Members" has the whole pattern.
9
+ */
10
+
11
+ export type MemberStatus = "active" | "pending" | "invited" | "locked";
12
+ export const MEMBER_STATUSES: readonly MemberStatus[] = ["active", "pending", "invited", "locked"];
13
+
14
+ /** A role an app declares. `staff`: holding it in any scope puts the person in the fixed "Team" chip (GemCommunity's admin and
15
+ * mod; none in GemCare, where everyone is staff, and the chip is not drawn). */
16
+ export interface MemberRole { id: string; label: string; staff?: boolean }
17
+
18
+ /** Where a role is held: GemCare has two workspaces (GemBoss care, GemPages care), GemCommunity one group. `roles` when this
19
+ * scope offers other roles than the page's; `allowNone`: "—" (no role here) can be chosen, not only shown. */
20
+ export interface MemberScope { id: string; label: string; roles?: readonly (MemberRole | string)[]; allowNone?: boolean }
21
+
22
+ export interface MemberPerson {
23
+ id: string;
24
+ name: string;
25
+ email: string;
26
+ avatar?: string | null;
27
+ status: MemberStatus;
28
+ /** The role in each scope, by scope id; null or missing: no role there ("—"). */
29
+ roles?: Readonly<Record<string, string | null | undefined>>;
30
+ /** Shorthand for a page with one scope: the role in the first scope. */
31
+ role?: string | null;
32
+ /** Already worded by the host, in its language ("2 hours ago", "hôm qua"). */
33
+ lastActive?: string;
34
+ /** What the drawer's Sign-in block shows. `twoFactor` null or missing: not said. */
35
+ signIn?: { method?: string; twoFactor?: boolean | null; last?: string };
36
+ }
37
+
38
+ /** The scope a page has when it declares none: one, unnamed. */
39
+ export const DEFAULT_SCOPE: MemberScope = { id: "default", label: "" };
40
+
41
+ const capital = (s: string) => (s ? s[0]!.toUpperCase() + s.slice(1) : s);
42
+
43
+ /** "admin" is { id: "admin", label: "Admin" }; a declared role is itself. */
44
+ export function normalizeRoles(roles: readonly (MemberRole | string)[] = []): MemberRole[] {
45
+ return roles.map((r) => (typeof r === "string" ? { id: r, label: capital(r) } : r));
46
+ }
47
+
48
+ export function scopesOf(scopes?: readonly MemberScope[]): MemberScope[] {
49
+ return scopes && scopes.length ? [...scopes] : [DEFAULT_SCOPE];
50
+ }
51
+
52
+ /** The roles a scope offers: its own, else the page's. */
53
+ export function rolesIn(scope: MemberScope, roles: readonly (MemberRole | string)[]): MemberRole[] {
54
+ return normalizeRoles(scope.roles ?? roles);
55
+ }
56
+
57
+ /** The person's role in a scope (the `role` shorthand counts for the first scope), or null. */
58
+ export function roleOf(person: MemberPerson, scopeId: string, scopes: readonly MemberScope[]): string | null {
59
+ const own = person.roles?.[scopeId];
60
+ if (own != null && own !== "") return own;
61
+ if (scopes[0]?.id === scopeId && person.role != null && person.role !== "") return person.role;
62
+ return null;
63
+ }
64
+
65
+ export function roleLabel(roleId: string | null, scope: MemberScope, roles: readonly (MemberRole | string)[]): string | null {
66
+ if (roleId == null) return null;
67
+ return rolesIn(scope, roles).find((r) => r.id === roleId)?.label ?? capital(roleId);
68
+ }
69
+
70
+ /** Holds a staff role (a role declared `staff`) in any scope. */
71
+ export function isTeam(person: MemberPerson, roles: readonly (MemberRole | string)[], scopes: readonly MemberScope[]): boolean {
72
+ return scopes.some((s) => {
73
+ const r = roleOf(person, s.id, scopes);
74
+ return r != null && rolesIn(s, roles).some((x) => x.id === r && x.staff);
75
+ });
76
+ }
77
+
78
+ /** Not in yet: waiting for approval, or invited and not signed in. */
79
+ export const isPending = (p: MemberPerson) => p.status === "pending" || p.status === "invited";
80
+
81
+ /** An app's own chip: its words and which people it holds. `count` when the host counts on the server (a page of rows). */
82
+ export interface MemberFilter { id: string; label: string; test: (person: MemberPerson) => boolean; count?: number }
83
+
84
+ /** The fixed group's ids. An app's chip ids must not be these. */
85
+ export const FIXED_FILTERS = ["all", "team", "pending"] as const;
86
+
87
+ /** Accents and case folded, so "le" finds "Lê" and "dang" finds "Đặng". */
88
+ export function foldText(s: string): string {
89
+ return s.normalize("NFD").replace(/\p{M}/gu, "").replace(/[đĐ]/g, "d").toLowerCase();
90
+ }
91
+
92
+ export function matchesQuery(person: MemberPerson, query: string): boolean {
93
+ const q = foldText(query.trim());
94
+ if (!q) return true;
95
+ return foldText(`${person.name} ${person.email}`).includes(q);
96
+ }
97
+
98
+ export interface MembersContext { roles: readonly (MemberRole | string)[]; scopes: readonly MemberScope[]; filters?: readonly MemberFilter[] }
99
+
100
+ export function matchesFilter(person: MemberPerson, filter: string, ctx: MembersContext): boolean {
101
+ if (filter === "all" || !filter) return true;
102
+ if (filter === "team") return isTeam(person, ctx.roles, ctx.scopes);
103
+ if (filter === "pending") return isPending(person);
104
+ const own = ctx.filters?.find((f) => f.id === filter);
105
+ return own ? own.test(person) : true;
106
+ }
107
+
108
+ /** How many each chip holds, over everyone (a chip's count does not move with the search). */
109
+ export function memberCounts(people: readonly MemberPerson[], ctx: MembersContext): Record<string, number> {
110
+ const out: Record<string, number> = { all: people.length, team: 0, pending: 0 };
111
+ for (const f of ctx.filters ?? []) out[f.id] = f.count ?? 0;
112
+ for (const p of people) {
113
+ if (isTeam(p, ctx.roles, ctx.scopes)) out.team! += 1;
114
+ if (isPending(p)) out.pending! += 1;
115
+ for (const f of ctx.filters ?? []) if (f.count == null && f.test(p)) out[f.id]! += 1;
116
+ }
117
+ return out;
118
+ }
119
+
120
+ export function visibleMembers(people: readonly MemberPerson[], filter: string, query: string, ctx: MembersContext): MemberPerson[] {
121
+ return people.filter((p) => matchesFilter(p, filter, ctx) && matchesQuery(p, query));
122
+ }
123
+
124
+ /** Whether the page has a Team chip at all: some role is a staff role. */
125
+ export function hasTeamRoles(roles: readonly (MemberRole | string)[], scopes: readonly MemberScope[]): boolean {
126
+ return scopes.some((s) => rolesIn(s, roles).some((r) => r.staff));
127
+ }
128
+
129
+ /**
130
+ * `canChangeRole` for the common rule: the LAST person holding `roleId` in a scope cannot have it changed there (the last admin
131
+ * of a workspace stays its admin). Returns `reason` for that person in that scope, true otherwise.
132
+ */
133
+ export function lastRoleGuard(people: readonly MemberPerson[], roleId: string, scopes: readonly MemberScope[] = [DEFAULT_SCOPE],
134
+ reason = "The last one with this role keeps it."): (person: MemberPerson, scopeId: string) => true | string {
135
+ const sc = scopesOf(scopes);
136
+ return (person, scopeId) => {
137
+ if (roleOf(person, scopeId, sc) !== roleId) return true;
138
+ const holders = people.filter((p) => p.status !== "locked" && roleOf(p, scopeId, sc) === roleId);
139
+ return holders.length <= 1 ? reason : true;
140
+ };
141
+ }
142
+
143
+ // ── A role change on a row: choose a new role, then Change or Cancel on the row; never window.confirm. ─────────────────────────────
144
+
145
+ /** `where`: the row's select or the drawer's (the inline confirm is drawn beside the one that was used). */
146
+ export interface RoleChange { personId: string; scopeId: string; from: string | null; to: string; where: "row" | "drawer"; saving: boolean }
147
+ export type RoleChangeEvent =
148
+ | { type: "choose"; personId: string; scopeId: string; from: string | null; to: string; where: "row" | "drawer" }
149
+ | { type: "cancel" }
150
+ | { type: "save" }
151
+ | { type: "done" }
152
+ | { type: "failed" };
153
+
154
+ /** The step machine. A new choice replaces one waiting for its confirm (one change at a time); choosing the role the person
155
+ * already has is a cancel; while a change saves, nothing but its end moves it. */
156
+ export function roleChangeStep(state: RoleChange | null, e: RoleChangeEvent): RoleChange | null {
157
+ switch (e.type) {
158
+ case "choose": {
159
+ if (state?.saving) return state;
160
+ if (e.to === (e.from ?? "")) return null;
161
+ return { personId: e.personId, scopeId: e.scopeId, from: e.from, to: e.to, where: e.where, saving: false };
162
+ }
163
+ case "cancel": return state?.saving ? state : null;
164
+ case "save": return state ? { ...state, saving: true } : null;
165
+ case "done":
166
+ case "failed": return null;
167
+ default: return state;
168
+ }
169
+ }
170
+
171
+ // ── Invite › Many: the CSV. ────────────────────────────────────────────────────────────────────────────────────────────────────
172
+
173
+ export interface MemberInvite { name: string; email: string; role: string; scope: string }
174
+ /** One line that will be imported. `line` is its line in the pasted text (1 = the first, a header line included). */
175
+ export interface MemberImportRow extends MemberInvite { line: number }
176
+ export type MemberImportReason = "email" | "role" | "scope" | "duplicate";
177
+ export interface MemberImportProblem { line: number; text: string; reason: MemberImportReason; value?: string }
178
+
179
+ const EMAIL = /^[^\s@,;<>"]+@[^\s@,;<>"]+\.[^\s@,;<>"]+$/;
180
+ export const isEmail = (s: string) => EMAIL.test(s.trim());
181
+
182
+ /** One CSV line into cells: `"…"` may hold the delimiter, `""` is a quote. */
183
+ export function splitCsvLine(line: string, delimiter: string): string[] {
184
+ const out: string[] = [];
185
+ let cur = "", quoted = false;
186
+ for (let i = 0; i < line.length; i++) {
187
+ const c = line[i]!;
188
+ if (quoted) {
189
+ if (c === '"' && line[i + 1] === '"') { cur += '"'; i++; }
190
+ else if (c === '"') quoted = false;
191
+ else cur += c;
192
+ } else if (c === '"' && cur.trim() === "") { quoted = true; cur = ""; }
193
+ else if (c === delimiter) { out.push(cur.trim()); cur = ""; }
194
+ else cur += c;
195
+ }
196
+ out.push(cur.trim());
197
+ return out;
198
+ }
199
+
200
+ /** Comma, unless the first line has more semicolons or tabs (a spreadsheet saved in a language that writes 1,5). */
201
+ function delimiterOf(line: string): string {
202
+ const n = (ch: string) => splitCsvLine(line, ch).length - 1;
203
+ const best = [",", ";", "\t"].map((d) => [d, n(d)] as const).sort((a, b) => b[1] - a[1])[0]!;
204
+ return best[1] > 0 ? best[0] : ",";
205
+ }
206
+
207
+ const HEADER: Record<string, keyof MemberInvite> = {
208
+ email: "email", "e-mail": "email", mail: "email",
209
+ name: "name", "full name": "name", fullname: "name",
210
+ role: "role",
211
+ scope: "scope", workspace: "scope", group: "scope", community: "scope",
212
+ };
213
+
214
+ export interface ParseMembersOptions {
215
+ roles: readonly (MemberRole | string)[];
216
+ scopes?: readonly MemberScope[];
217
+ /** A line with no role gets this one (default: the last role declared, the least one). */
218
+ defaultRole?: string;
219
+ /** A line with no scope gets this one (default: the first scope). */
220
+ defaultScope?: string;
221
+ }
222
+
223
+ /**
224
+ * Reads what was pasted (or read from a file) into the people it names and the lines it skips, with why. Columns by a first line
225
+ * of names (`email,name,role,scope`, in any order; `workspace` is `scope`; others are ignored), else in that order. Blank lines
226
+ * and `#` lines are skipped silently. A role or a scope is matched by its id or its label, any case; empty takes the default.
227
+ * The same email twice: the later line is skipped. Pure: the host still checks on its side (an account that exists, a seat).
228
+ */
229
+ export function parseMembersCsv(text: string, opts: ParseMembersOptions): { rows: MemberImportRow[]; problems: MemberImportProblem[] } {
230
+ const scopes = scopesOf(opts.scopes);
231
+ const lines = text.replace(/^/, "").split(/\r\n|\r|\n/);
232
+ const rows: MemberImportRow[] = [];
233
+ const problems: MemberImportProblem[] = [];
234
+ const first = lines.findIndex((l) => l.trim() && !l.trim().startsWith("#"));
235
+ if (first < 0) return { rows, problems };
236
+ const delimiter = delimiterOf(lines[first]!);
237
+ const head = splitCsvLine(lines[first]!, delimiter).map((c) => foldText(c));
238
+ let order: Array<keyof MemberInvite | null> = ["email", "name", "role", "scope"];
239
+ let start = first;
240
+ if (head.some((c) => HEADER[c] === "email")) {
241
+ order = head.map((c) => HEADER[c] ?? null);
242
+ start = first + 1;
243
+ }
244
+ const seen = new Set<string>();
245
+ const matchRole = (scope: MemberScope, v: string) => {
246
+ const k = foldText(v);
247
+ return rolesIn(scope, opts.roles).find((r) => foldText(r.id) === k || foldText(r.label) === k)?.id;
248
+ };
249
+ const matchScope = (v: string) => {
250
+ const k = foldText(v);
251
+ return scopes.find((s) => foldText(s.id) === k || (s.label && foldText(s.label) === k));
252
+ };
253
+ for (let i = start; i < lines.length; i++) {
254
+ const raw = lines[i]!;
255
+ const t = raw.trim();
256
+ if (!t || t.startsWith("#")) continue;
257
+ const cells = splitCsvLine(raw, delimiter);
258
+ const get = (k: keyof MemberInvite) => { const at = order.indexOf(k); return at >= 0 ? (cells[at] ?? "").trim() : ""; };
259
+ const line = i + 1;
260
+ const email = get("email").toLowerCase();
261
+ if (!isEmail(email)) { problems.push({ line, text: t, reason: "email", value: get("email") }); continue; }
262
+ const scopeText = get("scope");
263
+ const scope = scopeText ? matchScope(scopeText) : scopes.find((s) => s.id === opts.defaultScope) ?? scopes[0]!;
264
+ if (!scope) { problems.push({ line, text: t, reason: "scope", value: scopeText }); continue; }
265
+ const offered = rolesIn(scope, opts.roles);
266
+ const roleText = get("role");
267
+ const role = roleText ? matchRole(scope, roleText) : (offered.find((r) => r.id === opts.defaultRole) ?? offered[offered.length - 1])?.id;
268
+ if (!role) { problems.push({ line, text: t, reason: "role", value: roleText }); continue; }
269
+ const key = `${email}\u0000${scope.id}`;
270
+ if (seen.has(key)) { problems.push({ line, text: t, reason: "duplicate", value: email }); continue; }
271
+ seen.add(key);
272
+ rows.push({ line, email, name: get("name"), role, scope: scope.id });
273
+ }
274
+ return { rows, problems };
275
+ }
276
+
277
+ /** What the host says about a line after Check: the account exists (the import only adds the role), or it cannot be imported. */
278
+ export interface MemberImportVerdict { email: string; scope?: string; existing?: boolean; problem?: string }
@@ -0,0 +1 @@
1
+ .gb-members{container:gb-members / inline-size}.gb-members-notice{display:flex;flex-wrap:wrap;align-items:center;gap:4px 12px;padding:8px 12px;border-radius:var(--ui-radius-md, 8px);font-size:13px;line-height:20px}.gb-members-notice--warning{background:var(--gemboss-warning-soft, #fff8e0);color:var(--gemboss-warning, #9a6700)}.gb-members-notice--info{background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent-strong, #3a44de)}.gb-members-notice__text{flex:1 1 auto;min-width:0}.gb-members .gb-members-notice__action{flex:none;padding:0;border:0;background:transparent;color:inherit;font:inherit;font-weight:600;cursor:pointer;text-decoration:underline;text-underline-offset:2px}.gb-members .gb-members-notice__action:hover,.gb-members .gb-members-notice__action:active{background:transparent;color:inherit;text-decoration-thickness:2px}.gb-members .gb-members-notice__action:focus-visible{outline:2px solid var(--ui-focus, #5661f5);outline-offset:2px;border-radius:4px}.gb-members-bar{display:flex;flex-wrap:wrap;align-items:center;gap:8px 12px}.gb-members-chips{display:flex;flex-wrap:wrap;align-items:center;gap:6px;flex:1 1 auto;min-width:0}.gb-members .gb-members-chip{display:inline-flex;align-items:center;gap:6px;box-sizing:border-box;height:var(--ui-btn-h, 28px);padding:0 10px;border:1px solid var(--ui-border, #e5e7ea);border-radius:999px;background:var(--ui-surface, #fff);color:var(--ui-text-muted, #686b71);font:inherit;font-size:12px;line-height:16px;font-weight:500;white-space:nowrap;cursor:pointer}.gb-members .gb-members-chip:hover,.gb-members .gb-members-chip:active{background:var(--ui-surface-2, #eceef2);color:var(--ui-text, #1b1c1e)}.gb-members .gb-members-chip:focus-visible{outline:2px solid var(--ui-focus, #5661f5);outline-offset:1px}.gb-members-chip__n{font-weight:600;color:var(--ui-text, #1b1c1e);font-variant-numeric:tabular-nums}.gb-members .gb-members-chip[aria-pressed=true],.gb-members .gb-members-chip[aria-pressed=true]:hover{background:var(--ui-accent, #1b1c1e);border-color:var(--ui-accent, #1b1c1e);color:var(--ui-accent-fg, #fff)}.gb-members-chip[aria-pressed=true] .gb-members-chip__n{color:inherit}.gb-members-sep{flex:none;width:1px;height:18px;margin:0 4px;background:var(--ui-border, #e5e7ea)}.gb-members-search{flex:0 1 240px;min-width:180px}.gb-members-scroll{overflow-x:auto;max-width:100%}.gb-members-table{min-width:640px}.gb-members-row{cursor:pointer}.gb-members-table tbody .gb-members-row--changing,.gb-members-table tbody .gb-members-row--changing:hover,.gb-members-table tbody .gb-members-row--open{background:var(--ui-accent-soft, #f0f1f4)}.gb-members-table td{white-space:nowrap}.gb-members-table .gb-members-person{color:var(--ui-text, #1b1c1e);font-weight:400;white-space:normal;min-width:200px}.gb-members-who{display:flex;align-items:center;gap:10px;min-width:0}.gb-members-who__text{display:grid;min-width:0}.gb-members-who__line{display:flex;align-items:center;gap:6px;min-width:0}.gb-members .gb-members-name{min-width:0;padding:0;border:0;background:transparent;color:var(--ui-text-strong, #1b1c1e);font:inherit;font-size:13px;line-height:20px;font-weight:600;text-align:left;cursor:pointer;overflow-wrap:anywhere}.gb-members .gb-members-name:hover,.gb-members .gb-members-name:active{background:transparent;color:var(--ui-text-strong, #1b1c1e);text-decoration:underline;text-underline-offset:2px}.gb-members .gb-members-name:focus-visible{outline:2px solid var(--ui-focus, #5661f5);outline-offset:2px;border-radius:4px}.gb-members-you{flex:none;padding:0 6px;border-radius:999px;background:var(--ui-surface-2, #eceef2);color:var(--ui-text-muted, #686b71);font-size:11px;line-height:16px;font-weight:500}.gb-members-email{font-size:12px;line-height:16px;color:var(--ui-text-muted, #686b71);overflow-wrap:anywhere}.gb-members-role{min-width:112px}.gb-members-role--ro{display:inline-flex;align-items:center;box-sizing:border-box;height:30px;padding:0 10px;border:1px dashed var(--ui-border, #e5e7ea);border-radius:var(--ui-radius-md, 8px);background:var(--ui-surface-2, #eceef2);color:var(--ui-text-muted, #686b71);font-size:12px;cursor:default}.gb-members-role--changing.ui-select{border-color:var(--gemboss-accent, #5661f5);box-shadow:0 0 0 2px var(--gemboss-accent-soft, #eef0fe)}.gb-members-status{display:inline-flex;align-items:center;gap:6px}.gb-members-dot{flex:none;width:7px;height:7px;border-radius:50%;background:var(--gemboss-success, #007f5f)}.gb-members-status--pending .gb-members-dot{background:var(--gemboss-warning, #9a6700)}.gb-members-status--invited .gb-members-dot{background:transparent;box-shadow:inset 0 0 0 1.5px var(--ui-text-muted, #686b71)}.gb-members-status--locked .gb-members-dot{background:var(--gemboss-danger, #d72c0d)}.gb-members-status--locked{color:var(--gemboss-danger-strong, #b42318)}.gb-members-last{color:var(--ui-text-muted, #686b71);font-variant-numeric:tabular-nums}.gb-members-table .gb-members-actions{position:relative;width:1%;text-align:right}.gb-members-rowactions{display:inline-flex;align-items:center;justify-content:flex-end;gap:8px}.gb-members-confirm{display:inline-flex;flex-wrap:wrap;align-items:center;gap:8px;font-size:12px}.gb-members-actions>.gb-members-confirm{position:absolute;inset-block:0;right:0;flex-wrap:nowrap;justify-content:flex-end;padding:0 12px 0 24px;white-space:nowrap;background:linear-gradient(to right,transparent,var(--ui-accent-soft, #f0f1f4) 16px)}.gb-members-confirm__q{color:var(--gemboss-accent-strong, #3a44de);font-weight:600}.gb-members-cards{display:none;margin:0;padding:0;list-style:none}.gb-members-card{display:flex;align-items:center;gap:8px;padding:0 12px 0 0;border-bottom:1px solid var(--ui-border, #e5e7ea)}.gb-members-card:last-child{border-bottom:0}.gb-members .gb-members-card__open{display:flex;align-items:center;gap:10px;flex:1 1 auto;min-width:0;min-height:56px;padding:10px 0 10px 12px;border:0;background:transparent;color:var(--ui-text, #1b1c1e);font:inherit;font-size:13px;text-align:left;cursor:pointer}.gb-members .gb-members-card__open:hover,.gb-members .gb-members-card__open:active{background:transparent;color:var(--ui-text, #1b1c1e)}.gb-members .gb-members-card__open:focus-visible{outline:2px solid var(--ui-focus, #5661f5);outline-offset:-2px}.gb-members-card__text{display:grid;flex:1 1 auto;min-width:0}.gb-members-card__name{display:flex;align-items:center;gap:6px;font-weight:600;line-height:20px;overflow-wrap:anywhere}.gb-members-card__meta{font-size:12px;line-height:16px;color:var(--ui-text-muted, #686b71);overflow-wrap:anywhere}.gb-members-card__go{flex:none;color:var(--ui-text-muted, #686b71)}@container gb-members (max-width: 640px){.gb-members-scroll{display:none}.gb-members-cards{display:block}.gb-members-chips{flex:1 1 100%;flex-wrap:nowrap;overflow-x:auto;scrollbar-width:none;padding-bottom:2px}.gb-members-chips::-webkit-scrollbar{display:none}.gb-members-search{flex:1 1 100%;min-width:0}}.gb-members-drawer{display:grid}.gb-members-drawer__sec{display:grid;gap:8px;padding:0 0 16px}.gb-members-drawer__sec+.gb-members-drawer__sec{padding-top:16px;border-top:1px solid var(--ui-border, #e5e7ea)}.gb-members-drawer__h{margin:0;font-size:12px;line-height:16px;font-weight:600;color:var(--ui-text-muted, #686b71)}.gb-members-kv{display:grid;gap:8px;margin:0;font-size:13px;line-height:20px}.gb-members-kv__row{display:grid;grid-template-columns:128px minmax(0,1fr);gap:4px 12px;align-items:center}.gb-members-kv__row>dt{color:var(--ui-text-muted, #686b71)}.gb-members-kv__row>dd{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:0;min-width:0}.gb-members-tag{padding:0 6px;border-radius:999px;font-size:11px;line-height:18px;font-weight:600}.gb-members-tag--ok{background:var(--gemboss-success-soft, #e3f1df);color:var(--gemboss-success-strong, #0a6a4c)}.gb-members-tag--warn{background:var(--gemboss-warning-soft, #fff8e0);color:var(--gemboss-warning, #9a6700)}.gb-members-drawer__buttons{display:flex;flex-wrap:wrap;gap:8px}.gb-members-drawer .gb-members-btn--danger{color:var(--gemboss-danger-strong, #b42318)}.gb-members-drawer .gb-members-btn--danger:hover{background:var(--gemboss-danger-soft, #fff0e9);color:var(--gemboss-danger-strong, #b42318)}.gb-members-drawer__slot{padding-top:16px;border-top:1px solid var(--ui-border, #e5e7ea);min-width:0}.gb-members-tabs{margin:-4px 0 12px}.gb-members-panel{display:grid;gap:8px}.gb-members-form{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}.gb-members-field{display:grid;gap:4px;min-width:0}.gb-members-field__label{font-size:12px;line-height:16px;color:var(--ui-text-muted, #686b71)}.gb-members-input{width:100%}.gb-members-note{margin:0;font-size:12px;line-height:16px;color:var(--ui-text-muted, #686b71)}.gb-members-error{margin:0;font-size:12px;line-height:16px;color:var(--gemboss-danger-strong, #b42318)}.gb-members-csv{width:100%;box-sizing:border-box;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px}.gb-members-tools{display:flex;flex-wrap:wrap;gap:8px}.gb-members-check{display:grid;margin:0;padding:0;list-style:none;border:1px solid var(--ui-border, #e5e7ea);border-radius:var(--ui-radius-md, 8px);font-size:12px}.gb-members-check__row{display:grid;grid-template-columns:16px minmax(0,1fr) auto;gap:8px;align-items:center;padding:6px 10px}.gb-members-check__row+.gb-members-check__row{border-top:1px solid var(--ui-border, #e5e7ea)}.gb-members-check__mark{font-weight:700;color:var(--gemboss-success, #007f5f)}.gb-members-check__row--skip .gb-members-check__mark{color:var(--gemboss-warning, #9a6700)}.gb-members-check__what{overflow-wrap:anywhere}.gb-members-check__why{font-style:normal;color:var(--ui-text-muted, #686b71);white-space:nowrap}@media (max-width: 47.9975em){.gb-members-form{grid-template-columns:minmax(0,1fr)}}