@webiny/react-rich-text-lexical-renderer 0.0.0-unstable.085ff6572f
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 +21 -0
- package/README.md +107 -0
- package/index.d.ts +10 -0
- package/index.js +30 -0
- package/index.js.map +1 -0
- package/package.json +36 -0
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,107 @@
|
|
|
1
|
+
# @webiny/react-rich-text-lexical-renderer
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@webiny/react-rich-text-lexical-renderer)
|
|
4
|
+
[](https://www.npmjs.com/package/@webiny/react-rich-text-lexical-renderer)
|
|
5
|
+
[](https://github.com/prettier/prettier)
|
|
6
|
+
[](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 the rendering of data for developers, we created this component.
|
|
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
|
+
```
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { LexicalNode, LexicalValue, Klass } from "@webiny/lexical-editor/types";
|
|
3
|
+
declare type RendererLexicalValue = LexicalValue | Record<string, any> | null | undefined;
|
|
4
|
+
interface RichTextLexicalRenderer {
|
|
5
|
+
value: RendererLexicalValue;
|
|
6
|
+
theme?: Record<string, any>;
|
|
7
|
+
nodes?: Klass<LexicalNode>[];
|
|
8
|
+
}
|
|
9
|
+
export declare const RichTextLexicalRenderer: React.FC<RichTextLexicalRenderer>;
|
|
10
|
+
export {};
|
package/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
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) {
|
|
16
|
+
if (!value) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return typeof (props === null || props === void 0 ? void 0 : props.value) === "string" ? props.value : JSON.stringify(props.value);
|
|
20
|
+
};
|
|
21
|
+
return /*#__PURE__*/_react.default.createElement(_lexicalEditor.LexicalHtmlRenderer, {
|
|
22
|
+
value: getValue(props === null || props === void 0 ? void 0 : props.value),
|
|
23
|
+
theme: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, props === null || props === void 0 ? void 0 : props.theme), theme),
|
|
24
|
+
nodes: props.nodes
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
var RichTextLexicalRenderer = function RichTextLexicalRenderer(props) {
|
|
28
|
+
return /*#__PURE__*/_react.default.createElement(_appTheme.ThemeProvider, null, /*#__PURE__*/_react.default.createElement(LexicalRenderer, props));
|
|
29
|
+
};
|
|
30
|
+
exports.RichTextLexicalRenderer = RichTextLexicalRenderer;
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["LexicalRenderer","props","useTheme","theme","getValue","value","JSON","stringify","nodes","RichTextLexicalRenderer"],"sources":["index.tsx"],"sourcesContent":["import React from \"react\";\nimport { LexicalNode, LexicalValue, Klass } from \"@webiny/lexical-editor/types\";\nimport { LexicalHtmlRenderer } from \"@webiny/lexical-editor\";\nimport { ThemeProvider, useTheme } from \"@webiny/app-theme\";\n\ntype RendererLexicalValue = LexicalValue | Record<string, any> | null | undefined;\n\ninterface RichTextLexicalRenderer {\n value: RendererLexicalValue;\n theme?: Record<string, any>;\n nodes?: Klass<LexicalNode>[];\n}\n\nconst LexicalRenderer: React.FC<RichTextLexicalRenderer> = props => {\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 return (\n <LexicalHtmlRenderer\n value={getValue(props?.value)}\n theme={{ ...props?.theme, ...theme }}\n nodes={props.nodes}\n />\n );\n};\n\nexport const RichTextLexicalRenderer: React.FC<RichTextLexicalRenderer> = props => {\n return (\n <ThemeProvider>\n <LexicalRenderer {...props} />\n </ThemeProvider>\n );\n};\n"],"mappings":";;;;;;;;AAAA;AAEA;AACA;AAUA,IAAMA,eAAkD,GAAG,SAArDA,eAAkD,CAAGC,KAAK,EAAI;EAChE,gBAAkB,IAAAC,kBAAQ,GAAE;IAApBC,KAAK,aAALA,KAAK;EAEb,IAAMC,QAAQ,GAAG,SAAXA,QAAQ,CAAIC,KAA2B,EAAoB;IAC7D,IAAI,CAACA,KAAK,EAAE;MACR,OAAO,IAAI;IACf;IACA,OAAO,QAAOJ,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEI,KAAK,MAAK,QAAQ,GAAGJ,KAAK,CAACI,KAAK,GAAGC,IAAI,CAACC,SAAS,CAACN,KAAK,CAACI,KAAK,CAAC;EACvF,CAAC;EAED,oBACI,6BAAC,kCAAmB;IAChB,KAAK,EAAED,QAAQ,CAACH,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEI,KAAK,CAAE;IAC9B,KAAK,8DAAOJ,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEE,KAAK,GAAKA,KAAK,CAAG;IACrC,KAAK,EAAEF,KAAK,CAACO;EAAM,EACrB;AAEV,CAAC;AAEM,IAAMC,uBAA0D,GAAG,SAA7DA,uBAA0D,CAAGR,KAAK,EAAI;EAC/E,oBACI,6BAAC,uBAAa,qBACV,6BAAC,eAAe,EAAKA,KAAK,CAAI,CAClB;AAExB,CAAC;AAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/react-rich-text-lexical-renderer",
|
|
3
|
+
"version": "0.0.0-unstable.085ff6572f",
|
|
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
|
+
"@babel/runtime": "7.20.13",
|
|
13
|
+
"@types/react": "17.0.39",
|
|
14
|
+
"@webiny/app-theme": "0.0.0-unstable.085ff6572f",
|
|
15
|
+
"@webiny/lexical-editor": "0.0.0-unstable.085ff6572f",
|
|
16
|
+
"react": "17.0.2"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@testing-library/react": "12.1.5",
|
|
20
|
+
"@webiny/cli": "0.0.0-unstable.085ff6572f",
|
|
21
|
+
"@webiny/project-utils": "0.0.0-unstable.085ff6572f",
|
|
22
|
+
"@webiny/react-composition": "0.0.0-unstable.085ff6572f",
|
|
23
|
+
"identity-obj-proxy": "3.0.0",
|
|
24
|
+
"prettier": "2.8.3",
|
|
25
|
+
"theme": "0.0.0"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"directory": "dist"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "yarn webiny run build",
|
|
33
|
+
"watch": "yarn webiny run watch"
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "085ff6572f6bb6a76d218088b06d9f4ef92bbea7"
|
|
36
|
+
}
|