Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: exportJSON #6983

Merged
merged 10 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/vanilla-js-plugin/src/emoji-plugin/EmojiNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export class EmojiNode extends TextNode {
exportJSON(): SerializedEmojiNode {
return {
...super.exportJSON(),
type: 'emoji',
unifiedID: this.__unifiedID,
};
}
Expand Down
2 changes: 0 additions & 2 deletions packages/lexical-code/src/CodeHighlightNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ export class CodeHighlightNode extends TextNode {
return {
...super.exportJSON(),
highlightType: this.getHighlightType(),
type: 'code-highlight',
version: 1,
};
}

Expand Down
2 changes: 0 additions & 2 deletions packages/lexical-code/src/CodeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ export class CodeNode extends ElementNode {
return {
...super.exportJSON(),
language: this.getLanguage(),
type: 'code',
version: 1,
};
}

Expand Down
7 changes: 0 additions & 7 deletions packages/lexical-hashtag/src/LexicalHashtagNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ export class HashtagNode extends TextNode {
return node;
}

exportJSON(): SerializedTextNode {
return {
...super.exportJSON(),
type: 'hashtag',
};
}

canInsertTextBefore(): boolean {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {createRoot, Root} from 'react-dom/client';
import * as ReactTestUtils from 'shared/react-test-utils';

type SerializedCustomTextNode = Spread<
{type: ReturnType<typeof CustomTextNode.getType>; classes: string[]},
{type: string; classes: string[]},
SerializedTextNode
>;

Expand Down Expand Up @@ -87,7 +87,6 @@ class CustomTextNode extends TextNode {
return {
...super.exportJSON(),
classes: Array.from(this.getClasses()),
type: this.constructor.getType(),
};
}
}
Expand Down
4 changes: 0 additions & 4 deletions packages/lexical-link/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down Expand Up @@ -425,8 +423,6 @@ export class AutoLinkNode extends LinkNode {
return {
...super.exportJSON(),
isUnlinked: this.__isUnlinked,
type: 'autolink',
version: 1,
};
}

Expand Down
2 changes: 0 additions & 2 deletions packages/lexical-list/src/LexicalListItemNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ export class ListItemNode extends ElementNode {
return {
...super.exportJSON(),
checked: this.getChecked(),
type: 'listitem',
value: this.getValue(),
version: 1,
};
}

Expand Down
2 changes: 0 additions & 2 deletions packages/lexical-list/src/LexicalListNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ export class ListNode extends ElementNode {
listType: this.getListType(),
start: this.getStart(),
tag: this.getTag(),
type: 'list',
version: 1,
};
}

Expand Down
2 changes: 0 additions & 2 deletions packages/lexical-mark/src/MarkNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ export class MarkNode extends ElementNode {
return {
...super.exportJSON(),
ids: Array.from(this.getIDs()),
type: 'mark',
version: 1,
};
}

