@folijs/core 0.6.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +159 -0
- package/README.md +1 -1
- package/dist/document.d.ts +0 -7
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +5 -1
- package/dist/document.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +5 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +7 -0
- package/dist/internal.js.map +1 -0
- package/dist/model/attrs.d.ts +0 -10
- package/dist/model/attrs.d.ts.map +1 -1
- package/dist/model/attrs.js +10 -2
- package/dist/model/attrs.js.map +1 -1
- package/dist/model/content.d.ts +1 -1
- package/dist/model/content.d.ts.map +1 -1
- package/dist/model/content.js +1 -1
- package/dist/model/content.js.map +1 -1
- package/dist/model/errors.d.ts +0 -2
- package/dist/model/errors.d.ts.map +1 -1
- package/dist/model/errors.js +4 -1
- package/dist/model/errors.js.map +1 -1
- package/dist/model/fragment.d.ts +1 -1
- package/dist/model/fragment.d.ts.map +1 -1
- package/dist/model/fragment.js +3 -1
- package/dist/model/fragment.js.map +1 -1
- package/dist/model/mark.d.ts +1 -1
- package/dist/model/mark.d.ts.map +1 -1
- package/dist/model/mark.js +1 -1
- package/dist/model/mark.js.map +1 -1
- package/dist/model/node.d.ts +4 -4
- package/dist/model/node.d.ts.map +1 -1
- package/dist/model/node.js +8 -4
- package/dist/model/node.js.map +1 -1
- package/dist/model/schema.d.ts +8 -8
- package/dist/model/schema.d.ts.map +1 -1
- package/dist/model/schema.js +4 -3
- package/dist/model/schema.js.map +1 -1
- package/dist/schema.d.ts +0 -11
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2 -0
- package/dist/schema.js.map +1 -1
- package/dist/state/attempt.d.ts +1 -3
- package/dist/state/attempt.d.ts.map +1 -1
- package/dist/state/comments.d.ts +1 -7
- package/dist/state/comments.d.ts.map +1 -1
- package/dist/state/comments.js +1 -0
- package/dist/state/comments.js.map +1 -1
- package/dist/state/controls.d.ts +1 -19
- package/dist/state/controls.d.ts.map +1 -1
- package/dist/state/controls.js +21 -7
- package/dist/state/controls.js.map +1 -1
- package/dist/state/editor.d.ts +107 -72
- package/dist/state/editor.d.ts.map +1 -1
- package/dist/state/editor.js +121 -61
- package/dist/state/editor.js.map +1 -1
- package/dist/state/fields.d.ts +1 -12
- package/dist/state/fields.d.ts.map +1 -1
- package/dist/state/fields.js +16 -4
- package/dist/state/fields.js.map +1 -1
- package/dist/state/fieldupdate.d.ts +1 -47
- package/dist/state/fieldupdate.d.ts.map +1 -1
- package/dist/state/fieldupdate.js +1 -0
- package/dist/state/fieldupdate.js.map +1 -1
- package/dist/state/find.d.ts +1 -3
- package/dist/state/find.d.ts.map +1 -1
- package/dist/state/find.js +10 -2
- package/dist/state/find.js.map +1 -1
- package/dist/state/history.d.ts +1 -10
- package/dist/state/history.d.ts.map +1 -1
- package/dist/state/history.js +1 -0
- package/dist/state/history.js.map +1 -1
- package/dist/state/index.d.ts +4 -4
- package/dist/state/index.d.ts.map +1 -1
- package/dist/state/index.js +4 -4
- package/dist/state/index.js.map +1 -1
- package/dist/state/lists.d.ts +3 -3
- package/dist/state/lists.d.ts.map +1 -1
- package/dist/state/lists.js.map +1 -1
- package/dist/state/mark.d.ts +1 -17
- package/dist/state/mark.d.ts.map +1 -1
- package/dist/state/mark.js +2 -0
- package/dist/state/mark.js.map +1 -1
- package/dist/state/notes.d.ts +2 -12
- package/dist/state/notes.d.ts.map +1 -1
- package/dist/state/notes.js +10 -3
- package/dist/state/notes.js.map +1 -1
- package/dist/state/review.d.ts +1 -6
- package/dist/state/review.d.ts.map +1 -1
- package/dist/state/review.js +1 -0
- package/dist/state/review.js.map +1 -1
- package/dist/state/sections.d.ts +1 -11
- package/dist/state/sections.d.ts.map +1 -1
- package/dist/state/sections.js +10 -3
- package/dist/state/sections.js.map +1 -1
- package/dist/state/state.d.ts +13 -9
- package/dist/state/state.d.ts.map +1 -1
- package/dist/state/state.js +5 -2
- package/dist/state/state.js.map +1 -1
- package/dist/state/stories.d.ts +1 -40
- package/dist/state/stories.d.ts.map +1 -1
- package/dist/state/stories.js +18 -2
- package/dist/state/stories.js.map +1 -1
- package/dist/state/tables.d.ts +1 -36
- package/dist/state/tables.d.ts.map +1 -1
- package/dist/state/tables.js +23 -5
- package/dist/state/tables.js.map +1 -1
- package/dist/state/track.d.ts +1 -29
- package/dist/state/track.d.ts.map +1 -1
- package/dist/state/track.js +9 -2
- package/dist/state/track.js.map +1 -1
- package/dist/state/word.d.ts +8 -78
- package/dist/state/word.d.ts.map +1 -1
- package/dist/state/word.js +95 -28
- package/dist/state/word.js.map +1 -1
- package/dist/state/wordclip.d.ts +3 -1
- package/dist/state/wordclip.d.ts.map +1 -1
- package/dist/state/wordclip.js +67 -8
- package/dist/state/wordclip.js.map +1 -1
- package/dist/state/wordformat.d.ts +1 -86
- package/dist/state/wordformat.d.ts.map +1 -1
- package/dist/state/wordformat.js +54 -11
- package/dist/state/wordformat.js.map +1 -1
- package/dist/transform/stepmap.d.ts +0 -2
- package/dist/transform/stepmap.d.ts.map +1 -1
- package/dist/v3/check.d.ts +0 -25
- package/dist/v3/check.d.ts.map +1 -1
- package/dist/v3/check.js +35 -7
- package/dist/v3/check.js.map +1 -1
- package/dist/v3/document.d.ts +8 -6
- package/dist/v3/document.d.ts.map +1 -1
- package/dist/v3/document.js +28 -16
- package/dist/v3/document.js.map +1 -1
- package/dist/v3/extensions.d.ts +43 -0
- package/dist/v3/extensions.d.ts.map +1 -0
- package/dist/v3/extensions.js +154 -0
- package/dist/v3/extensions.js.map +1 -0
- package/dist/v3/index.d.ts +2 -1
- package/dist/v3/index.d.ts.map +1 -1
- package/dist/v3/index.js +2 -1
- package/dist/v3/index.js.map +1 -1
- package/dist/v3/resolve.d.ts.map +1 -1
- package/dist/v3/resolve.js +6 -0
- package/dist/v3/resolve.js.map +1 -1
- package/dist/v3/schema.d.ts +5 -18
- package/dist/v3/schema.d.ts.map +1 -1
- package/dist/v3/schema.js +79 -5
- package/dist/v3/schema.js.map +1 -1
- package/package.json +5 -1
- package/src/document.ts +5 -1
- package/src/index.ts +330 -4
- package/src/internal.ts +50 -0
- package/src/model/attrs.ts +10 -2
- package/src/model/content.ts +1 -1
- package/src/model/errors.ts +4 -1
- package/src/model/fragment.ts +2 -1
- package/src/model/mark.ts +1 -1
- package/src/model/node.ts +6 -4
- package/src/model/schema.ts +9 -3
- package/src/schema.ts +2 -0
- package/src/state/comments.ts +1 -0
- package/src/state/controls.ts +25 -9
- package/src/state/editor.ts +251 -130
- package/src/state/fields.ts +16 -4
- package/src/state/fieldupdate.ts +1 -0
- package/src/state/find.ts +12 -4
- package/src/state/history.ts +2 -0
- package/src/state/index.ts +5 -4
- package/src/state/lists.ts +2 -2
- package/src/state/mark.ts +2 -0
- package/src/state/notes.ts +27 -17
- package/src/state/review.ts +1 -0
- package/src/state/sections.ts +10 -3
- package/src/state/state.ts +16 -3
- package/src/state/stories.ts +32 -5
- package/src/state/tables.ts +27 -6
- package/src/state/track.ts +9 -2
- package/src/state/word.ts +105 -32
- package/src/state/wordclip.ts +76 -8
- package/src/state/wordformat.ts +55 -11
- package/src/v3/check.ts +35 -7
- package/src/v3/document.ts +39 -16
- package/src/v3/extensions.ts +201 -0
- package/src/v3/index.ts +9 -0
- package/src/v3/resolve.ts +5 -0
- package/src/v3/schema.ts +83 -5
package/src/state/index.ts
CHANGED
|
@@ -49,17 +49,21 @@ export {
|
|
|
49
49
|
setControlValue,
|
|
50
50
|
} from "./controls.js";
|
|
51
51
|
export {
|
|
52
|
+
type BuiltInCommands,
|
|
52
53
|
createEditor,
|
|
53
54
|
type DocumentTarget,
|
|
54
55
|
type Editor,
|
|
55
56
|
type EditorDocument,
|
|
56
57
|
type EditorListener,
|
|
57
58
|
type EditorOptions,
|
|
59
|
+
editorCommand,
|
|
60
|
+
type FoliCommands,
|
|
58
61
|
type FoundMatches,
|
|
59
62
|
type NavigationRequest,
|
|
60
63
|
type OpenStory,
|
|
61
64
|
type StoryView,
|
|
62
65
|
sectionSettings,
|
|
66
|
+
viewKeys,
|
|
63
67
|
} from "./editor.js";
|
|
64
68
|
export {
|
|
65
69
|
caretStop,
|
|
@@ -161,7 +165,6 @@ export {
|
|
|
161
165
|
convertNotes,
|
|
162
166
|
type InsertNoteOptions,
|
|
163
167
|
insertNote,
|
|
164
|
-
isNote,
|
|
165
168
|
type NoteKind,
|
|
166
169
|
type NoteNumber,
|
|
167
170
|
type NoteNumberOptions,
|
|
@@ -222,7 +225,6 @@ export {
|
|
|
222
225
|
} from "./selection.js";
|
|
223
226
|
export {
|
|
224
227
|
type Command,
|
|
225
|
-
defaultTextblockType,
|
|
226
228
|
EditorState,
|
|
227
229
|
type EditorStateConfig,
|
|
228
230
|
Plugin,
|
|
@@ -267,11 +269,10 @@ export {
|
|
|
267
269
|
} from "./track.js";
|
|
268
270
|
export {
|
|
269
271
|
CommentStep,
|
|
272
|
+
documentJSON,
|
|
270
273
|
EnvelopeStep,
|
|
271
|
-
type Story,
|
|
272
274
|
StoryStep,
|
|
273
275
|
setComments,
|
|
274
|
-
storyBody,
|
|
275
276
|
type WordContext,
|
|
276
277
|
type WordEnvelope,
|
|
277
278
|
withEnvelope,
|
package/src/state/lists.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Command, Plugin } from "./state.js";
|
|
1
|
+
import { type Command, type EditorState, Plugin } from "./state.js";
|
|
2
2
|
import {
|
|
3
3
|
endWordList,
|
|
4
4
|
type ListKind,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "./wordformat.js";
|
|
12
12
|
|
|
13
13
|
/** The kind of list all selected paragraphs are in ("bulletList", "orderedList"), or null. */
|
|
14
|
-
export const listKindAt = wordListKindAt;
|
|
14
|
+
export const listKindAt: (state: EditorState) => ListKind | null = wordListKindAt;
|
|
15
15
|
|
|
16
16
|
/** Numbers the selected paragraphs as a list of `kind` (one right before goes on). */
|
|
17
17
|
export const wrapInList: (kind: ListKind) => Command = wrapInWordList;
|
package/src/state/mark.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { Transform } from "../transform/transform.js";
|
|
|
10
10
|
* Attributes the paragraph mark carries in Word (schema v3): the section break, the mark's
|
|
11
11
|
* tracked change and the paragraph's own attributes (`w14:paraId`). Whichever paragraph keeps
|
|
12
12
|
* the mark keeps them.
|
|
13
|
+
* @internal
|
|
13
14
|
*/
|
|
14
15
|
export const MARK_ATTRS = ["section", "revision", "formatChange", "attributes"] as const;
|
|
15
16
|
|
|
@@ -30,6 +31,7 @@ const MARKERS = new Set([
|
|
|
30
31
|
* (it was empty, or deleted from its start), it is gone: the last one stays whole, as in Word.
|
|
31
32
|
* `tail` is where the content kept of the last one starts in it (a deletion into it). Nothing for
|
|
32
33
|
* a schema without them (v2).
|
|
34
|
+
* @internal
|
|
33
35
|
*/
|
|
34
36
|
export function keepLastMark(tr: Transform, pos: number, last: Node, tail = 0): void {
|
|
35
37
|
const merged = tr.doc.nodeAt(pos);
|
package/src/state/notes.ts
CHANGED
|
@@ -49,7 +49,10 @@ export function noteKindOf(id: string): NoteKind | null {
|
|
|
49
49
|
return id.startsWith("footnote:") ? "footnote" : id.startsWith("endnote:") ? "endnote" : null;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Whether `story` is a note with a text: not one of the separators.
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
53
56
|
export const isNote = (story: Pick<StoryJSON, "kind" | "noteType"> | undefined): boolean =>
|
|
54
57
|
(story?.kind === "footnote" || story?.kind === "endnote") &&
|
|
55
58
|
(story.noteType ?? "normal") === "normal";
|
|
@@ -210,7 +213,10 @@ function freshNoteId(state: EditorState, kind: NoteKind, taken: ReadonlySet<stri
|
|
|
210
213
|
return `${kind}:${max + 1}`;
|
|
211
214
|
}
|
|
212
215
|
|
|
213
|
-
/**
|
|
216
|
+
/**
|
|
217
|
+
* Makes the story ids of new notes, none used before.
|
|
218
|
+
* @internal
|
|
219
|
+
*/
|
|
214
220
|
export function noteIds(state: EditorState): (kind: NoteKind) => string {
|
|
215
221
|
const taken = new Set<string>();
|
|
216
222
|
return (kind) => {
|
|
@@ -272,21 +278,24 @@ export function insertNote(kind: NoteKind = "footnote", options: InsertNoteOptio
|
|
|
272
278
|
const mark = { type: "characterStyle", attrs: { id: styles.reference } };
|
|
273
279
|
const story: Story = {
|
|
274
280
|
kind,
|
|
275
|
-
doc: parseContent(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
281
|
+
doc: parseContent(
|
|
282
|
+
{
|
|
283
|
+
type: "doc",
|
|
284
|
+
content: [
|
|
285
|
+
{
|
|
286
|
+
type: "paragraph",
|
|
287
|
+
attrs: { style: styles.text },
|
|
288
|
+
content: [
|
|
289
|
+
custom
|
|
290
|
+
? { type: "text", text: custom, marks: [mark] }
|
|
291
|
+
: { type: "noteMark", marks: [mark] },
|
|
292
|
+
{ type: "text", text: " " },
|
|
293
|
+
],
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
},
|
|
297
|
+
{ schema: state.schema },
|
|
298
|
+
),
|
|
290
299
|
};
|
|
291
300
|
tr.step(new StoryStep(id, null, story));
|
|
292
301
|
if (styles.envelope !== context.envelope) withEnvelope(tr, styles.envelope);
|
|
@@ -480,6 +489,7 @@ function referenceMap(doc: Node): Map<string, BlockReference> {
|
|
|
480
489
|
* Keeps notes with their references, in the transaction's undo step: a reference that goes takes
|
|
481
490
|
* its note; one recorded as inserted or deleted has what the note holds recorded too; and a
|
|
482
491
|
* recorded reference accepted or rejected, and staying, settles the note's record with it.
|
|
492
|
+
* @internal
|
|
483
493
|
*/
|
|
484
494
|
export function notesPlugin(): Plugin {
|
|
485
495
|
return new Plugin({
|
package/src/state/review.ts
CHANGED
|
@@ -421,6 +421,7 @@ function join(tr: Transaction, pos: number, keepFirst: boolean): void {
|
|
|
421
421
|
/**
|
|
422
422
|
* Accepts or rejects every insertion or deletion recorded in story `id`, in `tr`: a note's, when
|
|
423
423
|
* the reference's own record is settled and the note stays.
|
|
424
|
+
* @internal
|
|
424
425
|
*/
|
|
425
426
|
export function resolveStoryChanges(
|
|
426
427
|
state: EditorState,
|
package/src/state/sections.ts
CHANGED
|
@@ -96,7 +96,10 @@ function holderFrom(doc: Node, from: number): { pos: number; node: Node } | null
|
|
|
96
96
|
return found;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* The last section's setup as `tr` leaves it.
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
100
103
|
export function lastSection(state: EditorState, tr: Transaction): SectionJSON {
|
|
101
104
|
let section = wordContext(state)?.envelope.section ?? {};
|
|
102
105
|
for (const step of tr.steps)
|
|
@@ -214,6 +217,7 @@ export function insertSectionBreak(kind: SectionBreakKind = "nextPage"): Command
|
|
|
214
217
|
* After the section `removed` ended (its break went): the section that follows `from` takes over
|
|
215
218
|
* its text, keeping its own setup, starting as `removed` started, with the header and footer
|
|
216
219
|
* references it inherited.
|
|
220
|
+
* @internal
|
|
217
221
|
*/
|
|
218
222
|
export function absorbSection(
|
|
219
223
|
state: EditorState,
|
|
@@ -434,7 +438,7 @@ function emptyStory(state: EditorState, side: StorySide): Story {
|
|
|
434
438
|
type: "doc",
|
|
435
439
|
content: [{ type: "paragraph", ...(style ? { attrs: { style: style.id } } : {}) }],
|
|
436
440
|
};
|
|
437
|
-
return { kind: side, doc: parseContent(content) };
|
|
441
|
+
return { kind: side, doc: parseContent(content, { schema: state.schema }) };
|
|
438
442
|
}
|
|
439
443
|
|
|
440
444
|
/** Makes `tr` give section `index` the reference `id` for `side` and `variant` (null: none). */
|
|
@@ -558,7 +562,10 @@ export function setDifferentEvenPages(on: boolean): Command {
|
|
|
558
562
|
return command;
|
|
559
563
|
}
|
|
560
564
|
|
|
561
|
-
/**
|
|
565
|
+
/**
|
|
566
|
+
* `section` once its tracked setup change is accepted, or rejected.
|
|
567
|
+
* @internal
|
|
568
|
+
*/
|
|
562
569
|
export function resolveSectionChange(section: SectionJSON, accept: boolean): SectionJSON {
|
|
563
570
|
const { change, ...rest } = section;
|
|
564
571
|
if (accept || !change) return rest;
|
package/src/state/state.ts
CHANGED
|
@@ -40,11 +40,21 @@ export interface PluginSpec<T> {
|
|
|
40
40
|
oldState: EditorState,
|
|
41
41
|
newState: EditorState,
|
|
42
42
|
): Transaction | null | undefined;
|
|
43
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Key name (e.g. "Mod-b", "Shift-Enter") → command. The view normalizes key events to these
|
|
45
|
+
* names. A user plugin's keymap runs before the built-in ones, so it can take any key that is
|
|
46
|
+
* not reserved (`docs/keyboard.md`).
|
|
47
|
+
*/
|
|
44
48
|
keymap?: Readonly<Record<string, Command>>;
|
|
49
|
+
/**
|
|
50
|
+
* Named command factories: `editor.commands.<name>(...args)` runs `factory(...args)`. Typed by
|
|
51
|
+
* augmenting `FoliCommands`. A name taken twice, or by a built-in command, throws in
|
|
52
|
+
* `createEditor`.
|
|
53
|
+
*/
|
|
54
|
+
commands?: Readonly<Record<string, (...args: never[]) => Command>>;
|
|
45
55
|
}
|
|
46
56
|
|
|
47
|
-
/**
|
|
57
|
+
/** A plugin: state, transaction hooks, keys and commands. Built-in features use the same API. */
|
|
48
58
|
export class Plugin<T = unknown> {
|
|
49
59
|
readonly key: PluginKey<T>;
|
|
50
60
|
|
|
@@ -171,7 +181,10 @@ export class Transaction extends Transform {
|
|
|
171
181
|
}
|
|
172
182
|
}
|
|
173
183
|
|
|
174
|
-
/**
|
|
184
|
+
/**
|
|
185
|
+
* The first textblock type of the schema (the "normal paragraph").
|
|
186
|
+
* @internal
|
|
187
|
+
*/
|
|
175
188
|
export function defaultTextblockType(schema: Schema): NodeType {
|
|
176
189
|
const type = Object.values(schema.nodes).find((t) => t.isTextblock);
|
|
177
190
|
if (!type) throw new RangeError("Schema has no textblock type");
|
package/src/state/stories.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { FoliDocumentError, type Node } from "../model/index.js";
|
|
9
9
|
import type { StoryJSON } from "../v3/document.js";
|
|
10
10
|
import { storyRules } from "../v3/document.js";
|
|
11
|
-
import type { Editor } from "./editor.js";
|
|
11
|
+
import type { Editor, EditorListener } from "./editor.js";
|
|
12
12
|
import { closeHistory, joinHistory, type StoryEdit, storyEdit } from "./history.js";
|
|
13
13
|
import { Selection, type SelectionJSON } from "./selection.js";
|
|
14
14
|
import { EditorState, Plugin, type Transaction } from "./state.js";
|
|
@@ -36,7 +36,26 @@ import {
|
|
|
36
36
|
wordContext,
|
|
37
37
|
} from "./word.js";
|
|
38
38
|
|
|
39
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Calls a listener; one that throws is reported (`console.error`) and the others still run.
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
export function callListener(
|
|
44
|
+
listener: EditorListener,
|
|
45
|
+
state: EditorState,
|
|
46
|
+
transactions: readonly Transaction[],
|
|
47
|
+
): void {
|
|
48
|
+
try {
|
|
49
|
+
listener(state, transactions);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error("Foli: an editor listener failed", error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* What a story's editor needs of the body's.
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
40
59
|
export interface StoryHost extends StoryBody {
|
|
41
60
|
/** The plugins of a story's state (keymaps, tracking, the word context). */
|
|
42
61
|
plugins(context: WordContext, track: TrackState | null): Plugin[];
|
|
@@ -85,12 +104,16 @@ function carryStoryChange(
|
|
|
85
104
|
return { after, patched };
|
|
86
105
|
}
|
|
87
106
|
|
|
88
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* What changes one tree of the document: its id (null: the body) and the edit.
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
89
111
|
export type TreeEdits = ReadonlyMap<string | null, (tr: Transaction) => void>;
|
|
90
112
|
|
|
91
113
|
/**
|
|
92
114
|
* Edits several trees as one transaction of the body, so one undo step. `tracked`: as tracked
|
|
93
115
|
* changes when tracking is on. Returns the trees whose edit was refused; the others are made.
|
|
116
|
+
* @internal
|
|
94
117
|
*/
|
|
95
118
|
export function editTrees(
|
|
96
119
|
editor: Editor,
|
|
@@ -144,9 +167,13 @@ export function editTrees(
|
|
|
144
167
|
return failed;
|
|
145
168
|
}
|
|
146
169
|
|
|
170
|
+
/** @internal */
|
|
147
171
|
export type StoryListener = (state: EditorState, transactions: readonly Transaction[]) => void;
|
|
148
172
|
|
|
149
|
-
/**
|
|
173
|
+
/**
|
|
174
|
+
* A story's editing state, kept in step with the body.
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
150
177
|
export class StoryEditing {
|
|
151
178
|
state: EditorState;
|
|
152
179
|
/** Set while the story's own transaction goes through the body. */
|
|
@@ -198,7 +225,7 @@ export class StoryEditing {
|
|
|
198
225
|
}
|
|
199
226
|
|
|
200
227
|
private notify(transactions: readonly Transaction[]): void {
|
|
201
|
-
for (const listener of this.listeners) listener
|
|
228
|
+
for (const listener of this.listeners) callListener(listener, this.state, transactions);
|
|
202
229
|
}
|
|
203
230
|
|
|
204
231
|
/** `state` with the body's context and tracking; its plugins keep their state. */
|
package/src/state/tables.ts
CHANGED
|
@@ -13,7 +13,10 @@ import { type Command, type EditorState, Plugin, type Transaction } from "./stat
|
|
|
13
13
|
|
|
14
14
|
const isTable = (node: Node) => node.type.name === "table";
|
|
15
15
|
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The depth of the innermost table cell around `$pos`, or -1.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
17
20
|
export function cellDepth($pos: ResolvedPos): number {
|
|
18
21
|
for (let d = $pos.depth; d > 0; d--) if ($pos.node(d).type.name === "tableCell") return d;
|
|
19
22
|
return -1;
|
|
@@ -30,6 +33,7 @@ function tableBelow($pos: ResolvedPos, shared: number): number {
|
|
|
30
33
|
/**
|
|
31
34
|
* Deletes `from..to` in `tr` keeping tables valid; returns false (and does nothing) when an
|
|
32
35
|
* ordinary delete keeps them valid (no end of the range inside a table it leaves).
|
|
36
|
+
* @internal
|
|
33
37
|
*/
|
|
34
38
|
export function deleteAcrossTables(tr: Transaction, from: number, to: number): boolean {
|
|
35
39
|
const doc = tr.doc;
|
|
@@ -135,6 +139,7 @@ function clearCells(tr: Transaction, from: number, to: number, start: number, en
|
|
|
135
139
|
* Empties the cells at positions (positions before them, any order): their text deleted
|
|
136
140
|
* (paragraphs in a cell joined), so a tracked clear can be rejected; a cell holding other blocks
|
|
137
141
|
* (a nested table) gets one empty paragraph instead.
|
|
142
|
+
* @internal
|
|
138
143
|
*/
|
|
139
144
|
export function emptyCells(tr: Transaction, positions: readonly number[]): void {
|
|
140
145
|
for (const pos of [...positions].sort((a, b) => b - a)) {
|
|
@@ -260,6 +265,7 @@ export function goToCell(dir: 1 | -1): Command {
|
|
|
260
265
|
* A new row like `last`: its properties, not its identity (`w14:paraId`…) or revisions; its
|
|
261
266
|
* cells empty, unmerged, their paragraph with the first one's properties, without what only one
|
|
262
267
|
* paragraph has. Null when the schema has no paragraph.
|
|
268
|
+
* @internal
|
|
263
269
|
*/
|
|
264
270
|
export function emptyRowLike(last: Node): Node | null {
|
|
265
271
|
const paragraph = last.type.schema.nodes.paragraph;
|
|
@@ -362,14 +368,20 @@ function cellAtColumn(table: Node, tableStart: number, r: number, column: number
|
|
|
362
368
|
}
|
|
363
369
|
return null;
|
|
364
370
|
}
|
|
365
|
-
/**
|
|
371
|
+
/**
|
|
372
|
+
* Tab and Shift+Tab between cells: before the lists' Tab (in a cell Word moves, numbered or not).
|
|
373
|
+
* @internal
|
|
374
|
+
*/
|
|
366
375
|
export function tableKeymap(): Plugin {
|
|
367
376
|
return new Plugin({ keymap: { Tab: goToCell(1), "Shift-Tab": goToCell(-1) } });
|
|
368
377
|
}
|
|
369
378
|
|
|
370
379
|
// ---- Cell selections (10.6c) ---------------------------------------------------------------------
|
|
371
380
|
|
|
372
|
-
/**
|
|
381
|
+
/**
|
|
382
|
+
* A cell where a table's grid has it: its position and the rows and grid columns it covers.
|
|
383
|
+
* @internal
|
|
384
|
+
*/
|
|
373
385
|
export interface GridCell {
|
|
374
386
|
pos: number;
|
|
375
387
|
row: number;
|
|
@@ -378,7 +390,10 @@ export interface GridCell {
|
|
|
378
390
|
span: number;
|
|
379
391
|
}
|
|
380
392
|
|
|
381
|
-
/**
|
|
393
|
+
/**
|
|
394
|
+
* A table's cells on its grid (a merge's first cell spans the rows its merge covers).
|
|
395
|
+
* @internal
|
|
396
|
+
*/
|
|
382
397
|
export function gridOf(table: Node, start: number): GridCell[] {
|
|
383
398
|
const out: GridCell[] = [];
|
|
384
399
|
const open = new Map<number, GridCell>();
|
|
@@ -473,7 +488,10 @@ export class CellSelection extends Selection {
|
|
|
473
488
|
}
|
|
474
489
|
}
|
|
475
490
|
|
|
476
|
-
/**
|
|
491
|
+
/**
|
|
492
|
+
* The grid cell covering the cell at `pos` of `table` (at `start`): a merge's, for a covered one.
|
|
493
|
+
* @internal
|
|
494
|
+
*/
|
|
477
495
|
export function coveringCell(
|
|
478
496
|
table: Node,
|
|
479
497
|
start: number,
|
|
@@ -496,7 +514,10 @@ export function coveringCell(
|
|
|
496
514
|
return undefined;
|
|
497
515
|
}
|
|
498
516
|
|
|
499
|
-
/**
|
|
517
|
+
/**
|
|
518
|
+
* The grid cell covering `row` and `column`.
|
|
519
|
+
* @internal
|
|
520
|
+
*/
|
|
500
521
|
export const coveringAt = (grid: readonly GridCell[], row: number, column: number) =>
|
|
501
522
|
grid.find(
|
|
502
523
|
(c) =>
|
package/src/state/track.ts
CHANGED
|
@@ -64,7 +64,10 @@ export const untracked = "untracked";
|
|
|
64
64
|
*/
|
|
65
65
|
export const revisionFloor = "revisionFloor";
|
|
66
66
|
|
|
67
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* On a rebuilt transaction: the ranges it records as deleted, as `[from, to]` of the document before.
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
68
71
|
export const trackedDeletes = "trackedDeletes";
|
|
69
72
|
|
|
70
73
|
/** Inline nodes a tracked change does not mark: they stand between runs in Word. */
|
|
@@ -103,6 +106,7 @@ interface ParagraphRevision {
|
|
|
103
106
|
deletion?: Revision;
|
|
104
107
|
}
|
|
105
108
|
|
|
109
|
+
/** @internal */
|
|
106
110
|
export function trackPlugin(state: TrackState): Plugin<TrackState> {
|
|
107
111
|
return new Plugin({
|
|
108
112
|
key,
|
|
@@ -118,7 +122,10 @@ export function trackState(state: EditorState): TrackState | null {
|
|
|
118
122
|
return key.getState(state) ?? null;
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
/**
|
|
125
|
+
/**
|
|
126
|
+
* Makes `tr` set the tracking state (a story's editor passes its change to the body).
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
122
129
|
export const withTrackState = (tr: Transaction, state: TrackState): Transaction =>
|
|
123
130
|
tr.setMeta(key, state);
|
|
124
131
|
|