@gemboss/ui 0.58.0 → 0.59.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 +85 -0
- package/README.md +189 -5
- package/catalog/editor.html +1 -1
- package/catalog/index.html +2 -2
- package/gemboss-ui.css +2 -2
- package/node/skill-flow/layout.js +194 -0
- package/node/skill-flow/model.js +279 -0
- package/package.json +16 -2
- package/parts/components.css +1 -1
- package/parts/core.css +1 -1
- package/parts/shell.css +1 -1
- package/src/auth-sso-plain.js +1 -1
- package/src/auth.tsx +2 -0
- package/src/editor.css +1 -1
- package/src/index.ts +11 -1
- package/src/list-page.css +1 -1
- package/src/members-data.ts +278 -0
- package/src/members.css +1 -0
- package/src/members.tsx +868 -0
- package/src/menu-extras.css +1 -1
- package/src/menu-select.css +1 -0
- package/src/menu.tsx +39 -12
- package/src/skill-card.css +1 -0
- package/src/skill-card.tsx +146 -0
- package/src/skill-flow/canvas.tsx +43 -24
- package/src/skill-flow/index.ts +3 -1
- package/src/skill-flow/layout.ts +15 -6
- package/src/skill-flow/model.ts +216 -60
- package/src/skill-flow.css +1 -1
- package/src/skill-view.css +1 -1
- package/src/skill-view.tsx +101 -109
- package/src/theme-dark.css +1 -1
package/src/menu-extras.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.ui-menu__busy{width:16px;height:16px;box-sizing:border-box;border:2px solid currentColor;border-right-color:transparent;border-radius:50%;animation:ui-menu-busy .8s linear infinite}@keyframes ui-menu-busy{to{transform:rotate(360deg)}}@media (prefers-reduced-motion: reduce){.ui-menu__busy{animation-duration:2s}}.ui-menu__list{max-width:calc(100vw - 16px)}.ui-menu__item{flex-wrap:wrap}.ui-menu__hint{max-width:32ch;white-space:normal;text-align:right}.ui-menu:not([open])>.ui-menu__list{display:none}.ui-menu__check{display:inline-flex;flex:none;width:16px;height:16px;visibility:hidden}.ui-menu__item[aria-checked=true]>.ui-menu__check{visibility:visible}.ui-menu__item[aria-checked=true]{font-weight:600}.ui-menu__group-title{padding:6px 6px 2px;color:var(--ui-text-muted);font-size:var(--ui-fs-caption);line-height:16px}@media (pointer: coarse),(max-width: 47.9975em){.ui-menu__group-title{padding:8px 16px 4px}}
|
|
1
|
+
.ui-menu__busy{width:16px;height:16px;box-sizing:border-box;border:2px solid currentColor;border-right-color:transparent;border-radius:50%;animation:ui-menu-busy .8s linear infinite}@keyframes ui-menu-busy{to{transform:rotate(360deg)}}@media (prefers-reduced-motion: reduce){.ui-menu__busy{animation-duration:2s}}.ui-menu__list{max-width:calc(100vw - 16px)}.ui-menu__item{flex-wrap:wrap}.ui-menu__hint{max-width:32ch;white-space:normal;text-align:right}.ui-menu:not([open])>.ui-menu__list{display:none}.ui-menu__check{display:inline-flex;flex:none;width:16px;height:16px;visibility:hidden}.ui-menu__item[aria-checked=true]>.ui-menu__check{visibility:visible}.ui-menu__item[aria-checked=true]{font-weight:600}.ui-menu__group-title{padding:6px 6px 2px;color:var(--ui-text-muted);font-size:var(--ui-fs-caption);line-height:16px}@media (pointer: coarse),(max-width: 47.9975em){.ui-menu__group-title{padding:8px 16px 4px}}.ui-menu__trigger{height:auto;min-height:24px;padding:0;gap:4px;border-color:transparent;background:transparent;color:var(--gemboss-accent-strong, #3a44de);font-size:var(--ui-fs-body);font-weight:600}.ui-menu__trigger:hover{background:transparent;text-decoration:underline}.ui-menu__trigger-icon,.ui-menu__icon{display:inline-flex;flex:none;align-items:center;justify-content:center}.ui-menu__trigger-icon svg{width:16px;height:16px;fill:currentColor}.ui-menu__icon{width:20px;color:var(--ui-text-muted)}.ui-menu__icon svg{width:16px;height:16px;fill:currentColor}.ui-menu__text{display:flex;flex:1 1 auto;flex-direction:column;min-width:0;padding-block:2px;white-space:normal}.ui-menu__label{overflow-wrap:anywhere}.ui-menu__desc{color:var(--ui-text-muted);font-size:var(--ui-fs-caption);line-height:16px}.ui-menu__group-title--overline{padding-top:8px;font-size:11px;font-weight:600;letter-spacing:.06em;text-transform:uppercase}@media (pointer: coarse),(max-width: 47.9975em){.ui-menu__trigger{min-height:44px}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.ui-menu--select{display:block}.ui-menu__select{display:flex;align-items:center;gap:8px;min-height:32px;padding:0 8px 0 12px;box-sizing:border-box;border:1px solid var(--gemboss-field-line);border-radius:var(--ui-radius-sm);background:var(--gemboss-field-bg);color:var(--gemboss-field-ink);font-size:var(--ui-fs-body)}.ui-menu__select:hover{border-color:var(--gemboss-field-line-hover);background:var(--gemboss-field-bg-hover)}.ui-menu__select:focus-visible{outline:2px solid var(--ui-focus, #5661f5);outline-offset:1px}.ui-menu__choice{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ui-menu__chevron{flex:none;color:var(--ui-text-muted)}.ui-menu--select>.ui-menu__list{min-width:280px;max-width:min(420px,calc(100vw - 16px))}@media (pointer: coarse),(max-width: 47.9975em){.ui-menu__select{min-height:44px}}
|
package/src/menu.tsx
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// goes on; one menu open at a time. Its CSS is its own file (./menu.css), so a surface without the core (the admin) draws it.
|
|
15
15
|
import "./menu.css";
|
|
16
16
|
import "./menu-extras.css";
|
|
17
|
+
import "./menu-select.css";
|
|
17
18
|
import React, { useEffect, useRef } from "react";
|
|
18
19
|
import { Icon } from "./icons";
|
|
19
20
|
import { canFloatMenus, floatMenu, listenForDetachedMenus, sinkMenu } from "./menu-layer";
|
|
@@ -21,10 +22,17 @@ import { chooseRow, closeMenu, focusRow, menuKeyDown, menuRows, openMenu, regist
|
|
|
21
22
|
|
|
22
23
|
/** The trigger is an icon button (`label` is its accessible name, and the menu's). `end` aligns the list to the right edge.
|
|
23
24
|
* `disabled`: the ⋯ takes no click and no key and leaves the Tab order (a row's work runs). `loading`: a ring in place of the
|
|
24
|
-
* dots, `aria-busy`, and disabled the same way (what it started runs: a rename, a duplicate).
|
|
25
|
-
|
|
25
|
+
* dots, `aria-busy`, and disabled the same way (what it started runs: a rename, a duplicate).
|
|
26
|
+
* `text` (04/11/2026): a text trigger instead, the words after `icon` in the link colour ("+ Add a condition"); the words are
|
|
27
|
+
* its name, `label` still names the list.
|
|
28
|
+
* `select` (04/11/2026, GemX New moment ubm-PZ-4w / 4t): a FIELD trigger instead, as wide as its column, the current choice and a
|
|
29
|
+
* chevron: a choice whose rows say more than an `<option>` can (parts, a mark, a line under the words, a row off with "Later").
|
|
30
|
+
* Named "label: choice" when the choice is words. */
|
|
31
|
+
export function Menu({ label, icon, text, select, end, children, className, disabled, loading }: {
|
|
26
32
|
label: string;
|
|
27
33
|
icon?: React.ReactNode;
|
|
34
|
+
text?: React.ReactNode;
|
|
35
|
+
select?: React.ReactNode;
|
|
28
36
|
end?: boolean;
|
|
29
37
|
children?: React.ReactNode;
|
|
30
38
|
className?: string;
|
|
@@ -66,15 +74,25 @@ export function Menu({ label, icon, end, children, className, disabled, loading
|
|
|
66
74
|
enter(el, "first");
|
|
67
75
|
};
|
|
68
76
|
return (
|
|
69
|
-
<details ref={ref} className={["ui-menu", end ? "ui-menu--end" : "", className ?? ""].filter(Boolean).join(" ")}
|
|
77
|
+
<details ref={ref} className={["ui-menu", end ? "ui-menu--end" : "", select !== undefined ? "ui-menu--select" : "", className ?? ""].filter(Boolean).join(" ")}
|
|
70
78
|
onKeyDown={(e) => { if (ref.current && !off) menuKeyDown(ref.current, e, { entry: enter }); }}
|
|
71
79
|
// Opened while off by anything but its button (find-in-page opens a closed details that holds a match, a script):
|
|
72
80
|
// closed again.
|
|
73
81
|
onToggle={(e) => { if (off && e.currentTarget.open) e.currentTarget.open = false; }}>
|
|
74
|
-
|
|
75
|
-
aria-
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
{select !== undefined ? (
|
|
83
|
+
<summary className="ui-menu__select" aria-label={typeof select === "string" ? `${label}: ${select}` : label} aria-haspopup="menu" onClick={onSummary}
|
|
84
|
+
aria-disabled={off || undefined} aria-busy={loading || undefined} tabIndex={off ? -1 : undefined}>
|
|
85
|
+
<span className="ui-menu__choice">{select}</span>
|
|
86
|
+
<svg className="ui-menu__chevron" viewBox="0 0 20 20" width="16" height="16" aria-hidden="true"><path d="M6 8l4 4 4-4" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" /></svg>
|
|
87
|
+
</summary>
|
|
88
|
+
) : (
|
|
89
|
+
<summary className={text ? "ui-btn ui-menu__trigger" : "ui-btn ui-btn--icon"} aria-label={text ? undefined : label} title={text ? undefined : label}
|
|
90
|
+
aria-haspopup="menu" onClick={onSummary} aria-disabled={off || undefined} aria-busy={loading || undefined} tabIndex={off ? -1 : undefined}>
|
|
91
|
+
{loading ? <span className="ui-menu__busy" aria-hidden="true" />
|
|
92
|
+
: text ? <>{icon ? <span className="ui-menu__trigger-icon" aria-hidden="true">{icon}</span> : null}{text}</>
|
|
93
|
+
: (icon ?? <Icon name="more" />)}
|
|
94
|
+
</summary>
|
|
95
|
+
)}
|
|
78
96
|
<div className="ui-menu__list gemboss-popover-surface" role="menu" aria-label={label}>{children}</div>
|
|
79
97
|
</details>
|
|
80
98
|
);
|
|
@@ -93,8 +111,12 @@ function enter(el: HTMLDetailsElement, which: "first" | "last"): void {
|
|
|
93
111
|
if (on) on.focus(); else focusRow(el, which);
|
|
94
112
|
}
|
|
95
113
|
|
|
96
|
-
export function MenuItem({ href, danger, hint, children, className, disabled, onClick, linkAs, checked, ...rest }: {
|
|
114
|
+
export function MenuItem({ href, danger, hint, icon, description, children, className, disabled, onClick, linkAs, checked, ...rest }: {
|
|
97
115
|
href?: string;
|
|
116
|
+
/** A mark before the label (04/11/2026). */
|
|
117
|
+
icon?: React.ReactNode;
|
|
118
|
+
/** A second line under the label, muted: what the row is, in a few words (04/11/2026, Audiences' "+ Add a condition"). */
|
|
119
|
+
description?: React.ReactNode;
|
|
98
120
|
/** A choice among others (in a MenuGroup): `menuitemradio`, a check before the one that is on. Left out: a plain row. */
|
|
99
121
|
checked?: boolean;
|
|
100
122
|
linkAs?: React.ElementType;
|
|
@@ -109,7 +131,10 @@ export function MenuItem({ href, danger, hint, children, className, disabled, on
|
|
|
109
131
|
const body = <>{checked === undefined ? null : <span className="ui-menu__check" aria-hidden="true"><Icon name="check" size={16} /></span>}
|
|
110
132
|
{/* A space before the hint, so its words are read apart from the row's ("Duplicate List is full", not "DuplicateList is
|
|
111
133
|
full"); the row is a flex box, which draws no space. */}
|
|
112
|
-
{
|
|
134
|
+
{icon ? <span className="ui-menu__icon" aria-hidden="true">{icon}</span> : null}
|
|
135
|
+
{/* The label over its description, a space between them for the same reason as the hint's. */}
|
|
136
|
+
{description ? <span className="ui-menu__text"><span className="ui-menu__label">{children}</span>{" "}<span className="ui-menu__desc">{description}</span></span> : children}
|
|
137
|
+
{hint ? <>{" "}<span className="ui-menu__hint">{hint}</span></> : null}</>;
|
|
113
138
|
// Every row closes its menu once chosen, a link too (a new tab, an anchor, a client router leave the page as it was).
|
|
114
139
|
// Focus is back on ⋯ before the row's handler runs (./menu-keys chooseRow).
|
|
115
140
|
const choose: React.MouseEventHandler<HTMLElement> = (e) => {
|
|
@@ -125,11 +150,13 @@ export function MenuItem({ href, danger, hint, children, className, disabled, on
|
|
|
125
150
|
}
|
|
126
151
|
|
|
127
152
|
/** Rows that are choices of one kind (Products' Auto-refresh: Daily, Off), named: `role="group"` with the title as its name,
|
|
128
|
-
* and the title shown above them. Its rows are MenuItems with `checked`.
|
|
129
|
-
|
|
153
|
+
* and the title shown above them. Its rows are MenuItems with `checked`. `overline` (04/11/2026): the title as a section's
|
|
154
|
+
* overline, small capitals, for a menu of actions in parts (Audiences' "+ Add a condition": known before the page shows,
|
|
155
|
+
* checked in the browser, from your apps, your own). */
|
|
156
|
+
export function MenuGroup({ title, overline, children }: { title: string; overline?: boolean; children?: React.ReactNode }) {
|
|
130
157
|
return (
|
|
131
158
|
<div className="ui-menu__group" role="group" aria-label={title}>
|
|
132
|
-
<div className="ui-menu__group-title" aria-hidden="true">{title}</div>
|
|
159
|
+
<div className={overline ? "ui-menu__group-title ui-menu__group-title--overline" : "ui-menu__group-title"} aria-hidden="true">{title}</div>
|
|
133
160
|
{children}
|
|
134
161
|
</div>
|
|
135
162
|
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.ui-skillgroup{display:grid;gap:12px;min-width:0}.ui-skillgroup+.ui-skillgroup{margin-top:28px}.ui-skillgroup__head{display:grid;gap:2px}.ui-skillgroup__title{margin:0;font-size:14px;line-height:20px;font-weight:650;color:var(--gemboss-text, #1b1c1e)}.ui-skillgroup__mark{display:inline-block;width:10px;height:10px;margin-right:8px;border-radius:3px}.ui-skillgroup__aside{margin-left:8px;font-size:12px;font-weight:500;color:var(--gemboss-text-muted, #686b71)}.ui-skillgroup__line{margin:0;font-size:13px;line-height:19px;color:var(--gemboss-text-muted, #686b71)}.ui-skillgroup__grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,var(--ui-skillgroup-min, 220px)),1fr));gap:12px}.ui-skillcard{display:flex;flex-direction:column;align-items:stretch;gap:6px;min-width:0;box-sizing:border-box;margin:0;padding:14px;border:1px solid var(--gemboss-divider, #e5e7ea);border-radius:12px;background:var(--gemboss-surface, #ffffff);color:var(--gemboss-text, #1b1c1e);font:inherit;text-align:left;text-decoration:none;cursor:pointer;transition:border-color .12s ease,box-shadow .12s ease}.ui-skillcard:hover,.ui-skillcard:active{border-color:var(--gemboss-chip-line, #cfd6ce);background:var(--gemboss-surface, #ffffff);color:var(--gemboss-text, #1b1c1e);box-shadow:var(--gemboss-shadow-resting, 0 1px 2px rgba(31, 30, 29, .04), 0 2px 6px rgba(31, 30, 29, .06))}.ui-skillcard:focus-visible{outline:2px solid var(--ui-focus, #5661f5);outline-offset:2px}@media (prefers-reduced-motion: reduce){.ui-skillcard{transition:none}}.ui-skillcard__top{display:flex;align-items:flex-start;justify-content:space-between;gap:8px;margin-bottom:4px}.ui-skillcard__icon{display:grid;place-items:center;width:32px;height:32px;border-radius:8px;background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent, #5661f5)}.ui-skillcard__icon svg{width:18px;height:18px}.ui-skillcard__art{flex:none;display:grid;place-items:center;min-width:var(--ui-skillcard-art, auto);min-height:var(--ui-skillcard-art, auto)}.ui-skillcard__badge{padding:0 8px;border-radius:999px;font-size:11px;line-height:20px;font-weight:600;background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent-strong, #3a44de)}.ui-skillcard__badge--ready{background:var(--gemboss-success-soft, #e3f1df);color:var(--gemboss-success-strong, #0a6a4c)}.ui-skillcard__badge--beta{background:var(--gemboss-warning-soft, #fff8e0);color:var(--gemboss-warning, #9a6700)}.ui-skillcard__badge--plain{background:var(--gemboss-primary-soft, #f2f3f5);color:var(--gemboss-text-muted, #686b71)}.ui-skillcard__title{font-size:14px;line-height:19px;font-weight:600}.ui-skillcard__aside{font-size:.82em}.ui-skillcard__line{font-size:12px;line-height:18px;color:var(--gemboss-text-muted, #686b71)}.ui-skillcard__foot{display:flex;flex-wrap:wrap;align-items:baseline;justify-content:space-between;gap:2px 8px;margin-top:auto;padding-top:6px}.ui-skillcard__about{display:flex;flex-wrap:wrap;align-items:center;gap:4px 10px;min-width:0}.ui-skillcard__meta{font:500 11px/16px ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--gemboss-text-muted, #686b71)}.ui-skillcard__extra{display:inline-flex;flex-wrap:wrap;align-items:center;gap:4px 10px;font-size:12px;line-height:16px;color:var(--gemboss-text-muted, #686b71)}.ui-skillcard__stat{font-size:12px;line-height:16px;color:var(--gemboss-text-muted, #686b71);font-variant-numeric:tabular-nums}.ui-skillcard--split{padding:0;gap:0;overflow:hidden;cursor:auto}.ui-skillcard__open{display:flex;flex-direction:column;gap:6px;flex:1 1 auto;min-width:0;margin:0;padding:14px;border:0;border-radius:0;background:none;color:inherit;font:inherit;text-align:left;text-decoration:none;cursor:pointer}.ui-skillcard__open:hover,.ui-skillcard__open:active{background:none;color:inherit}.ui-skillcard__open:focus-visible{outline:2px solid var(--ui-focus, #5661f5);outline-offset:-2px}.ui-skillcard__bar{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px;padding:10px 14px 12px;border-top:1px solid var(--gemboss-divider, #e5e7ea)}.ui-skillcard__bar>.ui-skillcard__about{flex:1 1 0}.ui-skillcard__bar .ui-skillcard__meta{white-space:nowrap}.ui-skillcard__actions{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin-left:auto}.ui-skillcard--lg{gap:12px;padding:18px 18px 14px;border-radius:16px}.ui-skillcard--lg.ui-skillcard--split{padding:0}.ui-skillcard--lg .ui-skillcard__open{gap:12px;padding:18px 18px 14px}.ui-skillcard--lg .ui-skillcard__bar{padding:12px 18px 14px}.ui-skillcard--lg .ui-skillcard__top{margin-bottom:0}.ui-skillcard--lg .ui-skillcard__title{font-size:16px;line-height:22px}.ui-skillcard--lg .ui-skillcard__line{margin-top:-8px;font-size:13px;line-height:19px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SkillGroup and SkillCard — @gemboss/ui (03/11/2026, the shared skills UI; their own file and entry, skill-card.css, since
|
|
5
|
+
* 04/11/2026). The list a skill's popup (SkillView) opens from: a group per job, a card per skill.
|
|
6
|
+
*
|
|
7
|
+
* 04/11/2026 (Chris: "Kit thêm slot, giữ giao diện content-radar"): content-radar's /v2/skills draws its cards and family groups with
|
|
8
|
+
* these, so they gained its slots, every one optional (GemBoss's Assistant › Skills draws what it drew before):
|
|
9
|
+
* a card: `iconSize` (a picture of its own, a 72px mascot, bare instead of the iris tile), `badgeTone` (Ready / Beta / Research /
|
|
10
|
+
* Later), `aside` (a second name), `children` (a framework's steps under the line), `extra` (more of the foot: style · voice),
|
|
11
|
+
* `actions` (a row under the card, OUTSIDE its link: a button cannot sit inside a link) and `size="lg"` (content-radar's room);
|
|
12
|
+
* a group: `mark` (a coloured square before the name), `aside` (its second name) and `minCardWidth`.
|
|
13
|
+
*/
|
|
14
|
+
import "./skill-card.css";
|
|
15
|
+
import React, { type CSSProperties, type ReactNode } from "react";
|
|
16
|
+
|
|
17
|
+
const cx = (...p: Array<string | false | null | undefined>) => p.filter(Boolean).join(" ");
|
|
18
|
+
/** A custom property in a React style (the box sizes below). */
|
|
19
|
+
const cssVar = (name: string, px: number | undefined): CSSProperties | undefined =>
|
|
20
|
+
(typeof px === "number" && px > 0 ? ({ [name]: `${px}px` } as CSSProperties) : undefined);
|
|
21
|
+
|
|
22
|
+
/** A skill's state as its badge says it: `new` is the kit's iris (the default), `ready` green, `beta` amber, `research` and
|
|
23
|
+
* `later` grey (content-radar's Ready / Beta / Research / Later). */
|
|
24
|
+
export type SkillBadgeTone = "new" | "ready" | "beta" | "research" | "later";
|
|
25
|
+
// Written whole, never built from the tone: a search for a class finds where it is drawn.
|
|
26
|
+
const BADGE_CLASS: Record<SkillBadgeTone, string> = {
|
|
27
|
+
new: "ui-skillcard__badge",
|
|
28
|
+
ready: "ui-skillcard__badge ui-skillcard__badge--ready",
|
|
29
|
+
beta: "ui-skillcard__badge ui-skillcard__badge--beta",
|
|
30
|
+
research: "ui-skillcard__badge ui-skillcard__badge--plain",
|
|
31
|
+
later: "ui-skillcard__badge ui-skillcard__badge--plain",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export interface SkillCardProps {
|
|
35
|
+
title: ReactNode;
|
|
36
|
+
/** A second name after the title, a little smaller (content-radar: " · Mẫu số chung" after "Common Ground"). */
|
|
37
|
+
aside?: ReactNode;
|
|
38
|
+
line?: ReactNode;
|
|
39
|
+
/** A kit icon (drawn on the 32px iris tile), or with `iconSize` a picture of its own. */
|
|
40
|
+
icon?: ReactNode;
|
|
41
|
+
/** The picture's size in px when it is not a kit icon (content-radar's 72px mascot): it stands bare, no tile. */
|
|
42
|
+
iconSize?: number;
|
|
43
|
+
/** "advertorial · v2". */
|
|
44
|
+
meta?: ReactNode;
|
|
45
|
+
/** More of the foot after `meta`, in its quiet type (content-radar: a style's icon and name, the voice). */
|
|
46
|
+
extra?: ReactNode;
|
|
47
|
+
/** "12 runs · 30 days": only when there is a number. */
|
|
48
|
+
stat?: ReactNode;
|
|
49
|
+
/** One word in the corner ("New", "Ready"). */
|
|
50
|
+
badge?: ReactNode;
|
|
51
|
+
badgeTone?: SkillBadgeTone;
|
|
52
|
+
/** Under the line, inside the card (a framework's steps, a usage line): part of what opens the skill. */
|
|
53
|
+
children?: ReactNode;
|
|
54
|
+
/** Buttons for this skill ("Write"): a bar under the card with `meta` and `extra`, OUTSIDE the card's link or button. */
|
|
55
|
+
actions?: ReactNode;
|
|
56
|
+
/** "lg": content-radar's room (18px in, 16px corners, a 16px title, the line at most two lines). */
|
|
57
|
+
size?: "lg";
|
|
58
|
+
href?: string;
|
|
59
|
+
onOpen?: () => void;
|
|
60
|
+
className?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A skill on the list: a kit icon on a tile (or a picture of its own, `iconSize`), its title by the job it does, one short line, a
|
|
65
|
+
* quiet foot ("advertorial · v2") and, when the surface has it, how often it ran. A button (or a link with `href`, the press handled
|
|
66
|
+
* by `onOpen` unless a modifier asks for a new tab). With `actions` the card is a frame: its body is the link, and the actions sit in
|
|
67
|
+
* a bar under it with the foot's words. Hover and press states are its own, so an app's bare `button:hover` cannot paint it.
|
|
68
|
+
*/
|
|
69
|
+
export function SkillCard({
|
|
70
|
+
title, aside, line, icon, iconSize, meta, extra, stat, badge, badgeTone = "new", children, actions, size, href, onOpen, className,
|
|
71
|
+
}: SkillCardProps) {
|
|
72
|
+
const art = typeof iconSize === "number" && iconSize > 0;
|
|
73
|
+
const metaEl = meta ? <span className="ui-skillcard__meta">{meta}</span> : null;
|
|
74
|
+
// meta and extra side by side, as one item of the foot (the stat keeps the far end).
|
|
75
|
+
const about = extra ? <span className="ui-skillcard__about">{metaEl}<span className="ui-skillcard__extra">{extra}</span></span> : metaEl;
|
|
76
|
+
const split = actions !== null && actions !== undefined && actions !== false;
|
|
77
|
+
const body = (
|
|
78
|
+
<>
|
|
79
|
+
<span className="ui-skillcard__top">
|
|
80
|
+
{icon ? (art
|
|
81
|
+
? <span className="ui-skillcard__art" aria-hidden="true" style={cssVar("--ui-skillcard-art", iconSize)}>{icon}</span>
|
|
82
|
+
: <span className="ui-skillcard__icon" aria-hidden="true">{icon}</span>) : null}
|
|
83
|
+
{badge ? <span className={BADGE_CLASS[badgeTone] ?? BADGE_CLASS.new}>{badge}</span> : null}
|
|
84
|
+
</span>
|
|
85
|
+
<b className="ui-skillcard__title">{title}{aside ? <span className="ui-skillcard__aside"> · {aside}</span> : null}</b>
|
|
86
|
+
{line ? <span className="ui-skillcard__line">{line}</span> : null}
|
|
87
|
+
{children}
|
|
88
|
+
{split ? (stat ? <span className="ui-skillcard__stat">{stat}</span> : null) : about || stat ? (
|
|
89
|
+
<span className="ui-skillcard__foot">
|
|
90
|
+
{about}
|
|
91
|
+
{stat ? <span className="ui-skillcard__stat">{stat}</span> : null}
|
|
92
|
+
</span>
|
|
93
|
+
) : null}
|
|
94
|
+
</>
|
|
95
|
+
);
|
|
96
|
+
const onLink = (e: React.MouseEvent) => { if (!onOpen || e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return; e.preventDefault(); onOpen(); };
|
|
97
|
+
const cls = cx("ui-skillcard", size === "lg" && "ui-skillcard--lg", split && "ui-skillcard--split", className);
|
|
98
|
+
if (!split) {
|
|
99
|
+
return href
|
|
100
|
+
? <a href={href} className={cls} onClick={onLink}>{body}</a>
|
|
101
|
+
: <button type="button" className={cls} onClick={onOpen}>{body}</button>;
|
|
102
|
+
}
|
|
103
|
+
return (
|
|
104
|
+
<div className={cls}>
|
|
105
|
+
{href
|
|
106
|
+
? <a href={href} className="ui-skillcard__open" onClick={onLink}>{body}</a>
|
|
107
|
+
: <button type="button" className="ui-skillcard__open" onClick={onOpen}>{body}</button>}
|
|
108
|
+
<div className="ui-skillcard__bar">
|
|
109
|
+
<span className="ui-skillcard__about">{metaEl}{extra ? <span className="ui-skillcard__extra">{extra}</span> : null}</span>
|
|
110
|
+
<span className="ui-skillcard__actions">{actions}</span>
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface SkillGroupProps {
|
|
117
|
+
title: ReactNode;
|
|
118
|
+
/** A second name after the title, quieter (content-radar: the family's Vietnamese name). */
|
|
119
|
+
aside?: ReactNode;
|
|
120
|
+
line?: ReactNode;
|
|
121
|
+
/** A coloured square before the name: any CSS colour ("var(--gemboss-success)", a family's banner colour). */
|
|
122
|
+
mark?: string;
|
|
123
|
+
/** The narrowest a card gets before the grid drops a column, in px (default 220; content-radar's list 270). */
|
|
124
|
+
minCardWidth?: number;
|
|
125
|
+
children?: ReactNode;
|
|
126
|
+
className?: string;
|
|
127
|
+
id?: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Skills that do one job, under its name and one line, as a grid of cards. Nothing in it: nothing drawn. */
|
|
131
|
+
export function SkillGroup({ title, aside, line, mark, minCardWidth, children, className, id }: SkillGroupProps) {
|
|
132
|
+
if (!React.Children.toArray(children).length) return null;
|
|
133
|
+
return (
|
|
134
|
+
<section className={cx("ui-skillgroup", className)} aria-labelledby={id ? `${id}-h` : undefined}>
|
|
135
|
+
<div className="ui-skillgroup__head">
|
|
136
|
+
<h2 className="ui-skillgroup__title" id={id ? `${id}-h` : undefined}>
|
|
137
|
+
{mark ? <i className="ui-skillgroup__mark" aria-hidden="true" style={{ background: mark }} /> : null}
|
|
138
|
+
{title}
|
|
139
|
+
{aside ? <span className="ui-skillgroup__aside">{aside}</span> : null}
|
|
140
|
+
</h2>
|
|
141
|
+
{line ? <p className="ui-skillgroup__line">{line}</p> : null}
|
|
142
|
+
</div>
|
|
143
|
+
<div className="ui-skillgroup__grid" style={cssVar("--ui-skillgroup-min", minCardWidth)}>{children}</div>
|
|
144
|
+
</section>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
useReactFlow, useViewport, useStore, type EdgeProps, type NodeChange, type NodeProps, type NodeTypes, type EdgeTypes,
|
|
28
28
|
} from "@xyflow/react";
|
|
29
29
|
import { ReaderDialog } from "../reader-dialog";
|
|
30
|
-
import { FLOW_ZOOM, flowWheelPans, flowZoomKey, phasesIn, shortTool, validateFlow, wheelZoom, zoomLabel, type Flow, type FlowEdgeKind, type FlowNode, type FlowPhase } from "./model";
|
|
30
|
+
import { FLOW_ZOOM, flowWheelPans, flowZoomKey, phasesIn, shortTool, validateFlow, wheelZoom, zoomLabel, type Flow, type FlowEdgeKind, type FlowMessages, type FlowNode, type FlowPhase } from "./model";
|
|
31
31
|
import { layoutFlow, type FlowLayout } from "./layout";
|
|
32
32
|
|
|
33
33
|
/** The words around the canvas. English by default; a surface passes its own. */
|
|
@@ -41,7 +41,11 @@ export interface SkillFlowLabels {
|
|
|
41
41
|
details: string; toolsHeading: string; examplesHeading: string; examplesNote: string; answers: string; nextHeading: string; from: string;
|
|
42
42
|
emptyPanel: string; closeDetails: string;
|
|
43
43
|
zoomBar: string; zoomIn: string; zoomOut: string; zoomLevel: string; fit: string; home: string; expand: string; close: string; closeFull: string;
|
|
44
|
+
/** The Expand button's tooltip. Left out: the surface's `expand` (the words it borrowed before 04/11/2026). */
|
|
45
|
+
expandTip?: string;
|
|
44
46
|
canvas: string; fullTitle: string; fullSubtitle: string; cantDraw: string;
|
|
47
|
+
/** The legend's name for a screen reader. Left out: the surface's `fullTitle` (the words it borrowed before 04/11/2026). */
|
|
48
|
+
legend?: string;
|
|
45
49
|
hint: (o: { full: boolean; touch: boolean; key: string }) => string;
|
|
46
50
|
}
|
|
47
51
|
|
|
@@ -57,9 +61,9 @@ export const SKILL_FLOW_LABELS: SkillFlowLabels = {
|
|
|
57
61
|
emptyPanel: "Tap a box to see what happens there, which tools the AI calls, an example, and where it goes next.",
|
|
58
62
|
closeDetails: "Close details",
|
|
59
63
|
zoomBar: "Zoom the flow", zoomIn: "Zoom in", zoomOut: "Zoom out", zoomLevel: "Zoom level", fit: "Fit the whole flow", home: "Back to the start",
|
|
60
|
-
expand: "Expand", close: "Close", closeFull: "Close full screen (Esc)",
|
|
64
|
+
expand: "Expand", expandTip: "Expand", close: "Close", closeFull: "Close full screen (Esc)",
|
|
61
65
|
canvas: "Flow canvas. Plus and minus zoom, 0 goes back to the start.",
|
|
62
|
-
fullTitle: "Skill flow", fullSubtitle: "Every step this skill takes, where it decides, and where it stops for you.",
|
|
66
|
+
fullTitle: "Skill flow", fullSubtitle: "Every step this skill takes, where it decides, and where it stops for you.", legend: "Skill flow",
|
|
63
67
|
cantDraw: "Couldn't draw this flow",
|
|
64
68
|
hint: ({ full, touch, key }) => (full
|
|
65
69
|
? (touch ? "Pinch to zoom, drag to move. Tap a box for what happens there." : `Scroll or drag to move, ${key} + scroll or a pinch to zoom. Click a box for what happens there.`)
|
|
@@ -75,8 +79,13 @@ export interface SkillFlowProps {
|
|
|
75
79
|
labels?: Partial<SkillFlowLabels>;
|
|
76
80
|
/** One line above the canvas (where the flow came from, a problem with it). */
|
|
77
81
|
note?: ReactNode;
|
|
78
|
-
/**
|
|
82
|
+
/** "bad": the note is a problem (the flow file is broken and a stand-in is drawn): the danger tint, said as an alert. */
|
|
83
|
+
noteTone?: "bad";
|
|
84
|
+
/** A phase key to light; the other lanes fade (where a job using this skill stands now). The lit lane carries `data-lit`
|
|
85
|
+
* and a ring; its boxes carry `data-lit` too. */
|
|
79
86
|
highlight?: string | null;
|
|
87
|
+
/** The words of a problem when `flow` does not pass validateFlow ("Couldn't draw this flow (…)"); model.ts FLOW_MESSAGES is the English. */
|
|
88
|
+
messages?: Partial<FlowMessages>;
|
|
80
89
|
/** Prefixes cut off a tool's name in a box (`gemboss_get_skill` → `get_skill`). */
|
|
81
90
|
toolPrefixes?: readonly string[];
|
|
82
91
|
/** The surface's class for rendered Markdown (an example's `html`). */
|
|
@@ -132,6 +141,13 @@ const FitIcon = () => <Stroke d="M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5
|
|
|
132
141
|
const ExpandIcon = () => <Stroke d="M9.5 2.5h4v4M13.5 2.5 9 7M6.5 13.5h-4v-4M2.5 13.5 7 9" />;
|
|
133
142
|
const CollapseIcon = () => <Stroke d="M13 7H9V3M9 7l4.5-4.5M3 9h4v4M7 9l-4.5 4.5" />;
|
|
134
143
|
|
|
144
|
+
/** The surface's words over the English ones. `expandTip` and `legend` were the `expand` and `fullTitle` words until 04/11/2026: a
|
|
145
|
+
* surface that renamed those and not these keeps what it had. */
|
|
146
|
+
export function skillFlowLabels(labels?: Partial<SkillFlowLabels>): SkillFlowLabels {
|
|
147
|
+
const L = { ...SKILL_FLOW_LABELS, ...labels };
|
|
148
|
+
return { ...L, expandTip: labels?.expandTip ?? labels?.expand ?? SKILL_FLOW_LABELS.expandTip, legend: labels?.legend ?? labels?.fullTitle ?? SKILL_FLOW_LABELS.legend };
|
|
149
|
+
}
|
|
150
|
+
|
|
135
151
|
/** `**bold**` and `code` inside a line of an example, as elements (no HTML string, nothing to sanitise). */
|
|
136
152
|
function inline(text: string): ReactNode[] {
|
|
137
153
|
return text.split(/(\*\*[^*]+\*\*|`[^`]+`)/g).filter(Boolean).map((p, i) => (p.startsWith("**") && p.endsWith("**") && p.length > 4
|
|
@@ -173,16 +189,17 @@ export function ExampleMd({ md }: { md: string }) {
|
|
|
173
189
|
return <>{out}</>;
|
|
174
190
|
}
|
|
175
191
|
|
|
176
|
-
type Ctx = { L: SkillFlowLabels; prefixes?: readonly string[]; dim: (phase: string) => boolean };
|
|
177
|
-
const FlowCtx = React.createContext<Ctx>({ L: SKILL_FLOW_LABELS, dim: () => false });
|
|
192
|
+
type Ctx = { L: SkillFlowLabels; prefixes?: readonly string[]; dim: (phase: string) => boolean; lit: (phase: string) => boolean; messages?: Partial<FlowMessages> };
|
|
193
|
+
const FlowCtx = React.createContext<Ctx>({ L: SKILL_FLOW_LABELS, dim: () => false, lit: () => false });
|
|
178
194
|
|
|
179
195
|
type NodeData = { node: FlowNode; lane: number };
|
|
180
196
|
function FlowNodeBox({ data, selected }: NodeProps) {
|
|
181
|
-
const { L, prefixes, dim } = React.useContext(FlowCtx);
|
|
197
|
+
const { L, prefixes, dim, lit } = React.useContext(FlowCtx);
|
|
182
198
|
const { node: n, lane } = data as unknown as NodeData;
|
|
183
199
|
const eye = n.kind === "step" ? (n.human ? L.person : null) : L.kinds[n.kind];
|
|
184
200
|
return (
|
|
185
|
-
<div className={NODE_CLASS[n.kind] ?? "skf-node"} data-lane={lane % LANE_TONES} data-on={selected ? "" : undefined} data-dim={dim(n.phase) ? "" : undefined}
|
|
201
|
+
<div className={NODE_CLASS[n.kind] ?? "skf-node"} data-lane={lane % LANE_TONES} data-on={selected ? "" : undefined} data-dim={dim(n.phase) ? "" : undefined}
|
|
202
|
+
data-lit={lit(n.phase) ? "" : undefined}>
|
|
186
203
|
<Handles />
|
|
187
204
|
{eye ? <span className="skf-node__eye">{n.kind === "stop" || n.human ? <PersonIcon /> : null}{eye}</span> : null}
|
|
188
205
|
<span className="skf-node__label">{n.label}</span>
|
|
@@ -193,10 +210,11 @@ function FlowNodeBox({ data, selected }: NodeProps) {
|
|
|
193
210
|
|
|
194
211
|
type BandData = { label: string; lanes: boolean; lane: number; phase: string };
|
|
195
212
|
function Band({ data }: NodeProps) {
|
|
196
|
-
const { dim } = React.useContext(FlowCtx);
|
|
213
|
+
const { dim, lit } = React.useContext(FlowCtx);
|
|
197
214
|
const b = data as unknown as BandData;
|
|
198
215
|
return (
|
|
199
|
-
<div className={`skf-band${b.lanes ? " skf-band--lane" : ""}`} data-lane={b.lane % LANE_TONES} data-dim={dim(b.phase) ? "" : undefined}
|
|
216
|
+
<div className={`skf-band${b.lanes ? " skf-band--lane" : ""}`} data-lane={b.lane % LANE_TONES} data-dim={dim(b.phase) ? "" : undefined}
|
|
217
|
+
data-lit={lit(b.phase) ? "" : undefined}>
|
|
200
218
|
<span className="skf-band__label">{b.label}</span>
|
|
201
219
|
</div>
|
|
202
220
|
);
|
|
@@ -341,7 +359,7 @@ function ZoomBar({ full, onFit, onReset, onExpand }: { full: boolean; onFit: ()
|
|
|
341
359
|
{onExpand ? (
|
|
342
360
|
<>
|
|
343
361
|
<i className="skf-zoom__sep" aria-hidden="true" />
|
|
344
|
-
<button type="button" className="skf-zoom__btn skf-zoom__wide" onClick={onExpand} title={full ? L.closeFull : L.
|
|
362
|
+
<button type="button" className="skf-zoom__btn skf-zoom__wide" onClick={onExpand} title={full ? L.closeFull : L.expandTip}>
|
|
345
363
|
{full ? <CollapseIcon /> : <ExpandIcon />}<span>{full ? L.close : L.expand}</span>
|
|
346
364
|
</button>
|
|
347
365
|
</>
|
|
@@ -350,11 +368,11 @@ function ZoomBar({ full, onFit, onReset, onExpand }: { full: boolean; onFit: ()
|
|
|
350
368
|
);
|
|
351
369
|
}
|
|
352
370
|
|
|
353
|
-
function Canvas({ flow, phases, sel, setSel, full = false, onExpand, note, mdClassName }: {
|
|
371
|
+
function Canvas({ flow, phases, sel, setSel, full = false, onExpand, note, noteTone, mdClassName }: {
|
|
354
372
|
flow: Flow; phases: readonly FlowPhase[]; sel: string | null; setSel: React.Dispatch<React.SetStateAction<string | null>>;
|
|
355
|
-
full?: boolean; onExpand?: () => void; note?: ReactNode; mdClassName?: string;
|
|
373
|
+
full?: boolean; onExpand?: () => void; note?: ReactNode; noteTone?: "bad"; mdClassName?: string;
|
|
356
374
|
}) {
|
|
357
|
-
const { L } = React.useContext(FlowCtx);
|
|
375
|
+
const { L, messages } = React.useContext(FlowCtx);
|
|
358
376
|
const rf = useReactFlow();
|
|
359
377
|
const box = useRef<HTMLDivElement>(null);
|
|
360
378
|
const stage = useRef<HTMLDivElement>(null);
|
|
@@ -381,8 +399,8 @@ function Canvas({ flow, phases, sel, setSel, full = false, onExpand, note, mdCla
|
|
|
381
399
|
|
|
382
400
|
const wide = w >= WIDE;
|
|
383
401
|
const lay = useMemo((): { L?: FlowLayout; err?: string } => {
|
|
384
|
-
try { return { L: layoutFlow(flow, { phases, lanes: wide }) }; } catch (e) { return { err: (e as Error).message }; }
|
|
385
|
-
}, [flow, phases, wide]);
|
|
402
|
+
try { return { L: layoutFlow(flow, { phases, lanes: wide, messages }) }; } catch (e) { return { err: (e as Error).message }; }
|
|
403
|
+
}, [flow, phases, wide, messages]);
|
|
386
404
|
const G = lay.L;
|
|
387
405
|
|
|
388
406
|
// Full screen: the canvas is as tall as the popup's frame, measured, for the first view.
|
|
@@ -501,7 +519,7 @@ function Canvas({ flow, phases, sel, setSel, full = false, onExpand, note, mdCla
|
|
|
501
519
|
return (
|
|
502
520
|
<div className={`skf${full ? " skf--full" : ""}`} ref={box}>
|
|
503
521
|
<div className="skf-top">
|
|
504
|
-
<ul className="skf-legend" aria-label={L.
|
|
522
|
+
<ul className="skf-legend" aria-label={L.legend}>
|
|
505
523
|
{shown.map((p) => <li key={p.key}><i className="skf-dot" data-lane={laneOf(p.key) % LANE_TONES} />{p.label}</li>)}
|
|
506
524
|
<li><i className="skf-key skf-key--decision" />{L.legendDecision}</li>
|
|
507
525
|
<li><i className="skf-key skf-key--stop" />{L.legendStop}</li>
|
|
@@ -511,7 +529,7 @@ function Canvas({ flow, phases, sel, setSel, full = false, onExpand, note, mdCla
|
|
|
511
529
|
</ul>
|
|
512
530
|
<p className="skf-hint">{hint}</p>
|
|
513
531
|
</div>
|
|
514
|
-
{!full && note ? <div className="skf-note">{note}</div> : null}
|
|
532
|
+
{!full && note ? (noteTone === "bad" ? <div className="skf-note skf-note--bad" role="alert">{note}</div> : <div className="skf-note">{note}</div>) : null}
|
|
515
533
|
{lay.err ? <p className="skf-note skf-note--bad" role="alert">{L.cantDraw} ({lay.err}).</p> : null}
|
|
516
534
|
{G && (view || full) ? (
|
|
517
535
|
<div className={`skf__stage${wide ? " is-wide" : ""}`} ref={stage} style={full || !view ? undefined : { height: view.h }} onKeyDown={onKeyDown}>
|
|
@@ -544,22 +562,23 @@ function Canvas({ flow, phases, sel, setSel, full = false, onExpand, note, mdCla
|
|
|
544
562
|
* A read-only canvas for one flow. The picked box is shared between the canvas in the page and the full-screen one (Expand): it
|
|
545
563
|
* opens on the box you were reading.
|
|
546
564
|
*/
|
|
547
|
-
export function SkillFlow({ flow: input, phases, labels, note, highlight = null, toolPrefixes, mdClassName }: SkillFlowProps) {
|
|
565
|
+
export function SkillFlow({ flow: input, phases, labels, note, noteTone, highlight = null, toolPrefixes, mdClassName, messages }: SkillFlowProps) {
|
|
548
566
|
const [sel, setSel] = useState<string | null>(null);
|
|
549
567
|
const [full, setFull] = useState(false);
|
|
550
|
-
const L = useMemo(() => (
|
|
568
|
+
const L = useMemo(() => skillFlowLabels(labels), [labels]);
|
|
551
569
|
// Checked once here, with the defaults filled (a node without `tools`, an edge without `kind`) and a server's example html kept:
|
|
552
570
|
// the boxes, the details and the layout all read this one copy, never the raw input.
|
|
553
571
|
const checked = useMemo((): { flow?: Flow; err?: string } => {
|
|
554
|
-
try { return { flow: validateFlow(input, { phases, allowHtml: true }) }; } catch (e) { return { err: (e as Error).message }; }
|
|
555
|
-
}, [input, phases]);
|
|
556
|
-
const ctx = useMemo<Ctx>(() => ({ L, prefixes: toolPrefixes, dim: (phase: string) => !!highlight && phase !== highlight
|
|
572
|
+
try { return { flow: validateFlow(input, { phases, allowHtml: true, messages }) }; } catch (e) { return { err: (e as Error).message }; }
|
|
573
|
+
}, [input, phases, messages]);
|
|
574
|
+
const ctx = useMemo<Ctx>(() => ({ L, prefixes: toolPrefixes, messages, dim: (phase: string) => !!highlight && phase !== highlight,
|
|
575
|
+
lit: (phase: string) => !!highlight && phase === highlight }), [L, toolPrefixes, highlight, messages]);
|
|
557
576
|
if (!checked.flow) return <div className="skf"><p className="skf-note skf-note--bad" role="alert">{L.cantDraw} ({checked.err}).</p></div>;
|
|
558
577
|
const flow = checked.flow;
|
|
559
578
|
return (
|
|
560
579
|
<FlowCtx.Provider value={ctx}>
|
|
561
580
|
<ReactFlowProvider>
|
|
562
|
-
<Canvas flow={flow} phases={phases} sel={sel} setSel={setSel} onExpand={() => setFull(true)} note={note} mdClassName={mdClassName} />
|
|
581
|
+
<Canvas flow={flow} phases={phases} sel={sel} setSel={setSel} onExpand={() => setFull(true)} note={note} noteTone={noteTone} mdClassName={mdClassName} />
|
|
563
582
|
</ReactFlowProvider>
|
|
564
583
|
{full ? (
|
|
565
584
|
// The kit's ReaderDialog, opened up to nearly the whole window (skill-flow.css): Esc / ✕ close it alone, the popup behind stays.
|
package/src/skill-flow/index.ts
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* load either. Import it lazily (next/dynamic with `ssr: false`, React.lazy), and only where a flow is drawn.
|
|
5
5
|
*
|
|
6
6
|
* The data side alone (checking a flow.json on a server, the zoom maths in a test) is `@gemboss/ui/skill-flow/model`: no peer.
|
|
7
|
+
* `@gemboss/ui/skill-flow/layout` is `layoutFlow` alone (dagre, no React). The published package carries both as plain JavaScript
|
|
8
|
+
* too, under the `node` condition, so Node without a TypeScript step imports them (scripts/pack-lib.mjs NODE_COPIES, 04/11/2026).
|
|
7
9
|
*/
|
|
8
|
-
export { ExampleMd, SkillFlow, SKILL_FLOW_LABELS, type SkillFlowLabels, type SkillFlowProps } from "./canvas";
|
|
10
|
+
export { ExampleMd, SkillFlow, SKILL_FLOW_LABELS, skillFlowLabels, type SkillFlowLabels, type SkillFlowProps } from "./canvas";
|
|
9
11
|
export { layoutFlow, nodeSize, type FlowBand, type FlowLayout, type LaidEdge, type LaidNode } from "./layout";
|
|
10
12
|
export * from "./model";
|
package/src/skill-flow/layout.ts
CHANGED
|
@@ -6,8 +6,13 @@
|
|
|
6
6
|
* Box sizes are estimated from the words (the canvas has fixed widths and boxes grow in height): skill-flow.css keeps the same
|
|
7
7
|
* numbers (padding, type size, the tool pills). Change one, change the other.
|
|
8
8
|
*/
|
|
9
|
-
import
|
|
10
|
-
import { FLOW_DIRECTIONS, shortTool, validateFlow, type Flow, type FlowDirection, type FlowEdgeKind, type FlowNode, type FlowPhase } from "./model";
|
|
9
|
+
import * as dagreModule from "@dagrejs/dagre";
|
|
10
|
+
import { FLOW_DIRECTIONS, shortTool, validateFlow, type Flow, type FlowDirection, type FlowEdgeKind, type FlowMessages, type FlowNode, type FlowPhase } from "./model";
|
|
11
|
+
|
|
12
|
+
// dagre 3 is an ES module with named exports; dagre 1.x (the peer range starts at 1.1) is CommonJS, which plain Node hands to an
|
|
13
|
+
// ES module as its `default` (this file also ships as plain JavaScript for Node: pack-lib.mjs NODE_COPIES). A bundler gives both.
|
|
14
|
+
type Dagre = typeof dagreModule;
|
|
15
|
+
const dagre: Dagre = (dagreModule as { graphlib?: unknown }).graphlib ? dagreModule : (dagreModule as unknown as { default: Dagre }).default;
|
|
11
16
|
|
|
12
17
|
const NODE_W: Record<string, number> = { start: 184, end: 184, step: 212, stop: 212, decision: 212, exit: 188 };
|
|
13
18
|
const LANE = { head: 34, pad: 14, gap: 44, min: 240, side: 40 };
|
|
@@ -44,7 +49,7 @@ function dagreLayout(nodes: Sized[], edges: Flow["edges"], rankdir: FlowDirectio
|
|
|
44
49
|
const into = edges.find((e) => e.to === n.id && ids.has(e.from) && byId.get(e.from)!.kind !== "exit");
|
|
45
50
|
if (into) side.set(n.id, into.from);
|
|
46
51
|
}
|
|
47
|
-
const g = new graphlib.Graph();
|
|
52
|
+
const g = new dagre.graphlib.Graph();
|
|
48
53
|
g.setGraph({ rankdir, align: "UR", nodesep: 22, ranksep: 40, edgesep: 12, marginx: 0, marginy: 0 });
|
|
49
54
|
g.setDefaultEdgeLabel(() => ({}));
|
|
50
55
|
for (const n of nodes) if (!side.has(n.id)) g.setNode(n.id, { ...n.size });
|
|
@@ -53,7 +58,7 @@ function dagreLayout(nodes: Sized[], edges: Flow["edges"], rankdir: FlowDirectio
|
|
|
53
58
|
if (e.kind === "loop" || !g.hasNode(e.from) || !g.hasNode(e.to)) continue;
|
|
54
59
|
g.setEdge(e.from, e.to, { minlen: 1, weight: e.kind === "no" ? 1 : 3 });
|
|
55
60
|
}
|
|
56
|
-
|
|
61
|
+
dagre.layout(g as never);
|
|
57
62
|
const gr = g.graph() as { width?: number; height?: number };
|
|
58
63
|
let width = gr.width || 0;
|
|
59
64
|
let height = gr.height || 0;
|
|
@@ -103,12 +108,16 @@ export interface FlowLayout { direction: FlowDirection; lanes: boolean; width: n
|
|
|
103
108
|
* `t-<side>` (target), side t | b | l | r: a node on the canvas carries all eight. `height` is an estimate (real words may run
|
|
104
109
|
* a line longer); the canvas lets the box grow.
|
|
105
110
|
*/
|
|
106
|
-
export function layoutFlow(input: unknown, { phases, direction, lanes = false
|
|
111
|
+
export function layoutFlow(input: unknown, { phases, direction, lanes = false, messages }: {
|
|
112
|
+
phases: readonly FlowPhase[]; direction?: FlowDirection; lanes?: boolean;
|
|
113
|
+
/** The words of a problem when the flow does not pass validateFlow (model.ts FLOW_MESSAGES is the English). */
|
|
114
|
+
messages?: Partial<FlowMessages>;
|
|
115
|
+
}): FlowLayout {
|
|
107
116
|
// The drawing only: the caller may carry extra keys at the top (a note, a source), and examples (with `html` from a server)
|
|
108
117
|
// do not move a box. validateFlow takes neither, so both go before it checks.
|
|
109
118
|
const bare = (n: unknown) => (n && typeof n === "object" && !Array.isArray(n) ? (({ examples: _x, ...rest }: Record<string, unknown>) => rest)(n as Record<string, unknown>) : n);
|
|
110
119
|
const obj = input && typeof input === "object" && !Array.isArray(input) ? (input as Record<string, unknown>) : null;
|
|
111
|
-
const flow = validateFlow(obj ? { direction: obj.direction, nodes: Array.isArray(obj.nodes) ? obj.nodes.map(bare) : obj.nodes, edges: obj.edges } : input, { phases });
|
|
120
|
+
const flow = validateFlow(obj ? { direction: obj.direction, nodes: Array.isArray(obj.nodes) ? obj.nodes.map(bare) : obj.nodes, edges: obj.edges } : input, { phases, messages });
|
|
112
121
|
const dir: FlowDirection = direction && FLOW_DIRECTIONS.includes(direction) ? direction : flow.direction;
|
|
113
122
|
const tb = dir === "TB";
|
|
114
123
|
const list: Sized[] = flow.nodes.map((n) => ({ ...n, size: nodeSize(n) }));
|