Expand Down
7 changes: 0 additions & 7 deletions packages/lexical-overflow/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions packages/lexical-playground/src/nodes/AutocompleteNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ export class AutocompleteNode extends TextNode {
exportJSON(): SerializedAutocompleteNode {
return {
...super.exportJSON(),
type: 'autocomplete',
uuid: this.__uuid,
version: 1,
};
}

Expand Down
1 change: 0 additions & 1 deletion packages/lexical-playground/src/nodes/EmojiNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export class EmojiNode extends TextNode {
return {
...super.exportJSON(),
className: this.getClassName(),
type: 'emoji',
};
}

Expand Down
3 changes: 1 addition & 2 deletions packages/lexical-playground/src/nodes/EquationNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ export class EquationNode extends DecoratorNode<JSX.Element> {

exportJSON(): SerializedEquationNode {
return {
...super.exportJSON(),
equation: this.getEquation(),
inline: this.__inline,
type: 'equation',
version: 1,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ export class ExcalidrawNode extends DecoratorNode<JSX.Element> {

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,
};
}
Expand Down
2 changes: 0 additions & 2 deletions packages/lexical-playground/src/nodes/FigmaNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ export class FigmaNode extends DecoratorBlockNode {
return {
...super.exportJSON(),
documentID: this.__id,
type: 'figma',
version: 1,
};
}

Expand Down
3 changes: 1 addition & 2 deletions packages/lexical-playground/src/nodes/ImageNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,13 @@ export class ImageNode extends DecoratorNode<JSX.Element> {

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,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,13 @@ export class InlineImageNode extends DecoratorNode<JSX.Element> {

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,
};
}
Expand Down
8 changes: 0 additions & 8 deletions packages/lexical-playground/src/nodes/KeywordNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ export class LayoutContainerNode extends ElementNode {
return {
...super.exportJSON(),
templateColumns: this.__templateColumns,
type: 'layout-container',
version: 1,
};
}

Expand Down
8 changes: 0 additions & 8 deletions packages/lexical-playground/src/nodes/LayoutItemNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions packages/lexical-playground/src/nodes/MentionNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ export class MentionNode extends TextNode {
return {
...super.exportJSON(),
mentionName: this.__mention,
type: 'mention',
version: 1,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,6 @@ export class PageBreakNode extends DecoratorNode<JSX.Element> {
};
}

exportJSON(): SerializedLexicalNode {
return {
type: this.getType(),
version: 1,
};
}

createDOM(): HTMLElement {
const el = document.createElement('figure');
el.style.pageBreakAfter = 'always';
Expand Down
3 changes: 1 addition & 2 deletions packages/lexical-playground/src/nodes/PollNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ export class PollNode extends DecoratorNode<JSX.Element> {

exportJSON(): SerializedPollNode {
return {
...super.exportJSON(),
options: this.__options,
question: this.__question,
type: 'poll',
version: 1,
};
}

Expand Down
7 changes: 0 additions & 7 deletions packages/lexical-playground/src/nodes/SpecialTextNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ export class SpecialTextNode extends TextNode {
return node;
}

exportJSON(): SerializedTextNode {
return {
...super.exportJSON(),
type: 'specialText',
};
}

isTextEntity(): true {
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/lexical-playground/src/nodes/StickyNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ export class StickyNode extends DecoratorNode<JSX.Element> {

exportJSON(): SerializedStickyNode {
return {
...super.exportJSON(),
caption: this.__caption.toJSON(),
color: this.__color,
type: 'sticky',
version: 1,
xOffset: this.__x,
yOffset: this.__y,
};
Expand Down
2 changes: 0 additions & 2 deletions packages/lexical-playground/src/nodes/TweetNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ export class TweetNode extends DecoratorBlockNode {
return {
...super.exportJSON(),
id: this.getId(),
type: 'tweet',
version: 1,
};
}

Expand Down
2 changes: 0 additions & 2 deletions packages/lexical-playground/src/nodes/YouTubeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ export class YouTubeNode extends DecoratorBlockNode {
exportJSON(): SerializedYouTubeNode {
return {
...super.exportJSON(),
type: 'youtube',
version: 1,
videoID: this.__id,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ export class CollapsibleContainerNode extends ElementNode {
return {
...super.exportJSON(),
open: this.__open,
type: 'collapsible-container',
version: 1,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions packages/lexical-react/src/LexicalDecoratorBlockNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ export class DecoratorBlockNode extends DecoratorNode<JSX.Element> {

exportJSON(): SerializedDecoratorBlockNode {
return {
...super.exportJSON(),
format: this.__format || '',
type: 'decorator-block',
version: 1,
};
}

Expand Down
7 changes: 0 additions & 7 deletions packages/lexical-react/src/LexicalHorizontalRuleNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,6 @@ export class HorizontalRuleNode extends DecoratorNode<JSX.Element> {
};
}

exportJSON(): SerializedLexicalNode {
return {
type: 'horizontalrule',
version: 1,
};
}

exportDOM(): DOMExportOutput {
return {element: document.createElement('hr')};
}
Expand Down
Loading
Loading