diff --git a/examples/vanilla-js-plugin/src/emoji-plugin/EmojiNode.ts b/examples/vanilla-js-plugin/src/emoji-plugin/EmojiNode.ts index 8c4da075173..5717a9c86b8 100644 --- a/examples/vanilla-js-plugin/src/emoji-plugin/EmojiNode.ts +++ b/examples/vanilla-js-plugin/src/emoji-plugin/EmojiNode.ts @@ -60,7 +60,6 @@ export class EmojiNode extends TextNode { exportJSON(): SerializedEmojiNode { return { ...super.exportJSON(), - type: 'emoji', unifiedID: this.__unifiedID, }; } diff --git a/packages/lexical-code/src/CodeHighlightNode.ts b/packages/lexical-code/src/CodeHighlightNode.ts index c9b43e486d3..9089e93feb3 100644 --- a/packages/lexical-code/src/CodeHighlightNode.ts +++ b/packages/lexical-code/src/CodeHighlightNode.ts @@ -175,8 +175,6 @@ export class CodeHighlightNode extends TextNode { return { ...super.exportJSON(), highlightType: this.getHighlightType(), - type: 'code-highlight', - version: 1, }; } diff --git a/packages/lexical-code/src/CodeNode.ts b/packages/lexical-code/src/CodeNode.ts index f2ae407c189..89bb095e955 100644 --- a/packages/lexical-code/src/CodeNode.ts +++ b/packages/lexical-code/src/CodeNode.ts @@ -223,8 +223,6 @@ export class CodeNode extends ElementNode { return { ...super.exportJSON(), language: this.getLanguage(), - type: 'code', - version: 1, }; } diff --git a/packages/lexical-hashtag/src/LexicalHashtagNode.ts b/packages/lexical-hashtag/src/LexicalHashtagNode.ts index 657bafcd5e6..5367d61039b 100644 --- a/packages/lexical-hashtag/src/LexicalHashtagNode.ts +++ b/packages/lexical-hashtag/src/LexicalHashtagNode.ts @@ -45,13 +45,6 @@ export class HashtagNode extends TextNode { return node; } - exportJSON(): SerializedTextNode { - return { - ...super.exportJSON(), - type: 'hashtag', - }; - } - canInsertTextBefore(): boolean { return false; } diff --git a/packages/lexical-history/src/__tests__/unit/LexicalHistory.test.tsx b/packages/lexical-history/src/__tests__/unit/LexicalHistory.test.tsx index 0cef7f59210..12eace707a0 100644 --- a/packages/lexical-history/src/__tests__/unit/LexicalHistory.test.tsx +++ b/packages/lexical-history/src/__tests__/unit/LexicalHistory.test.tsx @@ -44,7 +44,7 @@ import {createRoot, Root} from 'react-dom/client'; import * as ReactTestUtils from 'shared/react-test-utils'; type SerializedCustomTextNode = Spread< - {type: ReturnType; classes: string[]}, + {type: string; classes: string[]}, SerializedTextNode >; @@ -87,7 +87,6 @@ class CustomTextNode extends TextNode { return { ...super.exportJSON(), classes: Array.from(this.getClasses()), - type: this.constructor.getType(), }; } } diff --git a/packages/lexical-link/src/index.ts b/packages/lexical-link/src/index.ts index 2149cf4a30c..a43463e5a80 100644 --- a/packages/lexical-link/src/index.ts +++ b/packages/lexical-link/src/index.ts @@ -195,9 +195,7 @@ export class LinkNode extends ElementNode { rel: this.getRel(), target: this.getTarget(), title: this.getTitle(), - type: 'link', url: this.getURL(), - version: 1, }; } @@ -425,8 +423,6 @@ export class AutoLinkNode extends LinkNode { return { ...super.exportJSON(), isUnlinked: this.__isUnlinked, - type: 'autolink', - version: 1, }; } diff --git a/packages/lexical-list/src/LexicalListItemNode.ts b/packages/lexical-list/src/LexicalListItemNode.ts index 9dade3ae0a3..8a587c7dcd7 100644 --- a/packages/lexical-list/src/LexicalListItemNode.ts +++ b/packages/lexical-list/src/LexicalListItemNode.ts @@ -143,9 +143,7 @@ export class ListItemNode extends ElementNode { return { ...super.exportJSON(), checked: this.getChecked(), - type: 'listitem', value: this.getValue(), - version: 1, }; } diff --git a/packages/lexical-list/src/LexicalListNode.ts b/packages/lexical-list/src/LexicalListNode.ts index dfcaacc1d1f..16251b39c29 100644 --- a/packages/lexical-list/src/LexicalListNode.ts +++ b/packages/lexical-list/src/LexicalListNode.ts @@ -171,8 +171,6 @@ export class ListNode extends ElementNode { listType: this.getListType(), start: this.getStart(), tag: this.getTag(), - type: 'list', - version: 1, }; } diff --git a/packages/lexical-mark/src/MarkNode.ts b/packages/lexical-mark/src/MarkNode.ts index 2bc9ab140f0..6607bad18dc 100644 --- a/packages/lexical-mark/src/MarkNode.ts +++ b/packages/lexical-mark/src/MarkNode.ts @@ -58,8 +58,6 @@ export class MarkNode extends ElementNode { return { ...super.exportJSON(), ids: Array.from(this.getIDs()), - type: 'mark', - version: 1, }; } diff --git a/packages/lexical-overflow/src/index.ts b/packages/lexical-overflow/src/index.ts index 60e77d21ecb..19eaf1ed4b7 100644 --- a/packages/lexical-overflow/src/index.ts +++ b/packages/lexical-overflow/src/index.ts @@ -42,13 +42,6 @@ export class OverflowNode extends ElementNode { this.__type = 'overflow'; } - exportJSON(): SerializedElementNode { - return { - ...super.exportJSON(), - type: 'overflow', - }; - } - createDOM(config: EditorConfig): HTMLElement { const div = document.createElement('span'); const className = config.theme.characterLimit; diff --git a/packages/lexical-playground/src/nodes/AutocompleteNode.tsx b/packages/lexical-playground/src/nodes/AutocompleteNode.tsx index 777f0d69ab6..b4c95b4f070 100644 --- a/packages/lexical-playground/src/nodes/AutocompleteNode.tsx +++ b/packages/lexical-playground/src/nodes/AutocompleteNode.tsx @@ -62,9 +62,7 @@ export class AutocompleteNode extends TextNode { exportJSON(): SerializedAutocompleteNode { return { ...super.exportJSON(), - type: 'autocomplete', uuid: this.__uuid, - version: 1, }; } diff --git a/packages/lexical-playground/src/nodes/EmojiNode.tsx b/packages/lexical-playground/src/nodes/EmojiNode.tsx index 30b899666d1..23d3fdfde5d 100644 --- a/packages/lexical-playground/src/nodes/EmojiNode.tsx +++ b/packages/lexical-playground/src/nodes/EmojiNode.tsx @@ -73,7 +73,6 @@ export class EmojiNode extends TextNode { return { ...super.exportJSON(), className: this.getClassName(), - type: 'emoji', }; } diff --git a/packages/lexical-playground/src/nodes/EquationNode.tsx b/packages/lexical-playground/src/nodes/EquationNode.tsx index 1ab7cce2128..d23f6fd139b 100644 --- a/packages/lexical-playground/src/nodes/EquationNode.tsx +++ b/packages/lexical-playground/src/nodes/EquationNode.tsx @@ -74,10 +74,9 @@ export class EquationNode extends DecoratorNode { exportJSON(): SerializedEquationNode { return { + ...super.exportJSON(), equation: this.getEquation(), inline: this.__inline, - type: 'equation', - version: 1, }; } diff --git a/packages/lexical-playground/src/nodes/ExcalidrawNode/index.tsx b/packages/lexical-playground/src/nodes/ExcalidrawNode/index.tsx index 71d0860f4b5..51f33e29164 100644 --- a/packages/lexical-playground/src/nodes/ExcalidrawNode/index.tsx +++ b/packages/lexical-playground/src/nodes/ExcalidrawNode/index.tsx @@ -84,10 +84,9 @@ export class ExcalidrawNode extends DecoratorNode { exportJSON(): SerializedExcalidrawNode { return { + ...super.exportJSON(), data: this.__data, height: this.__height === 'inherit' ? undefined : this.__height, - type: 'excalidraw', - version: 1, width: this.__width === 'inherit' ? undefined : this.__width, }; } diff --git a/packages/lexical-playground/src/nodes/FigmaNode.tsx b/packages/lexical-playground/src/nodes/FigmaNode.tsx index 1984c4e4a5f..07b1c8de546 100644 --- a/packages/lexical-playground/src/nodes/FigmaNode.tsx +++ b/packages/lexical-playground/src/nodes/FigmaNode.tsx @@ -82,8 +82,6 @@ export class FigmaNode extends DecoratorBlockNode { return { ...super.exportJSON(), documentID: this.__id, - type: 'figma', - version: 1, }; } diff --git a/packages/lexical-playground/src/nodes/ImageNode.tsx b/packages/lexical-playground/src/nodes/ImageNode.tsx index a21971c85f0..7926fcdba61 100644 --- a/packages/lexical-playground/src/nodes/ImageNode.tsx +++ b/packages/lexical-playground/src/nodes/ImageNode.tsx @@ -163,14 +163,13 @@ export class ImageNode extends DecoratorNode { exportJSON(): SerializedImageNode { return { + ...super.exportJSON(), altText: this.getAltText(), caption: this.__caption.toJSON(), height: this.__height === 'inherit' ? 0 : this.__height, maxWidth: this.__maxWidth, showCaption: this.__showCaption, src: this.getSrc(), - type: 'image', - version: 1, width: this.__width === 'inherit' ? 0 : this.__width, }; } diff --git a/packages/lexical-playground/src/nodes/InlineImageNode/InlineImageNode.tsx b/packages/lexical-playground/src/nodes/InlineImageNode/InlineImageNode.tsx index df78864ca00..ebad678917b 100644 --- a/packages/lexical-playground/src/nodes/InlineImageNode/InlineImageNode.tsx +++ b/packages/lexical-playground/src/nodes/InlineImageNode/InlineImageNode.tsx @@ -158,14 +158,13 @@ export class InlineImageNode extends DecoratorNode { exportJSON(): SerializedInlineImageNode { return { + ...super.exportJSON(), altText: this.getAltText(), caption: this.__caption.toJSON(), height: this.__height === 'inherit' ? 0 : this.__height, position: this.__position, showCaption: this.__showCaption, src: this.getSrc(), - type: 'inline-image', - version: 1, width: this.__width === 'inherit' ? 0 : this.__width, }; } diff --git a/packages/lexical-playground/src/nodes/KeywordNode.ts b/packages/lexical-playground/src/nodes/KeywordNode.ts index 9d179b8cf2d..ea433f8740b 100644 --- a/packages/lexical-playground/src/nodes/KeywordNode.ts +++ b/packages/lexical-playground/src/nodes/KeywordNode.ts @@ -30,14 +30,6 @@ export class KeywordNode extends TextNode { return node; } - exportJSON(): SerializedKeywordNode { - return { - ...super.exportJSON(), - type: 'keyword', - version: 1, - }; - } - createDOM(config: EditorConfig): HTMLElement { const dom = super.createDOM(config); dom.style.cursor = 'default'; diff --git a/packages/lexical-playground/src/nodes/LayoutContainerNode.ts b/packages/lexical-playground/src/nodes/LayoutContainerNode.ts index 8bb7cddf47a..1972d94ecf4 100644 --- a/packages/lexical-playground/src/nodes/LayoutContainerNode.ts +++ b/packages/lexical-playground/src/nodes/LayoutContainerNode.ts @@ -110,8 +110,6 @@ export class LayoutContainerNode extends ElementNode { return { ...super.exportJSON(), templateColumns: this.__templateColumns, - type: 'layout-container', - version: 1, }; } diff --git a/packages/lexical-playground/src/nodes/LayoutItemNode.ts b/packages/lexical-playground/src/nodes/LayoutItemNode.ts index 3d227976d64..43c1dd2ba09 100644 --- a/packages/lexical-playground/src/nodes/LayoutItemNode.ts +++ b/packages/lexical-playground/src/nodes/LayoutItemNode.ts @@ -66,14 +66,6 @@ export class LayoutItemNode extends ElementNode { isShadowRoot(): boolean { return true; } - - exportJSON(): SerializedLayoutItemNode { - return { - ...super.exportJSON(), - type: 'layout-item', - version: 1, - }; - } } export function $createLayoutItemNode(): LayoutItemNode { diff --git a/packages/lexical-playground/src/nodes/MentionNode.ts b/packages/lexical-playground/src/nodes/MentionNode.ts index b6a41754025..491877c9d1b 100644 --- a/packages/lexical-playground/src/nodes/MentionNode.ts +++ b/packages/lexical-playground/src/nodes/MentionNode.ts @@ -71,8 +71,6 @@ export class MentionNode extends TextNode { return { ...super.exportJSON(), mentionName: this.__mention, - type: 'mention', - version: 1, }; } diff --git a/packages/lexical-playground/src/nodes/PageBreakNode/index.tsx b/packages/lexical-playground/src/nodes/PageBreakNode/index.tsx index 8e6a1f551a1..a0e34a4f18e 100644 --- a/packages/lexical-playground/src/nodes/PageBreakNode/index.tsx +++ b/packages/lexical-playground/src/nodes/PageBreakNode/index.tsx @@ -124,13 +124,6 @@ export class PageBreakNode extends DecoratorNode { }; } - exportJSON(): SerializedLexicalNode { - return { - type: this.getType(), - version: 1, - }; - } - createDOM(): HTMLElement { const el = document.createElement('figure'); el.style.pageBreakAfter = 'always'; diff --git a/packages/lexical-playground/src/nodes/PollNode.tsx b/packages/lexical-playground/src/nodes/PollNode.tsx index fd8fe8097e7..4278b573bcf 100644 --- a/packages/lexical-playground/src/nodes/PollNode.tsx +++ b/packages/lexical-playground/src/nodes/PollNode.tsx @@ -103,10 +103,9 @@ export class PollNode extends DecoratorNode { exportJSON(): SerializedPollNode { return { + ...super.exportJSON(), options: this.__options, question: this.__question, - type: 'poll', - version: 1, }; } diff --git a/packages/lexical-playground/src/nodes/SpecialTextNode.tsx b/packages/lexical-playground/src/nodes/SpecialTextNode.tsx index 8c89106f7cf..2521b79cbf1 100644 --- a/packages/lexical-playground/src/nodes/SpecialTextNode.tsx +++ b/packages/lexical-playground/src/nodes/SpecialTextNode.tsx @@ -57,13 +57,6 @@ export class SpecialTextNode extends TextNode { return node; } - exportJSON(): SerializedTextNode { - return { - ...super.exportJSON(), - type: 'specialText', - }; - } - isTextEntity(): true { return true; } diff --git a/packages/lexical-playground/src/nodes/StickyNode.tsx b/packages/lexical-playground/src/nodes/StickyNode.tsx index 883974ee48e..a7e9d9e6850 100644 --- a/packages/lexical-playground/src/nodes/StickyNode.tsx +++ b/packages/lexical-playground/src/nodes/StickyNode.tsx @@ -85,10 +85,9 @@ export class StickyNode extends DecoratorNode { exportJSON(): SerializedStickyNode { return { + ...super.exportJSON(), caption: this.__caption.toJSON(), color: this.__color, - type: 'sticky', - version: 1, xOffset: this.__x, yOffset: this.__y, }; diff --git a/packages/lexical-playground/src/nodes/TweetNode.tsx b/packages/lexical-playground/src/nodes/TweetNode.tsx index 4ca2c288a40..26451210cb3 100644 --- a/packages/lexical-playground/src/nodes/TweetNode.tsx +++ b/packages/lexical-playground/src/nodes/TweetNode.tsx @@ -151,8 +151,6 @@ export class TweetNode extends DecoratorBlockNode { return { ...super.exportJSON(), id: this.getId(), - type: 'tweet', - version: 1, }; } diff --git a/packages/lexical-playground/src/nodes/YouTubeNode.tsx b/packages/lexical-playground/src/nodes/YouTubeNode.tsx index 3c04a0269ed..b61de04ec65 100644 --- a/packages/lexical-playground/src/nodes/YouTubeNode.tsx +++ b/packages/lexical-playground/src/nodes/YouTubeNode.tsx @@ -97,8 +97,6 @@ export class YouTubeNode extends DecoratorBlockNode { exportJSON(): SerializedYouTubeNode { return { ...super.exportJSON(), - type: 'youtube', - version: 1, videoID: this.__id, }; } diff --git a/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContainerNode.ts b/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContainerNode.ts index 6d4387e0a59..d7ba9443779 100644 --- a/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContainerNode.ts +++ b/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContainerNode.ts @@ -133,8 +133,6 @@ export class CollapsibleContainerNode extends ElementNode { return { ...super.exportJSON(), open: this.__open, - type: 'collapsible-container', - version: 1, }; } diff --git a/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContentNode.ts b/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContentNode.ts index f6f4ce07ddd..fc193e5f03b 100644 --- a/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContentNode.ts +++ b/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleContentNode.ts @@ -106,14 +106,6 @@ export class CollapsibleContentNode extends ElementNode { isShadowRoot(): boolean { return true; } - - exportJSON(): SerializedCollapsibleContentNode { - return { - ...super.exportJSON(), - type: 'collapsible-content', - version: 1, - }; - } } export function $createCollapsibleContentNode(): CollapsibleContentNode { diff --git a/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleTitleNode.ts b/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleTitleNode.ts index 3b6a39061b3..fa6de18353f 100644 --- a/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleTitleNode.ts +++ b/packages/lexical-playground/src/plugins/CollapsiblePlugin/CollapsibleTitleNode.ts @@ -83,14 +83,6 @@ export class CollapsibleTitleNode extends ElementNode { return $createCollapsibleTitleNode(); } - exportJSON(): SerializedCollapsibleTitleNode { - return { - ...super.exportJSON(), - type: 'collapsible-title', - version: 1, - }; - } - collapseAtStart(_selection: RangeSelection): boolean { this.getParentOrThrow().insertBefore(this); return true; diff --git a/packages/lexical-react/src/LexicalDecoratorBlockNode.ts b/packages/lexical-react/src/LexicalDecoratorBlockNode.ts index 64b1f4bcb74..63969b2fe08 100644 --- a/packages/lexical-react/src/LexicalDecoratorBlockNode.ts +++ b/packages/lexical-react/src/LexicalDecoratorBlockNode.ts @@ -33,9 +33,8 @@ export class DecoratorBlockNode extends DecoratorNode { exportJSON(): SerializedDecoratorBlockNode { return { + ...super.exportJSON(), format: this.__format || '', - type: 'decorator-block', - version: 1, }; } diff --git a/packages/lexical-react/src/LexicalHorizontalRuleNode.tsx b/packages/lexical-react/src/LexicalHorizontalRuleNode.tsx index 19aae08faed..3e051100f28 100644 --- a/packages/lexical-react/src/LexicalHorizontalRuleNode.tsx +++ b/packages/lexical-react/src/LexicalHorizontalRuleNode.tsx @@ -138,13 +138,6 @@ export class HorizontalRuleNode extends DecoratorNode { }; } - exportJSON(): SerializedLexicalNode { - return { - type: 'horizontalrule', - version: 1, - }; - } - exportDOM(): DOMExportOutput { return {element: document.createElement('hr')}; } diff --git a/packages/lexical-rich-text/src/index.ts b/packages/lexical-rich-text/src/index.ts index 7e39f5631dd..21a923d0e24 100644 --- a/packages/lexical-rich-text/src/index.ts +++ b/packages/lexical-rich-text/src/index.ts @@ -182,13 +182,6 @@ export class QuoteNode extends ElementNode { return node; } - exportJSON(): SerializedElementNode { - return { - ...super.exportJSON(), - type: 'quote', - }; - } - // Mutation insertNewAfter(_: RangeSelection, restoreSelection?: boolean): ParagraphNode { @@ -352,8 +345,6 @@ export class HeadingNode extends ElementNode { return { ...super.exportJSON(), tag: this.getTag(), - type: 'heading', - version: 1, }; } diff --git a/packages/lexical-table/src/LexicalTableCellNode.ts b/packages/lexical-table/src/LexicalTableCellNode.ts index 396fc6564d7..a280ae48d98 100644 --- a/packages/lexical-table/src/LexicalTableCellNode.ts +++ b/packages/lexical-table/src/LexicalTableCellNode.ts @@ -183,7 +183,6 @@ export class TableCellNode extends ElementNode { colSpan: this.__colSpan, headerState: this.__headerState, rowSpan: this.__rowSpan, - type: 'tablecell', width: this.getWidth(), }; } diff --git a/packages/lexical-table/src/LexicalTableNode.ts b/packages/lexical-table/src/LexicalTableNode.ts index fa7aa3d4d04..b5390621a1f 100644 --- a/packages/lexical-table/src/LexicalTableNode.ts +++ b/packages/lexical-table/src/LexicalTableNode.ts @@ -168,8 +168,6 @@ export class TableNode extends ElementNode { ...super.exportJSON(), colWidths: this.getColWidths(), rowStriping: this.__rowStriping ? this.__rowStriping : undefined, - type: 'table', - version: 1, }; } diff --git a/packages/lexical-table/src/LexicalTableRowNode.ts b/packages/lexical-table/src/LexicalTableRowNode.ts index 4e216b865df..d09f3fe8a4b 100644 --- a/packages/lexical-table/src/LexicalTableRowNode.ts +++ b/packages/lexical-table/src/LexicalTableRowNode.ts @@ -65,8 +65,6 @@ export class TableRowNode extends ElementNode { return { ...super.exportJSON(), ...(this.getHeight() && {height: this.getHeight()}), - type: 'tablerow', - version: 1, }; } diff --git a/packages/lexical-website/docs/concepts/serialization.md b/packages/lexical-website/docs/concepts/serialization.md index 90eaf313fe3..3d39ae0b6b3 100644 --- a/packages/lexical-website/docs/concepts/serialization.md +++ b/packages/lexical-website/docs/concepts/serialization.md @@ -170,7 +170,7 @@ const jsonString = JSON.stringify(editorState); #### `LexicalNode.exportJSON()` -You can control how a `LexicalNode` is represented as JSON by adding an `exportJSON()` method. It's important to ensure your serialized JSON node has a `type` field and a `children` field if it's an `ElementNode`. +You can control how a `LexicalNode` is represented as JSON by adding an `exportJSON()` method. It's important that you extend the serialization of the superclass by invoking `super`: e.g. `{ ...super.exportJSON(), /* your other properties */ }`. ```js export type SerializedLexicalNode = { @@ -197,8 +197,6 @@ exportJSON(): SerializedHeadingNode { return { ...super.exportJSON(), tag: this.getTag(), - type: 'heading', - version: 1, }; } ``` @@ -373,13 +371,7 @@ export class ExtendedTextNode extends TextNode { return this.__type === 'extended-text' && this.__mode === 0; } - exportJSON(): SerializedTextNode { - return { - ...super.exportJSON(), - type: 'extended-text', - version: 1, - } - } + // no need to add exportJSON here, since we are not adding any new properties } export function $createExtendedTextNode(text: string): ExtendedTextNode { diff --git a/packages/lexical-website/docs/getting-started/creating-plugin.md b/packages/lexical-website/docs/getting-started/creating-plugin.md index 32791754217..7a5be385b11 100644 --- a/packages/lexical-website/docs/getting-started/creating-plugin.md +++ b/packages/lexical-website/docs/getting-started/creating-plugin.md @@ -75,7 +75,6 @@ export class EmojiNode extends TextNode { exportJSON(): SerializedEmojiNode { return { ...super.exportJSON(), - type: 'emoji', unifiedID: this.__unifiedID, }; } diff --git a/packages/lexical/src/LexicalEditor.ts b/packages/lexical/src/LexicalEditor.ts index 1961c8f4f34..3ccdd7c3fd9 100644 --- a/packages/lexical/src/LexicalEditor.ts +++ b/packages/lexical/src/LexicalEditor.ts @@ -514,14 +514,6 @@ export function createEditor(editorConfig?: CreateEditorArgs): LexicalEditor { `${name} should implement "importJSON" method to ensure JSON and default HTML serialization works as expected`, ); } - if ( - // eslint-disable-next-line no-prototype-builtins - !proto.hasOwnProperty('exportJSON') - ) { - console.warn( - `${name} should implement "exportJSON" method to ensure JSON and default HTML serialization works as expected`, - ); - } } } const type = klass.getType(); diff --git a/packages/lexical/src/LexicalNode.ts b/packages/lexical/src/LexicalNode.ts index 0aa1d1ca487..c8727bb87ac 100644 --- a/packages/lexical/src/LexicalNode.ts +++ b/packages/lexical/src/LexicalNode.ts @@ -869,7 +869,10 @@ export class LexicalNode { * * */ exportJSON(): SerializedLexicalNode { - invariant(false, 'exportJSON: base method not extended'); + return { + type: this.__type, + version: 1, + }; } /** diff --git a/packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx b/packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx index af71d8f681c..d0fca489f6c 100644 --- a/packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx +++ b/packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx @@ -2778,10 +2778,6 @@ describe('LexicalEditor tests', () => { static importJSON() { return new CustomParagraphNode(); } - - exportJSON() { - return {...super.exportJSON(), type: 'custom-paragraph'}; - } } createTestEditor({nodes: [CustomParagraphNode]}); diff --git a/packages/lexical/src/__tests__/unit/LexicalNode.test.ts b/packages/lexical/src/__tests__/unit/LexicalNode.test.ts index 7373f898d80..07baa4ac9b5 100644 --- a/packages/lexical/src/__tests__/unit/LexicalNode.test.ts +++ b/packages/lexical/src/__tests__/unit/LexicalNode.test.ts @@ -51,10 +51,6 @@ class TestNode extends LexicalNode { static importJSON() { return new TestNode(); } - - exportJSON() { - return {type: 'test', version: 1}; - } } class InlineDecoratorNode extends DecoratorNode { @@ -70,10 +66,6 @@ class InlineDecoratorNode extends DecoratorNode { return new InlineDecoratorNode(); } - exportJSON() { - return {type: 'inline-decorator', version: 1}; - } - createDOM(): HTMLElement { return document.createElement('span'); } @@ -166,9 +158,6 @@ describe('LexicalNode tests', () => { static importJSON(node: SerializedTextNode): VersionedTextNode { throw new Error('Not implemented'); } - exportJSON(): SerializedTextNode { - throw new Error('Not implemented'); - } afterCloneFrom(node: this): void { super.afterCloneFrom(node); this.__version = node.__version + 1; diff --git a/packages/lexical/src/__tests__/unit/LexicalSelection.test.ts b/packages/lexical/src/__tests__/unit/LexicalSelection.test.ts index 97be0aac4f1..bcd0b304e6c 100644 --- a/packages/lexical/src/__tests__/unit/LexicalSelection.test.ts +++ b/packages/lexical/src/__tests__/unit/LexicalSelection.test.ts @@ -807,9 +807,6 @@ describe('Regression tests for #6701', () => { isInline() { return true; } - exportJSON() { - return {...super.exportJSON(), type: this.getType()}; - } createDOM() { return document.createElement('span'); } diff --git a/packages/lexical/src/__tests__/unit/LexicalUtils.test.ts b/packages/lexical/src/__tests__/unit/LexicalUtils.test.ts index 6b7e913c1ba..086c19d1f75 100644 --- a/packages/lexical/src/__tests__/unit/LexicalUtils.test.ts +++ b/packages/lexical/src/__tests__/unit/LexicalUtils.test.ts @@ -372,9 +372,6 @@ describe('$applyNodeReplacement', () => { static clone(node: ExtendedTextNode): ExtendedTextNode { return new ExtendedTextNode(node.__text, node.getKey()); } - exportJSON(): SerializedTextNode { - return {...super.exportJSON(), type: this.getType()}; - } initWithTextNode(node: TextNode): this { this.__text = node.__text; TextNode.prototype.afterCloneFrom.call(this, node); @@ -407,9 +404,6 @@ describe('$applyNodeReplacement', () => { ): ExtendedExtendedTextNode { return $createExtendedExtendedTextNode().initWithJSON(serializedNode); } - exportJSON(): SerializedTextNode { - return {...super.exportJSON(), type: this.getType()}; - } } function $createExtendedTextNode(text: string = '') { return $applyNodeReplacement(new ExtendedTextNode(text)); diff --git a/packages/lexical/src/__tests__/utils/index.tsx b/packages/lexical/src/__tests__/utils/index.tsx index 4bb096f874d..54de1d30ec2 100644 --- a/packages/lexical/src/__tests__/utils/index.tsx +++ b/packages/lexical/src/__tests__/utils/index.tsx @@ -182,14 +182,6 @@ export class TestElementNode extends ElementNode { return node; } - exportJSON(): SerializedTestElementNode { - return { - ...super.exportJSON(), - type: 'test_block', - version: 1, - }; - } - createDOM() { return document.createElement('div'); } @@ -217,14 +209,6 @@ export class TestTextNode extends TextNode { static importJSON(serializedNode: SerializedTestTextNode): TestTextNode { return new TestTextNode(serializedNode.text); } - - exportJSON(): SerializedTestTextNode { - return { - ...super.exportJSON(), - type: 'test_text', - version: 1, - }; - } } export type SerializedTestInlineElementNode = SerializedElementNode; @@ -248,14 +232,6 @@ export class TestInlineElementNode extends ElementNode { return node; } - exportJSON(): SerializedTestInlineElementNode { - return { - ...super.exportJSON(), - type: 'test_inline_block', - version: 1, - }; - } - createDOM() { return document.createElement('a'); } @@ -294,14 +270,6 @@ export class TestShadowRootNode extends ElementNode { return node; } - exportJSON(): SerializedTestShadowRootNode { - return { - ...super.exportJSON(), - type: 'test_block', - version: 1, - }; - } - createDOM() { return document.createElement('div'); } @@ -340,14 +308,6 @@ export class TestSegmentedNode extends TextNode { node.setStyle(serializedNode.style); return node; } - - exportJSON(): SerializedTestSegmentedNode { - return { - ...super.exportJSON(), - type: 'test_segmented', - version: 1, - }; - } } export function $createTestSegmentedNode(text: string): TestSegmentedNode { @@ -375,14 +335,6 @@ export class TestExcludeFromCopyElementNode extends ElementNode { return node; } - exportJSON(): SerializedTestExcludeFromCopyElementNode { - return { - ...super.exportJSON(), - type: 'test_exclude_from_copy_block', - version: 1, - }; - } - createDOM() { return document.createElement('div'); } @@ -417,14 +369,6 @@ export class TestDecoratorNode extends DecoratorNode { return $createTestDecoratorNode(); } - exportJSON(): SerializedTestDecoratorNode { - return { - ...super.exportJSON(), - type: 'test_decorator', - version: 1, - }; - } - static importDOM() { return { 'test-decorator': (domNode: HTMLElement) => { diff --git a/packages/lexical/src/nodes/LexicalElementNode.ts b/packages/lexical/src/nodes/LexicalElementNode.ts index 19e54b0cfa6..a17daaf29d6 100644 --- a/packages/lexical/src/nodes/LexicalElementNode.ts +++ b/packages/lexical/src/nodes/LexicalElementNode.ts @@ -792,8 +792,10 @@ export class ElementNode extends LexicalNode { direction: this.getDirection(), format: this.getFormatType(), indent: this.getIndent(), - type: 'element', - version: 1, + // As an exception here we invoke super at the end for historical reasons. + // Namely, to preserve the order of the properties and not to break the tests + // that use the serialized string representation. + ...super.exportJSON(), }; } // These are intended to be extends for specific element heuristics. diff --git a/packages/lexical/src/nodes/LexicalLineBreakNode.ts b/packages/lexical/src/nodes/LexicalLineBreakNode.ts index 2d28db08c12..2842ed4bf42 100644 --- a/packages/lexical/src/nodes/LexicalLineBreakNode.ts +++ b/packages/lexical/src/nodes/LexicalLineBreakNode.ts @@ -66,13 +66,6 @@ export class LineBreakNode extends LexicalNode { ): LineBreakNode { return $createLineBreakNode(); } - - exportJSON(): SerializedLexicalNode { - return { - type: 'linebreak', - version: 1, - }; - } } function $convertLineBreakElement(node: Node): DOMConversionOutput { diff --git a/packages/lexical/src/nodes/LexicalParagraphNode.ts b/packages/lexical/src/nodes/LexicalParagraphNode.ts index 1fec9c8b257..85809dce997 100644 --- a/packages/lexical/src/nodes/LexicalParagraphNode.ts +++ b/packages/lexical/src/nodes/LexicalParagraphNode.ts @@ -173,8 +173,6 @@ export class ParagraphNode extends ElementNode { ...super.exportJSON(), textFormat: this.getTextFormat(), textStyle: this.getTextStyle(), - type: 'paragraph', - version: 1, }; } diff --git a/packages/lexical/src/nodes/LexicalRootNode.ts b/packages/lexical/src/nodes/LexicalRootNode.ts index 7e4782061f1..a22db32e947 100644 --- a/packages/lexical/src/nodes/LexicalRootNode.ts +++ b/packages/lexical/src/nodes/LexicalRootNode.ts @@ -105,17 +105,6 @@ export class RootNode extends ElementNode { return node; } - exportJSON(): SerializedRootNode { - return { - children: [], - direction: this.getDirection(), - format: this.getFormatType(), - indent: this.getIndent(), - type: 'root', - version: 1, - }; - } - collapseAtStart(): true { return true; } diff --git a/packages/lexical/src/nodes/LexicalTabNode.ts b/packages/lexical/src/nodes/LexicalTabNode.ts index 8c5999b33c2..492cc77fac9 100644 --- a/packages/lexical/src/nodes/LexicalTabNode.ts +++ b/packages/lexical/src/nodes/LexicalTabNode.ts @@ -66,14 +66,6 @@ export class TabNode extends TextNode { return node; } - exportJSON(): SerializedTabNode { - return { - ...super.exportJSON(), - type: 'tab', - version: 1, - }; - } - setTextContent(_text: string): this { invariant(false, 'TabNode does not support setTextContent'); } diff --git a/packages/lexical/src/nodes/LexicalTextNode.ts b/packages/lexical/src/nodes/LexicalTextNode.ts index ed57345627f..80fe5001c5c 100644 --- a/packages/lexical/src/nodes/LexicalTextNode.ts +++ b/packages/lexical/src/nodes/LexicalTextNode.ts @@ -652,8 +652,10 @@ export class TextNode extends LexicalNode { mode: this.getMode(), style: this.getStyle(), text: this.getTextContent(), - type: 'text', - version: 1, + // As an exception here we invoke super at the end for historical reasons. + // Namely, to preserve the order of the properties and not to break the tests + // that use the serialized string representation. + ...super.exportJSON(), }; }