Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | 44x 44x 44x 44x 44x 44x 44x 7698x 7698x 7698x 7698x 7698x 7698x 9195x 9195x 9195x 2465x 6730x 44x 4536x 4536x 4536x 4536x 4536x 4536x 4536x 3121x 3121x 9144x 9144x 9144x 5837x 5837x 3307x 3307x 1770x 4536x 4536x 4536x 4536x 7207x 7207x 7207x 2311x 4536x 44x 7551x 7551x 7551x 5255x 908x 908x 4347x 4347x 4347x 44x 1x 1x 13443x 13443x 13443x 13443x 13443x 27409x 27409x 27409x 15321x 15321x 15321x 12088x 4537x 7551x 7551x 7551x 7551x 7535x 7535x 7535x 7535x 16x 16x 16x 16x 16x | import {QuillConst} from './constants'; import {NodeApi} from '../../json-crdt/model/api/nodes'; import {konst} from '../../json-crdt-patch/builder/Konst'; import {SliceBehavior} from '../peritext/slice/constants'; import {PersistedSlice} from '../peritext/slice/PersistedSlice'; import {diffAttributes, getAttributes, removeErasures} from './util'; import type {PathStep} from '@jsonjoy.com/json-pointer'; import type {QuillDeltaNode} from './QuillDeltaNode'; import type {ArrApi, ArrNode, ExtApi, StrApi} from '../../json-crdt'; import type { QuillDeltaAttributes, QuillDeltaOpDelete, QuillDeltaOpInsert, QuillDeltaOpRetain, QuillDeltaPatch, } from './types'; import type {Peritext} from '../peritext'; import type {SliceNode} from '../peritext/slice/types'; const updateAttributes = (txt: Peritext, attributes: QuillDeltaAttributes | undefined, pos: number, len: number) => { Iif (!attributes) return; const range = txt.rangeAt(pos, len); const keys = Object.keys(attributes); const length = keys.length; const savedSlices = txt.savedSlices; for (let i = 0; i < length; i++) { const key = keys[i]; const value = attributes[key]; if (value === null) { savedSlices.ins(range, SliceBehavior.Erase, key); } else { savedSlices.ins(range, SliceBehavior.One, key, konst(value)); } } }; const rewriteAttributes = (txt: Peritext, attributes: QuillDeltaAttributes | undefined, pos: number, len: number) => { Iif (typeof attributes !== 'object') return; const range = txt.rangeAt(pos, len); range.expand(); const slices = txt.overlay.findOverlapping(range); const length = slices.size; const relevantOverlappingButNotContained = new Set<PathStep>(); if (length) { const savedSlices = txt.savedSlices; // biome-ignore lint: slices is not iterable slices.forEach((slice) => { if (slice instanceof PersistedSlice) { const isContained = range.contains(slice); if (!isContained) { relevantOverlappingButNotContained.add(slice.type as PathStep); return; } const type = slice.type as PathStep; if (type in attributes) { savedSlices.del(slice.id); } } }); } const keys = Object.keys(attributes); const attributeLength = keys.length; const attributesCopy = {...attributes}; for (let i = 0; i < attributeLength; i++) { const key = keys[i]; const value = attributes[key]; if (value === null && !relevantOverlappingButNotContained.has(key)) { delete attributesCopy[key]; } } updateAttributes(txt, attributesCopy, pos, len); }; const maybeUpdateAttributes = ( txt: Peritext, attributes: QuillDeltaAttributes | undefined, pos: number, len: number, ): void => { const range = txt.rangeAt(pos, 1); const overlayPoint = txt.overlay.getOrNextLower(range.start); if (!overlayPoint && !attributes) return; if (!overlayPoint) { updateAttributes(txt, removeErasures(attributes), pos, len); return; } const pointAttributes = getAttributes(overlayPoint); const attributeDiff = diffAttributes(pointAttributes, attributes); if (attributeDiff) updateAttributes(txt, attributeDiff, pos, len); }; export class QuillDeltaApi extends NodeApi<QuillDeltaNode> implements ExtApi<QuillDeltaNode> { public text(): StrApi { return this.api.wrap(this.node.text()); } public slices(): ArrApi<ArrNode<SliceNode>> { return this.api.wrap(this.node.slices()); } public apply(ops: QuillDeltaPatch['ops']) { const txt = this.node.txt; const overlay = txt.overlay; const length = ops.length; let pos = 0; for (let i = 0; i < length; i++) { overlay.refresh(true); const op = ops[i]; if (typeof (<QuillDeltaOpRetain>op).retain === 'number') { const {retain, attributes} = <QuillDeltaOpRetain>op; if (attributes) rewriteAttributes(txt, attributes, pos, retain); pos += retain; } else if (typeof (<QuillDeltaOpDelete>op).delete === 'number') { txt.delAt(pos, (<QuillDeltaOpDelete>op).delete); } else if ((<QuillDeltaOpInsert>op).insert) { const {insert} = <QuillDeltaOpInsert>op; let {attributes} = <QuillDeltaOpInsert>op; if (typeof insert === 'string') { txt.insAt(pos, insert); const insertLength = insert.length; maybeUpdateAttributes(txt, attributes, pos, insertLength); pos += insertLength; } else { txt.insAt(pos, QuillConst.EmbedChar); if (!attributes) attributes = {}; attributes[QuillConst.EmbedSliceType] = insert; maybeUpdateAttributes(txt, attributes, pos, 1); pos += 1; } } } } } |