@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.
Files changed (187) hide show
  1. package/README.md +4 -2
  2. package/dist/admin/AdminJobExecutionSheet.d.ts.map +1 -1
  3. package/dist/admin/AdminJobExecutionSheet.js +7 -0
  4. package/dist/admin/AdminJobExecutionSheet.js.map +1 -1
  5. package/dist/admin/analytics/RequestDialog.js +1 -1
  6. package/dist/admin/analytics/RequestDialog.js.map +1 -1
  7. package/dist/ai/AiChat.d.ts +6 -3
  8. package/dist/ai/AiChat.d.ts.map +1 -1
  9. package/dist/ai/AiChat.js +34 -5
  10. package/dist/ai/AiChat.js.map +1 -1
  11. package/dist/ai/AiChatConfirmCard.d.ts.map +1 -1
  12. package/dist/ai/AiChatConfirmCard.js +5 -1
  13. package/dist/ai/AiChatConfirmCard.js.map +1 -1
  14. package/dist/ai/AiChatFloat.d.ts +14 -0
  15. package/dist/ai/AiChatFloat.d.ts.map +1 -0
  16. package/dist/ai/AiChatFloat.js +30 -0
  17. package/dist/ai/AiChatFloat.js.map +1 -0
  18. package/dist/ai/AiChatMessage.js +2 -2
  19. package/dist/ai/AiChatMessage.js.map +1 -1
  20. package/dist/ai/AiChatPanel.d.ts +19 -0
  21. package/dist/ai/AiChatPanel.d.ts.map +1 -1
  22. package/dist/ai/AiChatPanel.js +65 -19
  23. package/dist/ai/AiChatPanel.js.map +1 -1
  24. package/dist/ai/AiChatToolStepDetails.d.ts +14 -0
  25. package/dist/ai/AiChatToolStepDetails.d.ts.map +1 -0
  26. package/dist/ai/AiChatToolStepDetails.js +34 -0
  27. package/dist/ai/AiChatToolStepDetails.js.map +1 -0
  28. package/dist/ai/AiChatToolTrace.d.ts +50 -0
  29. package/dist/ai/AiChatToolTrace.d.ts.map +1 -0
  30. package/dist/ai/AiChatToolTrace.js +91 -0
  31. package/dist/ai/AiChatToolTrace.js.map +1 -0
  32. package/dist/ai/index.d.ts +4 -2
  33. package/dist/ai/index.d.ts.map +1 -1
  34. package/dist/ai/index.js +3 -1
  35. package/dist/core/Button.d.ts.map +1 -1
  36. package/dist/core/Button.js +17 -1
  37. package/dist/core/Button.js.map +1 -1
  38. package/dist/core/Dialog.d.ts.map +1 -1
  39. package/dist/core/Dialog.js +1 -1
  40. package/dist/core/Dialog.js.map +1 -1
  41. package/dist/core/TimeAgo.d.ts +3 -4
  42. package/dist/core/TimeAgo.d.ts.map +1 -1
  43. package/dist/core/TimeAgo.js +3 -4
  44. package/dist/core/TimeAgo.js.map +1 -1
  45. package/dist/i18n/en/index.d.ts +22 -0
  46. package/dist/i18n/en/index.d.ts.map +1 -0
  47. package/dist/i18n/en/index.js +1 -0
  48. package/dist/i18n/en/uiEn.d.ts +37 -0
  49. package/dist/i18n/en/uiEn.d.ts.map +1 -0
  50. package/dist/i18n/en/uiEn.js +1468 -0
  51. package/dist/i18n/en/uiEn.js.map +1 -0
  52. package/dist/i18n/fr/uiFr.d.ts +3 -2
  53. package/dist/i18n/fr/uiFr.d.ts.map +1 -1
  54. package/dist/i18n/fr/uiFr.js +7 -2
  55. package/dist/i18n/fr/uiFr.js.map +1 -1
  56. package/dist/markdown/MarkdownView.d.ts +14 -0
  57. package/dist/markdown/MarkdownView.d.ts.map +1 -1
  58. package/dist/markdown/MarkdownView.js +16 -3
  59. package/dist/markdown/MarkdownView.js.map +1 -1
  60. package/dist/markdown/highlightLines.d.ts +27 -0
  61. package/dist/markdown/highlightLines.d.ts.map +1 -0
  62. package/dist/markdown/highlightLines.js +91 -0
  63. package/dist/markdown/highlightLines.js.map +1 -0
  64. package/dist/markdown/index.d.ts +5 -2
  65. package/dist/markdown/index.d.ts.map +1 -1
  66. package/dist/markdown/index.js +2 -1
  67. package/dist/shell/ButtonInbox.d.ts +8 -0
  68. package/dist/shell/ButtonInbox.d.ts.map +1 -1
  69. package/dist/shell/ButtonInbox.js +3 -1
  70. package/dist/shell/ButtonInbox.js.map +1 -1
  71. package/dist/shell/PlateLayout.d.ts.map +1 -1
  72. package/dist/shell/PlateLayout.js +2 -2
  73. package/dist/shell/PlateLayout.js.map +1 -1
  74. package/dist/sortable/index.d.ts +17 -0
  75. package/dist/sortable/index.d.ts.map +1 -0
  76. package/dist/sortable/index.js +4 -0
  77. package/dist/sortable/useSortableItem.d.ts +32 -0
  78. package/dist/sortable/useSortableItem.d.ts.map +1 -0
  79. package/dist/sortable/useSortableItem.js +35 -0
  80. package/dist/sortable/useSortableItem.js.map +1 -0
  81. package/dist/sortable/useSortableList.d.ts +85 -0
  82. package/dist/sortable/useSortableList.d.ts.map +1 -0
  83. package/dist/sortable/useSortableList.js +125 -0
  84. package/dist/sortable/useSortableList.js.map +1 -0
  85. package/dist/table/DataTable.d.ts.map +1 -1
  86. package/dist/table/DataTable.js +9 -6
  87. package/dist/table/DataTable.js.map +1 -1
  88. package/dist/table/DataTableRowActionGroupItem.d.ts +23 -0
  89. package/dist/table/DataTableRowActionGroupItem.d.ts.map +1 -0
  90. package/dist/table/DataTableRowActionGroupItem.js +38 -0
  91. package/dist/table/DataTableRowActionGroupItem.js.map +1 -0
  92. package/dist/table/DataTableRowActionItem.d.ts.map +1 -1
  93. package/dist/table/DataTableRowActionItem.js +15 -2
  94. package/dist/table/DataTableRowActionItem.js.map +1 -1
  95. package/dist/table/DataTableRowActionsInline.d.ts.map +1 -1
  96. package/dist/table/DataTableRowActionsInline.js +2 -1
  97. package/dist/table/DataTableRowActionsInline.js.map +1 -1
  98. package/dist/table/DataTableRowActionsMenu.d.ts +3 -2
  99. package/dist/table/DataTableRowActionsMenu.d.ts.map +1 -1
  100. package/dist/table/DataTableRowActionsMenu.js +12 -14
  101. package/dist/table/DataTableRowActionsMenu.js.map +1 -1
  102. package/dist/table/dataTableBaseProps.d.ts +16 -2
  103. package/dist/table/dataTableBaseProps.d.ts.map +1 -1
  104. package/dist/table/dataTablePersistence.d.ts +53 -11
  105. package/dist/table/dataTablePersistence.d.ts.map +1 -1
  106. package/dist/table/dataTablePersistence.js +66 -29
  107. package/dist/table/dataTablePersistence.js.map +1 -1
  108. package/dist/table/dataTableTypes.d.ts +20 -3
  109. package/dist/table/dataTableTypes.d.ts.map +1 -1
  110. package/dist/table/index.d.ts +8 -1
  111. package/dist/table/index.d.ts.map +1 -1
  112. package/dist/table/index.js +2 -1
  113. package/dist/table/useDataTableColumns.d.ts.map +1 -1
  114. package/dist/table/useDataTableColumns.js +4 -4
  115. package/dist/table/useDataTableColumns.js.map +1 -1
  116. package/dist/table/useDataTableData.d.ts.map +1 -1
  117. package/dist/table/useDataTableData.js +3 -3
  118. package/dist/table/useDataTableData.js.map +1 -1
  119. package/dist/table/useDataTableFilterForm.d.ts.map +1 -1
  120. package/dist/table/useDataTableFilterForm.js +6 -2
  121. package/dist/table/useDataTableFilterForm.js.map +1 -1
  122. package/dist/table/useDataTableFilterVisibility.d.ts +5 -0
  123. package/dist/table/useDataTableFilterVisibility.d.ts.map +1 -1
  124. package/dist/table/useDataTableFilterVisibility.js +16 -8
  125. package/dist/table/useDataTableFilterVisibility.js.map +1 -1
  126. package/dist/table/useDataTableRefresh.d.ts.map +1 -1
  127. package/dist/table/useDataTableRefresh.js +3 -2
  128. package/dist/table/useDataTableRefresh.js.map +1 -1
  129. package/dist/table/useDataTableSummary.d.ts +5 -0
  130. package/dist/table/useDataTableSummary.d.ts.map +1 -1
  131. package/dist/table/useDataTableSummary.js +6 -6
  132. package/dist/table/useDataTableSummary.js.map +1 -1
  133. package/docs/packages-alepha-ui-ai.md +3 -3
  134. package/docs/packages-alepha-ui-i18n-en.md +35 -0
  135. package/docs/packages-alepha-ui-markdown.md +3 -1
  136. package/docs/packages-alepha-ui-overview.md +4 -2
  137. package/docs/packages-alepha-ui-sortable.md +34 -0
  138. package/docs/packages-alepha-ui-table.md +7 -1
  139. package/package.json +21 -3
  140. package/src/admin/AdminJobExecutionSheet.tsx +9 -0
  141. package/src/admin/analytics/RequestDialog.tsx +1 -1
  142. package/src/ai/AiChat.tsx +44 -6
  143. package/src/ai/AiChatConfirmCard.tsx +7 -1
  144. package/src/ai/AiChatFloat.tsx +46 -0
  145. package/src/ai/AiChatMessage.tsx +2 -2
  146. package/src/ai/AiChatPanel.tsx +154 -47
  147. package/src/ai/AiChatToolStepDetails.tsx +42 -0
  148. package/src/ai/AiChatToolTrace.tsx +167 -0
  149. package/src/ai/__tests__/AiChat.browser.spec.tsx +270 -2
  150. package/src/ai/index.ts +4 -2
  151. package/src/core/Button.tsx +26 -1
  152. package/src/core/Dialog.tsx +6 -2
  153. package/src/core/TimeAgo.tsx +3 -4
  154. package/src/core/__tests__/Button.browser.spec.tsx +57 -0
  155. package/src/i18n/en/__tests__/uiEn.spec.ts +110 -0
  156. package/src/i18n/en/index.ts +22 -0
  157. package/src/i18n/en/uiEn.ts +1647 -0
  158. package/src/i18n/fr/uiFr.ts +7 -2
  159. package/src/markdown/MarkdownView.tsx +30 -1
  160. package/src/markdown/__tests__/highlightLines.spec.ts +45 -0
  161. package/src/markdown/highlightLines.ts +120 -0
  162. package/src/markdown/index.ts +14 -2
  163. package/src/shell/ButtonInbox.tsx +11 -1
  164. package/src/shell/PlateLayout.tsx +18 -9
  165. package/src/shell/__tests__/ButtonInbox.browser.spec.tsx +40 -0
  166. package/src/shell/__tests__/PlateLayout.browser.spec.tsx +19 -2
  167. package/src/sortable/__tests__/useSortableList.browser.spec.tsx +157 -0
  168. package/src/sortable/index.ts +22 -0
  169. package/src/sortable/useSortableItem.ts +65 -0
  170. package/src/sortable/useSortableList.ts +231 -0
  171. package/src/table/DataTable.tsx +8 -5
  172. package/src/table/DataTableRowActionGroupItem.tsx +75 -0
  173. package/src/table/DataTableRowActionItem.tsx +6 -0
  174. package/src/table/DataTableRowActionsInline.tsx +3 -1
  175. package/src/table/DataTableRowActionsMenu.tsx +33 -49
  176. package/src/table/__tests__/DataTablePersistenceStorage.browser.spec.tsx +204 -0
  177. package/src/table/__tests__/DataTableRowActionGroup.browser.spec.tsx +118 -1
  178. package/src/table/dataTableBaseProps.ts +16 -2
  179. package/src/table/dataTablePersistence.ts +118 -32
  180. package/src/table/dataTableTypes.ts +20 -3
  181. package/src/table/index.ts +14 -1
  182. package/src/table/useDataTableColumns.ts +9 -4
  183. package/src/table/useDataTableData.ts +8 -3
  184. package/src/table/useDataTableFilterForm.ts +6 -2
  185. package/src/table/useDataTableFilterVisibility.ts +20 -7
  186. package/src/table/useDataTableRefresh.ts +4 -2
  187. package/src/table/useDataTableSummary.ts +25 -8
