@webiny/react-rich-text-lexical-renderer 0.0.0-unstable.c7dec08bb0 → 0.0.0-unstable.e53eceafb5
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 +77 -14
- package/index.d.ts +5 -4
- package/index.js +29 -13
- package/index.js.map +1 -1
- package/package.json +15 -15
package/README.md
CHANGED
|
@@ -9,7 +9,8 @@ A React component to render lexical editor data coming from Webiny Headless CMS
|
|
|
9
9
|
|
|
10
10
|
## About
|
|
11
11
|
|
|
12
|
-
Webiny uses Lexical editor https://lexical.dev/ as a go to Rich Text Editor, with some additional plugins. To speed up
|
|
12
|
+
Webiny uses Lexical editor https://lexical.dev/ as a go to Rich Text Editor, with some additional plugins. To speed up
|
|
13
|
+
the rendering of data for developers, we created this component.
|
|
13
14
|
|
|
14
15
|
## Install
|
|
15
16
|
|
|
@@ -28,7 +29,7 @@ yarn add @webiny/react-rich-text-lexical-renderer
|
|
|
28
29
|
Fetch your data from Headless CMS, then pass it to the component like this:
|
|
29
30
|
|
|
30
31
|
```tsx
|
|
31
|
-
import {
|
|
32
|
+
import {RichTextRenderer} from "@webiny/react-rich-text-renderer";
|
|
32
33
|
|
|
33
34
|
// Load content from Headless CMS (here we show what your content might look like).
|
|
34
35
|
const content = {
|
|
@@ -55,16 +56,16 @@ const content = {
|
|
|
55
56
|
version: 1
|
|
56
57
|
}
|
|
57
58
|
],
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
direction: "ltr",
|
|
60
|
+
format: "",
|
|
61
|
+
indent: 0,
|
|
62
|
+
type: "root",
|
|
63
|
+
version: 1
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
// Mount the component
|
|
67
|
-
<RichTextLexicalRenderer value={content}
|
|
68
|
+
<RichTextLexicalRenderer value={content}/>;
|
|
68
69
|
```
|
|
69
70
|
|
|
70
71
|
## Adding your custom lexical nodes for rendering
|
|
@@ -74,18 +75,22 @@ You can add custom lexical nodes for rendering your content:
|
|
|
74
75
|
```tsx
|
|
75
76
|
|
|
76
77
|
class MyCustomNode extends LexicalNode {
|
|
77
|
-
|
|
78
|
+
...
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
// Mount the component
|
|
81
|
-
<RichTextLexicalRenderer value={content} nodes={[MyCustomNode]}
|
|
82
|
+
<RichTextLexicalRenderer value={content} nodes={[MyCustomNode]}/>;
|
|
82
83
|
```
|
|
83
84
|
|
|
84
85
|
## Adding your custom typography theme.
|
|
85
86
|
|
|
86
|
-
You can override Webiny default typography theme that is used by lexical editor by providing your custom typography
|
|
87
|
+
You can override Webiny default typography theme that is used by lexical editor by providing your custom typography
|
|
88
|
+
object.
|
|
89
|
+
|
|
90
|
+
Please [ read our docs ](https://www.webiny.com/docs/page-builder/theming/theme-object) and check
|
|
91
|
+
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)
|
|
92
|
+
before add you custom theme.
|
|
87
93
|
|
|
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
94
|
```tsx
|
|
90
95
|
|
|
91
96
|
const myTheme = {
|
|
@@ -96,12 +101,70 @@ const myTheme = {
|
|
|
96
101
|
id: "custom_heading1",
|
|
97
102
|
name: "Custom Heading 1",
|
|
98
103
|
tag: "h1",
|
|
99
|
-
styles: {
|
|
104
|
+
styles: {...headings, fontWeight: "bold", fontSize: 48}
|
|
100
105
|
}]
|
|
101
106
|
}
|
|
102
107
|
}
|
|
103
108
|
}
|
|
104
109
|
|
|
105
110
|
// Mount the component
|
|
106
|
-
<RichTextLexicalRenderer value={content}
|
|
111
|
+
<RichTextLexicalRenderer value={content} theme={myTheme} nodes={[MyCustomNode]}/>;
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Resolve the mismatch of the versions in the React v18 application
|
|
115
|
+
|
|
116
|
+
When you try to use `RichTextLexicalRenderer` component in React `v18` application you will see this error on the
|
|
117
|
+
screen:
|
|
118
|
+
|
|
119
|
+

|
|
120
|
+
|
|
121
|
+
This is because our `@webiny/react-rich-text-lexical-renderer` package and the React application have
|
|
122
|
+
different versions of React. Our rich text renderer component is using `v17.0.2`, and the React application is
|
|
123
|
+
using `v18.x.x`.
|
|
124
|
+
|
|
125
|
+
> You can check which React versions are requested by various dependencies by running the following command:
|
|
126
|
+
> - `yarn why react` for `yarn` users.
|
|
127
|
+
> - `npm ls react` for `npm` users.
|
|
128
|
+
|
|
129
|
+
To resolve this problem, we need to force all dependencies to use the same version of React.
|
|
130
|
+
|
|
131
|
+
### Instructions for `yarn` users
|
|
132
|
+
|
|
133
|
+
To force `yarn` to resolve dependencies across the project to the exact versions we're looking for, use
|
|
134
|
+
the `resolutions` field in the root `package.json` file.
|
|
135
|
+
|
|
136
|
+
```json package.json
|
|
137
|
+
{
|
|
138
|
+
...
|
|
139
|
+
"resolutions": {
|
|
140
|
+
"react": "18.x.x"
|
|
141
|
+
},
|
|
142
|
+
...
|
|
143
|
+
}
|
|
107
144
|
```
|
|
145
|
+
|
|
146
|
+
Once the `resolutions` field is defined, run `yarn` to apply the new config.
|
|
147
|
+
|
|
148
|
+
To learn more about the `resolutions` field, please check
|
|
149
|
+
this [yarn documentation article](https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/).
|
|
150
|
+
|
|
151
|
+
### Instructions for `npm` users
|
|
152
|
+
|
|
153
|
+
The `npm` supports the same functionality as `yarn` with the `overrides` field name. You need to add `overrides`
|
|
154
|
+
field in `package.json` file.
|
|
155
|
+
|
|
156
|
+
```json package.json
|
|
157
|
+
{
|
|
158
|
+
...
|
|
159
|
+
"overrides": {
|
|
160
|
+
"react": "^18.x.x"
|
|
161
|
+
},
|
|
162
|
+
...
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Once the `overrides` field is defined, run `npm install` to apply the new config.
|
|
167
|
+
|
|
168
|
+
To learn more about the `overrides` field, please check
|
|
169
|
+
this [npm documentation article](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides).
|
|
170
|
+
|
package/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { LexicalNode, LexicalValue, Klass } from "@webiny/lexical-editor/types";
|
|
3
|
-
|
|
2
|
+
import type { LexicalNode, LexicalValue, Klass } from "@webiny/lexical-editor/types";
|
|
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?: Partial<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,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.RichTextLexicalRenderer = void 0;
|
|
8
|
-
var
|
|
9
|
-
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
var _lexicalEditor = require("@webiny/lexical-editor");
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
8
|
var _appTheme = require("@webiny/app-theme");
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
var _lexicalEditor = require("@webiny/lexical-editor");
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
const defaultTheme = {
|
|
13
|
+
styles: {},
|
|
14
|
+
emotionMap: {}
|
|
15
|
+
};
|
|
16
|
+
const LexicalRenderer = props => {
|
|
17
|
+
const {
|
|
18
|
+
theme
|
|
19
|
+
} = (0, _appTheme.useTheme)();
|
|
20
|
+
const getValue = value => {
|
|
16
21
|
if (!value) {
|
|
17
22
|
return null;
|
|
18
23
|
}
|
|
19
|
-
return typeof
|
|
24
|
+
return typeof props?.value === "string" ? props.value : JSON.stringify(props.value);
|
|
20
25
|
};
|
|
26
|
+
const rendererTheme = (0, _react.useMemo)(() => {
|
|
27
|
+
return {
|
|
28
|
+
...props?.theme,
|
|
29
|
+
...theme
|
|
30
|
+
};
|
|
31
|
+
}, [props?.theme, theme]);
|
|
21
32
|
return /*#__PURE__*/_react.default.createElement(_lexicalEditor.LexicalHtmlRenderer, {
|
|
22
|
-
value: getValue(props
|
|
23
|
-
theme:
|
|
33
|
+
value: getValue(props?.value),
|
|
34
|
+
theme: {
|
|
35
|
+
...defaultTheme,
|
|
36
|
+
...rendererTheme
|
|
37
|
+
},
|
|
24
38
|
nodes: props.nodes
|
|
25
39
|
});
|
|
26
40
|
};
|
|
27
|
-
|
|
41
|
+
const RichTextLexicalRenderer = props => {
|
|
28
42
|
return /*#__PURE__*/_react.default.createElement(_appTheme.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(LexicalRenderer, props));
|
|
29
43
|
};
|
|
30
|
-
exports.RichTextLexicalRenderer = RichTextLexicalRenderer;
|
|
44
|
+
exports.RichTextLexicalRenderer = RichTextLexicalRenderer;
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["LexicalRenderer","props","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_appTheme","_lexicalEditor","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","defaultTheme","styles","emotionMap","LexicalRenderer","props","theme","useTheme","getValue","value","JSON","stringify","rendererTheme","useMemo","createElement","LexicalHtmlRenderer","nodes","RichTextLexicalRenderer","ThemeProvider","exports"],"sources":["index.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { ThemeProvider, useTheme } from \"@webiny/app-theme\";\nimport type { LexicalNode, LexicalValue, Klass } from \"@webiny/lexical-editor/types\";\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?: Partial<EditorTheme>;\n nodes?: Klass<LexicalNode>[];\n}\n\nconst defaultTheme: EditorTheme = {\n styles: {},\n emotionMap: {}\n};\n\nconst LexicalRenderer = (props: RichTextLexicalRenderer) => {\n const { theme } = useTheme();\n\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 const rendererTheme = useMemo(() => {\n return { ...props?.theme, ...theme };\n }, [props?.theme, theme]);\n\n return (\n <LexicalHtmlRenderer\n value={getValue(props?.value)}\n theme={{ ...defaultTheme, ...rendererTheme }}\n nodes={props.nodes}\n />\n );\n};\n\nexport const RichTextLexicalRenderer = (props: RichTextLexicalRenderer) => {\n return (\n <ThemeProvider>\n <LexicalRenderer {...props} />\n </ThemeProvider>\n );\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAGA,IAAAE,cAAA,GAAAF,OAAA;AAA6D,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAA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CAAA2B,aAAA,CAACV,eAAe,EAAKC,KAAQ,CAClB,CAAC;AAExB,CAAC;AAACc,OAAA,CAAAF,uBAAA,GAAAA,uBAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/react-rich-text-lexical-renderer",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.e53eceafb5",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,28 +9,28 @@
|
|
|
9
9
|
"author": "Webiny Ltd",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@
|
|
13
|
-
"@
|
|
14
|
-
"@webiny/
|
|
15
|
-
"@webiny/lexical-
|
|
16
|
-
"react": "
|
|
12
|
+
"@types/react": "18.2.79",
|
|
13
|
+
"@webiny/app-theme": "0.0.0-unstable.e53eceafb5",
|
|
14
|
+
"@webiny/lexical-editor": "0.0.0-unstable.e53eceafb5",
|
|
15
|
+
"@webiny/lexical-theme": "0.0.0-unstable.e53eceafb5",
|
|
16
|
+
"react": "18.2.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
21
|
-
"@webiny/
|
|
22
|
-
"@webiny/
|
|
19
|
+
"@emotion/react": "11.10.8",
|
|
20
|
+
"@testing-library/react": "15.0.7",
|
|
21
|
+
"@webiny/app-theme": "0.0.0",
|
|
22
|
+
"@webiny/project-utils": "0.0.0-unstable.e53eceafb5",
|
|
23
|
+
"@webiny/react-composition": "0.0.0-unstable.e53eceafb5",
|
|
23
24
|
"identity-obj-proxy": "3.0.0",
|
|
24
|
-
"prettier": "2.8.
|
|
25
|
-
"theme": "0.0.0"
|
|
25
|
+
"prettier": "2.8.8"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public",
|
|
29
29
|
"directory": "dist"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "
|
|
33
|
-
"watch": "
|
|
32
|
+
"build": "node ../cli/bin.js run build",
|
|
33
|
+
"watch": "node ../cli/bin.js run watch"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "e53eceafb5ce1a3872c9b4548939bb2eae5b1aef"
|
|
36
36
|
}
|