@mp-lb/mdkit 0.3.1 → 0.3.3

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 (160) hide show
  1. package/README.md +8 -2
  2. package/dist/collaboration/useMdKitCollaboration.d.ts +5 -0
  3. package/dist/collaboration/useMdKitCollaboration.d.ts.map +1 -0
  4. package/dist/collaboration/useMdKitCollaboration.js +4 -0
  5. package/dist/core/checkpointPolicy.d.ts +10 -0
  6. package/dist/core/checkpointPolicy.d.ts.map +1 -0
  7. package/dist/core/checkpointPolicy.js +9 -0
  8. package/dist/core/documentEngine.d.ts +1 -0
  9. package/dist/core/documentEngine.d.ts.map +1 -0
  10. package/dist/core/index.d.ts +1 -0
  11. package/dist/core/index.d.ts.map +1 -0
  12. package/dist/document/MdKitConflictPanel.d.ts +5 -0
  13. package/dist/document/MdKitConflictPanel.d.ts.map +1 -0
  14. package/dist/document/MdKitConflictPanel.js +4 -0
  15. package/dist/document/MdKitDocumentToolbar.d.ts +6 -0
  16. package/dist/document/MdKitDocumentToolbar.d.ts.map +1 -0
  17. package/dist/document/MdKitDocumentToolbar.js +5 -0
  18. package/dist/document/documentTypes.d.ts +6 -0
  19. package/dist/document/documentTypes.d.ts.map +1 -0
  20. package/dist/document/useMdKitDocument.d.ts +5 -0
  21. package/dist/document/useMdKitDocument.d.ts.map +1 -0
  22. package/dist/document/useMdKitDocument.js +4 -0
  23. package/dist/fastify.d.ts +1 -0
  24. package/dist/fastify.d.ts.map +1 -0
  25. package/dist/index.d.ts +4 -1
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/markdown/MarkdownBubbleMenu.d.ts +1 -0
  28. package/dist/markdown/MarkdownBubbleMenu.d.ts.map +1 -0
  29. package/dist/markdown/MarkdownPasteExtension.d.ts +1 -0
  30. package/dist/markdown/MarkdownPasteExtension.d.ts.map +1 -0
  31. package/dist/markdown/MarkdownSearchExtension.d.ts +1 -0
  32. package/dist/markdown/MarkdownSearchExtension.d.ts.map +1 -0
  33. package/dist/markdown/MarkdownSearchPanel.d.ts +1 -0
  34. package/dist/markdown/MarkdownSearchPanel.d.ts.map +1 -0
  35. package/dist/markdown/MdKitEditor.d.ts +11 -0
  36. package/dist/markdown/MdKitEditor.d.ts.map +1 -0
  37. package/dist/markdown/MdKitEditor.js +10 -2
  38. package/dist/markdown/MdKitView.d.ts +9 -1
  39. package/dist/markdown/MdKitView.d.ts.map +1 -0
  40. package/dist/markdown/MdKitView.js +7 -2
  41. package/dist/markdown/TiptapMarkdownSurface.d.ts +1 -0
  42. package/dist/markdown/TiptapMarkdownSurface.d.ts.map +1 -0
  43. package/dist/markdown/TiptapMarkdownSurface.js +10 -22
  44. package/dist/markdown/createMdKitTiptapExtensions.d.ts +1 -0
  45. package/dist/markdown/createMdKitTiptapExtensions.d.ts.map +1 -0
  46. package/dist/markdown/editorDebug.d.ts +1 -0
  47. package/dist/markdown/editorDebug.d.ts.map +1 -0
  48. package/dist/markdown/markdownFenceRanges.d.ts +1 -0
  49. package/dist/markdown/markdownFenceRanges.d.ts.map +1 -0
  50. package/dist/markdown/normalizeMarkdownSerialization.d.ts +1 -0
  51. package/dist/markdown/normalizeMarkdownSerialization.d.ts.map +1 -0
  52. package/dist/markdown/prepareMarkdownForEditorHydration.d.ts +1 -0
  53. package/dist/markdown/prepareMarkdownForEditorHydration.d.ts.map +1 -0
  54. package/dist/markdown/preserveMarkdownWhitespace.d.ts +1 -0
  55. package/dist/markdown/preserveMarkdownWhitespace.d.ts.map +1 -0
  56. package/dist/markdown/yamlFrontMatter.d.ts +1 -0
  57. package/dist/markdown/yamlFrontMatter.d.ts.map +1 -0
  58. package/dist/server.d.ts +1 -0
  59. package/dist/server.d.ts.map +1 -0
  60. package/dist/theme/MdKitThemeEditor.d.ts +5 -0
  61. package/dist/theme/MdKitThemeEditor.d.ts.map +1 -0
  62. package/dist/theme/MdKitThemeEditor.js +4 -0
  63. package/dist/theme/editorTheme.d.ts +1 -0
  64. package/dist/theme/editorTheme.d.ts.map +1 -0
  65. package/dist/theme/editorTheme.js +8 -8
  66. package/dist/transport/backend.d.ts +13 -0
  67. package/dist/transport/backend.d.ts.map +1 -0
  68. package/dist/transport/backend.js +6 -0
  69. package/dist/transport/fastify.d.ts +5 -0
  70. package/dist/transport/fastify.d.ts.map +1 -0
  71. package/dist/transport/fastify.js +4 -0
  72. package/dist/transport/http.d.ts +1 -0
  73. package/dist/transport/http.d.ts.map +1 -0
  74. package/dist/transport/index.d.ts +1 -0
  75. package/dist/transport/index.d.ts.map +1 -0
  76. package/dist/transport/rest.d.ts +6 -0
  77. package/dist/transport/rest.d.ts.map +1 -0
  78. package/dist/transport/rest.js +5 -0
  79. package/dist/transport/store.d.ts +1 -0
  80. package/dist/transport/store.d.ts.map +1 -0
  81. package/dist/transport/trpcClient.d.ts +8 -0
  82. package/dist/transport/trpcClient.d.ts.map +1 -0
  83. package/dist/transport/trpcClient.js +7 -0
  84. package/dist/transport/trpcServer.d.ts +6 -0
  85. package/dist/transport/trpcServer.d.ts.map +1 -0
  86. package/dist/transport/trpcServer.js +5 -0
  87. package/dist/trpc/client.d.ts +1 -0
  88. package/dist/trpc/client.d.ts.map +1 -0
  89. package/dist/trpc/server.d.ts +1 -0
  90. package/dist/trpc/server.d.ts.map +1 -0
  91. package/dist/trpc.d.ts +1 -0
  92. package/dist/trpc.d.ts.map +1 -0
  93. package/dist/ui/joinClassNames.d.ts +1 -0
  94. package/dist/ui/joinClassNames.d.ts.map +1 -0
  95. package/dist/versioning/VersionHistoryPanel.d.ts +5 -0
  96. package/dist/versioning/VersionHistoryPanel.d.ts.map +1 -0
  97. package/dist/versioning/VersionHistoryPanel.js +4 -0
  98. package/dist/versioning/useMdKitDocumentVersions.d.ts +5 -0
  99. package/dist/versioning/useMdKitDocumentVersions.d.ts.map +1 -0
  100. package/dist/versioning/useMdKitDocumentVersions.js +4 -0
  101. package/dist/yjs/MdKitMarkdownYjs.d.ts +1 -0
  102. package/dist/yjs/MdKitMarkdownYjs.d.ts.map +1 -0
  103. package/dist/yjs/index.d.ts +1 -0
  104. package/dist/yjs/index.d.ts.map +1 -0
  105. package/package.json +10 -12
  106. package/src/collaboration/useMdKitCollaboration.ts +528 -0
  107. package/src/core/checkpointPolicy.ts +107 -0
  108. package/src/core/documentEngine.ts +175 -0
  109. package/src/core/index.ts +33 -0
  110. package/src/document/MdKitConflictPanel.tsx +129 -0
  111. package/src/document/MdKitDocumentToolbar.tsx +141 -0
  112. package/src/document/documentTypes.ts +89 -0
  113. package/src/document/useMdKitDocument.ts +543 -0
  114. package/src/fastify.ts +6 -0
  115. package/src/index.ts +89 -0
  116. package/src/markdown/MarkdownBubbleMenu.tsx +271 -0
  117. package/src/markdown/MarkdownPasteExtension.ts +81 -0
  118. package/src/markdown/MarkdownSearchExtension.ts +77 -0
  119. package/src/markdown/MarkdownSearchPanel.tsx +98 -0
  120. package/src/markdown/MdKitEditor.tsx +75 -0
  121. package/src/markdown/MdKitView.tsx +80 -0
  122. package/src/markdown/TiptapMarkdownSurface.tsx +923 -0
  123. package/src/markdown/createMdKitTiptapExtensions.ts +42 -0
  124. package/src/markdown/editorDebug.ts +5 -0
  125. package/src/markdown/markdownFenceRanges.ts +68 -0
  126. package/src/markdown/normalizeMarkdownSerialization.ts +55 -0
  127. package/src/markdown/prepareMarkdownForEditorHydration.ts +23 -0
  128. package/src/markdown/preserveMarkdownWhitespace.ts +143 -0
  129. package/src/markdown/yamlFrontMatter.ts +135 -0
  130. package/src/server.ts +6 -0
  131. package/src/styles.css +125 -53
  132. package/src/theme/MdKitThemeEditor.tsx +134 -0
  133. package/src/theme/editorTheme.ts +72 -0
  134. package/src/transport/backend.ts +220 -0
  135. package/src/transport/fastify.ts +57 -0
  136. package/src/transport/http.ts +126 -0
  137. package/src/transport/index.ts +12 -0
  138. package/src/transport/rest.ts +80 -0
  139. package/src/transport/store.ts +45 -0
  140. package/src/transport/trpcClient.ts +90 -0
  141. package/src/transport/trpcServer.ts +66 -0
  142. package/src/trpc/client.ts +11 -0
  143. package/src/trpc/server.ts +12 -0
  144. package/src/trpc.ts +11 -0
  145. package/src/ui/joinClassNames.ts +3 -0
  146. package/src/versioning/VersionHistoryPanel.tsx +146 -0
  147. package/src/versioning/useMdKitDocumentVersions.ts +146 -0
  148. package/src/yjs/MdKitMarkdownYjs.ts +111 -0
  149. package/src/yjs/index.ts +8 -0
  150. package/docs/.vitepress/config.ts +0 -47
  151. package/docs/api.md +0 -512
  152. package/docs/architecture.md +0 -96
  153. package/docs/collaboration-persistence.md +0 -147
  154. package/docs/index.md +0 -341
  155. package/docs/permissions.md +0 -139
  156. package/docs/plain-text.md +0 -131
  157. package/docs/rest.md +0 -98
  158. package/docs/shadcn.md +0 -125
  159. package/docs/styling.md +0 -373
  160. package/docs/use-cases.md +0 -148
