@01.software/sdk 0.23.0 → 0.25.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/README.md +9 -2
- package/dist/{const-CMdmNgEs.d.ts → const-Bs-QcTj0.d.ts} +2 -2
- package/dist/{const-Cgd4op4V.d.cts → const-C8UhtzLn.d.cts} +2 -2
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-D8-G1PiT.d.cts → payload-types-BaK4zCQ8.d.cts} +63 -8
- package/dist/{payload-types-D8-G1PiT.d.ts → payload-types-BaK4zCQ8.d.ts} +63 -8
- package/dist/realtime.d.cts +2 -2
- package/dist/realtime.d.ts +2 -2
- package/dist/{server-DJcDyOmM.d.cts → server-CkGfBnSx.d.cts} +3 -3
- package/dist/{server-D7FcHj7J.d.ts → server-DQYWLnkt.d.ts} +3 -3
- package/dist/server.d.cts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/{types-C_kwEIvY.d.cts → types-BH-YBrFs.d.cts} +1 -1
- package/dist/{types-BQqfXbB2.d.ts → types-DjaaBExv.d.ts} +1 -1
- package/dist/ui/code-block.cjs.map +1 -1
- package/dist/ui/code-block.js.map +1 -1
- package/dist/ui/form.d.cts +1 -1
- package/dist/ui/form.d.ts +1 -1
- package/dist/ui/rich-text.cjs +170 -10
- package/dist/ui/rich-text.cjs.map +1 -1
- package/dist/ui/rich-text.d.cts +22 -3
- package/dist/ui/rich-text.d.ts +22 -3
- package/dist/ui/rich-text.js +165 -5
- package/dist/ui/rich-text.js.map +1 -1
- package/dist/ui/video.d.cts +1 -1
- package/dist/ui/video.d.ts +1 -1
- package/dist/webhook.d.cts +3 -3
- package/dist/webhook.d.ts +3 -3
- package/package.json +5 -4
package/dist/ui/rich-text.cjs
CHANGED
|
@@ -32,11 +32,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
var RichText_exports = {};
|
|
33
33
|
__export(RichText_exports, {
|
|
34
34
|
RichTextContent: () => RichTextContent,
|
|
35
|
-
StyledRichTextContent: () => StyledRichTextContent
|
|
35
|
+
StyledRichTextContent: () => StyledRichTextContent,
|
|
36
|
+
richTextNodeMap: () => richTextNodeMap,
|
|
37
|
+
richTextTextState: () => richTextTextState,
|
|
38
|
+
richTextViewMap: () => richTextViewMap
|
|
36
39
|
});
|
|
37
40
|
module.exports = __toCommonJS(RichText_exports);
|
|
38
|
-
var
|
|
39
|
-
var
|
|
41
|
+
var import_react3 = __toESM(require("react"), 1);
|
|
42
|
+
var import_react4 = require("@payloadcms/richtext-lexical/react");
|
|
40
43
|
|
|
41
44
|
// src/ui/RichText/styled.tsx
|
|
42
45
|
var import_react = __toESM(require("react"), 1);
|
|
@@ -177,12 +180,167 @@ function StyledRichTextContent({
|
|
|
177
180
|
);
|
|
178
181
|
}
|
|
179
182
|
|
|
183
|
+
// src/ui/RichText/views.tsx
|
|
184
|
+
var import_react2 = __toESM(require("react"), 1);
|
|
185
|
+
function getBlockFields(props) {
|
|
186
|
+
return props.formData;
|
|
187
|
+
}
|
|
188
|
+
function CodeView(props) {
|
|
189
|
+
const fields = getBlockFields(props);
|
|
190
|
+
const code = fields.code ?? "";
|
|
191
|
+
const language = fields.language ?? "plaintext";
|
|
192
|
+
if (props.isEditor) {
|
|
193
|
+
const { BlockCollapsible } = props.useBlockComponentContext();
|
|
194
|
+
return /* @__PURE__ */ import_react2.default.createElement(BlockCollapsible, { className: props.className }, /* @__PURE__ */ import_react2.default.createElement("pre", { style: { margin: 0, overflow: "auto", whiteSpace: "pre-wrap" } }, /* @__PURE__ */ import_react2.default.createElement("code", { "data-language": language }, code)));
|
|
195
|
+
}
|
|
196
|
+
return /* @__PURE__ */ import_react2.default.createElement("pre", { style: { overflow: "auto", whiteSpace: "pre-wrap" } }, /* @__PURE__ */ import_react2.default.createElement("code", { "data-language": language }, code));
|
|
197
|
+
}
|
|
198
|
+
function IframeView(props) {
|
|
199
|
+
const fields = getBlockFields(props);
|
|
200
|
+
const url = fields.url ?? "";
|
|
201
|
+
const width = fields.width ?? void 0;
|
|
202
|
+
const height = fields.height ?? void 0;
|
|
203
|
+
if (!url) return null;
|
|
204
|
+
if (props.isEditor) {
|
|
205
|
+
const { BlockCollapsible } = props.useBlockComponentContext();
|
|
206
|
+
return /* @__PURE__ */ import_react2.default.createElement(BlockCollapsible, { className: props.className }, /* @__PURE__ */ import_react2.default.createElement(
|
|
207
|
+
"iframe",
|
|
208
|
+
{
|
|
209
|
+
src: url,
|
|
210
|
+
title: fields.blockName ?? "Embedded content",
|
|
211
|
+
width,
|
|
212
|
+
height,
|
|
213
|
+
style: {
|
|
214
|
+
aspectRatio: width && height ? `${width} / ${height}` : "16 / 9",
|
|
215
|
+
width: "100%"
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
));
|
|
219
|
+
}
|
|
220
|
+
return /* @__PURE__ */ import_react2.default.createElement(
|
|
221
|
+
"iframe",
|
|
222
|
+
{
|
|
223
|
+
src: url,
|
|
224
|
+
title: fields.blockName ?? "Embedded content",
|
|
225
|
+
width,
|
|
226
|
+
height,
|
|
227
|
+
style: {
|
|
228
|
+
aspectRatio: width && height ? `${width} / ${height}` : "16 / 9",
|
|
229
|
+
width: "100%"
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
var richTextTextState = {
|
|
235
|
+
color: {
|
|
236
|
+
"text-red": {
|
|
237
|
+
css: {
|
|
238
|
+
color: "light-dark(oklch(0.577 0.245 27.325), oklch(0.704 0.191 22.216))"
|
|
239
|
+
},
|
|
240
|
+
label: "Red"
|
|
241
|
+
},
|
|
242
|
+
"text-orange": {
|
|
243
|
+
css: {
|
|
244
|
+
color: "light-dark(oklch(0.646 0.222 41.116), oklch(0.75 0.183 55.934))"
|
|
245
|
+
},
|
|
246
|
+
label: "Orange"
|
|
247
|
+
},
|
|
248
|
+
"text-yellow": {
|
|
249
|
+
css: {
|
|
250
|
+
color: "light-dark(oklch(0.554 0.135 66.442), oklch(0.905 0.182 98.111))"
|
|
251
|
+
},
|
|
252
|
+
label: "Yellow"
|
|
253
|
+
},
|
|
254
|
+
"text-green": {
|
|
255
|
+
css: {
|
|
256
|
+
color: "light-dark(oklch(0.527 0.154 150.069), oklch(0.792 0.209 151.711))"
|
|
257
|
+
},
|
|
258
|
+
label: "Green"
|
|
259
|
+
},
|
|
260
|
+
"text-blue": {
|
|
261
|
+
css: {
|
|
262
|
+
color: "light-dark(oklch(0.546 0.245 262.881), oklch(0.707 0.165 254.624))"
|
|
263
|
+
},
|
|
264
|
+
label: "Blue"
|
|
265
|
+
},
|
|
266
|
+
"text-purple": {
|
|
267
|
+
css: {
|
|
268
|
+
color: "light-dark(oklch(0.558 0.288 302.321), oklch(0.714 0.203 305.504))"
|
|
269
|
+
},
|
|
270
|
+
label: "Purple"
|
|
271
|
+
},
|
|
272
|
+
"text-pink": {
|
|
273
|
+
css: {
|
|
274
|
+
color: "light-dark(oklch(0.592 0.249 0.584), oklch(0.718 0.202 349.761))"
|
|
275
|
+
},
|
|
276
|
+
label: "Pink"
|
|
277
|
+
},
|
|
278
|
+
"bg-red": {
|
|
279
|
+
css: {
|
|
280
|
+
"background-color": "light-dark(oklch(0.704 0.191 22.216), oklch(0.577 0.245 27.325))"
|
|
281
|
+
},
|
|
282
|
+
label: "Red"
|
|
283
|
+
},
|
|
284
|
+
"bg-orange": {
|
|
285
|
+
css: {
|
|
286
|
+
"background-color": "light-dark(oklch(0.75 0.183 55.934), oklch(0.646 0.222 41.116))"
|
|
287
|
+
},
|
|
288
|
+
label: "Orange"
|
|
289
|
+
},
|
|
290
|
+
"bg-yellow": {
|
|
291
|
+
css: {
|
|
292
|
+
"background-color": "light-dark(oklch(0.905 0.182 98.111), oklch(0.554 0.135 66.442))"
|
|
293
|
+
},
|
|
294
|
+
label: "Yellow"
|
|
295
|
+
},
|
|
296
|
+
"bg-green": {
|
|
297
|
+
css: {
|
|
298
|
+
"background-color": "light-dark(oklch(0.792 0.209 151.711), oklch(0.527 0.154 150.069))"
|
|
299
|
+
},
|
|
300
|
+
label: "Green"
|
|
301
|
+
},
|
|
302
|
+
"bg-blue": {
|
|
303
|
+
css: {
|
|
304
|
+
"background-color": "light-dark(oklch(0.707 0.165 254.624), oklch(0.546 0.245 262.881))"
|
|
305
|
+
},
|
|
306
|
+
label: "Blue"
|
|
307
|
+
},
|
|
308
|
+
"bg-purple": {
|
|
309
|
+
css: {
|
|
310
|
+
"background-color": "light-dark(oklch(0.714 0.203 305.504), oklch(0.558 0.288 302.321))"
|
|
311
|
+
},
|
|
312
|
+
label: "Purple"
|
|
313
|
+
},
|
|
314
|
+
"bg-pink": {
|
|
315
|
+
css: {
|
|
316
|
+
"background-color": "light-dark(oklch(0.718 0.202 349.761), oklch(0.592 0.249 0.584))"
|
|
317
|
+
},
|
|
318
|
+
label: "Pink"
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
var richTextNodeMap = {
|
|
323
|
+
blocks: {
|
|
324
|
+
Code: {
|
|
325
|
+
Block: CodeView
|
|
326
|
+
},
|
|
327
|
+
Iframe: {
|
|
328
|
+
Block: IframeView
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
var richTextViewMap = {
|
|
333
|
+
default: {
|
|
334
|
+
nodes: richTextNodeMap
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
180
338
|
// src/ui/RichText/index.tsx
|
|
181
339
|
function hyphenToCamel(str) {
|
|
182
340
|
return str.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
183
341
|
}
|
|
184
342
|
function createTextStateConverter(state) {
|
|
185
|
-
const defaultTextConverter =
|
|
343
|
+
const defaultTextConverter = import_react4.TextJSXConverter.text;
|
|
186
344
|
return ({ node, ...rest }) => {
|
|
187
345
|
const base = defaultTextConverter({ node, ...rest });
|
|
188
346
|
const nodeState = node.$;
|
|
@@ -200,7 +358,7 @@ function createTextStateConverter(state) {
|
|
|
200
358
|
}
|
|
201
359
|
}
|
|
202
360
|
if (Object.keys(style).length === 0) return base;
|
|
203
|
-
return /* @__PURE__ */
|
|
361
|
+
return /* @__PURE__ */ import_react3.default.createElement("span", { style }, base);
|
|
204
362
|
};
|
|
205
363
|
}
|
|
206
364
|
function RichTextContent({
|
|
@@ -210,21 +368,23 @@ function RichTextContent({
|
|
|
210
368
|
converters,
|
|
211
369
|
blocks,
|
|
212
370
|
disableDefaultConverters,
|
|
371
|
+
nodeMap,
|
|
213
372
|
textState
|
|
214
373
|
}) {
|
|
215
374
|
const baseConverters = {
|
|
216
|
-
...disableDefaultConverters ? {} :
|
|
217
|
-
...(0,
|
|
375
|
+
...disableDefaultConverters ? {} : import_react4.defaultJSXConverters,
|
|
376
|
+
...(0, import_react4.LinkJSXConverter)({ internalDocToHref }),
|
|
218
377
|
...textState ? { text: createTextStateConverter(textState) } : {},
|
|
219
378
|
...converters,
|
|
220
379
|
...blocks ? { blocks } : {}
|
|
221
380
|
};
|
|
222
|
-
return /* @__PURE__ */
|
|
223
|
-
|
|
381
|
+
return /* @__PURE__ */ import_react3.default.createElement(
|
|
382
|
+
import_react4.RichText,
|
|
224
383
|
{
|
|
225
384
|
data,
|
|
226
385
|
className,
|
|
227
|
-
converters: baseConverters
|
|
386
|
+
converters: baseConverters,
|
|
387
|
+
nodeMap
|
|
228
388
|
}
|
|
229
389
|
);
|
|
230
390
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ui/RichText/index.tsx","../../src/ui/RichText/styled.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\nimport {\n SerializedBlockNode,\n SerializedLinkNode,\n} from '@payloadcms/richtext-lexical'\nimport {\n SerializedEditorState,\n SerializedLexicalNode,\n} from '@payloadcms/richtext-lexical/lexical'\nimport {\n defaultJSXConverters,\n JSXConverter,\n JSXConverters,\n LinkJSXConverter,\n RichText,\n TextJSXConverter,\n} from '@payloadcms/richtext-lexical/react'\n\n/**\n * Accepts both Lexical's strict `SerializedEditorState` and Payload's generated\n * richText type (which includes index signatures like `[k: string]: unknown`).\n */\nexport type RichTextData = SerializedEditorState<SerializedLexicalNode> | {\n root: {\n type: string\n children: { type: string; version: number; [k: string]: unknown }[]\n direction: string | null\n format: string\n indent: number\n version: number\n [k: string]: unknown\n }\n [k: string]: unknown\n}\n\nexport type TextStateConfig = {\n [stateKey: string]: {\n [stateValue: string]: {\n css: Record<string, string>\n label: string\n }\n }\n}\n\nexport interface RichTextContentProps {\n data: RichTextData\n className?: string\n internalDocToHref?: (args: { linkNode: SerializedLinkNode }) => string\n converters?: Partial<JSXConverters>\n blocks?: Record<string, JSXConverter<SerializedBlockNode>>\n disableDefaultConverters?: boolean\n textState?: TextStateConfig\n}\n\nexport { StyledRichTextContent } from './styled'\nexport type {\n RichTextComponents,\n StyledRichTextContentProps,\n HeadingSlotProps,\n ParagraphSlotProps,\n BlockquoteSlotProps,\n ListSlotProps,\n ListItemSlotProps,\n LinkSlotProps,\n HorizontalRuleSlotProps,\n UploadSlotProps,\n TableSlotProps,\n TableRowSlotProps,\n TableCellSlotProps,\n} from './styled'\n\nfunction hyphenToCamel(str: string): string {\n return str.replace(/-([a-z])/g, (_, c) => c.toUpperCase())\n}\n\nfunction createTextStateConverter(\n state: TextStateConfig,\n): JSXConverters['text'] {\n const defaultTextConverter = TextJSXConverter.text\n // eslint-disable-next-line react/display-name\n return ({ node, ...rest }) => {\n const base = (\n defaultTextConverter as (...args: unknown[]) => React.ReactNode\n )({ node, ...rest })\n const nodeState = (node as Record<string, unknown>).$ as\n | Record<string, string>\n | undefined\n if (!nodeState || typeof nodeState !== 'object') return base\n\n const style: Record<string, string> = {}\n for (const stateKey in nodeState) {\n const stateValue = nodeState[stateKey]\n if (!stateValue) continue\n const css = state[stateKey]?.[stateValue]?.css\n if (css) {\n for (const prop in css) {\n const val = css[prop]\n if (val) style[hyphenToCamel(prop)] = val\n }\n }\n }\n\n if (Object.keys(style).length === 0) return base\n return <span style={style}>{base}</span>\n }\n}\n\nexport function RichTextContent({\n data,\n className,\n internalDocToHref,\n converters,\n blocks,\n disableDefaultConverters,\n textState,\n}: RichTextContentProps) {\n const baseConverters: JSXConverters = {\n ...(disableDefaultConverters ? {} : defaultJSXConverters),\n ...LinkJSXConverter({ internalDocToHref }),\n ...(textState ? { text: createTextStateConverter(textState) } : {}),\n ...converters,\n ...(blocks ? { blocks } : {}),\n }\n\n return (\n <RichText\n data={data as SerializedEditorState<SerializedLexicalNode>}\n className={className}\n converters={baseConverters}\n />\n )\n}\n","'use client'\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport React from 'react'\nimport { SerializedLinkNode } from '@payloadcms/richtext-lexical'\nimport { JSXConverters } from '@payloadcms/richtext-lexical/react'\nimport { RichTextContent, RichTextContentProps } from './index'\n\n// --- Slot prop types (each slot gets structured data + raw node) ---\n\nexport interface HeadingSlotProps {\n tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'\n children: React.ReactNode\n node: any\n}\n\nexport interface ParagraphSlotProps {\n children: React.ReactNode\n isEmpty: boolean\n node: any\n}\n\nexport interface BlockquoteSlotProps {\n children: React.ReactNode\n node: any\n}\n\nexport interface ListSlotProps {\n tag: 'ul' | 'ol'\n listType: string\n children: React.ReactNode\n node: any\n}\n\nexport interface ListItemSlotProps {\n children: React.ReactNode\n hasSubLists: boolean\n checked?: boolean\n value?: number\n node: any\n}\n\nexport interface LinkSlotProps {\n href: string\n target?: string\n rel?: string\n children: React.ReactNode\n node: any\n}\n\nexport interface HorizontalRuleSlotProps {\n node?: any\n}\n\nexport interface UploadSlotProps {\n src: string\n alt: string\n width?: number\n height?: number\n mimeType: string\n filename: string\n sizes?: Record<string, any>\n node: any\n}\n\nexport interface TableSlotProps {\n children: React.ReactNode\n node: any\n}\n\nexport interface TableRowSlotProps {\n children: React.ReactNode\n node: any\n}\n\nexport interface TableCellSlotProps {\n tag: 'th' | 'td'\n children: React.ReactNode\n colSpan?: number\n rowSpan?: number\n backgroundColor?: string\n node: any\n}\n\n// --- Components map ---\n\nexport interface RichTextComponents {\n Heading?: React.ComponentType<HeadingSlotProps>\n Paragraph?: React.ComponentType<ParagraphSlotProps>\n Blockquote?: React.ComponentType<BlockquoteSlotProps>\n List?: React.ComponentType<ListSlotProps>\n ListItem?: React.ComponentType<ListItemSlotProps>\n Link?: React.ComponentType<LinkSlotProps>\n HorizontalRule?: React.ComponentType<HorizontalRuleSlotProps>\n Upload?: React.ComponentType<UploadSlotProps>\n Table?: React.ComponentType<TableSlotProps>\n TableRow?: React.ComponentType<TableRowSlotProps>\n TableCell?: React.ComponentType<TableCellSlotProps>\n}\n\nexport interface StyledRichTextContentProps extends Omit<\n RichTextContentProps,\n 'converters' | 'disableDefaultConverters'\n> {\n components?: RichTextComponents\n}\n\nfunction createComponentConverters(\n components: RichTextComponents,\n internalDocToHref?: (args: { linkNode: SerializedLinkNode }) => string,\n): Partial<JSXConverters> {\n const converters: Partial<JSXConverters> = {}\n\n if (components.Heading) {\n const Heading = components.Heading\n converters.heading = ({ node, nodesToJSX }) => (\n <Heading tag={node.tag} node={node}>\n {nodesToJSX({ nodes: node.children })}\n </Heading>\n )\n }\n\n if (components.Paragraph) {\n const Paragraph = components.Paragraph\n converters.paragraph = ({ node, nodesToJSX }) => {\n const children = nodesToJSX({ nodes: node.children })\n return (\n <Paragraph isEmpty={!children?.length} node={node}>\n {children?.length ? children : <br />}\n </Paragraph>\n )\n }\n }\n\n if (components.Blockquote) {\n const Blockquote = components.Blockquote\n converters.quote = ({ node, nodesToJSX }) => (\n <Blockquote node={node}>\n {nodesToJSX({ nodes: node.children })}\n </Blockquote>\n )\n }\n\n if (components.List) {\n const List = components.List\n converters.list = ({ node, nodesToJSX }) => (\n <List tag={node.tag} listType={node.listType} node={node}>\n {nodesToJSX({ nodes: node.children })}\n </List>\n )\n }\n\n if (components.ListItem) {\n const ListItem = components.ListItem\n converters.listitem = ({ node, nodesToJSX }) => {\n const hasSubLists = node.children.some(\n (child: { type: string }) => child.type === 'list',\n )\n return (\n <ListItem\n hasSubLists={hasSubLists}\n checked={node.checked}\n value={node.value}\n node={node}\n >\n {nodesToJSX({ nodes: node.children })}\n </ListItem>\n )\n }\n }\n\n if (components.Link) {\n const Link = components.Link\n\n const resolveHref = (node: any): string => {\n if (node.fields.linkType === 'internal') {\n return internalDocToHref ? internalDocToHref({ linkNode: node }) : '#'\n }\n return node.fields.url ?? ''\n }\n\n converters.link = ({ node, nodesToJSX }) => (\n <Link\n href={resolveHref(node)}\n rel={node.fields.newTab ? 'noopener noreferrer' : undefined}\n target={node.fields.newTab ? '_blank' : undefined}\n node={node}\n >\n {nodesToJSX({ nodes: node.children })}\n </Link>\n )\n\n converters.autolink = ({ node, nodesToJSX }) => (\n <Link\n href={node.fields.url ?? ''}\n rel={node.fields.newTab ? 'noopener noreferrer' : undefined}\n target={node.fields.newTab ? '_blank' : undefined}\n node={node}\n >\n {nodesToJSX({ nodes: node.children })}\n </Link>\n )\n }\n\n if (components.HorizontalRule) {\n const HorizontalRule = components.HorizontalRule\n converters.horizontalrule = <HorizontalRule />\n }\n\n if (components.Upload) {\n const Upload = components.Upload\n converters.upload = ({ node }) => {\n const uploadNode = node as any\n if (typeof uploadNode.value !== 'object') return null\n const doc = uploadNode.value\n return (\n <Upload\n src={doc.url}\n alt={uploadNode.fields?.alt || doc?.alt || ''}\n width={doc.width}\n height={doc.height}\n mimeType={doc.mimeType}\n filename={doc.filename}\n sizes={doc.sizes}\n node={node}\n />\n )\n }\n }\n\n if (components.Table) {\n const Table = components.Table\n converters.table = ({ node, nodesToJSX }) => (\n <Table node={node}>{nodesToJSX({ nodes: node.children })}</Table>\n )\n }\n\n if (components.TableRow) {\n const TableRow = components.TableRow\n converters.tablerow = ({ node, nodesToJSX }) => (\n <TableRow node={node}>{nodesToJSX({ nodes: node.children })}</TableRow>\n )\n }\n\n if (components.TableCell) {\n const TableCell = components.TableCell\n converters.tablecell = ({ node, nodesToJSX }) => (\n <TableCell\n tag={node.headerState > 0 ? 'th' : 'td'}\n colSpan={node.colSpan > 1 ? node.colSpan : undefined}\n rowSpan={node.rowSpan > 1 ? node.rowSpan : undefined}\n backgroundColor={node.backgroundColor || undefined}\n node={node}\n >\n {nodesToJSX({ nodes: node.children })}\n </TableCell>\n )\n }\n\n return converters\n}\n\nexport function StyledRichTextContent({\n components = {},\n internalDocToHref,\n blocks,\n textState,\n ...props\n}: StyledRichTextContentProps) {\n const converters = createComponentConverters(components, internalDocToHref)\n\n return (\n <RichTextContent\n {...props}\n internalDocToHref={internalDocToHref}\n converters={converters}\n blocks={blocks}\n textState={textState}\n />\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAAA,gBAAkB;AASlB,IAAAA,gBAOO;;;ACfP,mBAAkB;AAwGlB,SAAS,0BACP,YACA,mBACwB;AACxB,QAAM,aAAqC,CAAC;AAE5C,MAAI,WAAW,SAAS;AACtB,UAAM,UAAU,WAAW;AAC3B,eAAW,UAAU,CAAC,EAAE,MAAM,WAAW,MACvC,6BAAAC,QAAA,cAAC,WAAQ,KAAK,KAAK,KAAK,QACrB,WAAW,EAAE,OAAO,KAAK,SAAS,CAAC,CACtC;AAAA,EAEJ;AAEA,MAAI,WAAW,WAAW;AACxB,UAAM,YAAY,WAAW;AAC7B,eAAW,YAAY,CAAC,EAAE,MAAM,WAAW,MAAM;AAC/C,YAAM,WAAW,WAAW,EAAE,OAAO,KAAK,SAAS,CAAC;AACpD,aACE,6BAAAA,QAAA,cAAC,aAAU,SAAS,CAAC,UAAU,QAAQ,QACpC,UAAU,SAAS,WAAW,6BAAAA,QAAA,cAAC,UAAG,CACrC;AAAA,IAEJ;AAAA,EACF;AAEA,MAAI,WAAW,YAAY;AACzB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AAI,KAAK;AACP,mBAAW,QAAQ,KAAK;AACtB,gBAAM,MAAM,IAAI,IAAI;AACpB,cAAI,IAAK,OAAM,cAAc,IAAI,CAAC,IAAI;AAAA,QACxC;AAAA,MACF;AAAA,IACF;AAEA,QAAI,OAAO,KAAK,KAAK,EAAE,WAAW,EAAG,QAAO;AAC5C,WAAO,8BAAAC,QAAA,cAAC,UAAK,SAAe,IAAK;AAAA,EACnC;AACF;AAEO,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,iBAAgC;AAAA,IACpC,GAAI,2BAA2B,CAAC,IAAI;AAAA,IACpC,OAAG,gCAAiB,EAAE,kBAAkB,CAAC;AAAA,IACzC,GAAI,YAAY,EAAE,MAAM,yBAAyB,SAAS,EAAE,IAAI,CAAC;AAAA,IACjE,GAAG;AAAA,IACH,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;AAAA,EAC7B;AAEA,SACE,8BAAAA,QAAA;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,YAAY;AAAA;AAAA,EACd;AAEJ;","names":["import_react","React","React"]}
|
|
1
|
+
{"version":3,"sources":["../../src/ui/RichText/index.tsx","../../src/ui/RichText/styled.tsx","../../src/ui/RichText/views.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\nimport type {\n LexicalEditorNodeMap,\n SerializedBlockNode,\n SerializedLinkNode,\n} from '@payloadcms/richtext-lexical'\nimport type {\n SerializedEditorState,\n SerializedLexicalNode,\n} from '@payloadcms/richtext-lexical/lexical'\nimport {\n defaultJSXConverters,\n LinkJSXConverter,\n RichText,\n TextJSXConverter,\n} from '@payloadcms/richtext-lexical/react'\nimport type {\n JSXConverter,\n JSXConverters,\n} from '@payloadcms/richtext-lexical/react'\n\n/**\n * Accepts both Lexical's strict `SerializedEditorState` and Payload's generated\n * richText type (which includes index signatures like `[k: string]: unknown`).\n */\nexport type RichTextData =\n | SerializedEditorState<SerializedLexicalNode>\n | {\n root: {\n type: string\n children: { type: string; version: number; [k: string]: unknown }[]\n direction: string | null\n format: string\n indent: number\n version: number\n [k: string]: unknown\n }\n [k: string]: unknown\n }\n\nexport type TextStateConfig = {\n [stateKey: string]: {\n [stateValue: string]: {\n css: Record<string, string>\n label: string\n }\n }\n}\n\nexport interface RichTextContentProps {\n data: RichTextData\n className?: string\n internalDocToHref?: (args: { linkNode: SerializedLinkNode }) => string\n converters?: Partial<JSXConverters>\n blocks?: Record<string, JSXConverter<SerializedBlockNode>>\n disableDefaultConverters?: boolean\n nodeMap?: LexicalEditorNodeMap\n textState?: TextStateConfig\n}\n\nexport { StyledRichTextContent } from './styled'\nexport { richTextNodeMap, richTextTextState, richTextViewMap } from './views'\nexport type {\n RichTextComponents,\n StyledRichTextContentProps,\n HeadingSlotProps,\n ParagraphSlotProps,\n BlockquoteSlotProps,\n ListSlotProps,\n ListItemSlotProps,\n LinkSlotProps,\n HorizontalRuleSlotProps,\n UploadSlotProps,\n TableSlotProps,\n TableRowSlotProps,\n TableCellSlotProps,\n} from './styled'\n\nfunction hyphenToCamel(str: string): string {\n return str.replace(/-([a-z])/g, (_, c) => c.toUpperCase())\n}\n\nfunction createTextStateConverter(\n state: TextStateConfig,\n): JSXConverters['text'] {\n const defaultTextConverter = TextJSXConverter.text\n // eslint-disable-next-line react/display-name\n return ({ node, ...rest }) => {\n const base = (\n defaultTextConverter as (...args: unknown[]) => React.ReactNode\n )({ node, ...rest })\n const nodeState = (node as Record<string, unknown>).$ as\n | Record<string, string>\n | undefined\n if (!nodeState || typeof nodeState !== 'object') return base\n\n const style: Record<string, string> = {}\n for (const stateKey in nodeState) {\n const stateValue = nodeState[stateKey]\n if (!stateValue) continue\n const css = state[stateKey]?.[stateValue]?.css\n if (css) {\n for (const prop in css) {\n const val = css[prop]\n if (val) style[hyphenToCamel(prop)] = val\n }\n }\n }\n\n if (Object.keys(style).length === 0) return base\n return <span style={style}>{base}</span>\n }\n}\n\nexport function RichTextContent({\n data,\n className,\n internalDocToHref,\n converters,\n blocks,\n disableDefaultConverters,\n nodeMap,\n textState,\n}: RichTextContentProps) {\n const baseConverters: JSXConverters = {\n ...(disableDefaultConverters ? {} : defaultJSXConverters),\n ...LinkJSXConverter({ internalDocToHref }),\n ...(textState ? { text: createTextStateConverter(textState) } : {}),\n ...converters,\n ...(blocks ? { blocks } : {}),\n }\n\n return (\n <RichText\n data={data as SerializedEditorState<SerializedLexicalNode>}\n className={className}\n converters={baseConverters}\n nodeMap={nodeMap}\n />\n )\n}\n","'use client'\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport React from 'react'\nimport { SerializedLinkNode } from '@payloadcms/richtext-lexical'\nimport { JSXConverters } from '@payloadcms/richtext-lexical/react'\nimport { RichTextContent, RichTextContentProps } from './index'\n\n// --- Slot prop types (each slot gets structured data + raw node) ---\n\nexport interface HeadingSlotProps {\n tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'\n children: React.ReactNode\n node: any\n}\n\nexport interface ParagraphSlotProps {\n children: React.ReactNode\n isEmpty: boolean\n node: any\n}\n\nexport interface BlockquoteSlotProps {\n children: React.ReactNode\n node: any\n}\n\nexport interface ListSlotProps {\n tag: 'ul' | 'ol'\n listType: string\n children: React.ReactNode\n node: any\n}\n\nexport interface ListItemSlotProps {\n children: React.ReactNode\n hasSubLists: boolean\n checked?: boolean\n value?: number\n node: any\n}\n\nexport interface LinkSlotProps {\n href: string\n target?: string\n rel?: string\n children: React.ReactNode\n node: any\n}\n\nexport interface HorizontalRuleSlotProps {\n node?: any\n}\n\nexport interface UploadSlotProps {\n src: string\n alt: string\n width?: number\n height?: number\n mimeType: string\n filename: string\n sizes?: Record<string, any>\n node: any\n}\n\nexport interface TableSlotProps {\n children: React.ReactNode\n node: any\n}\n\nexport interface TableRowSlotProps {\n children: React.ReactNode\n node: any\n}\n\nexport interface TableCellSlotProps {\n tag: 'th' | 'td'\n children: React.ReactNode\n colSpan?: number\n rowSpan?: number\n backgroundColor?: string\n node: any\n}\n\n// --- Components map ---\n\nexport interface RichTextComponents {\n Heading?: React.ComponentType<HeadingSlotProps>\n Paragraph?: React.ComponentType<ParagraphSlotProps>\n Blockquote?: React.ComponentType<BlockquoteSlotProps>\n List?: React.ComponentType<ListSlotProps>\n ListItem?: React.ComponentType<ListItemSlotProps>\n Link?: React.ComponentType<LinkSlotProps>\n HorizontalRule?: React.ComponentType<HorizontalRuleSlotProps>\n Upload?: React.ComponentType<UploadSlotProps>\n Table?: React.ComponentType<TableSlotProps>\n TableRow?: React.ComponentType<TableRowSlotProps>\n TableCell?: React.ComponentType<TableCellSlotProps>\n}\n\nexport interface StyledRichTextContentProps extends Omit<\n RichTextContentProps,\n 'converters' | 'disableDefaultConverters'\n> {\n components?: RichTextComponents\n}\n\nfunction createComponentConverters(\n components: RichTextComponents,\n internalDocToHref?: (args: { linkNode: SerializedLinkNode }) => string,\n): Partial<JSXConverters> {\n const converters: Partial<JSXConverters> = {}\n\n if (components.Heading) {\n const Heading = components.Heading\n converters.heading = ({ node, nodesToJSX }) => (\n <Heading tag={node.tag} node={node}>\n {nodesToJSX({ nodes: node.children })}\n </Heading>\n )\n }\n\n if (components.Paragraph) {\n const Paragraph = components.Paragraph\n converters.paragraph = ({ node, nodesToJSX }) => {\n const children = nodesToJSX({ nodes: node.children })\n return (\n <Paragraph isEmpty={!children?.length} node={node}>\n {children?.length ? children : <br />}\n </Paragraph>\n )\n }\n }\n\n if (components.Blockquote) {\n const Blockquote = components.Blockquote\n converters.quote = ({ node, nodesToJSX }) => (\n <Blockquote node={node}>\n {nodesToJSX({ nodes: node.children })}\n </Blockquote>\n )\n }\n\n if (components.List) {\n const List = components.List\n converters.list = ({ node, nodesToJSX }) => (\n <List tag={node.tag} listType={node.listType} node={node}>\n {nodesToJSX({ nodes: node.children })}\n </List>\n )\n }\n\n if (components.ListItem) {\n const ListItem = components.ListItem\n converters.listitem = ({ node, nodesToJSX }) => {\n const hasSubLists = node.children.some(\n (child: { type: string }) => child.type === 'list',\n )\n return (\n <ListItem\n hasSubLists={hasSubLists}\n checked={node.checked}\n value={node.value}\n node={node}\n >\n {nodesToJSX({ nodes: node.children })}\n </ListItem>\n )\n }\n }\n\n if (components.Link) {\n const Link = components.Link\n\n const resolveHref = (node: any): string => {\n if (node.fields.linkType === 'internal') {\n return internalDocToHref ? internalDocToHref({ linkNode: node }) : '#'\n }\n return node.fields.url ?? ''\n }\n\n converters.link = ({ node, nodesToJSX }) => (\n <Link\n href={resolveHref(node)}\n rel={node.fields.newTab ? 'noopener noreferrer' : undefined}\n target={node.fields.newTab ? '_blank' : undefined}\n node={node}\n >\n {nodesToJSX({ nodes: node.children })}\n </Link>\n )\n\n converters.autolink = ({ node, nodesToJSX }) => (\n <Link\n href={node.fields.url ?? ''}\n rel={node.fields.newTab ? 'noopener noreferrer' : undefined}\n target={node.fields.newTab ? '_blank' : undefined}\n node={node}\n >\n {nodesToJSX({ nodes: node.children })}\n </Link>\n )\n }\n\n if (components.HorizontalRule) {\n const HorizontalRule = components.HorizontalRule\n converters.horizontalrule = <HorizontalRule />\n }\n\n if (components.Upload) {\n const Upload = components.Upload\n converters.upload = ({ node }) => {\n const uploadNode = node as any\n if (typeof uploadNode.value !== 'object') return null\n const doc = uploadNode.value\n return (\n <Upload\n src={doc.url}\n alt={uploadNode.fields?.alt || doc?.alt || ''}\n width={doc.width}\n height={doc.height}\n mimeType={doc.mimeType}\n filename={doc.filename}\n sizes={doc.sizes}\n node={node}\n />\n )\n }\n }\n\n if (components.Table) {\n const Table = components.Table\n converters.table = ({ node, nodesToJSX }) => (\n <Table node={node}>{nodesToJSX({ nodes: node.children })}</Table>\n )\n }\n\n if (components.TableRow) {\n const TableRow = components.TableRow\n converters.tablerow = ({ node, nodesToJSX }) => (\n <TableRow node={node}>{nodesToJSX({ nodes: node.children })}</TableRow>\n )\n }\n\n if (components.TableCell) {\n const TableCell = components.TableCell\n converters.tablecell = ({ node, nodesToJSX }) => (\n <TableCell\n tag={node.headerState > 0 ? 'th' : 'td'}\n colSpan={node.colSpan > 1 ? node.colSpan : undefined}\n rowSpan={node.rowSpan > 1 ? node.rowSpan : undefined}\n backgroundColor={node.backgroundColor || undefined}\n node={node}\n >\n {nodesToJSX({ nodes: node.children })}\n </TableCell>\n )\n }\n\n return converters\n}\n\nexport function StyledRichTextContent({\n components = {},\n internalDocToHref,\n blocks,\n textState,\n ...props\n}: StyledRichTextContentProps) {\n const converters = createComponentConverters(components, internalDocToHref)\n\n return (\n <RichTextContent\n {...props}\n internalDocToHref={internalDocToHref}\n converters={converters}\n blocks={blocks}\n textState={textState}\n />\n )\n}\n","'use client'\n\nimport React from 'react'\nimport type {\n LexicalEditorNodeMap,\n LexicalEditorViewMap,\n SerializedBlockNode,\n ViewMapBlockComponentProps,\n} from '@payloadcms/richtext-lexical'\nimport type { TextStateConfig } from './index'\n\ntype CodeBlockFields = {\n blockName?: null | string\n blockType: 'Code'\n code?: string | null\n language?: string | null\n}\n\ntype IframeBlockFields = {\n blockName?: null | string\n blockType: 'Iframe'\n height?: number | null\n url?: string | null\n width?: number | null\n}\n\ntype SupportedRichTextBlockNode =\n | SerializedBlockNode<CodeBlockFields>\n | SerializedBlockNode<IframeBlockFields>\n\ntype RichTextBlockProps<TFields extends CodeBlockFields | IframeBlockFields> =\n ViewMapBlockComponentProps<SerializedBlockNode<TFields>>\n\nfunction getBlockFields<TFields extends CodeBlockFields | IframeBlockFields>(\n props: RichTextBlockProps<TFields>,\n): TFields {\n return props.formData as TFields\n}\n\nfunction CodeView(props: RichTextBlockProps<CodeBlockFields>) {\n const fields = getBlockFields(props)\n const code = fields.code ?? ''\n const language = fields.language ?? 'plaintext'\n\n if (props.isEditor) {\n const { BlockCollapsible } = props.useBlockComponentContext()\n\n return (\n <BlockCollapsible className={props.className}>\n <pre style={{ margin: 0, overflow: 'auto', whiteSpace: 'pre-wrap' }}>\n <code data-language={language}>{code}</code>\n </pre>\n </BlockCollapsible>\n )\n }\n\n return (\n <pre style={{ overflow: 'auto', whiteSpace: 'pre-wrap' }}>\n <code data-language={language}>{code}</code>\n </pre>\n )\n}\n\nfunction IframeView(props: RichTextBlockProps<IframeBlockFields>) {\n const fields = getBlockFields(props)\n const url = fields.url ?? ''\n const width = fields.width ?? undefined\n const height = fields.height ?? undefined\n\n if (!url) return null\n\n if (props.isEditor) {\n const { BlockCollapsible } = props.useBlockComponentContext()\n\n return (\n <BlockCollapsible className={props.className}>\n <iframe\n src={url}\n title={fields.blockName ?? 'Embedded content'}\n width={width}\n height={height}\n style={{\n aspectRatio: width && height ? `${width} / ${height}` : '16 / 9',\n width: '100%',\n }}\n />\n </BlockCollapsible>\n )\n }\n\n return (\n <iframe\n src={url}\n title={fields.blockName ?? 'Embedded content'}\n width={width}\n height={height}\n style={{\n aspectRatio: width && height ? `${width} / ${height}` : '16 / 9',\n width: '100%',\n }}\n />\n )\n}\n\nexport const richTextTextState: TextStateConfig = {\n color: {\n 'text-red': {\n css: {\n color:\n 'light-dark(oklch(0.577 0.245 27.325), oklch(0.704 0.191 22.216))',\n },\n label: 'Red',\n },\n 'text-orange': {\n css: {\n color:\n 'light-dark(oklch(0.646 0.222 41.116), oklch(0.75 0.183 55.934))',\n },\n label: 'Orange',\n },\n 'text-yellow': {\n css: {\n color:\n 'light-dark(oklch(0.554 0.135 66.442), oklch(0.905 0.182 98.111))',\n },\n label: 'Yellow',\n },\n 'text-green': {\n css: {\n color:\n 'light-dark(oklch(0.527 0.154 150.069), oklch(0.792 0.209 151.711))',\n },\n label: 'Green',\n },\n 'text-blue': {\n css: {\n color:\n 'light-dark(oklch(0.546 0.245 262.881), oklch(0.707 0.165 254.624))',\n },\n label: 'Blue',\n },\n 'text-purple': {\n css: {\n color:\n 'light-dark(oklch(0.558 0.288 302.321), oklch(0.714 0.203 305.504))',\n },\n label: 'Purple',\n },\n 'text-pink': {\n css: {\n color:\n 'light-dark(oklch(0.592 0.249 0.584), oklch(0.718 0.202 349.761))',\n },\n label: 'Pink',\n },\n 'bg-red': {\n css: {\n 'background-color':\n 'light-dark(oklch(0.704 0.191 22.216), oklch(0.577 0.245 27.325))',\n },\n label: 'Red',\n },\n 'bg-orange': {\n css: {\n 'background-color':\n 'light-dark(oklch(0.75 0.183 55.934), oklch(0.646 0.222 41.116))',\n },\n label: 'Orange',\n },\n 'bg-yellow': {\n css: {\n 'background-color':\n 'light-dark(oklch(0.905 0.182 98.111), oklch(0.554 0.135 66.442))',\n },\n label: 'Yellow',\n },\n 'bg-green': {\n css: {\n 'background-color':\n 'light-dark(oklch(0.792 0.209 151.711), oklch(0.527 0.154 150.069))',\n },\n label: 'Green',\n },\n 'bg-blue': {\n css: {\n 'background-color':\n 'light-dark(oklch(0.707 0.165 254.624), oklch(0.546 0.245 262.881))',\n },\n label: 'Blue',\n },\n 'bg-purple': {\n css: {\n 'background-color':\n 'light-dark(oklch(0.714 0.203 305.504), oklch(0.558 0.288 302.321))',\n },\n label: 'Purple',\n },\n 'bg-pink': {\n css: {\n 'background-color':\n 'light-dark(oklch(0.718 0.202 349.761), oklch(0.592 0.249 0.584))',\n },\n label: 'Pink',\n },\n },\n}\n\nexport const richTextNodeMap: LexicalEditorNodeMap<SupportedRichTextBlockNode> =\n {\n blocks: {\n Code: {\n Block: CodeView,\n },\n Iframe: {\n Block: IframeView,\n },\n },\n }\n\nexport const richTextViewMap: LexicalEditorViewMap<SupportedRichTextBlockNode> =\n {\n default: {\n nodes: richTextNodeMap,\n },\n }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAAA,gBAAkB;AAUlB,IAAAA,gBAKO;;;ACdP,mBAAkB;AAwGlB,SAAS,0BACP,YACA,mBACwB;AACxB,QAAM,aAAqC,CAAC;AAE5C,MAAI,WAAW,SAAS;AACtB,UAAM,UAAU,WAAW;AAC3B,eAAW,UAAU,CAAC,EAAE,MA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AA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,QAAM,iBAAgC;AAAA,IACpC,GAAI,2BAA2B,CAAC,IAAI;AAAA,IACpC,OAAG,gCAAiB,EAAE,kBAAkB,CAAC;AAAA,IACzC,GAAI,YAAY,EAAE,MAAM,yBAAyB,SAAS,EAAE,IAAI,CAAC;AAAA,IACjE,GAAG;AAAA,IACH,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;AAAA,EAC7B;AAEA,SACE,8BAAAA,QAAA;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ;AAAA;AAAA,EACF;AAEJ;","names":["import_react","React","import_react","React","React"]}
|
package/dist/ui/rich-text.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { LexicalEditorNodeMap, SerializedBlockNode, LexicalEditorViewMap, SerializedLinkNode } from '@payloadcms/richtext-lexical';
|
|
3
3
|
import { SerializedEditorState, SerializedLexicalNode } from '@payloadcms/richtext-lexical/lexical';
|
|
4
4
|
import { JSXConverters, JSXConverter } from '@payloadcms/richtext-lexical/react';
|
|
5
5
|
|
|
@@ -84,6 +84,24 @@ interface StyledRichTextContentProps extends Omit<RichTextContentProps, 'convert
|
|
|
84
84
|
}
|
|
85
85
|
declare function StyledRichTextContent({ components, internalDocToHref, blocks, textState, ...props }: StyledRichTextContentProps): React.JSX.Element;
|
|
86
86
|
|
|
87
|
+
type CodeBlockFields = {
|
|
88
|
+
blockName?: null | string;
|
|
89
|
+
blockType: 'Code';
|
|
90
|
+
code?: string | null;
|
|
91
|
+
language?: string | null;
|
|
92
|
+
};
|
|
93
|
+
type IframeBlockFields = {
|
|
94
|
+
blockName?: null | string;
|
|
95
|
+
blockType: 'Iframe';
|
|
96
|
+
height?: number | null;
|
|
97
|
+
url?: string | null;
|
|
98
|
+
width?: number | null;
|
|
99
|
+
};
|
|
100
|
+
type SupportedRichTextBlockNode = SerializedBlockNode<CodeBlockFields> | SerializedBlockNode<IframeBlockFields>;
|
|
101
|
+
declare const richTextTextState: TextStateConfig;
|
|
102
|
+
declare const richTextNodeMap: LexicalEditorNodeMap<SupportedRichTextBlockNode>;
|
|
103
|
+
declare const richTextViewMap: LexicalEditorViewMap<SupportedRichTextBlockNode>;
|
|
104
|
+
|
|
87
105
|
/**
|
|
88
106
|
* Accepts both Lexical's strict `SerializedEditorState` and Payload's generated
|
|
89
107
|
* richText type (which includes index signatures like `[k: string]: unknown`).
|
|
@@ -121,9 +139,10 @@ interface RichTextContentProps {
|
|
|
121
139
|
converters?: Partial<JSXConverters>;
|
|
122
140
|
blocks?: Record<string, JSXConverter<SerializedBlockNode>>;
|
|
123
141
|
disableDefaultConverters?: boolean;
|
|
142
|
+
nodeMap?: LexicalEditorNodeMap;
|
|
124
143
|
textState?: TextStateConfig;
|
|
125
144
|
}
|
|
126
145
|
|
|
127
|
-
declare function RichTextContent({ data, className, internalDocToHref, converters, blocks, disableDefaultConverters, textState, }: RichTextContentProps): React.JSX.Element;
|
|
146
|
+
declare function RichTextContent({ data, className, internalDocToHref, converters, blocks, disableDefaultConverters, nodeMap, textState, }: RichTextContentProps): React.JSX.Element;
|
|
128
147
|
|
|
129
|
-
export { type BlockquoteSlotProps, type HeadingSlotProps, type HorizontalRuleSlotProps, type LinkSlotProps, type ListItemSlotProps, type ListSlotProps, type ParagraphSlotProps, type RichTextComponents, RichTextContent, type RichTextContentProps, type RichTextData, StyledRichTextContent, type StyledRichTextContentProps, type TableCellSlotProps, type TableRowSlotProps, type TableSlotProps, type TextStateConfig, type UploadSlotProps };
|
|
148
|
+
export { type BlockquoteSlotProps, type HeadingSlotProps, type HorizontalRuleSlotProps, type LinkSlotProps, type ListItemSlotProps, type ListSlotProps, type ParagraphSlotProps, type RichTextComponents, RichTextContent, type RichTextContentProps, type RichTextData, StyledRichTextContent, type StyledRichTextContentProps, type TableCellSlotProps, type TableRowSlotProps, type TableSlotProps, type TextStateConfig, type UploadSlotProps, richTextNodeMap, richTextTextState, richTextViewMap };
|
package/dist/ui/rich-text.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { LexicalEditorNodeMap, SerializedBlockNode, LexicalEditorViewMap, SerializedLinkNode } from '@payloadcms/richtext-lexical';
|
|
3
3
|
import { SerializedEditorState, SerializedLexicalNode } from '@payloadcms/richtext-lexical/lexical';
|
|
4
4
|
import { JSXConverters, JSXConverter } from '@payloadcms/richtext-lexical/react';
|
|
5
5
|
|
|
@@ -84,6 +84,24 @@ interface StyledRichTextContentProps extends Omit<RichTextContentProps, 'convert
|
|
|
84
84
|
}
|
|
85
85
|
declare function StyledRichTextContent({ components, internalDocToHref, blocks, textState, ...props }: StyledRichTextContentProps): React.JSX.Element;
|
|
86
86
|
|
|
87
|
+
type CodeBlockFields = {
|
|
88
|
+
blockName?: null | string;
|
|
89
|
+
blockType: 'Code';
|
|
90
|
+
code?: string | null;
|
|
91
|
+
language?: string | null;
|
|
92
|
+
};
|
|
93
|
+
type IframeBlockFields = {
|
|
94
|
+
blockName?: null | string;
|
|
95
|
+
blockType: 'Iframe';
|
|
96
|
+
height?: number | null;
|
|
97
|
+
url?: string | null;
|
|
98
|
+
width?: number | null;
|
|
99
|
+
};
|
|
100
|
+
type SupportedRichTextBlockNode = SerializedBlockNode<CodeBlockFields> | SerializedBlockNode<IframeBlockFields>;
|
|
101
|
+
declare const richTextTextState: TextStateConfig;
|
|
102
|
+
declare const richTextNodeMap: LexicalEditorNodeMap<SupportedRichTextBlockNode>;
|
|
103
|
+
declare const richTextViewMap: LexicalEditorViewMap<SupportedRichTextBlockNode>;
|
|
104
|
+
|
|
87
105
|
/**
|
|
88
106
|
* Accepts both Lexical's strict `SerializedEditorState` and Payload's generated
|
|
89
107
|
* richText type (which includes index signatures like `[k: string]: unknown`).
|
|
@@ -121,9 +139,10 @@ interface RichTextContentProps {
|
|
|
121
139
|
converters?: Partial<JSXConverters>;
|
|
122
140
|
blocks?: Record<string, JSXConverter<SerializedBlockNode>>;
|
|
123
141
|
disableDefaultConverters?: boolean;
|
|
142
|
+
nodeMap?: LexicalEditorNodeMap;
|
|
124
143
|
textState?: TextStateConfig;
|
|
125
144
|
}
|
|
126
145
|
|
|
127
|
-
declare function RichTextContent({ data, className, internalDocToHref, converters, blocks, disableDefaultConverters, textState, }: RichTextContentProps): React.JSX.Element;
|
|
146
|
+
declare function RichTextContent({ data, className, internalDocToHref, converters, blocks, disableDefaultConverters, nodeMap, textState, }: RichTextContentProps): React.JSX.Element;
|
|
128
147
|
|
|
129
|
-
export { type BlockquoteSlotProps, type HeadingSlotProps, type HorizontalRuleSlotProps, type LinkSlotProps, type ListItemSlotProps, type ListSlotProps, type ParagraphSlotProps, type RichTextComponents, RichTextContent, type RichTextContentProps, type RichTextData, StyledRichTextContent, type StyledRichTextContentProps, type TableCellSlotProps, type TableRowSlotProps, type TableSlotProps, type TextStateConfig, type UploadSlotProps };
|
|
148
|
+
export { type BlockquoteSlotProps, type HeadingSlotProps, type HorizontalRuleSlotProps, type LinkSlotProps, type ListItemSlotProps, type ListSlotProps, type ParagraphSlotProps, type RichTextComponents, RichTextContent, type RichTextContentProps, type RichTextData, StyledRichTextContent, type StyledRichTextContentProps, type TableCellSlotProps, type TableRowSlotProps, type TableSlotProps, type TextStateConfig, type UploadSlotProps, richTextNodeMap, richTextTextState, richTextViewMap };
|
package/dist/ui/rich-text.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/ui/RichText/index.tsx
|
|
4
|
-
import
|
|
4
|
+
import React3 from "react";
|
|
5
5
|
import {
|
|
6
6
|
defaultJSXConverters,
|
|
7
7
|
LinkJSXConverter,
|
|
@@ -148,6 +148,161 @@ function StyledRichTextContent({
|
|
|
148
148
|
);
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
// src/ui/RichText/views.tsx
|
|
152
|
+
import React2 from "react";
|
|
153
|
+
function getBlockFields(props) {
|
|
154
|
+
return props.formData;
|
|
155
|
+
}
|
|
156
|
+
function CodeView(props) {
|
|
157
|
+
const fields = getBlockFields(props);
|
|
158
|
+
const code = fields.code ?? "";
|
|
159
|
+
const language = fields.language ?? "plaintext";
|
|
160
|
+
if (props.isEditor) {
|
|
161
|
+
const { BlockCollapsible } = props.useBlockComponentContext();
|
|
162
|
+
return /* @__PURE__ */ React2.createElement(BlockCollapsible, { className: props.className }, /* @__PURE__ */ React2.createElement("pre", { style: { margin: 0, overflow: "auto", whiteSpace: "pre-wrap" } }, /* @__PURE__ */ React2.createElement("code", { "data-language": language }, code)));
|
|
163
|
+
}
|
|
164
|
+
return /* @__PURE__ */ React2.createElement("pre", { style: { overflow: "auto", whiteSpace: "pre-wrap" } }, /* @__PURE__ */ React2.createElement("code", { "data-language": language }, code));
|
|
165
|
+
}
|
|
166
|
+
function IframeView(props) {
|
|
167
|
+
const fields = getBlockFields(props);
|
|
168
|
+
const url = fields.url ?? "";
|
|
169
|
+
const width = fields.width ?? void 0;
|
|
170
|
+
const height = fields.height ?? void 0;
|
|
171
|
+
if (!url) return null;
|
|
172
|
+
if (props.isEditor) {
|
|
173
|
+
const { BlockCollapsible } = props.useBlockComponentContext();
|
|
174
|
+
return /* @__PURE__ */ React2.createElement(BlockCollapsible, { className: props.className }, /* @__PURE__ */ React2.createElement(
|
|
175
|
+
"iframe",
|
|
176
|
+
{
|
|
177
|
+
src: url,
|
|
178
|
+
title: fields.blockName ?? "Embedded content",
|
|
179
|
+
width,
|
|
180
|
+
height,
|
|
181
|
+
style: {
|
|
182
|
+
aspectRatio: width && height ? `${width} / ${height}` : "16 / 9",
|
|
183
|
+
width: "100%"
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
));
|
|
187
|
+
}
|
|
188
|
+
return /* @__PURE__ */ React2.createElement(
|
|
189
|
+
"iframe",
|
|
190
|
+
{
|
|
191
|
+
src: url,
|
|
192
|
+
title: fields.blockName ?? "Embedded content",
|
|
193
|
+
width,
|
|
194
|
+
height,
|
|
195
|
+
style: {
|
|
196
|
+
aspectRatio: width && height ? `${width} / ${height}` : "16 / 9",
|
|
197
|
+
width: "100%"
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
var richTextTextState = {
|
|
203
|
+
color: {
|
|
204
|
+
"text-red": {
|
|
205
|
+
css: {
|
|
206
|
+
color: "light-dark(oklch(0.577 0.245 27.325), oklch(0.704 0.191 22.216))"
|
|
207
|
+
},
|
|
208
|
+
label: "Red"
|
|
209
|
+
},
|
|
210
|
+
"text-orange": {
|
|
211
|
+
css: {
|
|
212
|
+
color: "light-dark(oklch(0.646 0.222 41.116), oklch(0.75 0.183 55.934))"
|
|
213
|
+
},
|
|
214
|
+
label: "Orange"
|
|
215
|
+
},
|
|
216
|
+
"text-yellow": {
|
|
217
|
+
css: {
|
|
218
|
+
color: "light-dark(oklch(0.554 0.135 66.442), oklch(0.905 0.182 98.111))"
|
|
219
|
+
},
|
|
220
|
+
label: "Yellow"
|
|
221
|
+
},
|
|
222
|
+
"text-green": {
|
|
223
|
+
css: {
|
|
224
|
+
color: "light-dark(oklch(0.527 0.154 150.069), oklch(0.792 0.209 151.711))"
|
|
225
|
+
},
|
|
226
|
+
label: "Green"
|
|
227
|
+
},
|
|
228
|
+
"text-blue": {
|
|
229
|
+
css: {
|
|
230
|
+
color: "light-dark(oklch(0.546 0.245 262.881), oklch(0.707 0.165 254.624))"
|
|
231
|
+
},
|
|
232
|
+
label: "Blue"
|
|
233
|
+
},
|
|
234
|
+
"text-purple": {
|
|
235
|
+
css: {
|
|
236
|
+
color: "light-dark(oklch(0.558 0.288 302.321), oklch(0.714 0.203 305.504))"
|
|
237
|
+
},
|
|
238
|
+
label: "Purple"
|
|
239
|
+
},
|
|
240
|
+
"text-pink": {
|
|
241
|
+
css: {
|
|
242
|
+
color: "light-dark(oklch(0.592 0.249 0.584), oklch(0.718 0.202 349.761))"
|
|
243
|
+
},
|
|
244
|
+
label: "Pink"
|
|
245
|
+
},
|
|
246
|
+
"bg-red": {
|
|
247
|
+
css: {
|
|
248
|
+
"background-color": "light-dark(oklch(0.704 0.191 22.216), oklch(0.577 0.245 27.325))"
|
|
249
|
+
},
|
|
250
|
+
label: "Red"
|
|
251
|
+
},
|
|
252
|
+
"bg-orange": {
|
|
253
|
+
css: {
|
|
254
|
+
"background-color": "light-dark(oklch(0.75 0.183 55.934), oklch(0.646 0.222 41.116))"
|
|
255
|
+
},
|
|
256
|
+
label: "Orange"
|
|
257
|
+
},
|
|
258
|
+
"bg-yellow": {
|
|
259
|
+
css: {
|
|
260
|
+
"background-color": "light-dark(oklch(0.905 0.182 98.111), oklch(0.554 0.135 66.442))"
|
|
261
|
+
},
|
|
262
|
+
label: "Yellow"
|
|
263
|
+
},
|
|
264
|
+
"bg-green": {
|
|
265
|
+
css: {
|
|
266
|
+
"background-color": "light-dark(oklch(0.792 0.209 151.711), oklch(0.527 0.154 150.069))"
|
|
267
|
+
},
|
|
268
|
+
label: "Green"
|
|
269
|
+
},
|
|
270
|
+
"bg-blue": {
|
|
271
|
+
css: {
|
|
272
|
+
"background-color": "light-dark(oklch(0.707 0.165 254.624), oklch(0.546 0.245 262.881))"
|
|
273
|
+
},
|
|
274
|
+
label: "Blue"
|
|
275
|
+
},
|
|
276
|
+
"bg-purple": {
|
|
277
|
+
css: {
|
|
278
|
+
"background-color": "light-dark(oklch(0.714 0.203 305.504), oklch(0.558 0.288 302.321))"
|
|
279
|
+
},
|
|
280
|
+
label: "Purple"
|
|
281
|
+
},
|
|
282
|
+
"bg-pink": {
|
|
283
|
+
css: {
|
|
284
|
+
"background-color": "light-dark(oklch(0.718 0.202 349.761), oklch(0.592 0.249 0.584))"
|
|
285
|
+
},
|
|
286
|
+
label: "Pink"
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
var richTextNodeMap = {
|
|
291
|
+
blocks: {
|
|
292
|
+
Code: {
|
|
293
|
+
Block: CodeView
|
|
294
|
+
},
|
|
295
|
+
Iframe: {
|
|
296
|
+
Block: IframeView
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
var richTextViewMap = {
|
|
301
|
+
default: {
|
|
302
|
+
nodes: richTextNodeMap
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
|
|
151
306
|
// src/ui/RichText/index.tsx
|
|
152
307
|
function hyphenToCamel(str) {
|
|
153
308
|
return str.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
@@ -171,7 +326,7 @@ function createTextStateConverter(state) {
|
|
|
171
326
|
}
|
|
172
327
|
}
|
|
173
328
|
if (Object.keys(style).length === 0) return base;
|
|
174
|
-
return /* @__PURE__ */
|
|
329
|
+
return /* @__PURE__ */ React3.createElement("span", { style }, base);
|
|
175
330
|
};
|
|
176
331
|
}
|
|
177
332
|
function RichTextContent({
|
|
@@ -181,6 +336,7 @@ function RichTextContent({
|
|
|
181
336
|
converters,
|
|
182
337
|
blocks,
|
|
183
338
|
disableDefaultConverters,
|
|
339
|
+
nodeMap,
|
|
184
340
|
textState
|
|
185
341
|
}) {
|
|
186
342
|
const baseConverters = {
|
|
@@ -190,17 +346,21 @@ function RichTextContent({
|
|
|
190
346
|
...converters,
|
|
191
347
|
...blocks ? { blocks } : {}
|
|
192
348
|
};
|
|
193
|
-
return /* @__PURE__ */
|
|
349
|
+
return /* @__PURE__ */ React3.createElement(
|
|
194
350
|
RichText,
|
|
195
351
|
{
|
|
196
352
|
data,
|
|
197
353
|
className,
|
|
198
|
-
converters: baseConverters
|
|
354
|
+
converters: baseConverters,
|
|
355
|
+
nodeMap
|
|
199
356
|
}
|
|
200
357
|
);
|
|
201
358
|
}
|
|
202
359
|
export {
|
|
203
360
|
RichTextContent,
|
|
204
|
-
StyledRichTextContent
|
|
361
|
+
StyledRichTextContent,
|
|
362
|
+
richTextNodeMap,
|
|
363
|
+
richTextTextState,
|
|
364
|
+
richTextViewMap
|
|
205
365
|
};
|
|
206
366
|
//# sourceMappingURL=rich-text.js.map
|