@lexical/headless 0.13.0 → 0.14.0
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/LexicalHeadless.dev.esm.js +29 -0
- package/LexicalHeadless.dev.js +1 -1
- package/LexicalHeadless.esm.js +10 -0
- package/LexicalHeadless.js +1 -1
- package/LexicalHeadless.prod.esm.js +7 -0
- package/README.md +3 -1
- package/index.d.ts +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { createEditor } from 'lexical';
|
|
8
|
+
|
|
9
|
+
/** @module @lexical/headless */
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Generates a headless editor that allows lexical to be used without the need for a DOM, eg in Node.js.
|
|
13
|
+
* Throws an error when unsupported methods are used.
|
|
14
|
+
* @param editorConfig - The optional lexical editor configuration.
|
|
15
|
+
* @returns - The configured headless editor.
|
|
16
|
+
*/
|
|
17
|
+
function createHeadlessEditor(editorConfig) {
|
|
18
|
+
const editor = createEditor(editorConfig);
|
|
19
|
+
editor._headless = true;
|
|
20
|
+
const unsupportedMethods = ['registerDecoratorListener', 'registerRootListener', 'registerMutationListener', 'getRootElement', 'setRootElement', 'getElementByKey', 'focus', 'blur'];
|
|
21
|
+
unsupportedMethods.forEach(method => {
|
|
22
|
+
editor[method] = () => {
|
|
23
|
+
throw new Error(`${method} is not supported in headless mode`);
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
return editor;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { createHeadlessEditor };
|
package/LexicalHeadless.dev.js
CHANGED
|
@@ -12,7 +12,7 @@ var lexical = require('lexical');
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Generates a headless editor that allows lexical to be used without the need for a DOM, eg in Node.js.
|
|
15
|
-
* Throws an error when unsupported
|
|
15
|
+
* Throws an error when unsupported methods are used.
|
|
16
16
|
* @param editorConfig - The optional lexical editor configuration.
|
|
17
17
|
* @returns - The configured headless editor.
|
|
18
18
|
*/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import * as modDev from './LexicalHeadless.dev.esm.js';
|
|
8
|
+
import * as modProd from './LexicalHeadless.prod.esm.js';
|
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
|
+
export const createHeadlessEditor = mod.createHeadlessEditor;
|
package/LexicalHeadless.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const LexicalHeadless = process.env.NODE_ENV === 'development' ? require('./LexicalHeadless.dev.js') : require('./LexicalHeadless.prod.js')
|
|
8
|
+
const LexicalHeadless = process.env.NODE_ENV === 'development' ? require('./LexicalHeadless.dev.js') : require('./LexicalHeadless.prod.js');
|
|
9
9
|
module.exports = LexicalHeadless;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import{createEditor as e}from"lexical";function t(t){const r=e(t);r._headless=!0;return["registerDecoratorListener","registerRootListener","registerMutationListener","getRootElement","setRootElement","getElementByKey","focus","blur"].forEach((e=>{r[e]=()=>{throw new Error(`${e} is not supported in headless mode`)}})),r}export{t as createHeadlessEditor};
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# `@lexical/headless`
|
|
2
2
|
|
|
3
|
+
[](https://lexical.dev/docs/api/modules/lexical_headless)
|
|
4
|
+
|
|
3
5
|
This package allows you to interact with Lexical in a headless environment (one that does not rely on DOM, e.g. for Node.js environment), and use its
|
|
4
6
|
main features like editor.update(), editor.registerNodeTransform(), editor.registerUpdateListener()
|
|
5
7
|
to create, update or traverse state.
|
|
@@ -40,7 +42,7 @@ app.get('article/:id/markdown', await (req, res) => {
|
|
|
40
42
|
});
|
|
41
43
|
|
|
42
44
|
const articleEditorStateJSON = await loadArticleBody(req.query.id);
|
|
43
|
-
editor.setEditorState(editor.parseEditorState(articleEditorStateJSON));
|
|
45
|
+
editor.setEditorState(editor.parseEditorState(articleEditorStateJSON));
|
|
44
46
|
|
|
45
47
|
editor.update(() => {
|
|
46
48
|
const markdown = $convertToMarkdownString(TRANSFORMERS);
|
package/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import type { CreateEditorArgs, LexicalEditor } from 'lexical';
|
|
10
10
|
/**
|
|
11
11
|
* Generates a headless editor that allows lexical to be used without the need for a DOM, eg in Node.js.
|
|
12
|
-
* Throws an error when unsupported
|
|
12
|
+
* Throws an error when unsupported methods are used.
|
|
13
13
|
* @param editorConfig - The optional lexical editor configuration.
|
|
14
14
|
* @returns - The configured headless editor.
|
|
15
15
|
*/
|
package/package.json
CHANGED
|
@@ -8,14 +8,16 @@
|
|
|
8
8
|
"headless"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.14.0",
|
|
12
12
|
"main": "LexicalHeadless.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.
|
|
14
|
+
"lexical": "0.14.0"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
18
|
"url": "https://github.com/facebook/lexical",
|
|
19
19
|
"directory": "packages/lexical-headless"
|
|
20
|
-
}
|
|
20
|
+
},
|
|
21
|
+
"module": "LexicalHeadless.esm.js",
|
|
22
|
+
"sideEffects": false
|
|
21
23
|
}
|