@alepha/ui 0.39.0 → 0.40.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/README.md +4 -2
- package/dist/admin/AdminJobExecutionSheet.d.ts.map +1 -1
- package/dist/admin/AdminJobExecutionSheet.js +7 -0
- package/dist/admin/AdminJobExecutionSheet.js.map +1 -1
- package/dist/admin/analytics/RequestDialog.js +1 -1
- package/dist/admin/analytics/RequestDialog.js.map +1 -1
- package/dist/ai/AiChat.d.ts +6 -3
- package/dist/ai/AiChat.d.ts.map +1 -1
- package/dist/ai/AiChat.js +34 -5
- package/dist/ai/AiChat.js.map +1 -1
- package/dist/ai/AiChatConfirmCard.d.ts.map +1 -1
- package/dist/ai/AiChatConfirmCard.js +5 -1
- package/dist/ai/AiChatConfirmCard.js.map +1 -1
- package/dist/ai/AiChatFloat.d.ts +14 -0
- package/dist/ai/AiChatFloat.d.ts.map +1 -0
- package/dist/ai/AiChatFloat.js +30 -0
- package/dist/ai/AiChatFloat.js.map +1 -0
- package/dist/ai/AiChatMessage.js +2 -2
- package/dist/ai/AiChatMessage.js.map +1 -1
- package/dist/ai/AiChatPanel.d.ts +19 -0
- package/dist/ai/AiChatPanel.d.ts.map +1 -1
- package/dist/ai/AiChatPanel.js +65 -19
- package/dist/ai/AiChatPanel.js.map +1 -1
- package/dist/ai/AiChatToolStepDetails.d.ts +14 -0
- package/dist/ai/AiChatToolStepDetails.d.ts.map +1 -0
- package/dist/ai/AiChatToolStepDetails.js +34 -0
- package/dist/ai/AiChatToolStepDetails.js.map +1 -0
- package/dist/ai/AiChatToolTrace.d.ts +50 -0
- package/dist/ai/AiChatToolTrace.d.ts.map +1 -0
- package/dist/ai/AiChatToolTrace.js +91 -0
- package/dist/ai/AiChatToolTrace.js.map +1 -0
- package/dist/ai/index.d.ts +4 -2
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +3 -1
- package/dist/core/Button.d.ts.map +1 -1
- package/dist/core/Button.js +17 -1
- package/dist/core/Button.js.map +1 -1
- package/dist/core/Dialog.d.ts.map +1 -1
- package/dist/core/Dialog.js +1 -1
- package/dist/core/Dialog.js.map +1 -1
- package/dist/core/TimeAgo.d.ts +3 -4
- package/dist/core/TimeAgo.d.ts.map +1 -1
- package/dist/core/TimeAgo.js +3 -4
- package/dist/core/TimeAgo.js.map +1 -1
- package/dist/i18n/en/index.d.ts +22 -0
- package/dist/i18n/en/index.d.ts.map +1 -0
- package/dist/i18n/en/index.js +1 -0
- package/dist/i18n/en/uiEn.d.ts +37 -0
- package/dist/i18n/en/uiEn.d.ts.map +1 -0
- package/dist/i18n/en/uiEn.js +1468 -0
- package/dist/i18n/en/uiEn.js.map +1 -0
- package/dist/i18n/fr/uiFr.d.ts +3 -2
- package/dist/i18n/fr/uiFr.d.ts.map +1 -1
- package/dist/i18n/fr/uiFr.js +7 -2
- package/dist/i18n/fr/uiFr.js.map +1 -1
- package/dist/markdown/MarkdownView.d.ts +14 -0
- package/dist/markdown/MarkdownView.d.ts.map +1 -1
- package/dist/markdown/MarkdownView.js +16 -3
- package/dist/markdown/MarkdownView.js.map +1 -1
- package/dist/markdown/highlightLines.d.ts +27 -0
- package/dist/markdown/highlightLines.d.ts.map +1 -0
- package/dist/markdown/highlightLines.js +91 -0
- package/dist/markdown/highlightLines.js.map +1 -0
- package/dist/markdown/index.d.ts +5 -2
- package/dist/markdown/index.d.ts.map +1 -1
- package/dist/markdown/index.js +2 -1
- package/dist/shell/ButtonInbox.d.ts +8 -0
- package/dist/shell/ButtonInbox.d.ts.map +1 -1
- package/dist/shell/ButtonInbox.js +3 -1
- package/dist/shell/ButtonInbox.js.map +1 -1
- package/dist/shell/PlateLayout.d.ts.map +1 -1
- package/dist/shell/PlateLayout.js +2 -2
- package/dist/shell/PlateLayout.js.map +1 -1
- package/dist/sortable/index.d.ts +17 -0
- package/dist/sortable/index.d.ts.map +1 -0
- package/dist/sortable/index.js +4 -0
- package/dist/sortable/useSortableItem.d.ts +32 -0
- package/dist/sortable/useSortableItem.d.ts.map +1 -0
- package/dist/sortable/useSortableItem.js +35 -0
- package/dist/sortable/useSortableItem.js.map +1 -0
- package/dist/sortable/useSortableList.d.ts +85 -0
- package/dist/sortable/useSortableList.d.ts.map +1 -0
- package/dist/sortable/useSortableList.js +125 -0
- package/dist/sortable/useSortableList.js.map +1 -0
- package/dist/table/DataTable.d.ts.map +1 -1
- package/dist/table/DataTable.js +9 -6
- package/dist/table/DataTable.js.map +1 -1
- package/dist/table/DataTableRowActionGroupItem.d.ts +23 -0
- package/dist/table/DataTableRowActionGroupItem.d.ts.map +1 -0
- package/dist/table/DataTableRowActionGroupItem.js +38 -0
- package/dist/table/DataTableRowActionGroupItem.js.map +1 -0
- package/dist/table/DataTableRowActionItem.d.ts.map +1 -1
- package/dist/table/DataTableRowActionItem.js +15 -2
- package/dist/table/DataTableRowActionItem.js.map +1 -1
- package/dist/table/DataTableRowActionsInline.d.ts.map +1 -1
- package/dist/table/DataTableRowActionsInline.js +2 -1
- package/dist/table/DataTableRowActionsInline.js.map +1 -1
- package/dist/table/DataTableRowActionsMenu.d.ts +3 -2
- package/dist/table/DataTableRowActionsMenu.d.ts.map +1 -1
- package/dist/table/DataTableRowActionsMenu.js +12 -14
- package/dist/table/DataTableRowActionsMenu.js.map +1 -1
- package/dist/table/dataTableBaseProps.d.ts +16 -2
- package/dist/table/dataTableBaseProps.d.ts.map +1 -1
- package/dist/table/dataTablePersistence.d.ts +53 -11
- package/dist/table/dataTablePersistence.d.ts.map +1 -1
- package/dist/table/dataTablePersistence.js +66 -29
- package/dist/table/dataTablePersistence.js.map +1 -1
- package/dist/table/dataTableTypes.d.ts +20 -3
- package/dist/table/dataTableTypes.d.ts.map +1 -1
- package/dist/table/index.d.ts +8 -1
- package/dist/table/index.d.ts.map +1 -1
- package/dist/table/index.js +2 -1
- package/dist/table/useDataTableColumns.d.ts.map +1 -1
- package/dist/table/useDataTableColumns.js +4 -4
- package/dist/table/useDataTableColumns.js.map +1 -1
- package/dist/table/useDataTableData.d.ts.map +1 -1
- package/dist/table/useDataTableData.js +3 -3
- package/dist/table/useDataTableData.js.map +1 -1
- package/dist/table/useDataTableFilterForm.d.ts.map +1 -1
- package/dist/table/useDataTableFilterForm.js +6 -2
- package/dist/table/useDataTableFilterForm.js.map +1 -1
- package/dist/table/useDataTableFilterVisibility.d.ts +5 -0
- package/dist/table/useDataTableFilterVisibility.d.ts.map +1 -1
- package/dist/table/useDataTableFilterVisibility.js +16 -8
- package/dist/table/useDataTableFilterVisibility.js.map +1 -1
- package/dist/table/useDataTableRefresh.d.ts.map +1 -1
- package/dist/table/useDataTableRefresh.js +3 -2
- package/dist/table/useDataTableRefresh.js.map +1 -1
- package/dist/table/useDataTableSummary.d.ts +5 -0
- package/dist/table/useDataTableSummary.d.ts.map +1 -1
- package/dist/table/useDataTableSummary.js +6 -6
- package/dist/table/useDataTableSummary.js.map +1 -1
- package/docs/packages-alepha-ui-ai.md +3 -3
- package/docs/packages-alepha-ui-i18n-en.md +35 -0
- package/docs/packages-alepha-ui-markdown.md +3 -1
- package/docs/packages-alepha-ui-overview.md +4 -2
- package/docs/packages-alepha-ui-sortable.md +34 -0
- package/docs/packages-alepha-ui-table.md +7 -1
- package/package.json +21 -3
- package/src/admin/AdminJobExecutionSheet.tsx +9 -0
- package/src/admin/analytics/RequestDialog.tsx +1 -1
- package/src/ai/AiChat.tsx +44 -6
- package/src/ai/AiChatConfirmCard.tsx +7 -1
- package/src/ai/AiChatFloat.tsx +46 -0
- package/src/ai/AiChatMessage.tsx +2 -2
- package/src/ai/AiChatPanel.tsx +154 -47
- package/src/ai/AiChatToolStepDetails.tsx +42 -0
- package/src/ai/AiChatToolTrace.tsx +167 -0
- package/src/ai/__tests__/AiChat.browser.spec.tsx +270 -2
- package/src/ai/index.ts +4 -2
- package/src/core/Button.tsx +26 -1
- package/src/core/Dialog.tsx +6 -2
- package/src/core/TimeAgo.tsx +3 -4
- package/src/core/__tests__/Button.browser.spec.tsx +57 -0
- package/src/i18n/en/__tests__/uiEn.spec.ts +110 -0
- package/src/i18n/en/index.ts +22 -0
- package/src/i18n/en/uiEn.ts +1647 -0
- package/src/i18n/fr/uiFr.ts +7 -2
- package/src/markdown/MarkdownView.tsx +30 -1
- package/src/markdown/__tests__/highlightLines.spec.ts +45 -0
- package/src/markdown/highlightLines.ts +120 -0
- package/src/markdown/index.ts +14 -2
- package/src/shell/ButtonInbox.tsx +11 -1
- package/src/shell/PlateLayout.tsx +18 -9
- package/src/shell/__tests__/ButtonInbox.browser.spec.tsx +40 -0
- package/src/shell/__tests__/PlateLayout.browser.spec.tsx +19 -2
- package/src/sortable/__tests__/useSortableList.browser.spec.tsx +157 -0
- package/src/sortable/index.ts +22 -0
- package/src/sortable/useSortableItem.ts +65 -0
- package/src/sortable/useSortableList.ts +231 -0
- package/src/table/DataTable.tsx +8 -5
- package/src/table/DataTableRowActionGroupItem.tsx +75 -0
- package/src/table/DataTableRowActionItem.tsx +6 -0
- package/src/table/DataTableRowActionsInline.tsx +3 -1
- package/src/table/DataTableRowActionsMenu.tsx +33 -49
- package/src/table/__tests__/DataTablePersistenceStorage.browser.spec.tsx +204 -0
- package/src/table/__tests__/DataTableRowActionGroup.browser.spec.tsx +118 -1
- package/src/table/dataTableBaseProps.ts +16 -2
- package/src/table/dataTablePersistence.ts +118 -32
- package/src/table/dataTableTypes.ts +20 -3
- package/src/table/index.ts +14 -1
- package/src/table/useDataTableColumns.ts +9 -4
- package/src/table/useDataTableData.ts +8 -3
- package/src/table/useDataTableFilterForm.ts +6 -2
- package/src/table/useDataTableFilterVisibility.ts +20 -7
- package/src/table/useDataTableRefresh.ts +4 -2
- package/src/table/useDataTableSummary.ts +25 -8
|
@@ -18,7 +18,21 @@ export interface MarkdownViewProps {
|
|
|
18
18
|
* exist). Return `children` alone to drop the link.
|
|
19
19
|
*/
|
|
20
20
|
renderLink?: MarkdownLinkRenderer;
|
|
21
|
+
/**
|
|
22
|
+
* Renders every image instead of the default `<img src>`: a repository's
|
|
23
|
+
* README points at `logo.png` beside it, which only the app can turn into
|
|
24
|
+
* a URL it serves. Return `null` to drop the image.
|
|
25
|
+
*/
|
|
26
|
+
renderImage?: MarkdownImageRenderer;
|
|
21
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* See {@link MarkdownViewProps.renderImage}.
|
|
30
|
+
*/
|
|
31
|
+
export type MarkdownImageRenderer = (image: {
|
|
32
|
+
src?: string;
|
|
33
|
+
alt?: string;
|
|
34
|
+
title?: string;
|
|
35
|
+
}) => ReactNode;
|
|
22
36
|
/**
|
|
23
37
|
* See {@link MarkdownViewProps.renderLink}.
|
|
24
38
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownView.d.ts","sourceRoot":"","sources":["../../src/markdown/MarkdownView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAAQ,KAAK,SAAS,EAAY,MAAM,OAAO,CAAC;AAkCvD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"MarkdownView.d.ts","sourceRoot":"","sources":["../../src/markdown/MarkdownView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAAQ,KAAK,SAAS,EAAY,MAAM,OAAO,CAAC;AAkCvD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC;;;;OAIG;IACH,WAAW,CAAC,EAAE,qBAAqB,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,KAAK,EAAE;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,KAAK,SAAS,CAAC;AAEhB;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;CACrB,KAAK,SAAS,CAAC;AAEhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,eAAO,MAAM,YAAY,UAAW,iBAAiB,sBAsJpD,CAAC"}
|
|
@@ -176,9 +176,22 @@ const MarkdownView = (props) => {
|
|
|
176
176
|
children
|
|
177
177
|
}),
|
|
178
178
|
hr: () => /* @__PURE__ */ jsx("hr", { className: "border-border my-6" }),
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
img: ({ src, alt, title }) => props.renderImage ? props.renderImage({
|
|
180
|
+
src: typeof src === "string" ? src : void 0,
|
|
181
|
+
alt,
|
|
182
|
+
title
|
|
183
|
+
}) : /* @__PURE__ */ jsx("img", {
|
|
184
|
+
src,
|
|
185
|
+
alt,
|
|
186
|
+
title,
|
|
187
|
+
className: "max-w-full"
|
|
188
|
+
}),
|
|
189
|
+
table: ({ children }) => /* @__PURE__ */ jsx("div", {
|
|
190
|
+
className: "my-4 max-w-full overflow-x-auto",
|
|
191
|
+
children: /* @__PURE__ */ jsx("table", {
|
|
192
|
+
className: "border-collapse text-xs",
|
|
193
|
+
children
|
|
194
|
+
})
|
|
182
195
|
}),
|
|
183
196
|
th: ({ children }) => /* @__PURE__ */ jsx("th", {
|
|
184
197
|
className: "border-border border px-2 py-1 text-start font-medium",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownView.js","names":["pre"],"sources":["../../src/markdown/MarkdownView.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport \"./MarkdownView.css\";\nimport { lazy, type ReactNode, Suspense } from \"react\";\nimport ReactMarkdown from \"react-markdown\";\nimport remarkGfm from \"remark-gfm\";\n\nimport { textLinkUnderlineClassName } from \"../core/TextLink.tsx\";\nimport { DiagramErrorBoundary } from \"./diagram/DiagramErrorBoundary.tsx\";\nimport { rehypeHighlight } from \"./rehypeHighlight.ts\";\nimport { remarkSpoiler } from \"./remarkSpoiler.ts\";\nimport { SpoilerSpan } from \"./SpoilerSpan.tsx\";\n\n/**\n * Both parsers, both layouts (`graphre` for the flowchart, arithmetic for\n * the sequence diagram) and both emitters, pulled in ONLY when a document\n * actually contains a mermaid fence.\n *\n * This is the constraint the whole diagram layer exists under: a document\n * with no diagram must pay nothing at all. One with a diagram pays one\n * chunk once, then it is cached. Measured on 2026-08-28 with both diagram\n * types in it: 64.5 kB raw, **22.2 kB gzip**, 19.4 kB brotli - against\n * 17.95 kB gzip when it drew flowcharts only. If it ever passes ~26 kB,\n * split the two pipelines into two chunks so a flowchart-only document\n * stops paying for the sequence one.\n *\n * ⚠️ A lazy import a bundler decides to inline fails silently: the feature\n * still works and the cost moves into the entry chunk. After changing this,\n * build an app that renders a `MarkdownView` (Lore does, in `lore/` in this\n * repository) and confirm, from its directory, that the\n * diagram code is in a chunk of its own and the entry has none of it:\n *\n * yarn alepha build\n * grep -rl 'addBorderSegments\\|sequenceDiagram' dist/public/\n */\nconst MermaidFence = lazy(() => import(\"./diagram/MermaidFence.tsx\"));\n\nexport interface MarkdownViewProps {\n content: string;\n /**\n * Extra classes for the prose root, merged after the defaults so a caller\n * can set its own reading face or measure. The defaults it overrides are\n * `text-sm leading-relaxed`: a surface that sets prose in a display serif\n * needs both, and no parent wrapper can supply them, since they sit on\n * this element rather than being inherited.\n */\n className?: string;\n /**\n * Renders every link instead of the default `<a href>`: an app routes an\n * internal path through its own router link, or leaves a link it does not\n * trust as plain text (an assistant's reply may carry a path that does not\n * exist). Return `children` alone to drop the link.\n */\n renderLink?: MarkdownLinkRenderer;\n}\n\n/**\n * See {@link MarkdownViewProps.renderLink}.\n */\nexport type MarkdownLinkRenderer = (link: {\n href?: string;\n children: ReactNode;\n}) => ReactNode;\n\n/**\n * Renders markdown as formatted prose.\n *\n * ## Diagrams\n *\n * A ` ```mermaid ` fence containing a **`flowchart`** or a\n * **`sequenceDiagram`** is drawn as an SVG diagram instead of a code block,\n * themed from the app's own CSS variables so dark mode needs no second\n * palette. The renderer is in-house: only flowchart layout is imported\n * (`graphre`, dagre in TypeScript, ~15.5 kB gzip), and the whole thing is\n * one lazy chunk pulled in only when a document actually contains a fence,\n * so a document with no diagram pays nothing.\n *\n * The flowchart subset is `flowchart TD|TB|LR|RL|BT`; the four node shapes\n * `[rect]` `(rounded)` `{diamond}` `((circle))`, with every other mermaid\n * bracket pair consumed and mapped onto them; edges `-->` `---` `-.->`\n * `==>` `<-->` with labels in both the `-->|text|` and `-- text -->` forms;\n * chains, `&` fans, `<br/>` line breaks and nested `subgraph`.\n *\n * The sequence subset is participants and actors, the eight arrow forms,\n * notes, `autonumber`, self-messages and the `alt` / `else` / `opt` /\n * `loop` fragment boxes. Activation bars are ignored. A wide sequence\n * diagram keeps its natural size in a scroll frame rather than shrinking\n * into the prose column.\n *\n * **Everything else degrades to the code block, silently.**\n * `classDiagram`, `gantt` and mindmaps are not drawn, `style` / `classDef`\n * are ignored, and a parse failure, a refused construct or a diagram past\n * its cap renders the plain fence rather than an error. Agents write\n * invalid mermaid, and a red box in the middle of a document is worse than\n * a grey fence. See `packages/@alepha/ui/DOC.md` for the full table.\n *\n * ## Spoilers\n *\n * `||text||` renders as a covered box that reveals on click, on Enter or on\n * Space, Discord's syntax and Discord's behaviour. Inline markdown inside it\n * survives, a code span or a fence keeps its pipes literally, and an\n * unterminated `||` renders as the two characters the author typed rather\n * than swallowing the rest of the paragraph.\n *\n * ⚠️ **It is not a security feature.** The text is in the DOM from the first\n * paint, in the raw markdown, in an export, over MCP and in any search\n * snippet. It hides a plot point from a reader's eye and nothing more.\n *\n * ## Raw HTML\n *\n * No raw HTML is ever rendered as markup: react-markdown's default is to\n * escape a raw node to text, and this component deliberately mounts no\n * plugin that changes that. A narrow `rehypeSafeImg` plugin used to promote\n * a lone `<img …>` (the one thing MDXEditor emitted for a *resized* image)\n * and was deleted along with the editor that produced it, since nothing\n * writes that markup anymore.\n *\n * Do not reach for `rehype-raw` to bring the capability back: this renders\n * content authored by one user to another, so every raw tag becoming live\n * markup turns every markdown surface in every app into an injection point.\n */\nexport const MarkdownView = (props: MarkdownViewProps) => {\n return (\n <div\n // `data-slot`, matching every other block here, so a host page can\n // reach the prose root without a wrapper class. Lore's folio\n // document uses it to make this inherit the reading size instead\n // of the `text-sm` default below.\n data-slot=\"markdown-view\"\n className={`max-w-none text-sm leading-relaxed ${props.className ?? \"\"}`}\n >\n <ReactMarkdown\n // ⚠️ `remarkSpoiler` runs AFTER `remarkGfm`, and the order is\n // load-bearing: by then a `| a | b |` row is a table with cells, so\n // the pipes are structure and the spoiler walk never sees them as\n // text. Reversed, every two-column table would be a spoiler.\n remarkPlugins={[remarkGfm, remarkSpoiler]}\n rehypePlugins={[\n // `plainText` claims the fence BEFORE highlighting runs: hljs would\n // otherwise tokenise the diagram source, and the fallback would be a\n // soup of spans instead of the text the author wrote.\n //\n // The plugin is the markdown module's own, over lowlight with the\n // fifteen grammars in `HIGHLIGHT_LANGUAGES`: `rehype-highlight`\n // kept all 37 of lowlight's `common` set in the chunk whatever it\n // was given. A fence in any other language renders plain.\n [rehypeHighlight, { detect: true, plainText: [\"mermaid\"] }],\n ]}\n components={{\n h1: ({ children }) => (\n <h1 className=\"mt-6 mb-3 text-2xl font-semibold tracking-tight\">\n {children}\n </h1>\n ),\n h2: ({ children }) => (\n <h2 className=\"mt-6 mb-2 text-xl font-semibold tracking-tight\">\n {children}\n </h2>\n ),\n h3: ({ children }) => (\n <h3 className=\"mt-4 mb-2 text-base font-semibold\">{children}</h3>\n ),\n p: ({ children }) => <p className=\"my-3\">{children}</p>,\n ul: ({ children }) => (\n <ul className=\"my-3 list-disc space-y-1 ps-5\">{children}</ul>\n ),\n ol: ({ children }) => (\n <ol className=\"my-3 list-decimal space-y-1 ps-5\">{children}</ol>\n ),\n li: ({ children }) => <li className=\"ps-1\">{children}</li>,\n a: ({ href, children }) =>\n props.renderLink ? (\n props.renderLink({ href, children })\n ) : (\n <a\n href={href}\n className={`hover:text-foreground font-medium ${textLinkUnderlineClassName}`}\n >\n {children}\n </a>\n ),\n code: ({ children, className }) => {\n const isBlock =\n className?.includes(\"language-\") || className?.includes(\"hljs\");\n if (isBlock) {\n return <code className={`${className} text-xs`}>{children}</code>;\n }\n return (\n <code className=\"bg-muted rounded px-1.5 py-0.5 font-mono text-[0.85em]\">\n {children}\n </code>\n );\n },\n pre: ({ children, node }) => {\n const block = (\n <pre className=\"border-border my-4 overflow-auto rounded-md border bg-transparent p-3 text-xs\">\n {children}\n </pre>\n );\n const source = mermaidSource(node);\n if (!source) return block;\n return (\n <DiagramErrorBoundary fallback={block}>\n {/*\n The loading state IS the code block: the fence is already on\n screen, and swapping it for the diagram when the chunk lands\n costs no spinner and no second layout.\n */}\n <Suspense fallback={block}>\n <MermaidFence source={source} fallback={block} />\n </Suspense>\n </DiagramErrorBoundary>\n );\n },\n // A `<span>` is a spoiler's or a highlighted token's, and the only\n // thing that marks a spoiler is the `data-spoiler` property\n // `remarkSpoiler` puts there. `node` is react-markdown's hast node,\n // never an attribute: spread, every token carried\n // `node=\"[object Object]\"`.\n //\n // ⚠️ The cast is not laziness: react-markdown types a span's props\n // as `HTMLAttributes<HTMLSpanElement>`, which PERMITS writing a\n // `data-*` attribute in JSX and does not declare one for reading.\n // The alternative - a custom `hName` with its own `components` key -\n // needs a cast into `components`, whose type is keyed on intrinsic\n // elements, so it buys nothing (the same note `mermaidSource`\n // already carries).\n span: ({ children, node: _node, ...rest }) => {\n const marked = (rest as { \"data-spoiler\"?: unknown })[\n \"data-spoiler\"\n ];\n if (marked) return <SpoilerSpan>{children}</SpoilerSpan>;\n return <span {...rest}>{children}</span>;\n },\n blockquote: ({ children }) => (\n <blockquote className=\"border-muted-foreground/30 my-3 border-s-2 ps-4 italic\">\n {children}\n </blockquote>\n ),\n hr: () => <hr className=\"border-border my-6\" />,\n table: ({ children }) => (\n <table className=\"my-4 border-collapse text-xs\">{children}</table>\n ),\n th: ({ children }) => (\n <th className=\"border-border border px-2 py-1 text-start font-medium\">\n {children}\n </th>\n ),\n td: ({ children }) => (\n <td className=\"border-border border px-2 py-1\">{children}</td>\n ),\n }}\n >\n {props.content}\n </ReactMarkdown>\n </div>\n );\n};\n\n/**\n * The text of a ` ```mermaid ` fence, or `undefined` for every other `<pre>`.\n *\n * Reads the hast node rather than the rendered children because the source\n * has to arrive at the parser exactly as the author typed it, and walking React\n * children would mean reassembling it from whatever the renderer produced.\n *\n * The alternative wiring, a remark plugin, is more code for the same result:\n * `mdast-util-to-hast` applies `data.hName` to the `<code>` element BEFORE\n * wrapping it in `<pre>`, so renaming the code node still leaves the diagram\n * inside this bordered box. Going that way needs a custom node type and a\n * cast into `components`, whose type is keyed on intrinsic elements.\n */\nconst mermaidSource = (node: unknown): string | undefined => {\n const pre = node as\n | {\n children?: Array<{\n type?: string;\n tagName?: string;\n properties?: { className?: unknown };\n children?: Array<{ type?: string; value?: string }>;\n }>;\n }\n | undefined;\n const code = pre?.children?.[0];\n if (code?.type !== \"element\" || code.tagName !== \"code\") return undefined;\n\n const className = code.properties?.className;\n const names = Array.isArray(className)\n ? className.map(String)\n : typeof className === \"string\"\n ? className.split(/\\s+/)\n : [];\n if (!names.includes(\"language-mermaid\")) return undefined;\n\n const text = code.children\n ?.filter((child) => child.type === \"text\")\n .map((child) => child.value ?? \"\")\n .join(\"\");\n return text?.trim() ? text : undefined;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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U,MAAM,SAAS,EAAE,CAAC,CACjC,KAAK,EAAE;CACV,OAAO,MAAM,KAAK,IAAI,OAAO,KAAA;AAC/B"}
|
|
1
|
+
{"version":3,"file":"MarkdownView.js","names":["pre"],"sources":["../../src/markdown/MarkdownView.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport \"./MarkdownView.css\";\nimport { lazy, type ReactNode, Suspense } from \"react\";\nimport ReactMarkdown from \"react-markdown\";\nimport remarkGfm from \"remark-gfm\";\n\nimport { textLinkUnderlineClassName } from \"../core/TextLink.tsx\";\nimport { DiagramErrorBoundary } from \"./diagram/DiagramErrorBoundary.tsx\";\nimport { rehypeHighlight } from \"./rehypeHighlight.ts\";\nimport { remarkSpoiler } from \"./remarkSpoiler.ts\";\nimport { SpoilerSpan } from \"./SpoilerSpan.tsx\";\n\n/**\n * Both parsers, both layouts (`graphre` for the flowchart, arithmetic for\n * the sequence diagram) and both emitters, pulled in ONLY when a document\n * actually contains a mermaid fence.\n *\n * This is the constraint the whole diagram layer exists under: a document\n * with no diagram must pay nothing at all. One with a diagram pays one\n * chunk once, then it is cached. Measured on 2026-08-28 with both diagram\n * types in it: 64.5 kB raw, **22.2 kB gzip**, 19.4 kB brotli - against\n * 17.95 kB gzip when it drew flowcharts only. If it ever passes ~26 kB,\n * split the two pipelines into two chunks so a flowchart-only document\n * stops paying for the sequence one.\n *\n * ⚠️ A lazy import a bundler decides to inline fails silently: the feature\n * still works and the cost moves into the entry chunk. After changing this,\n * build an app that renders a `MarkdownView` (Lore does, in `lore/` in this\n * repository) and confirm, from its directory, that the\n * diagram code is in a chunk of its own and the entry has none of it:\n *\n * yarn alepha build\n * grep -rl 'addBorderSegments\\|sequenceDiagram' dist/public/\n */\nconst MermaidFence = lazy(() => import(\"./diagram/MermaidFence.tsx\"));\n\nexport interface MarkdownViewProps {\n content: string;\n /**\n * Extra classes for the prose root, merged after the defaults so a caller\n * can set its own reading face or measure. The defaults it overrides are\n * `text-sm leading-relaxed`: a surface that sets prose in a display serif\n * needs both, and no parent wrapper can supply them, since they sit on\n * this element rather than being inherited.\n */\n className?: string;\n /**\n * Renders every link instead of the default `<a href>`: an app routes an\n * internal path through its own router link, or leaves a link it does not\n * trust as plain text (an assistant's reply may carry a path that does not\n * exist). Return `children` alone to drop the link.\n */\n renderLink?: MarkdownLinkRenderer;\n /**\n * Renders every image instead of the default `<img src>`: a repository's\n * README points at `logo.png` beside it, which only the app can turn into\n * a URL it serves. Return `null` to drop the image.\n */\n renderImage?: MarkdownImageRenderer;\n}\n\n/**\n * See {@link MarkdownViewProps.renderImage}.\n */\nexport type MarkdownImageRenderer = (image: {\n src?: string;\n alt?: string;\n title?: string;\n}) => ReactNode;\n\n/**\n * See {@link MarkdownViewProps.renderLink}.\n */\nexport type MarkdownLinkRenderer = (link: {\n href?: string;\n children: ReactNode;\n}) => ReactNode;\n\n/**\n * Renders markdown as formatted prose.\n *\n * ## Diagrams\n *\n * A ` ```mermaid ` fence containing a **`flowchart`** or a\n * **`sequenceDiagram`** is drawn as an SVG diagram instead of a code block,\n * themed from the app's own CSS variables so dark mode needs no second\n * palette. The renderer is in-house: only flowchart layout is imported\n * (`graphre`, dagre in TypeScript, ~15.5 kB gzip), and the whole thing is\n * one lazy chunk pulled in only when a document actually contains a fence,\n * so a document with no diagram pays nothing.\n *\n * The flowchart subset is `flowchart TD|TB|LR|RL|BT`; the four node shapes\n * `[rect]` `(rounded)` `{diamond}` `((circle))`, with every other mermaid\n * bracket pair consumed and mapped onto them; edges `-->` `---` `-.->`\n * `==>` `<-->` with labels in both the `-->|text|` and `-- text -->` forms;\n * chains, `&` fans, `<br/>` line breaks and nested `subgraph`.\n *\n * The sequence subset is participants and actors, the eight arrow forms,\n * notes, `autonumber`, self-messages and the `alt` / `else` / `opt` /\n * `loop` fragment boxes. Activation bars are ignored. A wide sequence\n * diagram keeps its natural size in a scroll frame rather than shrinking\n * into the prose column.\n *\n * **Everything else degrades to the code block, silently.**\n * `classDiagram`, `gantt` and mindmaps are not drawn, `style` / `classDef`\n * are ignored, and a parse failure, a refused construct or a diagram past\n * its cap renders the plain fence rather than an error. Agents write\n * invalid mermaid, and a red box in the middle of a document is worse than\n * a grey fence. See `packages/@alepha/ui/DOC.md` for the full table.\n *\n * ## Spoilers\n *\n * `||text||` renders as a covered box that reveals on click, on Enter or on\n * Space, Discord's syntax and Discord's behaviour. Inline markdown inside it\n * survives, a code span or a fence keeps its pipes literally, and an\n * unterminated `||` renders as the two characters the author typed rather\n * than swallowing the rest of the paragraph.\n *\n * ⚠️ **It is not a security feature.** The text is in the DOM from the first\n * paint, in the raw markdown, in an export, over MCP and in any search\n * snippet. It hides a plot point from a reader's eye and nothing more.\n *\n * ## Raw HTML\n *\n * No raw HTML is ever rendered as markup: react-markdown's default is to\n * escape a raw node to text, and this component deliberately mounts no\n * plugin that changes that. A narrow `rehypeSafeImg` plugin used to promote\n * a lone `<img …>` (the one thing MDXEditor emitted for a *resized* image)\n * and was deleted along with the editor that produced it, since nothing\n * writes that markup anymore.\n *\n * Do not reach for `rehype-raw` to bring the capability back: this renders\n * content authored by one user to another, so every raw tag becoming live\n * markup turns every markdown surface in every app into an injection point.\n */\nexport const MarkdownView = (props: MarkdownViewProps) => {\n return (\n <div\n // `data-slot`, matching every other block here, so a host page can\n // reach the prose root without a wrapper class. Lore's folio\n // document uses it to make this inherit the reading size instead\n // of the `text-sm` default below.\n data-slot=\"markdown-view\"\n className={`max-w-none text-sm leading-relaxed ${props.className ?? \"\"}`}\n >\n <ReactMarkdown\n // ⚠️ `remarkSpoiler` runs AFTER `remarkGfm`, and the order is\n // load-bearing: by then a `| a | b |` row is a table with cells, so\n // the pipes are structure and the spoiler walk never sees them as\n // text. Reversed, every two-column table would be a spoiler.\n remarkPlugins={[remarkGfm, remarkSpoiler]}\n rehypePlugins={[\n // `plainText` claims the fence BEFORE highlighting runs: hljs would\n // otherwise tokenise the diagram source, and the fallback would be a\n // soup of spans instead of the text the author wrote.\n //\n // The plugin is the markdown module's own, over lowlight with the\n // fifteen grammars in `HIGHLIGHT_LANGUAGES`: `rehype-highlight`\n // kept all 37 of lowlight's `common` set in the chunk whatever it\n // was given. A fence in any other language renders plain.\n [rehypeHighlight, { detect: true, plainText: [\"mermaid\"] }],\n ]}\n components={{\n h1: ({ children }) => (\n <h1 className=\"mt-6 mb-3 text-2xl font-semibold tracking-tight\">\n {children}\n </h1>\n ),\n h2: ({ children }) => (\n <h2 className=\"mt-6 mb-2 text-xl font-semibold tracking-tight\">\n {children}\n </h2>\n ),\n h3: ({ children }) => (\n <h3 className=\"mt-4 mb-2 text-base font-semibold\">{children}</h3>\n ),\n p: ({ children }) => <p className=\"my-3\">{children}</p>,\n ul: ({ children }) => (\n <ul className=\"my-3 list-disc space-y-1 ps-5\">{children}</ul>\n ),\n ol: ({ children }) => (\n <ol className=\"my-3 list-decimal space-y-1 ps-5\">{children}</ol>\n ),\n li: ({ children }) => <li className=\"ps-1\">{children}</li>,\n a: ({ href, children }) =>\n props.renderLink ? (\n props.renderLink({ href, children })\n ) : (\n <a\n href={href}\n className={`hover:text-foreground font-medium ${textLinkUnderlineClassName}`}\n >\n {children}\n </a>\n ),\n code: ({ children, className }) => {\n const isBlock =\n className?.includes(\"language-\") || className?.includes(\"hljs\");\n if (isBlock) {\n return <code className={`${className} text-xs`}>{children}</code>;\n }\n return (\n <code className=\"bg-muted rounded px-1.5 py-0.5 font-mono text-[0.85em]\">\n {children}\n </code>\n );\n },\n pre: ({ children, node }) => {\n const block = (\n <pre className=\"border-border my-4 overflow-auto rounded-md border bg-transparent p-3 text-xs\">\n {children}\n </pre>\n );\n const source = mermaidSource(node);\n if (!source) return block;\n return (\n <DiagramErrorBoundary fallback={block}>\n {/*\n The loading state IS the code block: the fence is already on\n screen, and swapping it for the diagram when the chunk lands\n costs no spinner and no second layout.\n */}\n <Suspense fallback={block}>\n <MermaidFence source={source} fallback={block} />\n </Suspense>\n </DiagramErrorBoundary>\n );\n },\n // A `<span>` is a spoiler's or a highlighted token's, and the only\n // thing that marks a spoiler is the `data-spoiler` property\n // `remarkSpoiler` puts there. `node` is react-markdown's hast node,\n // never an attribute: spread, every token carried\n // `node=\"[object Object]\"`.\n //\n // ⚠️ The cast is not laziness: react-markdown types a span's props\n // as `HTMLAttributes<HTMLSpanElement>`, which PERMITS writing a\n // `data-*` attribute in JSX and does not declare one for reading.\n // The alternative - a custom `hName` with its own `components` key -\n // needs a cast into `components`, whose type is keyed on intrinsic\n // elements, so it buys nothing (the same note `mermaidSource`\n // already carries).\n span: ({ children, node: _node, ...rest }) => {\n const marked = (rest as { \"data-spoiler\"?: unknown })[\n \"data-spoiler\"\n ];\n if (marked) return <SpoilerSpan>{children}</SpoilerSpan>;\n return <span {...rest}>{children}</span>;\n },\n blockquote: ({ children }) => (\n <blockquote className=\"border-muted-foreground/30 my-3 border-s-2 ps-4 italic\">\n {children}\n </blockquote>\n ),\n hr: () => <hr className=\"border-border my-6\" />,\n img: ({ src, alt, title }) =>\n props.renderImage ? (\n props.renderImage({\n src: typeof src === \"string\" ? src : undefined,\n alt,\n title,\n })\n ) : (\n <img src={src} alt={alt} title={title} className=\"max-w-full\" />\n ),\n // In its own scroll box: a table wider than its column scrolls on\n // its own rather than overflowing the page around it (#Q4546).\n table: ({ children }) => (\n <div className=\"my-4 max-w-full overflow-x-auto\">\n <table className=\"border-collapse text-xs\">{children}</table>\n </div>\n ),\n th: ({ children }) => (\n <th className=\"border-border border px-2 py-1 text-start font-medium\">\n {children}\n </th>\n ),\n td: ({ children }) => (\n <td className=\"border-border border px-2 py-1\">{children}</td>\n ),\n }}\n >\n {props.content}\n </ReactMarkdown>\n </div>\n );\n};\n\n/**\n * The text of a ` ```mermaid ` fence, or `undefined` for every other `<pre>`.\n *\n * Reads the hast node rather than the rendered children because the source\n * has to arrive at the parser exactly as the author typed it, and walking React\n * children would mean reassembling it from whatever the renderer produced.\n *\n * The alternative wiring, a remark plugin, is more code for the same result:\n * `mdast-util-to-hast` applies `data.hName` to the `<code>` element BEFORE\n * wrapping it in `<pre>`, so renaming the code node still leaves the diagram\n * inside this bordered box. Going that way needs a custom node type and a\n * cast into `components`, whose type is keyed on intrinsic elements.\n */\nconst mermaidSource = (node: unknown): string | undefined => {\n const pre = node as\n | {\n children?: Array<{\n type?: string;\n tagName?: string;\n properties?: { className?: unknown };\n children?: Array<{ type?: string; value?: string }>;\n }>;\n }\n | undefined;\n const code = pre?.children?.[0];\n if (code?.type !== \"element\" || code.tagName !== \"code\") return undefined;\n\n const className = code.properties?.className;\n const names = Array.isArray(className)\n ? className.map(String)\n : typeof className === \"string\"\n ? className.split(/\\s+/)\n : [];\n if (!names.includes(\"language-mermaid\")) return undefined;\n\n const text = code.children\n ?.filter((child) => child.type === \"text\")\n .map((child) => child.value ?? \"\")\n .join(\"\");\n return text?.trim() ? text : undefined;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAM,eAAe,WAAW,OAAO,4BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqGpE,MAAa,gBAAgB,UAA6B;CACxD,OACE,oBAAC,OAAD;EAKE,aAAU;EACV,WAAW,sCAAsC,MAAM,aAAa;EAEpE,UAAA,oBAAC,eAAD;GAKE,eAAe,CAAC,WAAW,aAAa;GACxC,eAAe,CASb,CAAC,iBAAiB;IAAE,QAAQ;IAAM,WAAW,CAAC,SAAS;GAAE,CAAC,CAC5D;GACA,YAAY;IACV,KAAK,EAAE,eACL,oBAAC,MAAD;KAAI,WAAU;KACX;IACC,CAAA;IAEN,KAAK,EAAE,eACL,oBAAC,MAAD;KAAI,WAAU;KACX;IACC,CAAA;IAEN,KAAK,EAAE,eACL,oBAAC,MAAD;KAAI,WAAU;KAAqC;IAAa,CAAA;IAElE,IAAI,EAAE,eAAe,oBAAC,KAAD;KAAG,WAAU;KAAQ;IAAY,CAAA;IACtD,KAAK,EAAE,eACL,oBAAC,MAAD;KAAI,WAAU;KAAi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F,CAAC,IAED,oBAAC,OAAD;KAAU;KAAU;KAAY;KAAO,WAAU;IAAc,CAAA;IAInE,QAAQ,EAAE,eACR,oBAAC,OAAD;KAAK,WAAU;KACb,UAAA,oBAAC,SAAD;MAAO,WAAU;MAA2B;KAAgB,CAAA;IACzD,CAAA;IAEP,KAAK,EAAE,eACL,oBAAC,MAAD;KAAI,WAAU;KACX;IACC,CAAA;IAEN,KAAK,EAAE,eACL,oBAAC,MAAD;KAAI,WAAU;KAAkC;IAAa,CAAA;GAEjE;GAEC,UAAA,MAAM;EACM,CAAA;CACZ,CAAA;AAET;;;;;;;;;;;;;;AAeA,MAAM,iBAAiB,SAAsC;CAW3D,MAAM,OAAOA,MAAK,WAAW;CAC7B,IAAI,MAAM,SAAS,aAAa,KAAK,YAAY,QAAQ,OAAO,KAAA;CAEhE,MAAM,YAAY,KAAK,YAAY;CAMnC,IAAI,EALU,MAAM,QAAQ,SAAS,IACjC,UAAU,IAAI,MAAM,IACpB,OAAO,cAAc,WACnB,UAAU,MAAM,KAAK,IACrB,CAAC,EAAA,CACI,SAAS,kBAAkB,GAAG,OAAO,KAAA;CAEhD,MAAM,OAAO,KAAK,UACd,QAAQ,UAAU,MAAM,SAAS,MAAM,CAAC,CACzC,KAAK,UAAU,MAAM,SAAS,EAAE,CAAC,CACjC,KAAK,EAAE;CACV,OAAO,MAAM,KAAK,IAAI,OAAO,KAAA;AAC/B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One piece of a highlighted line: its text, and the highlight.js classes
|
|
3
|
+
* (`hljs-keyword`, ...) of every token it sits in, outermost first.
|
|
4
|
+
*/
|
|
5
|
+
export interface HighlightToken {
|
|
6
|
+
value: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Highlight `text` line by line, with the grammars `MarkdownView` uses
|
|
11
|
+
* ({@link HIGHLIGHT_LANGUAGES}): a code browser or a diff numbers each line
|
|
12
|
+
* and needs its tokens per line, which highlight.js does not give.
|
|
13
|
+
*
|
|
14
|
+
* A token that spans lines (a block comment, a template string) is split at
|
|
15
|
+
* each newline and keeps its classes on every piece, so the second line of a
|
|
16
|
+
* comment is still a comment. A language that is not registered, or none,
|
|
17
|
+
* answers the lines as plain text. Always one entry per line of `text`,
|
|
18
|
+
* the last one empty when it ends with a newline, as `text.split("\n")`.
|
|
19
|
+
*/
|
|
20
|
+
export declare const highlightLines: (text: string, language?: string) => HighlightToken[][];
|
|
21
|
+
/**
|
|
22
|
+
* The highlight.js grammar a file's name asks for, among
|
|
23
|
+
* {@link HIGHLIGHT_LANGUAGES}, or undefined: by extension, and `Dockerfile`
|
|
24
|
+
* and `Makefile`-free names by their own.
|
|
25
|
+
*/
|
|
26
|
+
export declare const highlightLanguageOf: (path: string) => string | undefined;
|
|
27
|
+
//# sourceMappingURL=highlightLines.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlightLines.d.ts","sourceRoot":"","sources":["../../src/markdown/highlightLines.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAcD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,SACnB,MAAM,aACD,MAAM,KAChB,cAAc,EAAE,EA+BlB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,SAAU,MAAM,KAAG,MAAM,GAAG,SAS3D,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { HIGHLIGHT_LANGUAGES } from "./rehypeHighlight.js";
|
|
2
|
+
import { createLowlight } from "lowlight";
|
|
3
|
+
// src/markdown/highlightLines.ts
|
|
4
|
+
let shared;
|
|
5
|
+
/**
|
|
6
|
+
* Highlight `text` line by line, with the grammars `MarkdownView` uses
|
|
7
|
+
* ({@link HIGHLIGHT_LANGUAGES}): a code browser or a diff numbers each line
|
|
8
|
+
* and needs its tokens per line, which highlight.js does not give.
|
|
9
|
+
*
|
|
10
|
+
* A token that spans lines (a block comment, a template string) is split at
|
|
11
|
+
* each newline and keeps its classes on every piece, so the second line of a
|
|
12
|
+
* comment is still a comment. A language that is not registered, or none,
|
|
13
|
+
* answers the lines as plain text. Always one entry per line of `text`,
|
|
14
|
+
* the last one empty when it ends with a newline, as `text.split("\n")`.
|
|
15
|
+
*/
|
|
16
|
+
const highlightLines = (text, language) => {
|
|
17
|
+
shared ??= createLowlight(HIGHLIGHT_LANGUAGES);
|
|
18
|
+
const lines = [[]];
|
|
19
|
+
if (!language || !shared.registered(language)) return text.split("\n").map((line) => line ? [{ value: line }] : []);
|
|
20
|
+
const push = (value, classes) => {
|
|
21
|
+
value.split("\n").forEach((part, index) => {
|
|
22
|
+
if (index > 0) lines.push([]);
|
|
23
|
+
if (!part) return;
|
|
24
|
+
const className = classes.length ? classes.join(" ") : void 0;
|
|
25
|
+
const line = lines[lines.length - 1];
|
|
26
|
+
const last = line[line.length - 1];
|
|
27
|
+
if (last && last.className === className) last.value += part;
|
|
28
|
+
else line.push(className ? {
|
|
29
|
+
value: part,
|
|
30
|
+
className
|
|
31
|
+
} : { value: part });
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const walk = (node, classes) => {
|
|
35
|
+
if (node.type === "text") {
|
|
36
|
+
push(node.value ?? "", classes);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const own = Array.isArray(node.properties?.className) ? node.properties.className.map(String) : [];
|
|
40
|
+
const next = own.length ? [...classes, ...own] : classes;
|
|
41
|
+
for (const child of node.children ?? []) walk(child, next);
|
|
42
|
+
};
|
|
43
|
+
walk(shared.highlight(language, text), []);
|
|
44
|
+
return lines;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The highlight.js grammar a file's name asks for, among
|
|
48
|
+
* {@link HIGHLIGHT_LANGUAGES}, or undefined: by extension, and `Dockerfile`
|
|
49
|
+
* and `Makefile`-free names by their own.
|
|
50
|
+
*/
|
|
51
|
+
const highlightLanguageOf = (path) => {
|
|
52
|
+
const name = path.slice(path.lastIndexOf("/") + 1).toLowerCase();
|
|
53
|
+
if (name === "dockerfile" || name.endsWith(".dockerfile")) return "dockerfile";
|
|
54
|
+
const extension = name.includes(".") ? name.slice(name.lastIndexOf(".") + 1) : "";
|
|
55
|
+
return HIGHLIGHT_EXTENSIONS[extension];
|
|
56
|
+
};
|
|
57
|
+
const HIGHLIGHT_EXTENSIONS = {
|
|
58
|
+
ts: "typescript",
|
|
59
|
+
tsx: "typescript",
|
|
60
|
+
mts: "typescript",
|
|
61
|
+
cts: "typescript",
|
|
62
|
+
js: "javascript",
|
|
63
|
+
jsx: "javascript",
|
|
64
|
+
mjs: "javascript",
|
|
65
|
+
cjs: "javascript",
|
|
66
|
+
json: "json",
|
|
67
|
+
jsonc: "json",
|
|
68
|
+
md: "markdown",
|
|
69
|
+
markdown: "markdown",
|
|
70
|
+
yml: "yaml",
|
|
71
|
+
yaml: "yaml",
|
|
72
|
+
sh: "bash",
|
|
73
|
+
bash: "bash",
|
|
74
|
+
zsh: "bash",
|
|
75
|
+
css: "css",
|
|
76
|
+
html: "xml",
|
|
77
|
+
htm: "xml",
|
|
78
|
+
xml: "xml",
|
|
79
|
+
svg: "xml",
|
|
80
|
+
go: "go",
|
|
81
|
+
rs: "rust",
|
|
82
|
+
py: "python",
|
|
83
|
+
sql: "sql",
|
|
84
|
+
toml: "ini",
|
|
85
|
+
ini: "ini",
|
|
86
|
+
diff: "diff",
|
|
87
|
+
patch: "diff"
|
|
88
|
+
};
|
|
89
|
+
export { highlightLanguageOf, highlightLines };
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=highlightLines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlightLines.js","names":[],"sources":["../../src/markdown/highlightLines.ts"],"sourcesContent":["import { createLowlight } from \"lowlight\";\n\nimport { HIGHLIGHT_LANGUAGES } from \"./rehypeHighlight.ts\";\n\n/**\n * One piece of a highlighted line: its text, and the highlight.js classes\n * (`hljs-keyword`, ...) of every token it sits in, outermost first.\n */\nexport interface HighlightToken {\n value: string;\n className?: string;\n}\n\n/**\n * The subset of a lowlight node this walk reads.\n */\ninterface HastLike {\n type: string;\n value?: string;\n properties?: { className?: unknown };\n children?: HastLike[];\n}\n\nlet shared: ReturnType<typeof createLowlight> | undefined;\n\n/**\n * Highlight `text` line by line, with the grammars `MarkdownView` uses\n * ({@link HIGHLIGHT_LANGUAGES}): a code browser or a diff numbers each line\n * and needs its tokens per line, which highlight.js does not give.\n *\n * A token that spans lines (a block comment, a template string) is split at\n * each newline and keeps its classes on every piece, so the second line of a\n * comment is still a comment. A language that is not registered, or none,\n * answers the lines as plain text. Always one entry per line of `text`,\n * the last one empty when it ends with a newline, as `text.split(\"\\n\")`.\n */\nexport const highlightLines = (\n text: string,\n language?: string,\n): HighlightToken[][] => {\n shared ??= createLowlight(HIGHLIGHT_LANGUAGES);\n const lines: HighlightToken[][] = [[]];\n if (!language || !shared.registered(language)) {\n return text.split(\"\\n\").map((line) => (line ? [{ value: line }] : []));\n }\n const push = (value: string, classes: string[]) => {\n const parts = value.split(\"\\n\");\n parts.forEach((part, index) => {\n if (index > 0) lines.push([]);\n if (!part) return;\n const className = classes.length ? classes.join(\" \") : undefined;\n const line = lines[lines.length - 1]!;\n const last = line[line.length - 1];\n if (last && last.className === className) last.value += part;\n else line.push(className ? { value: part, className } : { value: part });\n });\n };\n const walk = (node: HastLike, classes: string[]) => {\n if (node.type === \"text\") {\n push(node.value ?? \"\", classes);\n return;\n }\n const own = Array.isArray(node.properties?.className)\n ? (node.properties.className as unknown[]).map(String)\n : [];\n const next = own.length ? [...classes, ...own] : classes;\n for (const child of node.children ?? []) walk(child, next);\n };\n walk(shared.highlight(language, text) as unknown as HastLike, []);\n return lines;\n};\n\n/**\n * The highlight.js grammar a file's name asks for, among\n * {@link HIGHLIGHT_LANGUAGES}, or undefined: by extension, and `Dockerfile`\n * and `Makefile`-free names by their own.\n */\nexport const highlightLanguageOf = (path: string): string | undefined => {\n const name = path.slice(path.lastIndexOf(\"/\") + 1).toLowerCase();\n if (name === \"dockerfile\" || name.endsWith(\".dockerfile\")) {\n return \"dockerfile\";\n }\n const extension = name.includes(\".\")\n ? name.slice(name.lastIndexOf(\".\") + 1)\n : \"\";\n return HIGHLIGHT_EXTENSIONS[extension];\n};\n\nconst HIGHLIGHT_EXTENSIONS: Record<string, string> = {\n ts: \"typescript\",\n tsx: \"typescript\",\n mts: \"typescript\",\n cts: \"typescript\",\n js: \"javascript\",\n jsx: \"javascript\",\n mjs: \"javascript\",\n cjs: \"javascript\",\n json: \"json\",\n jsonc: \"json\",\n md: \"markdown\",\n markdown: \"markdown\",\n yml: \"yaml\",\n yaml: \"yaml\",\n sh: \"bash\",\n bash: \"bash\",\n zsh: \"bash\",\n css: \"css\",\n html: \"xml\",\n htm: \"xml\",\n xml: \"xml\",\n svg: \"xml\",\n go: \"go\",\n rs: \"rust\",\n py: \"python\",\n sql: \"sql\",\n toml: \"ini\",\n ini: \"ini\",\n diff: \"diff\",\n patch: \"diff\",\n};\n"],"mappings":";;;AAuBA,IAAI;;;;;;;;;;;;AAaJ,MAAa,kBACX,MACA,aACuB;CACvB,WAAW,eAAe,mBAAmB;CAC7C,MAAM,QAA4B,CAAC,CAAC,CAAC;CACrC,IAAI,CAAC,YAAY,CAAC,OAAO,WAAW,QAAQ,GAC1C,OAAO,KAAK,MAAM,IAAI,CAAC,CAAC,KAAK,SAAU,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,CAAE;CAEvE,MAAM,QAAQ,OAAe,YAAsB;EACnC,MAAM,MAAM,IACtB,CAAC,CAAC,SAAS,MAAM,UAAU;GAC7B,IAAI,QAAQ,GAAG,MAAM,KAAK,CAAC,CAAC;GAC5B,IAAI,CAAC,MAAM;GACX,MAAM,YAAY,QAAQ,SAAS,QAAQ,KAAK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ACJ,IAAI;CACJ,KAAK;CACL,MAAM;CACN,KAAK;CACL,MAAM;CACN,OAAO;AACT"}
|
package/dist/markdown/index.d.ts
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* Markdown rendered as prose, with diagrams.
|
|
3
3
|
*
|
|
4
4
|
* `MarkdownView` renders GitHub-flavoured markdown with highlighted code, and
|
|
5
|
-
* draws `flowchart` and `sequenceDiagram` fences as SVG. `
|
|
5
|
+
* draws `flowchart` and `sequenceDiagram` fences as SVG. `highlightLines`
|
|
6
|
+
* highlights a whole file line by line with the same grammars, for a code
|
|
7
|
+
* view that numbers its lines. `diagramKind`,
|
|
6
8
|
* `parseFlowchart` and `parseSequence` expose the parsers, so an editor can
|
|
7
9
|
* validate a diagram before it is saved.
|
|
8
10
|
*
|
|
@@ -14,5 +16,6 @@
|
|
|
14
16
|
export { diagramKind } from "./diagram/diagramKind.ts";
|
|
15
17
|
export { parseFlowchart } from "./diagram/flowchartParser.ts";
|
|
16
18
|
export { parseSequence } from "./diagram/sequenceParser.ts";
|
|
17
|
-
export {
|
|
19
|
+
export { type HighlightToken, highlightLanguageOf, highlightLines, } from "./highlightLines.ts";
|
|
20
|
+
export { type MarkdownImageRenderer, type MarkdownLinkRenderer, MarkdownView, type MarkdownViewProps, } from "./MarkdownView.tsx";
|
|
18
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,KAAK,cAAc,EACnB,mBAAmB,EACnB,cAAc,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,YAAY,EACZ,KAAK,iBAAiB,GACvB,MAAM,oBAAoB,CAAC"}
|
package/dist/markdown/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { diagramKind } from "./diagram/diagramKind.js";
|
|
2
2
|
import { parseFlowchart } from "./diagram/flowchartParser.js";
|
|
3
3
|
import { parseSequence } from "./diagram/sequenceParser.js";
|
|
4
|
+
import { highlightLanguageOf, highlightLines } from "./highlightLines.js";
|
|
4
5
|
import { MarkdownView } from "./MarkdownView.js";
|
|
5
|
-
export { MarkdownView, diagramKind, parseFlowchart, parseSequence };
|
|
6
|
+
export { MarkdownView, diagramKind, highlightLanguageOf, highlightLines, parseFlowchart, parseSequence };
|
|
@@ -42,6 +42,14 @@ export interface ButtonInboxProps {
|
|
|
42
42
|
* app passes its own push.
|
|
43
43
|
*/
|
|
44
44
|
onOpen?: (href: string) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Called once the server has marked messages read from this dropdown: after
|
|
47
|
+
* "Mark all read", and after a clicked row was marked read. The bell keeps
|
|
48
|
+
* its own count, but a host showing unread counts elsewhere (per scope, in
|
|
49
|
+
* a sidebar) has no other way to learn they went stale, so it refreshes
|
|
50
|
+
* them here. Not called when a write is refused.
|
|
51
|
+
*/
|
|
52
|
+
onRead?: () => void;
|
|
45
53
|
}
|
|
46
54
|
/**
|
|
47
55
|
* The bell: an unread count, and the most recent messages behind it.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ButtonInbox.d.ts","sourceRoot":"","sources":["../../src/shell/ButtonInbox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAwB/B,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE,MAAM,CA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,6 +65,7 @@ const ButtonInbox = (props) => {
|
|
|
65
65
|
if (!row.readAt) try {
|
|
66
66
|
await api.markInboxRead({ params: { id: row.id } });
|
|
67
67
|
setUnread({ count: Math.max(0, unread.count - 1) });
|
|
68
|
+
props.onRead?.();
|
|
68
69
|
} catch {}
|
|
69
70
|
if (props.onOpen || isNavigable(row.href)) navigate(props, row.href);
|
|
70
71
|
};
|
|
@@ -75,7 +76,8 @@ const ButtonInbox = (props) => {
|
|
|
75
76
|
...it,
|
|
76
77
|
readAt: it.readAt ?? "read"
|
|
77
78
|
})));
|
|
78
|
-
|
|
79
|
+
props.onRead?.();
|
|
80
|
+
} }, [api, props.onRead]);
|
|
79
81
|
if (!available) return null;
|
|
80
82
|
const label = props.labels?.inbox ?? "Notifications";
|
|
81
83
|
const count = unread.count;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ButtonInbox.js","names":[],"sources":["../../src/shell/ButtonInbox.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport type { NotificationInboxController } from \"alepha/api/notifications\";\nimport { DateTimeProvider } from \"alepha/datetime\";\nimport { useAction, useClient, useInject, useStore } from \"alepha/react\";\nimport { Bell } from \"lucide-react\";\nimport { useCallback, useEffect, useState } from \"react\";\n\nimport { Button } from \"../core/Button.tsx\";\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuGroup,\n DropdownMenuItem,\n DropdownMenuLabel,\n DropdownMenuSeparator,\n DropdownMenuTrigger,\n} from \"../core/DropdownMenu.tsx\";\nimport { Tooltip, TooltipContent, TooltipTrigger } from \"../core/Tooltip.tsx\";\nimport { cn } from \"../core/utils.ts\";\nimport { inboxUnreadAtom } from \"./inboxUnreadAtom.ts\";\n\nexport interface ButtonInboxProps {\n /**\n * Where \"See all\" goes. `@alepha/ui` cannot know an application's routes,\n * so the destination is the surface's to decide; the footer is hidden when\n * it is absent.\n *\n * ⚠️ It should point at the **unfiltered** list. This dropdown lists\n * messages from every scope, so a footer landing on a filtered view shows\n * fewer rows than the menu it was clicked out of.\n */\n seeAllHref?: string;\n /**\n * How many messages the dropdown lists. Five is the shape the design\n * settled on: enough to recognise what happened, short enough to read\n * without scrolling.\n */\n limit?: number;\n /**\n * Labels, for an application that localises its chrome. Each falls back to\n * its English default.\n *\n * They are this component's own props rather than entries in a shared\n * cluster's `labels` bag, because the surface that mounts the bell is the\n * one that has a translator in hand.\n */\n labels?: {\n /**\n * The trigger's `aria-label` and tooltip. Defaults to `\"Notifications\"`.\n */\n inbox?: string;\n heading?: string;\n empty?: string;\n markAllRead?: string;\n seeAll?: string;\n };\n variant?: \"minimal\" | \"outlined\";\n /**\n * Called with the message's `href` when a row is clicked, after it has\n * been marked read. Defaults to a full navigation, which is correct for an\n * app with no router in scope and wrong for one that has it - so a router\n * app passes its own push.\n */\n onOpen?: (href: string) => void;\n}\n\ninterface InboxRow {\n id: string;\n title: string;\n href: string;\n createdAt: string;\n readAt?: string;\n scopeLabel?: string;\n}\n\n/**\n * The bell: an unread count, and the most recent messages behind it.\n *\n * ## It decides for itself whether it has anything to offer\n *\n * `countInbox.can()` is the gate, and it is a **registry lookup, not a\n * request**: `/api/_links` carries only the actions the server actually\n * registered, and it prunes every `$secure()` one for an anonymous caller.\n * So this renders nothing both when the app has not registered\n * `alepha/api/notifications` and when nobody is signed in, with no 404 fired\n * on every page load. `AccountDialog` gates its five sections the same way.\n *\n * ## ⚠️ The scope chip is a label the message carries, never a parsed scope\n *\n * `scope` is an app-owned opaque string (`project:65`) and this component has\n * no way to turn one into a name - nor should it learn. The message carries\n * `scopeLabel`, written by whoever pushed it and frozen at that moment. Null\n * means no chip.\n */\nexport const ButtonInbox = (props: ButtonInboxProps) => {\n const api = useClient<NotificationInboxController>();\n const dt = useInject(DateTimeProvider);\n const [unread, setUnread] = useStore(inboxUnreadAtom);\n const [items, setItems] = useState<InboxRow[]>([]);\n\n const available = api.countInbox.can();\n const limit = props.limit ?? 5;\n\n const refreshCount = useCallback(async () => {\n if (!available) return;\n try {\n const result = await api.countInbox({ query: {} });\n setUnread({ count: result.unread });\n } catch {\n // A bell that throws takes the header with it. A count nobody could\n // read is zero, and the badge disappears.\n setUnread({ count: 0 });\n }\n }, [api, available]);\n\n useEffect(() => {\n if (!available) return;\n // A fallback, not the primary read: a host whose route loader already\n // seeded the atom has a count before the first paint, and this only\n // covers the case where that call failed or never ran.\n if (unread.count === 0) {\n void refreshCount();\n }\n // Staleness, not coverage. A message arriving while somebody sits on one\n // page is invisible until they navigate, and this is the only thing that\n // changes that.\n const onFocus = () => void refreshCount();\n window.addEventListener(\"focus\", onFocus);\n return () => window.removeEventListener(\"focus\", onFocus);\n }, [available, refreshCount]);\n\n const load = async () => {\n if (!available) return;\n try {\n const page = await api.listInbox({ query: { limit } });\n setItems(page.items as InboxRow[]);\n setUnread({ count: page.unreadCount });\n } catch {\n setItems([]);\n }\n };\n\n const open = async (row: InboxRow) => {\n if (!row.readAt) {\n try {\n await api.markInboxRead({ params: { id: row.id } });\n setUnread({ count: Math.max(0, unread.count - 1) });\n } catch {\n // Opening the message matters more than recording that it was read.\n }\n }\n // The full navigation follows only a same-origin path or an http(s) URL.\n // The href was written at send time, possibly from a sender's variables,\n // and a `javascript:` one would run on the app's origin.\n if (props.onOpen || isNavigable(row.href)) {\n navigate(props, row.href);\n }\n };\n\n // Through `useAction`, so a refused write leaves the badge and the rows as\n // they were and reaches `react:action:error` (and a mounted\n // `ActionErrorToaster`) instead of becoming an unhandled rejection.\n const markAllRead = useAction(\n {\n handler: async () => {\n await api.markAllInboxRead({ query: {} });\n setUnread({ count: 0 });\n setItems((current) =>\n current.map((it) => ({ ...it, readAt: it.readAt ?? \"read\" })),\n );\n },\n },\n [api],\n );\n\n if (!available) {\n return null;\n }\n\n const label = props.labels?.inbox ?? \"Notifications\";\n const count = unread.count;\n\n return (\n <DropdownMenu onOpenChange={(next) => next && void load()}>\n <Tooltip>\n <TooltipTrigger\n render={\n <DropdownMenuTrigger\n render={\n <Button\n variant={props.variant ?? \"minimal\"}\n size=\"icon\"\n aria-label={label}\n className=\"relative\"\n />\n }\n />\n }\n >\n <Bell className=\"size-4\" />\n {count > 0 && (\n // Filled and in the destructive colour, not a subtle dot: the\n // whole point of the control is that an unread message is not\n // easy to miss.\n <span\n data-testid=\"inbox-badge\"\n className=\"bg-danger text-danger-foreground absolute -end-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[10px] leading-none font-medium\"\n >\n {count > 99 ? \"99+\" : count}\n </span>\n )}\n </TooltipTrigger>\n <TooltipContent>{label}</TooltipContent>\n </Tooltip>\n <DropdownMenuContent align=\"end\" className=\"w-80\">\n <DropdownMenuGroup>\n {/*\n The header is chrome, not a row: `bg-muted` under the `--bevel`\n line, the pair `PlateTabBar` and the table header use, closed by\n a border line below. Pulled out over the content's `p-1` so it\n runs edge to edge; the rounded, overflow-clipped popover trims\n its corners. The border replaces the separator that used to sit\n under it, which would have drawn a second line.\n */}\n <DropdownMenuLabel\n data-testid=\"inbox-header\"\n className=\"text-foreground chrome chrome-closed -mx-1 -mt-1 mb-1 flex items-center justify-between gap-2 px-2.5 py-2\"\n >\n <span>{props.labels?.heading ?? \"Notifications\"}</span>\n {count > 0 && (\n <button\n type=\"button\"\n className=\"text-muted-foreground hover:text-foreground text-xs font-normal\"\n onClick={(event) => {\n // The menu must not close: marking read is a change to what\n // is on screen, and the reader is still reading it.\n event.preventDefault();\n event.stopPropagation();\n void markAllRead.run();\n }}\n >\n {props.labels?.markAllRead ?? \"Mark all read\"}\n </button>\n )}\n </DropdownMenuLabel>\n {items.length === 0 ? (\n <p className=\"text-muted-foreground px-2 py-6 text-center text-sm\">\n {props.labels?.empty ?? \"Nothing new\"}\n </p>\n ) : (\n items.map((row) => (\n <DropdownMenuItem\n key={row.id}\n className=\"flex flex-col items-start gap-0.5\"\n onClick={() => void open(row)}\n >\n <span className=\"flex w-full items-center gap-2\">\n {!row.readAt && (\n <span\n data-testid=\"inbox-unread-dot\"\n className=\"bg-primary size-1.5 shrink-0 rounded-full\"\n />\n )}\n <span\n className={cn(\n \"flex-1 truncate text-sm\",\n !row.readAt && \"font-medium\",\n )}\n >\n {row.title}\n </span>\n </span>\n <span className=\"text-muted-foreground flex w-full items-center gap-2 text-xs\">\n <span>{dt.of(row.createdAt).fromNow()}</span>\n {row.scopeLabel && (\n <span className=\"bg-muted ms-auto rounded px-1.5 py-0.5\">\n {row.scopeLabel}\n </span>\n )}\n </span>\n </DropdownMenuItem>\n ))\n )}\n {props.seeAllHref && (\n <>\n <DropdownMenuSeparator />\n <DropdownMenuItem\n onClick={() => navigate(props, props.seeAllHref!)}\n className=\"justify-center text-sm\"\n >\n {props.labels?.seeAll ?? \"See all\"}\n </DropdownMenuItem>\n </>\n )}\n </DropdownMenuGroup>\n </DropdownMenuContent>\n </DropdownMenu>\n );\n};\n\n/**\n * Follow a message's destination.\n *\n * `onOpen` is what a router app passes; without one this is a full\n * navigation, which is correct for a host that has no router in scope.\n * `assign()` rather than writing `location.href`, because the href is not a\n * variable this component owns.\n */\nconst navigate = (props: ButtonInboxProps, href: string): void => {\n if (props.onOpen) {\n props.onOpen(href);\n return;\n }\n if (typeof window !== \"undefined\") {\n window.location.assign(href);\n }\n};\n\n/**\n * A same-origin path (`/x`, not the protocol-relative `//host` nor `/\\host`,\n * which a browser reads the same way) or an http(s) URL.\n */\nconst isNavigable = (href: string): boolean =>\n /^\\/(?![/\\\\])/.test(href) || /^https?:\\/\\//i.test(href);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiGA,MAAa,eAAe,UAA4B;CACtD,MAAM,MAAM,UAAuC;CACnD,MAAM,KAAK,UAAU,gBAAgB;CACrC,MAAM,CAAC,QAAQ,aAAa,SAAS,eAAe;CACpD,MAAM,CAAC,OAAO,YAAY,SAAqB,CAAC,CAAC;CAEjD,MAAM,YAAY,IAAI,WAAW,IAAI;CACrC,MAAM,QAAQ,MAAM,SAAS;CAE7B,MAAM,eAAe,YAAY,YAAY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CACG,CAAC,IAAI,UACJ,oBAAC,QAAD;OACE,eAAY;OACZ,WAAU;MACX,CAAA,GAEH,oBAAC,QAAD;OACE,WAAW,GACT,2BACA,CAAC,IAAI,UAAU,aACjB;OAEC,UAAA,IAAI;MACD,CAAA,CACF;KACN,CAAA,GAAA,qBAAC,QAAD;MAAM,WAAU;MAAhB,UAAA,CACE,oBAAC,QAAD,EAAA,UAAO,GAAG,GAAG,IAAI,SAAS,CAAC,CAAC,QAAQ,EAAQ,CAAA,GAC3C,IAAI,cACH,oBAAC,QAAD;OAAM,WAAU;OACb,UAAA,IAAI;MACD,CAAA,CAEJ;KACU,CAAA,CAAA;IA5BX,GAAA,IAAI,EA4BO,CACnB;IAEF,MAAM,cACL,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,uBAAD,CAAwB,CAAA,GACxB,oBAAC,kBAAD;KACE,eAAe,SAAS,OAAO,MAAM,UAAW;KAChD,WAAU;KAET,UAAA,MAAM,QAAQ,UAAU;IACT,CAAA,CAClB,EAAA,CAAA;GAEa,EAAA,CAAA;EACA,CAAA,CACT;;AAElB;;;;;;;;;AAUA,MAAM,YAAY,OAAyB,SAAuB;CAChE,IAAI,MAAM,QAAQ;EAChB,MAAM,OAAO,IAAI;EACjB;CACF;CACA,IAAI,OAAO,WAAW,aACpB,OAAO,SAAS,OAAO,IAAI;AAE/B;;;;;AAMA,MAAM,eAAe,SACnB,eAAe,KAAK,IAAI,KAAK,gBAAgB,KAAK,IAAI"}
|
|
1
|
+
{"version":3,"file":"ButtonInbox.js","names":[],"sources":["../../src/shell/ButtonInbox.tsx"],"sourcesContent":["import * as React from \"react\";\n\nvoid React;\n\nimport type { NotificationInboxController } from \"alepha/api/notifications\";\nimport { DateTimeProvider } from \"alepha/datetime\";\nimport { useAction, useClient, useInject, useStore } from \"alepha/react\";\nimport { Bell } from \"lucide-react\";\nimport { useCallback, useEffect, useState } from \"react\";\n\nimport { Button } from \"../core/Button.tsx\";\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuGroup,\n DropdownMenuItem,\n DropdownMenuLabel,\n DropdownMenuSeparator,\n DropdownMenuTrigger,\n} from \"../core/DropdownMenu.tsx\";\nimport { Tooltip, TooltipContent, TooltipTrigger } from \"../core/Tooltip.tsx\";\nimport { cn } from \"../core/utils.ts\";\nimport { inboxUnreadAtom } from \"./inboxUnreadAtom.ts\";\n\nexport interface ButtonInboxProps {\n /**\n * Where \"See all\" goes. `@alepha/ui` cannot know an application's routes,\n * so the destination is the surface's to decide; the footer is hidden when\n * it is absent.\n *\n * ⚠️ It should point at the **unfiltered** list. This dropdown lists\n * messages from every scope, so a footer landing on a filtered view shows\n * fewer rows than the menu it was clicked out of.\n */\n seeAllHref?: string;\n /**\n * How many messages the dropdown lists. Five is the shape the design\n * settled on: enough to recognise what happened, short enough to read\n * without scrolling.\n */\n limit?: number;\n /**\n * Labels, for an application that localises its chrome. Each falls back to\n * its English default.\n *\n * They are this component's own props rather than entries in a shared\n * cluster's `labels` bag, because the surface that mounts the bell is the\n * one that has a translator in hand.\n */\n labels?: {\n /**\n * The trigger's `aria-label` and tooltip. Defaults to `\"Notifications\"`.\n */\n inbox?: string;\n heading?: string;\n empty?: string;\n markAllRead?: string;\n seeAll?: string;\n };\n variant?: \"minimal\" | \"outlined\";\n /**\n * Called with the message's `href` when a row is clicked, after it has\n * been marked read. Defaults to a full navigation, which is correct for an\n * app with no router in scope and wrong for one that has it - so a router\n * app passes its own push.\n */\n onOpen?: (href: string) => void;\n /**\n * Called once the server has marked messages read from this dropdown: after\n * \"Mark all read\", and after a clicked row was marked read. The bell keeps\n * its own count, but a host showing unread counts elsewhere (per scope, in\n * a sidebar) has no other way to learn they went stale, so it refreshes\n * them here. Not called when a write is refused.\n */\n onRead?: () => void;\n}\n\ninterface InboxRow {\n id: string;\n title: string;\n href: string;\n createdAt: string;\n readAt?: string;\n scopeLabel?: string;\n}\n\n/**\n * The bell: an unread count, and the most recent messages behind it.\n *\n * ## It decides for itself whether it has anything to offer\n *\n * `countInbox.can()` is the gate, and it is a **registry lookup, not a\n * request**: `/api/_links` carries only the actions the server actually\n * registered, and it prunes every `$secure()` one for an anonymous caller.\n * So this renders nothing both when the app has not registered\n * `alepha/api/notifications` and when nobody is signed in, with no 404 fired\n * on every page load. `AccountDialog` gates its five sections the same way.\n *\n * ## ⚠️ The scope chip is a label the message carries, never a parsed scope\n *\n * `scope` is an app-owned opaque string (`project:65`) and this component has\n * no way to turn one into a name - nor should it learn. The message carries\n * `scopeLabel`, written by whoever pushed it and frozen at that moment. Null\n * means no chip.\n */\nexport const ButtonInbox = (props: ButtonInboxProps) => {\n const api = useClient<NotificationInboxController>();\n const dt = useInject(DateTimeProvider);\n const [unread, setUnread] = useStore(inboxUnreadAtom);\n const [items, setItems] = useState<InboxRow[]>([]);\n\n const available = api.countInbox.can();\n const limit = props.limit ?? 5;\n\n const refreshCount = useCallback(async () => {\n if (!available) return;\n try {\n const result = await api.countInbox({ query: {} });\n setUnread({ count: result.unread });\n } catch {\n // A bell that throws takes the header with it. A count nobody could\n // read is zero, and the badge disappears.\n setUnread({ count: 0 });\n }\n }, [api, available]);\n\n useEffect(() => {\n if (!available) return;\n // A fallback, not the primary read: a host whose route loader already\n // seeded the atom has a count before the first paint, and this only\n // covers the case where that call failed or never ran.\n if (unread.count === 0) {\n void refreshCount();\n }\n // Staleness, not coverage. A message arriving while somebody sits on one\n // page is invisible until they navigate, and this is the only thing that\n // changes that.\n const onFocus = () => void refreshCount();\n window.addEventListener(\"focus\", onFocus);\n return () => window.removeEventListener(\"focus\", onFocus);\n }, [available, refreshCount]);\n\n const load = async () => {\n if (!available) return;\n try {\n const page = await api.listInbox({ query: { limit } });\n setItems(page.items as InboxRow[]);\n setUnread({ count: page.unreadCount });\n } catch {\n setItems([]);\n }\n };\n\n const open = async (row: InboxRow) => {\n if (!row.readAt) {\n try {\n await api.markInboxRead({ params: { id: row.id } });\n setUnread({ count: Math.max(0, unread.count - 1) });\n props.onRead?.();\n } catch {\n // Opening the message matters more than recording that it was read.\n }\n }\n // The full navigation follows only a same-origin path or an http(s) URL.\n // The href was written at send time, possibly from a sender's variables,\n // and a `javascript:` one would run on the app's origin.\n if (props.onOpen || isNavigable(row.href)) {\n navigate(props, row.href);\n }\n };\n\n // Through `useAction`, so a refused write leaves the badge and the rows as\n // they were and reaches `react:action:error` (and a mounted\n // `ActionErrorToaster`) instead of becoming an unhandled rejection.\n const markAllRead = useAction(\n {\n handler: async () => {\n await api.markAllInboxRead({ query: {} });\n setUnread({ count: 0 });\n setItems((current) =>\n current.map((it) => ({ ...it, readAt: it.readAt ?? \"read\" })),\n );\n props.onRead?.();\n },\n },\n [api, props.onRead],\n );\n\n if (!available) {\n return null;\n }\n\n const label = props.labels?.inbox ?? \"Notifications\";\n const count = unread.count;\n\n return (\n <DropdownMenu onOpenChange={(next) => next && void load()}>\n <Tooltip>\n <TooltipTrigger\n render={\n <DropdownMenuTrigger\n render={\n <Button\n variant={props.variant ?? \"minimal\"}\n size=\"icon\"\n aria-label={label}\n className=\"relative\"\n />\n }\n />\n }\n >\n <Bell className=\"size-4\" />\n {count > 0 && (\n // Filled and in the destructive colour, not a subtle dot: the\n // whole point of the control is that an unread message is not\n // easy to miss.\n <span\n data-testid=\"inbox-badge\"\n className=\"bg-danger text-danger-foreground absolute -end-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[10px] leading-none font-medium\"\n >\n {count > 99 ? \"99+\" : count}\n </span>\n )}\n </TooltipTrigger>\n <TooltipContent>{label}</TooltipContent>\n </Tooltip>\n <DropdownMenuContent align=\"end\" className=\"w-80\">\n <DropdownMenuGroup>\n {/*\n The header is chrome, not a row: `bg-muted` under the `--bevel`\n line, the pair `PlateTabBar` and the table header use, closed by\n a border line below. Pulled out over the content's `p-1` so it\n runs edge to edge; the rounded, overflow-clipped popover trims\n its corners. The border replaces the separator that used to sit\n under it, which would have drawn a second line.\n */}\n <DropdownMenuLabel\n data-testid=\"inbox-header\"\n className=\"text-foreground chrome chrome-closed -mx-1 -mt-1 mb-1 flex items-center justify-between gap-2 px-2.5 py-2\"\n >\n <span>{props.labels?.heading ?? \"Notifications\"}</span>\n {count > 0 && (\n <button\n type=\"button\"\n className=\"text-muted-foreground hover:text-foreground text-xs font-normal\"\n onClick={(event) => {\n // The menu must not close: marking read is a change to what\n // is on screen, and the reader is still reading it.\n event.preventDefault();\n event.stopPropagation();\n void markAllRead.run();\n }}\n >\n {props.labels?.markAllRead ?? \"Mark all read\"}\n </button>\n )}\n </DropdownMenuLabel>\n {items.length === 0 ? (\n <p className=\"text-muted-foreground px-2 py-6 text-center text-sm\">\n {props.labels?.empty ?? \"Nothing new\"}\n </p>\n ) : (\n items.map((row) => (\n <DropdownMenuItem\n key={row.id}\n className=\"flex flex-col items-start gap-0.5\"\n onClick={() => void open(row)}\n >\n <span className=\"flex w-full items-center gap-2\">\n {!row.readAt && (\n <span\n data-testid=\"inbox-unread-dot\"\n className=\"bg-primary size-1.5 shrink-0 rounded-full\"\n />\n )}\n <span\n className={cn(\n \"flex-1 truncate text-sm\",\n !row.readAt && \"font-medium\",\n )}\n >\n {row.title}\n </span>\n </span>\n <span className=\"text-muted-foreground flex w-full items-center gap-2 text-xs\">\n <span>{dt.of(row.createdAt).fromNow()}</span>\n {row.scopeLabel && (\n <span className=\"bg-muted ms-auto rounded px-1.5 py-0.5\">\n {row.scopeLabel}\n </span>\n )}\n </span>\n </DropdownMenuItem>\n ))\n )}\n {props.seeAllHref && (\n <>\n <DropdownMenuSeparator />\n <DropdownMenuItem\n onClick={() => navigate(props, props.seeAllHref!)}\n className=\"justify-center text-sm\"\n >\n {props.labels?.seeAll ?? \"See all\"}\n </DropdownMenuItem>\n </>\n )}\n </DropdownMenuGroup>\n </DropdownMenuContent>\n </DropdownMenu>\n );\n};\n\n/**\n * Follow a message's destination.\n *\n * `onOpen` is what a router app passes; without one this is a full\n * navigation, which is correct for a host that has no router in scope.\n * `assign()` rather than writing `location.href`, because the href is not a\n * variable this component owns.\n */\nconst navigate = (props: ButtonInboxProps, href: string): void => {\n if (props.onOpen) {\n props.onOpen(href);\n return;\n }\n if (typeof window !== \"undefined\") {\n window.location.assign(href);\n }\n};\n\n/**\n * A same-origin path (`/x`, not the protocol-relative `//host` nor `/\\host`,\n * which a browser reads the same way) or an http(s) URL.\n */\nconst isNavigable = (href: string): boolean =>\n /^\\/(?![/\\\\])/.test(href) || /^https?:\\/\\//i.test(href);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,MAAa,eAAe,UAA4B;CACtD,MAAM,MAAM,UAAuC;CACnD,MAAM,KAAK,UAAU,gBAAgB;CACrC,MAAM,CAAC,QAAQ,aAAa,SAAS,eAAe;CACpD,MAAM,CAAC,OAAO,YAAY,SAAqB,CAAC,CAAC;CAEjD,MAAM,YAAY,IAAI,WAAW,IAAI;CACrC,MAAM,QAAQ,MAAM,SAAS;CAE7B,MAAM,eAAe,YAAY,YAAY;EAC3C,IAAI,CAAC,WAAW;EAChB,IAAI;GACF,MAAM,SAAS,MAAM,IAAI,WAAW,EAAE,OAAO,CAAC,EAAE,CAAC;GACjD,UAAU,EAAE,OAAO,OAAO,OAAO,CAAC;EACpC,QAAQ;GAGN,UAAU,EAAE,OAAO,EAAE,CAAC;EACxB;CACF,GAAG,CAAC,KAAK,SAAS,CAAC;CAEnB,gBAAgB;EACd,IAAI,CAAC,WAAW;EAIhB,IAAI,OAAO,UAAU,GACd,aAAa;EAKpB,MAAM,gBAAgB,KAAK,aAAa;EACxC,OAAO,iBAAiB,SAAS,OAAO;EACxC,aAAa,OAAO,oBAAoB,SAAS,OAAO;CAC1D,GAAG,CAAC,WAAW,YAAY,CAAC;CAE5B,MAAM,OAAO,YAAY;EACvB,IAAI,CAAC,WAAW;EAChB,IAAI;GACF,MAAM,OAAO,MAAM,IAAI,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;GACrD,SAAS,KAAK,KAAmB;GACjC,UAAU,EAAE,OAAO,KAAK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,MAAM,QAAQ,UAAU;IACT,CAAA,CAClB,EAAA,CAAA;GAEa,EAAA,CAAA;EACA,CAAA,CACT;;AAElB;;;;;;;;;AAUA,MAAM,YAAY,OAAyB,SAAuB;CAChE,IAAI,MAAM,QAAQ;EAChB,MAAM,OAAO,IAAI;EACjB;CACF;CACA,IAAI,OAAO,WAAW,aACpB,OAAO,SAAS,OAAO,IAAI;AAE/B;;;;;AAMA,MAAM,eAAe,SACnB,eAAe,KAAK,IAAI,KAAK,gBAAgB,KAAK,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlateLayout.d.ts","sourceRoot":"","sources":["../../src/shell/PlateLayout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,OAAO,EAAE,KAAK,QAAQ,EAAe,MAAM,mBAAmB,CAAC;AAE/D,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC;IACrC;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,UAAW,gBAAgB,
|
|
1
|
+
{"version":3,"file":"PlateLayout.d.ts","sourceRoot":"","sources":["../../src/shell/PlateLayout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,OAAO,EAAE,KAAK,QAAQ,EAAe,MAAM,mBAAmB,CAAC;AAE/D,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC;IACrC;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,UAAW,gBAAgB,gCAwHlD,CAAC"}
|
|
@@ -64,11 +64,11 @@ const PlateLayout = (props) => /* @__PURE__ */ jsxs("div", {
|
|
|
64
64
|
}) : null]
|
|
65
65
|
})]
|
|
66
66
|
}), props.scroll === false ? /* @__PURE__ */ jsx("div", {
|
|
67
|
-
className: "
|
|
67
|
+
className: cn("flex min-h-0 flex-1 flex-col", props.tabsVariant === "underline" ? "bg-card" : "bg-background"),
|
|
68
68
|
children: props.children
|
|
69
69
|
}) : /* @__PURE__ */ jsx("div", {
|
|
70
70
|
tabIndex: 0,
|
|
71
|
-
className: cn("focus-visible:ring-ring/50 min-h-0 flex-1 overflow-y-auto outline-none focus-visible:ring-[3px] focus-visible:ring-inset", props.tabsVariant === "underline" ? "bg-muted" : "bg-
|
|
71
|
+
className: cn("focus-visible:ring-ring/50 min-h-0 flex-1 overflow-y-auto outline-none focus-visible:ring-[3px] focus-visible:ring-inset", props.tabsVariant === "underline" ? "bg-muted" : "bg-background"),
|
|
72
72
|
children: props.children
|
|
73
73
|
})]
|
|
74
74
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlateLayout.js","names":[],"sources":["../../src/shell/PlateLayout.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\n\nimport { cn } from \"../core/utils.ts\";\nimport { PlateFolderTabs } from \"./PlateFolderTabs.tsx\";\nimport { type PlateTab, PlateTabBar } from \"./PlateTabBar.tsx\";\n\nexport interface PlateLayoutProps {\n /**\n * The band above the tabs: what this page IS. A title, the two or three\n * facts true on every tab, and the actions that act on the whole thing.\n *\n * A slot rather than props, because there is no shape common to a release's\n * tag and progress bar, a project's reporting period and an enrolled app's\n * address. What the layout owns is the band, not its contents.\n *\n * Optional, and genuinely so since feedback #2095: a page whose plate would\n * only reprint what the breadcrumb leaf already says is better without one.\n * Omitting it also drops the tab bar's top rule, which exists to separate\n * the tabs from the plate and has nothing to separate them from otherwise.\n */\n plate?: ReactNode;\n tabs: PlateTab[];\n /**\n * The active tab's `key`. For a router-driven bar, the current route name.\n */\n active: string;\n onSelect?: (key: string) => void;\n /**\n * Marks the tab bar for tests. See {@link PlateTabBarProps.testId}.\n */\n tabsTestId?: string;\n /**\n * Small actions at the end of the tab band, on the tabs' line: what\n * applies to the page whichever tab is open, such as an export or an\n * import: small minimal buttons (`size=\"sm\"`), and the page's main\n * action last, as a small primary button.\n */\n tabsActions?: ReactNode;\n /**\n * How the tabs are drawn. `folder`, the default, is a band of tiles, the\n * active one opening into the body below it, like a browser's tabs;\n * `underline` is a plain bottom row with an underline under the active\n * tab.\n *\n * @default \"folder\"\n */\n tabsVariant?: \"underline\" | \"folder\";\n /**\n * Whether the layout wraps the body in its own scroll region. Default\n * `true`, which is what keeps the plate still while the content moves.\n *\n * Pass `false` for a tab that owns its scrolling - one with a sticky\n * toolbar of its own, or a reading measure it has to centre. Nesting a\n * scroll region inside a scroll region gives it two.\n */\n scroll?: boolean;\n children: ReactNode;\n className?: string;\n}\n\n/**\n * A full-width plate over a tab strip, and a body that scrolls under both.\n *\n * Lifted from Lore's Release view, which is the shape it names: a page whose\n * identity is several facts wide, with sections that are big enough to be\n * their own view. Distinct from the resource view's left panel and segmented\n * tabs, which is for a page whose identity is one line and whose sections are\n * fields.\n *\n * Deliberately NOT a router: a tab may be a route (`href` on the tab) or a\n * panel swap (`onSelect`), and the layout does not care which. That is what\n * lets Reports and an app's page - which are real nested routes - and the\n * Release view - which is one route with a `?tab=` - share it.\n */\nexport const PlateLayout = (props: PlateLayoutProps) => (\n <div\n className={cn(\n \"flex min-h-0 w-full flex-1 flex-col overflow-hidden\",\n props.className,\n )}\n >\n <div\n data-slot=\"plate-band\"\n className={cn(\n // Solid `bg-card`, not a `/30` tint: a tint over the page is the\n // page's black in dark mode. In light it is the same white.\n \"bg-card border-border shrink-0\",\n // Folder tabs end on their own ruled strip (below), so only the\n // underline variant takes the band's bottom border.\n props.tabsVariant === \"underline\" && \"border-b\",\n )}\n >\n {props.plate}\n {props.tabsVariant !== \"underline\" ? (\n // The actions sit beside the strip, never in it: the strip is a\n // `tablist`, which holds tabs only. They carry the band's bottom\n // line on, so the band reads as one.\n <>\n <div className=\"flex items-stretch\">\n <PlateFolderTabs\n testId={props.tabsTestId}\n className=\"min-w-0 flex-1 rounded-none border-x-0 border-t-0 bg-transparent px-4\"\n tabs={props.tabs.map((tab) => ({\n key: tab.key,\n label: tab.label,\n icon: tab.icon,\n count: tab.count,\n href: tab.href,\n prefetch: tab.prefetch,\n active: tab.key === props.active,\n onSelect:\n tab.href === undefined\n ? () => props.onSelect?.(tab.key)\n : undefined,\n }))}\n />\n {props.tabsActions ? (\n <div\n data-slot=\"plate-tabs-actions\"\n className=\"flex shrink-0 items-center gap-1.5 px-3 pt-1.5 shadow-[inset_0_-1px_0_0_var(--border)]\"\n >\n {props.tabsActions}\n </div>\n ) : null}\n </div>\n {/*\n A thin strip in the active tile's fill, ruled at its foot: the\n tile opens into it with no seam
|
|
1
|
+
{"version":3,"file":"PlateLayout.js","names":[],"sources":["../../src/shell/PlateLayout.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\n\nimport { cn } from \"../core/utils.ts\";\nimport { PlateFolderTabs } from \"./PlateFolderTabs.tsx\";\nimport { type PlateTab, PlateTabBar } from \"./PlateTabBar.tsx\";\n\nexport interface PlateLayoutProps {\n /**\n * The band above the tabs: what this page IS. A title, the two or three\n * facts true on every tab, and the actions that act on the whole thing.\n *\n * A slot rather than props, because there is no shape common to a release's\n * tag and progress bar, a project's reporting period and an enrolled app's\n * address. What the layout owns is the band, not its contents.\n *\n * Optional, and genuinely so since feedback #2095: a page whose plate would\n * only reprint what the breadcrumb leaf already says is better without one.\n * Omitting it also drops the tab bar's top rule, which exists to separate\n * the tabs from the plate and has nothing to separate them from otherwise.\n */\n plate?: ReactNode;\n tabs: PlateTab[];\n /**\n * The active tab's `key`. For a router-driven bar, the current route name.\n */\n active: string;\n onSelect?: (key: string) => void;\n /**\n * Marks the tab bar for tests. See {@link PlateTabBarProps.testId}.\n */\n tabsTestId?: string;\n /**\n * Small actions at the end of the tab band, on the tabs' line: what\n * applies to the page whichever tab is open, such as an export or an\n * import: small minimal buttons (`size=\"sm\"`), and the page's main\n * action last, as a small primary button.\n */\n tabsActions?: ReactNode;\n /**\n * How the tabs are drawn. `folder`, the default, is a band of tiles, the\n * active one opening into the body below it, like a browser's tabs;\n * `underline` is a plain bottom row with an underline under the active\n * tab.\n *\n * @default \"folder\"\n */\n tabsVariant?: \"underline\" | \"folder\";\n /**\n * Whether the layout wraps the body in its own scroll region. Default\n * `true`, which is what keeps the plate still while the content moves.\n *\n * Pass `false` for a tab that owns its scrolling - one with a sticky\n * toolbar of its own, or a reading measure it has to centre. Nesting a\n * scroll region inside a scroll region gives it two.\n */\n scroll?: boolean;\n children: ReactNode;\n className?: string;\n}\n\n/**\n * A full-width plate over a tab strip, and a body that scrolls under both.\n *\n * Lifted from Lore's Release view, which is the shape it names: a page whose\n * identity is several facts wide, with sections that are big enough to be\n * their own view. Distinct from the resource view's left panel and segmented\n * tabs, which is for a page whose identity is one line and whose sections are\n * fields.\n *\n * Deliberately NOT a router: a tab may be a route (`href` on the tab) or a\n * panel swap (`onSelect`), and the layout does not care which. That is what\n * lets Reports and an app's page - which are real nested routes - and the\n * Release view - which is one route with a `?tab=` - share it.\n */\nexport const PlateLayout = (props: PlateLayoutProps) => (\n <div\n className={cn(\n \"flex min-h-0 w-full flex-1 flex-col overflow-hidden\",\n props.className,\n )}\n >\n <div\n data-slot=\"plate-band\"\n className={cn(\n // Solid `bg-card`, not a `/30` tint: a tint over the page is the\n // page's black in dark mode. In light it is the same white.\n \"bg-card border-border shrink-0\",\n // Folder tabs end on their own ruled strip (below), so only the\n // underline variant takes the band's bottom border.\n props.tabsVariant === \"underline\" && \"border-b\",\n )}\n >\n {props.plate}\n {props.tabsVariant !== \"underline\" ? (\n // The actions sit beside the strip, never in it: the strip is a\n // `tablist`, which holds tabs only. They carry the band's bottom\n // line on, so the band reads as one.\n <>\n <div className=\"flex items-stretch\">\n <PlateFolderTabs\n testId={props.tabsTestId}\n className=\"min-w-0 flex-1 rounded-none border-x-0 border-t-0 bg-transparent px-4\"\n tabs={props.tabs.map((tab) => ({\n key: tab.key,\n label: tab.label,\n icon: tab.icon,\n count: tab.count,\n href: tab.href,\n prefetch: tab.prefetch,\n active: tab.key === props.active,\n onSelect:\n tab.href === undefined\n ? () => props.onSelect?.(tab.key)\n : undefined,\n }))}\n />\n {props.tabsActions ? (\n <div\n data-slot=\"plate-tabs-actions\"\n className=\"flex shrink-0 items-center gap-1.5 px-3 pt-1.5 shadow-[inset_0_-1px_0_0_var(--border)]\"\n >\n {props.tabsActions}\n </div>\n ) : null}\n </div>\n {/*\n A thin strip in the active tile's fill, ruled at its foot: the\n tile opens into it with no seam. The body below takes the shell\n header's fill, `bg-background`, so header, band and body read as\n one surface and the cards inside stand out from it. It replaced a\n body filled grey to match the tile, which made every tab a grey\n page, and then a `bg-card` body, lighter than the header in dark.\n */}\n <div\n aria-hidden\n data-slot=\"plate-tabs-strip\"\n className=\"bg-muted h-2 border-b\"\n />\n </>\n ) : (\n <div className=\"flex items-center\">\n <div className=\"min-w-0 flex-1\">\n <PlateTabBar\n tabs={props.tabs}\n active={props.active}\n onSelect={props.onSelect}\n testId={props.tabsTestId}\n divided={props.plate !== undefined}\n />\n </div>\n {props.tabsActions ? (\n <div\n data-slot=\"plate-tabs-actions\"\n className=\"flex shrink-0 items-center gap-1.5 px-3\"\n >\n {props.tabsActions}\n </div>\n ) : null}\n </div>\n )}\n </div>\n\n {props.scroll === false ? (\n // A body that owns its scroll is a page of content under a toolbar of\n // its own. Opaque, never transparent: without a fill the shell behind\n // it shows through. Under folder tabs it takes the header's fill, like\n // the scrolling body below.\n <div\n className={cn(\n \"flex min-h-0 flex-1 flex-col\",\n props.tabsVariant === \"underline\" ? \"bg-card\" : \"bg-background\",\n )}\n >\n {props.children}\n </div>\n ) : (\n // Focusable, so a keyboard can scroll it when nothing inside it takes\n // focus (axe `scrollable-region-focusable`, WCAG 2.1.1).\n <div\n // oxlint-disable-next-line jsx-a11y/no-noninteractive-tabindex -- a scroll region must take focus for the keyboard to scroll it (WCAG 2.1.1); the lint rule does not know scroll containers\n tabIndex={0}\n // Folder tabs end on their grey strip, and the body under it takes\n // the shell header's fill, `bg-background`, so the page reads as one\n // surface with its cards on top. Underline tabs have no tile and keep\n // the flat fill.\n className={cn(\n \"focus-visible:ring-ring/50 min-h-0 flex-1 overflow-y-auto outline-none focus-visible:ring-[3px] focus-visible:ring-inset\",\n props.tabsVariant === \"underline\" ? \"bg-muted\" : \"bg-background\",\n )}\n >\n {props.children}\n </div>\n )}\n </div>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0EA,MAAa,eAAe,UAC1B,qBAAC,OAAD;CACE,WAAW,GACT,uDACA,MAAM,SACR;CAJF,UAAA,CAME,q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nD;EAEC,UAAA,MAAM;CACJ,CAAA,CAEJ"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sortable lists, on `@dnd-kit`.
|
|
3
|
+
*
|
|
4
|
+
* `useSortableList` holds a vertical list reordered by dragging (pointer or
|
|
5
|
+
* touch) or from the keyboard: the order shown between a drop and the
|
|
6
|
+
* server's answer, the drop index, a vertical-only modifier, and the keyboard
|
|
7
|
+
* move (Space picks up, the arrows move, Space or Enter drops, Escape puts
|
|
8
|
+
* back) with its screen-reader announcements. `useSortableItem` is one item
|
|
9
|
+
* of it. The look and the save stay the app's. Opt-in: nothing else in
|
|
10
|
+
* `@alepha/ui` imports it, so `@dnd-kit` loads only with it.
|
|
11
|
+
*
|
|
12
|
+
* @module alepha.ui.sortable
|
|
13
|
+
*/
|
|
14
|
+
export { DndContext } from "@dnd-kit/core";
|
|
15
|
+
export { type SortableItem, useSortableItem } from "./useSortableItem.ts";
|
|
16
|
+
export { type SortableList, type SortableListAnnouncements, type UseSortableListOptions, useSortableList, } from "./useSortableList.ts";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sortable/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,KAAK,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC3B,eAAe,GAChB,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type UniqueIdentifier } from "@dnd-kit/core";
|
|
2
|
+
import type { CSSProperties, PointerEvent } from "react";
|
|
3
|
+
export interface SortableItem {
|
|
4
|
+
/**
|
|
5
|
+
* The item's element: what moves, and what another item is dropped on.
|
|
6
|
+
*/
|
|
7
|
+
ref: (node: HTMLElement | null) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Where the item is while dragged.
|
|
10
|
+
*/
|
|
11
|
+
style: CSSProperties;
|
|
12
|
+
/**
|
|
13
|
+
* The drag's start, for the element a press begins on: the item itself,
|
|
14
|
+
* in the capture phase so a control inside it (a menu trigger) cannot
|
|
15
|
+
* swallow the press, or a grip of its own.
|
|
16
|
+
*/
|
|
17
|
+
onPointerDown: ((event: PointerEvent<HTMLElement>) => void) | undefined;
|
|
18
|
+
isDragging: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Another item is held over this one: where a drop lands.
|
|
21
|
+
*/
|
|
22
|
+
isOver: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* One item of a {@link useSortableList}: the element both dragged and dropped
|
|
26
|
+
* on, and only the pointer listener of `@dnd-kit`. The keyboard move is the
|
|
27
|
+
* list's own (`onKeyDown`), on whichever element of the item takes focus.
|
|
28
|
+
*/
|
|
29
|
+
export declare const useSortableItem: (id: UniqueIdentifier, options?: {
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
}) => SortableItem;
|
|
32
|
+
//# sourceMappingURL=useSortableItem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSortableItem.d.ts","sourceRoot":"","sources":["../../src/sortable/useSortableItem.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAEzD,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,GAAG,EAAE,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAC;IACxC;;OAEG;IACH,KAAK,EAAE,aAAa,CAAC;IACrB;;;;OAIG;IACH,aAAa,EAAE,CAAC,CAAC,KAAK,EAAE,YAAY,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACxE,UAAU,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,OACtB,gBAAgB,YACX;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,KAC9B,YA0BF,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useDraggable, useDroppable } from "@dnd-kit/core";
|
|
2
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
3
|
+
// src/sortable/useSortableItem.ts
|
|
4
|
+
/**
|
|
5
|
+
* One item of a {@link useSortableList}: the element both dragged and dropped
|
|
6
|
+
* on, and only the pointer listener of `@dnd-kit`. The keyboard move is the
|
|
7
|
+
* list's own (`onKeyDown`), on whichever element of the item takes focus.
|
|
8
|
+
*/
|
|
9
|
+
const useSortableItem = (id, options = {}) => {
|
|
10
|
+
const disabled = !!options.disabled;
|
|
11
|
+
const { listeners, setNodeRef: setDragRef, transform, isDragging } = useDraggable({
|
|
12
|
+
id,
|
|
13
|
+
disabled
|
|
14
|
+
});
|
|
15
|
+
const { setNodeRef: setDropRef, isOver } = useDroppable({
|
|
16
|
+
id,
|
|
17
|
+
disabled
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
ref: (node) => {
|
|
21
|
+
setDragRef(node);
|
|
22
|
+
setDropRef(node);
|
|
23
|
+
},
|
|
24
|
+
style: {
|
|
25
|
+
transform: CSS.Translate.toString(transform),
|
|
26
|
+
zIndex: isDragging ? 10 : void 0
|
|
27
|
+
},
|
|
28
|
+
onPointerDown: disabled ? void 0 : listeners?.onPointerDown,
|
|
29
|
+
isDragging,
|
|
30
|
+
isOver: isOver && !isDragging
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export { useSortableItem };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=useSortableItem.js.map
|