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

Function normalizeInsertDelta

packages/yjs-transform/src/delta.ts:5–33  ·  view source on GitHub ↗
(delta: InsertDelta)

Source from the content-addressed store, hash-verified

3import { deepEquals } from './object'
4
5export function normalizeInsertDelta(delta: InsertDelta): InsertDelta {
6 const normalized: InsertDelta = []
7
8 for (const element of delta) {
9 if (typeof element.insert === 'string' && element.insert.length === 0) {
10 continue
11 }
12
13 const prev = normalized[normalized.length - 1]
14 if (!prev || typeof prev.insert !== 'string' || typeof element.insert !== 'string') {
15 normalized.push(element)
16 continue
17 }
18
19 const merge =
20 prev.attributes === element.attributes ||
21 (!prev.attributes === !element.attributes &&
22 deepEquals(prev.attributes ?? {}, element.attributes ?? {}))
23
24 if (merge) {
25 prev.insert += element.insert
26 continue
27 }
28
29 normalized.push(element)
30 }
31
32 return normalized
33}
34
35export function yTextToInsertDelta(yText: Y.XmlText): InsertDelta {
36 return normalizeInsertDelta(yText.toDelta()) as InsertDelta

Callers 1

yTextToInsertDeltaFunction · 0.85

Calls 1

deepEqualsFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…