@knapsack/tiptap-utils 4.100.1--canary.7985.eb739a3.0 → 4.100.1--canary.7997.dfd8d05.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/.turbo/turbo-test.log +12 -0
- package/dist/find-unrecognized-content.d.ts +64 -0
- package/dist/find-unrecognized-content.d.ts.map +1 -0
- package/dist/find-unrecognized-content.js +297 -0
- package/dist/find-unrecognized-content.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/tiptap-extensions.d.ts +10 -2
- package/dist/tiptap-extensions.d.ts.map +1 -1
- package/dist/tiptap-extensions.js +34 -2
- package/dist/tiptap-extensions.js.map +1 -1
- package/dist/unrecognized-content-placeholder-node.d.ts +16 -0
- package/dist/unrecognized-content-placeholder-node.d.ts.map +1 -0
- package/dist/unrecognized-content-placeholder-node.js +88 -0
- package/dist/unrecognized-content-placeholder-node.js.map +1 -0
- package/dist/unsupported-formatting-node.d.ts +10 -0
- package/dist/unsupported-formatting-node.d.ts.map +1 -0
- package/dist/unsupported-formatting-node.js +26 -0
- package/dist/unsupported-formatting-node.js.map +1 -0
- package/package.json +10 -8
- package/src/find-unrecognized-content.ts +386 -0
- package/src/index.ts +1 -0
- package/src/tiptap-extensions.ts +45 -1
- package/src/unrecognized-content-placeholder-node.ts +94 -0
- package/src/unsupported-formatting-node.ts +27 -0
- package/tsconfig.json +7 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
$ tsc -p tsconfig.test.json && vitest run
|
|
2
|
+
|
|
3
|
+
[1m[30m[46m RUN [49m[39m[22m [36mv4.1.9 [39m[90m/home/runner/work/app-monorepo/app-monorepo/libs/tiptap-utils[39m
|
|
4
|
+
|
|
5
|
+
[32m✓[39m src/find-unrecognized-content.test.ts [2m([22m[2m30 tests[22m[2m)[22m[32m 61[2mms[22m[39m
|
|
6
|
+
[32m✓[39m src/conceal-mode-schema-validity.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 29[2mms[22m[39m
|
|
7
|
+
|
|
8
|
+
[2m Test Files [22m [1m[32m2 passed[39m[22m[90m (2)[39m
|
|
9
|
+
[2m Tests [22m [1m[32m33 passed[39m[22m[90m (33)[39m
|
|
10
|
+
[2m Start at [22m 19:33:24
|
|
11
|
+
[2m Duration [22m 904ms[2m (transform 543ms, setup 0ms, import 867ms, tests 91ms, environment 0ms)[22m
|
|
12
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { JSONContent } from '@tiptap/core';
|
|
2
|
+
/**
|
|
3
|
+
* `'salvage'` (used for admins, and for Doctor's explicit Fix action):
|
|
4
|
+
* unrecognized nodes are replaced with their plain-text content, visibly
|
|
5
|
+
* flagged via an `unsupportedFormatting` node - an explicit, visible fix.
|
|
6
|
+
*
|
|
7
|
+
* `'conceal'` (used for everyone else): unrecognized content must not
|
|
8
|
+
* render or be visible at all, but also must not be destroyed by an
|
|
9
|
+
* unrelated edit elsewhere in the same document - only an admin's explicit
|
|
10
|
+
* action should ever cause it to be dropped. Each unrecognized node is
|
|
11
|
+
* replaced with an invisible `unrecognizedContentPlaceholder(Block)` node
|
|
12
|
+
* carrying the exact original JSON in an opaque attr; `restoreConcealedContent`
|
|
13
|
+
* splices it back in verbatim before a save is persisted.
|
|
14
|
+
*/
|
|
15
|
+
export type UnrecognizedContentMode = 'salvage' | 'conceal';
|
|
16
|
+
/**
|
|
17
|
+
* Walks a JSONContent tree (node.type, node.marks[].type at every level,
|
|
18
|
+
* including nested `content` arrays) and returns the deduped list of type
|
|
19
|
+
* names not present in `recognizedTypeNames`. Never calls
|
|
20
|
+
* `schema.nodeFromJSON`/`createNodeFromContent` - cannot trigger tiptap's
|
|
21
|
+
* destructive "empty the whole doc" fallback.
|
|
22
|
+
*/
|
|
23
|
+
export declare function findUnrecognizedTiptapTypes(content: JSONContent | null | undefined, recognizedTypeNames: ReadonlySet<string>): string[];
|
|
24
|
+
/**
|
|
25
|
+
* Returns a new tree with the unrecognized nodes/marks handled per `mode`
|
|
26
|
+
* (see `UnrecognizedContentMode`) - every recognized sibling/ancestor is
|
|
27
|
+
* left untouched. Unrecognized marks are mode-dependent, like unrecognized
|
|
28
|
+
* nodes: `'salvage'` drops the mark from the node's `marks` array, leaving
|
|
29
|
+
* the text unstyled and visibly rendering; `'conceal'` preserves the mark
|
|
30
|
+
* losslessly by concealing the whole marked node behind the same
|
|
31
|
+
* placeholder mechanism used for unrecognized node types, since dropping
|
|
32
|
+
* it would otherwise permanently destroy data conceal mode guarantees
|
|
33
|
+
* survives until an admin explicitly acts. Only if the root node's own
|
|
34
|
+
* `type` is unrecognized and nothing was preserved (salvage mode with no
|
|
35
|
+
* text) does this fall back to an empty doc, since there's no parent to
|
|
36
|
+
* replace it in place - reported via `removedTypes` either way, never
|
|
37
|
+
* silent to the caller.
|
|
38
|
+
*/
|
|
39
|
+
export declare function stripUnrecognizedTiptapContent(content: JSONContent | null | undefined, recognizedTypeNames: ReadonlySet<string>, { mode }?: {
|
|
40
|
+
mode?: UnrecognizedContentMode;
|
|
41
|
+
}): {
|
|
42
|
+
content: JSONContent | null | undefined;
|
|
43
|
+
removedTypes: string[];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Reverses `stripUnrecognizedTiptapContent`'s `mode: 'conceal'` - splices
|
|
47
|
+
* each `unrecognizedContentPlaceholder(Block)` node back into its exact
|
|
48
|
+
* original JSON before a save is persisted, so the original unrecognized
|
|
49
|
+
* content survives edits made anywhere else in the same document. A no-op
|
|
50
|
+
* on content with no placeholders (e.g. anything produced in `'salvage'`
|
|
51
|
+
* mode), so it's always safe to call unconditionally before saving.
|
|
52
|
+
*
|
|
53
|
+
* A placeholder's `original` attr is untrusted (see `parseOriginal`'s doc
|
|
54
|
+
* comment) - anything that doesn't parse, or doesn't look like plausible
|
|
55
|
+
* JSONContent, is left as the placeholder rather than spliced in. This
|
|
56
|
+
* bounds a forged placeholder's damage to "stays invisibly inert" instead
|
|
57
|
+
* of crashing the save or injecting arbitrary structure into the document;
|
|
58
|
+
* it does not (and can't, without signing the payload) distinguish a
|
|
59
|
+
* well-formed forged node from genuinely concealed content, since neither
|
|
60
|
+
* carries any proof of where it came from.
|
|
61
|
+
*/
|
|
62
|
+
export declare function restoreConcealedContent(content: JSONContent): JSONContent;
|
|
63
|
+
export declare function restoreConcealedContent(content: JSONContent | null | undefined): JSONContent | null | undefined;
|
|
64
|
+
//# sourceMappingURL=find-unrecognized-content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-unrecognized-content.d.ts","sourceRoot":"","sources":["../src/find-unrecognized-content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AA4GhD;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,uBAAuB,GAAG,SAAS,GAAG,SAAS,CAAC;AA8D5D;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,EACvC,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAAC,GACvC,MAAM,EAAE,CAKV;AA2DD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,EACvC,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAAC,EACxC,EAAE,IAAgB,EAAE,GAAE;IAAE,IAAI,CAAC,EAAE,uBAAuB,CAAA;CAAO,GAC5D;IAAE,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IAAC,YAAY,EAAE,MAAM,EAAE,CAAA;CAAE,CA8CrE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,CAAC;AAC3E,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GACtC,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A doc tiptap can always render, used only when the root node's own `type`
|
|
3
|
+
* is unrecognized and nothing was preserved from it (mode `'salvage'` found
|
|
4
|
+
* no text) - there's no parent to drop it from, so this is the one case
|
|
5
|
+
* where some emptying can be unavoidable. Every other unrecognized
|
|
6
|
+
* node/mark is handled in place, keeping all valid siblings intact.
|
|
7
|
+
*
|
|
8
|
+
* Handed out by reference to every caller hitting this fallback - frozen
|
|
9
|
+
* for the same reason `findUnrecognizedTypesCached` freezes its cached
|
|
10
|
+
* arrays (see doctor's detect-unrecognized-tiptap-content.ts): an
|
|
11
|
+
* accidental downstream mutation must fail loudly instead of silently
|
|
12
|
+
* corrupting this shared instance for every other block that reaches it.
|
|
13
|
+
*/
|
|
14
|
+
const EMPTY_DOC = Object.freeze({
|
|
15
|
+
type: 'doc',
|
|
16
|
+
content: [{ type: 'paragraph' }],
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Node types whose `content` is inline (text runs), not block content - an
|
|
20
|
+
* unrecognized child here is replaced with an inline node. Everywhere else
|
|
21
|
+
* (doc, blockquote, list items, table cells, ...) a replacement needs its
|
|
22
|
+
* own block-level node, since an inline node isn't valid block content.
|
|
23
|
+
*/
|
|
24
|
+
const INLINE_CONTAINER_TYPES = new Set([
|
|
25
|
+
'paragraph',
|
|
26
|
+
'heading',
|
|
27
|
+
]);
|
|
28
|
+
const PLACEHOLDER_TYPES = new Set([
|
|
29
|
+
'unrecognizedContentPlaceholder',
|
|
30
|
+
'unrecognizedContentPlaceholderBlock',
|
|
31
|
+
]);
|
|
32
|
+
/** See `UnrecognizedContentPlaceholderRoot`'s doc comment for why this is kept distinct from `PLACEHOLDER_TYPES`. */
|
|
33
|
+
const ROOT_PLACEHOLDER_TYPE = 'unrecognizedContentPlaceholderRoot';
|
|
34
|
+
/**
|
|
35
|
+
* A placeholder's `original` attr is plain HTML-attribute text, editable by
|
|
36
|
+
* anyone who can paste HTML into the editor (tiptap's `parseHTML` accepts
|
|
37
|
+
* it from clipboard content, not just content this module itself wrote) -
|
|
38
|
+
* treat it as untrusted input, not a value only this module ever produces.
|
|
39
|
+
* A generous cap on genuine concealed content, but bounds how much an
|
|
40
|
+
* unrelated forged attribute can bloat storage.
|
|
41
|
+
*/
|
|
42
|
+
const MAX_ORIGINAL_JSON_LENGTH = 100_000;
|
|
43
|
+
/**
|
|
44
|
+
* Parses `original`, returning `undefined` for anything malformed, oversized,
|
|
45
|
+
* or absent - never throws. `undefined` is unambiguous as a "parse failed"
|
|
46
|
+
* sentinel because a placeholder's `original` is always itself valid JSON
|
|
47
|
+
* (an object or array), never the JSON value `undefined`.
|
|
48
|
+
*/
|
|
49
|
+
function parseOriginal(raw) {
|
|
50
|
+
if (!raw || raw.length > MAX_ORIGINAL_JSON_LENGTH)
|
|
51
|
+
return undefined;
|
|
52
|
+
try {
|
|
53
|
+
return JSON.parse(raw);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The minimum shape `restoreConcealedContent` trusts enough to splice back
|
|
61
|
+
* in - anything else is left as the inert, non-rendering placeholder
|
|
62
|
+
* rather than guessed at. Checks the *whole* nested tree (every
|
|
63
|
+
* `content`/`marks` entry, at every depth), not just the top node - a
|
|
64
|
+
* forged `original` attr can be well-formed JSON with a valid-looking
|
|
65
|
+
* `type` at the root while carrying garbage (a string instead of an array,
|
|
66
|
+
* a number where a mark belongs) underneath, which would otherwise splice
|
|
67
|
+
* structurally-invalid JSONContent into the persisted document. This
|
|
68
|
+
* intentionally does NOT check that `type` names are recognized - a
|
|
69
|
+
* genuinely concealed node's `type` is unrecognized by definition, and
|
|
70
|
+
* restoring it is this function's entire purpose.
|
|
71
|
+
*/
|
|
72
|
+
function isPlausibleJSONContent(value) {
|
|
73
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const { type, content, marks } = value;
|
|
77
|
+
if (typeof type !== 'string')
|
|
78
|
+
return false;
|
|
79
|
+
if (content !== undefined) {
|
|
80
|
+
if (!Array.isArray(content) || !content.every(isPlausibleJSONContent)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (marks !== undefined) {
|
|
85
|
+
if (!Array.isArray(marks) ||
|
|
86
|
+
!marks.every((mark) => typeof mark === 'object' &&
|
|
87
|
+
mark !== null &&
|
|
88
|
+
typeof mark.type === 'string')) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
function extractPlainText(node) {
|
|
95
|
+
if (node.type === 'text')
|
|
96
|
+
return node.text ?? '';
|
|
97
|
+
return (node.content ?? []).map(extractPlainText).join('');
|
|
98
|
+
}
|
|
99
|
+
function isInlineContext(parentType) {
|
|
100
|
+
return !!parentType && INLINE_CONTAINER_TYPES.has(parentType);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The stand-in for an unrecognized node, wrapped to be valid in its
|
|
104
|
+
* parent's content model. In `'salvage'` mode this is the unstyled
|
|
105
|
+
* plain-text content wrapped in an `unsupportedFormatting` node (null - the
|
|
106
|
+
* node is dropped entirely - when there's no text to show). In `'conceal'`
|
|
107
|
+
* mode this is always an invisible placeholder carrying the original node
|
|
108
|
+
* losslessly, regardless of whether it has text.
|
|
109
|
+
*/
|
|
110
|
+
function buildReplacement(node, parentType, mode) {
|
|
111
|
+
const inline = isInlineContext(parentType);
|
|
112
|
+
if (mode === 'conceal') {
|
|
113
|
+
return {
|
|
114
|
+
type: inline
|
|
115
|
+
? 'unrecognizedContentPlaceholder'
|
|
116
|
+
: 'unrecognizedContentPlaceholderBlock',
|
|
117
|
+
attrs: { original: JSON.stringify([node]) },
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const text = extractPlainText(node);
|
|
121
|
+
if (!text)
|
|
122
|
+
return null;
|
|
123
|
+
const notice = {
|
|
124
|
+
type: 'unsupportedFormatting',
|
|
125
|
+
content: [{ type: 'text', text }],
|
|
126
|
+
};
|
|
127
|
+
return inline ? notice : { type: 'paragraph', content: [notice] };
|
|
128
|
+
}
|
|
129
|
+
function collectUnrecognizedTypes(node, recognizedTypeNames, found) {
|
|
130
|
+
if (node.type && !recognizedTypeNames.has(node.type)) {
|
|
131
|
+
found.add(node.type);
|
|
132
|
+
}
|
|
133
|
+
node.marks?.forEach((mark) => {
|
|
134
|
+
if (!recognizedTypeNames.has(mark.type)) {
|
|
135
|
+
found.add(mark.type);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
node.content?.forEach((child) => collectUnrecognizedTypes(child, recognizedTypeNames, found));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Walks a JSONContent tree (node.type, node.marks[].type at every level,
|
|
142
|
+
* including nested `content` arrays) and returns the deduped list of type
|
|
143
|
+
* names not present in `recognizedTypeNames`. Never calls
|
|
144
|
+
* `schema.nodeFromJSON`/`createNodeFromContent` - cannot trigger tiptap's
|
|
145
|
+
* destructive "empty the whole doc" fallback.
|
|
146
|
+
*/
|
|
147
|
+
export function findUnrecognizedTiptapTypes(content, recognizedTypeNames) {
|
|
148
|
+
if (!content)
|
|
149
|
+
return [];
|
|
150
|
+
const found = new Set();
|
|
151
|
+
collectUnrecognizedTypes(content, recognizedTypeNames, found);
|
|
152
|
+
return [...found];
|
|
153
|
+
}
|
|
154
|
+
function cleanNode(node, recognizedTypeNames, removed, mode) {
|
|
155
|
+
const cleaned = { ...node };
|
|
156
|
+
if (node.marks) {
|
|
157
|
+
const hasUnrecognizedMark = node.marks.some((mark) => !recognizedTypeNames.has(mark.type));
|
|
158
|
+
// Conceal mode's guarantee is lossless until an admin explicitly fixes
|
|
159
|
+
// it - dropping an unrecognized mark from `node.marks` below would
|
|
160
|
+
// permanently destroy it on a non-admin's save. Instead conceal the
|
|
161
|
+
// whole node (marks and all) behind the same placeholder mechanism
|
|
162
|
+
// used for unrecognized node types - always the inline placeholder,
|
|
163
|
+
// since marks only ever apply to inline/text nodes.
|
|
164
|
+
if (hasUnrecognizedMark && mode === 'conceal') {
|
|
165
|
+
node.marks.forEach((mark) => {
|
|
166
|
+
if (!recognizedTypeNames.has(mark.type))
|
|
167
|
+
removed.add(mark.type);
|
|
168
|
+
});
|
|
169
|
+
return {
|
|
170
|
+
type: 'unrecognizedContentPlaceholder',
|
|
171
|
+
attrs: { original: JSON.stringify([node]) },
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const keptMarks = node.marks.filter((mark) => {
|
|
175
|
+
const isRecognized = recognizedTypeNames.has(mark.type);
|
|
176
|
+
if (!isRecognized)
|
|
177
|
+
removed.add(mark.type);
|
|
178
|
+
return isRecognized;
|
|
179
|
+
});
|
|
180
|
+
if (keptMarks.length > 0) {
|
|
181
|
+
cleaned.marks = keptMarks;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
delete cleaned.marks;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (node.content) {
|
|
188
|
+
cleaned.content = node.content.flatMap((child) => {
|
|
189
|
+
const isRecognized = !child.type || recognizedTypeNames.has(child.type);
|
|
190
|
+
if (isRecognized) {
|
|
191
|
+
return [cleanNode(child, recognizedTypeNames, removed, mode)];
|
|
192
|
+
}
|
|
193
|
+
removed.add(child.type);
|
|
194
|
+
const replacement = buildReplacement(child, node.type, mode);
|
|
195
|
+
return replacement ? [replacement] : [];
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return cleaned;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Returns a new tree with the unrecognized nodes/marks handled per `mode`
|
|
202
|
+
* (see `UnrecognizedContentMode`) - every recognized sibling/ancestor is
|
|
203
|
+
* left untouched. Unrecognized marks are mode-dependent, like unrecognized
|
|
204
|
+
* nodes: `'salvage'` drops the mark from the node's `marks` array, leaving
|
|
205
|
+
* the text unstyled and visibly rendering; `'conceal'` preserves the mark
|
|
206
|
+
* losslessly by concealing the whole marked node behind the same
|
|
207
|
+
* placeholder mechanism used for unrecognized node types, since dropping
|
|
208
|
+
* it would otherwise permanently destroy data conceal mode guarantees
|
|
209
|
+
* survives until an admin explicitly acts. Only if the root node's own
|
|
210
|
+
* `type` is unrecognized and nothing was preserved (salvage mode with no
|
|
211
|
+
* text) does this fall back to an empty doc, since there's no parent to
|
|
212
|
+
* replace it in place - reported via `removedTypes` either way, never
|
|
213
|
+
* silent to the caller.
|
|
214
|
+
*/
|
|
215
|
+
export function stripUnrecognizedTiptapContent(content, recognizedTypeNames, { mode = 'salvage' } = {}) {
|
|
216
|
+
if (!content)
|
|
217
|
+
return { content, removedTypes: [] };
|
|
218
|
+
if (content.type && !recognizedTypeNames.has(content.type)) {
|
|
219
|
+
if (mode === 'conceal') {
|
|
220
|
+
return {
|
|
221
|
+
content: {
|
|
222
|
+
type: 'doc',
|
|
223
|
+
content: [
|
|
224
|
+
{
|
|
225
|
+
type: ROOT_PLACEHOLDER_TYPE,
|
|
226
|
+
// The whole original root node (its own type/attrs included,
|
|
227
|
+
// not just its children) - `restoreConcealedContent` returns
|
|
228
|
+
// this verbatim in place of the synthetic wrapping `doc`.
|
|
229
|
+
attrs: { original: JSON.stringify(content) },
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
removedTypes: [content.type],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
const text = extractPlainText(content);
|
|
237
|
+
return {
|
|
238
|
+
content: text
|
|
239
|
+
? {
|
|
240
|
+
type: 'doc',
|
|
241
|
+
content: [
|
|
242
|
+
{
|
|
243
|
+
type: 'paragraph',
|
|
244
|
+
content: [
|
|
245
|
+
{
|
|
246
|
+
type: 'unsupportedFormatting',
|
|
247
|
+
content: [{ type: 'text', text }],
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
}
|
|
253
|
+
: EMPTY_DOC,
|
|
254
|
+
removedTypes: [content.type],
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
const removed = new Set();
|
|
258
|
+
const cleaned = cleanNode(content, recognizedTypeNames, removed, mode);
|
|
259
|
+
return { content: cleaned, removedTypes: [...removed] };
|
|
260
|
+
}
|
|
261
|
+
export function restoreConcealedContent(content) {
|
|
262
|
+
if (!content?.content)
|
|
263
|
+
return content;
|
|
264
|
+
// The whole document was concealed (the root's own type was
|
|
265
|
+
// unrecognized) - restore the original root node itself instead of
|
|
266
|
+
// leaving it nested inside a synthetic `doc` it never actually had.
|
|
267
|
+
const [onlyChild] = content.content;
|
|
268
|
+
if (content.type === 'doc' &&
|
|
269
|
+
content.content.length === 1 &&
|
|
270
|
+
onlyChild.type === ROOT_PLACEHOLDER_TYPE) {
|
|
271
|
+
const restored = parseOriginal(onlyChild.attrs?.original);
|
|
272
|
+
return isPlausibleJSONContent(restored) ? restored : content;
|
|
273
|
+
}
|
|
274
|
+
return {
|
|
275
|
+
...content,
|
|
276
|
+
content: content.content.flatMap((child) => {
|
|
277
|
+
if (child.type && PLACEHOLDER_TYPES.has(child.type)) {
|
|
278
|
+
const restored = parseOriginal(child.attrs?.original);
|
|
279
|
+
return Array.isArray(restored) && restored.every(isPlausibleJSONContent)
|
|
280
|
+
? restored
|
|
281
|
+
: [child];
|
|
282
|
+
}
|
|
283
|
+
// A root placeholder that's no longer the doc's sole child (a sibling
|
|
284
|
+
// was added before save) misses the fast path above. Splice the
|
|
285
|
+
// original root node back in anyway - its type is still unrecognized,
|
|
286
|
+
// so the next load re-conceals it and detection keeps reporting it,
|
|
287
|
+
// rather than letting the raw (now-"recognized") placeholder type
|
|
288
|
+
// persist to storage unnoticed.
|
|
289
|
+
if (child.type === ROOT_PLACEHOLDER_TYPE) {
|
|
290
|
+
const restored = parseOriginal(child.attrs?.original);
|
|
291
|
+
return isPlausibleJSONContent(restored) ? [restored] : [child];
|
|
292
|
+
}
|
|
293
|
+
return [restoreConcealedContent(child)];
|
|
294
|
+
}),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=find-unrecognized-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-unrecognized-content.js","sourceRoot":"","sources":["../src/find-unrecognized-content.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,SAAS,GAAgB,MAAM,CAAC,MAAM,CAAC;IAC3C,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;CACjC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,sBAAsB,GAAwB,IAAI,GAAG,CAAC;IAC1D,WAAW;IACX,SAAS;CACV,CAAC,CAAC;AAEH,MAAM,iBAAiB,GAAwB,IAAI,GAAG,CAAC;IACrD,gCAAgC;IAChC,qCAAqC;CACtC,CAAC,CAAC;AAEH,qHAAqH;AACrH,MAAM,qBAAqB,GAAG,oCAAoC,CAAC;AAEnE;;;;;;;GAOG;AACH,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAEzC;;;;;GAKG;AACH,SAAS,aAAa,CAAC,GAAuB;IAC5C,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,wBAAwB;QAAE,OAAO,SAAS,CAAC;IACpE,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAS,sBAAsB,CAAC,KAAc;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,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CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;gBACtD,OAAO,sBAAsB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YACjE,CAAC;YACD,OAAO,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1C,CAAC,CAAC;KACH,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gCAAgC,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gCAAgC,CAAC"}
|
|
@@ -20,6 +20,8 @@ import { FileHandler } from '@tiptap/extension-file-handler';
|
|
|
20
20
|
import { FloatingMenu } from '@tiptap/extension-floating-menu';
|
|
21
21
|
import { Dropcursor, Gapcursor, Placeholder, UndoRedo } from '@tiptap/extensions';
|
|
22
22
|
import { Link } from './custom-link/link.js';
|
|
23
|
+
import { UnrecognizedContentPlaceholder, UnrecognizedContentPlaceholderBlock, UnrecognizedContentPlaceholderRoot } from './unrecognized-content-placeholder-node.js';
|
|
24
|
+
import { UnsupportedFormatting } from './unsupported-formatting-node.js';
|
|
23
25
|
export type { JSONContent, Editor };
|
|
24
26
|
export declare const baseExtensions: (import("@tiptap/core").Node<any, any> | import("@tiptap/core").Extension<any, any>)[];
|
|
25
27
|
/**
|
|
@@ -27,8 +29,14 @@ export declare const baseExtensions: (import("@tiptap/core").Node<any, any> | im
|
|
|
27
29
|
* so we do not include with the formatting options.
|
|
28
30
|
*/
|
|
29
31
|
export declare const formattingExtensions: (import("@tiptap/core").Node<import("@tiptap/extension-blockquote").BlockquoteOptions, any> | import("@tiptap/core").Mark<import("@tiptap/extension-bold").BoldOptions, any>)[];
|
|
30
|
-
export declare const listExtensions: (import("@tiptap/core").Node<import("@tiptap/extension-list").
|
|
32
|
+
export declare const listExtensions: (import("@tiptap/core").Node<import("@tiptap/extension-list").ListItemOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-list").BulletListOptions, any> | import("@tiptap/core").Extension<import("@tiptap/extension-list").ListKeymapOptions, any>)[];
|
|
31
33
|
export declare const tableExtensions: import("@tiptap/core").Node<import("@tiptap/extension-table").TableRowOptions, any>[];
|
|
32
34
|
export declare const allExtensions: (import("@tiptap/core").Node<any, any> | import("@tiptap/core").Extension<any, any> | import("@tiptap/core").Mark<import("@tiptap/extension-bold").BoldOptions, any>)[];
|
|
33
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Node/Mark type names that can legitimately appear as a `type` value
|
|
37
|
+
* anywhere in a JSONContent tree. Plain `Extension`s (Dropcursor,
|
|
38
|
+
* Placeholder, UndoRedo, etc.) never do, so they're excluded.
|
|
39
|
+
*/
|
|
40
|
+
export declare const recognizedTiptapTypeNames: ReadonlySet<string>;
|
|
41
|
+
export { Doc, Dropcursor, FileHandler, FloatingMenu, Gapcursor, Placeholder, UndoRedo, Text, Paragraph, Blockquote, Bold, BulletList, Code, CodeBlock, HardBreak, Heading, Strike, HorizontalRule, Image, Italic, Link, ListItem, ListKeymap, OrderedList, Table, TableCell, TableHeader, TableRow, TextAlign, Underline, UnsupportedFormatting, UnrecognizedContentPlaceholder, UnrecognizedContentPlaceholderBlock, UnrecognizedContentPlaceholderRoot, };
|
|
34
42
|
//# sourceMappingURL=tiptap-extensions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap-extensions.d.ts","sourceRoot":"","sources":["../src/tiptap-extensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,QAAQ,IAAI,GAAG,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EACL,UAAU,EACV,QAAQ,EACR,UAAU,EACV,WAAW,EACZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EACL,KAAK,EACL,SAAS,EACT,WAAW,EACX,QAAQ,EACT,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,8B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T,qBAAqB,EACrB,8BAA8B,EAC9B,mCAAmC,EACnC,kCAAkC,GACnC,CAAC"}
|
|
@@ -20,6 +20,8 @@ import { FloatingMenu } from '@tiptap/extension-floating-menu';
|
|
|
20
20
|
import { Dropcursor, Gapcursor, Placeholder, UndoRedo, } from '@tiptap/extensions';
|
|
21
21
|
// Custom extensions
|
|
22
22
|
import { Link } from './custom-link/link.js';
|
|
23
|
+
import { UnrecognizedContentPlaceholder, UnrecognizedContentPlaceholderBlock, UnrecognizedContentPlaceholderRoot, } from './unrecognized-content-placeholder-node.js';
|
|
24
|
+
import { UnsupportedFormatting } from './unsupported-formatting-node.js';
|
|
23
25
|
// Required for all Editor instances
|
|
24
26
|
export const baseExtensions = [
|
|
25
27
|
Doc,
|
|
@@ -45,9 +47,27 @@ export const formattingExtensions = [
|
|
|
45
47
|
Strike,
|
|
46
48
|
Underline,
|
|
47
49
|
];
|
|
50
|
+
// `ListItem`'s stock content spec is `'paragraph block*'` - the first
|
|
51
|
+
// child must be a node literally named `paragraph`, not merely a member of
|
|
52
|
+
// the `block` group. `UnrecognizedContentPlaceholderBlock` (`group:
|
|
53
|
+
// 'block'`, see unrecognized-content-placeholder-node.ts) can be swapped
|
|
54
|
+
// in as any block-level child by `stripUnrecognizedTiptapContent`'s
|
|
55
|
+
// `'conceal'` mode - including a list item's first child, for legacy
|
|
56
|
+
// content where the removed/unrecognized type was there. Under the stock
|
|
57
|
+
// spec that produces a schema-invalid document, which is exactly the
|
|
58
|
+
// condition that makes tiptap silently empty the whole document - the bug
|
|
59
|
+
// this package exists to eliminate, just reintroduced one level down.
|
|
60
|
+
// Relaxed to `'block+'` (a plain node/mark spec change, not a behavioral
|
|
61
|
+
// override of any command) so any `block`-group node - including a real
|
|
62
|
+
// `paragraph` - can lead a list item; ProseMirror's list commands
|
|
63
|
+
// (splitListItem/sinkListItem/liftListItem, used via ListKeymap) query the
|
|
64
|
+
// content match generically and aren't hardcoded to the `paragraph` name.
|
|
65
|
+
const ListItemAnyBlockFirst = ListItem.extend({
|
|
66
|
+
content: 'block+',
|
|
67
|
+
});
|
|
48
68
|
export const listExtensions = [
|
|
49
69
|
BulletList,
|
|
50
|
-
|
|
70
|
+
ListItemAnyBlockFirst,
|
|
51
71
|
OrderedList,
|
|
52
72
|
ListKeymap.configure({
|
|
53
73
|
listTypes: [
|
|
@@ -75,10 +95,22 @@ export const allExtensions = [
|
|
|
75
95
|
HorizontalRule,
|
|
76
96
|
Image,
|
|
77
97
|
Link,
|
|
98
|
+
UnsupportedFormatting,
|
|
99
|
+
UnrecognizedContentPlaceholder,
|
|
100
|
+
UnrecognizedContentPlaceholderBlock,
|
|
101
|
+
UnrecognizedContentPlaceholderRoot,
|
|
78
102
|
];
|
|
103
|
+
/**
|
|
104
|
+
* Node/Mark type names that can legitimately appear as a `type` value
|
|
105
|
+
* anywhere in a JSONContent tree. Plain `Extension`s (Dropcursor,
|
|
106
|
+
* Placeholder, UndoRedo, etc.) never do, so they're excluded.
|
|
107
|
+
*/
|
|
108
|
+
export const recognizedTiptapTypeNames = new Set(allExtensions
|
|
109
|
+
.filter((e) => e.type === 'node' || e.type === 'mark')
|
|
110
|
+
.map((e) => e.name));
|
|
79
111
|
// These need to get exported out as well so that each of their `import`
|
|
80
112
|
// statements exist in outputted code. That is needed because the TypeScript
|
|
81
113
|
// Declaration Merging of `@tiptap/core` to ensure that the `Editor` type has
|
|
82
114
|
// `Commands` from each of these extensions.
|
|
83
|
-
export { Doc, Dropcursor, FileHandler, FloatingMenu, Gapcursor, Placeholder, UndoRedo, Text, Paragraph, Blockquote, Bold, BulletList, Code, CodeBlock, HardBreak, Heading, Strike, HorizontalRule, Image, Italic, Link, ListItem, ListKeymap, OrderedList, Table, TableCell, TableHeader, TableRow, TextAlign, Underline, };
|
|
115
|
+
export { Doc, Dropcursor, FileHandler, FloatingMenu, Gapcursor, Placeholder, UndoRedo, Text, Paragraph, Blockquote, Bold, BulletList, Code, CodeBlock, HardBreak, Heading, Strike, HorizontalRule, Image, Italic, Link, ListItem, ListKeymap, OrderedList, Table, TableCell, TableHeader, TableRow, TextAlign, Underline, UnsupportedFormatting, UnrecognizedContentPlaceholder, UnrecognizedContentPlaceholderBlock, UnrecognizedContentPlaceholderRoot, };
|
|
84
116
|
//# sourceMappingURL=tiptap-extensions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap-extensions.js","sourceRoot":"","sources":["../src/tiptap-extensions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,QAAQ,IAAI,GAAG,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EACL,UAAU,EACV,QAAQ,EACR,UAAU,EACV,WAAW,GACZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EACL,KAAK,EACL,SAAS,EACT,WAAW,EACX,QAAQ,GACT,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,C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qBAAqB,EACrB,8BAA8B,EAC9B,mCAAmC,EACnC,kCAAkC,GACnC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
export declare const UnrecognizedContentPlaceholder: Node<any, any>;
|
|
3
|
+
export declare const UnrecognizedContentPlaceholderBlock: Node<any, any>;
|
|
4
|
+
/**
|
|
5
|
+
* Distinct from `UnrecognizedContentPlaceholderBlock` even though it's
|
|
6
|
+
* schema-identical - this one is only ever the sole child of the
|
|
7
|
+
* synthetic wrapping `doc` `stripUnrecognizedTiptapContent` builds when
|
|
8
|
+
* the ROOT node's own type is unrecognized (there's no real parent to
|
|
9
|
+
* hold a child placeholder in that case). The distinct name lets
|
|
10
|
+
* `restoreConcealedContent` tell "the whole document was concealed" apart
|
|
11
|
+
* from "one ordinary child among others was concealed" and restore the
|
|
12
|
+
* original root type itself, rather than leaving it wrapped in a `doc` it
|
|
13
|
+
* never actually had.
|
|
14
|
+
*/
|
|
15
|
+
export declare const UnrecognizedContentPlaceholderRoot: Node<any, any>;
|
|
16
|
+
//# sourceMappingURL=unrecognized-content-placeholder-node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unrecognized-content-placeholder-node.d.ts","sourceRoot":"","sources":["../src/unrecognized-content-placeholder-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AAoBrD,eAAO,MAAM,8BAA8B,gBAoBzC,CAAC;AAEH,eAAO,MAAM,mCAAmC,gBAmB9C,CAAC;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kCAAkC,gBAmB7C,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Node, mergeAttributes } from '@tiptap/core';
|
|
2
|
+
/**
|
|
3
|
+
* `stripUnrecognizedTiptapContent`'s `mode: 'conceal'` (see
|
|
4
|
+
* `find-unrecognized-content.ts`) substitutes one of these for an
|
|
5
|
+
* unrecognized node - never a bare `text`/`unsupportedFormatting` node, so
|
|
6
|
+
* nothing about the removed content renders. The original node's exact
|
|
7
|
+
* JSON is round-tripped through the `original` attr (as a JSON string, so
|
|
8
|
+
* its own possibly-unrecognized nested types never reach the schema) and
|
|
9
|
+
* spliced back in verbatim by `restoreConcealedContent` before a save is
|
|
10
|
+
* persisted - so an edit elsewhere in the same document never destroys it.
|
|
11
|
+
* `selectable: false` keeps it out of normal selection; nothing renders so
|
|
12
|
+
* there's nothing to click on regardless.
|
|
13
|
+
*/
|
|
14
|
+
function addOriginalAttribute() {
|
|
15
|
+
return {
|
|
16
|
+
original: { default: '[]' },
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export const UnrecognizedContentPlaceholder = Node.create({
|
|
20
|
+
name: 'unrecognizedContentPlaceholder',
|
|
21
|
+
group: 'inline',
|
|
22
|
+
inline: true,
|
|
23
|
+
atom: true,
|
|
24
|
+
selectable: false,
|
|
25
|
+
addAttributes: addOriginalAttribute,
|
|
26
|
+
parseHTML() {
|
|
27
|
+
return [{ tag: 'span[data-unrecognized-content-placeholder]' }];
|
|
28
|
+
},
|
|
29
|
+
renderHTML({ HTMLAttributes }) {
|
|
30
|
+
return [
|
|
31
|
+
'span',
|
|
32
|
+
mergeAttributes(HTMLAttributes, {
|
|
33
|
+
'data-unrecognized-content-placeholder': '',
|
|
34
|
+
style: 'display:none',
|
|
35
|
+
}),
|
|
36
|
+
];
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
export const UnrecognizedContentPlaceholderBlock = Node.create({
|
|
40
|
+
name: 'unrecognizedContentPlaceholderBlock',
|
|
41
|
+
group: 'block',
|
|
42
|
+
atom: true,
|
|
43
|
+
selectable: false,
|
|
44
|
+
addAttributes: addOriginalAttribute,
|
|
45
|
+
parseHTML() {
|
|
46
|
+
return [{ tag: 'div[data-unrecognized-content-placeholder-block]' }];
|
|
47
|
+
},
|
|
48
|
+
renderHTML({ HTMLAttributes }) {
|
|
49
|
+
return [
|
|
50
|
+
'div',
|
|
51
|
+
mergeAttributes(HTMLAttributes, {
|
|
52
|
+
'data-unrecognized-content-placeholder-block': '',
|
|
53
|
+
style: 'display:none',
|
|
54
|
+
}),
|
|
55
|
+
];
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Distinct from `UnrecognizedContentPlaceholderBlock` even though it's
|
|
60
|
+
* schema-identical - this one is only ever the sole child of the
|
|
61
|
+
* synthetic wrapping `doc` `stripUnrecognizedTiptapContent` builds when
|
|
62
|
+
* the ROOT node's own type is unrecognized (there's no real parent to
|
|
63
|
+
* hold a child placeholder in that case). The distinct name lets
|
|
64
|
+
* `restoreConcealedContent` tell "the whole document was concealed" apart
|
|
65
|
+
* from "one ordinary child among others was concealed" and restore the
|
|
66
|
+
* original root type itself, rather than leaving it wrapped in a `doc` it
|
|
67
|
+
* never actually had.
|
|
68
|
+
*/
|
|
69
|
+
export const UnrecognizedContentPlaceholderRoot = Node.create({
|
|
70
|
+
name: 'unrecognizedContentPlaceholderRoot',
|
|
71
|
+
group: 'block',
|
|
72
|
+
atom: true,
|
|
73
|
+
selectable: false,
|
|
74
|
+
addAttributes: addOriginalAttribute,
|
|
75
|
+
parseHTML() {
|
|
76
|
+
return [{ tag: 'div[data-unrecognized-content-placeholder-root]' }];
|
|
77
|
+
},
|
|
78
|
+
renderHTML({ HTMLAttributes }) {
|
|
79
|
+
return [
|
|
80
|
+
'div',
|
|
81
|
+
mergeAttributes(HTMLAttributes, {
|
|
82
|
+
'data-unrecognized-content-placeholder-root': '',
|
|
83
|
+
style: 'display:none',
|
|
84
|
+
}),
|
|
85
|
+
];
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=unrecognized-content-placeholder-node.js.map
|