@webiny/lexical-converter 0.0.0-unstable.eb196ccd2f β 0.0.0-unstable.eb81deee7e
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 -101
- package/createHtmlToLexicalParser.d.ts +1 -1
- package/createHtmlToLexicalParser.js +31 -53
- package/createHtmlToLexicalParser.js.map +1 -1
- package/createLexicalStateTransformer.js +53 -57
- package/createLexicalStateTransformer.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +2 -41
- package/package.json +18 -17
- package/postProcessHtml.js +8 -16
- package/postProcessHtml.js.map +1 -1
- package/types.js +0 -7
- package/index.js.map +0 -1
- package/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,106 +1,11 @@
|
|
|
1
1
|
# @webiny/lexical-converter
|
|
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
|
-
> Webiny use the Lexical editor as primary rich text editor across the platform.
|
|
15
|
-
|
|
16
|
-
Note: This module is built to be used in the `node.js` environment.
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
To parse the HTML to lexical editor state object, you need to import `createHtmlToLexicalParser` factory function,
|
|
21
|
-
to create the parser function (with default or custom configuration) and provide the HTML content as parameter.
|
|
22
|
-
Parser will return Lexical editor state object.
|
|
23
|
-
|
|
24
|
-
> The parser uses the default configuration with the Webiny's Lexical nodes. DOM elements like headings and
|
|
25
|
-
> paragraph, for example, will be converted to our custom Webiny Lexical nodes.
|
|
26
|
-
|
|
27
|
-
```tsx
|
|
28
|
-
import { createHtmlToLexicalParser } from "@webiny/lexical-converter";
|
|
29
|
-
|
|
30
|
-
const htmlString = "<p>My paragraph</p>";
|
|
31
|
-
|
|
32
|
-
// Create a parser function.
|
|
33
|
-
const myParser = createHtmlToLexicalParser();
|
|
34
|
-
|
|
35
|
-
// Parse the HTML string to Lexical editor state object.
|
|
36
|
-
const lexicalEditorState = myParser(htmlString);
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
Here is the result in JSON format. This object structure is a valid Lexical editor state.
|
|
40
|
-
|
|
41
|
-
```json
|
|
42
|
-
{
|
|
43
|
-
"root": {
|
|
44
|
-
"children": [
|
|
45
|
-
{
|
|
46
|
-
"children": [
|
|
47
|
-
{
|
|
48
|
-
"detail": 0,
|
|
49
|
-
"format": 0,
|
|
50
|
-
"mode": "normal",
|
|
51
|
-
"style": "",
|
|
52
|
-
"text": "Space",
|
|
53
|
-
"type": "text",
|
|
54
|
-
"version": 1
|
|
55
|
-
}
|
|
56
|
-
],
|
|
57
|
-
"direction": null,
|
|
58
|
-
"format": "",
|
|
59
|
-
"indent": 0,
|
|
60
|
-
"styles": [],
|
|
61
|
-
"type": "paragraph-element",
|
|
62
|
-
"version": 1
|
|
63
|
-
}
|
|
64
|
-
],
|
|
65
|
-
"direction": null,
|
|
66
|
-
"format": "",
|
|
67
|
-
"indent": 0,
|
|
68
|
-
"type": "root",
|
|
69
|
-
"version": 1
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Configuration
|
|
75
|
-
|
|
76
|
-
To configure the parser, you can pass an optional configuration object to the parser factory.
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
import { createHtmlToLexicalParser } from "@webiny/lexical-converter";
|
|
80
|
-
import { myCustomTheme } from "./theme/myCustomTheme";
|
|
81
|
-
import { MyCustomLexicalNode } from "./lexical/nodes/MyCustomLexicalNode";
|
|
82
|
-
|
|
83
|
-
const addCustomThemeStyleToHeadings = (node: LexicalNode): LexicalNode => {
|
|
84
|
-
if (node.getType() === "heading-element") {
|
|
85
|
-
return (node as HeadingNode).setThemeStyles([{ styleId: "my-default-id", type: "typography" }]);
|
|
86
|
-
}
|
|
87
|
-
return node;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// Create your parser with custom configuration
|
|
91
|
-
const myParser = createHtmlToLexicalParser({
|
|
92
|
-
// Lexical editor configuration
|
|
93
|
-
editorConfig: {
|
|
94
|
-
// Add custom nodes for parsing
|
|
95
|
-
nodes: [MyCustomLexicalNode],
|
|
96
|
-
// Add you custom theme
|
|
97
|
-
theme: myCustomTheme
|
|
98
|
-
},
|
|
99
|
-
nodeMapper: addCustomThemeStyleToHeadings,
|
|
100
|
-
normalizeTextNodes: false // Default: true
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const lexicalEditorState = myParser(htmlString);
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
To learn more about how to create custom Lexical nodes, please visit [Lexical's documentation web page](https://lexical.dev/docs/intro).
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
|
@@ -1,55 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const selection = (0, _lexical.$getSelection)();
|
|
33
|
-
if (selection) {
|
|
34
|
-
try {
|
|
35
|
-
selection.insertNodes(lexicalNodes);
|
|
36
|
-
} catch (err) {
|
|
37
|
-
parsingError = err;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
/**
|
|
42
|
-
* Prevents this update from being batched, forcing it to run synchronously.
|
|
43
|
-
*/
|
|
44
|
-
{
|
|
45
|
-
discrete: true
|
|
46
|
-
});
|
|
47
|
-
if (parsingError) {
|
|
48
|
-
throw parsingError;
|
|
49
|
-
}
|
|
50
|
-
return editor.getEditorState().toJSON();
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
exports.createHtmlToLexicalParser = createHtmlToLexicalParser;
|
|
1
|
+
import { createHeadlessEditor } from "@lexical/headless";
|
|
2
|
+
import { $generateNodesFromDOM } from "@lexical/html";
|
|
3
|
+
import { $getRoot, $getSelection } from "lexical";
|
|
4
|
+
import { allNodes } from "@webiny/lexical-nodes";
|
|
5
|
+
const passthroughMapper = (node)=>node;
|
|
6
|
+
const createHtmlToLexicalParser = (config = {})=>(domDocument)=>{
|
|
7
|
+
const customNodeMapper = config.nodeMapper ?? passthroughMapper;
|
|
8
|
+
const editor = createHeadlessEditor({
|
|
9
|
+
...config.editorConfig,
|
|
10
|
+
nodes: [
|
|
11
|
+
...allNodes,
|
|
12
|
+
...config.editorConfig?.nodes || []
|
|
13
|
+
]
|
|
14
|
+
});
|
|
15
|
+
let parsingError;
|
|
16
|
+
editor.update(()=>{
|
|
17
|
+
const lexicalNodes = $generateNodesFromDOM(editor, domDocument).map(customNodeMapper);
|
|
18
|
+
$getRoot().select();
|
|
19
|
+
const selection = $getSelection();
|
|
20
|
+
if (selection) try {
|
|
21
|
+
selection.insertNodes(lexicalNodes);
|
|
22
|
+
} catch (err) {
|
|
23
|
+
parsingError = err;
|
|
24
|
+
}
|
|
25
|
+
}, {
|
|
26
|
+
discrete: true
|
|
27
|
+
});
|
|
28
|
+
if (parsingError) throw parsingError;
|
|
29
|
+
return editor.getEditorState().toJSON();
|
|
30
|
+
};
|
|
31
|
+
export { createHtmlToLexicalParser };
|
|
54
32
|
|
|
55
33
|
//# sourceMappingURL=createHtmlToLexicalParser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createHtmlToLexicalParser.js","sources":["../src/createHtmlToLexicalParser.ts"],"sourcesContent":["import { createHeadlessEditor } from \"@lexical/headless\";\nimport { $generateNodesFromDOM } from \"@lexical/html\";\nimport { $getRoot, $getSelection } from \"lexical\";\nimport { allNodes } from \"@webiny/lexical-nodes\";\nimport type { NodeMapper, ParserConfigurationOptions } from \"~/types.js\";\n\nconst passthroughMapper: NodeMapper = node => node;\n\n/**\n * Parse html string to lexical JSON object.\n */\nexport const createHtmlToLexicalParser = (config: ParserConfigurationOptions = {}) => {\n return (domDocument: Document): Record<string, any> | null => {\n const customNodeMapper: NodeMapper = config.nodeMapper ?? passthroughMapper;\n\n const editor = createHeadlessEditor({\n ...config.editorConfig,\n nodes: [...allNodes, ...(config.editorConfig?.nodes || [])]\n });\n\n let parsingError;\n\n editor.update(\n () => {\n // Convert to lexical node objects that can be stored in db.\n const lexicalNodes = $generateNodesFromDOM(editor, domDocument).map(\n customNodeMapper\n );\n\n // Select the root\n $getRoot().select();\n\n // Insert the nodes at a selection.\n const selection = $getSelection();\n if (selection) {\n try {\n selection.insertNodes(lexicalNodes);\n } catch (err) {\n parsingError = err;\n }\n }\n },\n /**\n * Prevents this update from being batched, forcing it to run synchronously.\n */\n { discrete: true }\n );\n\n if (parsingError) {\n throw parsingError;\n }\n\n return editor.getEditorState().toJSON();\n };\n};\n"],"names":["passthroughMapper","node","createHtmlToLexicalParser","config","domDocument","customNodeMapper","editor","createHeadlessEditor","allNodes","parsingError","lexicalNodes","$generateNodesFromDOM","$getRoot","selection","$getSelection","err"],"mappings":";;;;AAMA,MAAMA,oBAAgCC,CAAAA,OAAQA;AAKvC,MAAMC,4BAA4B,CAACC,SAAqC,CAAC,CAAC,GACtE,CAACC;QACJ,MAAMC,mBAA+BF,OAAO,UAAU,IAAIH;QAE1D,MAAMM,SAASC,qBAAqB;YAChC,GAAGJ,OAAO,YAAY;YACtB,OAAO;mBAAIK;mBAAcL,OAAO,YAAY,EAAE,SAAS,EAAE;aAAE;QAC/D;QAEA,IAAIM;QAEJH,OAAO,MAAM,CACT;YAEI,MAAMI,eAAeC,sBAAsBL,QAAQF,aAAa,GAAG,CAC/DC;YAIJO,WAAW,MAAM;YAGjB,MAAMC,YAAYC;YAClB,IAAID,WACA,IAAI;gBACAA,UAAU,WAAW,CAACH;YAC1B,EAAE,OAAOK,KAAK;gBACVN,eAAeM;YACnB;QAER,GAIA;YAAE,UAAU;QAAK;QAGrB,IAAIN,cACA,MAAMA;QAGV,OAAOH,OAAO,cAAc,GAAG,MAAM;IACzC"}
|
|
@@ -1,63 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
exports.createLexicalStateTransformer = void 0;
|
|
7
|
-
var _lexical = require("lexical");
|
|
8
|
-
var _html = require("@lexical/html");
|
|
9
|
-
var _headless = require("@lexical/headless");
|
|
10
|
-
var _lexicalNodes = require("@webiny/lexical-nodes");
|
|
11
|
-
var _postProcessHtml = require("./postProcessHtml");
|
|
1
|
+
import { $createNodeSelection, $getRoot, $isElementNode } from "lexical";
|
|
2
|
+
import { $generateHtmlFromNodes } from "@lexical/html";
|
|
3
|
+
import { createHeadlessEditor } from "@lexical/headless";
|
|
4
|
+
import { allNodes, prepareLexicalState } from "@webiny/lexical-nodes";
|
|
5
|
+
import { postProcessHtml } from "./postProcessHtml.js";
|
|
12
6
|
class LexicalStateTransformer {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
7
|
+
constructor(config = {}){
|
|
8
|
+
this.editor = createHeadlessEditor({
|
|
9
|
+
...config.editorConfig,
|
|
10
|
+
nodes: [
|
|
11
|
+
...allNodes,
|
|
12
|
+
...config.editorConfig?.nodes || []
|
|
13
|
+
]
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
flatten(state) {
|
|
17
|
+
const editorState = this.editor.parseEditorState(prepareLexicalState(state));
|
|
18
|
+
this.editor.setEditorState(editorState);
|
|
19
|
+
let flattenedNodes = [];
|
|
20
|
+
this.editor.update(()=>{
|
|
21
|
+
const children = $getRoot().getChildren();
|
|
22
|
+
flattenedNodes = children.map((childNode)=>{
|
|
23
|
+
const selection = $createNodeSelection();
|
|
24
|
+
selection.add(childNode.getKey());
|
|
25
|
+
this.getNodeDescendants(childNode).forEach((node)=>{
|
|
26
|
+
selection.add(node.getKey());
|
|
27
|
+
});
|
|
28
|
+
const html = $generateHtmlFromNodes(this.editor, selection);
|
|
29
|
+
return {
|
|
30
|
+
node: childNode,
|
|
31
|
+
html: postProcessHtml(html)
|
|
32
|
+
};
|
|
33
|
+
});
|
|
30
34
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
getNodeDescendants(node) {
|
|
51
|
-
if (!(0, _lexical.$isElementNode)(node)) {
|
|
52
|
-
return [];
|
|
35
|
+
return flattenedNodes;
|
|
36
|
+
}
|
|
37
|
+
toHtml(state) {
|
|
38
|
+
const preparedState = prepareLexicalState(state);
|
|
39
|
+
const editorState = this.editor.parseEditorState(preparedState);
|
|
40
|
+
this.editor.setEditorState(editorState);
|
|
41
|
+
let html = "";
|
|
42
|
+
this.editor.update(()=>{
|
|
43
|
+
html = $generateHtmlFromNodes(this.editor);
|
|
44
|
+
});
|
|
45
|
+
return postProcessHtml(html);
|
|
46
|
+
}
|
|
47
|
+
getNodeDescendants(node) {
|
|
48
|
+
if (!$isElementNode(node)) return [];
|
|
49
|
+
const children = node.getChildren();
|
|
50
|
+
return [
|
|
51
|
+
...children,
|
|
52
|
+
...children.map((child)=>this.getNodeDescendants(child)).flat()
|
|
53
|
+
];
|
|
53
54
|
}
|
|
54
|
-
const children = node.getChildren();
|
|
55
|
-
return [...children, ...children.map(child => this.getNodeDescendants(child)).flat()];
|
|
56
|
-
}
|
|
57
55
|
}
|
|
58
|
-
const createLexicalStateTransformer = config
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
exports.createLexicalStateTransformer = createLexicalStateTransformer;
|
|
56
|
+
const createLexicalStateTransformer = (config)=>new LexicalStateTransformer(config);
|
|
57
|
+
export { createLexicalStateTransformer };
|
|
62
58
|
|
|
63
59
|
//# sourceMappingURL=createLexicalStateTransformer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createLexicalStateTransformer.js","sources":["../src/createLexicalStateTransformer.ts"],"sourcesContent":["import type { CreateEditorArgs, LexicalEditor, SerializedEditorState, LexicalNode } from \"lexical\";\nimport { $getRoot, $createNodeSelection, $isElementNode } from \"lexical\";\nimport { $generateHtmlFromNodes } from \"@lexical/html\";\nimport { createHeadlessEditor } from \"@lexical/headless\";\nimport { allNodes, prepareLexicalState } from \"@webiny/lexical-nodes\";\nimport { postProcessHtml } from \"./postProcessHtml.js\";\n\ninterface LexicalStateTransformerConfig {\n editorConfig?: Pick<CreateEditorArgs, \"nodes\" | \"theme\">;\n}\n\nexport type FlatStateWithHTML = Array<{ node: LexicalNode; html: string }>;\n\nclass LexicalStateTransformer {\n private readonly editor: LexicalEditor;\n\n constructor(config: LexicalStateTransformerConfig = {}) {\n this.editor = createHeadlessEditor({\n ...config.editorConfig,\n nodes: [...allNodes, ...(config.editorConfig?.nodes || [])]\n });\n }\n\n public flatten(state: string | SerializedEditorState) {\n const editorState = this.editor.parseEditorState(prepareLexicalState(state));\n this.editor.setEditorState(editorState);\n\n let flattenedNodes: FlatStateWithHTML = [];\n\n this.editor.update(() => {\n const children = $getRoot().getChildren();\n\n flattenedNodes = children.map(childNode => {\n const selection = $createNodeSelection();\n selection.add(childNode.getKey());\n\n this.getNodeDescendants(childNode).forEach(node => {\n selection.add(node.getKey());\n });\n\n const html = $generateHtmlFromNodes(this.editor, selection);\n\n return {\n node: childNode,\n html: postProcessHtml(html)\n };\n });\n });\n\n return flattenedNodes;\n }\n\n public toHtml(state: string | SerializedEditorState) {\n const preparedState = prepareLexicalState(state);\n const editorState = this.editor.parseEditorState(preparedState);\n this.editor.setEditorState(editorState);\n\n let html = \"\";\n\n this.editor.update(() => {\n html = $generateHtmlFromNodes(this.editor);\n });\n\n return postProcessHtml(html);\n }\n\n private getNodeDescendants(node: LexicalNode): LexicalNode[] {\n if (!$isElementNode(node)) {\n return [];\n }\n const children = node.getChildren();\n return [...children, ...children.map(child => this.getNodeDescendants(child)).flat()];\n }\n}\n\nexport const createLexicalStateTransformer = (config?: LexicalStateTransformerConfig) => {\n return new LexicalStateTransformer(config);\n};\n"],"names":["LexicalStateTransformer","config","createHeadlessEditor","allNodes","state","editorState","prepareLexicalState","flattenedNodes","children","$getRoot","childNode","selection","$createNodeSelection","node","html","$generateHtmlFromNodes","postProcessHtml","preparedState","$isElementNode","child","createLexicalStateTransformer"],"mappings":";;;;;AAaA,MAAMA;IAGF,YAAYC,SAAwC,CAAC,CAAC,CAAE;QACpD,IAAI,CAAC,MAAM,GAAGC,qBAAqB;YAC/B,GAAGD,OAAO,YAAY;YACtB,OAAO;mBAAIE;mBAAcF,OAAO,YAAY,EAAE,SAAS,EAAE;aAAE;QAC/D;IACJ;IAEO,QAAQG,KAAqC,EAAE;QAClD,MAAMC,cAAc,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAACC,oBAAoBF;QACrE,IAAI,CAAC,MAAM,CAAC,cAAc,CAACC;QAE3B,IAAIE,iBAAoC,EAAE;QAE1C,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;YACf,MAAMC,WAAWC,WAAW,WAAW;YAEvCF,iBAAiBC,SAAS,GAAG,CAACE,CAAAA;gBAC1B,MAAMC,YAAYC;gBAClBD,UAAU,GAAG,CAACD,UAAU,MAAM;gBAE9B,IAAI,CAAC,kBAAkB,CAACA,WAAW,OAAO,CAACG,CAAAA;oBACvCF,UAAU,GAAG,CAACE,KAAK,MAAM;gBAC7B;gBAEA,MAAMC,OAAOC,uBAAuB,IAAI,CAAC,MAAM,EAAEJ;gBAEjD,OAAO;oBACH,MAAMD;oBACN,MAAMM,gBAAgBF;gBAC1B;YACJ;QACJ;QAEA,OAAOP;IACX;IAEO,OAAOH,KAAqC,EAAE;QACjD,MAAMa,gBAAgBX,oBAAoBF;QAC1C,MAAMC,cAAc,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAACY;QACjD,IAAI,CAAC,MAAM,CAAC,cAAc,CAACZ;QAE3B,IAAIS,OAAO;QAEX,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;YACfA,OAAOC,uBAAuB,IAAI,CAAC,MAAM;QAC7C;QAEA,OAAOC,gBAAgBF;IAC3B;IAEQ,mBAAmBD,IAAiB,EAAiB;QACzD,IAAI,CAACK,eAAeL,OAChB,OAAO,EAAE;QAEb,MAAML,WAAWK,KAAK,WAAW;QACjC,OAAO;eAAIL;eAAaA,SAAS,GAAG,CAACW,CAAAA,QAAS,IAAI,CAAC,kBAAkB,CAACA,QAAQ,IAAI;SAAG;IACzF;AACJ;AAEO,MAAMC,gCAAgC,CAACnB,SACnC,IAAID,wBAAwBC"}
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { SerializedEditorState } from "lexical";
|
|
2
|
-
export * from "./createHtmlToLexicalParser";
|
|
3
|
-
export * from "./createLexicalStateTransformer";
|
|
1
|
+
export type { SerializedEditorState } from "lexical";
|
|
2
|
+
export * from "./createHtmlToLexicalParser.js";
|
|
3
|
+
export * from "./createLexicalStateTransformer.js";
|
package/index.js
CHANGED
|
@@ -1,41 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
SerializedEditorState: true
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "SerializedEditorState", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function () {
|
|
12
|
-
return _lexical.SerializedEditorState;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
var _lexical = require("lexical");
|
|
16
|
-
var _createHtmlToLexicalParser = require("./createHtmlToLexicalParser");
|
|
17
|
-
Object.keys(_createHtmlToLexicalParser).forEach(function (key) {
|
|
18
|
-
if (key === "default" || key === "__esModule") return;
|
|
19
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
20
|
-
if (key in exports && exports[key] === _createHtmlToLexicalParser[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _createHtmlToLexicalParser[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _createLexicalStateTransformer = require("./createLexicalStateTransformer");
|
|
29
|
-
Object.keys(_createLexicalStateTransformer).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
32
|
-
if (key in exports && exports[key] === _createLexicalStateTransformer[key]) return;
|
|
33
|
-
Object.defineProperty(exports, key, {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: function () {
|
|
36
|
-
return _createLexicalStateTransformer[key];
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./createHtmlToLexicalParser.js";
|
|
2
|
+
export * from "./createLexicalStateTransformer.js";
|
package/package.json
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/lexical-converter",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.eb81deee7e",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./index.js",
|
|
7
|
+
"./*": "./*"
|
|
8
|
+
},
|
|
4
9
|
"dependencies": {
|
|
5
|
-
"@lexical/headless": "0.
|
|
6
|
-
"@lexical/html": "0.
|
|
7
|
-
"@webiny/lexical-nodes": "0.0.0-unstable.
|
|
8
|
-
"cheerio": "1.
|
|
9
|
-
"lexical": "0.
|
|
10
|
+
"@lexical/headless": "0.49.0",
|
|
11
|
+
"@lexical/html": "0.49.0",
|
|
12
|
+
"@webiny/lexical-nodes": "0.0.0-unstable.eb81deee7e",
|
|
13
|
+
"cheerio": "1.2.0",
|
|
14
|
+
"lexical": "0.49.0"
|
|
10
15
|
},
|
|
11
16
|
"devDependencies": {
|
|
12
|
-
"@
|
|
13
|
-
"
|
|
14
|
-
"
|
|
17
|
+
"@webiny/build-tools": "0.0.0-unstable.eb81deee7e",
|
|
18
|
+
"jsdom": "30.0.1",
|
|
19
|
+
"vitest": "4.1.11"
|
|
15
20
|
},
|
|
16
21
|
"publishConfig": {
|
|
17
|
-
"access": "public"
|
|
18
|
-
"directory": "dist"
|
|
19
|
-
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "node ../cli/bin.js run build",
|
|
22
|
-
"watch": "node ../cli/bin.js run watch"
|
|
22
|
+
"access": "public"
|
|
23
23
|
},
|
|
24
|
-
"
|
|
25
|
-
|
|
24
|
+
"webiny": {
|
|
25
|
+
"publishFrom": "dist"
|
|
26
|
+
}
|
|
26
27
|
}
|
package/postProcessHtml.js
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const postProcessHtml = html => {
|
|
9
|
-
const $ = (0, _cheerio.load)(html);
|
|
10
|
-
|
|
11
|
-
// Replace <b> elements with their text content (unwrap them)
|
|
12
|
-
$("b").each((_, el) => {
|
|
13
|
-
$(el).replaceWith($(el).html() ?? "");
|
|
14
|
-
});
|
|
15
|
-
return $("body").html() ?? html;
|
|
1
|
+
import { load } from "cheerio";
|
|
2
|
+
const postProcessHtml = (html)=>{
|
|
3
|
+
const $ = load(html);
|
|
4
|
+
$("b").each((_, el)=>{
|
|
5
|
+
$(el).replaceWith($(el).html() ?? "");
|
|
6
|
+
});
|
|
7
|
+
return $("body").html() ?? html;
|
|
16
8
|
};
|
|
17
|
-
|
|
9
|
+
export { postProcessHtml };
|
|
18
10
|
|
|
19
11
|
//# sourceMappingURL=postProcessHtml.js.map
|
package/postProcessHtml.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"postProcessHtml.js","sources":["../src/postProcessHtml.ts"],"sourcesContent":["import { load } from \"cheerio\";\n\nexport const postProcessHtml = (html: string) => {\n const $ = load(html);\n\n // Replace <b> elements with their text content (unwrap them)\n $(\"b\").each((_, el) => {\n $(el).replaceWith($(el).html() ?? \"\");\n });\n\n return $(\"body\").html() ?? html;\n};\n"],"names":["postProcessHtml","html","$","load","_","el"],"mappings":";AAEO,MAAMA,kBAAkB,CAACC;IAC5B,MAAMC,IAAIC,KAAKF;IAGfC,EAAE,KAAK,IAAI,CAAC,CAACE,GAAGC;QACZH,EAAEG,IAAI,WAAW,CAACH,EAAEG,IAAI,IAAI,MAAM;IACtC;IAEA,OAAOH,EAAE,QAAQ,IAAI,MAAMD;AAC/B"}
|
package/types.js
CHANGED
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_lexical","require","_createHtmlToLexicalParser","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_createLexicalStateTransformer"],"sources":["index.ts"],"sourcesContent":["export { SerializedEditorState } from \"lexical\";\nexport * from \"./createHtmlToLexicalParser\";\nexport * from \"./createLexicalStateTransformer\";\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,0BAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,0BAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,0BAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,0BAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,8BAAA,GAAAd,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAW,8BAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,8BAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,8BAAA,CAAAT,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
package/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { CreateEditorArgs, LexicalNode } from \"lexical\";\n\nexport type NodeMapper = (node: LexicalNode) => LexicalNode;\n\nexport interface ParserConfigurationOptions {\n editorConfig?: Pick<CreateEditorArgs, \"nodes\" | \"theme\">;\n nodeMapper?: NodeMapper;\n}\n"],"mappings":"","ignoreList":[]}
|