@webiny/lexical-converter 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 +21 -0
- package/README.md +106 -0
- package/createHtmlToLexicalParser.d.ts +5 -0
- package/createHtmlToLexicalParser.js +55 -0
- package/createHtmlToLexicalParser.js.map +1 -0
- package/createLexicalStateTransformer.d.ts +17 -0
- package/createLexicalStateTransformer.js +63 -0
- package/createLexicalStateTransformer.js.map +1 -0
- package/index.d.ts +3 -0
- package/index.js +41 -0
- package/index.js.map +1 -0
- package/package.json +26 -0
- package/postProcessHtml.d.ts +1 -0
- package/postProcessHtml.js +19 -0
- package/postProcessHtml.js.map +1 -0
- package/types.d.ts +6 -0
- package/types.js +7 -0
- package/types.js.map +1 -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,106 @@
|
|
|
1
|
+
# @webiny/lexical-converter
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@webiny/llexical-lexical-converter)
|
|
4
|
+
[](https://www.npmjs.com/package/@webiny/lexical-converter)
|
|
5
|
+
[](https://github.com/prettier/prettier)
|
|
6
|
+
[](http://makeapullrequest.com)
|
|
7
|
+
|
|
8
|
+
## About
|
|
9
|
+
|
|
10
|
+
This package provides features that will enable you to parse your HTML pages into Lexical editor state object.
|
|
11
|
+
|
|
12
|
+
Further, this lexical state object can be imported into Webiny's apps like the Page builder and Headless CMS, trough the [Webiny's graphql API](https://www.webiny.com/docs/headless-cms/basics/graphql-api).
|
|
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).
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createHtmlToLexicalParser = void 0;
|
|
7
|
+
var _headless = require("@lexical/headless");
|
|
8
|
+
var _html = require("@lexical/html");
|
|
9
|
+
var _lexical = require("lexical");
|
|
10
|
+
var _lexicalNodes = require("@webiny/lexical-nodes");
|
|
11
|
+
const passthroughMapper = node => node;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Parse html string to lexical JSON object.
|
|
15
|
+
*/
|
|
16
|
+
const createHtmlToLexicalParser = (config = {}) => {
|
|
17
|
+
return domDocument => {
|
|
18
|
+
const customNodeMapper = config.nodeMapper ?? passthroughMapper;
|
|
19
|
+
const editor = (0, _headless.createHeadlessEditor)({
|
|
20
|
+
...config.editorConfig,
|
|
21
|
+
nodes: [..._lexicalNodes.allNodes, ...(config.editorConfig?.nodes || [])]
|
|
22
|
+
});
|
|
23
|
+
let parsingError;
|
|
24
|
+
editor.update(() => {
|
|
25
|
+
// Convert to lexical node objects that can be stored in db.
|
|
26
|
+
const lexicalNodes = (0, _html.$generateNodesFromDOM)(editor, domDocument).map(customNodeMapper);
|
|
27
|
+
|
|
28
|
+
// Select the root
|
|
29
|
+
(0, _lexical.$getRoot)().select();
|
|
30
|
+
|
|
31
|
+
// Insert the nodes at a selection.
|
|
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;
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=createHtmlToLexicalParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_headless","require","_html","_lexical","_lexicalNodes","passthroughMapper","node","createHtmlToLexicalParser","config","domDocument","customNodeMapper","nodeMapper","editor","createHeadlessEditor","editorConfig","nodes","allNodes","parsingError","update","lexicalNodes","$generateNodesFromDOM","map","$getRoot","select","selection","$getSelection","insertNodes","err","discrete","getEditorState","toJSON","exports"],"sources":["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\";\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"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AAGA,MAAMI,iBAA6B,GAAGC,IAAI,IAAIA,IAAI;;AAElD;AACA;AACA;AACO,MAAMC,yBAAyB,GAAGA,CAACC,MAAkC,GAAG,CAAC,CAAC,KAAK;EAClF,OAAQC,WAAqB,IAAiC;IAC1D,MAAMC,gBAA4B,GAAGF,MAAM,CAACG,UAAU,IAAIN,iBAAiB;IAE3E,MAAMO,MAAM,GAAG,IAAAC,8BAAoB,EAAC;MAChC,GAAGL,MAAM,CAACM,YAAY;MACtBC,KAAK,EAAE,CAAC,GAAGC,sBAAQ,EAAE,IAAIR,MAAM,CAACM,YAAY,EAAEC,KAAK,IAAI,EAAE,CAAC;IAC9D,CAAC,CAAC;IAEF,IAAIE,YAAY;IAEhBL,MAAM,CAACM,MAAM,CACT,MAAM;MACF;MACA,MAAMC,YAAY,GAAG,IAAAC,2BAAqB,EAACR,MAAM,EAAEH,WAAW,CAAC,CAACY,GAAG,CAC/DX,gBACJ,CAAC;;MAED;MACA,IAAAY,iBAAQ,EAAC,CAAC,CAACC,MAAM,CAAC,CAAC;;MAEnB;MACA,MAAMC,SAAS,GAAG,IAAAC,sBAAa,EAAC,CAAC;MACjC,IAAID,SAAS,EAAE;QACX,IAAI;UACAA,SAAS,CAACE,WAAW,CAACP,YAAY,CAAC;QACvC,CAAC,CAAC,OAAOQ,GAAG,EAAE;UACVV,YAAY,GAAGU,GAAG;QACtB;MACJ;IACJ,CAAC;IACD;AACZ;AACA;IACY;MAAEC,QAAQ,EAAE;IAAK,CACrB,CAAC;IAED,IAAIX,YAAY,EAAE;MACd,MAAMA,YAAY;IACtB;IAEA,OAAOL,MAAM,CAACiB,cAAc,CAAC,CAAC,CAACC,MAAM,CAAC,CAAC;EAC3C,CAAC;AACL,CAAC;AAACC,OAAA,CAAAxB,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CreateEditorArgs, SerializedEditorState, LexicalNode } from "lexical";
|
|
2
|
+
interface LexicalStateTransformerConfig {
|
|
3
|
+
editorConfig?: Pick<CreateEditorArgs, "nodes" | "theme">;
|
|
4
|
+
}
|
|
5
|
+
export type FlatStateWithHTML = Array<{
|
|
6
|
+
node: LexicalNode;
|
|
7
|
+
html: string;
|
|
8
|
+
}>;
|
|
9
|
+
declare class LexicalStateTransformer {
|
|
10
|
+
private readonly editor;
|
|
11
|
+
constructor(config?: LexicalStateTransformerConfig);
|
|
12
|
+
flatten(state: string | SerializedEditorState): FlatStateWithHTML;
|
|
13
|
+
toHtml(state: string | SerializedEditorState): string;
|
|
14
|
+
private getNodeDescendants;
|
|
15
|
+
}
|
|
16
|
+
export declare const createLexicalStateTransformer: (config?: LexicalStateTransformerConfig) => LexicalStateTransformer;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
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");
|
|
12
|
+
class LexicalStateTransformer {
|
|
13
|
+
constructor(config = {}) {
|
|
14
|
+
this.editor = (0, _headless.createHeadlessEditor)({
|
|
15
|
+
...config.editorConfig,
|
|
16
|
+
nodes: [..._lexicalNodes.allNodes, ...(config.editorConfig?.nodes || [])]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
flatten(state) {
|
|
20
|
+
const editorState = this.editor.parseEditorState((0, _lexicalNodes.prepareLexicalState)(state));
|
|
21
|
+
this.editor.setEditorState(editorState);
|
|
22
|
+
let flattenedNodes = [];
|
|
23
|
+
this.editor.update(() => {
|
|
24
|
+
const children = (0, _lexical.$getRoot)().getChildren();
|
|
25
|
+
flattenedNodes = children.map(childNode => {
|
|
26
|
+
const selection = (0, _lexical.$createNodeSelection)();
|
|
27
|
+
selection.add(childNode.getKey());
|
|
28
|
+
this.getNodeDescendants(childNode).forEach(node => {
|
|
29
|
+
selection.add(node.getKey());
|
|
30
|
+
});
|
|
31
|
+
const html = (0, _html.$generateHtmlFromNodes)(this.editor, selection);
|
|
32
|
+
return {
|
|
33
|
+
node: childNode,
|
|
34
|
+
html: (0, _postProcessHtml.postProcessHtml)(html)
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
return flattenedNodes;
|
|
39
|
+
}
|
|
40
|
+
toHtml(state) {
|
|
41
|
+
const preparedState = (0, _lexicalNodes.prepareLexicalState)(state);
|
|
42
|
+
const editorState = this.editor.parseEditorState(preparedState);
|
|
43
|
+
this.editor.setEditorState(editorState);
|
|
44
|
+
let html = "";
|
|
45
|
+
this.editor.update(() => {
|
|
46
|
+
html = (0, _html.$generateHtmlFromNodes)(this.editor);
|
|
47
|
+
});
|
|
48
|
+
return (0, _postProcessHtml.postProcessHtml)(html);
|
|
49
|
+
}
|
|
50
|
+
getNodeDescendants(node) {
|
|
51
|
+
if (!(0, _lexical.$isElementNode)(node)) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
const children = node.getChildren();
|
|
55
|
+
return [...children, ...children.map(child => this.getNodeDescendants(child)).flat()];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const createLexicalStateTransformer = config => {
|
|
59
|
+
return new LexicalStateTransformer(config);
|
|
60
|
+
};
|
|
61
|
+
exports.createLexicalStateTransformer = createLexicalStateTransformer;
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=createLexicalStateTransformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_lexical","require","_html","_headless","_lexicalNodes","_postProcessHtml","LexicalStateTransformer","constructor","config","editor","createHeadlessEditor","editorConfig","nodes","allNodes","flatten","state","editorState","parseEditorState","prepareLexicalState","setEditorState","flattenedNodes","update","children","$getRoot","getChildren","map","childNode","selection","$createNodeSelection","add","getKey","getNodeDescendants","forEach","node","html","$generateHtmlFromNodes","postProcessHtml","toHtml","preparedState","$isElementNode","child","flat","createLexicalStateTransformer","exports"],"sources":["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\";\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"],"mappings":"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","ignoreList":[]}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/lexical-converter",
|
|
3
|
+
"version": "0.0.0-unstable.06b2ede40f",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@lexical/headless": "0.23.1",
|
|
6
|
+
"@lexical/html": "0.23.1",
|
|
7
|
+
"@webiny/lexical-nodes": "0.0.0-unstable.06b2ede40f",
|
|
8
|
+
"cheerio": "1.1.2",
|
|
9
|
+
"lexical": "0.23.1"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@types/jsdom": "^21.1.6",
|
|
13
|
+
"@webiny/project-utils": "0.0.0-unstable.06b2ede40f",
|
|
14
|
+
"jsdom": "25.0.1"
|
|
15
|
+
},
|
|
16
|
+
"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"
|
|
23
|
+
},
|
|
24
|
+
"test": "jest --verbose --runInBand --detectOpenHandles --forceExit",
|
|
25
|
+
"gitHead": "06b2ede40fc2212a70eeafd74afd50b56fb0ce82"
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const postProcessHtml: (html: string) => string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.postProcessHtml = void 0;
|
|
7
|
+
var _cheerio = require("cheerio");
|
|
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;
|
|
16
|
+
};
|
|
17
|
+
exports.postProcessHtml = postProcessHtml;
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=postProcessHtml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_cheerio","require","postProcessHtml","html","$","load","each","_","el","replaceWith","exports"],"sources":["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"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEO,MAAMC,eAAe,GAAIC,IAAY,IAAK;EAC7C,MAAMC,CAAC,GAAG,IAAAC,aAAI,EAACF,IAAI,CAAC;;EAEpB;EACAC,CAAC,CAAC,GAAG,CAAC,CAACE,IAAI,CAAC,CAACC,CAAC,EAAEC,EAAE,KAAK;IACnBJ,CAAC,CAACI,EAAE,CAAC,CAACC,WAAW,CAACL,CAAC,CAACI,EAAE,CAAC,CAACL,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;EACzC,CAAC,CAAC;EAEF,OAAOC,CAAC,CAAC,MAAM,CAAC,CAACD,IAAI,CAAC,CAAC,IAAIA,IAAI;AACnC,CAAC;AAACO,OAAA,CAAAR,eAAA,GAAAA,eAAA","ignoreList":[]}
|
package/types.d.ts
ADDED
package/types.js
ADDED
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|