2 * Copyright (c) Meta Platforms, Inc. and affiliates.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
9 import type {Binding} from '.';
10 import type {CollabElementNode} from './CollabElementNode';
11 import type {LineBreakNode, NodeKey} from 'lexical';
12 import type {Map as YMap} from 'yjs';
14 import {$getNodeByKey, $isLineBreakNode} from 'lexical';
16 export class CollabLineBreakNode {
19 _parent: CollabElementNode;
22 constructor(map: YMap<unknown>, parent: CollabElementNode) {
25 this._parent = parent;
26 this._type = 'linebreak';
29 getNode(): null | LineBreakNode {
30 const node = $getNodeByKey(this._key);
31 return $isLineBreakNode(node) ? node : null;
38 getSharedType(): YMap<unknown> {
51 const collabElementNode = this._parent;
52 return collabElementNode.getChildOffset(this);
55 destroy(binding: Binding): void {
56 const collabNodeMap = binding.collabNodeMap;
57 collabNodeMap.delete(this._key);
61 export function $createCollabLineBreakNode(
63 parent: CollabElementNode,
64 ): CollabLineBreakNode {
65 const collabNode = new CollabLineBreakNode(map, parent);
66 map._collabNode = collabNode;