@webiny/react-rich-text-lexical-renderer 0.0.0-unstable.06b2ede40f

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Webiny
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,170 @@
1
+ # @webiny/react-rich-text-lexical-renderer
2
+
3
+ [![](https://img.shields.io/npm/dw/@webiny/react-rich-textlexical-renderer.svg)](https://www.npmjs.com/package/@webiny/react-rich-text-lexical-renderer)
4
+ [![](https://img.shields.io/npm/v/@webiny/react-rich-text-lexical-renderer.svg)](https://www.npmjs.com/package/@webiny/react-rich-text-lexical-renderer)
5
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
6
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
7
+
8
+ A React component to render lexical editor data coming from Webiny Headless CMS and Webiny Form Builder.
9
+
10
+ ## About
11
+
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.
14
+
15
+ ## Install
16
+
17
+ ```
18
+ npm install --save @webiny/react-rich-text-lexical-renderer
19
+ ```
20
+
21
+ Or if you prefer yarn:
22
+
23
+ ```
24
+ yarn add @webiny/react-rich-text-lexical-renderer
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ Fetch your data from Headless CMS, then pass it to the component like this:
30
+
31
+ ```tsx
32
+ import {RichTextRenderer} from "@webiny/react-rich-text-renderer";
33
+
34
+ // Load content from Headless CMS (here we show what your content might look like).
35
+ const content = {
36
+ root: {
37
+ children: [
38
+ {
39
+ children: [
40
+ {
41
+ detail: 0,
42
+ format: 0,
43
+ mode: "normal",
44
+ style: "",
45
+ text: "A well written paragraph of text can bring so much joy!",
46
+ type: "text",
47
+ version: 1
48
+ }
49
+ ],
50
+ direction: "ltr",
51
+ styles: [],
52
+ format: "",
53
+ indent: 0,
54
+ tag: "p",
55
+ type: "paragraph-element",
56
+ version: 1
57
+ }
58
+ ],
59
+ direction: "ltr",
60
+ format: "",
61
+ indent: 0,
62
+ type: "root",
63
+ version: 1
64
+ }
65
+ }
66
+
67
+ // Mount the component
68
+ <RichTextLexicalRenderer value={content}/>;
69
+ ```
70
+
71
+ ## Adding your custom lexical nodes for rendering
72
+
73
+ You can add custom lexical nodes for rendering your content:
74
+
75
+ ```tsx
76
+
77
+ class MyCustomNode extends LexicalNode {
78
+ ...
79
+ }
80
+
81
+ // Mount the component
82
+ <RichTextLexicalRenderer value={content} nodes={[MyCustomNode]}/>;
83
+ ```
84
+
85
+ ## Adding your custom typography theme.
86
+
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.
93
+
94
+ ```tsx
95
+
96
+ const myTheme = {
97
+ styles: {
98
+ typography: {
99
+ headings: [
100
+ {
101
+ id: "custom_heading1",
102
+ name: "Custom Heading 1",
103
+ tag: "h1",
104
+ styles: {...headings, fontWeight: "bold", fontSize: 48}
105
+ }]
106
+ }
107
+ }
108
+ }
109
+
110
+ // Mount the component
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
+ ![React application error for mismatch of the React versions](./images/react-renderer-versisons-conflict-error.png)
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
+ }
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 ADDED
@@ -0,0 +1,11 @@
1
+ import React from "react";
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;
5
+ interface RichTextLexicalRenderer {
6
+ value: RendererLexicalValue;
7
+ theme?: Partial<EditorTheme>;
8
+ nodes?: Klass<LexicalNode>[];
9
+ }
10
+ export declare const RichTextLexicalRenderer: (props: RichTextLexicalRenderer) => React.JSX.Element;
11
+ export {};
package/index.js ADDED
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RichTextLexicalRenderer = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _appTheme = require("@webiny/app-theme");
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 => {
21
+ if (!value) {
22
+ return null;
23
+ }
24
+ return typeof props?.value === "string" ? props.value : JSON.stringify(props.value);
25
+ };
26
+ const rendererTheme = (0, _react.useMemo)(() => {
27
+ return {
28
+ ...props?.theme,
29
+ ...theme
30
+ };
31
+ }, [props?.theme, theme]);
32
+ return /*#__PURE__*/_react.default.createElement(_lexicalEditor.LexicalHtmlRenderer, {
33
+ value: getValue(props?.value),
34
+ theme: {
35
+ ...defaultTheme,
36
+ ...rendererTheme
37
+ },
38
+ nodes: props.nodes
39
+ });
40
+ };
41
+ const RichTextLexicalRenderer = props => {
42
+ return /*#__PURE__*/_react.default.createElement(_appTheme.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(LexicalRenderer, props));
43
+ };
44
+ exports.RichTextLexicalRenderer = RichTextLexicalRenderer;
45
+
46
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
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,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BAAmB;IAChBN,KAAK,EAAED,QAAQ,CAACH,KAAK,EAAEI,KAAK,CAAE;IAC9BH,KAAK,EAAE;MAAE,GAAGL,YAAY;MAAE,GAAGW;IAAc,CAAE;IAC7CI,KAAK,EAAEX,KAAK,CAACW;EAAM,CACtB,CAAC;AAEV,CAAC;AAEM,MAAMC,uBAAuB,GAAIZ,KAA8B,IAAK;EACvE,oBACI7B,MAAA,CAAAW,OAAA,CAAA2B,aAAA,CAACnC,SAAA,CAAAuC,aAAa,qBACV1C,MAAA,CAAAW,OAAA,CAAA2B,aAAA,CAACV,eAAe,EAAKC,KAAQ,CAClB,CAAC;AAExB,CAAC;AAACc,OAAA,CAAAF,uBAAA,GAAAA,uBAAA","ignoreList":[]}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@webiny/react-rich-text-lexical-renderer",
3
+ "version": "0.0.0-unstable.06b2ede40f",
4
+ "main": "index.js",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/webiny/webiny-js.git"
8
+ },
9
+ "author": "Webiny Ltd",
10
+ "license": "MIT",
11
+ "dependencies": {
12
+ "@types/react": "18.2.79",
13
+ "@webiny/app-theme": "0.0.0-unstable.06b2ede40f",
14
+ "@webiny/lexical-editor": "0.0.0-unstable.06b2ede40f",
15
+ "@webiny/lexical-theme": "0.0.0-unstable.06b2ede40f",
16
+ "react": "18.2.0"
17
+ },
18
+ "devDependencies": {
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.06b2ede40f",
23
+ "@webiny/react-composition": "0.0.0-unstable.06b2ede40f",
24
+ "identity-obj-proxy": "3.0.0",
25
+ "prettier": "2.8.8"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public",
29
+ "directory": "dist"
30
+ },
31
+ "scripts": {
32
+ "build": "node ../cli/bin.js run build",
33
+ "watch": "node ../cli/bin.js run watch"
34
+ },
35
+ "gitHead": "06b2ede40fc2212a70eeafd74afd50b56fb0ce82"
36
+ }