package/docs/styling.md DELETED
@@ -1,373 +0,0 @@
1
- # Styling
2
-
3
- `MdKitEditor` can render without package CSS, but most applications should
4
- import the stylesheet once. It gives the editor a reset-resistant markdown
5
- baseline and exposes CSS variables for theme changes.
6
-
7
- ```ts
8
- import "@mp-lb/mdkit/styles.css";
9
- ```
10
-
11
- Without this stylesheet, the editor still works, but headings, lists,
12
- blockquotes, code blocks, spacing, and focus areas are left to your app's CSS.
13
-
14
- ## CSS Resets
15
-
16
- Many app frameworks include CSS resets. Tailwind Preflight, for example, removes
17
- default margins and list styling. The package stylesheet restores markdown
18
- editor defaults under `.mp-lb-mdkit-markdown-editor`, including:
19
-
20
- - heading sizes and spacing
21
- - paragraph spacing
22
- - unordered and ordered list markers
23
- - compact list item spacing
24
- - inline code and code block styling
25
- - blockquote styling
26
- - link color
27
- - full-width editor layout
28
-
29
- Import the stylesheet after global reset styles when possible:
30
-
31
- ```ts
32
- import "./app.css";
33
- import "@mp-lb/mdkit/styles.css";
34
- ```
35
-
36
- If your bundler or framework controls CSS order differently, make sure the
37
- mdkit stylesheet is not overridden by a later broad reset such as
38
- `ul { list-style: none; }`.
39
-
40
- ## Default Styling
41
-
42
- The simplest setup is:
43
-
44
- ```tsx
45
- import { MdKitEditor } from "@mp-lb/mdkit";
46
- import "@mp-lb/mdkit/styles.css";
47
-
48
- export function Editor({ markdown, setMarkdown }) {
49
- return <MdKitEditor value={markdown} onChange={setMarkdown} />;
50
- }
51
- ```
52
-
53
- The editor fills the available width by default. Use `fillHeight` only when you
54
- want the editor to fill its parent's height, own its scroll area, and make the
55
- empty area below the last line clickable.
56
-
57
- ```tsx
58
- <MdKitEditor fillHeight value={markdown} onChange={setMarkdown} />
59
- ```
60
-
61
- ## Custom Styling
62
-
63
- The package stylesheet is intentionally controlled through CSS variables. You
64
- can override them with a class:
65
-
66
- ```css
67
- .my-markdown-editor {
68
- --mp-lb-mdkit-background: #ffffff;
69
- --mp-lb-mdkit-foreground: #172033;
70
- --mp-lb-mdkit-muted: #eef1f4;
71
- --mp-lb-mdkit-muted-foreground: #5b6472;
72
- --mp-lb-mdkit-border: #d8dee8;
73
- --mp-lb-mdkit-link: #4f46e5;
74
- --mp-lb-mdkit-font-family: Inter, system-ui, sans-serif;
75
- --mp-lb-mdkit-font-size: 16px;
76
- --mp-lb-mdkit-line-height: 1.7;
77
- --mp-lb-mdkit-surface-padding: 1rem;
78
- --mp-lb-mdkit-block-gap: 0.75rem;
79
- --mp-lb-mdkit-list-item-gap: 0.125rem;
80
- --mp-lb-mdkit-code-background: #eef1f4;
81
- --mp-lb-mdkit-code-radius: 0.35rem;
82
- --mp-lb-mdkit-code-block-radius: 0.75rem;
83
- }
84
- ```
85
-
86
- ```tsx
87
- <MdKitEditor
88
- className="my-markdown-editor"
89
- value={markdown}
90
- onChange={setMarkdown}
91
- />
92
- ```
93
-
94
- You can also pass variables through `style` when the values are generated at
95
- runtime:
96
-
97
- ```tsx
98
- <MdKitEditor
99
- style={{
100
- "--mp-lb-mdkit-font-family": "ui-serif, Georgia, serif",
101
- "--mp-lb-mdkit-font-size": "18px",
102
- "--mp-lb-mdkit-line-height": "1.8",
103
- }}
104
- value={markdown}
105
- onChange={setMarkdown}
106
- />
107
- ```
108
-
109
- See [`MdKitEditorProps`](./api.md#mdkiteditorprops) for the full component
110
- props.
111
-
112
- ## Class Hooks
113
-
114
- The package uses stable `mp-lb-mdkit-*` class names for all package-owned
115
- markup. These classes are a supported integration point for product-specific
116
- styling. Prefer CSS variables for theme-level changes, and use class hooks when
117
- you need structural changes, component-specific spacing, or state styling.
118
-
119
- ### Editor
120
-
121
- `MdKitEditor` renders the markdown editing surface and the selection bubble
122
- toolbar. The toolbar appears for non-empty text selections while the editor or
123
- toolbar has focus. The search panel appears only when `search` is enabled and
124
- the user opens it with the find keyboard shortcut.
125
-
126
- - `.mp-lb-mdkit-markdown-editor`: root element rendered by `MdKitEditor`
127
- - `.mp-lb-mdkit-markdown-editor-fill-height`: added to the root when
128
- `fillHeight` is enabled
129
- - `.mp-lb-mdkit-editor-shell`: internal editor layout wrapper
130
- - `.mp-lb-mdkit-editor-surface`: scroll and background surface around the
131
- ProseMirror editor
132
- - `.mp-lb-mdkit-editor-empty`: loading or connecting placeholder
133
- - `.mp-lb-mdkit-search-panel`: optional document search panel
134
- - `.mp-lb-mdkit-search-input`: search text input
135
- - `.mp-lb-mdkit-search-status`: search result count
136
- - `.mp-lb-mdkit-search-button`: search navigation or close button
137
- - `.mp-lb-mdkit-tiptap`: ProseMirror editable element
138
- - `.mp-lb-mdkit-toolbar`: selection bubble toolbar
139
- - `.mp-lb-mdkit-toolbar-button`: toolbar button
140
- - `.mp-lb-mdkit-toolbar-button-active`: added to active toolbar buttons
141
- - `.mp-lb-mdkit-toolbar-divider`: toolbar divider
142
- - `.mp-lb-mdkit-collaboration-caret`: remote collaboration caret
143
- - `.mp-lb-mdkit-collaboration-caret-label`: remote collaborator label
144
-
145
- The editor root exposes `data-read-only="true"` when `readOnly` is enabled.
146
-
147
- ### Theme Editor
148
-
149
- `MdKitThemeEditor` renders controls for editing a theme object.
150
-
151
- - `.mp-lb-mdkit-theme-editor`: root element rendered by `MdKitThemeEditor`
152
-
153
- ### Document Toolbar
154
-
155
- `MdKitDocumentToolbar` renders document save, restore, and conflict controls.
156
-
157
- - `.mp-lb-mdkit-document-toolbar`: root element
158
- - `.mp-lb-mdkit-document-toolbar-status`: status text group
159
- - `.mp-lb-mdkit-document-toolbar-error`: non-conflict error message
160
- - `.mp-lb-mdkit-document-toolbar-actions`: action button group
161
- - `.mp-lb-mdkit-document-toolbar-conflict-trigger`: button that opens external
162
- conflict UI
163
- - `.mp-lb-mdkit-document-toolbar-conflict`: inline conflict action row
164
-
165
- The root exposes these state attributes:
166
-
167
- - `data-conflict`: `"true"` when a document conflict exists
168
- - `data-dirty`: `"true"` when local edits are unsaved
169
- - `data-save-status`: raw save status from the document controller
170
- - `data-status`: display status normalized for CSS selectors, such as
171
- `"saved"`, `"unsaved-changes"`, `"autosave-pending"`, or `"conflict"`
172
-
173
- Example:
174
-
175
- ```css
176
- .mp-lb-mdkit-document-toolbar {
177
- display: flex;
178
- align-items: center;
179
- gap: 0.5rem;
180
- border-bottom: 1px solid var(--border);
181
- padding: 0.5rem 0;
182
- }
183
-
184
- .mp-lb-mdkit-document-toolbar-status,
185
- .mp-lb-mdkit-document-toolbar-actions,
186
- .mp-lb-mdkit-document-toolbar-conflict {
187
- display: flex;
188
- align-items: center;
189
- gap: 0.5rem;
190
- }
191
-
192
- .mp-lb-mdkit-document-toolbar[data-conflict="true"] {
193
- color: #991b1b;
194
- }
195
- ```
196
-
197
- ### Conflict Panel
198
-
199
- `MdKitConflictPanel` renders conflict details, previews, and conflict actions.
200
-
201
- - `.mp-lb-mdkit-conflict-panel`: root element
202
- - `.mp-lb-mdkit-conflict-panel-content`: title, explanatory text, and metadata
203
- - `.mp-lb-mdkit-conflict-panel-error`: error text
204
- - `.mp-lb-mdkit-conflict-panel-meta`: remote revision metadata
205
- - `.mp-lb-mdkit-conflict-panel-preview`: preview area
206
- - `.mp-lb-mdkit-conflict-panel-tabs`: preview tab list
207
- - `.mp-lb-mdkit-conflict-panel-tab`: preview tab button
208
- - `.mp-lb-mdkit-conflict-panel-tab-active`: active preview tab button
209
- - `.mp-lb-mdkit-conflict-panel-action-row`: action button row
210
- - `.mp-lb-mdkit-panel-secondary-action`: secondary panel action button
211
-
212
- The preview tabs also use `aria-selected` for state-aware styling.
213
-
214
- ### Checkpoint History Panel
215
-
216
- `VersionHistoryPanel` renders checkpoint history: a checkpoint list, selected
217
- checkpoint preview, restore action, and empty/error states. The component and
218
- CSS class names keep `version-history` for current API compatibility.
219
-
220
- - `.mp-lb-mdkit-version-history-panel`: root element
221
- - `.mp-lb-mdkit-version-history-header`: panel header
222
- - `.mp-lb-mdkit-version-history-title`: panel title
223
- - `.mp-lb-mdkit-version-history-subtitle`: panel subtitle
224
- - `.mp-lb-mdkit-version-history-layout`: list and preview layout
225
- - `.mp-lb-mdkit-version-history-list`: checkpoint list
226
- - `.mp-lb-mdkit-version-history-item`: checkpoint list item button
227
- - `.mp-lb-mdkit-version-history-item-active`: selected checkpoint list item
228
- - `.mp-lb-mdkit-version-history-item-title`: list item title
229
- - `.mp-lb-mdkit-version-history-item-meta`: list item or selected checkpoint metadata
230
- - `.mp-lb-mdkit-version-history-preview`: selected checkpoint preview area
231
- - `.mp-lb-mdkit-version-history-preview-header`: preview header
232
- - `.mp-lb-mdkit-version-history-preview-title`: preview title
233
- - `.mp-lb-mdkit-version-history-code`: markdown preview code block
234
- - `.mp-lb-mdkit-version-history-empty`: empty state text
235
- - `.mp-lb-mdkit-version-history-error`: error state text
236
- - `.mp-lb-mdkit-version-history-meta`: footer metadata
237
- - `.mp-lb-mdkit-panel-primary-action`: primary panel action button
238
-
239
- ### Shared Panel Actions
240
-
241
- Conflict and checkpoint panels share generic action classes:
242
-
243
- - `.mp-lb-mdkit-panel-primary-action`: primary action button
244
- - `.mp-lb-mdkit-panel-secondary-action`: secondary action button
245
-
246
- ## CSS Variables
247
-
248
- The package stylesheet defines variables on component roots so consumers can
249
- override broad styling without depending on internal element structure.
250
-
251
- ### Editor Variables
252
-
253
- Set these on `.mp-lb-mdkit-markdown-editor`, a custom `className` passed to
254
- `MdKitEditor`, or the inline `style` prop:
255
-
256
- - `--mp-lb-mdkit-background`
257
- - `--mp-lb-mdkit-foreground`
258
- - `--mp-lb-mdkit-muted`
259
- - `--mp-lb-mdkit-muted-foreground`
260
- - `--mp-lb-mdkit-border`
261
- - `--mp-lb-mdkit-accent`
262
- - `--mp-lb-mdkit-accent-foreground`
263
- - `--mp-lb-mdkit-link`
264
- - `--mp-lb-mdkit-font-family`
265
- - `--mp-lb-mdkit-font-size`
266
- - `--mp-lb-mdkit-line-height`
267
- - `--mp-lb-mdkit-surface-padding`
268
- - `--mp-lb-mdkit-block-gap`
269
- - `--mp-lb-mdkit-list-item-gap`
270
- - `--mp-lb-mdkit-heading-font-weight`
271
- - `--mp-lb-mdkit-heading-1-size`
272
- - `--mp-lb-mdkit-heading-2-size`
273
- - `--mp-lb-mdkit-code-background`
274
- - `--mp-lb-mdkit-code-radius`
275
- - `--mp-lb-mdkit-code-block-radius`
276
- - `--mp-lb-mdkit-code-font-family`
277
- - `--mp-lb-mdkit-quote-border-color`
278
-
279
- ### Panel Variables
280
-
281
- Set these on `.mp-lb-mdkit-document-toolbar`,
282
- `.mp-lb-mdkit-conflict-panel`, `.mp-lb-mdkit-version-history-panel`, or a
283
- wrapper around those components:
284
-
285
- - `--mp-lb-mdkit-panel-background`
286
- - `--mp-lb-mdkit-panel-surface`
287
- - `--mp-lb-mdkit-panel-foreground`
288
- - `--mp-lb-mdkit-panel-muted`
289
- - `--mp-lb-mdkit-panel-muted-foreground`
290
- - `--mp-lb-mdkit-panel-border`
291
- - `--mp-lb-mdkit-panel-strong-border`
292
- - `--mp-lb-mdkit-panel-danger`
293
- - `--mp-lb-mdkit-panel-success`
294
- - `--mp-lb-mdkit-panel-action-background`
295
- - `--mp-lb-mdkit-panel-action-foreground`
296
-
297
- ## Theme Helpers
298
-
299
- For app code, CSS variables are usually the simplest integration. The package
300
- also exports theme helpers when you want to store or generate a theme object:
301
-
302
- ```tsx
303
- import {
304
- MdKitEditor,
305
- createMdKitEditorThemeStyle,
306
- darkMdKitEditorTheme,
307
- } from "@mp-lb/mdkit";
308
-
309
- const style = createMdKitEditorThemeStyle({
310
- ...darkMdKitEditorTheme,
311
- fontFamily: "Inter, system-ui, sans-serif",
312
- lineHeight: "1.75",
313
- });
314
-
315
- <MdKitEditor style={style} value={markdown} onChange={setMarkdown} />;
316
- ```
317
-
318
- Related exports are listed in the [API reference](./api.md#styling).
319
-
320
- ## Dark Mode
321
-
322
- For class-based dark mode, scope variable overrides to your dark selector:
323
-
324
- ```css
325
- .my-markdown-editor {
326
- --mp-lb-mdkit-background: #ffffff;
327
- --mp-lb-mdkit-foreground: #172033;
328
- --mp-lb-mdkit-muted: #eef1f4;
329
- --mp-lb-mdkit-muted-foreground: #5b6472;
330
- --mp-lb-mdkit-border: #d8dee8;
331
- --mp-lb-mdkit-link: #4f46e5;
332
- --mp-lb-mdkit-code-background: #eef1f4;
333
- }
334
-
335
- .dark .my-markdown-editor {
336
- --mp-lb-mdkit-background: #0b1220;
337
- --mp-lb-mdkit-foreground: #e5edf7;
338
- --mp-lb-mdkit-muted: #172033;
339
- --mp-lb-mdkit-muted-foreground: #94a3b8;
340
- --mp-lb-mdkit-border: #314158;
341
- --mp-lb-mdkit-link: #38bdf8;
342
- --mp-lb-mdkit-code-background: #111827;
343
- }
344
- ```
345
-
346
- Then apply the class normally:
347
-
348
- ```tsx
349
- <MdKitEditor
350
- className="my-markdown-editor"
351
- value={markdown}
352
- onChange={setMarkdown}
353
- />
354
- ```
355
-
356
- You can also switch theme objects in React:
357
-
358
- ```tsx
359
- const style = createMdKitEditorThemeStyle(
360
- isDark ? darkMdKitEditorTheme : defaultMdKitEditorTheme,
361
- );
362
-
363
- <MdKitEditor style={style} value={markdown} onChange={setMarkdown} />;
364
- ```
365
-
366
- ## What Not To Customize First
367
-
368
- Prefer changing CSS variables before overriding internal selectors like
369
- `.mp-lb-mdkit-tiptap p` or `.mp-lb-mdkit-editor-surface`. Direct selector overrides are still an
370
- escape hatch, but they couple your app to mdkit's internal DOM.
371
-
372
- Use `MdKitThemeEditor` for theme builders, documentation, and debug tooling. It
373
- is not required for normal editor integration.
package/docs/use-cases.md DELETED
@@ -1,148 +0,0 @@
1
- # Use Cases
2
-
3
- MDKit is designed as independent layers. Use only the pieces your product
4
- needs:
5
-
6
- | Layers | Behavior |
7
- | --- | --- |
8
- | Editor only | Controlled markdown editor. No backend, checkpoints, or collaboration. |
9
- | Editor + storage | Autosave, current-document reads/writes, and conflict handling. |
10
- | Editor + storage + checkpoints | Autosave plus meaningful history and restore. |
11
- | Editor + storage + collaboration | Live collaboration plus canonical markdown snapshots. |
12
- | Full stack | Storage, checkpoints, restore, collaboration, and permissions. |
13
-
14
- ## Core Model
15
-
16
- MDKit treats historical document state as checkpoint history.
17
-
18
- A checkpoint is an immutable markdown snapshot with metadata. Version-per-write
19
- is not a separate architecture; it is the checkpoint policy where every
20
- successful write creates a checkpoint. No history is the checkpoint
21
- policy where checkpoint creation is disabled.
22
-
23
- That gives MDKit one history abstraction:
24
-
25
- - autosave writes the canonical current markdown document
26
- - checkpoint rules decide when current content becomes user-facing history
27
- - history UI lists, previews, and restores checkpoints
28
-
29
- ## Checkpoint Policies
30
-
31
- ### Never
32
-
33
- The app stores one current markdown document. The document still has an opaque
34
- revision token for conflict detection, but no user-facing history.
35
-
36
- ### Always
37
-
38
- Every successful write creates a checkpoint. This is useful for deliberate
39
- manual-save products, but it is usually too noisy for autosave because
40
- autosave writes can be tiny implementation details.
41
-
42
- ### Manual
43
-
44
- Manual checkpoints are created by explicit user or product actions such as Save
45
- checkpoint, publish, approve, or mark milestone.
46
-
47
- ### Smart
48
-
49
- Autosave keeps the current document durable. A smart checkpoint policy decides
50
- when a change is meaningful enough to become history. Practical policies use
51
- values such as edit distance, elapsed time since the last checkpoint, author,
52
- and write context.
53
-
54
- ```ts
55
- const policy = CheckpointPolicy.smart({
56
- minEditDistance: 250,
57
- minIntervalMs: 5 * 60_000,
58
- });
59
- ```
60
-
61
- Use a custom function when the built-in policy is not enough:
62
-
63
- ```ts
64
- const policy = CheckpointPolicy.function(
65
- ({
66
- currentContent,
67
- editDistance,
68
- previousCheckpointContent,
69
- timeSinceLastCheckpointMs,
70
- }) =>
71
- editDistance > 500 ||
72
- timeSinceLastCheckpointMs > 10 * 60_000 ||
73
- currentContent.startsWith("# Published") !==
74
- previousCheckpointContent?.startsWith("# Published"),
75
- );
76
- ```
77
-
78
- The function receives both computed values and raw document content, so products
79
- can use mdkit's edit-distance calculation or compute their own comparison.
80
-
81
- ## Canonical Data
82
-
83
- The canonical current document is markdown plus metadata:
84
-
85
- - `documentId`
86
- - `content`
87
- - `revision`
88
- - `updatedAt`
89
- - optional caller-owned metadata
90
-
91
- `revision` is an opaque concurrency token. It is not the same thing as a
92
- checkpoint id.
93
-
94
- Checkpoints are immutable markdown snapshots:
95
-
96
- - `checkpointId`
97
- - `documentId`
98
- - `content`
99
- - `createdAt`
100
- - `sourceRevision`
101
- - optional caller-owned metadata
102
-
103
- The application owns product metadata, authorship, permissions, tenancy, and
104
- audit data. MDKit should pass that data through without inspecting it.
105
-
106
- ## Restore
107
-
108
- The safest restore flow preserves current work before replacing it:
109
-
110
- - read the checkpoint being restored
111
- - checkpoint the current document if it is not already represented
112
- - update the canonical current document to the restored content
113
- - create a new current revision
114
- - reset collaboration state if collaboration is enabled
115
-
116
- The restored checkpoint remains immutable. Products can choose whether restore
117
- also creates a restore checkpoint at the top of history.
118
-
119
- ## Collaboration
120
-
121
- Yjs state is the live collaboration state. Markdown remains the canonical
122
- snapshot format for current-document storage and checkpoint history.
123
-
124
- The opinionated collaboration flow is:
125
-
126
- - seed an empty collaboration room from canonical markdown
127
- - persist Yjs state through application-owned durable storage connected to the
128
- collaboration server
129
- - snapshot active Yjs state to markdown before updating canonical storage or
130
- creating a checkpoint
131
- - on restore, replace canonical markdown and reset/reseed collaboration state
132
-
133
- Correctness is more important than preserving cursor continuity. A restore may
134
- close or reset active collaboration sessions.
135
-
136
- ## API Direction
137
-
138
- The current package already exposes the editor, storage hooks, checkpoint-list
139
- hooks, base panels, tRPC/REST helpers, and markdown/Yjs conversion helpers.
140
-
141
- Future backend helpers should add:
142
-
143
- - checkpoint policy helpers for `never`, `always`, `smart`, and custom
144
- functions
145
- - first-class checkpoint creation
146
- - restore as a frontend/backend workflow
147
- - generic metadata/context passthrough
148
- - collaboration helpers for markdown/Yjs seeding, snapshotting, and reset