Skip to content

Commit f56feb9

Browse files
committed
Rename
1 parent fd9133d commit f56feb9

File tree

8 files changed

+51
-51
lines changed

8 files changed

+51
-51
lines changed

src/core/commands/edit.spec.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from "vitest";
22
import { deleteEdit, insertEdit } from "./edit";
3-
import type { DomSnapshot, SelectionSnapshot, Writeable } from "../types";
3+
import type { DocFragment, SelectionSnapshot, Writeable } from "../types";
44

55
const splitAt = (targetStr: string, index: number): [string, string] => {
66
return [targetStr.slice(0, index), targetStr.slice(index)];
@@ -43,7 +43,7 @@ describe(insertEdit.name, () => {
4343
it("insert text at line before caret", () => {
4444
const docText = "abcde";
4545
const docText2 = "fghij";
46-
const doc: Writeable<DomSnapshot> = [[docText], [docText2]];
46+
const doc: Writeable<DocFragment> = [[docText], [docText2]];
4747
const sel: Writeable<SelectionSnapshot> = [
4848
[1, 2],
4949
[1, 2],
@@ -59,7 +59,7 @@ describe(insertEdit.name, () => {
5959
it("insert lines at line before caret", () => {
6060
const docText = "abcde";
6161
const docText2 = "fghij";
62-
const doc: Writeable<DomSnapshot> = [[docText], [docText2]];
62+
const doc: Writeable<DocFragment> = [[docText], [docText2]];
6363
const sel: Writeable<SelectionSnapshot> = [
6464
[1, 2],
6565
[1, 2],
@@ -76,7 +76,7 @@ describe(insertEdit.name, () => {
7676

7777
it("insert text before caret", () => {
7878
const docText = "abcde";
79-
const doc: Writeable<DomSnapshot> = [[docText]];
79+
const doc: Writeable<DocFragment> = [[docText]];
8080
const sel: Writeable<SelectionSnapshot> = [
8181
[0, 2],
8282
[0, 2],
@@ -91,7 +91,7 @@ describe(insertEdit.name, () => {
9191

9292
it("insert lines before caret", () => {
9393
const docText = "abcde";
94-
const doc: Writeable<DomSnapshot> = [[docText]];
94+
const doc: Writeable<DocFragment> = [[docText]];
9595
const sel: Writeable<SelectionSnapshot> = [
9696
[0, 2],
9797
[0, 2],
@@ -110,7 +110,7 @@ describe(insertEdit.name, () => {
110110

111111
it("insert text on caret", () => {
112112
const docText = "abcde";
113-
const doc: Writeable<DomSnapshot> = [[docText]];
113+
const doc: Writeable<DocFragment> = [[docText]];
114114
const sel: Writeable<SelectionSnapshot> = [
115115
[0, 2],
116116
[0, 2],
@@ -125,7 +125,7 @@ describe(insertEdit.name, () => {
125125

126126
it("insert lines on caret", () => {
127127
const docText = "abcde";
128-
const doc: Writeable<DomSnapshot> = [[docText]];
128+
const doc: Writeable<DocFragment> = [[docText]];
129129
const sel: Writeable<SelectionSnapshot> = [
130130
[0, 2],
131131
[0, 2],
@@ -144,7 +144,7 @@ describe(insertEdit.name, () => {
144144

145145
it("insert text inside selection", () => {
146146
const docText = "abcde";
147-
const doc: Writeable<DomSnapshot> = [[docText]];
147+
const doc: Writeable<DocFragment> = [[docText]];
148148
const sel: Writeable<SelectionSnapshot> = [
149149
[0, 1],
150150
[0, 3],
@@ -159,7 +159,7 @@ describe(insertEdit.name, () => {
159159

160160
it("insert lines inside selection", () => {
161161
const docText = "abcde";
162-
const doc: Writeable<DomSnapshot> = [[docText]];
162+
const doc: Writeable<DocFragment> = [[docText]];
163163
const sel: Writeable<SelectionSnapshot> = [
164164
[0, 1],
165165
[0, 3],
@@ -181,7 +181,7 @@ describe(insertEdit.name, () => {
181181

182182
it("insert text after caret", () => {
183183
const docText = "abcde";
184-
const doc: Writeable<DomSnapshot> = [[docText]];
184+
const doc: Writeable<DocFragment> = [[docText]];
185185
const sel: Writeable<SelectionSnapshot> = [
186186
[0, 2],
187187
[0, 2],
@@ -196,7 +196,7 @@ describe(insertEdit.name, () => {
196196

197197
it("insert lines after caret", () => {
198198
const docText = "abcde";
199-
const doc: Writeable<DomSnapshot> = [[docText]];
199+
const doc: Writeable<DocFragment> = [[docText]];
200200
const sel: Writeable<SelectionSnapshot> = [
201201
[0, 2],
202202
[0, 2],
@@ -214,7 +214,7 @@ describe(insertEdit.name, () => {
214214
it("insert text at line after caret", () => {
215215
const docText = "abcde";
216216
const docText2 = "fghij";
217-
const doc: Writeable<DomSnapshot> = [[docText], [docText2]];
217+
const doc: Writeable<DocFragment> = [[docText], [docText2]];
218218
const sel: Writeable<SelectionSnapshot> = [
219219
[0, 2],
220220
[0, 2],
@@ -230,7 +230,7 @@ describe(insertEdit.name, () => {
230230
it("insert lines at line after caret", () => {
231231
const docText = "abcde";
232232
const docText2 = "fghij";
233-
const doc: Writeable<DomSnapshot> = [[docText], [docText2]];
233+
const doc: Writeable<DocFragment> = [[docText], [docText2]];
234234
const sel: Writeable<SelectionSnapshot> = [
235235
[0, 2],
236236
[0, 2],
@@ -249,12 +249,12 @@ describe(insertEdit.name, () => {
249249
describe(deleteEdit.name, () => {
250250
it("do nothing if start and end is the same", () => {
251251
const docText = "abcde";
252-
const doc: Writeable<DomSnapshot> = [[docText]];
252+
const doc: Writeable<DocFragment> = [[docText]];
253253
const sel: Writeable<SelectionSnapshot> = [
254254
[0, 2],
255255
[0, 2],
256256
];
257-
const initialDoc: DomSnapshot = structuredClone(doc);
257+
const initialDoc: DocFragment = structuredClone(doc);
258258
const initialSel: SelectionSnapshot = structuredClone(sel);
259259
deleteEdit(doc, sel, [0, 1], [0, 1]);
260260

@@ -265,7 +265,7 @@ describe(deleteEdit.name, () => {
265265
it("delete text at line before caret", () => {
266266
const docText = "abcde";
267267
const docText2 = "fghij";
268-
const doc: Writeable<DomSnapshot> = [[docText], [docText2]];
268+
const doc: Writeable<DocFragment> = [[docText], [docText2]];
269269
const sel: Writeable<SelectionSnapshot> = [
270270
[1, 2],
271271
[1, 2],
@@ -280,7 +280,7 @@ describe(deleteEdit.name, () => {
280280
it("delete linebreak at line before caret", () => {
281281
const docText = "abcde";
282282
const docText2 = "fghij";
283-
const doc: Writeable<DomSnapshot> = [[docText], [docText2]];
283+
const doc: Writeable<DocFragment> = [[docText], [docText2]];
284284
const sel: Writeable<SelectionSnapshot> = [
285285
[1, 3],
286286
[1, 3],
@@ -299,7 +299,7 @@ describe(deleteEdit.name, () => {
299299

300300
it("delete text before caret", () => {
301301
const docText = "abcde";
302-
const doc: Writeable<DomSnapshot> = [[docText]];
302+
const doc: Writeable<DocFragment> = [[docText]];
303303
const sel: Writeable<SelectionSnapshot> = [
304304
[0, 3],
305305
[0, 3],
@@ -313,7 +313,7 @@ describe(deleteEdit.name, () => {
313313

314314
it("delete text just before caret", () => {
315315
const docText = "abcde";
316-
const doc: Writeable<DomSnapshot> = [[docText]];
316+
const doc: Writeable<DocFragment> = [[docText]];
317317
const sel: Writeable<SelectionSnapshot> = [
318318
[0, 3],
319319
[0, 3],
@@ -327,7 +327,7 @@ describe(deleteEdit.name, () => {
327327

328328
it("delete text around caret", () => {
329329
const docText = "abcde";
330-
const doc: Writeable<DomSnapshot> = [[docText]];
330+
const doc: Writeable<DocFragment> = [[docText]];
331331
const sel: Writeable<SelectionSnapshot> = [
332332
[0, 3],
333333
[0, 3],
@@ -341,7 +341,7 @@ describe(deleteEdit.name, () => {
341341

342342
it("delete text around selection", () => {
343343
const docText = "abcde";
344-
const doc: Writeable<DomSnapshot> = [[docText]];
344+
const doc: Writeable<DocFragment> = [[docText]];
345345
const sel: Writeable<SelectionSnapshot> = [
346346
[0, 2],
347347
[0, 4],
@@ -357,7 +357,7 @@ describe(deleteEdit.name, () => {
357357

358358
it("delete text around selection anchor", () => {
359359
const docText = "abcde";
360-
const doc: Writeable<DomSnapshot> = [[docText]];
360+
const doc: Writeable<DocFragment> = [[docText]];
361361
const sel: Writeable<SelectionSnapshot> = [
362362
[0, 2],
363363
[0, 4],
@@ -371,7 +371,7 @@ describe(deleteEdit.name, () => {
371371

372372
it("delete text around selection focus", () => {
373373
const docText = "abcde";
374-
const doc: Writeable<DomSnapshot> = [[docText]];
374+
const doc: Writeable<DocFragment> = [[docText]];
375375
const sel: Writeable<SelectionSnapshot> = [
376376
[0, 2],
377377
[0, 4],
@@ -386,7 +386,7 @@ describe(deleteEdit.name, () => {
386386
it("delete linebreak inside selection", () => {
387387
const docText = "abcde";
388388
const docText2 = "fghij";
389-
const doc: Writeable<DomSnapshot> = [[docText], [docText2]];
389+
const doc: Writeable<DocFragment> = [[docText], [docText2]];
390390
const sel: Writeable<SelectionSnapshot> = [
391391
[0, 2],
392392
[1, 2],
@@ -402,7 +402,7 @@ describe(deleteEdit.name, () => {
402402

403403
it("delete text just after caret", () => {
404404
const docText = "abcde";
405-
const doc: Writeable<DomSnapshot> = [[docText]];
405+
const doc: Writeable<DocFragment> = [[docText]];
406406
const sel: Writeable<SelectionSnapshot> = [
407407
[0, 3],
408408
[0, 3],
@@ -416,7 +416,7 @@ describe(deleteEdit.name, () => {
416416

417417
it("delete text after caret", () => {
418418
const docText = "abcde";
419-
const doc: Writeable<DomSnapshot> = [[docText]];
419+
const doc: Writeable<DocFragment> = [[docText]];
420420
const sel: Writeable<SelectionSnapshot> = [
421421
[0, 3],
422422
[0, 3],
@@ -431,7 +431,7 @@ describe(deleteEdit.name, () => {
431431
it("delete text at line after caret", () => {
432432
const docText = "abcde";
433433
const docText2 = "fghij";
434-
const doc: Writeable<DomSnapshot> = [[docText], [docText2]];
434+
const doc: Writeable<DocFragment> = [[docText], [docText2]];
435435
const sel: Writeable<SelectionSnapshot> = [
436436
[0, 2],
437437
[0, 2],
@@ -447,7 +447,7 @@ describe(deleteEdit.name, () => {
447447
const docText = "abcde";
448448
const docText2 = "fghij";
449449
const docText3 = "klmno";
450-
const doc: Writeable<DomSnapshot> = [[docText], [docText2], [docText3]];
450+
const doc: Writeable<DocFragment> = [[docText], [docText2], [docText3]];
451451
const sel: Writeable<SelectionSnapshot> = [
452452
[0, 2],
453453
[0, 2],

src/core/commands/edit.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { compareLine, comparePosition } from "../position";
22
import {
3-
DomSnapshot,
3+
DocFragment,
44
NodeRef,
55
Position,
66
SelectionSnapshot,
@@ -93,8 +93,8 @@ const fixPositionAfterDelete = (
9393
};
9494

9595
const replaceRange = (
96-
doc: Writeable<DomSnapshot>,
97-
fragment: DomSnapshot,
96+
doc: Writeable<DocFragment>,
97+
fragment: DocFragment,
9898
start: Position,
9999
end?: Position
100100
) => {
@@ -120,9 +120,9 @@ const replaceRange = (
120120
* @internal
121121
*/
122122
export const insertEdit = (
123-
doc: Writeable<DomSnapshot>,
123+
doc: Writeable<DocFragment>,
124124
selection: Writeable<SelectionSnapshot>,
125-
lines: DomSnapshot,
125+
lines: DocFragment,
126126
pos: Position
127127
) => {
128128
const [anchor, focus] = selection;
@@ -148,7 +148,7 @@ export const insertEdit = (
148148
* @internal
149149
*/
150150
export const deleteEdit = (
151-
doc: Writeable<DomSnapshot>,
151+
doc: Writeable<DocFragment>,
152152
selection: Writeable<SelectionSnapshot>,
153153
start: Position,
154154
end: Position
@@ -169,9 +169,9 @@ export const deleteEdit = (
169169
* @internal
170170
*/
171171
export const flatten = (
172-
doc: DomSnapshot,
172+
doc: DocFragment,
173173
[[anchorLine, anchorOffset], [focusLine, focusOffset]]: SelectionSnapshot
174-
): [DomSnapshot, SelectionSnapshot] => {
174+
): [DocFragment, SelectionSnapshot] => {
175175
let offsetBeforeAnchor = 0;
176176
let offsetBeforeFocus = 0;
177177

src/core/commands/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {
2-
DomSnapshot,
2+
DocFragment,
33
Position,
44
SelectionSnapshot,
55
Writeable,
@@ -11,7 +11,7 @@ import { deleteEdit, insertEdit } from "./edit";
1111
* @internal
1212
*/
1313
export type EditableCommand<T extends unknown[]> = (
14-
doc: Writeable<DomSnapshot>,
14+
doc: Writeable<DocFragment>,
1515
selection: Writeable<SelectionSnapshot>,
1616
...args: T
1717
) => void;
@@ -40,7 +40,7 @@ export const Delete: EditableCommand<[range?: SelectionSnapshot]> = (
4040
/**
4141
* @internal
4242
*/
43-
export const InsertFragment: EditableCommand<[lines: DomSnapshot]> = (
43+
export const InsertFragment: EditableCommand<[lines: DocFragment]> = (
4444
doc,
4545
selection,
4646
lines

src/core/dom/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
ParserConfig,
1212
} from "./parser";
1313
import { comparePosition } from "../position";
14-
import { DomSnapshot, Position, NodeRef, SelectionSnapshot } from "../types";
14+
import { DocFragment, Position, NodeRef, SelectionSnapshot } from "../types";
1515
import { min } from "../utils";
1616

1717
// const DOCUMENT_POSITION_DISCONNECTED = 0x01;
@@ -298,7 +298,7 @@ export const takeDomSnapshot = (
298298
document: Document,
299299
root: Node,
300300
config: ParserConfig
301-
): DomSnapshot => {
301+
): DocFragment => {
302302
return parse(
303303
(readNext) => {
304304
let type: NodeType | void;

src/core/editable.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
getPointedCaretPosition,
1010
} from "./dom";
1111
import { createMutationObserver } from "./mutation";
12-
import { DomSnapshot, SelectionSnapshot, Writeable } from "./types";
12+
import { DocFragment, SelectionSnapshot, Writeable } from "./types";
1313
import { microtask } from "./utils";
1414
import {
1515
Delete,
@@ -218,7 +218,7 @@ export const editable = <T>(
218218
};
219219

220220
const updateState = (
221-
dom: DomSnapshot,
221+
dom: DocFragment,
222222
selection: SelectionSnapshot,
223223
prevSelection: SelectionSnapshot
224224
) => {
@@ -295,11 +295,11 @@ export const editable = <T>(
295295
const flushCommand = () => {
296296
if (commands.length) {
297297
const selection: Writeable<SelectionSnapshot> = [...currentSelection];
298-
const dom: Writeable<DomSnapshot> = takeDomSnapshot(
298+
const dom: Writeable<DocFragment> = takeDomSnapshot(
299299
document,
300300
element,
301301
parserConfig
302-
) as Writeable<DomSnapshot>; // TODO improve type
302+
) as Writeable<DocFragment>; // TODO improve type
303303

304304
let command: (typeof commands)[number] | undefined;
305305
while ((command = commands.pop())) {

src/core/schema/plain.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { DomSnapshot } from "../types";
1+
import type { DocFragment } from "../types";
22
import type { EditableSchema } from "./types";
33

4-
const serializeToString = (snapshot: DomSnapshot): string => {
4+
const serializeToString = (snapshot: DocFragment): string => {
55
return snapshot.reduce((acc, r, i) => {
66
if (i !== 0) {
77
acc += "\n";

src/core/schema/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { DomSnapshot } from "../types";
1+
import type { DocFragment } from "../types";
22

33
export interface EditableSchema<T> {
44
single: boolean;
5-
data: (snapshot: DomSnapshot) => T;
6-
copy: (dataTransfer: DataTransfer, snapshot: DomSnapshot, dom: Node) => void;
5+
data: (snapshot: DocFragment) => T;
6+
copy: (dataTransfer: DataTransfer, snapshot: DocFragment, dom: Node) => void;
77
paste: (dataTransfer: DataTransfer) => Node | string;
88
}
99

0 commit comments

Comments
 (0)