@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
@@ -1,131 +0,0 @@
1
- # Plain Text Editors
2
-
3
- MDKit's connected workflow is not limited to `MdKitEditor`. The document hooks
4
- and backend adapters work with serialized text, so you can bring a plain text,
5
- code, JSON, or custom text editor and still use the same storage, autosave,
6
- checkpoint history, restore, and conflict handling.
7
-
8
- The one major exception is collaboration. Collaboration is currently a
9
- markdown/Tiptap capability because it depends on Yjs, ProseMirror, and the
10
- Tiptap collaboration extensions.
11
-
12
- ## What Works
13
-
14
- Any editor can plug into the connected workflow if it behaves like a controlled
15
- text input:
16
-
17
- ```tsx
18
- type TextEditorProps = {
19
- value: string;
20
- onChange(value: string): void;
21
- onFocusChange?(focused: boolean): void;
22
- readOnly?: boolean;
23
- };
24
- ```
25
-
26
- That is enough for:
27
-
28
- - loading the current document
29
- - autosave
30
- - dirty state
31
- - conflict detection
32
- - force save
33
- - remote resync
34
- - checkpoint history
35
- - checkpoint restore
36
-
37
- The editor does not need to know about MDKit internals. It only needs to receive
38
- `document.value` and call `document.setContent`.
39
-
40
- ## Example
41
-
42
- ```tsx
43
- import {
44
- MdKitConflictPanel,
45
- MdKitDocumentToolbar,
46
- VersionHistoryPanel,
47
- useMdKitDocument,
48
- useMdKitDocumentVersions,
49
- type MdKitDocumentAdapter,
50
- } from "@mp-lb/mdkit";
51
-
52
- function PlainTextDocument({
53
- adapter,
54
- documentId,
55
- }: {
56
- adapter: MdKitDocumentAdapter;
57
- documentId: string;
58
- }) {
59
- const document = useMdKitDocument({
60
- adapter,
61
- debounceMs: 1000,
62
- documentId,
63
- });
64
- const versions = useMdKitDocumentVersions({ adapter, documentId });
65
-
66
- return (
67
- <>
68
- <MdKitDocumentToolbar document={document} versions={versions} />
69
-
70
- <textarea
71
- readOnly={document.conflict}
72
- value={document.value}
73
- onBlur={() => document.setFocused(false)}
74
- onChange={(event) => document.setContent(event.currentTarget.value)}
75
- onFocus={() => document.setFocused(true)}
76
- />
77
-
78
- <MdKitConflictPanel document={document} />
79
- <VersionHistoryPanel controller={versions} />
80
- </>
81
- );
82
- }
83
- ```
84
-
85
- Use the same backend adapter you would use for markdown. The document content is
86
- still just `content: string`.
87
-
88
- ## Backend Shape
89
-
90
- You do not need a separate backend for plain text documents. A single MDKit
91
- backend can expose:
92
-
93
- - document read/write
94
- - checkpoint list/read/restore
95
- - optional collaboration websocket routes
96
- - optional collaboration state persistence
97
-
98
- Plain text editors use the document and checkpoint APIs. Markdown collaborative
99
- editors additionally use the collaboration websocket and Yjs persistence.
100
-
101
- The underlying database layout is application-owned. It is reasonable to store
102
- markdown and plain text documents in the same documents table, or in separate
103
- tables if your product needs that. MDKit only requires a stable `documentId`,
104
- `content`, and an opaque revision token.
105
-
106
- ## Collaboration Boundary
107
-
108
- Do not pass `useMdKitCollaboration` to a plain text editor. The current
109
- collaboration adapter is for `MdKitEditor` because that editor knows how to bind
110
- Tiptap to a Yjs document and render remote cursors.
111
-
112
- For plain text documents:
113
-
114
- - keep using `useMdKitDocument`
115
- - omit `useMdKitCollaboration`
116
- - omit collaboration UI
117
- - rely on optimistic conflicts and resync for multi-client safety
118
-
119
- If MDKit later adds a collaboration-capable CodeMirror, Monaco, or textarea
120
- adapter, that should be a new editor-specific capability. The generic text
121
- workflow does not need to change.
122
-
123
- ## Testbench
124
-
125
- The testbench includes a connected stack named
126
- `Storage + checkpoints (plain text)`. It reuses the same checkpoints backend as
127
- the markdown stack, stores content under `docs/plain-text.txt`, and renders a
128
- controlled textarea instead of `MdKitEditor`.
129
-
130
- Use it to verify that plain text can autosave, create checkpoints, restore
131
- history, and avoid collaboration UI.
package/docs/rest.md DELETED
@@ -1,98 +0,0 @@
1
- # REST Backend
2
-
3
- Use REST when you want the quick-start frontend without tRPC. The editor,
4
- toolbar, conflict panel, checkpoint panel, and collaboration hook are the same.
5
- The difference is the backend transport.
6
-
7
- If your backend uses Fastify, mdkit can register the REST routes for you. If you
8
- use another server framework, implement the same endpoint shape shown below.
9
-
10
- ## Frontend Wiring
11
-
12
- Use the connected frontend from the [Quick Start](./index.md#frontend-with-trpc).
13
- Keep the same component structure, but change the transport-specific pieces:
14
-
15
- - replace the tRPC adapter with `createMdKitRestAdapter`, using a REST base URL
16
- such as `${apiUrl}/mdkit`
17
- - point collaboration at `${apiUrl.replace(/^http/, "ws")}/mdkit/collaboration`
18
- - point the restore callback at `POST /mdkit/versions/:versionId/restore`
19
-
20
- `createMdKitRestAdapter` covers current-document reads, writes, resync,
21
- checkpoint listing, and checkpoint detail reads. Restore is separate because it
22
- is not part of `MdKitDocumentAdapter` yet.
23
-
24
- ## Fastify Backend
25
-
26
- ```ts
27
- import cors from "@fastify/cors";
28
- import websocket from "@fastify/websocket";
29
- import { Database } from "@hocuspocus/extension-database";
30
- import { Server } from "@hocuspocus/server";
31
- import Fastify from "fastify";
32
- import { CheckpointPolicy } from "@mp-lb/mdkit/core";
33
- import {
34
- createMdKitBackend,
35
- type MdKitBackendStore,
36
- } from "@mp-lb/mdkit/server";
37
- import { registerMdKitFastify } from "@mp-lb/mdkit/fastify";
38
-
39
- const app = Fastify();
40
- const store: MdKitBackendStore = createYourDocumentStore();
41
-
42
- const mdkit = createMdKitBackend({
43
- store,
44
- checkpointPolicy: CheckpointPolicy.smart(),
45
- });
46
-
47
- const collaboration = Server.configure({
48
- extensions: [
49
- new Database({
50
- fetch: ({ documentName }) => mdkit.readCollaborationState(documentName),
51
- store: ({ documentName, state }) =>
52
- mdkit.writeCollaborationState(documentName, state),
53
- }),
54
- ],
55
- });
56
-
57
- await app.register(cors, { origin: true });
58
- await app.register(websocket);
59
-
60
- await registerMdKitFastify(app, {
61
- prefix: "/mdkit",
62
- store: mdkit,
63
- });
64
-
65
- app.get("/mdkit/collaboration", { websocket: true }, (socket, request) => {
66
- collaboration.handleConnection(socket, request.raw, {});
67
- });
68
-
69
- app.addHook("onClose", async () => {
70
- await collaboration.destroy();
71
- });
72
-
73
- await app.listen({ port: Number(process.env.PORT ?? 4312) });
74
- ```
75
-
76
- The store object is still your application boundary. It connects mdkit's REST
77
- routes to your database and owns metadata, permissions, tenancy, and durable
78
- Yjs storage. Mdkit applies the checkpoint policy and calls your store's
79
- checkpoint creation method when needed. See
80
- [`createMdKitBackend`](./api.md#createmdkitbackend).
81
-
82
- ## Endpoint Shape
83
-
84
- If you are not using Fastify, implement these routes with your server framework:
85
-
86
- | Method | Path | Behavior |
87
- | --- | --- | --- |
88
- | `GET` | `/mdkit/documents?documentId=...` | Read the current document. |
89
- | `PUT` | `/mdkit/documents?documentId=...` | Write current content with `baseVersion`. |
90
- | `POST` | `/mdkit/documents/resync?documentId=...` | Force a fresh current-document read. |
91
- | `GET` | `/mdkit/versions?documentId=...` | List checkpoints as `{ versions }`. |
92
- | `GET` | `/mdkit/versions/:versionId?documentId=...` | Read one checkpoint. |
93
- | `POST` | `/mdkit/versions/:versionId/restore?documentId=...` | Restore one checkpoint. |
94
-
95
- The REST frontend adapter expects the same JSON shapes as
96
- `MdKitDocumentAdapter`. Write conflicts should return the conflict body with
97
- HTTP `409`; the adapter treats that as a successful mdkit response so the editor
98
- can show the conflict workflow.
package/docs/shadcn.md DELETED
@@ -1,125 +0,0 @@
1
- # Shadcn Plugin
2
-
3
- The core npm package is design-system agnostic. It exports the editor, hooks,
4
- base panels, types, and generic CSS. It does not export shadcn components at
5
- runtime.
6
-
7
- The shadcn path should be a registry/plugin item. Installing it copies editable
8
- source into your app, and that source imports your app's own shadcn primitives:
9
-
10
- ```tsx
11
- import { Button } from "@/components/ui/button";
12
- import { Badge } from "@/components/ui/badge";
13
- import {
14
- Dialog,
15
- DialogContent,
16
- DialogHeader,
17
- DialogTitle,
18
- } from "@/components/ui/dialog";
19
- import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
20
- import { Textarea } from "@/components/ui/textarea";
21
- ```
22
-
23
- That means the workflow component can own polished app UI: toolbar, checkpoint
24
- history dialog, conflict dialog, tabs, buttons, and layout. The underlying state
25
- still comes from the mdkit hooks. The recommended transport for this path is
26
- the tRPC adapter from `@mp-lb/mdkit/trpc/client`.
27
-
28
- ## Intended Shape
29
-
30
- The installed component should be one app-local workflow component that you
31
- render next to `MdKitEditor`.
32
-
33
- ```tsx
34
- import {
35
- MdKitEditor,
36
- useMdKitCollaboration,
37
- useMdKitDocument,
38
- useMdKitDocumentVersions,
39
- } from "@mp-lb/mdkit";
40
- import {
41
- createMdKitTrpcAdapter,
42
- createMdKitTrpcClient,
43
- } from "@mp-lb/mdkit/trpc/client";
44
- import { MdKitConnectedWorkflow } from "@/components/mdkit/mdkit-connected-workflow";
45
-
46
- export function EditorScreen() {
47
- const client = createMdKitTrpcClient({ url: "/trpc" });
48
- const adapter = createMdKitTrpcAdapter({ client });
49
- const document = useMdKitDocument({
50
- adapter,
51
- debounceMs: 1000,
52
- documentId,
53
- });
54
- const versions = useMdKitDocumentVersions({ adapter, documentId });
55
-
56
- const collaboration = useMdKitCollaboration({
57
- collaborator,
58
- documentId,
59
- endpoint: hocuspocusEndpoint,
60
- });
61
-
62
- const restoreVersion = async (version) => {
63
- await client.restoreDocumentVersion.mutate({
64
- documentId,
65
- versionId: version.id,
66
- });
67
-
68
- await document.resync();
69
- await versions.refresh();
70
- };
71
-
72
- return (
73
- <MdKitConnectedWorkflow
74
- collaboration={collaboration}
75
- document={document}
76
- versions={versions}
77
- onRestoreVersion={restoreVersion}
78
- >
79
- <MdKitEditor
80
- collaboration={collaboration}
81
- readOnly={document.conflict}
82
- value={document.value}
83
- onChange={document.setContent}
84
- onFocusChange={document.setFocused}
85
- />
86
- </MdKitConnectedWorkflow>
87
- );
88
- }
89
- ```
90
-
91
- The shadcn component is deliberately source-installed instead of imported from
92
- the npm package. That is how shadcn is designed to work: the code lives in your
93
- app, uses your aliases, and can be edited like any other local component.
94
-
95
- ## Why Not A Runtime Export?
96
-
97
- mdkit should not:
98
-
99
- - bundle copies of shadcn primitives
100
- - depend on shadcn as a package
101
- - ask you to pass a map of local `Button`, `Dialog`, or `Tabs` components into
102
- mdkit
103
- - ship Tailwind-only wrappers from the npm package and hope your build scans
104
- external package source
105
-
106
- The npm package stays focused on the durable logic. The registry item owns the
107
- app-local shadcn composition.
108
-
109
- ## Fallback Path
110
-
111
- If you do not use shadcn, use the base panels from the npm package:
112
-
113
- - `MdKitDocumentToolbar`
114
- - `VersionHistoryPanel`
115
- - `MdKitConflictPanel`
116
-
117
- They render plain semantic HTML with stable `mp-lb-mdkit-*` classes. Import
118
- `@mp-lb/mdkit/styles.css` for generic fallback styling, or
119
- replace the CSS entirely. See [Styling](./styling.md#component-styling).
120
-
121
- ## Status
122
-
123
- The mdkit testbench currently contains the reference shadcn workflow component.
124
- It is the target shape for the future registry/plugin item. Until that registry
125
- item exists, treat the base panels as the supported published path.