@withl5e/richtext-payload 0.3.3-alpha.4 → 1.0.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.js CHANGED
@@ -1,316 +1,254 @@
1
- import { jsxFactory as n, Fragment as y, isValidElement as S, cloneElement as b } from "@withl5e/l5e/jsx-runtime";
2
- import { hasText as v } from "@payloadcms/richtext-lexical/shared";
3
- import { v4 as T } from "uuid";
4
- import { NodeFormat as p } from "@payloadcms/richtext-lexical";
5
- import { stringToLexical as W } from "./stringToLexical.js";
6
- const w = {
7
- quote: ({ node: e, nodesToJSX: t }) => {
8
- const r = t({
9
- nodes: e.children
10
- });
11
- return /* @__PURE__ */ n("blockquote", null, r);
12
- }
13
- }, C = {
14
- heading: ({ node: e, nodesToJSX: t }) => {
15
- const r = t({
16
- nodes: e.children
17
- }), l = e.tag;
18
- return /* @__PURE__ */ n(l, null, r);
19
- }
20
- }, J = {
21
- horizontalrule: /* @__PURE__ */ n("hr", null)
22
- }, X = {
23
- linebreak: /* @__PURE__ */ n("br", null)
24
- }, L = ({ internalDocToHref: e }) => ({
25
- autolink: ({ node: t, nodesToJSX: r }) => {
26
- const l = r({
27
- nodes: t.children
28
- }), i = t.fields.newTab ? "noopener noreferrer" : void 0, o = t.fields.newTab ? "_blank" : void 0;
29
- return /* @__PURE__ */ n("a", { href: t.fields.url, rel: i, target: o }, l);
30
- },
31
- link: ({ node: t, nodesToJSX: r }) => {
32
- const l = r({
33
- nodes: t.children
34
- }), i = t.fields.newTab ? "noopener noreferrer" : void 0, o = t.fields.newTab ? "_blank" : void 0;
35
- let s = t.fields.url ?? "";
36
- return t.fields.linkType === "internal" && (e ? s = e({ linkNode: t }) : (console.error(
37
- "Lexical => JSX converter: Link converter: found internal link, but internalDocToHref is not provided"
38
- ), s = "#")), /* @__PURE__ */ n("a", { href: s, rel: i, target: o }, l);
39
- }
40
- }), I = {
41
- list: ({ node: e, nodesToJSX: t }) => {
42
- const r = t({
43
- nodes: e.children
44
- }), l = e.tag;
45
- return /* @__PURE__ */ n(l, { class: `list-${e?.listType}` }, r);
46
- },
47
- listitem: ({ node: e, nodesToJSX: t, parent: r }) => {
48
- const l = e.children.some((o) => o.type === "list"), i = t({
49
- nodes: e.children
50
- });
51
- if ("listType" in r && r?.listType === "check") {
52
- const o = T();
53
- return /* @__PURE__ */ n(
54
- "li",
55
- {
56
- "aria-checked": e.checked ? "true" : "false",
57
- class: `list-item-checkbox${e.checked ? " list-item-checkbox-checked" : " list-item-checkbox-unchecked"}${l ? " nestedListItem" : ""}`,
58
- role: "checkbox",
59
- style: "list-style-type: none;",
60
- tabindex: "-1",
61
- value: e?.value
62
- },
63
- l ? i : /* @__PURE__ */ n(y, null, /* @__PURE__ */ n("input", { checked: e.checked, id: o, readonly: !0, type: "checkbox" }), /* @__PURE__ */ n("label", { for: o }, i), /* @__PURE__ */ n("br", null))
64
- );
65
- } else
66
- return /* @__PURE__ */ n(
67
- "li",
68
- {
69
- class: `${l ? "nestedListItem" : ""}`,
70
- style: l ? "list-style-type: none;" : "",
71
- value: e?.value
72
- },
73
- i
74
- );
75
- }
76
- }, N = {
77
- paragraph: ({ node: e, nodesToJSX: t }) => {
78
- const r = t({
79
- nodes: e.children
80
- });
81
- return r?.length ? /* @__PURE__ */ n("p", null, r) : /* @__PURE__ */ n("p", null, /* @__PURE__ */ n("br", null));
82
- }
83
- }, E = {
84
- tab: " "
85
- }, $ = {
86
- table: ({ node: e, nodesToJSX: t }) => {
87
- const r = t({
88
- nodes: e.children
89
- });
90
- return /* @__PURE__ */ n("div", { class: "lexical-table-container" }, /* @__PURE__ */ n("table", { class: "lexical-table", style: "border-collapse: collapse;" }, /* @__PURE__ */ n("tbody", null, r)));
91
- },
92
- tablecell: ({ node: e, nodesToJSX: t }) => {
93
- const r = t({
94
- nodes: e.children
95
- }), l = e.headerState > 0 ? "th" : "td", i = `lexical-table-cell-header-${e.headerState}`;
96
- let o = "";
97
- e.backgroundColor && (o += `background-color: ${e.backgroundColor};`), o += "border: 1px solid #ccc;", o += "padding: 8px;";
98
- const s = e.colSpan && e.colSpan > 1 ? e.colSpan : void 0, c = e.rowSpan && e.rowSpan > 1 ? e.rowSpan : void 0;
99
- return /* @__PURE__ */ n(
100
- l,
101
- {
102
- class: `lexical-table-cell ${i}`,
103
- colspan: s,
104
- rowspan: c,
105
- style: o
106
- },
107
- r
108
- );
109
- },
110
- tablerow: ({ node: e, nodesToJSX: t }) => {
111
- const r = t({
112
- nodes: e.children
113
- });
114
- return /* @__PURE__ */ n("tr", { class: "lexical-table-row" }, r);
115
- }
116
- }, z = {
117
- text: ({ node: e }) => {
118
- let t = e.text;
119
- return e.format & p.IS_BOLD && (t = /* @__PURE__ */ n("strong", null, t)), e.format & p.IS_ITALIC && (t = /* @__PURE__ */ n("em", null, t)), e.format & p.IS_STRIKETHROUGH && (t = /* @__PURE__ */ n("span", { style: "text-decoration: line-through;" }, t)), e.format & p.IS_UNDERLINE && (t = /* @__PURE__ */ n("span", { style: "text-decoration: underline;" }, t)), e.format & p.IS_CODE && (t = /* @__PURE__ */ n("code", null, t)), e.format & p.IS_SUBSCRIPT && (t = /* @__PURE__ */ n("sub", null, t)), e.format & p.IS_SUPERSCRIPT && (t = /* @__PURE__ */ n("sup", null, t)), t;
120
- }
121
- }, _ = {
122
- upload: ({ node: e }) => {
123
- const t = e;
124
- if (typeof t.value != "object")
125
- return null;
126
- const r = t.value, l = r.url;
127
- if (!r.mimeType.startsWith("image"))
128
- return /* @__PURE__ */ n("a", { href: l, rel: "noopener noreferrer" }, r.filename);
129
- if (!r.sizes || !Object.keys(r.sizes).length)
130
- return /* @__PURE__ */ n("img", { alt: r.filename, height: r.height, src: l, width: r.width });
131
- const i = [];
132
- for (const o in r.sizes) {
133
- const s = r.sizes[o];
134
- if (!s || !s.width || !s.height || !s.mimeType || !s.filesize || !s.filename || !s.url)
135
- continue;
136
- const c = s?.url;
137
- i.push(
138
- /* @__PURE__ */ n(
139
- "source",
140
- {
141
- key: o,
142
- media: `(max-width: ${s.width}px)`,
143
- srcset: c,
144
- type: s.mimeType
145
- }
146
- )
147
- );
148
- }
149
- return i.push(
150
- /* @__PURE__ */ n(
151
- "img",
152
- {
153
- alt: r?.filename,
154
- height: r?.height,
155
- key: "image",
156
- src: l,
157
- width: r?.width
158
- }
159
- )
160
- ), /* @__PURE__ */ n("picture", null, i);
161
- }
162
- }, D = {
163
- ...N,
164
- ...z,
165
- ...X,
166
- ...w,
167
- ...$,
168
- ...C,
169
- ...J,
170
- ...I,
171
- ...L({}),
172
- ..._,
173
- ...E
1
+ import { stringToLexical as e } from "./stringToLexical.js";
2
+ import { Fragment as t, cloneElement as n, isValidElement as r, jsxFactory as i } from "@withl5e/l5e/jsx-runtime";
3
+ import { hasText as a } from "@payloadcms/richtext-lexical/shared";
4
+ import { v4 as o } from "uuid";
5
+ import { NodeFormat as s } from "@payloadcms/richtext-lexical";
6
+ //#region src/richtext-render/converters/blockquote.tsx
7
+ var c = { quote: ({ node: e, nodesToJSX: t }) => {
8
+ let n = t({ nodes: e.children });
9
+ return /* @__PURE__ */ i("blockquote", null, n);
10
+ } }, l = { heading: ({ node: e, nodesToJSX: t }) => {
11
+ let n = t({ nodes: e.children }), r = e.tag;
12
+ return /* @__PURE__ */ i(r, null, n);
13
+ } }, u = { horizontalrule: /* @__PURE__ */ i("hr", null) }, d = { linebreak: /* @__PURE__ */ i("br", null) }, f = ({ internalDocToHref: e }) => ({
14
+ autolink: ({ node: e, nodesToJSX: t }) => {
15
+ let n = t({ nodes: e.children }), r = e.fields.newTab ? "noopener noreferrer" : void 0, a = e.fields.newTab ? "_blank" : void 0;
16
+ return /* @__PURE__ */ i("a", {
17
+ href: e.fields.url,
18
+ rel: r,
19
+ target: a
20
+ }, n);
21
+ },
22
+ link: ({ node: t, nodesToJSX: n }) => {
23
+ let r = n({ nodes: t.children }), a = t.fields.newTab ? "noopener noreferrer" : void 0, o = t.fields.newTab ? "_blank" : void 0, s = t.fields.url ?? "";
24
+ return t.fields.linkType === "internal" && (e ? s = e({ linkNode: t }) : (console.error("Lexical => JSX converter: Link converter: found internal link, but internalDocToHref is not provided"), s = "#")), /* @__PURE__ */ i("a", {
25
+ href: s,
26
+ rel: a,
27
+ target: o
28
+ }, r);
29
+ }
30
+ }), p = {
31
+ list: ({ node: e, nodesToJSX: t }) => {
32
+ let n = t({ nodes: e.children }), r = e.tag;
33
+ return /* @__PURE__ */ i(r, { class: `list-${e?.listType}` }, n);
34
+ },
35
+ listitem: ({ node: e, nodesToJSX: n, parent: r }) => {
36
+ let a = e.children.some((e) => e.type === "list"), s = n({ nodes: e.children });
37
+ if ("listType" in r && r?.listType === "check") {
38
+ let n = o();
39
+ return /* @__PURE__ */ i("li", {
40
+ "aria-checked": e.checked ? "true" : "false",
41
+ class: `list-item-checkbox${e.checked ? " list-item-checkbox-checked" : " list-item-checkbox-unchecked"}${a ? " nestedListItem" : ""}`,
42
+ role: "checkbox",
43
+ style: "list-style-type: none;",
44
+ tabindex: "-1",
45
+ value: e?.value
46
+ }, a ? s : /* @__PURE__ */ i(t, null, /* @__PURE__ */ i("input", {
47
+ checked: e.checked,
48
+ id: n,
49
+ readonly: !0,
50
+ type: "checkbox"
51
+ }), /* @__PURE__ */ i("label", { for: n }, s), /* @__PURE__ */ i("br", null)));
52
+ }
53
+ return /* @__PURE__ */ i("li", {
54
+ class: `${a ? "nestedListItem" : ""}`,
55
+ style: a ? "list-style-type: none;" : "",
56
+ value: e?.value
57
+ }, s);
58
+ }
59
+ }, m = { paragraph: ({ node: e, nodesToJSX: t }) => {
60
+ let n = t({ nodes: e.children });
61
+ return n?.length ? /* @__PURE__ */ i("p", null, n) : /* @__PURE__ */ i("p", null, /* @__PURE__ */ i("br", null));
62
+ } }, h = { tab: " " }, g = {
63
+ table: ({ node: e, nodesToJSX: t }) => {
64
+ let n = t({ nodes: e.children });
65
+ return /* @__PURE__ */ i("div", { class: "lexical-table-container" }, /* @__PURE__ */ i("table", {
66
+ class: "lexical-table",
67
+ style: "border-collapse: collapse;"
68
+ }, /* @__PURE__ */ i("tbody", null, n)));
69
+ },
70
+ tablecell: ({ node: e, nodesToJSX: t }) => {
71
+ let n = t({ nodes: e.children }), r = e.headerState > 0 ? "th" : "td", a = `lexical-table-cell-header-${e.headerState}`, o = "";
72
+ e.backgroundColor && (o += `background-color: ${e.backgroundColor};`), o += "border: 1px solid #ccc;", o += "padding: 8px;";
73
+ let s = e.colSpan && e.colSpan > 1 ? e.colSpan : void 0, c = e.rowSpan && e.rowSpan > 1 ? e.rowSpan : void 0;
74
+ return /* @__PURE__ */ i(r, {
75
+ class: `lexical-table-cell ${a}`,
76
+ colspan: s,
77
+ rowspan: c,
78
+ style: o
79
+ }, n);
80
+ },
81
+ tablerow: ({ node: e, nodesToJSX: t }) => {
82
+ let n = t({ nodes: e.children });
83
+ return /* @__PURE__ */ i("tr", { class: "lexical-table-row" }, n);
84
+ }
85
+ }, _ = { text: ({ node: e }) => {
86
+ let t = e.text;
87
+ return e.format & s.IS_BOLD && (t = /* @__PURE__ */ i("strong", null, t)), e.format & s.IS_ITALIC && (t = /* @__PURE__ */ i("em", null, t)), e.format & s.IS_STRIKETHROUGH && (t = /* @__PURE__ */ i("span", { style: "text-decoration: line-through;" }, t)), e.format & s.IS_UNDERLINE && (t = /* @__PURE__ */ i("span", { style: "text-decoration: underline;" }, t)), e.format & s.IS_CODE && (t = /* @__PURE__ */ i("code", null, t)), e.format & s.IS_SUBSCRIPT && (t = /* @__PURE__ */ i("sub", null, t)), e.format & s.IS_SUPERSCRIPT && (t = /* @__PURE__ */ i("sup", null, t)), t;
88
+ } }, v = { upload: ({ node: e }) => {
89
+ let t = e;
90
+ if (typeof t.value != "object") return null;
91
+ let n = t.value, r = n.url;
92
+ if (!n.mimeType.startsWith("image")) return /* @__PURE__ */ i("a", {
93
+ href: r,
94
+ rel: "noopener noreferrer"
95
+ }, n.filename);
96
+ if (!n.sizes || !Object.keys(n.sizes).length) return /* @__PURE__ */ i("img", {
97
+ alt: n.filename,
98
+ height: n.height,
99
+ src: r,
100
+ width: n.width
101
+ });
102
+ let a = [];
103
+ for (let e in n.sizes) {
104
+ let t = n.sizes[e];
105
+ if (!t || !t.width || !t.height || !t.mimeType || !t.filesize || !t.filename || !t.url) continue;
106
+ let r = t?.url;
107
+ a.push(/* @__PURE__ */ i("source", {
108
+ key: e,
109
+ media: `(max-width: ${t.width}px)`,
110
+ srcset: r,
111
+ type: t.mimeType
112
+ }));
113
+ }
114
+ return a.push(/* @__PURE__ */ i("img", {
115
+ alt: n?.filename,
116
+ height: n?.height,
117
+ key: "image",
118
+ src: r,
119
+ width: n?.width
120
+ })), /* @__PURE__ */ i("picture", null, a);
121
+ } }, y = {
122
+ ...m,
123
+ ..._,
124
+ ...d,
125
+ ...c,
126
+ ...g,
127
+ ...l,
128
+ ...u,
129
+ ...p,
130
+ ...f({}),
131
+ ...v,
132
+ ...h
174
133
  };
175
- function U(e) {
176
- return e.toLowerCase().normalize("NFD").replace(/[\u0300-\u036F]/g, "").replace(/đ/g, "d").replace(/[\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]/g, "-").replace(/[\s\u00A0\/\\|_.,;:+=@&]+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "");
134
+ //#endregion
135
+ //#region src/richtext-render/utils/genFragmentIdentifier.ts
136
+ function b(e) {
137
+ return e.toLowerCase().normalize("NFD").replace(/[\u0300-\u036F]/g, "").replace(/đ/g, "d").replace(/[\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]/g, "-").replace(/[\s\u00A0\/\\|_.,;:+=@&]+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "");
177
138
  }
178
- function g(e) {
179
- return e ? e.type === "text" ? e.text || "" : !("children" in e) || !Array.isArray(e.children) ? "" : e.children.map((t) => g(t)).join("") : "";
139
+ //#endregion
140
+ //#region src/richtext-render/utils/getTextOfLexical.ts
141
+ function x(e) {
142
+ return e ? e.type === "text" ? e.text || "" : !("children" in e) || !Array.isArray(e.children) ? "" : e.children.map((e) => x(e)).join("") : "";
180
143
  }
181
- function k(e) {
182
- const t = [];
183
- if ("root" in e && e.root)
184
- return k(e.root);
185
- const r = e;
186
- if (r.type === "heading") {
187
- const i = r.tag || "", o = i === "h2" ? 2 : i === "h3" ? 3 : i === "h4" ? 4 : i === "h5" ? 5 : i === "h6" ? 6 : 0;
188
- if (o > 0) {
189
- const s = g(r);
190
- s && t.push({
191
- text: s,
192
- level: o
193
- });
194
- }
195
- }
196
- return "children" in r && Array.isArray(r.children) && r.children.forEach((l) => {
197
- t.push(...k(l));
198
- }), t;
144
+ //#endregion
145
+ //#region src/richtext-render/utils/getTableOfContents.ts
146
+ function S(e) {
147
+ let t = [];
148
+ if ("root" in e && e.root) return S(e.root);
149
+ let n = e;
150
+ if (n.type === "heading") {
151
+ let e = n.tag || "", r = e === "h2" ? 2 : e === "h3" ? 3 : e === "h4" ? 4 : e === "h5" ? 5 : e === "h6" ? 6 : 0;
152
+ if (r > 0) {
153
+ let e = x(n);
154
+ e && t.push({
155
+ text: e,
156
+ level: r
157
+ });
158
+ }
159
+ }
160
+ return "children" in n && Array.isArray(n.children) && n.children.forEach((e) => {
161
+ t.push(...S(e));
162
+ }), t;
199
163
  }
200
- function O(e) {
201
- const t = [], r = [];
202
- return e.forEach((l) => {
203
- const i = {
204
- ...l,
205
- children: []
206
- };
207
- for (; r.length > 0 && r[r.length - 1].level >= l.level; )
208
- r.pop();
209
- r.length === 0 ? t.push(i) : r[r.length - 1].children.push(i), r.push(i);
210
- }), t;
164
+ function C(e) {
165
+ let t = [], n = [];
166
+ return e.forEach((e) => {
167
+ let r = {
168
+ ...e,
169
+ children: []
170
+ };
171
+ for (; n.length > 0 && n[n.length - 1].level >= e.level;) n.pop();
172
+ n.length === 0 ? t.push(r) : n[n.length - 1].children.push(r), n.push(r);
173
+ }), t;
211
174
  }
212
- const A = 210;
213
- function H(e) {
214
- if (!e) return 0;
215
- const r = g(e).trim().split(/\s+/).length, l = Math.ceil(r / A);
216
- return Math.max(1, l);
175
+ //#endregion
176
+ //#region src/richtext-render/utils/getTimeRead.ts
177
+ var w = 210;
178
+ function T(e) {
179
+ if (!e) return 0;
180
+ let t = x(e).trim().split(/\s+/).length, n = Math.ceil(t / w);
181
+ return Math.max(1, n);
217
182
  }
218
- function P({
219
- converters: e,
220
- data: t,
221
- disableIndent: r,
222
- disableTextAlign: l
223
- }) {
224
- return v(t) ? /* @__PURE__ */ n(y, null, x({
225
- converters: e,
226
- disableIndent: r,
227
- disableTextAlign: l,
228
- nodes: t?.root?.children,
229
- parent: t?.root
230
- })) : /* @__PURE__ */ n(y, null);
183
+ //#endregion
184
+ //#region src/richtext-render/index.tsx
185
+ function E({ converters: e, data: n, disableIndent: r, disableTextAlign: o }) {
186
+ return a(n) ? /* @__PURE__ */ i(t, null, D({
187
+ converters: e,
188
+ disableIndent: r,
189
+ disableTextAlign: o,
190
+ nodes: n?.root?.children,
191
+ parent: n?.root
192
+ })) : /* @__PURE__ */ i(t, null);
231
193
  }
232
- function x({
233
- converters: e,
234
- disableIndent: t,
235
- disableTextAlign: r,
236
- nodes: l,
237
- parent: i
238
- }) {
239
- const o = e.unknown;
240
- return l.map((c, d) => {
241
- let a;
242
- c.type === "block" ? (a = e?.blocks?.[c?.fields?.blockType], !a && !o && console.error(
243
- `Lexical => JSX converter: Blocks converter: found ${c?.fields?.blockType} block, but no converter is provided`
244
- )) : c.type === "inlineBlock" ? (a = e?.inlineBlocks?.[c?.fields?.blockType], !a && !o && console.error(
245
- `Lexical => JSX converter: Inline Blocks converter: found ${c?.fields?.blockType} inline block, but no converter is provided`
246
- )) : a = e[c.type];
247
- try {
248
- !a && o && (a = o);
249
- let u;
250
- a ? u = typeof a == "function" ? a({
251
- childIndex: d,
252
- converters: e,
253
- node: c,
254
- nodesToJSX: (f) => x({
255
- converters: f.converters ?? e,
256
- disableIndent: f.disableIndent ?? t,
257
- disableTextAlign: f.disableTextAlign ?? r,
258
- nodes: f.nodes,
259
- parent: f.parent ?? {
260
- ...c,
261
- parent: i
262
- }
263
- }),
264
- parent: i
265
- }) : a : u = /* @__PURE__ */ n("span", { key: d }, "unknown node");
266
- let h = "";
267
- if (!r && (!Array.isArray(r) || !r?.includes(c.type)) && "format" in c && c.format)
268
- switch (c.format) {
269
- case "center":
270
- h += "text-align: center;";
271
- break;
272
- case "end":
273
- h += "text-align: right;";
274
- break;
275
- case "justify":
276
- h += "text-align: justify;";
277
- break;
278
- case "left":
279
- break;
280
- case "right":
281
- h += "text-align: right;";
282
- break;
283
- case "start":
284
- h += "text-align: left;";
285
- break;
286
- }
287
- if (!t && (!Array.isArray(t) || !t?.includes(c.type)) && "indent" in c && c.indent && c.type !== "listitem" && (h += `padding-inline-start: ${Number(c.indent) * 40}px;`), S(u)) {
288
- if (h) {
289
- const m = typeof u?.props?.style == "string" ? u.props.style : "", f = `${h} ${m}`.trim();
290
- return b(u, {
291
- key: d,
292
- style: f
293
- });
294
- }
295
- return b(u, {
296
- key: d
297
- });
298
- }
299
- return u;
300
- } catch (u) {
301
- return console.error("Error converting lexical node to JSX:", u, "node:", c), null;
302
- }
303
- }).filter(Boolean);
194
+ function D({ converters: e, disableIndent: t, disableTextAlign: a, nodes: o, parent: s }) {
195
+ let c = e.unknown;
196
+ return o.map((o, l) => {
197
+ let u;
198
+ o.type === "block" ? (u = e?.blocks?.[o?.fields?.blockType], !u && !c && console.error(`Lexical => JSX converter: Blocks converter: found ${o?.fields?.blockType} block, but no converter is provided`)) : o.type === "inlineBlock" ? (u = e?.inlineBlocks?.[o?.fields?.blockType], !u && !c && console.error(`Lexical => JSX converter: Inline Blocks converter: found ${o?.fields?.blockType} inline block, but no converter is provided`)) : u = e[o.type];
199
+ try {
200
+ !u && c && (u = c);
201
+ let d;
202
+ d = u ? typeof u == "function" ? u({
203
+ childIndex: l,
204
+ converters: e,
205
+ node: o,
206
+ nodesToJSX: (n) => D({
207
+ converters: n.converters ?? e,
208
+ disableIndent: n.disableIndent ?? t,
209
+ disableTextAlign: n.disableTextAlign ?? a,
210
+ nodes: n.nodes,
211
+ parent: n.parent ?? {
212
+ ...o,
213
+ parent: s
214
+ }
215
+ }),
216
+ parent: s
217
+ }) : u : /* @__PURE__ */ i("span", { key: l }, "unknown node");
218
+ let f = "";
219
+ if (!a && (!Array.isArray(a) || !a?.includes(o.type)) && "format" in o && o.format) switch (o.format) {
220
+ case "center":
221
+ f += "text-align: center;";
222
+ break;
223
+ case "end":
224
+ f += "text-align: right;";
225
+ break;
226
+ case "justify":
227
+ f += "text-align: justify;";
228
+ break;
229
+ case "left": break;
230
+ case "right":
231
+ f += "text-align: right;";
232
+ break;
233
+ case "start": f += "text-align: left;";
234
+ }
235
+ if (!t && (!Array.isArray(t) || !t?.includes(o.type)) && "indent" in o && o.indent && o.type !== "listitem" && (f += `padding-inline-start: ${Number(o.indent) * 40}px;`), r(d)) {
236
+ if (f) {
237
+ let e = typeof d?.props?.style == "string" ? d.props.style : "", t = `${f} ${e}`.trim();
238
+ return n(d, {
239
+ key: l,
240
+ style: t
241
+ });
242
+ }
243
+ return n(d, { key: l });
244
+ }
245
+ return d;
246
+ } catch (e) {
247
+ return console.error("Error converting lexical node to JSX:", e, "node:", o), null;
248
+ }
249
+ }).filter(Boolean);
304
250
  }
305
- export {
306
- O as buildTableOfContents,
307
- x as convertLexicalNodesToJSX,
308
- P as convertLexicalToJSX,
309
- D as defaultJSXConverters,
310
- U as genFragmentIdentifier,
311
- k as getHeaders,
312
- g as getTextLexicalNode,
313
- H as getTimeRead,
314
- W as stringToLexical
315
- };
316
- //# sourceMappingURL=index.js.map
251
+ //#endregion
252
+ export { C as buildTableOfContents, D as convertLexicalNodesToJSX, E as convertLexicalToJSX, y as defaultJSXConverters, b as genFragmentIdentifier, S as getHeaders, x as getTextLexicalNode, T as getTimeRead, e as stringToLexical };
253
+
254
+ //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/richtext-render/converters/blockquote.tsx","../src/richtext-render/converters/heading.tsx","../src/richtext-render/converters/horizontalRule.tsx","../src/richtext-render/converters/linebreak.tsx","../src/richtext-render/converters/link.tsx","../src/richtext-render/converters/list.tsx","../src/richtext-render/converters/paragraph.tsx","../src/richtext-render/converters/tab.tsx","../src/richtext-render/converters/table.tsx","../src/richtext-render/converters/text.tsx","../src/richtext-render/converters/upload.tsx","../src/richtext-render/defaultConverters.ts","../src/richtext-render/utils/genFragmentIdentifier.ts","../src/richtext-render/utils/getTextOfLexical.ts","../src/richtext-render/utils/getTableOfContents.ts","../src/richtext-render/utils/getTimeRead.ts","../src/richtext-render/index.tsx"],"sourcesContent":["import type { SerializedQuoteNode } from '@payloadcms/richtext-lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const BlockquoteJSXConverter: JSXConverters<SerializedQuoteNode> = {\n quote: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n return <blockquote>{children}</blockquote>;\n },\n};\n","import { SerializedHeadingNode } from '@payloadcms/richtext-lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const HeadingJSXConverter: JSXConverters<SerializedHeadingNode> = {\n heading: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n const NodeTag = node.tag;\n\n return <NodeTag>{children}</NodeTag>;\n },\n};\n","import { SerializedHorizontalRuleNode } from '@payloadcms/richtext-lexical';\nimport type { JSXConverters } from '../types.js';\nexport const HorizontalRuleJSXConverter: JSXConverters<SerializedHorizontalRuleNode> = {\n horizontalrule: <hr />,\n};\n","import type { SerializedLineBreakNode } from 'lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const LinebreakJSXConverter: JSXConverters<SerializedLineBreakNode> = {\n linebreak: <br />,\n};\n","import type { SerializedAutoLinkNode, SerializedLinkNode } from '@payloadcms/richtext-lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const LinkJSXConverter: (args: {\n internalDocToHref?: (args: { linkNode: SerializedLinkNode }) => string;\n}) => JSXConverters<SerializedAutoLinkNode | SerializedLinkNode> = ({ internalDocToHref }) => ({\n autolink: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n const rel: string | undefined = node.fields.newTab ? 'noopener noreferrer' : undefined;\n const target: string | undefined = node.fields.newTab ? '_blank' : undefined;\n\n return (\n <a href={node.fields.url} {...{ rel, target }}>\n {children}\n </a>\n );\n },\n link: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n const rel: string | undefined = node.fields.newTab ? 'noopener noreferrer' : undefined;\n const target: string | undefined = node.fields.newTab ? '_blank' : undefined;\n\n let href: string = node.fields.url ?? '';\n if (node.fields.linkType === 'internal') {\n if (internalDocToHref) {\n href = internalDocToHref({ linkNode: node });\n } else {\n console.error(\n 'Lexical => JSX converter: Link converter: found internal link, but internalDocToHref is not provided',\n );\n href = '#'; // fallback\n }\n }\n\n return (\n <a href={href} {...{ rel, target }}>\n {children}\n </a>\n );\n },\n});\n","import { v4 as uuidv4 } from 'uuid';\nimport { Fragment } from '@withl5e/l5e/jsx-runtime';\n\nimport type { SerializedListItemNode, SerializedListNode } from '@payloadcms/richtext-lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const ListJSXConverter: JSXConverters<SerializedListItemNode | SerializedListNode> = {\n list: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n const NodeTag = node.tag;\n\n return <NodeTag class={`list-${node?.listType}`}>{children}</NodeTag>;\n },\n listitem: ({ node, nodesToJSX, parent }) => {\n const hasSubLists = node.children.some((child) => child.type === 'list');\n\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n if ('listType' in parent && parent?.listType === 'check') {\n const uuid = uuidv4();\n\n return (\n <li\n aria-checked={node.checked ? 'true' : 'false'}\n class={`list-item-checkbox${node.checked ? ' list-item-checkbox-checked' : ' list-item-checkbox-unchecked'}${hasSubLists ? ' nestedListItem' : ''}`}\n // eslint-disable-next-line jsx-a11y/no-noninteractive-element-to-interactive-role\n role=\"checkbox\"\n style=\"list-style-type: none;\"\n tabindex={'-1'}\n value={node?.value}\n >\n {hasSubLists ? (\n children\n ) : (\n <>\n <input checked={node.checked} id={uuid} readonly={true} type=\"checkbox\" />\n <label for={uuid}>{children}</label>\n <br />\n </>\n )}\n </li>\n );\n } else {\n return (\n <li\n class={`${hasSubLists ? 'nestedListItem' : ''}`}\n style={hasSubLists ? 'list-style-type: none;' : ''}\n value={node?.value}\n >\n {children}\n </li>\n );\n }\n },\n};\n","import type { SerializedParagraphNode } from 'lexical';\nimport type { JSXConverter, JSXConverters } from '../types.js';\n\ntype ParagraphConverterArgs = Parameters<\n Extract<JSXConverter<SerializedParagraphNode>, (...args: any[]) => JSX.Element>\n>[0];\n\nexport const ParagraphJSXConverter: JSXConverters<SerializedParagraphNode> = {\n paragraph: ({ node, nodesToJSX }: ParagraphConverterArgs) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n if (!children?.length) {\n return (\n <p>\n <br />\n </p>\n );\n }\n\n return <p>{children}</p>;\n },\n};\n","import type { SerializedTabNode } from 'lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const TabJSXConverter: JSXConverters<SerializedTabNode> = {\n tab: '\\t',\n};\n","import type {\n SerializedTableCellNode,\n SerializedTableNode,\n SerializedTableRowNode,\n} from '@payloadcms/richtext-lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const TableJSXConverter: JSXConverters<\n SerializedTableCellNode | SerializedTableNode | SerializedTableRowNode\n> = {\n table: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n return (\n <div class=\"lexical-table-container\">\n <table class=\"lexical-table\" style=\"border-collapse: collapse;\">\n <tbody>{children}</tbody>\n </table>\n </div>\n );\n },\n tablecell: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n const TagName = node.headerState > 0 ? 'th' : 'td'; // Use capital letter to denote a component\n const headerStateClass = `lexical-table-cell-header-${node.headerState}`;\n let style = '';\n if (node.backgroundColor) {\n style += `background-color: ${node.backgroundColor};`;\n }\n\n style += `border: 1px solid #ccc;`;\n\n style += `padding: 8px;`;\n\n // Note: JSX does not support setting attributes directly as strings, so you must convert the colSpan and rowSpan to numbers\n const colSpan = node.colSpan && node.colSpan > 1 ? node.colSpan : undefined;\n const rowSpan = node.rowSpan && node.rowSpan > 1 ? node.rowSpan : undefined;\n\n return (\n <TagName\n class={`lexical-table-cell ${headerStateClass}`}\n colspan={colSpan} // colSpan and rowSpan will only be added if they are not null\n rowspan={rowSpan}\n style={style}\n >\n {children}\n </TagName>\n );\n },\n tablerow: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n return <tr class=\"lexical-table-row\">{children}</tr>;\n },\n};\n","import { NodeFormat } from '@payloadcms/richtext-lexical';\nimport type { SerializedTextNode } from 'lexical';\nimport type { JSXConverter, JSXConverters } from '../types.js';\n\ntype TextConverterArgs = Parameters<\n Extract<JSXConverter<SerializedTextNode>, (...args: any[]) => JSX.Element>\n>[0];\n\nexport const TextJSXConverter: JSXConverters<SerializedTextNode> = {\n text: ({ node }: TextConverterArgs) => {\n let text: JSX.Element = node.text;\n\n if (node.format & NodeFormat.IS_BOLD) {\n text = <strong>{text}</strong>;\n }\n if (node.format & NodeFormat.IS_ITALIC) {\n text = <em>{text}</em>;\n }\n if (node.format & NodeFormat.IS_STRIKETHROUGH) {\n text = <span style=\"text-decoration: line-through;\">{text}</span>;\n }\n if (node.format & NodeFormat.IS_UNDERLINE) {\n text = <span style=\"text-decoration: underline;\">{text}</span>;\n }\n if (node.format & NodeFormat.IS_CODE) {\n text = <code>{text}</code>;\n }\n if (node.format & NodeFormat.IS_SUBSCRIPT) {\n text = <sub>{text}</sub>;\n }\n if (node.format & NodeFormat.IS_SUPERSCRIPT) {\n text = <sup>{text}</sup>;\n }\n\n return text;\n },\n};\n","import type { FileData, FileSizeImproved, TypeWithID } from 'payload';\n\nimport type { SerializedUploadNode } from '@payloadcms/richtext-lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const UploadJSXConverter: JSXConverters<SerializedUploadNode> = {\n upload: ({ node }) => {\n // TO-DO (v4): SerializedUploadNode should use UploadData_P4\n const uploadNode = node as any;\n if (typeof uploadNode.value !== 'object') {\n return null;\n }\n\n const uploadDoc = uploadNode.value as FileData & TypeWithID;\n\n const url = uploadDoc.url;\n\n /**\n * If the upload is not an image, return a link to the upload\n */\n if (!uploadDoc.mimeType.startsWith('image')) {\n return (\n <a href={url} rel=\"noopener noreferrer\">\n {uploadDoc.filename}\n </a>\n );\n }\n\n /**\n * If the upload is a simple image with no different sizes, return a simple img tag\n */\n if (!uploadDoc.sizes || !Object.keys(uploadDoc.sizes).length) {\n return (\n <img alt={uploadDoc.filename} height={uploadDoc.height} src={url} width={uploadDoc.width} />\n );\n }\n\n /**\n * If the upload is an image with different sizes, return a picture element\n */\n const pictureJSX: JSX.Element[] = [];\n\n // Iterate through each size in the data.sizes object\n for (const size in uploadDoc.sizes) {\n const imageSize = uploadDoc.sizes[size] as FileSizeImproved;\n\n // Skip if any property of the size object is null\n if (\n !imageSize ||\n !imageSize.width ||\n !imageSize.height ||\n !imageSize.mimeType ||\n !imageSize.filesize ||\n !imageSize.filename ||\n !imageSize.url\n ) {\n continue;\n }\n const imageSizeURL = imageSize?.url;\n\n pictureJSX.push(\n <source\n key={size}\n media={`(max-width: ${imageSize.width}px)`}\n srcset={imageSizeURL}\n type={imageSize.mimeType}\n />,\n );\n }\n\n // Add the default img tag\n pictureJSX.push(\n <img\n alt={uploadDoc?.filename}\n height={uploadDoc?.height}\n key={'image'}\n src={url}\n width={uploadDoc?.width}\n />,\n );\n return <picture>{pictureJSX}</picture>;\n },\n};\n","import type { JSXConverters } from './types.js';\n\nimport { DefaultNodeTypes } from '@payloadcms/richtext-lexical';\nimport { BlockquoteJSXConverter } from './converters/blockquote.js';\nimport { HeadingJSXConverter } from './converters/heading.js';\nimport { HorizontalRuleJSXConverter } from './converters/horizontalRule.js';\nimport { LinebreakJSXConverter } from './converters/linebreak.js';\nimport { LinkJSXConverter } from './converters/link.js';\nimport { ListJSXConverter } from './converters/list.js';\nimport { ParagraphJSXConverter } from './converters/paragraph.js';\nimport { TabJSXConverter } from './converters/tab.js';\nimport { TableJSXConverter } from './converters/table.js';\nimport { TextJSXConverter } from './converters/text.js';\nimport { UploadJSXConverter } from './converters/upload.js';\n\nexport const defaultJSXConverters: JSXConverters<DefaultNodeTypes> = {\n ...ParagraphJSXConverter,\n ...TextJSXConverter,\n ...LinebreakJSXConverter,\n ...BlockquoteJSXConverter,\n ...TableJSXConverter,\n ...HeadingJSXConverter,\n ...HorizontalRuleJSXConverter,\n ...ListJSXConverter,\n ...LinkJSXConverter({}),\n ...UploadJSXConverter,\n ...TabJSXConverter,\n};\n","export function genFragmentIdentifier(text: string): string {\n return text\n .toLowerCase()\n .normalize('NFD') // tách dấu ra khỏi ký tự\n .replace(/[\\u0300-\\u036F]/g, '') // bỏ dấu VN\n .replace(/đ/g, 'd')\n .replace(/[\\u2010-\\u2015\\u2212\\uFE58\\uFE63\\uFF0D]/g, '-') // quy mọi dạng gạch ngang Unicode → '-'\n .replace(/[\\s\\u00A0\\/\\\\|_.,;:+=@&]+/g, '-') // khoảng trắng & dấu phân tách → '-'\n .replace(/[^a-z0-9-]/g, '') // giữ lại a-z, số, dấu '-'\n .replace(/-+/g, '-') // gộp nhiều dấu - liên tiếp bằng 1 dấu -\n .replace(/^-|-$/g, ''); // bỏ - ở đầu/cuối (nếu có)\n}\n","import type { SerializedLexicalNode } from '@payloadcms/richtext-lexical/lexical';\nimport type { SerializedTextNode } from 'lexical';\n\nexport function getTextLexicalNode(node: SerializedLexicalNode | null | undefined): string {\n if (!node) return '';\n if (node.type === 'text') {\n return (node as SerializedTextNode).text || '';\n }\n if (!('children' in node) || !Array.isArray(node.children)) return '';\n return node.children.map((child) => getTextLexicalNode(child)).join('');\n}\n","import type { SerializedHeadingNode } from '@payloadcms/richtext-lexical';\nimport type { SerializedLexicalNode } from '@payloadcms/richtext-lexical/lexical';\nimport type { SerializedEditorState } from 'lexical';\nimport { getTextLexicalNode } from './getTextOfLexical.js';\n\nexport interface TableOfContentsHeading {\n text: string;\n level: number;\n}\n\nexport interface TableOfContentsHeadingWithChildren extends TableOfContentsHeading {\n children: TableOfContentsHeadingWithChildren[];\n}\n\n// Hàm lấy tất cả các heading từ content\nexport function getHeaders(\n node: SerializedLexicalNode | SerializedEditorState,\n): TableOfContentsHeading[] {\n const headers: TableOfContentsHeading[] = [];\n\n // Handle SerializedEditorState\n if ('root' in node && node.root) {\n return getHeaders(node.root);\n }\n\n // At this point, node must be SerializedLexicalNode\n const lexicalNode = node as SerializedLexicalNode;\n\n // Handle heading node\n if (lexicalNode.type === 'heading') {\n const headingNode = lexicalNode as SerializedHeadingNode;\n const tag = headingNode.tag || '';\n const level =\n tag === 'h2'\n ? 2\n : tag === 'h3'\n ? 3\n : tag === 'h4'\n ? 4\n : tag === 'h5'\n ? 5\n : tag === 'h6'\n ? 6\n : 0;\n if (level > 0) {\n const text = getTextLexicalNode(lexicalNode);\n if (text) {\n headers.push({\n text,\n level,\n });\n }\n }\n }\n\n // Recursively process children\n if ('children' in lexicalNode && Array.isArray(lexicalNode.children)) {\n lexicalNode.children.forEach((child) => {\n headers.push(...getHeaders(child));\n });\n }\n\n return headers;\n}\n\n// Xây dựng cấu trúc mục lục\nexport function buildTableOfContents(\n headers: TableOfContentsHeading[],\n): TableOfContentsHeadingWithChildren[] {\n const result: TableOfContentsHeadingWithChildren[] = [];\n const stack: TableOfContentsHeadingWithChildren[] = [];\n\n headers.forEach((header) => {\n const headingWithChildren: TableOfContentsHeadingWithChildren = {\n ...header,\n children: [],\n };\n\n while (stack.length > 0 && stack[stack.length - 1].level >= header.level) {\n stack.pop();\n }\n\n if (stack.length === 0) {\n result.push(headingWithChildren);\n } else {\n stack[stack.length - 1].children.push(headingWithChildren);\n }\n\n stack.push(headingWithChildren);\n });\n\n return result;\n}\n","import type { SerializedLexicalNode } from '@payloadcms/richtext-lexical/lexical';\nimport { getTextLexicalNode } from './getTextOfLexical.js';\n\nconst WORDS_PER_MINUTE = 210;\n\nexport function getTimeRead(node: SerializedLexicalNode | null | undefined): number {\n if (!node) return 0;\n const text = getTextLexicalNode(node);\n const wordCount = text.trim().split(/\\s+/).length;\n const minutes = Math.ceil(wordCount / WORDS_PER_MINUTE);\n return Math.max(1, minutes); // Return at least 1 minute\n}\n","/* eslint-disable no-console */\nimport type { SerializedEditorState, SerializedLexicalNode } from 'lexical';\nimport { cloneElement, Fragment, isValidElement } from '@withl5e/l5e/jsx-runtime';\n\nimport type { SerializedBlockNode, SerializedInlineBlockNode } from '@payloadcms/richtext-lexical';\nimport { hasText } from '@payloadcms/richtext-lexical/shared';\nimport type { JSXConverter, JSXConverters, SerializedLexicalNodeWithParent } from './types.js';\n\nexport { defaultJSXConverters } from './defaultConverters.js';\n\nexport { stringToLexical } from './utils/stringToLexical.js';\nexport { genFragmentIdentifier } from './utils/genFragmentIdentifier.js';\nexport {\n buildTableOfContents,\n getHeaders,\n type TableOfContentsHeading,\n type TableOfContentsHeadingWithChildren,\n} from './utils/getTableOfContents.js';\nexport { getTextLexicalNode } from './utils/getTextOfLexical.js';\nexport { getTimeRead } from './utils/getTimeRead.js';\n\nexport type ConvertLexicalToJSXArgs = {\n converters: JSXConverters;\n data: SerializedEditorState;\n disableIndent?: boolean | string[];\n disableTextAlign?: boolean | string[];\n};\n\nexport function convertLexicalToJSX({\n converters,\n data,\n disableIndent,\n disableTextAlign,\n}: ConvertLexicalToJSXArgs): JSX.Element {\n if (hasText(data)) {\n return (\n <Fragment>\n {convertLexicalNodesToJSX({\n converters,\n disableIndent,\n disableTextAlign,\n nodes: data?.root?.children,\n parent: data?.root,\n })}\n </Fragment>\n );\n }\n return <Fragment />;\n}\n\nexport function convertLexicalNodesToJSX({\n converters,\n disableIndent,\n disableTextAlign,\n nodes,\n parent,\n}: {\n converters: JSXConverters;\n disableIndent?: boolean | string[];\n disableTextAlign?: boolean | string[];\n nodes: SerializedLexicalNode[];\n parent: SerializedLexicalNodeWithParent;\n}): JSX.Element[] {\n const unknownConverter: JSXConverter<any> = converters.unknown as JSXConverter<any>;\n\n const jsxArray: JSX.Element[] = nodes.map((node, i) => {\n let converterForNode: JSXConverter<any> | undefined;\n if (node.type === 'block') {\n converterForNode = converters?.blocks?.[(node as SerializedBlockNode)?.fields?.blockType];\n if (!converterForNode && !unknownConverter) {\n console.error(\n `Lexical => JSX converter: Blocks converter: found ${(node as SerializedBlockNode)?.fields?.blockType} block, but no converter is provided`,\n );\n }\n } else if (node.type === 'inlineBlock') {\n converterForNode =\n converters?.inlineBlocks?.[(node as SerializedInlineBlockNode)?.fields?.blockType];\n if (!converterForNode && !unknownConverter) {\n console.error(\n `Lexical => JSX converter: Inline Blocks converter: found ${(node as SerializedInlineBlockNode)?.fields?.blockType} inline block, but no converter is provided`,\n );\n }\n } else {\n converterForNode = converters[node.type] as JSXConverter<any>;\n }\n\n try {\n if (!converterForNode && unknownConverter) {\n converterForNode = unknownConverter;\n }\n\n let reactNode: JSX.Element;\n if (converterForNode) {\n const converted =\n typeof converterForNode === 'function'\n ? converterForNode({\n childIndex: i,\n converters,\n node,\n nodesToJSX: (args) => {\n return convertLexicalNodesToJSX({\n converters: args.converters ?? converters,\n disableIndent: args.disableIndent ?? disableIndent,\n disableTextAlign: args.disableTextAlign ?? disableTextAlign,\n nodes: args.nodes,\n parent: args.parent ?? {\n ...node,\n parent,\n },\n });\n },\n parent,\n })\n : converterForNode;\n reactNode = converted;\n } else {\n reactNode = <span key={i}>unknown node</span>;\n }\n\n let style: string = '';\n\n // Check if disableTextAlign is not true and does not include node type\n if (\n !disableTextAlign &&\n (!Array.isArray(disableTextAlign) || !disableTextAlign?.includes(node.type))\n ) {\n if ('format' in node && node.format) {\n switch (node.format) {\n case 'center':\n style += 'text-align: center;';\n break;\n case 'end':\n style += 'text-align: right;';\n break;\n case 'justify':\n style += 'text-align: justify;';\n break;\n case 'left':\n //style.textAlign = 'left'\n // Do nothing, as left is the default\n break;\n case 'right':\n style += 'text-align: right;';\n break;\n case 'start':\n style += 'text-align: left;';\n break;\n }\n }\n }\n\n if (\n !disableIndent &&\n (!Array.isArray(disableIndent) || !disableIndent?.includes(node.type))\n ) {\n if ('indent' in node && node.indent && node.type !== 'listitem') {\n // the unit should be px. Do not change it to rem, em, or something else.\n // The quantity should be 40px. Do not change it either.\n // See rationale in\n // https://github.com/payloadcms/payload/issues/13130#issuecomment-3058348085\n style += `padding-inline-start: ${Number(node.indent) * 40}px;`;\n }\n }\n\n if (isValidElement(reactNode)) {\n // Inject style into reactNode\n if (style) {\n const existingStyle =\n typeof reactNode?.props?.style === 'string' ? reactNode.props.style : '';\n const newStyle = `${style} ${existingStyle}`.trim();\n\n return cloneElement(reactNode, {\n key: i,\n style: newStyle,\n });\n }\n return cloneElement(reactNode, {\n key: i,\n });\n }\n\n return reactNode;\n } catch (error) {\n console.error('Error converting lexical node to JSX:', error, 'node:', node);\n return null;\n }\n });\n\n return jsxArray.filter(Boolean);\n}\n"],"names":["BlockquoteJSXConverter","node","nodesToJSX","children","jsxFactory","HeadingJSXConverter","NodeTag","HorizontalRuleJSXConverter","LinebreakJSXConverter","LinkJSXConverter","internalDocToHref","rel","target","href","ListJSXConverter","parent","hasSubLists","child","uuid","uuidv4","__Fragment","ParagraphJSXConverter","TabJSXConverter","TableJSXConverter","TagName","headerStateClass","style","colSpan","rowSpan","TextJSXConverter","text","NodeFormat","UploadJSXConverter","uploadNode","uploadDoc","url","pictureJSX","size","imageSize","imageSizeURL","defaultJSXConverters","genFragmentIdentifier","getTextLexicalNode","getHeaders","headers","lexicalNode","tag","level","buildTableOfContents","result","stack","header","headingWithChildren","WORDS_PER_MINUTE","getTimeRead","wordCount","minutes","convertLexicalToJSX","converters","data","disableIndent","disableTextAlign","hasText","Fragment","convertLexicalNodesToJSX","nodes","unknownConverter","i","converterForNode","reactNode","args","isValidElement","existingStyle","newStyle","cloneElement","error"],"mappings":";;;;;AAG0E,MAAAA,IAAA;AAAA,EACxE,OAAO,CAAC,EAAE,MAAAC,GAAM,YAAAC,QAAiB;AAC/B,UAAMC,IAAWD,EAAW;AAAA,MAC1B,OAAOD,EAAK;AAAA,IAAA,CACb;AAED,WAAO,gBAAAG,EAAC,oBAAYD,CAAS;AAAA,EAC/B;AACF,GCRyEE,IAAA;AAAA,EACvE,SAAS,CAAC,EAAE,MAAAJ,GAAM,YAAAC,QAAiB;AACjC,UAAMC,IAAWD,EAAW;AAAA,MAC1B,OAAOD,EAAK;AAAA,IAAA,CACb,GAEKK,IAAUL,EAAK;AAErB,WAAO,gBAAAG,EAACE,SAASH,CAAS;AAAA,EAC5B;AACF,GCXuFI,IAAA;AAAA,EACrF,kCAAiB,MAAA,IAAG;AACtB,GCD6EC,IAAA;AAAA,EAC3E,6BAAY,MAAA,IAAG;AACjB,GCA+FC,IAAA,CAAA,EAAA,mBAAAC,SAAA;AAAA,EAC7F,UAAU,CAAC,EAAE,MAAAT,GAAM,YAAAC,QAAiB;AAClC,UAAMC,IAAWD,EAAW;AAAA,MAC1B,OAAOD,EAAK;AAAA,IAAA,CACb,GAEKU,IAA0BV,EAAK,OAAO,SAAS,wBAAwB,QACvEW,IAA6BX,EAAK,OAAO,SAAS,WAAW;AAEnE,WACE,gBAAAG,EAAC,KAAA,EAAE,MAAMH,EAAK,OAAO,KAAW,KAAAU,GAAK,QAAAC,EAAO,GACzCT,CACH;AAAA,EAEJ;AAAA,EACA,MAAM,CAAC,EAAE,MAAAF,GAAM,YAAAC,QAAiB;AAC9B,UAAMC,IAAWD,EAAW;AAAA,MAC1B,OAAOD,EAAK;AAAA,IAAA,CACb,GAEKU,IAA0BV,EAAK,OAAO,SAAS,wBAAwB,QACvEW,IAA6BX,EAAK,OAAO,SAAS,WAAW;AAEnE,QAAIY,IAAeZ,EAAK,OAAO,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T;AAAA,UACF,KAAK;AACH,YAAAA,KAAS;AACT;AAAA,UACF,KAAK;AACH,YAAAA,KAAS;AACT;AAAA,UACF,KAAK;AAGH;AAAA,UACF,KAAK;AACH,YAAAA,KAAS;AACT;AAAA,UACF,KAAK;AACH,YAAAA,KAAS;AACT;AAAA,QAAA;AAkBR,UAZE,CAACkC,MACA,CAAC,MAAM,QAAQA,CAAa,KAAK,CAACA,GAAe,SAAS3D,EAAK,IAAI,MAEhE,YAAYA,KAAQA,EAAK,UAAUA,EAAK,SAAS,eAKnDyB,KAAS,yBAAyB,OAAOzB,EAAK,MAAM,IAAI,EAAE,QAI1DsE,EAAeF,CAAS,GAAG;AAE7B,YAAI3C,GAAO;AACT,gBAAM8C,IACJ,OAAOH,GAAW,OAAO,SAAU,WAAWA,EAAU,MAAM,QAAQ,IAClEI,IAAW,GAAG/C,CAAK,IAAI8C,CAAa,GAAG,KAAA;AAE7C,iBAAOE,EAAaL,GAAW;AAAA,YAC7B,KAAKF;AAAA,YACL,OAAOM;AAAA,UAAA,CACR;AAAA,QACH;AACA,eAAOC,EAAaL,GAAW;AAAA,UAC7B,KAAKF;AAAA,QAAA,CACN;AAAA,MACH;AAEA,aAAOE;AAAA,IACT,SAASM,GAAO;AACd,qBAAQ,MAAM,yCAAyCA,GAAO,SAAS1E,CAAI,GACpE;AAAA,IACT;AAAA,EACF,CAAC,EAEe,OAAO,OAAO;AAChC;"}
1
+ {"version":3,"file":"index.js","names":["headingNode"],"sources":["../src/richtext-render/converters/blockquote.tsx","../src/richtext-render/converters/heading.tsx","../src/richtext-render/converters/horizontalRule.tsx","../src/richtext-render/converters/linebreak.tsx","../src/richtext-render/converters/link.tsx","../src/richtext-render/converters/list.tsx","../src/richtext-render/converters/paragraph.tsx","../src/richtext-render/converters/tab.tsx","../src/richtext-render/converters/table.tsx","../src/richtext-render/converters/text.tsx","../src/richtext-render/converters/upload.tsx","../src/richtext-render/defaultConverters.ts","../src/richtext-render/utils/genFragmentIdentifier.ts","../src/richtext-render/utils/getTextOfLexical.ts","../src/richtext-render/utils/getTableOfContents.ts","../src/richtext-render/utils/getTimeRead.ts","../src/richtext-render/index.tsx"],"sourcesContent":["import type { SerializedQuoteNode } from '@payloadcms/richtext-lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const BlockquoteJSXConverter: JSXConverters<SerializedQuoteNode> = {\n quote: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n return <blockquote>{children}</blockquote>;\n },\n};\n","import { SerializedHeadingNode } from '@payloadcms/richtext-lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const HeadingJSXConverter: JSXConverters<SerializedHeadingNode> = {\n heading: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n const NodeTag = node.tag;\n\n return <NodeTag>{children}</NodeTag>;\n },\n};\n","import { SerializedHorizontalRuleNode } from '@payloadcms/richtext-lexical';\nimport type { JSXConverters } from '../types.js';\nexport const HorizontalRuleJSXConverter: JSXConverters<SerializedHorizontalRuleNode> = {\n horizontalrule: <hr />,\n};\n","import type { SerializedLineBreakNode } from 'lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const LinebreakJSXConverter: JSXConverters<SerializedLineBreakNode> = {\n linebreak: <br />,\n};\n","import type { SerializedAutoLinkNode, SerializedLinkNode } from '@payloadcms/richtext-lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const LinkJSXConverter: (args: {\n internalDocToHref?: (args: { linkNode: SerializedLinkNode }) => string;\n}) => JSXConverters<SerializedAutoLinkNode | SerializedLinkNode> = ({ internalDocToHref }) => ({\n autolink: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n const rel: string | undefined = node.fields.newTab ? 'noopener noreferrer' : undefined;\n const target: string | undefined = node.fields.newTab ? '_blank' : undefined;\n\n return (\n <a href={node.fields.url} {...{ rel, target }}>\n {children}\n </a>\n );\n },\n link: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n const rel: string | undefined = node.fields.newTab ? 'noopener noreferrer' : undefined;\n const target: string | undefined = node.fields.newTab ? '_blank' : undefined;\n\n let href: string = node.fields.url ?? '';\n if (node.fields.linkType === 'internal') {\n if (internalDocToHref) {\n href = internalDocToHref({ linkNode: node });\n } else {\n console.error(\n 'Lexical => JSX converter: Link converter: found internal link, but internalDocToHref is not provided',\n );\n href = '#'; // fallback\n }\n }\n\n return (\n <a href={href} {...{ rel, target }}>\n {children}\n </a>\n );\n },\n});\n","import { v4 as uuidv4 } from 'uuid';\nimport { Fragment } from '@withl5e/l5e/jsx-runtime';\n\nimport type { SerializedListItemNode, SerializedListNode } from '@payloadcms/richtext-lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const ListJSXConverter: JSXConverters<SerializedListItemNode | SerializedListNode> = {\n list: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n const NodeTag = node.tag;\n\n return <NodeTag class={`list-${node?.listType}`}>{children}</NodeTag>;\n },\n listitem: ({ node, nodesToJSX, parent }) => {\n const hasSubLists = node.children.some((child) => child.type === 'list');\n\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n if ('listType' in parent && parent?.listType === 'check') {\n const uuid = uuidv4();\n\n return (\n <li\n aria-checked={node.checked ? 'true' : 'false'}\n class={`list-item-checkbox${node.checked ? ' list-item-checkbox-checked' : ' list-item-checkbox-unchecked'}${hasSubLists ? ' nestedListItem' : ''}`}\n // eslint-disable-next-line jsx-a11y/no-noninteractive-element-to-interactive-role\n role=\"checkbox\"\n style=\"list-style-type: none;\"\n tabindex={'-1'}\n value={node?.value}\n >\n {hasSubLists ? (\n children\n ) : (\n <>\n <input checked={node.checked} id={uuid} readonly={true} type=\"checkbox\" />\n <label for={uuid}>{children}</label>\n <br />\n </>\n )}\n </li>\n );\n } else {\n return (\n <li\n class={`${hasSubLists ? 'nestedListItem' : ''}`}\n style={hasSubLists ? 'list-style-type: none;' : ''}\n value={node?.value}\n >\n {children}\n </li>\n );\n }\n },\n};\n","import type { SerializedParagraphNode } from 'lexical';\nimport type { JSXConverter, JSXConverters } from '../types.js';\n\ntype ParagraphConverterArgs = Parameters<\n Extract<JSXConverter<SerializedParagraphNode>, (...args: any[]) => JSX.Element>\n>[0];\n\nexport const ParagraphJSXConverter: JSXConverters<SerializedParagraphNode> = {\n paragraph: ({ node, nodesToJSX }: ParagraphConverterArgs) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n if (!children?.length) {\n return (\n <p>\n <br />\n </p>\n );\n }\n\n return <p>{children}</p>;\n },\n};\n","import type { SerializedTabNode } from 'lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const TabJSXConverter: JSXConverters<SerializedTabNode> = {\n tab: '\\t',\n};\n","import type {\n SerializedTableCellNode,\n SerializedTableNode,\n SerializedTableRowNode,\n} from '@payloadcms/richtext-lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const TableJSXConverter: JSXConverters<\n SerializedTableCellNode | SerializedTableNode | SerializedTableRowNode\n> = {\n table: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n return (\n <div class=\"lexical-table-container\">\n <table class=\"lexical-table\" style=\"border-collapse: collapse;\">\n <tbody>{children}</tbody>\n </table>\n </div>\n );\n },\n tablecell: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n\n const TagName = node.headerState > 0 ? 'th' : 'td'; // Use capital letter to denote a component\n const headerStateClass = `lexical-table-cell-header-${node.headerState}`;\n let style = '';\n if (node.backgroundColor) {\n style += `background-color: ${node.backgroundColor};`;\n }\n\n style += `border: 1px solid #ccc;`;\n\n style += `padding: 8px;`;\n\n // Note: JSX does not support setting attributes directly as strings, so you must convert the colSpan and rowSpan to numbers\n const colSpan = node.colSpan && node.colSpan > 1 ? node.colSpan : undefined;\n const rowSpan = node.rowSpan && node.rowSpan > 1 ? node.rowSpan : undefined;\n\n return (\n <TagName\n class={`lexical-table-cell ${headerStateClass}`}\n colspan={colSpan} // colSpan and rowSpan will only be added if they are not null\n rowspan={rowSpan}\n style={style}\n >\n {children}\n </TagName>\n );\n },\n tablerow: ({ node, nodesToJSX }) => {\n const children = nodesToJSX({\n nodes: node.children,\n });\n return <tr class=\"lexical-table-row\">{children}</tr>;\n },\n};\n","import { NodeFormat } from '@payloadcms/richtext-lexical';\nimport type { SerializedTextNode } from 'lexical';\nimport type { JSXConverter, JSXConverters } from '../types.js';\n\ntype TextConverterArgs = Parameters<\n Extract<JSXConverter<SerializedTextNode>, (...args: any[]) => JSX.Element>\n>[0];\n\nexport const TextJSXConverter: JSXConverters<SerializedTextNode> = {\n text: ({ node }: TextConverterArgs) => {\n let text: JSX.Element = node.text;\n\n if (node.format & NodeFormat.IS_BOLD) {\n text = <strong>{text}</strong>;\n }\n if (node.format & NodeFormat.IS_ITALIC) {\n text = <em>{text}</em>;\n }\n if (node.format & NodeFormat.IS_STRIKETHROUGH) {\n text = <span style=\"text-decoration: line-through;\">{text}</span>;\n }\n if (node.format & NodeFormat.IS_UNDERLINE) {\n text = <span style=\"text-decoration: underline;\">{text}</span>;\n }\n if (node.format & NodeFormat.IS_CODE) {\n text = <code>{text}</code>;\n }\n if (node.format & NodeFormat.IS_SUBSCRIPT) {\n text = <sub>{text}</sub>;\n }\n if (node.format & NodeFormat.IS_SUPERSCRIPT) {\n text = <sup>{text}</sup>;\n }\n\n return text;\n },\n};\n","import type { FileData, FileSizeImproved, TypeWithID } from 'payload';\n\nimport type { SerializedUploadNode } from '@payloadcms/richtext-lexical';\nimport type { JSXConverters } from '../types.js';\n\nexport const UploadJSXConverter: JSXConverters<SerializedUploadNode> = {\n upload: ({ node }) => {\n // TO-DO (v4): SerializedUploadNode should use UploadData_P4\n const uploadNode = node as any;\n if (typeof uploadNode.value !== 'object') {\n return null;\n }\n\n const uploadDoc = uploadNode.value as FileData & TypeWithID;\n\n const url = uploadDoc.url;\n\n /**\n * If the upload is not an image, return a link to the upload\n */\n if (!uploadDoc.mimeType.startsWith('image')) {\n return (\n <a href={url} rel=\"noopener noreferrer\">\n {uploadDoc.filename}\n </a>\n );\n }\n\n /**\n * If the upload is a simple image with no different sizes, return a simple img tag\n */\n if (!uploadDoc.sizes || !Object.keys(uploadDoc.sizes).length) {\n return (\n <img alt={uploadDoc.filename} height={uploadDoc.height} src={url} width={uploadDoc.width} />\n );\n }\n\n /**\n * If the upload is an image with different sizes, return a picture element\n */\n const pictureJSX: JSX.Element[] = [];\n\n // Iterate through each size in the data.sizes object\n for (const size in uploadDoc.sizes) {\n const imageSize = uploadDoc.sizes[size] as FileSizeImproved;\n\n // Skip if any property of the size object is null\n if (\n !imageSize ||\n !imageSize.width ||\n !imageSize.height ||\n !imageSize.mimeType ||\n !imageSize.filesize ||\n !imageSize.filename ||\n !imageSize.url\n ) {\n continue;\n }\n const imageSizeURL = imageSize?.url;\n\n pictureJSX.push(\n <source\n key={size}\n media={`(max-width: ${imageSize.width}px)`}\n srcset={imageSizeURL}\n type={imageSize.mimeType}\n />,\n );\n }\n\n // Add the default img tag\n pictureJSX.push(\n <img\n alt={uploadDoc?.filename}\n height={uploadDoc?.height}\n key={'image'}\n src={url}\n width={uploadDoc?.width}\n />,\n );\n return <picture>{pictureJSX}</picture>;\n },\n};\n","import type { JSXConverters } from './types.js';\n\nimport { DefaultNodeTypes } from '@payloadcms/richtext-lexical';\nimport { BlockquoteJSXConverter } from './converters/blockquote.js';\nimport { HeadingJSXConverter } from './converters/heading.js';\nimport { HorizontalRuleJSXConverter } from './converters/horizontalRule.js';\nimport { LinebreakJSXConverter } from './converters/linebreak.js';\nimport { LinkJSXConverter } from './converters/link.js';\nimport { ListJSXConverter } from './converters/list.js';\nimport { ParagraphJSXConverter } from './converters/paragraph.js';\nimport { TabJSXConverter } from './converters/tab.js';\nimport { TableJSXConverter } from './converters/table.js';\nimport { TextJSXConverter } from './converters/text.js';\nimport { UploadJSXConverter } from './converters/upload.js';\n\nexport const defaultJSXConverters: JSXConverters<DefaultNodeTypes> = {\n ...ParagraphJSXConverter,\n ...TextJSXConverter,\n ...LinebreakJSXConverter,\n ...BlockquoteJSXConverter,\n ...TableJSXConverter,\n ...HeadingJSXConverter,\n ...HorizontalRuleJSXConverter,\n ...ListJSXConverter,\n ...LinkJSXConverter({}),\n ...UploadJSXConverter,\n ...TabJSXConverter,\n};\n","export function genFragmentIdentifier(text: string): string {\n return text\n .toLowerCase()\n .normalize('NFD') // tách dấu ra khỏi ký tự\n .replace(/[\\u0300-\\u036F]/g, '') // bỏ dấu VN\n .replace(/đ/g, 'd')\n .replace(/[\\u2010-\\u2015\\u2212\\uFE58\\uFE63\\uFF0D]/g, '-') // quy mọi dạng gạch ngang Unicode → '-'\n .replace(/[\\s\\u00A0\\/\\\\|_.,;:+=@&]+/g, '-') // khoảng trắng & dấu phân tách → '-'\n .replace(/[^a-z0-9-]/g, '') // giữ lại a-z, số, dấu '-'\n .replace(/-+/g, '-') // gộp nhiều dấu - liên tiếp bằng 1 dấu -\n .replace(/^-|-$/g, ''); // bỏ - ở đầu/cuối (nếu có)\n}\n","import type { SerializedLexicalNode } from '@payloadcms/richtext-lexical/lexical';\nimport type { SerializedTextNode } from 'lexical';\n\nexport function getTextLexicalNode(node: SerializedLexicalNode | null | undefined): string {\n if (!node) return '';\n if (node.type === 'text') {\n return (node as SerializedTextNode).text || '';\n }\n if (!('children' in node) || !Array.isArray(node.children)) return '';\n return node.children.map((child) => getTextLexicalNode(child)).join('');\n}\n","import type { SerializedHeadingNode } from '@payloadcms/richtext-lexical';\nimport type { SerializedLexicalNode } from '@payloadcms/richtext-lexical/lexical';\nimport type { SerializedEditorState } from 'lexical';\nimport { getTextLexicalNode } from './getTextOfLexical.js';\n\nexport interface TableOfContentsHeading {\n text: string;\n level: number;\n}\n\nexport interface TableOfContentsHeadingWithChildren extends TableOfContentsHeading {\n children: TableOfContentsHeadingWithChildren[];\n}\n\n// Hàm lấy tất cả các heading từ content\nexport function getHeaders(\n node: SerializedLexicalNode | SerializedEditorState,\n): TableOfContentsHeading[] {\n const headers: TableOfContentsHeading[] = [];\n\n // Handle SerializedEditorState\n if ('root' in node && node.root) {\n return getHeaders(node.root);\n }\n\n // At this point, node must be SerializedLexicalNode\n const lexicalNode = node as SerializedLexicalNode;\n\n // Handle heading node\n if (lexicalNode.type === 'heading') {\n const headingNode = lexicalNode as SerializedHeadingNode;\n const tag = headingNode.tag || '';\n const level =\n tag === 'h2'\n ? 2\n : tag === 'h3'\n ? 3\n : tag === 'h4'\n ? 4\n : tag === 'h5'\n ? 5\n : tag === 'h6'\n ? 6\n : 0;\n if (level > 0) {\n const text = getTextLexicalNode(lexicalNode);\n if (text) {\n headers.push({\n text,\n level,\n });\n }\n }\n }\n\n // Recursively process children\n if ('children' in lexicalNode && Array.isArray(lexicalNode.children)) {\n lexicalNode.children.forEach((child) => {\n headers.push(...getHeaders(child));\n });\n }\n\n return headers;\n}\n\n// Xây dựng cấu trúc mục lục\nexport function buildTableOfContents(\n headers: TableOfContentsHeading[],\n): TableOfContentsHeadingWithChildren[] {\n const result: TableOfContentsHeadingWithChildren[] = [];\n const stack: TableOfContentsHeadingWithChildren[] = [];\n\n headers.forEach((header) => {\n const headingWithChildren: TableOfContentsHeadingWithChildren = {\n ...header,\n children: [],\n };\n\n while (stack.length > 0 && stack[stack.length - 1].level >= header.level) {\n stack.pop();\n }\n\n if (stack.length === 0) {\n result.push(headingWithChildren);\n } else {\n stack[stack.length - 1].children.push(headingWithChildren);\n }\n\n stack.push(headingWithChildren);\n });\n\n return result;\n}\n","import type { SerializedLexicalNode } from '@payloadcms/richtext-lexical/lexical';\nimport { getTextLexicalNode } from './getTextOfLexical.js';\n\nconst WORDS_PER_MINUTE = 210;\n\nexport function getTimeRead(node: SerializedLexicalNode | null | undefined): number {\n if (!node) return 0;\n const text = getTextLexicalNode(node);\n const wordCount = text.trim().split(/\\s+/).length;\n const minutes = Math.ceil(wordCount / WORDS_PER_MINUTE);\n return Math.max(1, minutes); // Return at least 1 minute\n}\n","/* eslint-disable no-console */\nimport type { SerializedEditorState, SerializedLexicalNode } from 'lexical';\nimport { cloneElement, Fragment, isValidElement } from '@withl5e/l5e/jsx-runtime';\n\nimport type { SerializedBlockNode, SerializedInlineBlockNode } from '@payloadcms/richtext-lexical';\nimport { hasText } from '@payloadcms/richtext-lexical/shared';\nimport type { JSXConverter, JSXConverters, SerializedLexicalNodeWithParent } from './types.js';\n\nexport { defaultJSXConverters } from './defaultConverters.js';\n\nexport { stringToLexical } from './utils/stringToLexical.js';\nexport { genFragmentIdentifier } from './utils/genFragmentIdentifier.js';\nexport {\n buildTableOfContents,\n getHeaders,\n type TableOfContentsHeading,\n type TableOfContentsHeadingWithChildren,\n} from './utils/getTableOfContents.js';\nexport { getTextLexicalNode } from './utils/getTextOfLexical.js';\nexport { getTimeRead } from './utils/getTimeRead.js';\n\nexport type ConvertLexicalToJSXArgs = {\n converters: JSXConverters;\n data: SerializedEditorState;\n disableIndent?: boolean | string[];\n disableTextAlign?: boolean | string[];\n};\n\nexport function convertLexicalToJSX({\n converters,\n data,\n disableIndent,\n disableTextAlign,\n}: ConvertLexicalToJSXArgs): JSX.Element {\n if (hasText(data)) {\n return (\n <Fragment>\n {convertLexicalNodesToJSX({\n converters,\n disableIndent,\n disableTextAlign,\n nodes: data?.root?.children,\n parent: data?.root,\n })}\n </Fragment>\n );\n }\n return <Fragment />;\n}\n\nexport function convertLexicalNodesToJSX({\n converters,\n disableIndent,\n disableTextAlign,\n nodes,\n parent,\n}: {\n converters: JSXConverters;\n disableIndent?: boolean | string[];\n disableTextAlign?: boolean | string[];\n nodes: SerializedLexicalNode[];\n parent: SerializedLexicalNodeWithParent;\n}): JSX.Element[] {\n const unknownConverter: JSXConverter<any> = converters.unknown as JSXConverter<any>;\n\n const jsxArray: JSX.Element[] = nodes.map((node, i) => {\n let converterForNode: JSXConverter<any> | undefined;\n if (node.type === 'block') {\n converterForNode = converters?.blocks?.[(node as SerializedBlockNode)?.fields?.blockType];\n if (!converterForNode && !unknownConverter) {\n console.error(\n `Lexical => JSX converter: Blocks converter: found ${(node as SerializedBlockNode)?.fields?.blockType} block, but no converter is provided`,\n );\n }\n } else if (node.type === 'inlineBlock') {\n converterForNode =\n converters?.inlineBlocks?.[(node as SerializedInlineBlockNode)?.fields?.blockType];\n if (!converterForNode && !unknownConverter) {\n console.error(\n `Lexical => JSX converter: Inline Blocks converter: found ${(node as SerializedInlineBlockNode)?.fields?.blockType} inline block, but no converter is provided`,\n );\n }\n } else {\n converterForNode = converters[node.type] as JSXConverter<any>;\n }\n\n try {\n if (!converterForNode && unknownConverter) {\n converterForNode = unknownConverter;\n }\n\n let reactNode: JSX.Element;\n if (converterForNode) {\n const converted =\n typeof converterForNode === 'function'\n ? converterForNode({\n childIndex: i,\n converters,\n node,\n nodesToJSX: (args) => {\n return convertLexicalNodesToJSX({\n converters: args.converters ?? converters,\n disableIndent: args.disableIndent ?? disableIndent,\n disableTextAlign: args.disableTextAlign ?? disableTextAlign,\n nodes: args.nodes,\n parent: args.parent ?? {\n ...node,\n parent,\n },\n });\n },\n parent,\n })\n : converterForNode;\n reactNode = converted;\n } else {\n reactNode = <span key={i}>unknown node</span>;\n }\n\n let style: string = '';\n\n // Check if disableTextAlign is not true and does not include node type\n if (\n !disableTextAlign &&\n (!Array.isArray(disableTextAlign) || !disableTextAlign?.includes(node.type))\n ) {\n if ('format' in node && node.format) {\n switch (node.format) {\n case 'center':\n style += 'text-align: center;';\n break;\n case 'end':\n style += 'text-align: right;';\n break;\n case 'justify':\n style += 'text-align: justify;';\n break;\n case 'left':\n //style.textAlign = 'left'\n // Do nothing, as left is the default\n break;\n case 'right':\n style += 'text-align: right;';\n break;\n case 'start':\n style += 'text-align: left;';\n break;\n }\n }\n }\n\n if (\n !disableIndent &&\n (!Array.isArray(disableIndent) || !disableIndent?.includes(node.type))\n ) {\n if ('indent' in node && node.indent && node.type !== 'listitem') {\n // the unit should be px. Do not change it to rem, em, or something else.\n // The quantity should be 40px. Do not change it either.\n // See rationale in\n // https://github.com/payloadcms/payload/issues/13130#issuecomment-3058348085\n style += `padding-inline-start: ${Number(node.indent) * 40}px;`;\n }\n }\n\n if (isValidElement(reactNode)) {\n // Inject style into reactNode\n if (style) {\n const existingStyle =\n typeof reactNode?.props?.style === 'string' ? reactNode.props.style : '';\n const newStyle = `${style} ${existingStyle}`.trim();\n\n return cloneElement(reactNode, {\n key: i,\n style: newStyle,\n });\n }\n return cloneElement(reactNode, {\n key: i,\n });\n }\n\n return reactNode;\n } catch (error) {\n console.error('Error converting lexical node to JSX:', error, 'node:', node);\n return null;\n }\n });\n\n return jsxArray.filter(Boolean);\n}\n"],"mappings":";;;;;;AAImC,IAAA,IAAA,EAAA,QAAA,EAAA,SAAA,oBAAA;CAC/B,IAAM,IAAW,EAAW,EAC1B,OAAO,EAAK,SACd,CAAC;CAED,OAAO,kBAAC,cAAA,MAAY,CAAqB;AAC3C,EACF,GCPqC,IAAA,EAAA,UAAA,EAAA,SAAA,oBAAA;CACjC,IAAM,IAAW,EAAW,EAC1B,OAAO,EAAK,SACd,CAAC,GAEK,IAAU,EAAK;CAErB,OAAO,kBAAC,GAAA,MAAS,CAAkB;AACrC,EACF,GCTA,IAAA,EAAA,gBAAA,kBAAA,MAAA,IAAA,EAAA,GCCA,IAAA,EAAA,WAAA,kBAAA,MAAA,IAAA,EAAA,GCA+F,KAAA,EAAA,4BAAA;CAC7F,WAAW,EAAE,SAAM,oBAAiB;EAClC,IAAM,IAAW,EAAW,EAC1B,OAAO,EAAK,SACd,CAAC,GAEK,IAA0B,EAAK,OAAO,SAAS,wBAAwB,KAAA,GACvE,IAA6B,EAAK,OAAO,SAAS,WAAW,KAAA;EAEnE,OACE,kBAAC,KAAD;GAAG,MAAM,EAAK,OAAO;GAAW;GAAK;EAElC,GADA,CACA;CAEP;CACA,OAAO,EAAE,SAAM,oBAAiB;EAC9B,IAAM,IAAW,EAAW,EAC1B,OAAO,EAAK,SACd,CAAC,GAEK,IAA0B,EAAK,OAAO,SAA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EAAU,MAAM,QAAQ,IAClE,IAAW,GAAG,EAAM,GAAG,IAAgB,KAAK;KAElD,OAAO,EAAa,GAAW;MAC7B,KAAK;MACL,OAAO;KACT,CAAC;IACH;IACA,OAAO,EAAa,GAAW,EAC7B,KAAK,EACP,CAAC;GACH;GAEA,OAAO;EACT,SAAS,GAAO;GAEd,OADA,QAAQ,MAAM,yCAAyC,GAAO,SAAS,CAAI,GACpE;EACT;CACF,CAEO,CAAA,CAAS,OAAO,OAAO;AAChC"}
@@ -1,36 +1,33 @@
1
- function o(t) {
2
- const e = t == null ? "" : String(t);
3
- return {
4
- root: {
5
- type: "root",
6
- format: "",
7
- indent: 0,
8
- version: 1,
9
- direction: "ltr",
10
- children: (e.length === 0 ? [""] : e.split(/\r?\n/)).map((r) => ({
11
- type: "paragraph",
12
- format: "",
13
- indent: 0,
14
- version: 1,
15
- direction: "ltr",
16
- textFormat: 0,
17
- textStyle: "",
18
- children: r.length === 0 ? [] : [
19
- {
20
- type: "text",
21
- text: r,
22
- version: 1,
23
- detail: 0,
24
- format: 0,
25
- mode: "normal",
26
- style: ""
27
- }
28
- ]
29
- }))
30
- }
31
- };
1
+ //#region src/richtext-render/utils/stringToLexical.ts
2
+ function e(e) {
3
+ let t = e == null ? "" : String(e);
4
+ return { root: {
5
+ type: "root",
6
+ format: "",
7
+ indent: 0,
8
+ version: 1,
9
+ direction: "ltr",
10
+ children: (t.length === 0 ? [""] : t.split(/\r?\n/)).map((e) => ({
11
+ type: "paragraph",
12
+ format: "",
13
+ indent: 0,
14
+ version: 1,
15
+ direction: "ltr",
16
+ textFormat: 0,
17
+ textStyle: "",
18
+ children: e.length === 0 ? [] : [{
19
+ type: "text",
20
+ text: e,
21
+ version: 1,
22
+ detail: 0,
23
+ format: 0,
24
+ mode: "normal",
25
+ style: ""
26
+ }]
27
+ }))
28
+ } };
32
29
  }
33
- export {
34
- o as stringToLexical
35
- };
36
- //# sourceMappingURL=stringToLexical.js.map
30
+ //#endregion
31
+ export { e as stringToLexical };
32
+
33
+ //# sourceMappingURL=stringToLexical.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stringToLexical.js","sources":["../src/richtext-render/utils/stringToLexical.ts"],"sourcesContent":["export type LexicalContent = {\n root: {\n type: string;\n format: '' | 'left' | 'start' | 'center' | 'right' | 'end' | 'justify';\n indent: number;\n version: number;\n direction: 'ltr' | 'rtl' | null;\n children: Array<{ type: any; version: number; [k: string]: unknown }>;\n };\n [k: string]: unknown;\n};\n\nexport function stringToLexical(text: string | null | undefined): LexicalContent {\n const raw = text == null ? '' : String(text);\n const lines = raw.length === 0 ? [''] : raw.split(/\\r?\\n/);\n\n return {\n root: {\n type: 'root',\n format: '',\n indent: 0,\n version: 1,\n direction: 'ltr',\n children: lines.map((line) => ({\n type: 'paragraph',\n format: '',\n indent: 0,\n version: 1,\n direction: 'ltr',\n textFormat: 0,\n textStyle: '',\n children:\n line.length === 0\n ? []\n : [\n {\n type: 'text',\n text: line,\n version: 1,\n detail: 0,\n format: 0,\n mode: 'normal',\n style: '',\n },\n ],\n })),\n },\n };\n}\n"],"names":["stringToLexical","text","raw","line"],"mappings":"AAYO,SAASA,EAAgBC,GAAiD;AAC/E,QAAMC,IAAMD,KAAQ,OAAO,KAAK,OAAOA,CAAI;AAG3C,SAAO;AAAA,IACL,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,WAAW;AAAA,MACX,WATUC,EAAI,WAAW,IAAI,CAAC,EAAE,IAAIA,EAAI,MAAM,OAAO,GASrC,IAAI,CAACC,OAAU;AAAA,QAC7B,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,WAAW;AAAA,QACX,YAAY;AAAA,QACZ,WAAW;AAAA,QACX,UACEA,EAAK,WAAW,IACZ,CAAA,IACA;AAAA,UACE;AAAA,YACE,MAAM;AAAA,YACN,MAAMA;AAAA,YACN,SAAS;AAAA,YACT,QAAQ;AAAA,YACR,QAAQ;AAAA,YACR,MAAM;AAAA,YACN,OAAO;AAAA,UAAA;AAAA,QACT;AAAA,MACF,EACN;AAAA,IAAA;AAAA,EACJ;AAEJ;"}
1
+ {"version":3,"file":"stringToLexical.js","names":[],"sources":["../src/richtext-render/utils/stringToLexical.ts"],"sourcesContent":["export type LexicalContent = {\n root: {\n type: string;\n format: '' | 'left' | 'start' | 'center' | 'right' | 'end' | 'justify';\n indent: number;\n version: number;\n direction: 'ltr' | 'rtl' | null;\n children: Array<{ type: any; version: number; [k: string]: unknown }>;\n };\n [k: string]: unknown;\n};\n\nexport function stringToLexical(text: string | null | undefined): LexicalContent {\n const raw = text == null ? '' : String(text);\n const lines = raw.length === 0 ? [''] : raw.split(/\\r?\\n/);\n\n return {\n root: {\n type: 'root',\n format: '',\n indent: 0,\n version: 1,\n direction: 'ltr',\n children: lines.map((line) => ({\n type: 'paragraph',\n format: '',\n indent: 0,\n version: 1,\n direction: 'ltr',\n textFormat: 0,\n textStyle: '',\n children:\n line.length === 0\n ? []\n : [\n {\n type: 'text',\n text: line,\n version: 1,\n detail: 0,\n format: 0,\n mode: 'normal',\n style: '',\n },\n ],\n })),\n },\n };\n}\n"],"mappings":";AAYA,SAAgB,EAAgB,GAAiD;CAC/E,IAAM,IAAM,KAAQ,OAAO,KAAK,OAAO,CAAI;CAG3C,OAAO,EACL,MAAM;EACJ,MAAM;EACN,QAAQ;EACR,QAAQ;EACR,SAAS;EACT,WAAW;EACX,WATU,EAAI,WAAW,IAAI,CAAC,EAAE,IAAI,EAAI,MAAM,OAAO,EAAA,CASrC,KAAK,OAAU;GAC7B,MAAM;GACN,QAAQ;GACR,QAAQ;GACR,SAAS;GACT,WAAW;GACX,YAAY;GACZ,WAAW;GACX,UACE,EAAK,WAAW,IACZ,CAAC,IACD,CACE;IACE,MAAM;IACN,MAAM;IACN,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,OAAO;GACT,CACF;EACR,EAAE;CACJ,EACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withl5e/richtext-payload",
3
- "version": "0.3.3-alpha.4",
3
+ "version": "1.0.0",
4
4
  "description": "Payload Lexical rich text renderer adapter for L5E.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,7 +27,7 @@
27
27
  "uuid": "13.0.0"
28
28
  },
29
29
  "peerDependencies": {
30
- "@withl5e/l5e": "^0.1.1-alpha.2",
30
+ "@withl5e/l5e": "^1.0.0",
31
31
  "@payloadcms/richtext-lexical": "^3.73.0",
32
32
  "lexical": "^0.39.0",
33
33
  "payload": "^3.73.0"
@@ -37,8 +37,8 @@
37
37
  "lexical": "0.39.0",
38
38
  "payload": "3.73.0",
39
39
  "typescript": "^5.6.3",
40
- "vite": "^7.1.5",
41
- "@withl5e/l5e": "0.3.3-alpha.4"
40
+ "vite": "^8.2.2",
41
+ "@withl5e/l5e": "1.0.0"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"