@ignite-ember/ui-react 0.0.0-stage → 0.2.1
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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +260 -2
- package/dist/CopySource.d.ts +4 -0
- package/dist/CopySource.d.ts.map +1 -0
- package/dist/CopySource.js +50 -0
- package/dist/CopySource.js.map +1 -0
- package/dist/DataTable.d.ts +77 -0
- package/dist/DataTable.d.ts.map +1 -0
- package/dist/DataTable.js +45 -0
- package/dist/DataTable.js.map +1 -0
- package/dist/Dialog.d.ts +41 -0
- package/dist/Dialog.d.ts.map +1 -0
- package/dist/Dialog.js +94 -0
- package/dist/Dialog.js.map +1 -0
- package/dist/ErrorBoundary.d.ts +97 -0
- package/dist/ErrorBoundary.d.ts.map +1 -0
- package/dist/ErrorBoundary.js +97 -0
- package/dist/ErrorBoundary.js.map +1 -0
- package/dist/LiveRegion.d.ts +41 -0
- package/dist/LiveRegion.d.ts.map +1 -0
- package/dist/LiveRegion.js +76 -0
- package/dist/LiveRegion.js.map +1 -0
- package/dist/Markdown.d.ts +22 -0
- package/dist/Markdown.d.ts.map +1 -0
- package/dist/Markdown.js +56 -0
- package/dist/Markdown.js.map +1 -0
- package/dist/MarkdownInline.d.ts +53 -0
- package/dist/MarkdownInline.d.ts.map +1 -0
- package/dist/MarkdownInline.js +159 -0
- package/dist/MarkdownInline.js.map +1 -0
- package/dist/MenuIcon.d.ts +60 -0
- package/dist/MenuIcon.d.ts.map +1 -0
- package/dist/MenuIcon.js +102 -0
- package/dist/MenuIcon.js.map +1 -0
- package/dist/Mermaid.d.ts +40 -0
- package/dist/Mermaid.d.ts.map +1 -0
- package/dist/Mermaid.js +121 -0
- package/dist/Mermaid.js.map +1 -0
- package/dist/Monogram.d.ts +46 -0
- package/dist/Monogram.d.ts.map +1 -0
- package/dist/Monogram.js +96 -0
- package/dist/Monogram.js.map +1 -0
- package/dist/OverflowMenu.d.ts +60 -0
- package/dist/OverflowMenu.d.ts.map +1 -0
- package/dist/OverflowMenu.js +149 -0
- package/dist/OverflowMenu.js.map +1 -0
- package/dist/Shell.d.ts +67 -0
- package/dist/Shell.d.ts.map +1 -0
- package/dist/Shell.js +44 -0
- package/dist/Shell.js.map +1 -0
- package/dist/Skeleton.d.ts +62 -0
- package/dist/Skeleton.d.ts.map +1 -0
- package/dist/Skeleton.js +56 -0
- package/dist/Skeleton.js.map +1 -0
- package/dist/Split.d.ts +85 -0
- package/dist/Split.d.ts.map +1 -0
- package/dist/Split.js +156 -0
- package/dist/Split.js.map +1 -0
- package/dist/Tabs.d.ts +77 -0
- package/dist/Tabs.d.ts.map +1 -0
- package/dist/Tabs.js +91 -0
- package/dist/Tabs.js.map +1 -0
- package/dist/Toast.d.ts +98 -0
- package/dist/Toast.d.ts.map +1 -0
- package/dist/Toast.js +129 -0
- package/dist/Toast.js.map +1 -0
- package/dist/Tooltip.d.ts +24 -0
- package/dist/Tooltip.d.ts.map +1 -0
- package/dist/Tooltip.js +166 -0
- package/dist/Tooltip.js.map +1 -0
- package/dist/controls.d.ts +117 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +59 -0
- package/dist/controls.js.map +1 -0
- package/dist/cx.d.ts +3 -0
- package/dist/cx.d.ts.map +1 -0
- package/dist/cx.js +5 -0
- package/dist/cx.js.map +1 -0
- package/dist/fenceInfo.d.ts +26 -0
- package/dist/fenceInfo.d.ts.map +1 -0
- package/dist/fenceInfo.js +22 -0
- package/dist/fenceInfo.js.map +1 -0
- package/dist/formControls.d.ts +143 -0
- package/dist/formControls.d.ts.map +1 -0
- package/dist/formControls.js +108 -0
- package/dist/formControls.js.map +1 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +95 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +93 -0
- package/dist/layout.js.map +1 -0
- package/dist/primitives.d.ts +33 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +33 -0
- package/dist/primitives.js.map +1 -0
- package/dist/progress.d.ts +64 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +51 -0
- package/dist/progress.js.map +1 -0
- package/dist/text.d.ts +63 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +61 -0
- package/dist/text.js.map +1 -0
- package/package.json +56 -4
- package/src/CopySource.tsx +67 -0
- package/src/DataTable.tsx +120 -0
- package/src/Dialog.tsx +158 -0
- package/src/ErrorBoundary.tsx +137 -0
- package/src/LiveRegion.tsx +127 -0
- package/src/Markdown.tsx +75 -0
- package/src/MarkdownInline.tsx +177 -0
- package/src/MenuIcon.tsx +209 -0
- package/src/Mermaid.tsx +144 -0
- package/src/Monogram.tsx +112 -0
- package/src/OverflowMenu.tsx +359 -0
- package/src/Shell.tsx +99 -0
- package/src/Skeleton.tsx +98 -0
- package/src/Split.tsx +267 -0
- package/src/Tabs.tsx +194 -0
- package/src/Toast.tsx +269 -0
- package/src/Tooltip.tsx +213 -0
- package/src/controls.tsx +159 -0
- package/src/cx.ts +4 -0
- package/src/fenceInfo.ts +36 -0
- package/src/formControls.tsx +249 -0
- package/src/index.ts +149 -0
- package/src/layout.tsx +141 -0
- package/src/primitives.tsx +33 -0
- package/src/progress.tsx +129 -0
- package/src/text.tsx +99 -0
package/src/MenuIcon.tsx
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The small glyphs beside a menu item.
|
|
3
|
+
*
|
|
4
|
+
* A menu of five verbs reads as five equal options, and picking the
|
|
5
|
+
* wrong one of Archive and Remove costs quite differently. An icon is
|
|
6
|
+
* what makes a list scannable: the shape is recognised before the
|
|
7
|
+
* word is read, so the item somebody wants is found by looking rather
|
|
8
|
+
* than by reading the list from the top each time.
|
|
9
|
+
*
|
|
10
|
+
* **One set, one grammar.** All of them are 16×16, drawn in strokes
|
|
11
|
+
* of the same weight on the same grid, and coloured ``currentColor``
|
|
12
|
+
* so a disabled item's icon dims with its label and a destructive
|
|
13
|
+
* one turns red with it. Mixing a filled glyph into a stroked set is
|
|
14
|
+
* the single most obvious way to make a menu look assembled from
|
|
15
|
+
* parts.
|
|
16
|
+
*
|
|
17
|
+
* Inline rather than a sprite or a font: these are small paths used
|
|
18
|
+
* in a few menus, and a build step, a network request or a font with
|
|
19
|
+
* a flash of missing glyphs are all more machinery than the problem
|
|
20
|
+
* has.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export type MenuIconName =
|
|
24
|
+
| "open"
|
|
25
|
+
| "rename"
|
|
26
|
+
| "export"
|
|
27
|
+
| "share"
|
|
28
|
+
| "archive"
|
|
29
|
+
| "restore"
|
|
30
|
+
| "remove"
|
|
31
|
+
| "document"
|
|
32
|
+
| "document-add"
|
|
33
|
+
| "folder"
|
|
34
|
+
| "folder-add"
|
|
35
|
+
| "outdent"
|
|
36
|
+
| "compare"
|
|
37
|
+
| "lineage"
|
|
38
|
+
// Formatting. Drawn in the same grammar as the rest so the
|
|
39
|
+
// editor's bar and the document's menus look like one product.
|
|
40
|
+
| "code"
|
|
41
|
+
| "list-bullet"
|
|
42
|
+
| "list-ordered"
|
|
43
|
+
| "list-task"
|
|
44
|
+
| "quote"
|
|
45
|
+
| "code-block"
|
|
46
|
+
| "table"
|
|
47
|
+
| "divider"
|
|
48
|
+
| "link"
|
|
49
|
+
| "image"
|
|
50
|
+
| "undo"
|
|
51
|
+
| "redo"
|
|
52
|
+
| "resolve"
|
|
53
|
+
| "reopen"
|
|
54
|
+
| "lock"
|
|
55
|
+
| "unlock"
|
|
56
|
+
| "bell"
|
|
57
|
+
// A diagram's copy button, before and after.
|
|
58
|
+
| "copy"
|
|
59
|
+
| "check";
|
|
60
|
+
|
|
61
|
+
/** The drawing for each name, on a 16×16 grid. */
|
|
62
|
+
const PATHS: Record<MenuIconName, string> = {
|
|
63
|
+
// A page with a corner turned.
|
|
64
|
+
open: "M9 1.5H4.5A1.5 1.5 0 0 0 3 3v10a1.5 1.5 0 0 0 1.5 1.5h7A1.5 1.5 0 0 0 13 13V5.5zM9 1.5V5.5h4",
|
|
65
|
+
// A pencil across a line.
|
|
66
|
+
rename: "M11.2 2.3 13.7 4.8 6.2 12.3 3 13l.7-3.2zM2.5 14.5h11",
|
|
67
|
+
// Out of a tray, downwards — the file leaves.
|
|
68
|
+
export:
|
|
69
|
+
"M8 2v7m0 0 2.8-2.8M8 9 5.2 6.2M2.8 10.5v2.2a1 1 0 0 0 1 1h8.4a1 1 0 0 0 1-1v-2.2",
|
|
70
|
+
// Two nodes joined to a third: one thing, several people.
|
|
71
|
+
share:
|
|
72
|
+
"M5.6 9.3 10.4 12M10.4 4 5.6 6.7M12 2.2a1.8 1.8 0 1 1 0 3.6 1.8 1.8 0 0 1 0-3.6zM4 6.2a1.8 1.8 0 1 1 0 3.6 1.8 1.8 0 0 1 0-3.6zM12 10.2a1.8 1.8 0 1 1 0 3.6 1.8 1.8 0 0 1 0-3.6z",
|
|
73
|
+
// A box with a lid, and a handle on the drawer.
|
|
74
|
+
archive:
|
|
75
|
+
"M2 3.2h12v2.6H2zM3 5.8v7a.8.8 0 0 0 .8.8h8.4a.8.8 0 0 0 .8-.8v-7M6.4 8.4h3.2",
|
|
76
|
+
// The same box, with the arrow coming back up out of it.
|
|
77
|
+
restore:
|
|
78
|
+
"M2 3.2h12v2.6H2zM3 5.8v7a.8.8 0 0 0 .8.8h8.4a.8.8 0 0 0 .8-.8v-7M8 11.6V7.4m0 0L6.2 9.2M8 7.4l1.8 1.8",
|
|
79
|
+
// A bin. Deliberately the least like the archive of any of these.
|
|
80
|
+
remove:
|
|
81
|
+
"M2.8 4.3h10.4M6.4 4.3V2.9a.7.7 0 0 1 .7-.7h1.8a.7.7 0 0 1 .7.7v1.4M4.2 4.3l.6 8.5a.9.9 0 0 0 .9.8h4.6a.9.9 0 0 0 .9-.8l.6-8.5M6.7 6.8v4.2M9.3 6.8v4.2",
|
|
82
|
+
// A page. The same shape as ``open`` without the action.
|
|
83
|
+
document:
|
|
84
|
+
"M9 1.5H4.5A1.5 1.5 0 0 0 3 3v10a1.5 1.5 0 0 0 1.5 1.5h7A1.5 1.5 0 0 0 13 13V5.5zM9 1.5V5.5h4M5.5 8.5h5M5.5 11h3",
|
|
85
|
+
// The same page and folder, with the plus that makes one. Drawn
|
|
86
|
+
// from the same outlines rather than new shapes: "new document"
|
|
87
|
+
// and "document" should be recognisably the same noun.
|
|
88
|
+
"document-add":
|
|
89
|
+
"M8.4 1.5H4.5A1.5 1.5 0 0 0 3 3v10a1.5 1.5 0 0 0 1.5 1.5h3.2M8.4 1.5V5.5h3.6M11.8 8.8v4.6M9.5 11.1h4.6",
|
|
90
|
+
folder:
|
|
91
|
+
"M1.8 4.2a1 1 0 0 1 1-1h3.1l1.4 1.6h5.9a1 1 0 0 1 1 1v6.4a1 1 0 0 1-1 1H2.8a1 1 0 0 1-1-1z",
|
|
92
|
+
"folder-add":
|
|
93
|
+
"M1.8 4.2a1 1 0 0 1 1-1h3.1l1.4 1.6h5.9a1 1 0 0 1 1 1v1.5M1.8 4.2v8.4a1 1 0 0 0 1 1h4.9M11.4 8.8v4.6M9.1 11.1h4.6",
|
|
94
|
+
// Up and to the left: out of where it is, to the level above.
|
|
95
|
+
outdent: "M13 4H6M13 8H8.5M13 12H6M4.5 5.5 2 8l2.5 2.5",
|
|
96
|
+
// Two columns, side by side.
|
|
97
|
+
compare: "M6.4 2.5v11M9.6 2.5v11M2 2.5h12v11H2zM2 2.5",
|
|
98
|
+
// Chevrons, the way code is written about.
|
|
99
|
+
code: "M5.8 4.6 1.8 8l4 3.4M10.2 4.6 14.2 8l-4 3.4",
|
|
100
|
+
// Three dots with three lines. The dots are round rather than
|
|
101
|
+
// square so a bullet list and a checklist are not the same
|
|
102
|
+
// silhouette at a glance.
|
|
103
|
+
"list-bullet":
|
|
104
|
+
"M6.2 4.2h7.6M6.2 8h7.6M6.2 11.8h7.6M2.6 3.6a.6.6 0 1 1 0 1.2.6.6 0 0 1 0-1.2zM2.6 7.4a.6.6 0 1 1 0 1.2.6.6 0 0 1 0-1.2zM2.6 11.2a.6.6 0 1 1 0 1.2.6.6 0 0 1 0-1.2z",
|
|
105
|
+
"list-ordered":
|
|
106
|
+
"M6.4 4.2h7.4M6.4 8h7.4M6.4 11.8h7.4M2 3.2h1v2.4M1.7 5.6h1.8M1.7 9.6h2l-2 2.6h2.2",
|
|
107
|
+
// A tick in a box, against the bullet list's round dots.
|
|
108
|
+
"list-task":
|
|
109
|
+
"M6.6 4.2h7.2M6.6 11.8h7.2M1.4 2.7h3.4v3.4H1.4zM1.4 10.3h3.4v3.4H1.4zM2.1 11.9l.9.9 1.4-1.6",
|
|
110
|
+
// The bar a quote is set behind, with the lines it holds.
|
|
111
|
+
quote: "M2.6 3.4v9.2M5.8 5h8M5.8 8h8M5.8 11h5.4",
|
|
112
|
+
// A fence: the chevrons again, boxed.
|
|
113
|
+
"code-block":
|
|
114
|
+
"M1.8 3.2h12.4v9.6H1.8zM6.2 6.4 4.4 8l1.8 1.6M9.8 6.4 11.6 8l-1.8 1.6",
|
|
115
|
+
// A grid with its header row set apart, which is what makes a
|
|
116
|
+
// table a table rather than a box with lines in it.
|
|
117
|
+
table: "M1.8 3.2h12.4v9.6H1.8zM1.8 6.4h12.4M6.4 6.4v6.4M10.2 6.4v6.4",
|
|
118
|
+
divider: "M2 8h12",
|
|
119
|
+
// A chain of two links, at an angle.
|
|
120
|
+
link: "M6.6 9.4 9.4 6.6M6.9 4.6 8.4 3.1a2.6 2.6 0 0 1 3.7 3.7l-1.5 1.5M9.1 11.4l-1.5 1.5a2.6 2.6 0 0 1-3.7-3.7l1.5-1.5",
|
|
121
|
+
// A frame with a horizon and a sun: recognisable at this size in
|
|
122
|
+
// a way a literal photograph is not.
|
|
123
|
+
image:
|
|
124
|
+
"M1.8 3.2h12.4v9.6H1.8zM1.8 10.4l3.4-3.2 3 2.8 2.2-2 3.8 3.4M10.6 5.6a.9.9 0 1 1 0 1.8.9.9 0 0 1 0-1.8z",
|
|
125
|
+
// A tick in a circle: settled, and closed. The checklist glyph
|
|
126
|
+
// was standing in for this and said the wrong thing — a checklist
|
|
127
|
+
// is a kind of list, not a ruling on a conversation.
|
|
128
|
+
resolve:
|
|
129
|
+
"M8 1.6a6.4 6.4 0 1 1 0 12.8A6.4 6.4 0 0 1 8 1.6zM5.2 8.2l1.9 1.9 3.7-4",
|
|
130
|
+
// The same circle, opened again: an arrow coming back round.
|
|
131
|
+
reopen: "M13.4 8a5.4 5.4 0 1 1-1.9-4.1M13.6 2.4v3.4h-3.4",
|
|
132
|
+
// A padlock, shackle closed. Shown beside a colleague who cannot
|
|
133
|
+
// open the document — a state, not an action, which is why it is
|
|
134
|
+
// the only icon here that is never on a button of its own.
|
|
135
|
+
lock: "M4.2 7.2h7.6a.8.8 0 0 1 .8.8v5a.8.8 0 0 1-.8.8H4.2a.8.8 0 0 1-.8-.8V8a.8.8 0 0 1 .8-.8zM5.6 7.2V4.9a2.4 2.4 0 0 1 4.8 0v2.3",
|
|
136
|
+
// The same padlock with the shackle swung open. Drawn from the
|
|
137
|
+
// same body so the two read as one object in two states rather
|
|
138
|
+
// than as two icons — the whole point is noticing that it changed.
|
|
139
|
+
unlock:
|
|
140
|
+
"M4.2 7.2h7.6a.8.8 0 0 1 .8.8v5a.8.8 0 0 1-.8.8H4.2a.8.8 0 0 1-.8-.8V8a.8.8 0 0 1 .8-.8zM5.6 7.2V4.9a2.4 2.4 0 0 1 4.8 0",
|
|
141
|
+
undo: "M4.2 6.6H10a3.4 3.4 0 0 1 0 6.8H6.6M4.2 6.6l2.6-2.6M4.2 6.6l2.6 2.6",
|
|
142
|
+
redo: "M11.8 6.6H6a3.4 3.4 0 0 0 0 6.8h3.4M11.8 6.6 9.2 4M11.8 6.6 9.2 9.2",
|
|
143
|
+
// A node with two feeding into it: what this was built on.
|
|
144
|
+
// A bell, drawn at the same weight as the rest: the clapper is a
|
|
145
|
+
// separate stroke so it reads at 14px, where a single outline
|
|
146
|
+
// closes up into a blob.
|
|
147
|
+
bell: "M8 2.2a3.8 3.8 0 0 0-3.8 3.8c0 3-1.1 4-1.1 4h9.8s-1.1-1-1.1-4A3.8 3.8 0 0 0 8 2.2zM9.3 12.2a1.5 1.5 0 0 1-2.6 0",
|
|
148
|
+
// Two pages, one over the other: the source, duplicated.
|
|
149
|
+
copy: "M5.6 5.6h7a.8.8 0 0 1 .8.8v7a.8.8 0 0 1-.8.8h-7a.8.8 0 0 1-.8-.8v-7a.8.8 0 0 1 .8-.8zM3.2 10.4h-.4a.8.8 0 0 1-.8-.8v-7a.8.8 0 0 1 .8-.8h7a.8.8 0 0 1 .8.8v.4",
|
|
150
|
+
// The tick on its own, without the circle ``resolve`` draws it in.
|
|
151
|
+
check: "M3 8.4l3.2 3.2L13 4.8",
|
|
152
|
+
lineage:
|
|
153
|
+
"M3.6 4.2h3.1a2 2 0 0 1 2 2v3.6a2 2 0 0 0 2 2h1.7M3.6 11.8h3.1M1.4 2.8a1.4 1.4 0 1 1 0 2.8 1.4 1.4 0 0 1 0-2.8zM1.4 10.4a1.4 1.4 0 1 1 0 2.8 1.4 1.4 0 0 1 0-2.8zM13.2 10.4a1.4 1.4 0 1 1 0 2.8 1.4 1.4 0 0 1 0-2.8z",
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/** What a {@link MenuIcon} takes. */
|
|
157
|
+
export interface MenuIconProps {
|
|
158
|
+
/** One of igni's own icons. */
|
|
159
|
+
name?: MenuIconName;
|
|
160
|
+
/**
|
|
161
|
+
* An SVG path, for an icon igni does not have.
|
|
162
|
+
*
|
|
163
|
+
* Here because the alternative is a closed union, and an extension
|
|
164
|
+
* cannot add a member to one. `PageKind` had the same problem and
|
|
165
|
+
* was opened for the same reason: what exists is decided at install
|
|
166
|
+
* time by what an administrator put on the machine, not at compile
|
|
167
|
+
* time by us.
|
|
168
|
+
*
|
|
169
|
+
* Drawn on a 16×16 grid, stroked rather than filled, to match. A
|
|
170
|
+
* path that assumes a different viewBox will look like it belongs
|
|
171
|
+
* to a different application, which is the one thing this whole
|
|
172
|
+
* package exists to prevent.
|
|
173
|
+
*/
|
|
174
|
+
path?: string;
|
|
175
|
+
/** Added to the element's classes, beside the one the theme gives it. */
|
|
176
|
+
className?: string;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* One of igni's own icons, drawn on a 16×16 grid.
|
|
181
|
+
*
|
|
182
|
+
* Every icon is drawn in one grammar: 16×16, strokes of the same
|
|
183
|
+
* weight, `currentColor`. A name that is not in the set draws nothing, rather
|
|
184
|
+
* than a broken box: the label says what the item does, and the icon
|
|
185
|
+
* is only how it is found.
|
|
186
|
+
*
|
|
187
|
+
* @param name — one of igni's own icons.
|
|
188
|
+
* @param path — an SVG path, for an icon igni does not have; it is
|
|
189
|
+
* drawn on the same 16×16 grid, stroked rather than filled.
|
|
190
|
+
* @param className — added to the element's classes, beside the one the
|
|
191
|
+
* theme gives it.
|
|
192
|
+
*/
|
|
193
|
+
export function MenuIcon({ name, path, className }: MenuIconProps) {
|
|
194
|
+
const d = path ?? (name ? PATHS[name] : undefined);
|
|
195
|
+
// An unknown name draws nothing rather than a broken box. The
|
|
196
|
+
// label is the thing that says what the item does; the icon is how
|
|
197
|
+
// it is found again.
|
|
198
|
+
if (!d) return null;
|
|
199
|
+
return (
|
|
200
|
+
<svg
|
|
201
|
+
className={className ? `menu-icon ${className}` : "menu-icon"}
|
|
202
|
+
viewBox="0 0 16 16"
|
|
203
|
+
aria-hidden="true"
|
|
204
|
+
focusable="false"
|
|
205
|
+
>
|
|
206
|
+
<path d={d} />
|
|
207
|
+
</svg>
|
|
208
|
+
);
|
|
209
|
+
}
|
package/src/Mermaid.tsx
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mermaid diagrams.
|
|
3
|
+
*
|
|
4
|
+
* ```mermaid``` becomes a diagram, in a document exactly as it
|
|
5
|
+
* already does in chat.
|
|
6
|
+
*
|
|
7
|
+
* **A fence, deliberately.** This is what lets a document carry a
|
|
8
|
+
* diagram while staying markdown: the source is a code block, so it
|
|
9
|
+
* diffs a line at a time, chunks for search, survives the editor's
|
|
10
|
+
* round trip untouched, and reads as its own source in any other
|
|
11
|
+
* markdown tool. The alternative — embedding HTML, or a bespoke
|
|
12
|
+
* node type — would cost every one of those. ``fenceInfo`` is the
|
|
13
|
+
* helper that spots one.
|
|
14
|
+
*
|
|
15
|
+
* Shared by the chat and the document view rather than copied.
|
|
16
|
+
* There was one mermaid renderer living inside ``ChatItems`` and a
|
|
17
|
+
* document could not reach it, which is the usual way two renderers
|
|
18
|
+
* of the same thing start disagreeing about what it looks like.
|
|
19
|
+
*
|
|
20
|
+
* **`mermaid` is a peer dependency**, loaded on demand. An
|
|
21
|
+
* extension that never renders a diagram never downloads it; one
|
|
22
|
+
* that does must have it installed. This is the only export under
|
|
23
|
+
* the floor that asks anything of your package.json.
|
|
24
|
+
*
|
|
25
|
+
* ``SpecBlock`` used to live here and does not any more: it reaches
|
|
26
|
+
* into the app for the ``json-render`` renderer, so it could not be
|
|
27
|
+
* published without publishing that too. It is app code now.
|
|
28
|
+
*/
|
|
29
|
+
import { useEffect, useRef, useState } from "react";
|
|
30
|
+
|
|
31
|
+
import { CopySource } from "./CopySource.js";
|
|
32
|
+
|
|
33
|
+
type MermaidTheme = "default" | "dark";
|
|
34
|
+
|
|
35
|
+
interface MermaidConfig {
|
|
36
|
+
startOnLoad: boolean;
|
|
37
|
+
securityLevel: "strict";
|
|
38
|
+
theme: MermaidTheme;
|
|
39
|
+
themeVariables: { fontFamily: string; background: string };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface MermaidLib {
|
|
43
|
+
initialize: (config: MermaidConfig) => void;
|
|
44
|
+
render: (id: string, src: string) => Promise<{ svg: string }>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Mermaid draws into a scratch element by id, and the id becomes the
|
|
48
|
+
// SVG's own and scopes the <style> it injects. One counter for the
|
|
49
|
+
// page, so no two renders anywhere on it share one — not across
|
|
50
|
+
// blocks, not across React roots, not across an edit in flight.
|
|
51
|
+
let mermaidId = 0;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A mermaid theme matching igni's.
|
|
55
|
+
*
|
|
56
|
+
* ``default`` is the colourful light palette and ``dark`` its dark
|
|
57
|
+
* counterpart. Both run in colour — ``neutral``, which reads like
|
|
58
|
+
* the safe choice, is what made every diagram grey.
|
|
59
|
+
*/
|
|
60
|
+
function mermaidTheme(): MermaidTheme {
|
|
61
|
+
if (typeof document === "undefined") return "default";
|
|
62
|
+
const explicit = document.documentElement.dataset.theme;
|
|
63
|
+
if (explicit === "dark") return "dark";
|
|
64
|
+
if (explicit === "light") return "default";
|
|
65
|
+
if (typeof window !== "undefined" && window.matchMedia) {
|
|
66
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches
|
|
67
|
+
? "dark"
|
|
68
|
+
: "default";
|
|
69
|
+
}
|
|
70
|
+
return "default";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Mermaid, configured for the theme in force right now.
|
|
75
|
+
*
|
|
76
|
+
* Mermaid is about 700KB, so it arrives only if a document has one;
|
|
77
|
+
* the bundler caches the module, so asking again costs nothing.
|
|
78
|
+
* Configured on every call rather than once, because the theme is
|
|
79
|
+
* read when it is configured — a diagram drawn after a switch to
|
|
80
|
+
* dark has to be drawn in dark.
|
|
81
|
+
*/
|
|
82
|
+
export async function loadMermaid(): Promise<MermaidLib> {
|
|
83
|
+
// Inline on purpose: `mermaid` is an optional peer dependency.
|
|
84
|
+
const lib = (await import("mermaid")).default as unknown as MermaidLib;
|
|
85
|
+
lib.initialize({
|
|
86
|
+
startOnLoad: false,
|
|
87
|
+
securityLevel: "strict",
|
|
88
|
+
theme: mermaidTheme(),
|
|
89
|
+
themeVariables: {
|
|
90
|
+
fontFamily: "var(--font-ui)",
|
|
91
|
+
background: "transparent",
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
return lib;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A mermaid diagram.
|
|
99
|
+
*
|
|
100
|
+
* `source` is the text inside the fence. A diagram that does not
|
|
101
|
+
* parse is shown as its own source rather than as a blank box: it is
|
|
102
|
+
* usually a diagram somebody is halfway through writing.
|
|
103
|
+
*
|
|
104
|
+
* @param source — the text inside the fence.
|
|
105
|
+
*/
|
|
106
|
+
export function MermaidBlock({ source }: { source: string }) {
|
|
107
|
+
const frame = useRef<HTMLDivElement>(null);
|
|
108
|
+
const [error, setError] = useState<string | null>(null);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
let cancelled = false;
|
|
112
|
+
setError(null);
|
|
113
|
+
void loadMermaid()
|
|
114
|
+
.then((lib) => lib.render(`mermaid-${++mermaidId}`, source))
|
|
115
|
+
.then(({ svg }) => {
|
|
116
|
+
if (cancelled || !frame.current) return;
|
|
117
|
+
frame.current.innerHTML = svg;
|
|
118
|
+
})
|
|
119
|
+
.catch((e: unknown) => {
|
|
120
|
+
if (cancelled) return;
|
|
121
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
122
|
+
});
|
|
123
|
+
return () => {
|
|
124
|
+
cancelled = true;
|
|
125
|
+
};
|
|
126
|
+
}, [source]);
|
|
127
|
+
|
|
128
|
+
if (error) {
|
|
129
|
+
// The source, not a blank box. A diagram that does not parse is
|
|
130
|
+
// usually a diagram somebody is halfway through writing, and
|
|
131
|
+
// hiding what they wrote is the least helpful response to that.
|
|
132
|
+
return (
|
|
133
|
+
<pre className="mermaid-error" title={`Mermaid render failed: ${error}`}>
|
|
134
|
+
{source}
|
|
135
|
+
</pre>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return (
|
|
139
|
+
<div className="mermaid-diagram">
|
|
140
|
+
<CopySource source={source} />
|
|
141
|
+
<div ref={frame} />
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
}
|
package/src/Monogram.tsx
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two letters standing in for a face.
|
|
3
|
+
*
|
|
4
|
+
* Not an avatar. Nothing in the product stores an uploaded picture —
|
|
5
|
+
* there is no `avatar_url` on a user anywhere in the server — and a
|
|
6
|
+
* generic silhouette for everybody says strictly less than two
|
|
7
|
+
* letters of somebody's own name. The portal draws the same thing
|
|
8
|
+
* from the same source, so the two surfaces agree about what a person
|
|
9
|
+
* looks like.
|
|
10
|
+
*
|
|
11
|
+
* The colour is derived from the name rather than chosen, so the same
|
|
12
|
+
* person is the same colour on every machine and across restarts.
|
|
13
|
+
* That is the whole point: the monogram is a recognition aid, and one
|
|
14
|
+
* that changed colour per session would be decoration.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export function initialsOf(name: string): string {
|
|
18
|
+
const cleaned = (name || "").trim();
|
|
19
|
+
if (!cleaned) return "?";
|
|
20
|
+
|
|
21
|
+
// An address is not a name: "maya@acme.test" should read as M, not
|
|
22
|
+
// as MA from "maya" and "acme".
|
|
23
|
+
const local = cleaned.includes("@") ? cleaned.split("@")[0] : cleaned;
|
|
24
|
+
const words = local.split(/[\s._-]+/).filter(Boolean);
|
|
25
|
+
if (words.length === 0) return "?";
|
|
26
|
+
// By code point: slicing by UTF-16 unit cuts an emoji in half.
|
|
27
|
+
const letters = (word: string) => Array.from(word);
|
|
28
|
+
if (words.length === 1) {
|
|
29
|
+
return letters(words[0]).slice(0, 2).join("").toUpperCase();
|
|
30
|
+
}
|
|
31
|
+
const last = words[words.length - 1];
|
|
32
|
+
return (letters(words[0])[0] + letters(last)[0]).toUpperCase();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A stable hue for a name. Same person, same colour, every time. */
|
|
36
|
+
export function hueOf(name: string): number {
|
|
37
|
+
let hash = 0;
|
|
38
|
+
for (const ch of name || "") {
|
|
39
|
+
hash = (hash * 31 + ch.charCodeAt(0)) % 360;
|
|
40
|
+
}
|
|
41
|
+
return hash;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The same colour, written as ``#rrggbb``.
|
|
46
|
+
*
|
|
47
|
+
* For the places that cannot take ``hsl()``. The collaborative
|
|
48
|
+
* caret is one: it validates against ``/^#[0-9a-fA-F]{6}$/`` and
|
|
49
|
+
* quietly renders anything else transparent — a cursor that is
|
|
50
|
+
* there, labelled with the right name, and invisible.
|
|
51
|
+
*
|
|
52
|
+
* Derived from the same hue as the monogram, so somebody's caret and
|
|
53
|
+
* their initials are the same colour.
|
|
54
|
+
*/
|
|
55
|
+
export function hexOf(
|
|
56
|
+
name: string,
|
|
57
|
+
saturation = 0.62,
|
|
58
|
+
lightness = 0.52,
|
|
59
|
+
): string {
|
|
60
|
+
const hue = hueOf(name) / 360;
|
|
61
|
+
const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
|
|
62
|
+
const second = chroma * (1 - Math.abs(((hue * 6) % 2) - 1));
|
|
63
|
+
const base = lightness - chroma / 2;
|
|
64
|
+
const sixth = Math.floor(hue * 6) % 6;
|
|
65
|
+
const [r, g, b] = (
|
|
66
|
+
[
|
|
67
|
+
[chroma, second, 0],
|
|
68
|
+
[second, chroma, 0],
|
|
69
|
+
[0, chroma, second],
|
|
70
|
+
[0, second, chroma],
|
|
71
|
+
[second, 0, chroma],
|
|
72
|
+
[chroma, 0, second],
|
|
73
|
+
] as const
|
|
74
|
+
)[sixth];
|
|
75
|
+
const byte = (value: number) =>
|
|
76
|
+
Math.round((value + base) * 255)
|
|
77
|
+
.toString(16)
|
|
78
|
+
.padStart(2, "0");
|
|
79
|
+
return `#${byte(r)}${byte(g)}${byte(b)}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Two letters standing in for a face.
|
|
84
|
+
*
|
|
85
|
+
* Not an avatar: nothing stores an uploaded picture, so the two
|
|
86
|
+
* letters come from the name. The colour comes from the name too, so
|
|
87
|
+
* the same person is the same colour on every machine and across
|
|
88
|
+
* restarts.
|
|
89
|
+
*
|
|
90
|
+
* @param name — the name the initials and the colour are derived from.
|
|
91
|
+
* @param size — the width and height of the square, in pixels.
|
|
92
|
+
*/
|
|
93
|
+
export function Monogram({ name, size = 18 }: { name: string; size?: number }) {
|
|
94
|
+
const hue = hueOf(name);
|
|
95
|
+
return (
|
|
96
|
+
<span
|
|
97
|
+
className="monogram"
|
|
98
|
+
aria-hidden="true"
|
|
99
|
+
style={{
|
|
100
|
+
width: size,
|
|
101
|
+
height: size,
|
|
102
|
+
fontSize: Math.round(size * 0.46),
|
|
103
|
+
// Fixed saturation and lightness so every generated colour
|
|
104
|
+
// clears contrast against white text, rather than hoping the
|
|
105
|
+
// hash lands somewhere readable.
|
|
106
|
+
background: `hsl(${hue} 42% 42%)`,
|
|
107
|
+
}}
|
|
108
|
+
>
|
|
109
|
+
{initialsOf(name)}
|
|
110
|
+
</span>
|
|
111
|
+
);
|
|
112
|
+
}
|