MCPcopy Create free account
hub / github.com/editablejs/editable / getYTarget

Function getYTarget

packages/yjs-transform/src/location.ts:20–59  ·  view source on GitHub ↗
(yRoot: Y.XmlText, editorRoot: Node, path: Path)

Source from the content-addressed store, hash-verified

18}
19
20export function getYTarget(yRoot: Y.XmlText, editorRoot: Node, path: Path): YTarget {
21 if (path.length === 0) {
22 throw new Error('Path has to a have a length >= 1')
23 }
24
25 if (Text.isText(editorRoot)) {
26 throw new Error('Cannot descent into editor text')
27 }
28
29 const [pathOffset, ...childPath] = path
30
31 const yOffset = editorPathOffsetToYOffset(editorRoot, pathOffset)
32 const targetNode = editorRoot.children[pathOffset]
33
34 const delta = yTextToInsertDelta(yRoot)
35 const targetLength = getEditorNodeYLength(targetNode)
36
37 const targetDelta = sliceInsertDelta(delta, yOffset, targetLength)
38 if (targetDelta.length > 1) {
39 throw new Error("Path doesn't match yText, yTarget spans multiple nodes")
40 }
41
42 const yTarget = targetDelta[0]?.insert
43 if (childPath.length > 0) {
44 if (!(yTarget instanceof Y.XmlText)) {
45 throw new Error("Path doesn't match yText, cannot descent into non-yText")
46 }
47
48 return getYTarget(yTarget, targetNode, childPath)
49 }
50
51 return {
52 yParent: yRoot,
53 textRange: { start: yOffset, end: yOffset + targetLength },
54 yTarget: yTarget instanceof Y.XmlText ? yTarget : undefined,
55 editorParent: editorRoot,
56 editorTarget: targetNode,
57 targetDelta,
58 }
59}
60
61export function yOffsetToEditorOffsets(
62 parent: Element,

Callers 9

insertTextFunction · 0.90
removeTextFunction · 0.90
removeNodeFunction · 0.90
insertNodeFunction · 0.90
setNodeFunction · 0.90
mergeNodeFunction · 0.90
moveNodeFunction · 0.90
splitNodeFunction · 0.90

Calls 4

yTextToInsertDeltaFunction · 0.90
sliceInsertDeltaFunction · 0.90
getEditorNodeYLengthFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…