@arbidocs/coedit 0.4.120 → 0.4.122

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.
@@ -51,7 +51,30 @@ interface DocParagraph {
51
51
  marks?: DocMark[];
52
52
  /** Its footnote and endnote references. */
53
53
  notes?: DocNote[];
54
+ /** Its pending tracked insertions and deletions, in document order. */
55
+ revisions?: DocRevision[];
54
56
  }
57
+ /**
58
+ * A pending tracked change in a paragraph. `text` leaves deleted text out, while the engine's
59
+ * offsets (a {@link DocPoint}) count it: an insertion covers `length` characters of `text` from
60
+ * `offset`; a deletion's `text` sits at `offset`, between the characters of `text` around it.
61
+ */
62
+ interface DocRevision {
63
+ kind: 'insert' | 'delete';
64
+ offset: number;
65
+ length: number;
66
+ author?: string;
67
+ /** A deletion's text. */
68
+ text?: string;
69
+ }
70
+ /**
71
+ * Where a position in a paragraph's `text` is in the engine's offsets, which count pending
72
+ * deleted text. `pastDeletions`: a position with deleted text right at it is placed after that
73
+ * text rather than before it.
74
+ */
75
+ declare function engineOffset(paragraph: DocParagraph, offset: number, pastDeletions?: boolean): number;
76
+ /** A paragraph's length in the engine's offsets: its text and its pending deleted text. */
77
+ declare const engineLength: (paragraph: DocParagraph) => number;
55
78
  /** A stretch of a paragraph's text in a watched character style. */
56
79
  interface DocMark {
57
80
  styleId: string;
@@ -185,4 +208,4 @@ interface ReferencesPort extends DefinitionsPort {
185
208
  runsXml(paragraphId: string): string | null;
186
209
  }
187
210
 
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 };
211
+ 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 DocRevision as i, type DocumentNumbering as j, type LevelOf as k, type ListItemInfo as l, documentNumbering as m, engineLength as n, engineOffset as o, filterTargets as p, listTargets as q, paragraphNumber as r, readParagraphs as s, styleNames as t };
@@ -51,7 +51,30 @@ interface DocParagraph {
51
51
  marks?: DocMark[];
52
52
  /** Its footnote and endnote references. */
53
53
  notes?: DocNote[];
54
+ /** Its pending tracked insertions and deletions, in document order. */
55
+ revisions?: DocRevision[];
54
56
  }
57
+ /**
58
+ * A pending tracked change in a paragraph. `text` leaves deleted text out, while the engine's
59
+ * offsets (a {@link DocPoint}) count it: an insertion covers `length` characters of `text` from
60
+ * `offset`; a deletion's `text` sits at `offset`, between the characters of `text` around it.
61
+ */
62
+ interface DocRevision {
63
+ kind: 'insert' | 'delete';
64
+ offset: number;
65
+ length: number;
66
+ author?: string;
67
+ /** A deletion's text. */
68
+ text?: string;
69
+ }
70
+ /**
71
+ * Where a position in a paragraph's `text` is in the engine's offsets, which count pending
72
+ * deleted text. `pastDeletions`: a position with deleted text right at it is placed after that
73
+ * text rather than before it.
74
+ */
75
+ declare function engineOffset(paragraph: DocParagraph, offset: number, pastDeletions?: boolean): number;
76
+ /** A paragraph's length in the engine's offsets: its text and its pending deleted text. */
77
+ declare const engineLength: (paragraph: DocParagraph) => number;
55
78
  /** A stretch of a paragraph's text in a watched character style. */
