@webiny/react-rich-text-lexical-renderer 0.0.0-unstable.c7dec08bb0 β 0.0.0-unstable.df7a8bb475
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 +6 -102
- package/index.d.ts +5 -4
- package/index.js +12 -22
- package/index.js.map +1 -1
- package/package.json +19 -16
package/README.md
CHANGED
|
@@ -1,107 +1,11 @@
|
|
|
1
1
|
# @webiny/react-rich-text-lexical-renderer
|
|
2
2
|
|
|
3
|
-
[!
|
|
4
|
-
[
|
|
5
|
-
|
|
6
|
-
[](http://makeapullrequest.com)
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> Itβs **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
π **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
---
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
## Install
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
npm install --save @webiny/react-rich-text-lexical-renderer
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Or if you prefer yarn:
|
|
21
|
-
|
|
22
|
-
```
|
|
23
|
-
yarn add @webiny/react-rich-text-lexical-renderer
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Usage
|
|
27
|
-
|
|
28
|
-
Fetch your data from Headless CMS, then pass it to the component like this:
|
|
29
|
-
|
|
30
|
-
```tsx
|
|
31
|
-
import { RichTextRenderer } from "@webiny/react-rich-text-renderer";
|
|
32
|
-
|
|
33
|
-
// Load content from Headless CMS (here we show what your content might look like).
|
|
34
|
-
const content = {
|
|
35
|
-
root: {
|
|
36
|
-
children: [
|
|
37
|
-
{
|
|
38
|
-
children: [
|
|
39
|
-
{
|
|
40
|
-
detail: 0,
|
|
41
|
-
format: 0,
|
|
42
|
-
mode: "normal",
|
|
43
|
-
style: "",
|
|
44
|
-
text: "A well written paragraph of text can bring so much joy!",
|
|
45
|
-
type: "text",
|
|
46
|
-
version: 1
|
|
47
|
-
}
|
|
48
|
-
],
|
|
49
|
-
direction: "ltr",
|
|
50
|
-
styles: [],
|
|
51
|
-
format: "",
|
|
52
|
-
indent: 0,
|
|
53
|
-
tag: "p",
|
|
54
|
-
type: "paragraph-element",
|
|
55
|
-
version: 1
|
|
56
|
-
}
|
|
57
|
-
],
|
|
58
|
-
direction: "ltr",
|
|
59
|
-
format: "",
|
|
60
|
-
indent: 0,
|
|
61
|
-
type: "root",
|
|
62
|
-
version: 1
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Mount the component
|
|
67
|
-
<RichTextLexicalRenderer value={content} />;
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## Adding your custom lexical nodes for rendering
|
|
71
|
-
|
|
72
|
-
You can add custom lexical nodes for rendering your content:
|
|
73
|
-
|
|
74
|
-
```tsx
|
|
75
|
-
|
|
76
|
-
class MyCustomNode extends LexicalNode {
|
|
77
|
-
...
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Mount the component
|
|
81
|
-
<RichTextLexicalRenderer value={content} nodes={[MyCustomNode]} />;
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
## Adding your custom typography theme.
|
|
85
|
-
|
|
86
|
-
You can override Webiny default typography theme that is used by lexical editor by providing your custom typography object.
|
|
87
|
-
|
|
88
|
-
Please [ read our docs ](https://www.webiny.com/docs/page-builder/theming/theme-object) and check our [theme object on GitHub](hhttps://github.com/webiny/webiny-js/blob/v5.35.0/packages/cwp-template-aws/template/common/apps/theme/theme.ts) before add you custom theme.
|
|
89
|
-
```tsx
|
|
90
|
-
|
|
91
|
-
const myTheme = {
|
|
92
|
-
styles: {
|
|
93
|
-
typography: {
|
|
94
|
-
headings: [
|
|
95
|
-
{
|
|
96
|
-
id: "custom_heading1",
|
|
97
|
-
name: "Custom Heading 1",
|
|
98
|
-
tag: "h1",
|
|
99
|
-
styles: { ...headings, fontWeight: "bold", fontSize: 48 }
|
|
100
|
-
}]
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Mount the component
|
|
106
|
-
<RichTextLexicalRenderer value={content} theme={myTheme} nodes={[MyCustomNode]} />;
|
|
107
|
-
```
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
package/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { LexicalNode, LexicalValue
|
|
3
|
-
|
|
2
|
+
import type { Klass, LexicalNode, LexicalValue } from "@webiny/lexical-editor/types.js";
|
|
3
|
+
import type { EditorTheme } from "@webiny/lexical-theme";
|
|
4
|
+
type RendererLexicalValue = LexicalValue | Record<string, any> | null | undefined;
|
|
4
5
|
interface RichTextLexicalRenderer {
|
|
5
6
|
value: RendererLexicalValue;
|
|
6
|
-
theme
|
|
7
|
+
theme: EditorTheme;
|
|
7
8
|
nodes?: Klass<LexicalNode>[];
|
|
8
9
|
}
|
|
9
|
-
export declare const RichTextLexicalRenderer: React.
|
|
10
|
+
export declare const RichTextLexicalRenderer: (props: RichTextLexicalRenderer) => React.JSX.Element;
|
|
10
11
|
export {};
|
package/index.js
CHANGED
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.RichTextLexicalRenderer = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
var _lexicalEditor = require("@webiny/lexical-editor");
|
|
11
|
-
var _appTheme = require("@webiny/app-theme");
|
|
12
|
-
var LexicalRenderer = function LexicalRenderer(props) {
|
|
13
|
-
var _useTheme = (0, _appTheme.useTheme)(),
|
|
14
|
-
theme = _useTheme.theme;
|
|
15
|
-
var getValue = function getValue(value) {
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { LexicalHtmlRenderer } from "@webiny/lexical-editor";
|
|
3
|
+
const LexicalRenderer = props => {
|
|
4
|
+
const getValue = value => {
|
|
16
5
|
if (!value) {
|
|
17
6
|
return null;
|
|
18
7
|
}
|
|
19
|
-
return typeof
|
|
8
|
+
return typeof props?.value === "string" ? props.value : JSON.stringify(props.value);
|
|
20
9
|
};
|
|
21
|
-
return /*#__PURE__*/
|
|
22
|
-
value: getValue(props
|
|
23
|
-
theme:
|
|
10
|
+
return /*#__PURE__*/React.createElement(LexicalHtmlRenderer, {
|
|
11
|
+
value: getValue(props?.value),
|
|
12
|
+
theme: props.theme,
|
|
24
13
|
nodes: props.nodes
|
|
25
14
|
});
|
|
26
15
|
};
|
|
27
|
-
|
|
28
|
-
return /*#__PURE__*/
|
|
16
|
+
export const RichTextLexicalRenderer = props => {
|
|
17
|
+
return /*#__PURE__*/React.createElement(LexicalRenderer, props);
|
|
29
18
|
};
|
|
30
|
-
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","LexicalHtmlRenderer","LexicalRenderer","props","getValue","value","JSON","stringify","createElement","theme","nodes","RichTextLexicalRenderer"],"sources":["index.tsx"],"sourcesContent":["import React from \"react\";\nimport type { Klass, LexicalNode, LexicalValue } from \"@webiny/lexical-editor/types.js\";\nimport type { EditorTheme } from \"@webiny/lexical-theme\";\nimport { LexicalHtmlRenderer } from \"@webiny/lexical-editor\";\n\ntype RendererLexicalValue = LexicalValue | Record<string, any> | null | undefined;\n\ninterface RichTextLexicalRenderer {\n value: RendererLexicalValue;\n theme: EditorTheme;\n nodes?: Klass<LexicalNode>[];\n}\n\nconst LexicalRenderer = (props: RichTextLexicalRenderer) => {\n const getValue = (value: RendererLexicalValue): string | null => {\n if (!value) {\n return null;\n }\n return typeof props?.value === \"string\" ? props.value : JSON.stringify(props.value);\n };\n\n return (\n <LexicalHtmlRenderer\n value={getValue(props?.value)}\n theme={props.theme}\n nodes={props.nodes}\n />\n );\n};\n\nexport const RichTextLexicalRenderer = (props: RichTextLexicalRenderer) => {\n return <LexicalRenderer {...props} />;\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAGzB,SAASC,mBAAmB,QAAQ,wBAAwB;AAU5D,MAAMC,eAAe,GAAIC,KAA8B,IAAK;EACxD,MAAMC,QAAQ,GAAIC,KAA2B,IAAoB;IAC7D,IAAI,CAACA,KAAK,EAAE;MACR,OAAO,IAAI;IACf;IACA,OAAO,OAAOF,KAAK,EAAEE,KAAK,KAAK,QAAQ,GAAGF,KAAK,CAACE,KAAK,GAAGC,IAAI,CAACC,SAAS,CAACJ,KAAK,CAACE,KAAK,CAAC;EACvF,CAAC;EAED,oBACIL,KAAA,CAAAQ,aAAA,CAACP,mBAAmB;IAChBI,KAAK,EAAED,QAAQ,CAACD,KAAK,EAAEE,KAAK,CAAE;IAC9BI,KAAK,EAAEN,KAAK,CAACM,KAAM;IACnBC,KAAK,EAAEP,KAAK,CAACO;EAAM,CACtB,CAAC;AAEV,CAAC;AAED,OAAO,MAAMC,uBAAuB,GAAIR,KAA8B,IAAK;EACvE,oBAAOH,KAAA,CAAAQ,aAAA,CAACN,eAAe,EAAKC,KAAQ,CAAC;AACzC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/react-rich-text-lexical-renderer",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.df7a8bb475",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "index.js",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
@@ -9,28 +10,30 @@
|
|
|
9
10
|
"author": "Webiny Ltd",
|
|
10
11
|
"license": "MIT",
|
|
11
12
|
"dependencies": {
|
|
12
|
-
"@
|
|
13
|
-
"@
|
|
14
|
-
"@webiny/
|
|
15
|
-
"
|
|
16
|
-
"react": "17.0.2"
|
|
13
|
+
"@types/react": "18.2.79",
|
|
14
|
+
"@webiny/lexical-editor": "0.0.0-unstable.df7a8bb475",
|
|
15
|
+
"@webiny/lexical-theme": "0.0.0-unstable.df7a8bb475",
|
|
16
|
+
"react": "18.2.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
21
|
-
"@webiny/
|
|
22
|
-
"@webiny/react-composition": "0.0.0-unstable.
|
|
19
|
+
"@emotion/react": "11.10.8",
|
|
20
|
+
"@testing-library/react": "15.0.7",
|
|
21
|
+
"@webiny/build-tools": "0.0.0-unstable.df7a8bb475",
|
|
22
|
+
"@webiny/react-composition": "0.0.0-unstable.df7a8bb475",
|
|
23
23
|
"identity-obj-proxy": "3.0.0",
|
|
24
|
-
"prettier": "
|
|
25
|
-
"
|
|
24
|
+
"prettier": "3.6.2",
|
|
25
|
+
"vitest": "3.2.4"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public",
|
|
29
29
|
"directory": "dist"
|
|
30
30
|
},
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
31
|
+
"adio": {
|
|
32
|
+
"ignore": {
|
|
33
|
+
"src": [
|
|
34
|
+
"@webiny/app-theme"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
34
37
|
},
|
|
35
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "df7a8bb4755a1da047f0af8c56bdb649cc81bf7d"
|
|
36
39
|
}
|