Comments (1)
I found it was solved, here is the #1262
Here is the summarized solution provided below:
Here is the example
- Define a class CustomParagraphNode
- Notice here must be a new type
- Notice here must inherit the class you want to replace such as ParagraphNode
import { ParagraphNode } from "lexical";
export class CustomParagraphNode extends ParagraphNode {
static getType() {
return "custom-paragraph";
}
static clone(node) {
return new CustomParagraphNode(node.__key);
}
createDOM(config) {
const dom = super.createDOM(config);
dom.style = "background: green";
return dom;
}
}
- In Editor.js, do not register the node which define in lexical such as ParagraphNode, the only thing you do is register new one such as CustomParagraphNode, and so on add a function help lexical to replace ParagraphNode to your CustomParagraphNode.
CustomParagraphNode,
{
replace: ParagraphNode,
with: (node) => {
return new CustomParagraphNode();
}
}
- At last, if you want to write a class which can be customized by external, such as ParagraphNode, you just add a function $applyNodeReplacement
export function $createParagraphNode(): ParagraphNode {
return $applyNodeReplacement(new ParagraphNode());
}
Here is the official example
from lexical.
Related Issues (20)
- Bug: API modules list HOT 1
- Docs: Generate docusaurus sidebars from filesystem
- Bug: private module 'shared' is referenced in shipped type declarations HOT 1
- Feature: Use api-extractor when generating the .d.ts files for distribution HOT 4
- Feature: escape key handler for plain text plugin
- TODO: Add a test for mouse leaving browser window during table selection HOT 1
- Proposal: DecoratorElementNode HOT 10
- Bug: (Firefox) Caret disappears after dragging a block HOT 2
- Bug: Unable to find an active editor state. State helpers or node methods can only be used synchronously during the callback of editor.update() or editorState.read(). HOT 3
- Refactor: Move AutoCompleteNode styling to theme.
- Docs: add release management process to the maintainers guide
- Consider DecoratorNode in $insertNodeToNearestRoot
- Bug: LexicalClipboard pasting over mention crashes Chrome HOT 2
- How to keep styles between lines? HOT 2
- Feature: Lexical collaboration editor doesnt clear cache
- Bug: Inserting a paragraph after a table within a custom ElementNode causes an infinite loop
- Bug: failed to toggle link using TOGGLE_LINK_COMMAND HOT 3
- Feature: Full featured vanillajs example HOT 4
- Cleanup ArtificialNode__DO_NOT_USE
- Bug: Should not focus on root element HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lexical.