56
79
  interface DocMark {
57
80
  styleId: string;
@@ -185,4 +208,4 @@ interface ReferencesPort extends DefinitionsPort {
185
208
  runsXml(paragraphId: string): string | null;
186
209
  }
187
210
 
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 };
211
+ 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 DocRevision as i, type DocumentNumbering as j, type LevelOf as k, type ListItemInfo as l, documentNumbering as m, engineLength as n, engineOffset as o, filterTargets as p, listTargets as q, paragraphNumber as r, readParagraphs as s, styleNames as t };
package/dist/server.cjs CHANGED
@@ -69,6 +69,7 @@ function readParagraph(node, topLevel, bookmarks) {
69
69
  let runStyle;
70
70
  const fields = [];
71
71
  const notes = [];
72
+ const revisions = [];
72
73
  let current = null;
73
74
  const field = (c) => {
74
75
  const type = attr(c, "fldCharType");
@@ -110,7 +111,31 @@ function readParagraph(node, topLevel, bookmarks) {
110
111
  }
111
112
  continue;
112
113
  }
113
- if (c.localName === "delText" || c.localName === "del" || c.localName === "rPr") continue;
114
+ if (c.localName === "del") {
115
+ const deleted = deletedText(c);
116
+ if (deleted && fieldDepth === 0)
117
+ revisions.push({
118
+ kind: "delete",
119
+ offset: text.length,
120
+ length: deleted.length,
121
+ author: attr(c, "author"),
122
+ text: deleted
123
+ });
124
+ continue;
125
+ }
126
+ if (c.localName === "ins") {
127
+ const start = text.length;
128
+ walk(c, link);
129
+ if (text.length > start && fieldDepth === 0)
130
+ revisions.push({
131
+ kind: "insert",
132
+ offset: start,
133
+ length: text.length - start,
134
+ author: attr(c, "author")
135
+ });
136
+ continue;
137
+ }
138
+ if (c.localName === "delText" || c.localName === "rPr") continue;
114
139
  if (c.localName === "r") {
115
140
  const rStyle = c.children?.find((x) => x.localName === "rPr")?.children?.find((x) => x.localName === "rStyle");
116
141
  const watched = rStyle && attr(rStyle, "val");
@@ -173,9 +198,20 @@ function readParagraph(node, topLevel, bookmarks) {
173
198
  links,
174
199
  ...fields.length ? { fields } : {},
175
200
  ...marks.length ? { marks } : {},
176
- ...notes.length ? { notes } : {}
201
+ ...notes.length ? { notes } : {},
202
+ ...revisions.length ? { revisions } : {}
177
203
  };
178
204
  }
205
+ function deletedText(node) {
206
+ let out = "";
207
+ for (const c of node.children ?? []) {
208
+ if (c.localName === "instrText") continue;
209
+ if (c.localName === "delText") out += (c.children ?? []).map((t) => t.value ?? "").join("");
210
+ else if (c.localName === "tab") out += " ";
211
+ else if (c.localName !== "rPr") out += deletedText(c);
212
+ }
213
+ return out;
214
+ }
179
215
  function documentNumbering(source) {
180
216
  let numbering;
181
217
  let cascade;
@@ -1350,6 +1386,10 @@ var NodeRegistry = class {
1350
1386
  get(id) {
1351
1387
  return this.entries.get(id);
1352
1388
  }
1389
+ /** Whether the id names a node, one inside a paragraph that is not open yet included. */
1390
+ has(id) {
1391
+ return (this.entries.get(id) ?? this.resolveInsideParagraph(id)) !== void 0;
1392
+ }
1353
1393
  require(id) {
1354
1394
  let entry = this.entries.get(id) ?? this.resolveInsideParagraph(id);
1355
1395
  if (!entry) throw new RegistryError(`journal names unknown node ${id}`);
@@ -1750,8 +1790,31 @@ function moveNode(registry, id, destinationId, destinationIndex) {
1750
1790
  const destination = childrenOf(asLiveElement(destinationEntry.live, destinationId));
1751
1791
  destination.insert(destinationIndex, [registry.toLive(copy)]);
1752
1792
  }
1793
+ function renameNode(registry, id, qname) {
1794
+ const entry = registry.require(id);
1795
+ if ("plain" in entry) {
1796
+ const el2 = entry.plain;
1797
+ if (el2.type !== "element") return false;
1798
+ el2.ns = qname.namespaceUri;
1799
+ el2.local = qname.localName;
1800
+ if (qname.prefix === void 0) delete el2.prefix;
1801
+ else el2.prefix = qname.prefix;
1802
+ registry.touch(el2);
1803
+ return true;
1804
+ }
1805
+ const live = entry.live;
1806
+ if (live instanceof Y3__namespace.Text || isRichParagraph(live)) return false;
1807
+ if (live.get("ns") !== qname.namespaceUri) live.set("ns", qname.namespaceUri);
1808
+ if (live.get("local") !== qname.localName) live.set("local", qname.localName);
1809
+ if (qname.prefix === void 0) {
1810
+ if (live.has("prefix")) live.delete("prefix");
1811
+ } else if (live.get("prefix") !== qname.prefix) live.set("prefix", qname.prefix);
1812
+ return true;
1813
+ }
1753
1814
  function putNode(registry, effect) {
1754
1815
  const d = effect.descriptor;
1816
+ if (d.kind !== "textValue" && registry.has(d.logicalId) && renameNode(registry, d.logicalId, d.qname))
1817
+ return;
1755
1818
  if (d.kind === "textValue") {
1756
1819
  registry.registerPlain({ type: "text", id: d.logicalId, value: "" });
1757
1820
  return;