@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.
package/dist/server.d.cts CHANGED
@@ -3,7 +3,7 @@ import { createServerAutomationHost, ServerAutomationHostOptions } from '@docx-e
3
3
  import * as Y from 'yjs';
4
4
  import { CollaborationIdentity } from '@docx-editor.dev/core/collaboration';
5
5
  import { TreePackageStore, PackageTransactResult, HeadlessDocumentView, ImageDecodePort } from '@docx-editor.dev/core/store';
6
- import { R as ReferencesPort } from './port-ip7WByvH.cjs';
6
+ import { R as ReferencesPort } from './port-BbN5OZHx.cjs';
7
7
  import { R as Revision } from './track-eYC94jTp.cjs';
8
8
  import { D as DocxCollaborationSession } from './session-Cf9iu1Vt.cjs';
9
9
  export { C as COLLAB_PROTOCOL, D as DOCUMENT_COLLABORATION_VERSIONS } from './versions-DXiFQMA6.cjs';
package/dist/server.d.ts CHANGED
@@ -3,7 +3,7 @@ import { createServerAutomationHost, ServerAutomationHostOptions } from '@docx-e
3
3
  import * as Y from 'yjs';
4
4
  import { CollaborationIdentity } from '@docx-editor.dev/core/collaboration';
5
5
  import { TreePackageStore, PackageTransactResult, HeadlessDocumentView, ImageDecodePort } from '@docx-editor.dev/core/store';
6
- import { R as ReferencesPort } from './port-ip7WByvH.js';
6
+ import { R as ReferencesPort } from './port-BbN5OZHx.js';
7
7
  import { R as Revision } from './track-eYC94jTp.js';
8
8
  import { D as DocxCollaborationSession } from './session-Cf9iu1Vt.js';
9
9
  export { C as COLLAB_PROTOCOL, D as DOCUMENT_COLLABORATION_VERSIONS } from './versions-DXiFQMA6.js';
package/dist/server.js CHANGED
@@ -47,6 +47,7 @@ function readParagraph(node, topLevel, bookmarks) {
47
47
  let runStyle;
48
48
  const fields = [];
49
49
  const notes = [];
50
+ const revisions = [];
50
51
  let current = null;
51
52
  const field = (c) => {
52
53
  const type = attr(c, "fldCharType");
@@ -88,7 +89,31 @@ function readParagraph(node, topLevel, bookmarks) {
88
89
  }
89
90
  continue;
90
91
  }
91
- if (c.localName === "delText" || c.localName === "del" || c.localName === "rPr") continue;
92
+ if (c.localName === "del") {
93
+ const deleted = deletedText(c);
94
+ if (deleted && fieldDepth === 0)
95
+ revisions.push({
96
+ kind: "delete",
97
+ offset: text.length,
98
+ length: deleted.length,
99
+ author: attr(c, "author"),
100
+ text: deleted
101
+ });
102
+ continue;
103
+ }
104
+ if (c.localName === "ins") {
105
+ const start = text.length;
106
+ walk(c, link);
107
+ if (text.length > start && fieldDepth === 0)
108
+ revisions.push({
109
+ kind: "insert",
110
+ offset: start,
111
+ length: text.length - start,
112
+ author: attr(c, "author")
113
+ });
114
+ continue;
115
+ }
116
+ if (c.localName === "delText" || c.localName === "rPr") continue;
92
117
  if (c.localName === "r") {
93
118
  const rStyle = c.children?.find((x) => x.localName === "rPr")?.children?.find((x) => x.localName === "rStyle");
94
119
  const watched = rStyle && attr(rStyle, "val");
@@ -151,9 +176,20 @@ function readParagraph(node, topLevel, bookmarks) {
151
176
  links,
152
177
  ...fields.length ? { fields } : {},
153
178
  ...marks.length ? { marks } : {},
154
- ...notes.length ? { notes } : {}
179
+ ...notes.length ? { notes } : {},
180
+ ...revisions.length ? { revisions } : {}
155
181
  };
156
182
  }
183
+ function deletedText(node) {
184
+ let out = "";
185
+ for (const c of node.children ?? []) {
186
+ if (c.localName === "instrText") continue;
187
+ if (c.localName === "delText") out += (c.children ?? []).map((t) => t.value ?? "").join("");
188
+ else if (c.localName === "tab") out += " ";
189
+ else if (c.localName !== "rPr") out += deletedText(c);
190
+ }
191
+ return out;
192
+ }
157
193
  function documentNumbering(source) {
158
194
  let numbering;
159
195
  let cascade;
@@ -1328,6 +1364,10 @@ var NodeRegistry = class {
1328
1364
  get(id) {
1329
1365
  return this.entries.get(id);
1330
1366
  }
1367
+ /** Whether the id names a node, one inside a paragraph that is not open yet included. */
1368
+ has(id) {
1369
+ return (this.entries.get(id) ?? this.resolveInsideParagraph(id)) !== void 0;
1370
+ }
1331
1371
  require(id) {
1332
1372
  let entry = this.entries.get(id) ?? this.resolveInsideParagraph(id);
1333
1373
  if (!entry) throw new RegistryError(`journal names unknown node ${id}`);
@@ -1728,8 +1768,31 @@ function moveNode(registry, id, destinationId, destinationIndex) {
1728
1768
  const destination = childrenOf(asLiveElement(destinationEntry.live, destinationId));
1729
1769
  destination.insert(destinationIndex, [registry.toLive(copy)]);
1730
1770
  }
1771
+ function renameNode(registry, id, qname) {
1772
+ const entry = registry.require(id);
1773
+ if ("plain" in entry) {
1774
+ const el2 = entry.plain;
1775
+ if (el2.type !== "element") return false;
1776
+ el2.ns = qname.namespaceUri;
1777
+ el2.local = qname.localName;
1778
+ if (qname.prefix === void 0) delete el2.prefix;
1779
+ else el2.prefix = qname.prefix;
1780
+ registry.touch(el2);
1781
+ return true;
1782
+ }
1783
+ const live = entry.live;
1784
+ if (live instanceof Y3.Text || isRichParagraph(live)) return false;
1785
+ if (live.get("ns") !== qname.namespaceUri) live.set("ns", qname.namespaceUri);
1786
+ if (live.get("local") !== qname.localName) live.set("local", qname.localName);
1787
+ if (qname.prefix === void 0) {
1788
+ if (live.has("prefix")) live.delete("prefix");
1789
+ } else if (live.get("prefix") !== qname.prefix) live.set("prefix", qname.prefix);
1790
+ return true;
1791
+ }
1731
1792
  function putNode(registry, effect) {
1732
1793
  const d = effect.descriptor;
1794
+ if (d.kind !== "textValue" && registry.has(d.logicalId) && renameNode(registry, d.logicalId, d.qname))
1795
+ return;
1733
1796
  if (d.kind === "textValue") {
1734
1797
  registry.registerPlain({ type: "text", id: d.logicalId, value: "" });
1735
1798
  return;