@charcuterie/ui 4.30.0 → 4.31.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.
Files changed (117) hide show
  1. package/README.md +7 -2
  2. package/docs/README.md +573 -0
  3. package/docs/building-an-app.md +231 -0
  4. package/docs/components/Accordion.md +106 -0
  5. package/docs/components/ActionMenu.md +63 -0
  6. package/docs/components/ActionTiles.md +233 -0
  7. package/docs/components/AdaptiveGrid.md +215 -0
  8. package/docs/components/Alert.md +99 -0
  9. package/docs/components/AnchorLink.md +23 -0
  10. package/docs/components/Avatar.md +153 -0
  11. package/docs/components/Badge.md +81 -0
  12. package/docs/components/BadgeButton.md +84 -0
  13. package/docs/components/Board.md +277 -0
  14. package/docs/components/Breadcrumbs.md +87 -0
  15. package/docs/components/Button.md +72 -0
  16. package/docs/components/ButtonLink.md +81 -0
  17. package/docs/components/Card.md +114 -0
  18. package/docs/components/CatalogPicker.md +250 -0
  19. package/docs/components/Chart.md +39 -0
  20. package/docs/components/Checkbox.md +197 -0
  21. package/docs/components/ColorPicker.md +99 -0
  22. package/docs/components/ColorSchemeSwitcher.md +92 -0
  23. package/docs/components/ColorSchemeToggle.md +98 -0
  24. package/docs/components/Combobox.md +175 -0
  25. package/docs/components/CommandPalette.md +120 -0
  26. package/docs/components/ComparisonChart.md +31 -0
  27. package/docs/components/CopyButton.md +112 -0
  28. package/docs/components/DataTable.md +170 -0
  29. package/docs/components/DatePicker.md +225 -0
  30. package/docs/components/Dialog.md +134 -0
  31. package/docs/components/DropRail.md +107 -0
  32. package/docs/components/EmptyState.md +65 -0
  33. package/docs/components/Field.md +215 -0
  34. package/docs/components/FieldGroup.md +45 -0
  35. package/docs/components/FileDropZone.md +98 -0
  36. package/docs/components/GroupedList.md +189 -0
  37. package/docs/components/Header.md +76 -0
  38. package/docs/components/HtmlEditor-html-editor.md +76 -0
  39. package/docs/components/HtmlView-html-editor.md +47 -0
  40. package/docs/components/HtmlView-html-view.md +47 -0
  41. package/docs/components/IconButton.md +52 -0
  42. package/docs/components/LaneTimeline.md +254 -0
  43. package/docs/components/Lightbox.md +101 -0
  44. package/docs/components/Listbox.md +109 -0
  45. package/docs/components/LiveStatusIndicator.md +60 -0
  46. package/docs/components/LogViewer.md +142 -0
  47. package/docs/components/Main.md +247 -0
  48. package/docs/components/MarkdownEditor.md +262 -0
  49. package/docs/components/MarkdownEditorCodeMirror-markdown-editor-codemirror.md +230 -0
  50. package/docs/components/MarkdownLine.md +187 -0
  51. package/docs/components/MarkdownView-markdown-editor-codemirror.md +235 -0
  52. package/docs/components/MediaTile.md +106 -0
  53. package/docs/components/Menu.md +209 -0
  54. package/docs/components/MetricCard.md +38 -0
  55. package/docs/components/Modal.md +89 -0
  56. package/docs/components/Nav.md +167 -0
  57. package/docs/components/NavBar.md +190 -0
  58. package/docs/components/Picker.md +132 -0
  59. package/docs/components/Popover.md +135 -0
  60. package/docs/components/PortraitTiles.md +169 -0
  61. package/docs/components/ProgressBar.md +70 -0
  62. package/docs/components/ProgressCard.md +65 -0
  63. package/docs/components/QueryBuilder.md +132 -0
  64. package/docs/components/RadioGroup.md +165 -0
  65. package/docs/components/Rail.md +79 -0
  66. package/docs/components/RangeSlider.md +144 -0
  67. package/docs/components/ReactRouterAdapter-react-router.md +27 -0
  68. package/docs/components/ReactRouterLink-react-router.md +23 -0
  69. package/docs/components/ReorderList.md +143 -0
  70. package/docs/components/RouterLinkProvider.md +33 -0
  71. package/docs/components/ScheduleBoard.md +41 -0
  72. package/docs/components/ScrollMemoryProvider.md +33 -0
  73. package/docs/components/SearchInput.md +46 -0
  74. package/docs/components/SegmentedControl.md +98 -0
  75. package/docs/components/Select.md +169 -0
  76. package/docs/components/Shell.md +162 -0
  77. package/docs/components/Skeleton.md +48 -0
  78. package/docs/components/Slider.md +128 -0
  79. package/docs/components/SortableTableHeader.md +84 -0
  80. package/docs/components/Spinner.md +50 -0
  81. package/docs/components/Stepper.md +121 -0
  82. package/docs/components/Swatch.md +79 -0
  83. package/docs/components/Switch.md +80 -0
  84. package/docs/components/TableColumns.md +29 -0
  85. package/docs/components/TableViewport.md +42 -0
  86. package/docs/components/Tabs.md +184 -0
  87. package/docs/components/TextLink.md +106 -0
  88. package/docs/components/TimecodeInput.md +222 -0
  89. package/docs/components/Toast.md +108 -0
  90. package/docs/components/ToastRegion.md +35 -0
  91. package/docs/components/Toolbar.md +118 -0
  92. package/docs/components/Tooltip.md +94 -0
  93. package/docs/components/UnstyledLink.md +21 -0
  94. package/docs/components/ValuePairs.md +30 -0
  95. package/docs/components/VirtualizedGrid.md +204 -0
  96. package/docs/components/VisuallyHidden.md +39 -0
  97. package/docs/components/WeekdayIndicator.md +39 -0
  98. package/docs/hooks/useAdaptiveColumns.md +111 -0
  99. package/docs/hooks/useCommandPalette.md +40 -0
  100. package/docs/hooks/useCommandPaletteHotkeys.md +33 -0
  101. package/docs/hooks/useDeploymentUpdate.md +39 -0
  102. package/docs/hooks/useLastPresentValue.md +23 -0
  103. package/docs/hooks/useListMotion.md +65 -0
  104. package/docs/hooks/useNavLayout.md +59 -0
  105. package/docs/hooks/usePresence.md +39 -0
  106. package/docs/hooks/useRouterLink.md +22 -0
  107. package/docs/hooks/useValueChangeMotion.md +28 -0
  108. package/package.json +7 -5
  109. package/skills/charcuterie/SKILL.md +17 -0
  110. package/skills/charcuterie/references/build-a-screen.md +6 -0
  111. package/skills/charcuterie/references/create-a-component.md +6 -0
  112. package/src/AdaptiveGrid/AdaptiveGrid.stories.tsx +1 -1
  113. package/src/Tabs/Tabs.stories.tsx +1 -1
  114. package/src/VirtualizedGrid/VirtualizedGrid.stories.tsx +65 -28
  115. package/src/VirtualizedGrid/VirtualizedGrid.test.tsx +29 -0
  116. package/src/shell.storyHelpers.tsx +3 -3
  117. package/src/sourceRules.test.ts +16 -2
