@tiptap/static-renderer 3.24.0 → 3.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +5 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -14
- package/dist/index.d.ts +42 -14
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/json/html-string/index.cjs +3 -3
- package/dist/json/html-string/index.cjs.map +1 -1
- package/dist/json/html-string/index.d.cts +39 -11
- package/dist/json/html-string/index.d.ts +39 -11
- package/dist/json/html-string/index.js +3 -3
- package/dist/json/html-string/index.js.map +1 -1
- package/dist/json/react/index.cjs +3 -3
- package/dist/json/react/index.cjs.map +1 -1
- package/dist/json/react/index.d.cts +39 -11
- package/dist/json/react/index.d.ts +39 -11
- package/dist/json/react/index.js +3 -3
- package/dist/json/react/index.js.map +1 -1
- package/dist/json/renderer.cjs +3 -3
- package/dist/json/renderer.cjs.map +1 -1
- package/dist/json/renderer.d.cts +36 -8
- package/dist/json/renderer.d.ts +36 -8
- package/dist/json/renderer.js +3 -3
- package/dist/json/renderer.js.map +1 -1
- package/dist/pm/html-string/index.cjs +3 -3
- package/dist/pm/html-string/index.cjs.map +1 -1
- package/dist/pm/html-string/index.d.cts +32 -4
- package/dist/pm/html-string/index.d.ts +32 -4
- package/dist/pm/html-string/index.js +3 -3
- package/dist/pm/html-string/index.js.map +1 -1
- package/dist/pm/markdown/index.cjs +5 -4
- package/dist/pm/markdown/index.cjs.map +1 -1
- package/dist/pm/markdown/index.d.cts +32 -4
- package/dist/pm/markdown/index.d.ts +32 -4
- package/dist/pm/markdown/index.js +5 -4
- package/dist/pm/markdown/index.js.map +1 -1
- package/dist/pm/react/index.cjs +3 -3
- package/dist/pm/react/index.cjs.map +1 -1
- package/dist/pm/react/index.d.cts +32 -4
- package/dist/pm/react/index.d.ts +32 -4
- package/dist/pm/react/index.js +3 -3
- package/dist/pm/react/index.js.map +1 -1
- package/package.json +5 -5
- package/src/json/html-string/string.ts +4 -6
- package/src/json/react/react.ts +4 -5
- package/src/json/renderer.ts +34 -8
- package/src/pm/markdown/markdown.ts +1 -1
package/src/json/renderer.ts
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
/* oslint-disableno-explicit-any */
|
|
2
|
-
import type {
|
|
2
|
+
import type { JSONContent } from '@tiptap/core'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A JSON representation of a mark (a Tiptap/ProseMirror mark serialized to JSON).
|
|
6
|
+
*/
|
|
7
|
+
export type JSONMarkType = NonNullable<JSONContent['marks']>[number]
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A JSON representation of a node (a Tiptap/ProseMirror node serialized to JSON).
|
|
11
|
+
*
|
|
12
|
+
* `marks` is tied to the `TMark` type parameter so the node<->mark relationship
|
|
13
|
+
* stays sound. This is also why we cannot simply default `TNodeType` to
|
|
14
|
+
* `JSONContent`: the generic constraint references `TMarkType` via
|
|
15
|
+
* `marks?: readonly TMarkType[]`, and `JSONContent.marks` is a *concrete* array,
|
|
16
|
+
* which TypeScript rejects ("TMarkType could be instantiated with a different
|
|
17
|
+
* subtype of constraint"). Parameterizing the node type by the same `TMark`
|
|
18
|
+
* avoids that bivariance error. Please don't "simplify" this back to
|
|
19
|
+
* `JSONContent` — it won't type-check.
|
|
20
|
+
*/
|
|
21
|
+
export type JSONNodeType<TMark extends { type: string | { name: string } } = JSONMarkType> = {
|
|
22
|
+
type?: string
|
|
23
|
+
attrs?: Record<string, any>
|
|
24
|
+
content?: JSONNodeType<TMark>[]
|
|
25
|
+
marks?: readonly TMark[]
|
|
26
|
+
text?: string
|
|
27
|
+
[key: string]: any
|
|
28
|
+
}
|
|
3
29
|
|
|
4
30
|
/**
|
|
5
31
|
* Props for a node renderer
|
|
@@ -62,15 +88,15 @@ export type TiptapStaticRendererOptions<
|
|
|
62
88
|
/**
|
|
63
89
|
* A mark type is either a JSON representation of a mark or a Prosemirror mark instance
|
|
64
90
|
*/
|
|
65
|
-
TMarkType extends { type: any } =
|
|
91
|
+
TMarkType extends { type: any } = JSONMarkType,
|
|
66
92
|
/**
|
|
67
93
|
* A node type is either a JSON representation of a node or a Prosemirror node instance
|
|
68
94
|
*/
|
|
69
95
|
TNodeType extends {
|
|
70
96
|
content?: { forEach: (cb: (node: TNodeType) => void) => void }
|
|
71
97
|
marks?: readonly TMarkType[]
|
|
72
|
-
type
|
|
73
|
-
} =
|
|
98
|
+
type?: string | { name: string }
|
|
99
|
+
} = JSONNodeType<TMarkType>,
|
|
74
100
|
/**
|
|
75
101
|
* A node renderer is a function that takes a node and its children and returns the rendered output
|
|
76
102
|
*/
|
|
@@ -123,15 +149,15 @@ export function TiptapStaticRenderer<
|
|
|
123
149
|
/**
|
|
124
150
|
* A mark type is either a JSON representation of a mark or a Prosemirror mark instance
|
|
125
151
|
*/
|
|
126
|
-
TMarkType extends { type: string | { name: string } } =
|
|
152
|
+
TMarkType extends { type: string | { name: string } } = JSONMarkType,
|
|
127
153
|
/**
|
|
128
154
|
* A node type is either a JSON representation of a node or a Prosemirror node instance
|
|
129
155
|
*/
|
|
130
156
|
TNodeType extends {
|
|
131
157
|
content?: { forEach: (cb: (node: TNodeType) => void) => void }
|
|
132
158
|
marks?: readonly TMarkType[]
|
|
133
|
-
type
|
|
134
|
-
} =
|
|
159
|
+
type?: string | { name: string }
|
|
160
|
+
} = JSONNodeType<TMarkType>,
|
|
135
161
|
/**
|
|
136
162
|
* A node renderer is a function that takes a node and its children and returns the rendered output
|
|
137
163
|
*/
|
|
@@ -184,7 +210,7 @@ export function TiptapStaticRenderer<
|
|
|
184
210
|
*/
|
|
185
211
|
parent?: TNodeType
|
|
186
212
|
}): TReturnType {
|
|
187
|
-
const nodeType = typeof content.type === 'string' ? content.type : content.type
|
|
213
|
+
const nodeType = typeof content.type === 'string' ? content.type : (content.type?.name ?? '')
|
|
188
214
|
const NodeHandler = nodeMapping[nodeType] ?? unhandledNode
|
|
189
215
|
|
|
190
216
|
if (!NodeHandler) {
|