@growth-labs/cms 0.5.17 → 0.5.19
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/README.md +66 -0
- package/dist/engine/published-content.js +1 -1
- package/dist/engine/published-content.js.map +1 -1
- package/dist/engine/publisher.d.ts +6 -0
- package/dist/engine/publisher.d.ts.map +1 -1
- package/dist/engine/publisher.js +16 -7
- package/dist/engine/publisher.js.map +1 -1
- package/dist/engine/revisions.d.ts.map +1 -1
- package/dist/engine/revisions.js +1 -0
- package/dist/engine/revisions.js.map +1 -1
- package/dist/routes/content.d.ts.map +1 -1
- package/dist/routes/content.js +19 -1
- package/dist/routes/content.js.map +1 -1
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +1 -0
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/migrations.d.ts.map +1 -1
- package/dist/schema/migrations.js +7 -0
- package/dist/schema/migrations.js.map +1 -1
- package/dist/schema/portable-text.d.ts +52 -0
- package/dist/schema/portable-text.d.ts.map +1 -0
- package/dist/schema/portable-text.js +94 -0
- package/dist/schema/portable-text.js.map +1 -0
- package/dist/schema/types.d.ts +2 -0
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/types.js.map +1 -1
- package/dist/ui/editor/ContentForm.d.ts.map +1 -1
- package/dist/ui/editor/ContentForm.js +5 -3
- package/dist/ui/editor/ContentForm.js.map +1 -1
- package/dist/ui/editor/Rte.d.ts +12 -3
- package/dist/ui/editor/Rte.d.ts.map +1 -1
- package/dist/ui/editor/Rte.js +91 -10
- package/dist/ui/editor/Rte.js.map +1 -1
- package/dist/ui/editor/blocks.d.ts +17 -0
- package/dist/ui/editor/blocks.d.ts.map +1 -0
- package/dist/ui/editor/blocks.js +113 -0
- package/dist/ui/editor/blocks.js.map +1 -0
- package/dist/ui/editor/content-payload.d.ts +2 -0
- package/dist/ui/editor/content-payload.d.ts.map +1 -1
- package/dist/ui/editor/content-payload.js +1 -0
- package/dist/ui/editor/content-payload.js.map +1 -1
- package/dist/ui/editor/extensions.d.ts +1 -1
- package/dist/ui/editor/extensions.d.ts.map +1 -1
- package/dist/ui/editor/extensions.js +9 -0
- package/dist/ui/editor/extensions.js.map +1 -1
- package/dist/ui/editor/portable-text.d.ts +7 -0
- package/dist/ui/editor/portable-text.d.ts.map +1 -0
- package/dist/ui/editor/portable-text.js +517 -0
- package/dist/ui/editor/portable-text.js.map +1 -0
- package/dist/ui/editor/serialize.d.ts.map +1 -1
- package/dist/ui/editor/serialize.js +195 -5
- package/dist/ui/editor/serialize.js.map +1 -1
- package/dist/ui/styles/broadsheet.css +21 -0
- package/migrations/0024_article_portable_text.sql +6 -0
- package/package.json +2 -1
- package/src/engine/published-content.ts +1 -1
- package/src/engine/publisher.ts +22 -5
- package/src/engine/revisions.ts +2 -0
- package/src/routes/content.ts +20 -1
- package/src/schema/index.ts +8 -0
- package/src/schema/migrations.ts +7 -0
- package/src/schema/portable-text.ts +118 -0
- package/src/schema/types.ts +2 -0
- package/src/ui/editor/ContentForm.tsx +8 -2
- package/src/ui/editor/Rte.tsx +120 -10
- package/src/ui/editor/blocks.ts +140 -0
- package/src/ui/editor/content-payload.ts +3 -0
- package/src/ui/editor/extensions.ts +9 -0
- package/src/ui/editor/portable-text.ts +582 -0
- package/src/ui/editor/serialize.ts +207 -5
- package/src/ui/styles/broadsheet.css +21 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blocks.js","sourceRoot":"","sources":["../../../src/ui/editor/blocks.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,4EAA4E;AAC5E,6EAA6E;AAC7E,6DAA6D;AAC7D,kEAAkE;AAClE,wEAAwE;AACxE,0EAA0E;AAC1E,4EAA4E;AAE5E,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAE1D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAM,EA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,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC;IACnC,IAAI,EAAE,UAAU;IAEhB,aAAa;QACZ,OAAO;YACN,IAAI,EAAE;gBACL,OAAO,EAAE,EAAE;gBACX,SAAS,EAAE,CAAC,OAAoB,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE;gBACvE,UAAU,EAAE,CAAC,UAAmC,EAAE,EAAE,CAAC,CAAC;oBACrD,IAAI,EAAE,UAAU,CAAC,IAAI;iBACrB,CAAC;aACF;SACD,CAAA;IACF,CAAC;IAED,SAAS;QACR,OAAO,CAAC,EAAE,GAAG,EAAE,kBAAkB,EAAE,CAAC,CAAA;IACrC,CAAC;IAED,UAAU,CAAC,EAAE,cAAc,EAAE;QAC5B,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,cAAc,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAC1E,CAAC;CACD,CAAC,CAAA"}
|
|
@@ -3,6 +3,8 @@ export interface ContentDraftFields {
|
|
|
3
3
|
title: string;
|
|
4
4
|
dek: string;
|
|
5
5
|
body: string;
|
|
6
|
+
/** Serialized Portable Text envelope for the body; null until the editor emits one. */
|
|
7
|
+
bodyPortableText?: string | null;
|
|
6
8
|
videoUrl: string;
|
|
7
9
|
videoSourceKind?: string | null;
|
|
8
10
|
videoId?: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-payload.d.ts","sourceRoot":"","sources":["../../../src/ui/editor/content-payload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,MAAM,WAAW,kBAAkB;IAClC,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,CAAC,EAAE,MAAM,GAAG,IA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AAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAG3E;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQlD;AAED,wBAAgB,qBAAqB,CACpC,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,kBAAkB,GACvB,OAAO,CAkBT;AAED,wBAAgB,6BAA6B,CAC5C,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,kBAAkB,GACvB,MAAM,GAAG,IAAI,CAUf;AAED,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAe9E;AAED,wBAAgB,yBAAyB,CACxC,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,kBAAkB,GACvB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA6CzB;AAED,wBAAgB,yBAAyB,CACxC,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,kBAAkB,GACvB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQzB"}
|
|
@@ -70,6 +70,7 @@ export function buildContentUpdatePayload(contentType, draft) {
|
|
|
70
70
|
const wordCount = countWords(draft.body);
|
|
71
71
|
payload.content = {
|
|
72
72
|
bodyMarkdown: draft.body,
|
|
73
|
+
bodyPortableText: draft.bodyPortableText || null,
|
|
73
74
|
wordCount,
|
|
74
75
|
readTimeMinutes: estimateReadTime(wordCount),
|
|
75
76
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-payload.js","sourceRoot":"","sources":["../../../src/ui/editor/content-payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"content-payload.js","sourceRoot":"","sources":["../../../src/ui/editor/content-payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAmBxE,MAAM,UAAU,6BAA6B,CAAC,KAAc;IAC3D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,IAAI,CAAA;IACnF,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACxB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAa;IACzC,OAAO,KAAK;SACV,WAAW,EAAE;SACb,IAAI,EAAE;SACN,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;SACxB,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC;SACxB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;AACf,CAAC;AAED,MAAM,UAAU,qBAAqB,CACpC,WAAwB,EACxB,KAAyB;IAEzB,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAA;IAC/C,IAAI,WAAW,KAAK,SAAS,IAAI,WAAW,KAAK,YAAY,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;QACzF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAA;IACpC,CAAC;IACD,IAAI,WAAW,KAAK,OAAO,EAAE,CAAC;QAC7B,OAAO,CACN,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;YAChC,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ACZ,CAAC,CAAC;oBACA,mBAAmB,EAAE,SAAS;oBAC9B,oBAAoB,EAAE,KAAK,CAAC,eAAe,IAAI,oBAAoB,CAAC,SAAS,CAAC;iBAC9E;gBACF,CAAC,CAAC,EAAE,CAAC;SACN,CAAA;IACF,CAAC;SAAM,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,CAAC,OAAO,GAAG;YACjB,UAAU,EAAE,EAAE;YACd,UAAU,EAAE,KAAK,CAAC,QAAQ;YAC1B,eAAe,EAAE,6BAA6B,CAAC,KAAK,CAAC,eAAe,CAAC;SACrE,CAAA;IACF,CAAC;IAED,OAAO,OAAO,CAAA;AACf,CAAC;AAED,MAAM,UAAU,yBAAyB,CACxC,WAAwB,EACxB,KAAyB;IAEzB,MAAM,OAAO,GAA4B;QACxC,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,KAAK,IAAI,UAAU,CAAC;QAC7C,GAAG,yBAAyB,CAAC,WAAW,EAAE,KAAK,CAAC;KAChD,CAAA;IACD,IAAI,OAAO,CAAC,eAAe,KAAK,IAAI;QAAE,OAAO,OAAO,CAAC,eAAe,CAAA;IACpE,OAAO,OAAO,CAAA;AACf,CAAC"}
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
* and interleaved underscores through link syntax (the recurring "hyperlinks
|
|
7
7
|
* formatted incorrectly" incidents). With no underline extension, TipTap
|
|
8
8
|
* silently drops underline styling on paste — Word documents come in clean. */
|
|
9
|
-
export declare function createRteExtensions(): (import("@tiptap/core").
|
|
9
|
+
export declare function createRteExtensions(): (import("@tiptap/core").Node<any, any> | import("@tiptap/core").Mark<any, any> | import("@tiptap/core").Extension<any, any> | import("@tiptap/core").Extension<import("@tiptap/starter-kit").StarterKitOptions, any> | import("@tiptap/core").Mark<import("@tiptap/extension-link").LinkOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-image").ImageOptions, any> | import("@tiptap/core").Extension<import("@tiptap/extension-table").TableKitOptions, any>)[];
|
|
10
10
|
//# sourceMappingURL=extensions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../../../src/ui/editor/extensions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../../../src/ui/editor/extensions.ts"],"names":[],"mappings":"AAQA;;;;;;;+EAO+E;AAC/E,wBAAgB,mBAAmB,2dAelC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import Image from '@tiptap/extension-image';
|
|
2
2
|
import Link from '@tiptap/extension-link';
|
|
3
|
+
import { TableKit } from '@tiptap/extension-table';
|
|
3
4
|
import StarterKit from '@tiptap/starter-kit';
|
|
5
|
+
import { Callout, Citation, GeneratedFaq, PullQuote } from './blocks.js';
|
|
4
6
|
import { TrimBoundaryMarks } from './trim-boundary-marks.js';
|
|
5
7
|
import { TweetEmbed } from './tweet-embed.js';
|
|
6
8
|
/** The single extension set used by Masthead and its behavioral editor tests.
|
|
@@ -18,6 +20,13 @@ export function createRteExtensions() {
|
|
|
18
20
|
TrimBoundaryMarks,
|
|
19
21
|
Image,
|
|
20
22
|
TweetEmbed,
|
|
23
|
+
// One consolidated package registers table/tableRow/tableHeader/tableCell.
|
|
24
|
+
// Gapcursor (via StarterKit) lets the caret sit before/after a table.
|
|
25
|
+
TableKit.configure({ table: { resizable: true } }),
|
|
26
|
+
Callout,
|
|
27
|
+
PullQuote,
|
|
28
|
+
GeneratedFaq,
|
|
29
|
+
Citation,
|
|
21
30
|
];
|
|
22
31
|
}
|
|
23
32
|
//# sourceMappingURL=extensions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extensions.js","sourceRoot":"","sources":["../../../src/ui/editor/extensions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,yBAAyB,CAAA;AAC3C,OAAO,IAAI,MAAM,wBAAwB,CAAA;AACzC,OAAO,U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,YAAY;QACZ,QAAQ;KACR,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { JSONContent } from '@tiptap/core';
|
|
2
|
+
import type { PortableTextObject } from '../../schema/portable-text.js';
|
|
3
|
+
/** Serialise a Tiptap JSONContent document to a Portable Text array. */
|
|
4
|
+
export declare function docToPortableText(doc: JSONContent): PortableTextObject[];
|
|
5
|
+
/** Parse a Portable Text array back into a Tiptap JSONContent document. */
|
|
6
|
+
export declare function portableTextToDoc(blocks: PortableTextObject[]): JSONContent;
|
|
7
|
+
//# sourceMappingURL=portable-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portable-text.d.ts","sourceRoot":"","sources":["../../../src/ui/editor/portable-text.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AA+BvE,wEAAwE;AACxE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,WAAW,GAAG,kBAAkB,EAAE,CAIxE;AA8SD,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,WAAW,CAE3E"}
|
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
// src/ui/editor/portable-text.ts
|
|
2
|
+
// PURE Tiptap doc↔Portable Text serializer pair.
|
|
3
|
+
// Operates exclusively on the ProseMirror JSONContent shape — no Editor,
|
|
4
|
+
// no EditorView, no DOM, fully testable in vitest (Node env).
|
|
5
|
+
//
|
|
6
|
+
// Portable Text is the durable store (schema/portable-text.ts documents the
|
|
7
|
+
// version 1 vocabulary); markdown stays a derived view produced by
|
|
8
|
+
// serialize.ts from the same Tiptap doc. Both serializers here are total over
|
|
9
|
+
// the editor's node set — an unknown node degrades to its text content on the
|
|
10
|
+
// way out, and an unknown `_type` throws on the way in so a vocabulary drift
|
|
11
|
+
// fails loudly instead of silently dropping content.
|
|
12
|
+
//
|
|
13
|
+
// Mark mapping (Tiptap ↔ Portable Text):
|
|
14
|
+
// bold ↔ strong, italic ↔ em, strike ↔ strike-through, code ↔ code,
|
|
15
|
+
// link ↔ markDef annotation { _type: 'link', href, title?, target? }
|
|
16
|
+
// Lists are stored FLAT (listItem + level per block) per the Portable Text
|
|
17
|
+
// convention; nesting is reconstructed on load. Hard breaks are stored as
|
|
18
|
+
// newlines inside span text.
|
|
19
|
+
import { normalizeBoundaryMarks } from './trim-boundary-marks.js';
|
|
20
|
+
/** Deterministic 12-hex key sequence: identical docs serialize identically. */
|
|
21
|
+
function createKeyGenerator() {
|
|
22
|
+
let n = 0;
|
|
23
|
+
return () => {
|
|
24
|
+
n += 1;
|
|
25
|
+
return n.toString(16).padStart(12, '0');
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
29
|
+
// docToPortableText — JSONContent → PortableTextObject[]
|
|
30
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
31
|
+
const DECORATOR_BY_TIPTAP_MARK = {
|
|
32
|
+
bold: 'strong',
|
|
33
|
+
italic: 'em',
|
|
34
|
+
strike: 'strike-through',
|
|
35
|
+
code: 'code',
|
|
36
|
+
};
|
|
37
|
+
/** Serialise a Tiptap JSONContent document to a Portable Text array. */
|
|
38
|
+
export function docToPortableText(doc) {
|
|
39
|
+
const normalized = normalizeBoundaryMarks(doc);
|
|
40
|
+
const nextKey = createKeyGenerator();
|
|
41
|
+
return serializeBlocks(normalized.content ?? [], nextKey);
|
|
42
|
+
}
|
|
43
|
+
function serializeBlocks(nodes, nextKey) {
|
|
44
|
+
const out = [];
|
|
45
|
+
for (const node of nodes)
|
|
46
|
+
serializeBlockNode(node, out, nextKey, null);
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
function serializeBlockNode(node, out, nextKey, list) {
|
|
50
|
+
switch (node.type ?? 'paragraph') {
|
|
51
|
+
case 'paragraph':
|
|
52
|
+
out.push(buildTextBlock('normal', node.content ?? [], nextKey, list));
|
|
53
|
+
return;
|
|
54
|
+
case 'heading': {
|
|
55
|
+
const level = node.attrs?.level ?? 2;
|
|
56
|
+
out.push(buildTextBlock(`h${level}`, node.content ?? [], nextKey, list));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
case 'blockquote': {
|
|
60
|
+
for (const child of node.content ?? []) {
|
|
61
|
+
if (child.type === 'paragraph') {
|
|
62
|
+
out.push(buildTextBlock('blockquote', child.content ?? [], nextKey, list));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
serializeBlockNode(child, out, nextKey, list);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
case 'bulletList':
|
|
71
|
+
serializeList(node, out, nextKey, 'bullet', list ? list.level + 1 : 1);
|
|
72
|
+
return;
|
|
73
|
+
case 'orderedList':
|
|
74
|
+
serializeList(node, out, nextKey, 'number', list ? list.level + 1 : 1);
|
|
75
|
+
return;
|
|
76
|
+
case 'codeBlock': {
|
|
77
|
+
const code = (node.content ?? []).map((child) => child.text ?? '').join('');
|
|
78
|
+
out.push({
|
|
79
|
+
_type: 'code',
|
|
80
|
+
_key: nextKey(),
|
|
81
|
+
language: node.attrs?.language ?? null,
|
|
82
|
+
code,
|
|
83
|
+
});
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
case 'image':
|
|
87
|
+
out.push(imageObject(node, nextKey));
|
|
88
|
+
return;
|
|
89
|
+
case 'tweetEmbed':
|
|
90
|
+
out.push({
|
|
91
|
+
_type: 'tweetEmbed',
|
|
92
|
+
_key: nextKey(),
|
|
93
|
+
url: node.attrs?.url ?? '',
|
|
94
|
+
});
|
|
95
|
+
return;
|
|
96
|
+
case 'horizontalRule':
|
|
97
|
+
out.push({ _type: 'horizontalRule', _key: nextKey() });
|
|
98
|
+
return;
|
|
99
|
+
case 'table':
|
|
100
|
+
out.push(serializeTable(node, nextKey));
|
|
101
|
+
return;
|
|
102
|
+
case 'callout':
|
|
103
|
+
out.push({
|
|
104
|
+
_type: 'callout',
|
|
105
|
+
_key: nextKey(),
|
|
106
|
+
tone: node.attrs?.tone ?? 'note',
|
|
107
|
+
content: serializeBlocks(node.content ?? [], nextKey),
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
case 'pullQuote':
|
|
111
|
+
out.push({
|
|
112
|
+
_type: 'pullQuote',
|
|
113
|
+
_key: nextKey(),
|
|
114
|
+
attribution: node.attrs?.attribution ?? null,
|
|
115
|
+
content: serializeBlocks(node.content ?? [], nextKey),
|
|
116
|
+
});
|
|
117
|
+
return;
|
|
118
|
+
case 'generatedFaq':
|
|
119
|
+
out.push({
|
|
120
|
+
_type: 'generatedFaq',
|
|
121
|
+
_key: nextKey(),
|
|
122
|
+
markdown: node.attrs?.markdown ?? '',
|
|
123
|
+
});
|
|
124
|
+
return;
|
|
125
|
+
default: {
|
|
126
|
+
// Unknown block: keep its text content rather than dropping it.
|
|
127
|
+
const inline = node.content ?? [];
|
|
128
|
+
if (inline.length > 0)
|
|
129
|
+
out.push(buildTextBlock('normal', inline, nextKey, list));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function serializeList(node, out, nextKey, kind, level) {
|
|
134
|
+
for (const item of node.content ?? []) {
|
|
135
|
+
for (const child of item.content ?? []) {
|
|
136
|
+
if (child.type === 'paragraph') {
|
|
137
|
+
out.push(buildTextBlock('normal', child.content ?? [], nextKey, { kind, level }));
|
|
138
|
+
}
|
|
139
|
+
else if (child.type === 'bulletList') {
|
|
140
|
+
serializeList(child, out, nextKey, 'bullet', level + 1);
|
|
141
|
+
}
|
|
142
|
+
else if (child.type === 'orderedList') {
|
|
143
|
+
serializeList(child, out, nextKey, 'number', level + 1);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
serializeBlockNode(child, out, nextKey, { kind, level });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function imageObject(node, nextKey) {
|
|
152
|
+
return {
|
|
153
|
+
_type: 'image',
|
|
154
|
+
_key: nextKey(),
|
|
155
|
+
src: node.attrs?.src ?? '',
|
|
156
|
+
alt: node.attrs?.alt ?? '',
|
|
157
|
+
title: node.attrs?.title ?? null,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function buildTextBlock(style, inline, nextKey, list) {
|
|
161
|
+
const markDefs = [];
|
|
162
|
+
const pending = [];
|
|
163
|
+
const pushText = (text, marks) => {
|
|
164
|
+
const previous = pending[pending.length - 1];
|
|
165
|
+
if (previous &&
|
|
166
|
+
!('_type' in previous) &&
|
|
167
|
+
JSON.stringify(previous.marks) === JSON.stringify(marks)) {
|
|
168
|
+
previous.text += text;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
pending.push({ marks, text });
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
for (const node of inline) {
|
|
175
|
+
if (node.type === 'hardBreak') {
|
|
176
|
+
pushText('\n', []);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (node.type === 'image') {
|
|
180
|
+
pending.push(imageObject(node, nextKey));
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const text = node.text ?? '';
|
|
184
|
+
if (text === '' && (node.marks ?? []).length === 0 && node.type !== 'text')
|
|
185
|
+
continue;
|
|
186
|
+
const marks = [];
|
|
187
|
+
for (const mark of node.marks ?? []) {
|
|
188
|
+
const decorator = DECORATOR_BY_TIPTAP_MARK[mark.type ?? ''];
|
|
189
|
+
if (decorator) {
|
|
190
|
+
marks.push(decorator);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (mark.type === 'link') {
|
|
194
|
+
marks.push(linkMarkDefKey(mark, markDefs, nextKey));
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (mark.type === 'citation') {
|
|
198
|
+
marks.push(citationMarkDefKey(mark, markDefs, nextKey));
|
|
199
|
+
}
|
|
200
|
+
// Marks without a Portable Text form (legacy underline) are dropped,
|
|
201
|
+
// matching the markdown serializer.
|
|
202
|
+
}
|
|
203
|
+
pushText(text, marks);
|
|
204
|
+
}
|
|
205
|
+
const children = pending.map((entry) => '_type' in entry
|
|
206
|
+
? entry
|
|
207
|
+
: { _type: 'span', _key: nextKey(), text: entry.text, marks: entry.marks });
|
|
208
|
+
if (children.length === 0) {
|
|
209
|
+
children.push({ _type: 'span', _key: nextKey(), text: '', marks: [] });
|
|
210
|
+
}
|
|
211
|
+
const block = {
|
|
212
|
+
_type: 'block',
|
|
213
|
+
_key: nextKey(),
|
|
214
|
+
style,
|
|
215
|
+
markDefs,
|
|
216
|
+
children,
|
|
217
|
+
};
|
|
218
|
+
if (list) {
|
|
219
|
+
block.listItem = list.kind;
|
|
220
|
+
block.level = list.level;
|
|
221
|
+
}
|
|
222
|
+
return block;
|
|
223
|
+
}
|
|
224
|
+
function linkMarkDefKey(mark, markDefs, nextKey) {
|
|
225
|
+
const href = mark.attrs?.href ?? '';
|
|
226
|
+
const title = mark.attrs?.title ?? null;
|
|
227
|
+
const target = mark.attrs?.target ?? null;
|
|
228
|
+
const existing = markDefs.find((def) => def._type === 'link' &&
|
|
229
|
+
def.href === href &&
|
|
230
|
+
(def.title ?? null) === title &&
|
|
231
|
+
(def.target ?? null) === target);
|
|
232
|
+
if (existing)
|
|
233
|
+
return existing._key;
|
|
234
|
+
const def = { _key: nextKey(), _type: 'link', href };
|
|
235
|
+
if (title !== null)
|
|
236
|
+
def.title = title;
|
|
237
|
+
if (target !== null)
|
|
238
|
+
def.target = target;
|
|
239
|
+
markDefs.push(def);
|
|
240
|
+
return def._key;
|
|
241
|
+
}
|
|
242
|
+
function citationMarkDefKey(mark, markDefs, nextKey) {
|
|
243
|
+
const href = mark.attrs?.href ?? '';
|
|
244
|
+
const existing = markDefs.find((def) => def._type === 'citation' && def.href === href);
|
|
245
|
+
if (existing)
|
|
246
|
+
return existing._key;
|
|
247
|
+
const def = { _key: nextKey(), _type: 'citation', href };
|
|
248
|
+
markDefs.push(def);
|
|
249
|
+
return def._key;
|
|
250
|
+
}
|
|
251
|
+
function serializeTable(node, nextKey) {
|
|
252
|
+
const rows = (node.content ?? []).filter((row) => row.type === 'tableRow');
|
|
253
|
+
let headerRows = 0;
|
|
254
|
+
for (const row of rows) {
|
|
255
|
+
const cells = row.content ?? [];
|
|
256
|
+
if (cells.length > 0 && cells.every((cell) => cell.type === 'tableHeader'))
|
|
257
|
+
headerRows += 1;
|
|
258
|
+
else
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
_type: 'table',
|
|
263
|
+
_key: nextKey(),
|
|
264
|
+
headerRows,
|
|
265
|
+
rows: rows.map((row, rowIndex) => ({
|
|
266
|
+
_type: 'row',
|
|
267
|
+
_key: nextKey(),
|
|
268
|
+
cells: (row.content ?? []).map((cell) => serializeTableCell(cell, rowIndex, headerRows, nextKey)),
|
|
269
|
+
})),
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function serializeTableCell(cell, rowIndex, headerRows, nextKey) {
|
|
273
|
+
const out = {
|
|
274
|
+
_type: 'cell',
|
|
275
|
+
_key: nextKey(),
|
|
276
|
+
value: serializeBlocks(cell.content ?? [], nextKey),
|
|
277
|
+
};
|
|
278
|
+
if (cell.type === 'tableHeader' && rowIndex >= headerRows)
|
|
279
|
+
out.header = true;
|
|
280
|
+
const colspan = cell.attrs?.colspan ?? 1;
|
|
281
|
+
const rowspan = cell.attrs?.rowspan ?? 1;
|
|
282
|
+
const colwidth = cell.attrs?.colwidth ?? null;
|
|
283
|
+
const align = cell.attrs?.align ?? null;
|
|
284
|
+
if (colspan !== 1)
|
|
285
|
+
out.colspan = colspan;
|
|
286
|
+
if (rowspan !== 1)
|
|
287
|
+
out.rowspan = rowspan;
|
|
288
|
+
if (colwidth !== null)
|
|
289
|
+
out.colwidth = colwidth;
|
|
290
|
+
if (align !== null)
|
|
291
|
+
out.align = align;
|
|
292
|
+
return out;
|
|
293
|
+
}
|
|
294
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
295
|
+
// portableTextToDoc — PortableTextObject[] → JSONContent
|
|
296
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
297
|
+
const TIPTAP_MARK_BY_DECORATOR = {
|
|
298
|
+
strong: 'bold',
|
|
299
|
+
em: 'italic',
|
|
300
|
+
'strike-through': 'strike',
|
|
301
|
+
code: 'code',
|
|
302
|
+
};
|
|
303
|
+
/** Parse a Portable Text array back into a Tiptap JSONContent document. */
|
|
304
|
+
export function portableTextToDoc(blocks) {
|
|
305
|
+
return { type: 'doc', content: parseBlocks(blocks) };
|
|
306
|
+
}
|
|
307
|
+
function parseBlocks(blocks) {
|
|
308
|
+
const out = [];
|
|
309
|
+
let index = 0;
|
|
310
|
+
while (index < blocks.length) {
|
|
311
|
+
const block = blocks[index];
|
|
312
|
+
if (block._type === 'block' && typeof block.listItem === 'string') {
|
|
313
|
+
const run = [];
|
|
314
|
+
while (index < blocks.length &&
|
|
315
|
+
blocks[index]._type === 'block' &&
|
|
316
|
+
typeof blocks[index].listItem === 'string') {
|
|
317
|
+
run.push(blocks[index]);
|
|
318
|
+
index += 1;
|
|
319
|
+
}
|
|
320
|
+
out.push(...buildListNodes(run));
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
if (block._type === 'block' && block.style === 'blockquote') {
|
|
324
|
+
const paragraphs = [];
|
|
325
|
+
while (index < blocks.length &&
|
|
326
|
+
blocks[index]._type === 'block' &&
|
|
327
|
+
blocks[index].style === 'blockquote' &&
|
|
328
|
+
typeof blocks[index].listItem !== 'string') {
|
|
329
|
+
paragraphs.push({ type: 'paragraph', content: parseInline(blocks[index]) });
|
|
330
|
+
index += 1;
|
|
331
|
+
}
|
|
332
|
+
out.push({ type: 'blockquote', content: paragraphs });
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
out.push(parseObject(block));
|
|
336
|
+
index += 1;
|
|
337
|
+
}
|
|
338
|
+
return out;
|
|
339
|
+
}
|
|
340
|
+
function parseObject(block) {
|
|
341
|
+
switch (block._type) {
|
|
342
|
+
case 'block': {
|
|
343
|
+
const style = block.style ?? 'normal';
|
|
344
|
+
const heading = /^h([1-6])$/.exec(style);
|
|
345
|
+
if (heading) {
|
|
346
|
+
return {
|
|
347
|
+
type: 'heading',
|
|
348
|
+
attrs: { level: Number(heading[1]) },
|
|
349
|
+
content: parseInline(block),
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
return { type: 'paragraph', content: parseInline(block) };
|
|
353
|
+
}
|
|
354
|
+
case 'code': {
|
|
355
|
+
const code = block.code ?? '';
|
|
356
|
+
return {
|
|
357
|
+
type: 'codeBlock',
|
|
358
|
+
attrs: { language: block.language ?? null },
|
|
359
|
+
content: code ? [{ type: 'text', text: code }] : [],
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
case 'image':
|
|
363
|
+
return {
|
|
364
|
+
type: 'image',
|
|
365
|
+
attrs: {
|
|
366
|
+
src: block.src ?? '',
|
|
367
|
+
alt: block.alt ?? '',
|
|
368
|
+
title: block.title ?? null,
|
|
369
|
+
},
|
|
370
|
+
};
|
|
371
|
+
case 'tweetEmbed':
|
|
372
|
+
return { type: 'tweetEmbed', attrs: { url: block.url ?? '' } };
|
|
373
|
+
case 'horizontalRule':
|
|
374
|
+
return { type: 'horizontalRule' };
|
|
375
|
+
case 'table':
|
|
376
|
+
return parseTable(block);
|
|
377
|
+
case 'callout':
|
|
378
|
+
return {
|
|
379
|
+
type: 'callout',
|
|
380
|
+
attrs: { tone: block.tone ?? 'note' },
|
|
381
|
+
content: parseBlocks(block.content ?? []),
|
|
382
|
+
};
|
|
383
|
+
case 'pullQuote':
|
|
384
|
+
return {
|
|
385
|
+
type: 'pullQuote',
|
|
386
|
+
attrs: { attribution: block.attribution ?? null },
|
|
387
|
+
content: parseBlocks(block.content ?? []),
|
|
388
|
+
};
|
|
389
|
+
case 'generatedFaq':
|
|
390
|
+
return {
|
|
391
|
+
type: 'generatedFaq',
|
|
392
|
+
attrs: { markdown: block.markdown ?? '' },
|
|
393
|
+
};
|
|
394
|
+
default:
|
|
395
|
+
throw new Error(`portableTextToDoc: unknown Portable Text _type "${block._type}" — the stored content is newer than this serializer`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
function buildListNodes(run) {
|
|
399
|
+
const roots = [];
|
|
400
|
+
const stack = [];
|
|
401
|
+
for (const block of run) {
|
|
402
|
+
const kind = block.listItem === 'number' ? 'number' : 'bullet';
|
|
403
|
+
const level = typeof block.level === 'number' && block.level > 0 ? block.level : 1;
|
|
404
|
+
const listType = kind === 'number' ? 'orderedList' : 'bulletList';
|
|
405
|
+
while (stack.length > 0 && stack[stack.length - 1].level > level)
|
|
406
|
+
stack.pop();
|
|
407
|
+
let top = stack[stack.length - 1];
|
|
408
|
+
if (top && top.level === level && top.kind !== kind) {
|
|
409
|
+
stack.pop();
|
|
410
|
+
top = stack[stack.length - 1];
|
|
411
|
+
}
|
|
412
|
+
if (!top || top.level < level) {
|
|
413
|
+
const list = { type: listType, content: [] };
|
|
414
|
+
if (top && top.level < level) {
|
|
415
|
+
const items = top.list.content ?? [];
|
|
416
|
+
const lastItem = items[items.length - 1];
|
|
417
|
+
if (lastItem) {
|
|
418
|
+
lastItem.content = [...(lastItem.content ?? []), list];
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
roots.push(list);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
roots.push(list);
|
|
426
|
+
}
|
|
427
|
+
stack.push({ list, kind, level });
|
|
428
|
+
top = stack[stack.length - 1];
|
|
429
|
+
}
|
|
430
|
+
top.list.content = [
|
|
431
|
+
...(top.list.content ?? []),
|
|
432
|
+
{ type: 'listItem', content: [{ type: 'paragraph', content: parseInline(block) }] },
|
|
433
|
+
];
|
|
434
|
+
}
|
|
435
|
+
return roots;
|
|
436
|
+
}
|
|
437
|
+
function parseInline(block) {
|
|
438
|
+
const markDefs = block.markDefs ?? [];
|
|
439
|
+
const out = [];
|
|
440
|
+
for (const child of block.children ?? []) {
|
|
441
|
+
if (child._type === 'span') {
|
|
442
|
+
out.push(...parseSpan(child, markDefs));
|
|
443
|
+
}
|
|
444
|
+
else if (child._type === 'image') {
|
|
445
|
+
out.push(parseObject(child));
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
throw new Error(`portableTextToDoc: unknown inline Portable Text _type "${child._type}"`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return out;
|
|
452
|
+
}
|
|
453
|
+
function parseSpan(span, markDefs) {
|
|
454
|
+
const marks = [];
|
|
455
|
+
for (const name of span.marks ?? []) {
|
|
456
|
+
const def = markDefs.find((candidate) => candidate._key === name);
|
|
457
|
+
if (def) {
|
|
458
|
+
if (def._type === 'link') {
|
|
459
|
+
marks.push({
|
|
460
|
+
type: 'link',
|
|
461
|
+
attrs: {
|
|
462
|
+
href: def.href ?? '',
|
|
463
|
+
title: def.title ?? null,
|
|
464
|
+
target: def.target ?? null,
|
|
465
|
+
},
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
else if (def._type === 'citation') {
|
|
469
|
+
marks.push({ type: 'citation', attrs: { href: def.href ?? '' } });
|
|
470
|
+
}
|
|
471
|
+
// Other annotation types have no Tiptap node yet; drop the mark but
|
|
472
|
+
// keep the text.
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
const tiptapMark = TIPTAP_MARK_BY_DECORATOR[name];
|
|
476
|
+
if (tiptapMark)
|
|
477
|
+
marks.push({ type: tiptapMark });
|
|
478
|
+
}
|
|
479
|
+
const text = span.text ?? '';
|
|
480
|
+
const segments = text.split('\n');
|
|
481
|
+
const out = [];
|
|
482
|
+
segments.forEach((segment, index) => {
|
|
483
|
+
if (index > 0)
|
|
484
|
+
out.push({ type: 'hardBreak' });
|
|
485
|
+
if (segment !== '') {
|
|
486
|
+
const node = { type: 'text', text: segment };
|
|
487
|
+
if (marks.length > 0)
|
|
488
|
+
node.marks = marks.map((mark) => ({ ...mark }));
|
|
489
|
+
out.push(node);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
return out;
|
|
493
|
+
}
|
|
494
|
+
function parseTable(block) {
|
|
495
|
+
const headerRows = typeof block.headerRows === 'number' ? block.headerRows : 0;
|
|
496
|
+
const rows = block.rows ?? [];
|
|
497
|
+
return {
|
|
498
|
+
type: 'table',
|
|
499
|
+
content: rows.map((row, rowIndex) => ({
|
|
500
|
+
type: 'tableRow',
|
|
501
|
+
content: (row.cells ?? []).map((cell) => {
|
|
502
|
+
const isHeader = rowIndex < headerRows || cell.header === true;
|
|
503
|
+
return {
|
|
504
|
+
type: isHeader ? 'tableHeader' : 'tableCell',
|
|
505
|
+
attrs: {
|
|
506
|
+
colspan: cell.colspan ?? 1,
|
|
507
|
+
rowspan: cell.rowspan ?? 1,
|
|
508
|
+
colwidth: cell.colwidth ?? null,
|
|
509
|
+
align: cell.align ?? null,
|
|
510
|
+
},
|
|
511
|
+
content: parseBlocks(cell.value ?? []),
|
|
512
|
+
};
|
|
513
|
+
}),
|
|
514
|
+
})),
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
//# sourceMappingURL=portable-text.js.map
|