@@ -0,0 +1,262 @@
1
+ # MarkdownEditor
2
+
3
+ ```ts
4
+ import { MarkdownEditor } from "@charcuterie/ui"
5
+ ```
6
+
7
+ A live hybrid markdown editor whose stored value is markdown and **only** markdown.
8
+
9
+ Docket asked for this one and its requirement is unusually sharp, because the tracker it
10
+ replaces destroyed data by storing HTML in a field it later read back as text. So the
11
+ constraint is not "prefer markdown" — it is that an HTML tag must not be *able* to reach the
12
+ stored string.
13
+
14
+ > **Reading rather than editing?** `isReadOnly` here leaves the toolbar on screen, because it
15
+ > means "an editor you cannot type in". A surface with no toolbar in the DOM is
16
+ > [`MarkdownView`](MarkdownView-markdown-editor-codemirror.md), in the
17
+ > `@charcuterie/ui/markdown-editor-codemirror` subpath.
18
+
19
+ ## No HTML can reach the value, by construction
20
+
21
+ Four properties, and none of them is a rule somebody has to remember:
22
+
23
+ - the editing surface is a `<textarea>`, which takes **`text/plain`** off the clipboard and
24
+ nothing else. Copy a styled paragraph out of a browser and the `text/html` flavour is
25
+ simply never read;
26
+ - every command in `markdownCommands.ts` returns markdown. There is no serialiser and no
27
+ intermediate document model anywhere in the component;
28
+ - the painted layer emits `{ kind, text }` spans that React renders as **text nodes**. No
29
+ `innerHTML`, no sanitiser, and nothing to get wrong — a `<script>` in the source is a
30
+ handful of coloured characters on screen;
31
+ - image insertion escapes its alt text and brackets a dirty URL, so a filename with a `]` in
32
+ it cannot end the construct early.
33
+
34
+ `markdownCommands.test.ts` runs every command over a value full of tags and entities and
35
+ asserts each fragment survives **verbatim** — not "contains no `&lt;`", because the fixture
36
+ deliberately contains `&lt;` as literal text and a naive absence check would pass on an
37
+ escaped value and fail on a correct one.
38
+
39
+ ## Why a `<textarea>` and not an editor core
40
+
41
+ Charcuterie is published, so a dependency here is a permanent cost to every consumer.
42
+ Measured on this machine — `esbuild --bundle --minify`, React external, gzip -9:
43
+
44
+ | Candidate | minified | gzipped |
45
+ | --- | --- | --- |
46
+ | TipTap 3.30 + starter kit + `tiptap-markdown` | 720 KB | **238 KB** |
47
+ | CodeMirror 6 (`basicSetup` + `lang-markdown`) | 609 KB | **206 KB** |
48
+ | CodeMirror 6, hand-assembled minimum | 512 KB | **176 KB** |
49
+ | Lexical 0.49 + markdown/list/link/code nodes | 449 KB | **148 KB** |
50
+ | **This component** | — | **0 KB added** |
51
+
52
+ The full argument, including what the choice gives up and what would justify reversing it,
53
+ is in
54
+ [`docs/decisions/2026-08-19-the-markdown-editor-is-a-textarea-with-a-painted-layer.md`](https://github.com/Sawtaytoes/charcuterie/blob/master/docs/decisions/2026-08-19-the-markdown-editor-is-a-textarea-with-a-painted-layer.md).
55
+
56
+ The accessibility half of it is the half that is hard to buy back later. A `<textarea>`
57
+ arrives with caret movement, word-wise selection, `Home`/`End`, IME composition, spellcheck,
58
+ autocorrect, the platform's own undo stack, `role="textbox"` and `aria-multiline="true"` —
59
+ all of it, in every browser, tested by the vendors. A `contenteditable` starts with none of
60
+ those and re-earns each one, and the ones it never fully re-earns are IME and undo.
61
+
62
+ ## The painted layer, and the geometry that constrains it
63
+
64
+ The surface is a real `<textarea>` with a painted layer behind it in the **same grid cell**.
65
+ The textarea owns the caret, the selection, the undo stack and the IME; the layer owns the
66
+ colour. Its text is transparent and its `caret-color` is not, which is what `caret-color`
67
+ exists for.
68
+
69
+ That only works while the two layers **lay out identically**, so:
70
+
71
+ - the tokenizer keeps **every character**. It never trims, never normalises a tab, never
72
+ drops an unterminated marker. `markdownSpans.test.ts` joins every span back together and
73
+ asserts it reproduces the source byte for byte;
74
+ - every span style is **metric-neutral**. Bold is faux bold — `text-shadow` at ±0.02em paints
75
+ the glyph twice, a hair apart, which thickens it and moves nothing. Italic is real, because
76
+ the surface is monospaced and a monospaced italic keeps the advance width by definition.
77
+ Headings get weight and colour rather than size. `MarkdownEditor.test.tsx` **measures** each
78
+ one against plain text and fails if any of them is wider.
79
+
80
+ The honest limit follows from the same constraint: **markers are dimmed, not hidden.**
81
+ Concealing `**` would change the line's width and there is no way to do it in this medium.
82
+ So "raw syntax on the cursor's line" becomes a contrast change — muted markers everywhere,
83
+ accent markers on the line the caret is on — and true concealment is the staged follow-up,
84
+ which needs a decoration-capable surface (CodeMirror 6) and would arrive as an **optional
85
+ subpath** so consumers that do not use it keep paying nothing.
86
+
87
+ ## Uncontrolled, and that is not a shortcut
88
+
89
+ `defaultValue` in, `onChange` out — the same contract as `Select`, and here it protects
90
+ something specific. A controlled React `<textarea>` round-trips every keystroke through
91
+ render, and any programmatic `value` assignment **wipes the browser's undo stack**: Ctrl+Z
92
+ after a toolbar click then skips the paragraph you typed before it, or does nothing at all.
93
+
94
+ So the textarea is never handed a `value`. Its text is mirrored into state for *painting*
95
+ only, and every programmatic edit is applied as a range replacement through
96
+ `document.execCommand("insertText")` — deprecated, and still the only API that appends to
97
+ the native undo stack. `getMinimalEdit` is what turns a command's whole-string result back
98
+ into that range, so a bold toggle is **one** undo step over four characters rather than a
99
+ document-sized one.
100
+
101
+ A consumer that must swap the whole document — Docket opening a different task — remounts
102
+ with a `key`. That is one line, and it is honest about the fact that the old undo history
103
+ belonged to the old document.
104
+
105
+ ## Put an image at the cursor — paste, drop, or press **Image**
106
+
107
+
108
+
109
+ **The component owns no storage.** It hands you a `File`, waits, and inserts the URL you
110
+ return as `![alt](url)` at the caret. Docket keeps its own blob storage precisely so the URL
111
+ stays stable and theirs.
112
+
113
+ While the request is in flight the document holds a **markdown placeholder** —
114
+ `![Uploading rack.png](#uploading-1)` — rather than an overlay, because the user keeps typing
115
+ during an upload and the insertion point has to move with what they type. It carries a
116
+ counter so two files of the same name do not resolve into each other's slot, and a failed
117
+ upload leaves a document the user can read and fix rather than a dangling widget.
118
+
119
+ Omit `onUploadImage` and none of the three is offered — no toolbar button, and a paste left
120
+ to the browser. A `<textarea>` ignores a pasted image on its own, which is the correct
121
+ fallback rather than a broken one.
122
+
123
+ ### The **Image** button, and why it is in the toolbar
124
+
125
+ Paste and drop are both mouse-and-keyboard gestures. On a tablet there is nothing to paste
126
+ from and nothing to drag, so wiring `onUploadImage` also puts an **Image** action in the
127
+ toolbar: it opens the platform file picker, which on a phone is where the camera is offered.
128
+
129
+ It is a toolbar action rather than a `FileDropZone` under the box **because of the caret**.
130
+ Pressing anything outside the editor moves focus out of it, so a control beside the editor
131
+ can only append to the end of the document — and an image in prose belongs at the point it
132
+ is explained, not stapled to the bottom. The `<textarea>` keeps its `selectionStart` while
133
+ blurred, so the insertion lands where the user last was.
134
+
135
+ **It is the fourth action, and the position is load-bearing.** `Toolbar` overflows from the
136
+ **end** of the list, so the order in that list is the priority order. Placed last — beside
137
+ Link, where it reads most naturally — Image was the first thing to collapse, hidden behind
138
+ "More actions" at 900px. A control nobody can find does not fix "adding an image is buried";
139
+ it moves the problem. Fourth is visible wherever four actions fit, and it reads as a group:
140
+ emphasis, structure, insert.
141
+
142
+ ⚠️ **It still collapses on a genuinely narrow editor, and that is not a bug to route around.**
143
+ Measured on the `Interactive` story: at 900px the bar carries eight actions and Image is one
144
+ of them; at 460px it carries three, and everything after Heading is in the overflow. A
145
+ comment box in a rail is that width. Keep a `FileDropZone` beside such an editor as well —
146
+ appending to the end of the document is the right trade when the alternative is a control
147
+ nobody can reach.
148
+
149
+ ## Composition, and the one component that did not fit
150
+
151
+ The toolbar is this package's `Toolbar`, so the row collapses into a **menu by measurement**
152
+ rather than at a breakpoint — which is what the Narrow View actually needs, since a lane in a
153
+ three-up board is narrow on a 4K display. `Field` wraps it through `SlotProps`, so a label, a
154
+ description and an error wire themselves to the `<textarea>` rather than stopping at this
155
+ component.
156
+
157
+ `FileDropZone` does **not** wrap it, and that is the interesting one. That component is a
158
+ `<label>` around a file input covering its whole area — correct for "drop a disc image here",
159
+ and wrong for a text surface, where the drop has to land *at a character offset* and the area
160
+ has to keep taking clicks as caret placement. So the editor handles its own drop, and
161
+ `FileDropZone` stays the right answer for the attachment list beside it — and for a
162
+ narrow editor whose toolbar has collapsed the Image action away.
163
+
164
+ ## The toolbar is words until you bring icons
165
+
166
+ The bar defaults to word buttons because this package ships **no icons**, and words render
167
+ in every font on every target. Pass an `icons` bag and the row fits as glyphs, keeping the
168
+ words as the accessible names and as the labels of whatever still collapses into the menu.
169
+
170
+ `icons.overflow` is the tenth key. It is the **bar's own** trigger rather than a markdown
171
+ command, and it is in the same bag so that an app cannot pass nine glyphs and be left with
172
+ the words "More actions" at the end of the row.
173
+
174
+ ## Keyboard
175
+
176
+ | Key | Does |
177
+ | --- | --- |
178
+ | `Ctrl`/`Cmd` + `B` | Bold, and un-bold |
179
+ | `Ctrl`/`Cmd` + `I` | Italic |
180
+ | `Ctrl`/`Cmd` + `E` | Inline code |
181
+ | `Ctrl`/`Cmd` + `K` | Link, caret parked in the destination |
182
+ | `Ctrl`/`Cmd` + `]` / `[` | Indent / outdent the selected lines |
183
+ | `Enter` | Continues a list, a task list or a quote — and **clears** an empty item |
184
+ | `Tab` | Moves focus. Always. |
185
+
186
+ **`Tab` is never captured**, at any time. Indenting with Tab is the convention in editors
187
+ that own the whole page, and inside a form it is a keyboard trap: WCAG 2.1.2 wants focus to
188
+ be able to leave every component with the standard gesture, and a multi-line field on a task
189
+ form is exactly where somebody tabs onward.
190
+
191
+ Enter returns *nothing to do* rather than an unchanged state when the caret is not in a list,
192
+ so the keypress falls through to the browser and lands on the native undo stack as an
193
+ ordinary typing step.
194
+
195
+ ## What this deliberately does not parse
196
+
197
+ The tokenizer resolves **one line at a time**, carrying exactly one bit of cross-line state:
198
+ whether we are inside a fenced code block. Painting re-runs on every keystroke, so the cost
199
+ has to be linear in the line rather than in the document — and a mis-coloured marker is
200
+ cosmetic while a mis-*placed* one is a broken editor.
201
+
202
+ So these colour as plain text: setext headings (`Title` over `=====`), indented four-space
203
+ code blocks, reference links (`[a][b]`), autolinks in angle brackets, and emphasis that spans
204
+ a line break. They all still **store** correctly, because the stored value is the textarea's
205
+ and not the tokenizer's.
206
+
207
+ ## Example from the stories
208
+
209
+ See the full [story example](../../src/MarkdownEditor/MarkdownEditor.stories.tsx).
210
+
211
+ ```tsx
212
+ <MarkdownEditor defaultValue="- [ ] It **works**" />
213
+ ```
214
+
215
+ ## Published TypeScript API
216
+
217
+ ```ts
218
+ const MarkdownEditor: ({ className, defaultValue, icons, isDisabled, isReadOnly, label, onChange, onUploadError, onUploadImage, placeholder, toolbarLabel, ...receivedSlotProps }: MarkdownEditorProps) => ReactNode
219
+
220
+ type MarkdownEditorProps = SlotProps & {
221
+ className?: string;
222
+ /**
223
+ * **Initial** only. This control is uncontrolled, and the long
224
+ * reason is in the doc comment below — it is the whole design.
225
+ */
226
+ defaultValue?: string;
227
+ /** See `MarkdownEditorIcons`. */
228
+ icons?: MarkdownEditorIcons;
229
+ isDisabled?: boolean;
230
+ isReadOnly?: boolean;
231
+ /**
232
+ * The accessible name, as `aria-label`. Omit it inside a `Field`,
233
+ * which supplies a real `<label htmlFor>` — same contract as
234
+ * `Select`.
235
+ */
236
+ label?: string;
237
+ onChange?: (value: string) => void;
238
+ /**
239
+ * A failed upload, after the placeholder has been taken back out
240
+ * of the text. Pair it with a `Toast`; this component does not
241
+ * own one.
242
+ */
243
+ onUploadError?: (file: File, error: unknown) => void;
244
+ /**
245
+ * Paste or drop an image and this runs. **The component does not
246
+ * own storage** — it hands you a `File`, you put it somewhere,
247
+ * and the URL you return is inserted at the caret as
248
+ * `![alt](url)`. Docket keeps its own blob storage precisely so
249
+ * the URL stays stable and theirs.
250
+ *
251
+ * Omit it and image paste is simply not offered: a `<textarea>`
252
+ * ignores a pasted image on its own, which is the correct
253
+ * fallback rather than a broken one.
254
+ */
255
+ onUploadImage?: (file: File) => Promise<MarkdownImageUpload>;
256
+ placeholder?: string;
257
+ /** The editing surface's accessible name in the toolbar's label. */
258
+ toolbarLabel?: string;
259
+ };
260
+ ```
261
+
262
+ [Full declarations](../../dist/MarkdownEditor/MarkdownEditor.d.ts)
@@ -0,0 +1,230 @@
1
+ # MarkdownEditorCodeMirror
2
+
3
+ ```ts
4
+ import { MarkdownEditorCodeMirror } from "@charcuterie/ui/markdown-editor-codemirror"
5
+ ```
6
+
7
+ Obsidian-style live preview: markers conceal themselves once the caret leaves, headings are
8
+ genuinely larger, images render in place, task boxes are real checkboxes — and the stored
9
+ value is still markdown, byte for byte.
10
+
11
+ It is **opt-in**, from a subpath:
12
+
13
+ ```tsx
14
+ import { MarkdownEditorCodeMirror } from "@charcuterie/ui/markdown-editor-codemirror"
15
+ ```
16
+
17
+ ## Reading, not editing
18
+
19
+ `isReadOnly` here means *an editor you cannot type in*: the toolbar stays, drawn in its
20
+ disabled colours above a document nobody is editing. That is right for a form field that is
21
+ temporarily locked, and wrong for reading a file.
22
+
23
+ For reading, take **[`MarkdownView`](MarkdownView-markdown-editor-codemirror.md)** from
24
+ this same subpath. It has no toolbar in the DOM at all, it is controlled rather than
25
+ uncontrolled, its content is a `role="article"` instead of a `role="textbox"`, and it renders
26
+ **identically** to this component because it is the same code — same range rules, same theme.
27
+
28
+ ## Which of the two editors you want
29
+
30
+ `MarkdownEditor` is still the default, and most consumers should keep it.
31
+
32
+ | | `MarkdownEditor` | `MarkdownEditorCodeMirror` |
33
+ | --- | --- | --- |
34
+ | Surface | `<textarea>` + painted layer | CodeMirror 6 |
35
+ | New dependency | **none** | ~176 KB gz, optional peer |
36
+ | Markers | dimmed, never hidden | **concealed** until the caret arrives |
37
+ | Headings | weight and colour only | **actually larger** |
38
+ | Images | shown as `![alt](url)` | **rendered in place** |
39
+ | Tasks | shown as `- [ ]` | **checkbox you can click** |
40
+ | Bare URLs | painted as a URL | **clickable link** |
41
+ | Undo, IME, spellcheck | the platform's own | CodeMirror's |
42
+
43
+ Take the subpath when the description field is a **primary** surface of the app and the
44
+ bundle has room. Keep the default when it is one field on a form — a component library that
45
+ makes every consumer install an editor core to render a description has made the wrong
46
+ trade, and `castkit/packages/slatecast` has 60 KB gz of total budget to prove it.
47
+
48
+ ## Markdown is still the stored value
49
+
50
+ This is the part worth being exact about, because "WYSIWYG" usually means the opposite.
51
+
52
+ There is **no document model here and no serialiser**. CodeMirror's state holds the markdown
53
+ *text*. Live preview is a set of decorations *over* that text: concealing `**` hides two
54
+ characters that are still in the document, still in `onChange`, and still in whatever you
55
+ save. Replacing `![alt](url)` with an image does not rewrite the line — move the caret into
56
+ it and the markup is simply there again.
57
+
58
+ That is why this is not TipTap or Lexical. An editor core inverts the relationship: its
59
+ document model becomes authoritative and markdown becomes a lossy *export*, so any construct
60
+ the serialiser does not know about is silently dropped or silently becomes HTML. Docket
61
+ exists partly because HTML in a description field destroyed a previous tracker's data, and
62
+ an editor core would have been the easier build and the one thing that could not be allowed.
63
+
64
+ The [decision record][decision] has the measured bundle table and the full argument.
65
+
66
+ [decision]: https://github.com/Sawtaytoes/charcuterie/blob/master/docs/decisions/2026-08-19-the-markdown-editor-is-a-textarea-with-a-painted-layer.md
67
+
68
+ ## Concealment is the caret's answer, not the parser's
69
+
70
+ A construct reveals its markers when the selection **touches** it, and hides them again when
71
+ the selection leaves. Two consequences that are easy to mistake for bugs:
72
+
73
+ - **An unfocused editor reveals nothing.** There is no caret in a document nobody is editing,
74
+ so the resting offset of `0` deliberately does not count as "inside" the first construct.
75
+ Without this, a description that opens with a heading rendered its `#` on load and no other
76
+ heading's.
77
+ - **Reveal is per-construct, not per-line.** Two bold runs on one line reveal independently.
78
+
79
+ ## The "Markdown source" toggle
80
+
81
+ Nothing is concealed, nothing is replaced by a widget, no line is rescaled, and the surface
82
+ switches to monospace — because a source view is code. The syntax stays **coloured**: the
83
+ point of the toggle is to see the markup, not to lose the highlighting.
84
+
85
+ It is a `Switch` rather than a toolbar button because it is state, not a verb, and a
86
+ `ToolbarAction` renders a `Button` that announces nothing about being on.
87
+
88
+ ## What a mark does when it is hidden
89
+
90
+ Not every marker conceals, and the rule is narrower than "block marks stay":
91
+
92
+ > **A mark persists unless something else already says what it said.**
93
+
94
+ A blockquote gets an accent bar down its inline start, so its `>` is redundant and hides. A
95
+ fenced code block keeps its ` ``` ` and its language tag, because concealing them leaves a
96
+ blank line at the top and bottom of the block that reads as a rendering bug. A list bullet
97
+ stays, because hiding `-` turns an unordered list into indented prose — Obsidian substitutes
98
+ a `•`, which means choosing a width, and this component has no business choosing one.
99
+
100
+ ## Tables render, and the caret edits them
101
+
102
+ A table is the one construct on this surface whose meaning is *geometry*. Every other
103
+ decoration hangs on text CodeMirror draws anyway; a column cannot, because column two's text
104
+ is on four separate lines. So the pipes stop being drawn and a real `<table>` is drawn
105
+ instead — alignment from the delimiter row, and `**bold**`, `` `code` ``, links and images
106
+ rendering inside the cells exactly as they do in a paragraph.
107
+
108
+ **Click a cell and the markdown comes back with the caret in that cell.** That is the same
109
+ trade as a link or an image, and it is the only way in: you cannot edit a column you cannot
110
+ see. Arrow keys work too — Down from the line above enters at the top row, Up from below
111
+ enters at the bottom — because CodeMirror otherwise steps *over* a block widget and the
112
+ table would be unreachable without a mouse.
113
+
114
+ Three decisions worth knowing:
115
+
116
+ - **The widest row wins, not the header.** GFM drops cells past the header's width. An
117
+ editor that did the same would put text you typed on screen nowhere, so short rows gain
118
+ empty cells instead and nothing is ever hidden.
119
+ - **An empty cell keeps its column.** The parser emits no cell node for `| |`; the `|`
120
+ positions are what the columns are read from, so a blank cell does not shift the row.
121
+ - **A wide table scrolls inside its own block** rather than pushing the editor sideways.
122
+
123
+ `\|` — the only way to put a pipe *in* a cell — now conceals its backslash like any other
124
+ marker, in tables and everywhere else.
125
+
126
+ ## Clicking a link opens it
127
+
128
+ Obsidian's behaviour, not VS Code's: where the markup is hidden, a link that looks like a
129
+ link should act like one. Bare URLs count — GFM autolinks them, so a URL pasted into a
130
+ description is clickable with nothing typed around it.
131
+
132
+ The trade is real and worth stating: **you cannot click into link text to edit it.** Arrow in
133
+ from either edge, or flip the Markdown source toggle, which is exactly what it is for.
134
+
135
+ ## Pasting
136
+
137
+ - **An image** — pasted, dropped, or picked with the toolbar's **Image** action, which
138
+ appears only when `onUploadImage` is wired and is the only way in on a tablet — runs
139
+ `onUploadImage` and inserts `![alt](url)` at the caret, then
140
+ renders it in place. The component does not own storage — it hands you a `File`.
141
+ - **A URL over selected text** becomes `[selection](url)`, the way it does in every other
142
+ editor. Deliberately strict: one absolute `http(s)` URL and nothing else, because mangling
143
+ a literal paste is worse than not linkifying one.
144
+ - **Anything else** is left to the browser.
145
+
146
+ ## The toolbar is words until you bring icons
147
+
148
+ This package ships **no icons**, so the bar defaults to ten word buttons — which is a bar
149
+ that has already collapsed most of itself into "More actions" at the width a description
150
+ field actually gets. Pass an `icons` bag and the whole row fits, with the words kept as the
151
+ accessible names.
152
+
153
+ `icons.overflow` is the tenth key and the odd one out — it is the **bar's own** trigger,
154
+ not a markdown command. It is in the same bag because an app that passes the nine and not
155
+ the tenth gets nine glyphs followed by the words "More actions", and until now there was no
156
+ prop to fix that with.
157
+
158
+ ## Accessibility, and the honest cost
159
+
160
+ The `<textarea>` sibling gets caret movement, IME composition, spellcheck, the platform undo
161
+ stack and `role="textbox"` from the browser, tested by the vendors. A `contenteditable`
162
+ re-earns every one of those, and CodeMirror is the reason that is acceptable rather than
163
+ reckless — it is the most heavily exercised implementation of that re-earning there is. It is
164
+ still a re-implementation, and that is what this subpath costs beyond its bytes.
165
+
166
+ `Tab` is **never** captured, at any time. Indenting a list with Tab is the convention in
167
+ editors that own the whole page, and inside a form it is a keyboard trap — WCAG 2.1.2 wants
168
+ focus to leave every component with the standard gesture. Indent and outdent are `Ctrl+]` and
169
+ `Ctrl+[`. `indentWithTab` is the extension that would change this, and it is deliberately not
170
+ installed.
171
+
172
+ ## It is uncontrolled
173
+
174
+ `defaultValue` in, `onChange` out — the same contract as `Select` and as the sibling editor.
175
+ An `EditorView` owns the caret, the selection, the scroll position and the undo history, and
176
+ rebuilding it throws all four away, so the view is built exactly **once**. Props that can
177
+ legitimately change afterwards reach it through a compartment (`isReadOnly`, `isDisabled`) or
178
+ through a ref (the callbacks); the rest are frozen at mount.
179
+
180
+ To swap documents — Docket opening a different task — remount with a `key`. That is one line,
181
+ and it is honest about the old undo history belonging to the old document.
182
+
183
+ ## Example from the stories
184
+
185
+ See the full [story example](../../src/markdownEditorCodeMirror/MarkdownEditorCodeMirror.stories.tsx).
186
+
187
+ ```tsx
188
+ <MarkdownEditorCodeMirror defaultValue="Wired through `SlotProps`." />
189
+ ```
190
+
191
+ ## Published TypeScript API
192
+
193
+ ```ts
194
+ const MarkdownEditorCodeMirror: ({ className, defaultValue, icons, isDisabled, isRawModeDefault, isReadOnly, label, onChange, onUploadError, onUploadImage, placeholder, rawModeLabel, toolbarLabel, ...receivedSlotProps }: MarkdownEditorCodeMirrorProps) => ReactNode
195
+
196
+ type MarkdownEditorCodeMirrorProps = SlotProps & {
197
+ className?: string;
198
+ /**
199
+ * **Initial** only, and the same uncontrolled contract as the
200
+ * sibling `MarkdownEditor` — for the same reason, one layer over:
201
+ * reassigning the whole document from outside throws away the
202
+ * undo history that belonged to it. Swap documents with a `key`.
203
+ */
204
+ defaultValue?: string;
205
+ /** Start in raw-markdown mode. **Initial** only. */
206
+ isRawModeDefault?: boolean;
207
+ icons?: MarkdownEditorIcons;
208
+ isDisabled?: boolean;
209
+ isReadOnly?: boolean;
210
+ /**
211
+ * The accessible name. Omit it inside a `Field`, which supplies a
212
+ * real `<label htmlFor>`.
213
+ */
214
+ label?: string;
215
+ onChange?: (value: string) => void;
216
+ onUploadError?: (file: File, error: unknown) => void;
217
+ /**
218
+ * Paste or drop an image and this runs; the URL you return is
219
+ * inserted at the caret as `![alt](url)` — and, unlike the
220
+ * textarea sibling, is then **rendered in place**.
221
+ */
222
+ onUploadImage?: (file: File) => Promise<MarkdownImageUpload>;
223
+ placeholder?: string;
224
+ /** Label for the raw-markdown toggle. */
225
+ rawModeLabel?: string;
226
+ toolbarLabel?: string;
227
+ };
228
+ ```
229
+
230
+ [Full declarations](../../dist/markdownEditorCodeMirror/MarkdownEditorCodeMirror.d.ts)
@@ -0,0 +1,187 @@
1
+ # MarkdownLine
2
+
3
+ ```ts
4
+ import { MarkdownLine } from "@charcuterie/ui"
5
+ ```
6
+
7
+ **One line of markdown, drawn with its inline marks and nothing else.** Reach for it
8
+ wherever a stored string is a *name* rather than a document — a card title, a lane heading,
9
+ a table cell, a breadcrumb.
10
+
11
+ ## Why marks belong in a title
12
+
13
+ A grid of task names set in one flat weight is a wall. The parts that tell two cards apart —
14
+ the path, the urgency, the thing that is already done — are exactly the parts markdown would
15
+ have marked, so the marks are doing the same job the priority bar and the project colour do
16
+ one layer up: making a list **scannable**.
17
+
18
+ ## It is inline-only, and it is one line
19
+
20
+ | Rendered | Literal text |
21
+ | --- | --- |
22
+ | `**bold**`, `__bold__` | `# heading` |
23
+ | `*italic*`, `_italic_` | `- list item`, `1. list item` |
24
+ | `` `code` `` | `> blockquote` |
25
+ | `~~strikethrough~~` | `\| table \| row \|` |
26
+ | `[text](url)`, `<url>`, bare `https://…` and `www.…` | `![image](url)` |
27
+
28
+ A newline collapses to a space. Every surface that draws one of these clamps to one or two
29
+ lines anyway, so a hard break would only push the second half of a title out of a box that
30
+ was measured for one line.
31
+
32
+ ## File names are not markup
33
+
34
+ The case this component is most often asked to get wrong.
35
+
36
+ `ingest_the_files.sh` keeps its underscores because CommonMark's flanking rules say an
37
+ underscore **inside a word** opens nothing — the rule that makes `_` and `*` genuinely
38
+ different characters, and the one a hand-rolled "strip the markdown" regex always misses.
39
+ `2 * 3 * 4` is arithmetic for the same reason: a delimiter followed by a space cannot open.
40
+
41
+ ## `href` — a link inside a link
42
+
43
+ A card title is usually a link to the card, and a title may also *contain* a link. An anchor
44
+ inside an anchor is invalid HTML: the parser closes the outer one at the inner one's start
45
+ tag, so the text after the inner link silently stops opening the card. It looks completely
46
+ correct and half of it does not work.
47
+
48
+ So `href` is a prop rather than something you wrap the component in. Given one, the plain
49
+ runs become anchors to `href` and a markdown link stays a **sibling** anchor with its own
50
+ destination:
51
+
52
+
53
+
54
+ Consecutive runs sharing a destination are merged into one anchor, so `**Ship** it` is a
55
+ single tab stop and one entry in a screen reader's link list.
56
+
57
+ A markdown link **splits** the line into more than one anchor, and each is named by the words
58
+ it covers — `Ship`, `#53`, `tonight`. That is honest, and it is not good: `tonight` is a poor
59
+ name for a link to a task. Naming all three after the whole line was tried and is worse — two
60
+ links with the same name are ambiguous to anything driving the page by name, and this
61
+ library's own `expectAgentDrivable` refuses it. The conclusion is a design one rather than an
62
+ API one: **a link usually belongs in a task's description**, where it has a sentence around
63
+ it, rather than in its title.
64
+
65
+ An in-app destination goes through the injected `RouterLinkProvider`; an off-origin one
66
+ does not, and opens in a new tab. A title that names a pull request is a reference, and
67
+ following it should not lose the board the reader was on.
68
+
69
+ ## `isInsideLink` — when the card is already the link
70
+
71
+ The third and last answer to *who owns the link here*. `href` says this component does;
72
+ neither says the markdown links do; `isInsideLink` says **nobody** — draw the marks and emit
73
+ no anchor at all.
74
+
75
+ Reach for it whenever the line sits inside a link the caller already owns, which is what a
76
+ whole-card link is. The trap it closes has teeth even when no author ever typed a link: a
77
+ **bare URL autolinks**, so a captured note whose title ends in `https://…` would nest an
78
+ anchor without anybody writing `[]()`.
79
+
80
+ ## Anywhere a string is required
81
+
82
+ `aria-label`, `title`, `document.title`, a confirmation sentence — call `toPlainMarkdownText`
83
+ rather than writing a regex that strips the markup:
84
+
85
+ ```ts
86
+ import { toPlainMarkdownText } from "@charcuterie/ui"
87
+
88
+ document.title = `${toPlainMarkdownText(task.title)} — Docket`
89
+ ```
90
+
91
+ It is the **same parse** the component renders from, so it cannot drift. A second stripper is
92
+ how a card comes to read `Ingest 53 movies` while its own tooltip reads
93
+ ``Ingest 53 movies from `Downloads/MOVIES` ``.
94
+
95
+ ## A refused URL keeps its source
96
+
97
+ URLs cross `safeUrls.ts` — an allowlist of `http`, `https`, `mailto` and `tel` — before they
98
+ reach an `href`, the same module `MarkdownView` and the CodeMirror editor use. A scheme that
99
+ does not survive it produces **no anchor at all**, and every character of the source stays on
100
+ screen. A reader who can see `[click me](javascript:…)` is better served than one shown a
101
+ confident blue word that silently refuses to work.
102
+
103
+ ## Not a small `MarkdownView`
104
+
105
+ `MarkdownView` renders a *document*, through CodeMirror, from the optional
106
+ `@charcuterie/ui/markdown-editor-codemirror` entry point. Neither half suits a name: an
107
+ editor state, a syntax tree and a decoration set per card is an absurd price for forty
108
+ characters, and the main entry may not reach the CodeMirror stack at all.
109
+
110
+ So this is a second parser, which is worth being nervous about — two parsers are two answers
111
+ to "what does this markdown mean". Three things keep them honest: this one is **inline-only**,
112
+ so there is no block level to disagree about; both call the **same** URL guard; and the
113
+ flanking rules here are CommonMark's rather than a convenient approximation.
114
+
115
+ ## Example from the stories
116
+
117
+ See the full [story example](../../src/MarkdownLine/MarkdownLine.stories.tsx).
118
+
119
+ ```tsx
120
+ <MarkdownLine value="# 4 in the queue" />
121
+ ```
122
+
123
+ ## Published TypeScript API
124
+
125
+ ```ts
126
+ const MarkdownLine: ({ className, href, isInsideLink, value, }: MarkdownLineProps) => ReactNode
127
+
128
+ type MarkdownLineProps = {
129
+ className?: string;
130
+ /**
131
+ * Where the text that is **not** itself a link points — the task
132
+ * a card opens, usually.
133
+ *
134
+ * Given one, every plain run becomes its own anchor to it and a
135
+ * markdown link stays a separate anchor beside them. That is the
136
+ * whole reason this prop exists rather than the caller wrapping
137
+ * the component in an `<a>`: an anchor inside an anchor is invalid
138
+ * HTML, the browser closes the outer one, and the second half of
139
+ * the title silently stops opening the task.
140
+ *
141
+ * Left out, the runs are plain text and only the markdown links
142
+ * are clickable — which is right for a heading, a table cell, or
143
+ * anywhere the line is not itself a destination.
144
+ *
145
+ * ⚠️ **A markdown link splits this into more than one anchor**, and
146
+ * each one is named by the words it actually covers — `Ship`, then
147
+ * `#53`, then `tonight`. That is honest (what is announced is what
148
+ * is on screen, per WCAG 2.5.3) and it is not *good*: `tonight` is
149
+ * a poor name for a link to a task. Giving them all one name was
150
+ * tried and is worse — two links with the same name are ambiguous
151
+ * to anything driving the page by name, which this library's own
152
+ * `expectAgentDrivable` refuses outright. The conclusion is a
153
+ * design one: a link usually belongs in a task's **description**,
154
+ * where it has a sentence around it, rather than in its title.
155
+ */
156
+ href?: string;
157
+ /**
158
+ * The caller has already wrapped this line in a link — so draw the
159
+ * marks and emit **no anchors at all**, not even for a markdown
160
+ * link.
161
+ *
162
+ * The third and last answer to "who owns the link here", after
163
+ * `href` (this component does) and neither (the markdown links do,
164
+ * and nothing else is clickable). It exists because a whole-card
165
+ * link is a real and common shape — Docket's triage cards wrap the
166
+ * title *and* the body, so middle-click opens the proposal — and
167
+ * inside one, an anchor of any kind is an anchor inside an anchor.
168
+ *
169
+ * That trap has teeth even when no author ever typed a link: a
170
+ * **bare URL autolinks**, so a captured note whose title ends in
171
+ * `https://…` would nest one without anybody writing `[]()`.
172
+ *
173
+ * A markdown link's text still renders, with its marks; it simply
174
+ * does not navigate on its own. The card's link is what a click
175
+ * follows.
176
+ */
177
+ isInsideLink?: boolean;
178
+ /**
179
+ * The markdown. **Inline constructs only** — see
180
+ * `inlineMarkdown.ts`; a `#` or a `- ` is a literal character
181
+ * here, and a newline collapses to a space.
182
+ */
183
+ value: string;
184
+ };
185
+ ```
186
+
187
+ [Full declarations](../../dist/MarkdownLine/MarkdownLine.d.ts)