@arbidocs/coedit 0.4.111 → 0.4.113

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.
@@ -0,0 +1,188 @@
1
+ /**
2
+ * The read side of the Word-editor commands: a document's paragraphs as the commands see them
3
+ * (text in the engine's offset vocabulary, bookmarks, internal links, fields, note references),
4
+ * read from the engine's OOXML tree. The same tree comes from a live editor
5
+ * (`surface.session.part().root`) or from document bytes (`openHeadlessDocument`), so the toolbar
6
+ * and ARBI's headless tools read a document the same way.
7
+ */
8
+ /** Character style of an inserted term: a dotted underline, so a defined term reads as one. */
9
+ declare const DEFINED_TERM_STYLE = "DefinedTerm";
10
+ /** Character style of a cross-reference: a muted blue with a dotted underline (Word's name). */
11
+ declare const CROSS_REFERENCE_STYLE = "CrossReference";
12
+ /** Character style of a cross-reference whose target is gone: its last text, flagged. */
13
+ declare const BROKEN_CROSS_REFERENCE_STYLE = "CrossReferenceBroken";
14
+ /** A position: a paragraph (the engine's node id) and a UTF-16 offset into its text. */
15
+ interface DocPoint {
16
+ paragraphId: string;
17
+ offset: number;
18
+ }
19
+ /** An internal link in a paragraph. */
20
+ interface DocLink {
21
+ anchor: string;
22
+ text: string;
23
+ /** Where its text starts in the paragraph's text. */
24
+ offset?: number;
25
+ }
26
+ /** A footnote or endnote reference: one character of the paragraph, as the engine counts it. */
27
+ interface DocNote {
28
+ offset: number;
29
+ kind: 'footnote' | 'endnote';
30
+ /** `w:id` of the note. */
31
+ id: string;
32
+ }
33
+ /** One paragraph, in document order. */
34
+ interface DocParagraph {
35
+ id: string;
36
+ /** `w14:paraId`, the id that is the same in every replica of a collaboration room. */
37
+ paraId?: string;
38
+ text: string;
39
+ /** Styled as a heading (a `Heading n` style or an outline level). */
40
+ heading: boolean;
41
+ styleId?: string;
42
+ /** A paragraph of the body itself, not inside a table. */
43
+ topLevel: boolean;
44
+ /** Names of the bookmarks that start in it. */
45
+ bookmarks: string[];
46
+ /** Its internal links (`w:hyperlink w:anchor`). */
47
+ links: DocLink[];
48
+ /** Its complex fields: where each sits (its one-character offset), its instruction and result. */
49
+ fields?: DocField[];
50
+ /** Its runs in a watched character style (a broken cross-reference's mark), with their text. */
51
+ marks?: DocMark[];
52
+ /** Its footnote and endnote references. */
53
+ notes?: DocNote[];
54
+ }
55
+ /** A stretch of a paragraph's text in a watched character style. */
56
+ interface DocMark {
57
+ styleId: string;
58
+ offset: number;
59
+ text: string;
60
+ }
61
+ /** Character styles whose runs a paragraph read reports as marks. */
62
+ declare const WATCHED_STYLES: Set<string>;
63
+ /** A complex field of a paragraph. */
64
+ interface DocField {
65
+ offset: number;
66
+ instruction: string;
67
+ result: string;
68
+ }
69
+ type OoxmlNodeLike = {
70
+ id: string;
71
+ kind: string;
72
+ localName?: string;
73
+ value?: string;
74
+ attributes?: readonly {
75
+ localName: string;
76
+ value: string;
77
+ }[];
78
+ children?: readonly OoxmlNodeLike[];
79
+ };
80
+ /** How a field (or a note reference) counts in a paragraph's text (the engine's model vocabulary). */
81
+ declare const FIELD_ATOM = "\uFFFC";
82
+ /** The paragraphs of a part's body, read from the engine's OOXML tree. */
83
+ declare function readParagraphs(root: OoxmlNodeLike): DocParagraph[];
84
+ /** Style id to style name (`Heading1` → `heading 1`), from a styles part's tree. */
85
+ declare function styleNames(root: OoxmlNodeLike | null | undefined): Map<string, string>;
86
+
87
+ /**
88
+ * Cross-reference targets: the document's numbered paragraphs (clauses, sub-clauses, numbered
89
+ * captions) and its headings, with the number Word's `REF \r` shows for each.
90
+ *
91
+ * The number is what the editor computes for a `REF … \r` field — and it has to be exactly that,
92
+ * because the engine shows a field's live value only while the field's cached result matches what
93
+ * it computes (otherwise it keeps the cached text for good). So this mirrors the engine: the
94
+ * paragraph's own list level, preceded by each higher level whose number its level text does not
95
+ * already show (`%1.%2` already shows level 1; `(%3)` does not show `2.1`), and one trailing
96
+ * period dropped (`2.` reads `2`).
97
+ */
98
+
99
+ /** A paragraph's resolved list numbering (the engine's list item). */
100
+ interface ListItemInfo {
101
+ numId: string;
102
+ ilvl: number;
103
+ markerText: string;
104
+ numFmt: string;
105
+ }
106
+ /** A list level's definition: its level text (`%1.%2`) and number format. */
107
+ interface LevelInfo {
108
+ lvlText: string;
109
+ numFmt: string;
110
+ }
111
+ type LevelOf = (numId: string, ilvl: number) => LevelInfo | null;
112
+ /**
113
+ * The number `REF \r` shows for a paragraph, or null when it is not numbered. `order` is every
114
+ * paragraph id in document order (for the markers of the levels above it).
115
+ */
116
+ declare function paragraphNumber(order: readonly string[], items: ReadonlyMap<string, ListItemInfo>, levelOf: LevelOf, paragraphId: string): string | null;
117
+ /** One place a cross-reference can point at. */
118
+ interface CrossReferenceTarget {
119
+ paragraphId: string;
120
+ /** A numbered paragraph (clause, sub-clause, caption) or an unnumbered heading. */
121
+ kind: 'numbered' | 'heading';
122
+ /** What `REF \r` shows (`8.2`), or null for an unnumbered heading. */
123
+ number: string | null;
124
+ /** The paragraph's list marker as painted (`8.2`, `(a)`), or empty. */
125
+ marker: string;
126
+ /** The paragraph's text (without its marker). */
127
+ text: string;
128
+ heading: boolean;
129
+ /** Its list level (0 for a top-level clause), or 0 for a heading. */
130
+ level: number;
131
+ }
132
+ /** Every numbered paragraph and every heading, in document order. */
133
+ declare function listTargets(paragraphs: readonly DocParagraph[], items: ReadonlyMap<string, ListItemInfo>, levelOf: LevelOf): CrossReferenceTarget[];
134
+ /** Targets whose number or text contains the query (case-insensitive). */
135
+ declare function filterTargets(targets: readonly CrossReferenceTarget[], query: string): CrossReferenceTarget[];
136
+ /** What the engine's numbering needs of a document: its parts' trees. */
137
+ interface NumberingSource {
138
+ /** The main document part's root. */
139
+ root(): OoxmlNodeLike;
140
+ stylesRoot(): unknown;
141
+ numberingRoot(): unknown;
142
+ settingsRoot(): unknown;
143
+ }
144
+ /** A document's list numbering as the engine resolves it. */
145
+ interface DocumentNumbering {
146
+ /** Each numbered paragraph's list item, by paragraph (node) id. */
147
+ listItems(): ReadonlyMap<string, ListItemInfo>;
148
+ levelOf: LevelOf;
149
+ }
150
+ /**
151
+ * The numbering of a document, as the editor paints it: from a live editor's session or from a
152
+ * headless document view alike.
153
+ */
154
+ declare function documentNumbering(source: NumberingSource): DocumentNumbering;
155
+
156
+ /**
157
+ * The few things the defined-term and cross-reference commands need from a document, behind an
158
+ * interface: a live editor (arbi-blocks' `editorPort`), a collaboration room (`roomCommandsPort` in
159
+ * `@arbidocs/coedit/server`), or the in-memory model the tests use.
160
+ */
161
+
162
+ interface DefinitionsPort {
163
+ /** Every body paragraph, in document order (table cells included, `topLevel: false`). */
164
+ paragraphs(): DocParagraph[];
165
+ /** The caret, or `null` when the selection is a range or there is none. */
166
+ caret(): DocPoint | null;
167
+ setCaret(point: DocPoint): void;
168
+ /** Delete everything between two points (across paragraphs: the marks between them go too). */
169
+ deleteRange(from: DocPoint, to: DocPoint): void;
170
+ /**
171
+ * Paste paragraph XML at the caret. `covered`: the fragment ends with a whole paragraph, so at
172
+ * the start of a paragraph it lands as paragraphs before it. Otherwise it runs inline.
173
+ */
174
+ paste(body: string, text: string, covered: boolean, relationships?: string): boolean;
175
+ /** Split the caret's paragraph (Enter), the caret moving into the new one. */
176
+ splitParagraph(): void;
177
+ /** Type plain text at the caret. */
178
+ typeText(text: string): void;
179
+ }
180
+ interface ReferencesPort extends DefinitionsPort {
181
+ /** Each numbered paragraph's list item, by paragraph id. */
182
+ listItems(): ReadonlyMap<string, ListItemInfo>;
183
+ levelOf: LevelOf;
184
+ /** The paragraph's runs as WordprocessingML, or null when it holds more than plain runs. */
185
+ runsXml(paragraphId: string): string | null;
186
+ }
187
+
188
+ export { BROKEN_CROSS_REFERENCE_STYLE as B, CROSS_REFERENCE_STYLE as C, DEFINED_TERM_STYLE as D, FIELD_ATOM as F, type LevelInfo as L, type NumberingSource as N, type OoxmlNodeLike as O, type ReferencesPort as R, WATCHED_STYLES as W, type CrossReferenceTarget as a, type DefinitionsPort as b, type DocField as c, type DocLink as d, type DocMark as e, type DocNote as f, type DocParagraph as g, type DocPoint as h, type DocumentNumbering as i, type LevelOf as j, type ListItemInfo as k, documentNumbering as l, filterTargets as m, listTargets as n, paragraphNumber as p, readParagraphs as r, styleNames as s };
@@ -0,0 +1,188 @@
1
+ /**
2
+ * The read side of the Word-editor commands: a document's paragraphs as the commands see them
3
+ * (text in the engine's offset vocabulary, bookmarks, internal links, fields, note references),
4
+ * read from the engine's OOXML tree. The same tree comes from a live editor
5
+ * (`surface.session.part().root`) or from document bytes (`openHeadlessDocument`), so the toolbar
6
+ * and ARBI's headless tools read a document the same way.
7
+ */
8
+ /** Character style of an inserted term: a dotted underline, so a defined term reads as one. */
9
+ declare const DEFINED_TERM_STYLE = "DefinedTerm";
10
+ /** Character style of a cross-reference: a muted blue with a dotted underline (Word's name). */
11
+ declare const CROSS_REFERENCE_STYLE = "CrossReference";
12
+ /** Character style of a cross-reference whose target is gone: its last text, flagged. */
13
+ declare const BROKEN_CROSS_REFERENCE_STYLE = "CrossReferenceBroken";
14
+ /** A position: a paragraph (the engine's node id) and a UTF-16 offset into its text. */
15
+ interface DocPoint {
16
+ paragraphId: string;
17
+ offset: number;
18
+ }
19
+ /** An internal link in a paragraph. */
20
+ interface DocLink {
21
+ anchor: string;
22
+ text: string;
23
+ /** Where its text starts in the paragraph's text. */
24
+ offset?: number;
25
+ }
26
+ /** A footnote or endnote reference: one character of the paragraph, as the engine counts it. */
27
+ interface DocNote {
28
+ offset: number;
29
+ kind: 'footnote' | 'endnote';
30
+ /** `w:id` of the note. */
31
+ id: string;
32
+ }
33
+ /** One paragraph, in document order. */
34
+ interface DocParagraph {
35
+ id: string;
36
+ /** `w14:paraId`, the id that is the same in every replica of a collaboration room. */
37
+ paraId?: string;
38
+ text: string;
39
+ /** Styled as a heading (a `Heading n` style or an outline level). */
40
+ heading: boolean;
41
+ styleId?: string;
42
+ /** A paragraph of the body itself, not inside a table. */
43
+ topLevel: boolean;
44
+ /** Names of the bookmarks that start in it. */
45
+ bookmarks: string[];
46
+ /** Its internal links (`w:hyperlink w:anchor`). */
47
+ links: DocLink[];
48
+ /** Its complex fields: where each sits (its one-character offset), its instruction and result. */
49
+ fields?: DocField[];
50
+ /** Its runs in a watched character style (a broken cross-reference's mark), with their text. */
51
+ marks?: DocMark[];
52
+ /** Its footnote and endnote references. */
53
+ notes?: DocNote[];
54
+ }
55
+ /** A stretch of a paragraph's text in a watched character style. */
56
+ interface DocMark {
57
+ styleId: string;
58
+ offset: number;
59
+ text: string;
60
+ }
61
+ /** Character styles whose runs a paragraph read reports as marks. */
62
+ declare const WATCHED_STYLES: Set<string>;
63
+ /** A complex field of a paragraph. */
64
+ interface DocField {
65
+ offset: number;
66
+ instruction: string;
67
+ result: string;
68
+ }
69
+ type OoxmlNodeLike = {
70
+ id: string;
71
+ kind: string;
72
+ localName?: string;
73
+ value?: string;
74
+ attributes?: readonly {
75
+ localName: string;
76
+ value: string;
77
+ }[];
78
+ children?: readonly OoxmlNodeLike[];
79
+ };
80
+ /** How a field (or a note reference) counts in a paragraph's text (the engine's model vocabulary). */
81
+ declare const FIELD_ATOM = "\uFFFC";
82
+ /** The paragraphs of a part's body, read from the engine's OOXML tree. */
83
+ declare function readParagraphs(root: OoxmlNodeLike): DocParagraph[];
84
+ /** Style id to style name (`Heading1` → `heading 1`), from a styles part's tree. */
85
+ declare function styleNames(root: OoxmlNodeLike | null | undefined): Map<string, string>;
86
+
87
+ /**
88
+ * Cross-reference targets: the document's numbered paragraphs (clauses, sub-clauses, numbered
89
+ * captions) and its headings, with the number Word's `REF \r` shows for each.
90
+ *
91
+ * The number is what the editor computes for a `REF … \r` field — and it has to be exactly that,
92
+ * because the engine shows a field's live value only while the field's cached result matches what
93
+ * it computes (otherwise it keeps the cached text for good). So this mirrors the engine: the
94
+ * paragraph's own list level, preceded by each higher level whose number its level text does not
95
+ * already show (`%1.%2` already shows level 1; `(%3)` does not show `2.1`), and one trailing
96
+ * period dropped (`2.` reads `2`).
97
+ */
98
+
99
+ /** A paragraph's resolved list numbering (the engine's list item). */
100
+ interface ListItemInfo {
101
+ numId: string;
102
+ ilvl: number;
103
+ markerText: string;
104
+ numFmt: string;
105
+ }
106
+ /** A list level's definition: its level text (`%1.%2`) and number format. */
107
+ interface LevelInfo {
108
+ lvlText: string;
109
+ numFmt: string;
110
+ }
111
+ type LevelOf = (numId: string, ilvl: number) => LevelInfo | null;
112
+ /**
113
+ * The number `REF \r` shows for a paragraph, or null when it is not numbered. `order` is every
114
+ * paragraph id in document order (for the markers of the levels above it).
115
+ */
116
+ declare function paragraphNumber(order: readonly string[], items: ReadonlyMap<string, ListItemInfo>, levelOf: LevelOf, paragraphId: string): string | null;
117
+ /** One place a cross-reference can point at. */
118
+ interface CrossReferenceTarget {
119
+ paragraphId: string;
120
+ /** A numbered paragraph (clause, sub-clause, caption) or an unnumbered heading. */
121
+ kind: 'numbered' | 'heading';
122
+ /** What `REF \r` shows (`8.2`), or null for an unnumbered heading. */
123
+ number: string | null;
124
+ /** The paragraph's list marker as painted (`8.2`, `(a)`), or empty. */
125
+ marker: string;
126
+ /** The paragraph's text (without its marker). */
127
+ text: string;
128
+ heading: boolean;
129
+ /** Its list level (0 for a top-level clause), or 0 for a heading. */
130
+ level: number;
131
+ }
132
+ /** Every numbered paragraph and every heading, in document order. */
133
+ declare function listTargets(paragraphs: readonly DocParagraph[], items: ReadonlyMap<string, ListItemInfo>, levelOf: LevelOf): CrossReferenceTarget[];
134
+ /** Targets whose number or text contains the query (case-insensitive). */
135
+ declare function filterTargets(targets: readonly CrossReferenceTarget[], query: string): CrossReferenceTarget[];
136
+ /** What the engine's numbering needs of a document: its parts' trees. */
137
+ interface NumberingSource {
138
+ /** The main document part's root. */
139
+ root(): OoxmlNodeLike;
140
+ stylesRoot(): unknown;
141
+ numberingRoot(): unknown;
142
+ settingsRoot(): unknown;
143
+ }
144
+ /** A document's list numbering as the engine resolves it. */
145
+ interface DocumentNumbering {
146
+ /** Each numbered paragraph's list item, by paragraph (node) id. */
147
+ listItems(): ReadonlyMap<string, ListItemInfo>;
148
+ levelOf: LevelOf;
149
+ }
150
+ /**
151
+ * The numbering of a document, as the editor paints it: from a live editor's session or from a
152
+ * headless document view alike.
153
+ */
154
+ declare function documentNumbering(source: NumberingSource): DocumentNumbering;
155
+
156
+ /**
157
+ * The few things the defined-term and cross-reference commands need from a document, behind an
158
+ * interface: a live editor (arbi-blocks' `editorPort`), a collaboration room (`roomCommandsPort` in
159
+ * `@arbidocs/coedit/server`), or the in-memory model the tests use.
160
+ */
161
+
162
+ interface DefinitionsPort {
163
+ /** Every body paragraph, in document order (table cells included, `topLevel: false`). */
164
+ paragraphs(): DocParagraph[];
165
+ /** The caret, or `null` when the selection is a range or there is none. */
166
+ caret(): DocPoint | null;
167
+ setCaret(point: DocPoint): void;
168
+ /** Delete everything between two points (across paragraphs: the marks between them go too). */
169
+ deleteRange(from: DocPoint, to: DocPoint): void;
170
+ /**
171
+ * Paste paragraph XML at the caret. `covered`: the fragment ends with a whole paragraph, so at
172
+ * the start of a paragraph it lands as paragraphs before it. Otherwise it runs inline.
173
+ */
174
+ paste(body: string, text: string, covered: boolean, relationships?: string): boolean;
175
+ /** Split the caret's paragraph (Enter), the caret moving into the new one. */
176
+ splitParagraph(): void;
177
+ /** Type plain text at the caret. */
178
+ typeText(text: string): void;
179
+ }
180
+ interface ReferencesPort extends DefinitionsPort {
181
+ /** Each numbered paragraph's list item, by paragraph id. */
182
+ listItems(): ReadonlyMap<string, ListItemInfo>;
183
+ levelOf: LevelOf;
184
+ /** The paragraph's runs as WordprocessingML, or null when it holds more than plain runs. */
185
+ runsXml(paragraphId: string): string | null;
186
+ }
187
+
188
+ export { BROKEN_CROSS_REFERENCE_STYLE as B, CROSS_REFERENCE_STYLE as C, DEFINED_TERM_STYLE as D, FIELD_ATOM as F, type LevelInfo as L, type NumberingSource as N, type OoxmlNodeLike as O, type ReferencesPort as R, WATCHED_STYLES as W, type CrossReferenceTarget as a, type DefinitionsPort as b, type DocField as c, type DocLink as d, type DocMark as e, type DocNote as f, type DocParagraph as g, type DocPoint as h, type DocumentNumbering as i, type LevelOf as j, type ListItemInfo as k, documentNumbering as l, filterTargets as m, listTargets as n, paragraphNumber as p, readParagraphs as r, styleNames as s };