@@ -41,8 +41,9 @@ import type { DictionaryEntry } from "alepha/react/i18n";
41
41
  * sample and not a catalogue. Keys interpolate with `$1`, `$2` … positionally,
42
42
  * matching the `args` each call site passes.
43
43
  *
44
- * A second language means a sibling file; there is deliberately no `uiEn`, since
45
- * the components already default to English.
44
+ * A second language means a sibling file. `uiEn` (`@alepha/ui/i18n/en`) is
45
+ * one: the components default to English, but an application whose
46
+ * `fallbackLang` is `fr` reads a key missing from its `en` catalogue here.
46
47
  */
47
48
  export const uiFr: Record<string, DictionaryEntry> = {
48
49
  // The assistant (`@alepha/ui/ai`), in a drawer or a dock.
@@ -61,6 +62,8 @@ export const uiFr: Record<string, DictionaryEntry> = {
61
62
  "ai.chat.history": "Historique",
62
63
  "ai.chat.message": "Message",
63
64
  "ai.chat.minimize": "Réduire",
65
+ "ai.chat.fullscreen": "Plein écran",
66
+ "ai.chat.exitFullscreen": "Quitter le plein écran",
64
67
  "ai.chat.new": "Nouvelle conversation",
65
68
  "ai.chat.noHistory": "Aucune conversation pour l'instant",
66
69
  "ai.chat.placeholder": "Demandez à l'assistant",
@@ -73,6 +76,7 @@ export const uiFr: Record<string, DictionaryEntry> = {
73
76
  "ai.chat.title": "Assistant",
74
77
  "ai.chat.toolDenied": "$1 annulé",
75
78
  "ai.chat.toolDone": "$1 exécuté",
79
+ "ai.chat.toolsUsed": "$1 outils utilisés",
76
80
  "ai.chat.toolFailed": "Échec de $1",
77
81
  "ai.chat.untitled": "Conversation sans titre",
78
82
  "ai.chat.waiting": "Confirmez ou annulez la carte pour continuer",
@@ -653,6 +657,7 @@ export const uiFr: Record<string, DictionaryEntry> = {
653
657
  "admin.jobs.originApp": "Application",
654
658
  "admin.jobs.originSystem": "Système",
655
659
  "admin.jobs.payloadTitle": "Charge utile",
660
+ "admin.jobs.resultTitle": "Résultat",
656
661
  "admin.jobs.retention.days": "$1 jours",
657
662
  "admin.jobs.statsTitle": "Dernières 24 heures",
658
663
  "admin.jobs.statsError": "Échecs",
@@ -54,8 +54,23 @@ export interface MarkdownViewProps {
54
54
  * exist). Return `children` alone to drop the link.
55
55
  */
56
56
  renderLink?: MarkdownLinkRenderer;
57
+ /**
58
+ * Renders every image instead of the default `<img src>`: a repository's
59
+ * README points at `logo.png` beside it, which only the app can turn into
60
+ * a URL it serves. Return `null` to drop the image.
61
+ */
62
+ renderImage?: MarkdownImageRenderer;
57
63
  }
58
64
 
65
+ /**
66
+ * See {@link MarkdownViewProps.renderImage}.
67
+ */
68
+ export type MarkdownImageRenderer = (image: {
69
+ src?: string;
70
+ alt?: string;
71
+ title?: string;
72
+ }) => ReactNode;
73
+
59
74
  /**
60
75
  * See {@link MarkdownViewProps.renderLink}.
61
76
  */
@@ -240,8 +255,22 @@ export const MarkdownView = (props: MarkdownViewProps) => {
240
255
  </blockquote>
241
256
  ),
242
257
  hr: () => <hr className="border-border my-6" />,
258
+ img: ({ src, alt, title }) =>
259
+ props.renderImage ? (
260
+ props.renderImage({
261
+ src: typeof src === "string" ? src : undefined,
262
+ alt,
263
+ title,
264
+ })
265
+ ) : (
266
+ <img src={src} alt={alt} title={title} className="max-w-full" />
267
+ ),
268
+ // In its own scroll box: a table wider than its column scrolls on
269
+ // its own rather than overflowing the page around it (#Q4546).
243
270
  table: ({ children }) => (
244
- <table className="my-4 border-collapse text-xs">{children}</table>
271
+ <div className="my-4 max-w-full overflow-x-auto">
272
+ <table className="border-collapse text-xs">{children}</table>
273
+ </div>
245
274
  ),
246
275
  th: ({ children }) => (
247
276
  <th className="border-border border px-2 py-1 text-start font-medium">
@@ -0,0 +1,45 @@
1
+ import { describe, it } from "vitest";
2
+
3
+ import { highlightLanguageOf, highlightLines } from "../highlightLines.ts";
4
+
5
+ describe("highlightLines", () => {
6
+ it("answers one entry per line, a multi-line comment classed on every line", ({
7
+ expect,
8
+ }) => {
9
+ const lines = highlightLines(
10
+ "const a = 1;\n/* one\ntwo */\nlet b = `x\ny`;\n",
11
+ "typescript",
12
+ );
13
+ expect(lines).toHaveLength(6);
14
+ expect(lines[0]?.[0]).toEqual({
15
+ value: "const",
16
+ className: "hljs-keyword",
17
+ });
18
+ expect(lines[1]).toEqual([{ value: "/* one", className: "hljs-comment" }]);
19
+ expect(lines[2]).toEqual([{ value: "two */", className: "hljs-comment" }]);
20
+ expect(lines[4]?.find((it) => it.value.includes("y`"))?.className).toBe(
21
+ "hljs-string",
22
+ );
23
+ expect(lines[5]).toEqual([]);
24
+ expect(
25
+ lines.map((line) => line.map((it) => it.value).join("")).join("\n"),
26
+ ).toBe("const a = 1;\n/* one\ntwo */\nlet b = `x\ny`;\n");
27
+ });
28
+
29
+ it("answers plain lines for an unknown language or none", ({ expect }) => {
30
+ expect(highlightLines("a\n\nb", "cobol")).toEqual([
31
+ [{ value: "a" }],
32
+ [],
33
+ [{ value: "b" }],
34
+ ]);
35
+ expect(highlightLines("a", undefined)).toEqual([[{ value: "a" }]]);
36
+ });
37
+
38
+ it("names a grammar from a path", ({ expect }) => {
39
+ expect(highlightLanguageOf("src/app.tsx")).toBe("typescript");
40
+ expect(highlightLanguageOf("deploy/Dockerfile")).toBe("dockerfile");
41
+ expect(highlightLanguageOf("README.md")).toBe("markdown");
42
+ expect(highlightLanguageOf("bin/tool")).toBeUndefined();
43
+ expect(highlightLanguageOf("image.png")).toBeUndefined();
44
+ });
45
+ });
@@ -0,0 +1,120 @@
1
+ import { createLowlight } from "lowlight";
2
+
3
+ import { HIGHLIGHT_LANGUAGES } from "./rehypeHighlight.ts";
4
+
5
+ /**
6
+ * One piece of a highlighted line: its text, and the highlight.js classes
7
+ * (`hljs-keyword`, ...) of every token it sits in, outermost first.
8
+ */
9
+ export interface HighlightToken {
10
+ value: string;
11
+ className?: string;
12
+ }
13
+
14
+ /**
15
+ * The subset of a lowlight node this walk reads.
16
+ */
17
+ interface HastLike {
18
+ type: string;
19
+ value?: string;
20
+ properties?: { className?: unknown };
21
+ children?: HastLike[];
22
+ }
23
+
24
+ let shared: ReturnType<typeof createLowlight> | undefined;
25
+
26
+ /**
27
+ * Highlight `text` line by line, with the grammars `MarkdownView` uses
28
+ * ({@link HIGHLIGHT_LANGUAGES}): a code browser or a diff numbers each line
29
+ * and needs its tokens per line, which highlight.js does not give.
30
+ *
31
+ * A token that spans lines (a block comment, a template string) is split at
32
+ * each newline and keeps its classes on every piece, so the second line of a
33
+ * comment is still a comment. A language that is not registered, or none,
34
+ * answers the lines as plain text. Always one entry per line of `text`,
35
+ * the last one empty when it ends with a newline, as `text.split("\n")`.
36
+ */
37
+ export const highlightLines = (
38
+ text: string,
39
+ language?: string,
40
+ ): HighlightToken[][] => {
41
+ shared ??= createLowlight(HIGHLIGHT_LANGUAGES);
42
+ const lines: HighlightToken[][] = [[]];
43
+ if (!language || !shared.registered(language)) {
44
+ return text.split("\n").map((line) => (line ? [{ value: line }] : []));
45
+ }
46
+ const push = (value: string, classes: string[]) => {
47
+ const parts = value.split("\n");
48
+ parts.forEach((part, index) => {
49
+ if (index > 0) lines.push([]);
50
+ if (!part) return;
51
+ const className = classes.length ? classes.join(" ") : undefined;
52
+ const line = lines[lines.length - 1]!;
53
+ const last = line[line.length - 1];
54
+ if (last && last.className === className) last.value += part;
55
+ else line.push(className ? { value: part, className } : { value: part });
56
+ });
57
+ };
58
+ const walk = (node: HastLike, classes: string[]) => {
59
+ if (node.type === "text") {
60
+ push(node.value ?? "", classes);
61
+ return;
62
+ }
63
+ const own = Array.isArray(node.properties?.className)
64
+ ? (node.properties.className as unknown[]).map(String)
65
+ : [];
66
+ const next = own.length ? [...classes, ...own] : classes;
67
+ for (const child of node.children ?? []) walk(child, next);
68
+ };
69
+ walk(shared.highlight(language, text) as unknown as HastLike, []);
70
+ return lines;
71
+ };
72
+
73
+ /**
74
+ * The highlight.js grammar a file's name asks for, among
75
+ * {@link HIGHLIGHT_LANGUAGES}, or undefined: by extension, and `Dockerfile`
76
+ * and `Makefile`-free names by their own.
77
+ */
78
+ export const highlightLanguageOf = (path: string): string | undefined => {
79
+ const name = path.slice(path.lastIndexOf("/") + 1).toLowerCase();
80
+ if (name === "dockerfile" || name.endsWith(".dockerfile")) {
81
+ return "dockerfile";
82
+ }
83
+ const extension = name.includes(".")
84
+ ? name.slice(name.lastIndexOf(".") + 1)
85
+ : "";
86
+ return HIGHLIGHT_EXTENSIONS[extension];
87
+ };
88
+
89
+ const HIGHLIGHT_EXTENSIONS: Record<string, string> = {
90
+ ts: "typescript",
91
+ tsx: "typescript",
92
+ mts: "typescript",
93
+ cts: "typescript",
94
+ js: "javascript",
95
+ jsx: "javascript",
96
+ mjs: "javascript",
97
+ cjs: "javascript",
98
+ json: "json",
99
+ jsonc: "json",
100
+ md: "markdown",
101
+ markdown: "markdown",
102
+ yml: "yaml",
103
+ yaml: "yaml",
104
+ sh: "bash",
105
+ bash: "bash",
106
+ zsh: "bash",
107
+ css: "css",
108
+ html: "xml",
109
+ htm: "xml",
110
+ xml: "xml",
111
+ svg: "xml",
112
+ go: "go",
113
+ rs: "rust",
114
+ py: "python",
115
+ sql: "sql",
116
+ toml: "ini",
117
+ ini: "ini",
118
+ diff: "diff",
119
+ patch: "diff",
120
+ };
@@ -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. `diagramKind`,
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
  *
@@ -15,4 +17,14 @@
15
17
  export { diagramKind } from "./diagram/diagramKind.ts";
16
18
  export { parseFlowchart } from "./diagram/flowchartParser.ts";
17
19
  export { parseSequence } from "./diagram/sequenceParser.ts";
18
- export { MarkdownView, type MarkdownViewProps } from "./MarkdownView.tsx";
20
+ export {
21
+ type HighlightToken,
22
+ highlightLanguageOf,
23
+ highlightLines,
24
+ } from "./highlightLines.ts";
25
+ export {
26
+ type MarkdownImageRenderer,
27
+ type MarkdownLinkRenderer,
28
+ MarkdownView,
29
+ type MarkdownViewProps,
30
+ } from "./MarkdownView.tsx";
@@ -65,6 +65,14 @@ export interface ButtonInboxProps {
65
65
  * app passes its own push.
66
66
  */
67
67
  onOpen?: (href: string) => void;
68
+ /**
69
+ * Called once the server has marked messages read from this dropdown: after
70
+ * "Mark all read", and after a clicked row was marked read. The bell keeps
71
+ * its own count, but a host showing unread counts elsewhere (per scope, in
72
+ * a sidebar) has no other way to learn they went stale, so it refreshes
73
+ * them here. Not called when a write is refused.
74
+ */
75
+ onRead?: () => void;
68
76
  }
69
77
 
70
78
  interface InboxRow {
@@ -148,6 +156,7 @@ export const ButtonInbox = (props: ButtonInboxProps) => {
148
156
  try {
149
157
  await api.markInboxRead({ params: { id: row.id } });
150
158
  setUnread({ count: Math.max(0, unread.count - 1) });
159
+ props.onRead?.();
151
160
  } catch {
152
161
  // Opening the message matters more than recording that it was read.
153
162
  }
@@ -171,9 +180,10 @@ export const ButtonInbox = (props: ButtonInboxProps) => {
171
180
  setItems((current) =>
172
181
  current.map((it) => ({ ...it, readAt: it.readAt ?? "read" })),
173
182
  );
183
+ props.onRead?.();
174
184
  },
175
185
  },
176
- [api],
186
+ [api, props.onRead],
177
187
  );
178
188
 
179
189
  if (!available) {
@@ -125,10 +125,11 @@ export const PlateLayout = (props: PlateLayoutProps) => (
125
125
  </div>
126
126
  {/*
127
127
  A thin strip in the active tile's fill, ruled at its foot: the
128
- tile opens into it with no seam, and the body below is content,
129
- on `bg-card` (the surface rules in `styles.css`). It replaced a
128
+ tile opens into it with no seam. The body below takes the shell
129
+ header's fill, `bg-background`, so header, band and body read as
130
+ one surface and the cards inside stand out from it. It replaced a
130
131
  body filled grey to match the tile, which made every tab a grey
131
- page.
132
+ page, and then a `bg-card` body, lighter than the header in dark.
132
133
  */}
133
134
  <div
134
135
  aria-hidden
@@ -161,9 +162,15 @@ export const PlateLayout = (props: PlateLayoutProps) => (
161
162
 
162
163
  {props.scroll === false ? (
163
164
  // A body that owns its scroll is a page of content under a toolbar of
164
- // its own, on the content surface. Opaque, never transparent: without a
165
- // fill the shell behind it shows through.
166
- <div className="bg-card flex min-h-0 flex-1 flex-col">
165
+ // its own. Opaque, never transparent: without a fill the shell behind
166
+ // it shows through. Under folder tabs it takes the header's fill, like
167
+ // the scrolling body below.
168
+ <div
169
+ className={cn(
170
+ "flex min-h-0 flex-1 flex-col",
171
+ props.tabsVariant === "underline" ? "bg-card" : "bg-background",
172
+ )}
173
+ >
167
174
  {props.children}
168
175
  </div>
169
176
  ) : (
@@ -172,11 +179,13 @@ export const PlateLayout = (props: PlateLayoutProps) => (
172
179
  <div
173
180
  // 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
174
181
  tabIndex={0}
175
- // Folder tabs end on their grey strip, so the body is content, on
176
- // `bg-card`. Underline tabs have no tile and keep the flat fill.
182
+ // Folder tabs end on their grey strip, and the body under it takes
183
+ // the shell header's fill, `bg-background`, so the page reads as one
184
+ // surface with its cards on top. Underline tabs have no tile and keep
185
+ // the flat fill.
177
186
  className={cn(
178
187
  "focus-visible:ring-ring/50 min-h-0 flex-1 overflow-y-auto outline-none focus-visible:ring-[3px] focus-visible:ring-inset",
179
- props.tabsVariant === "underline" ? "bg-muted" : "bg-card",
188
+ props.tabsVariant === "underline" ? "bg-muted" : "bg-background",
180
189
  )}
181
190
  >
182
191
  {props.children}
@@ -236,6 +236,46 @@ describe("ButtonInbox", () => {
236
236
  await waitFor(() => expect(view.queryByTestId("inbox-badge")).toBeNull());
237
237
  });
238
238
 
239
+ /**
240
+ * A host with unread counts of its own (a sidebar's, per scope) refreshes
241
+ * them from `onRead`: the bell's own count is the only one it updates.
242
+ */
243
+ it("tells the host once messages were read, by Mark all read or by a row", async () => {
244
+ const reads: string[] = [];
245
+ const { view, links } = await mount({
246
+ onOpen: () => {},
247
+ onRead: () => reads.push("read"),
248
+ });
249
+
250
+ fireEvent.click(view.container.querySelector("button")!);
251
+ await waitFor(() => expect(view.getByText("Mark all read")).toBeTruthy());
252
+ fireEvent.click(view.getByText("Fabrice mentioned you in #Q402"));
253
+ await waitFor(() => expect(links.readCalls).toEqual(["m-1"]));
254
+ await waitFor(() => expect(reads).toHaveLength(1));
255
+
256
+ fireEvent.click(view.container.querySelector("button")!);
257
+ await waitFor(() => expect(view.getByText("Mark all read")).toBeTruthy());
258
+ fireEvent.click(view.getByText("Mark all read"));
259
+ await waitFor(() => expect(links.markAllCalls).toBe(1));
260
+ await waitFor(() => expect(reads).toHaveLength(2));
261
+ });
262
+
263
+ it("does not tell the host when Mark all read is refused", async () => {
264
+ const reads: string[] = [];
265
+ const { view, links } = await mount(
266
+ { onRead: () => reads.push("read") },
267
+ (links) => {
268
+ links.markAllError = new Error("refused");
269
+ },
270
+ );
271
+
272
+ fireEvent.click(view.container.querySelector("button")!);
273
+ await waitFor(() => expect(view.getByText("Mark all read")).toBeTruthy());
274
+ fireEvent.click(view.getByText("Mark all read"));
275
+ await waitFor(() => expect(links.markAllCalls).toBe(1));
276
+ expect(reads).toEqual([]);
277
+ });
278
+
239
279
  /**
240
280
  * The write is the truth: a refused "Mark all read" leaves the badge and
241
281
  * the dots as they were, and the failure reaches `react:action:error`
@@ -97,7 +97,8 @@ describe("PlateLayout", () => {
97
97
 
98
98
  /**
99
99
  * Folder tabs end on a thin strip in the active tile's fill, ruled at its
100
- * foot, and the body below it is content, on `bg-card`. The band itself
100
+ * foot, and the body below it takes the shell header's fill,
101
+ * `bg-background` (#Q4520), scrolling or not. The band itself
101
102
  * draws no rule, or there would be two.
102
103
  */
103
104
  it("ends folder tabs on a ruled grey strip over a content body", async () => {
@@ -118,11 +119,27 @@ describe("PlateLayout", () => {
118
119
  expect.arrayContaining(["bg-muted", "border-b"]),
119
120
  );
120
121
  const body = classes(folder.getByText("body").parentElement);
121
- expect(body).toContain("bg-card");
122
+ expect(body).toContain("bg-background");
123
+ expect(body).not.toContain("bg-card");
122
124
  expect(body).not.toContain("bg-muted");
123
125
  expect(body).not.toContain("bg-linear-to-b");
124
126
  folder.unmount();
125
127
 
128
+ const fixed = await mount(
129
+ <PlateLayout
130
+ tabs={stateTabs}
131
+ active="overview"
132
+ tabsTestId="probe-tabs"
133
+ scroll={false}
134
+ >
135
+ <p>body</p>
136
+ </PlateLayout>,
137
+ );
138
+ const fixedBody = classes(fixed.getByText("body").parentElement);
139
+ expect(fixedBody).toContain("bg-background");
140
+ expect(fixedBody).not.toContain("bg-card");
141
+ fixed.unmount();
142
+
126
143
  const underline = await mount(
127
144
  <PlateLayout
128
145
  tabs={stateTabs}
@@ -0,0 +1,157 @@
1
+ import { DndContext } from "@dnd-kit/core";
2
+ import { fireEvent, render, screen } from "@testing-library/react";
3
+ import { useState } from "react";
4
+ import { describe, expect, it } from "vitest";
5
+
6
+ import { useSortableItem } from "../useSortableItem.ts";
7
+ import { useSortableList } from "../useSortableList.ts";
8
+
9
+ interface Saved {
10
+ next: string[];
11
+ previous: string[];
12
+ }
13
+
14
+ const Row = (props: {
15
+ id: string;
16
+ onKeyDown: (event: React.KeyboardEvent<HTMLElement>) => void;
17
+ picked: boolean;
18
+ }) => {
19
+ const item = useSortableItem(props.id);
20
+ return (
21
+ <li
22
+ ref={item.ref}
23
+ style={item.style}
24
+ data-picked={props.picked || undefined}
25
+ >
26
+ <button
27
+ type="button"
28
+ data-testid={`row-${props.id}`}
29
+ onKeyDown={props.onKeyDown}
30
+ >
31
+ {props.id}
32
+ </button>
33
+ </li>
34
+ );
35
+ };
36
+
37
+ const List = (props: {
38
+ initial: string[];
39
+ saves: Saved[];
40
+ server?: boolean;
41
+ }) => {
42
+ const [ids, setIds] = useState(props.initial);
43
+ const list = useSortableList({
44
+ ids,
45
+ labelOf: (id) => id,
46
+ onReorder: (next, previous) => {
47
+ props.saves.push({ next, previous });
48
+ // The server reads the new order back.
49
+ if (props.server) setIds(next);
50
+ },
51
+ announcements: {
52
+ picked: (label) => `picked ${label}`,
53
+ moved: (label, at, total) => `${label} ${at}/${total}`,
54
+ dropped: (label) => `dropped ${label}`,
55
+ cancelled: (label) => `cancelled ${label}`,
56
+ },
57
+ });
58
+ return (
59
+ <DndContext {...list.contextProps}>
60
+ <p data-testid="live">{list.announcement}</p>
61
+ <ul data-testid="order">
62
+ {list.order.map((id) => (
63
+ <Row
64
+ key={id}
65
+ id={id}
66
+ onKeyDown={list.onKeyDown(id)}
67
+ picked={list.picked === id}
68
+ />
69
+ ))}
70
+ </ul>
71
+ </DndContext>
72
+ );
73
+ };
74
+
75
+ const order = () =>
76
+ Array.from(screen.getByTestId("order").querySelectorAll("button")).map(
77
+ (it) => it.textContent,
78
+ );
79
+ const key = (id: string, k: string) =>
80
+ fireEvent.keyDown(screen.getByTestId(`row-${id}`), { key: k });
81
+
82
+ /**
83
+ * The shared sortable list (#Q4128): the keyboard move every list gets, the
84
+ * order held until the app has it, and the announcements a screen reader
85
+ * hears.
86
+ */
87
+ describe("useSortableList", () => {
88
+ it("moves an item from the keyboard and saves once, on the drop", () => {
89
+ const saves: Saved[] = [];
90
+ render(<List initial={["a", "b", "c"]} saves={saves} />);
91
+
92
+ key("a", " ");
93
+ expect(screen.getByTestId("live").textContent).toBe("picked a");
94
+ key("a", "ArrowDown");
95
+ key("a", "ArrowDown");
96
+ expect(order()).toEqual(["b", "c", "a"]);
97
+ expect(screen.getByTestId("live").textContent).toBe("a 3/3");
98
+ // Drawn at each step, saved only on the drop.
99
+ expect(saves).toHaveLength(0);
100
+
101
+ key("a", "Enter");
102
+
103
+ expect(saves).toEqual([
104
+ { next: ["b", "c", "a"], previous: ["a", "b", "c"] },
105
+ ]);
106
+ expect(screen.getByTestId("live").textContent).toBe("dropped a");
107
+ // Held until the app's order changes.
108
+ expect(order()).toEqual(["b", "c", "a"]);
109
+ });
110
+
111
+ it("puts the item back on Escape, and saves nothing", () => {
112
+ const saves: Saved[] = [];
113
+ render(<List initial={["a", "b", "c"]} saves={saves} />);
114
+
115
+ key("b", " ");
116
+ key("b", "ArrowUp");
117
+ expect(order()).toEqual(["b", "a", "c"]);
118
+ key("b", "Escape");
119
+
120
+ expect(order()).toEqual(["a", "b", "c"]);
121
+ expect(saves).toHaveLength(0);
122
+ expect(screen.getByTestId("live").textContent).toBe("cancelled b");
123
+ });
124
+
125
+ it("never moves past the ends, and a drop where it was saves nothing", () => {
126
+ const saves: Saved[] = [];
127
+ render(<List initial={["a", "b"]} saves={saves} />);
128
+
129
+ key("a", " ");
130
+ key("a", "ArrowUp");
131
+ expect(order()).toEqual(["a", "b"]);
132
+ key("a", " ");
133
+
134
+ expect(saves).toHaveLength(0);
135
+ });
136
+
137
+ it("ignores the arrows until an item is picked up", () => {
138
+ const saves: Saved[] = [];
139
+ render(<List initial={["a", "b"]} saves={saves} />);
140
+
141
+ key("a", "ArrowDown");
142
+
143
+ expect(order()).toEqual(["a", "b"]);
144
+ });
145
+
146
+ it("hands back to the app's order once it reads back", () => {
147
+ const saves: Saved[] = [];
148
+ render(<List initial={["a", "b", "c"]} saves={saves} server />);
149
+
150
+ key("c", " ");
151
+ key("c", "ArrowUp");
152
+ key("c", " ");
153
+
154
+ expect(order()).toEqual(["a", "c", "b"]);
155
+ expect(saves).toHaveLength(1);
156
+ });
157
+ });
@@ -0,0 +1,22 @@
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
+
15
+ export { DndContext } from "@dnd-kit/core";
16
+ export { type SortableItem, useSortableItem } from "./useSortableItem.ts";
17
+ export {
18
+ type SortableList,
19
+ type SortableListAnnouncements,
20
+ type UseSortableListOptions,
21
+ useSortableList,
22
+ } from "./useSortableList.ts";