Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { createHeadlessEditor } from '@lexical/headless'
import {
$createHorizontalRuleNode as $createLexicalHorizontalRuleNode,
HorizontalRuleNode as LexicalHorizontalRuleNode,
} from '../../../../lexical-proxy/@lexical-react/LexicalHorizontalRuleNode.js'
import { describe, expect, it } from 'vitest'

import {
$createHorizontalRuleNode,
$isHorizontalRuleNode,
HorizontalRuleNode,
} from './HorizontalRuleNode.js'

describe('HorizontalRuleNode client export', () => {
it('should use the same HorizontalRuleNode class as lexical', () => {
expect(HorizontalRuleNode).toBe(LexicalHorizontalRuleNode)
})

it('should create nodes that match lexical class identity', () => {
const editor = createHeadlessEditor({
nodes: [HorizontalRuleNode],
})

editor.update(
() => {
const node = $createHorizontalRuleNode()
const lexicalNode = $createLexicalHorizontalRuleNode()

expect(node.constructor).toBe(lexicalNode.constructor)
expect($isHorizontalRuleNode(node)).toBe(true)
},
{ discrete: true },
)
})
})
Original file line number Diff line number Diff line change
@@ -1,51 +1,7 @@
'use client'
import type { DOMConversionOutput, LexicalNode, SerializedLexicalNode } from 'lexical'

import { $applyNodeReplacement } from 'lexical'
import * as React from 'react'

import type { SerializedHorizontalRuleNode } from '../../server/nodes/HorizontalRuleNode.js'

import { HorizontalRuleServerNode } from '../../server/nodes/HorizontalRuleNode.js'

export class HorizontalRuleNode extends HorizontalRuleServerNode {
static override clone(node: HorizontalRuleServerNode): HorizontalRuleServerNode {
return super.clone(node)
}

static override getType(): string {
return super.getType()
}

/**
* The data for this node is stored serialized as JSON. This is the "load function" of that node: it takes the saved data and converts it into a node.
*/
static override importJSON(serializedNode: SerializedHorizontalRuleNode): HorizontalRuleNode {
return $createHorizontalRuleNode()
}

/**
* Allows you to render a React component within whatever createDOM returns.
*/
override decorate() {
return null
}

override exportJSON(): SerializedLexicalNode {
return super.exportJSON()
}
}

function $convertHorizontalRuleElement(): DOMConversionOutput {
return { node: $createHorizontalRuleNode() }
}

export function $createHorizontalRuleNode(): HorizontalRuleNode {
return $applyNodeReplacement(new HorizontalRuleNode())
}

export function $isHorizontalRuleNode(
node: LexicalNode | null | undefined,
): node is HorizontalRuleNode {
return node instanceof HorizontalRuleNode
}
export {
$createHorizontalRuleNode,
$isHorizontalRuleNode,
HorizontalRuleNode,
} from '../../../../lexical-proxy/@lexical-react/LexicalHorizontalRuleNode.js'
Loading