@harbour-enterprises/superdoc 0.23.0-next.14 → 0.23.0-next.16

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.
Files changed (36) hide show
  1. package/dist/chunks/{PdfViewer-D3cgkd9j.cjs → PdfViewer-CJrsZCLf.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-BaaVD5bX.es.js → PdfViewer-DfGIeWvO.es.js} +1 -1
  3. package/dist/chunks/{eventemitter3-CR2eBWft.es.js → eventemitter3-BWEnUdTY.es.js} +1 -1
  4. package/dist/chunks/{eventemitter3-DSRogsNq.cjs → eventemitter3-DkXkH2rT.cjs} +1 -1
  5. package/dist/chunks/{index-CESuSQe2.es.js → index-CwhKMy0h.es.js} +27 -332
  6. package/dist/chunks/{index-CAHkANZY.cjs → index-DGSQ4Gfx.cjs} +160 -465
  7. package/dist/chunks/{super-editor.es-BYutUrPg.cjs → super-editor.es-b9ACFl9D.cjs} +649 -125
  8. package/dist/chunks/{super-editor.es-BKb7p4fi.es.js → super-editor.es-bIibjiHo.es.js} +649 -125
  9. package/dist/chunks/{xml-js-CWV8R-ek.cjs → xml-js-D_ZIzxu0.cjs} +1 -1
  10. package/dist/chunks/xml-js-Dx4FIjnp.es.js +2 -0
  11. package/dist/core/types/index.d.ts +19 -1
  12. package/dist/core/types/index.d.ts.map +1 -1
  13. package/dist/super-editor/ai-writer.es.js +2 -2
  14. package/dist/super-editor/chunks/{converter-DD7uNz2k.js → converter-vEmAnrOg.js} +665 -249
  15. package/dist/super-editor/chunks/{docx-zipper-DraPR30Z.js → docx-zipper-DA00N7eN.js} +1 -1
  16. package/dist/super-editor/chunks/{editor-xzhKWRFZ.js → editor-CVzagv2Y.js} +127 -19
  17. package/dist/super-editor/chunks/{toolbar-D6SJTVWT.js → toolbar-BCJtFyig.js} +2 -2
  18. package/dist/super-editor/converter.es.js +1 -1
  19. package/dist/super-editor/docx-zipper.es.js +2 -2
  20. package/dist/super-editor/editor.es.js +3 -3
  21. package/dist/super-editor/file-zipper.es.js +1 -1
  22. package/dist/super-editor/src/core/Editor.d.ts +57 -3
  23. package/dist/super-editor/src/core/super-converter/SuperConverter.d.ts +58 -2
  24. package/dist/super-editor/src/core/super-converter/exporter-docx-defs.d.ts +28 -39
  25. package/dist/super-editor/super-editor.es.js +6 -6
  26. package/dist/super-editor/toolbar.es.js +2 -2
  27. package/dist/super-editor.cjs +1 -1
  28. package/dist/super-editor.es.js +1 -1
  29. package/dist/superdoc.cjs +2 -3
  30. package/dist/superdoc.es.js +2 -3
  31. package/dist/superdoc.umd.js +674 -455
  32. package/dist/superdoc.umd.js.map +1 -1
  33. package/package.json +1 -1
  34. package/dist/chunks/xml-js-Bbc0NeKa.es.js +0 -2
  35. package/dist/chunks/{jszip-DAXEPCUv.es.js → jszip-BDk3JBqp.es.js} +3 -3
  36. package/dist/chunks/{jszip-B4LDL19y.cjs → jszip-u4dvXAKa.cjs} +3 -3
@@ -7752,11 +7752,7 @@
7752
7752
  var __accessCheck$2 = (obj, member, msg2) => member.has(obj) || __typeError$2("Cannot " + msg2);
7753
7753
  var __privateAdd$2 = (obj, member, value) => member.has(obj) ? __typeError$2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7754
7754
  var __privateMethod$2 = (obj, member, method) => (__accessCheck$2(obj, member, "access private method"), method);
7755
- var _a, _DocxExporter_instances, generate_xml_as_list_fn, replaceSpecialCharacters_fn, generateXml_fn, _SuperConverter_instances, exportNumberingFile_fn, prepareCommentsXmlFilesForExport_fn, exportProcessHeadersFooters_fn, exportProcessNewRelationships_fn, exportProcessMediaFiles_fn;
7756
- var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
7757
- function getDefaultExportFromCjs$1$1(x) {
7758
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
7759
- }
7755
+ var _a, _DocxExporter_instances, generate_xml_as_list_fn, replaceSpecialCharacters_fn, generateXml_fn, _SuperConverter_instances, generateDocumentHash_fn, exportNumberingFile_fn, prepareCommentsXmlFilesForExport_fn, exportProcessHeadersFooters_fn, exportProcessNewRelationships_fn, exportProcessMediaFiles_fn;
7760
7756
  var buffer = {};
7761
7757
  var base64Js = {};
7762
7758
  base64Js.byteLength = byteLength;
@@ -9523,6 +9519,10 @@
9523
9519
  }
9524
9520
  })(buffer);
9525
9521
  const Buffer2 = buffer.Buffer;
9522
+ var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
9523
+ function getDefaultExportFromCjs$2(x) {
9524
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
9525
+ }
9526
9526
  var sax = {};
9527
9527
  var events$2 = { exports: {} };
9528
9528
  var hasRequiredEvents;
@@ -9925,7 +9925,7 @@
9925
9925
  }
9926
9926
  return inherits_browser.exports;
9927
9927
  }
9928
- function getDefaultExportFromCjs$2(x) {
9928
+ function getDefaultExportFromCjs$1(x) {
9929
9929
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
9930
9930
  }
9931
9931
  var browser$1 = { exports: {} };
@@ -10086,7 +10086,7 @@
10086
10086
  return 0;
10087
10087
  };
10088
10088
  var browserExports = browser$1.exports;
10089
- const process$1$1 = /* @__PURE__ */ getDefaultExportFromCjs$2(browserExports);
10089
+ const process$1$1 = /* @__PURE__ */ getDefaultExportFromCjs$1(browserExports);
10090
10090
  var streamBrowser;
10091
10091
  var hasRequiredStreamBrowser;
10092
10092
  function requireStreamBrowser() {
@@ -19071,7 +19071,7 @@
19071
19071
  return lib;
19072
19072
  }
19073
19073
  var libExports = requireLib();
19074
- const xmljs = /* @__PURE__ */ getDefaultExportFromCjs$1$1(libExports);
19074
+ const xmljs = /* @__PURE__ */ getDefaultExportFromCjs$2(libExports);
19075
19075
  var getRandomValues$1;
19076
19076
  var rnds8$1 = new Uint8Array(16);
19077
19077
  function rng$1() {
@@ -19106,6 +19106,306 @@
19106
19106
  rnds[8] = rnds[8] & 63 | 128;
19107
19107
  return stringify$1(rnds);
19108
19108
  }
19109
+ function getDefaultExportFromCjs$3(x) {
19110
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
19111
+ }
19112
+ const CRC_TABLE = new Int32Array([
19113
+ 0,
19114
+ 1996959894,
19115
+ 3993919788,
19116
+ 2567524794,
19117
+ 124634137,
19118
+ 1886057615,
19119
+ 3915621685,
19120
+ 2657392035,
19121
+ 249268274,
19122
+ 2044508324,
19123
+ 3772115230,
19124
+ 2547177864,
19125
+ 162941995,
19126
+ 2125561021,
19127
+ 3887607047,
19128
+ 2428444049,
19129
+ 498536548,
19130
+ 1789927666,
19131
+ 4089016648,
19132
+ 2227061214,
19133
+ 450548861,
19134
+ 1843258603,
19135
+ 4107580753,
19136
+ 2211677639,
19137
+ 325883990,
19138
+ 1684777152,
19139
+ 4251122042,
19140
+ 2321926636,
19141
+ 335633487,
19142
+ 1661365465,
19143
+ 4195302755,
19144
+ 2366115317,
19145
+ 997073096,
19146
+ 1281953886,
19147
+ 3579855332,
19148
+ 2724688242,
19149
+ 1006888145,
19150
+ 1258607687,
19151
+ 3524101629,
19152
+ 2768942443,
19153
+ 901097722,
19154
+ 1119000684,
19155
+ 3686517206,
19156
+ 2898065728,
19157
+ 853044451,
19158
+ 1172266101,
19159
+ 3705015759,
19160
+ 2882616665,
19161
+ 651767980,
19162
+ 1373503546,
19163
+ 3369554304,
19164
+ 3218104598,
19165
+ 565507253,
19166
+ 1454621731,
19167
+ 3485111705,
19168
+ 3099436303,
19169
+ 671266974,
19170
+ 1594198024,
19171
+ 3322730930,
19172
+ 2970347812,
19173
+ 795835527,
19174
+ 1483230225,
19175
+ 3244367275,
19176
+ 3060149565,
19177
+ 1994146192,
19178
+ 31158534,
19179
+ 2563907772,
19180
+ 4023717930,
19181
+ 1907459465,
19182
+ 112637215,
19183
+ 2680153253,
19184
+ 3904427059,
19185
+ 2013776290,
19186
+ 251722036,
19187
+ 2517215374,
19188
+ 3775830040,
19189
+ 2137656763,
19190
+ 141376813,
19191
+ 2439277719,
19192
+ 3865271297,
19193
+ 1802195444,
19194
+ 476864866,
19195
+ 2238001368,
19196
+ 4066508878,
19197
+ 1812370925,
19198
+ 453092731,
19199
+ 2181625025,
19200
+ 4111451223,
19201
+ 1706088902,
19202
+ 314042704,
19203
+ 2344532202,
19204
+ 4240017532,
19205
+ 1658658271,
19206
+ 366619977,
19207
+ 2362670323,
19208
+ 4224994405,
19209
+ 1303535960,
19210
+ 984961486,
19211
+ 2747007092,
19212
+ 3569037538,
19213
+ 1256170817,
19214
+ 1037604311,
19215
+ 2765210733,
19216
+ 3554079995,
19217
+ 1131014506,
19218
+ 879679996,
19219
+ 2909243462,
19220
+ 3663771856,
19221
+ 1141124467,
19222
+ 855842277,
19223
+ 2852801631,
19224
+ 3708648649,
19225
+ 1342533948,
19226
+ 654459306,
19227
+ 3188396048,
19228
+ 3373015174,
19229
+ 1466479909,
19230
+ 544179635,
19231
+ 3110523913,
19232
+ 3462522015,
19233
+ 1591671054,
19234
+ 702138776,
19235
+ 2966460450,
19236
+ 3352799412,
19237
+ 1504918807,
19238
+ 783551873,
19239
+ 3082640443,
19240
+ 3233442989,
19241
+ 3988292384,
19242
+ 2596254646,
19243
+ 62317068,
19244
+ 1957810842,
19245
+ 3939845945,
19246
+ 2647816111,
19247
+ 81470997,
19248
+ 1943803523,
19249
+ 3814918930,
19250
+ 2489596804,
19251
+ 225274430,
19252
+ 2053790376,
19253
+ 3826175755,
19254
+ 2466906013,
19255
+ 167816743,
19256
+ 2097651377,
19257
+ 4027552580,
19258
+ 2265490386,
19259
+ 503444072,
19260
+ 1762050814,
19261
+ 4150417245,
19262
+ 2154129355,
19263
+ 426522225,
19264
+ 1852507879,
19265
+ 4275313526,
19266
+ 2312317920,
19267
+ 282753626,
19268
+ 1742555852,
19269
+ 4189708143,
19270
+ 2394877945,
19271
+ 397917763,
19272
+ 1622183637,
19273
+ 3604390888,
19274
+ 2714866558,
19275
+ 953729732,
19276
+ 1340076626,
19277
+ 3518719985,
19278
+ 2797360999,
19279
+ 1068828381,
19280
+ 1219638859,
19281
+ 3624741850,
19282
+ 2936675148,
19283
+ 906185462,
19284
+ 1090812512,
19285
+ 3747672003,
19286
+ 2825379669,
19287
+ 829329135,
19288
+ 1181335161,
19289
+ 3412177804,
19290
+ 3160834842,
19291
+ 628085408,
19292
+ 1382605366,
19293
+ 3423369109,
19294
+ 3138078467,
19295
+ 570562233,
19296
+ 1426400815,
19297
+ 3317316542,
19298
+ 2998733608,
19299
+ 733239954,
19300
+ 1555261956,
19301
+ 3268935591,
19302
+ 3050360625,
19303
+ 752459403,
19304
+ 1541320221,
19305
+ 2607071920,
19306
+ 3965973030,
19307
+ 1969922972,
19308
+ 40735498,
19309
+ 2617837225,
19310
+ 3943577151,
19311
+ 1913087877,
19312
+ 83908371,
19313
+ 2512341634,
19314
+ 3803740692,
19315
+ 2075208622,
19316
+ 213261112,
19317
+ 2463272603,
19318
+ 3855990285,
19319
+ 2094854071,
19320
+ 198958881,
19321
+ 2262029012,
19322
+ 4057260610,
19323
+ 1759359992,
19324
+ 534414190,
19325
+ 2176718541,
19326
+ 4139329115,
19327
+ 1873836001,
19328
+ 414664567,
19329
+ 2282248934,
19330
+ 4279200368,
19331
+ 1711684554,
19332
+ 285281116,
19333
+ 2405801727,
19334
+ 4167216745,
19335
+ 1634467795,
19336
+ 376229701,
19337
+ 2685067896,
19338
+ 3608007406,
19339
+ 1308918612,
19340
+ 956543938,
19341
+ 2808555105,
19342
+ 3495958263,
19343
+ 1231636301,
19344
+ 1047427035,
19345
+ 2932959818,
19346
+ 3654703836,
19347
+ 1088359270,
19348
+ 936918e3,
19349
+ 2847714899,
19350
+ 3736837829,
19351
+ 1202900863,
19352
+ 817233897,
19353
+ 3183342108,
19354
+ 3401237130,
19355
+ 1404277552,
19356
+ 615818150,
19357
+ 3134207493,
19358
+ 3453421203,
19359
+ 1423857449,
19360
+ 601450431,
19361
+ 3009837614,
19362
+ 3294710456,
19363
+ 1567103746,
19364
+ 711928724,
19365
+ 3020668471,
19366
+ 3272380065,
19367
+ 1510334235,
19368
+ 755167117
19369
+ ]);
19370
+ function ensureBuffer(input) {
19371
+ if (Buffer2.isBuffer(input)) {
19372
+ return input;
19373
+ }
19374
+ if (typeof input === "number") {
19375
+ return Buffer2.alloc(input);
19376
+ } else if (typeof input === "string") {
19377
+ return Buffer2.from(input);
19378
+ } else {
19379
+ throw new Error("input must be buffer, number, or string, received " + typeof input);
19380
+ }
19381
+ }
19382
+ function bufferizeInt(num) {
19383
+ const tmp = ensureBuffer(4);
19384
+ tmp.writeInt32BE(num, 0);
19385
+ return tmp;
19386
+ }
19387
+ function _crc32(buf, previous) {
19388
+ buf = ensureBuffer(buf);
19389
+ if (Buffer2.isBuffer(previous)) {
19390
+ previous = previous.readUInt32BE(0);
19391
+ }
19392
+ let crc = ~~previous ^ -1;
19393
+ for (var n = 0; n < buf.length; n++) {
19394
+ crc = CRC_TABLE[(crc ^ buf[n]) & 255] ^ crc >>> 8;
19395
+ }
19396
+ return crc ^ -1;
19397
+ }
19398
+ function crc32() {
19399
+ return bufferizeInt(_crc32.apply(null, arguments));
19400
+ }
19401
+ crc32.signed = function() {
19402
+ return _crc32.apply(null, arguments);
19403
+ };
19404
+ crc32.unsigned = function() {
19405
+ return _crc32.apply(null, arguments) >>> 0;
19406
+ };
19407
+ var bufferCrc32 = crc32;
19408
+ const index$2 = /* @__PURE__ */ getDefaultExportFromCjs$3(bufferCrc32);
19109
19409
  function callOrGet(value, context = null, ...props) {
19110
19410
  if (typeof value === "function") {
19111
19411
  if (context) return value.bind(context)(...props);
@@ -22787,18 +23087,6 @@
22787
23087
  }
22788
23088
  ]
22789
23089
  };
22790
- const SETTINGS_CUSTOM_XML = {
22791
- elements: [
22792
- {
22793
- type: "element",
22794
- name: "w:settings",
22795
- attributes: {
22796
- "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
22797
- },
22798
- elements: []
22799
- }
22800
- ]
22801
- };
22802
23090
  const COMMENT_REF = {
22803
23091
  type: "element",
22804
23092
  name: "w:r",
@@ -25135,15 +25423,15 @@
25135
25423
  if (base2 < 0 || $pos.parent.type.spec.isolating || !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) || !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount)))
25136
25424
  return false;
25137
25425
  for (let d2 = $pos.depth - 1, i2 = depth - 2; d2 > base2; d2--, i2--) {
25138
- let node = $pos.node(d2), index22 = $pos.index(d2);
25426
+ let node = $pos.node(d2), index3 = $pos.index(d2);
25139
25427
  if (node.type.spec.isolating)
25140
25428
  return false;
25141
- let rest = node.content.cutByIndex(index22, node.childCount);
25429
+ let rest = node.content.cutByIndex(index3, node.childCount);
25142
25430
  let overrideChild = typesAfter && typesAfter[i2 + 1];
25143
25431
  if (overrideChild)
25144
25432
  rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs));
25145
25433
  let after = typesAfter && typesAfter[i2] || node;
25146
- if (!node.canReplace(index22 + 1, node.childCount) || !after.type.validContent(rest))
25434
+ if (!node.canReplace(index3 + 1, node.childCount) || !after.type.validContent(rest))
25147
25435
  return false;
25148
25436
  }
25149
25437
  let index2 = $pos.indexAfter(base2);
@@ -37882,7 +38170,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
37882
38170
  return he$2.exports;
37883
38171
  }
37884
38172
  var heExports = requireHe();
37885
- const he = /* @__PURE__ */ getDefaultExportFromCjs$1$1(heExports);
38173
+ const he = /* @__PURE__ */ getDefaultExportFromCjs$2(heExports);
37886
38174
  function translateFieldAnnotation(params2) {
37887
38175
  const { node, isFinalDoc, fieldsHighlightColor } = params2;
37888
38176
  const { attrs = {} } = node;
@@ -41020,7 +41308,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
41020
41308
  fileType: filePath.split(".").pop()
41021
41309
  };
41022
41310
  });
41023
- converter.telemetry.trackFileStructure(
41311
+ const trackStructure = (documentIdentifier = null) => converter.telemetry.trackFileStructure(
41024
41312
  {
41025
41313
  totalFiles: files.length,
41026
41314
  maxDepth: Math.max(...files.map((f) => f.fileDepth)),
@@ -41028,9 +41316,20 @@ Please report this to https://github.com/markedjs/marked.`, e) {
41028
41316
  files
41029
41317
  },
41030
41318
  converter.fileSource,
41031
- converter.documentId,
41319
+ converter.documentGuid ?? converter.documentId ?? null,
41320
+ documentIdentifier ?? converter.documentId ?? null,
41032
41321
  converter.documentInternalId
41033
41322
  );
41323
+ try {
41324
+ const identifierResult = converter.getDocumentIdentifier?.();
41325
+ if (identifierResult && typeof identifierResult.then === "function") {
41326
+ identifierResult.then(trackStructure).catch(() => trackStructure());
41327
+ } else {
41328
+ trackStructure(identifierResult);
41329
+ }
41330
+ } catch (error) {
41331
+ trackStructure();
41332
+ }
41034
41333
  }
41035
41334
  const nodeListHandler = defaultNodeListHandler();
41036
41335
  const bodyNode = json.elements[0].elements.find((el) => el.name === "w:body");
@@ -41581,6 +41880,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
41581
41880
  this.documentInternalId = null;
41582
41881
  this.fileSource = params2?.fileSource || null;
41583
41882
  this.documentId = params2?.documentId || null;
41883
+ this.documentGuid = null;
41884
+ this.documentHash = null;
41885
+ this.documentModified = false;
41584
41886
  if (this.docx.length || this.xml) this.parseFromXml();
41585
41887
  }
41586
41888
  static getFontTableEntry(docx, fontName) {
@@ -41628,50 +41930,177 @@ Please report this to https://github.com/markedjs/marked.`, e) {
41628
41930
  this.initialJSON = this.convertedXml["word/document.xml"];
41629
41931
  if (!this.initialJSON) this.initialJSON = this.parseXmlToJson(this.xml);
41630
41932
  this.declaration = this.initialJSON?.declaration;
41933
+ this.resolveDocumentGuid();
41631
41934
  }
41632
41935
  parseXmlToJson(xml) {
41633
41936
  const newXml = xml.replace(/(<w:t xml:space="preserve">)(\s+)(<\/w:t>)/g, "$1[[sdspace]]$2[[sdspace]]$3");
41634
41937
  return JSON.parse(xmljs.xml2json(newXml, null, 2));
41635
41938
  }
41636
- static getStoredSuperdocVersion(docx) {
41939
+ /**
41940
+ * Generic method to get a stored custom property from docx
41941
+ * @static
41942
+ * @param {Array} docx - Array of docx file objects
41943
+ * @param {string} propertyName - Name of the property to retrieve
41944
+ * @returns {string|null} The property value or null if not found
41945
+ */
41946
+ static getStoredCustomProperty(docx, propertyName) {
41637
41947
  try {
41638
41948
  const customXml = docx.find((doc2) => doc2.name === "docProps/custom.xml");
41639
- if (!customXml) return;
41949
+ if (!customXml) return null;
41640
41950
  const converter = new _SuperConverter2();
41641
41951
  const content = customXml.content;
41642
41952
  const contentJson = converter.parseXmlToJson(content);
41643
41953
  const properties = contentJson.elements.find((el) => el.name === "Properties");
41644
- if (!properties.elements) return;
41645
- const superdocVersion = properties.elements.find(
41646
- (el) => el.name === "property" && el.attributes.name === "SuperdocVersion"
41647
- );
41648
- if (!superdocVersion) return;
41649
- const version2 = superdocVersion.elements[0].elements[0].text;
41650
- return version2;
41954
+ if (!properties.elements) return null;
41955
+ const property2 = properties.elements.find((el) => el.name === "property" && el.attributes.name === propertyName);
41956
+ if (!property2) return null;
41957
+ return property2.elements[0].elements[0].text;
41651
41958
  } catch (e) {
41652
- console.warn("Error getting Superdoc version", e);
41653
- return;
41959
+ console.warn(`Error getting custom property ${propertyName}:`, e);
41960
+ return null;
41654
41961
  }
41655
41962
  }
41656
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.22.0") {
41963
+ /**
41964
+ * Generic method to set a stored custom property in docx
41965
+ * @static
41966
+ * @param {Object} docx - The docx object to store the property in
41967
+ * @param {string} propertyName - Name of the property
41968
+ * @param {string|Function} value - Value or function that returns the value
41969
+ * @param {boolean} preserveExisting - If true, won't overwrite existing values
41970
+ * @returns {string} The stored value
41971
+ */
41972
+ static setStoredCustomProperty(docx, propertyName, value, preserveExisting = false) {
41657
41973
  const customLocation = "docProps/custom.xml";
41658
- if (!docx[customLocation]) {
41659
- docx[customLocation] = generateCustomXml();
41660
- }
41661
- const customXml = docx["docProps/custom.xml"];
41662
- if (!customXml) return;
41663
- const properties = customXml.elements.find((el) => el.name === "Properties");
41974
+ if (!docx[customLocation]) docx[customLocation] = generateCustomXml();
41975
+ const customXml = docx[customLocation];
41976
+ const properties = customXml.elements?.find((el) => el.name === "Properties");
41977
+ if (!properties) return null;
41664
41978
  if (!properties.elements) properties.elements = [];
41665
- const superdocVersion = properties.elements.find(
41666
- (el) => el.name === "property" && el.attributes.name === "SuperdocVersion"
41667
- );
41668
- if (!superdocVersion) {
41669
- const newCustomXml = generateSuperdocVersion();
41670
- properties.elements.push(newCustomXml);
41979
+ let property2 = properties.elements.find((el) => el.name === "property" && el.attributes.name === propertyName);
41980
+ if (property2 && preserveExisting) {
41981
+ return property2.elements[0].elements[0].text;
41982
+ }
41983
+ const finalValue = typeof value === "function" ? value() : value;
41984
+ if (!property2) {
41985
+ const existingPids = properties.elements.filter((el) => el.attributes?.pid).map((el) => parseInt(el.attributes.pid, 10)).filter(Number.isInteger);
41986
+ const pid = existingPids.length > 0 ? Math.max(...existingPids) + 1 : 2;
41987
+ property2 = {
41988
+ type: "element",
41989
+ name: "property",
41990
+ attributes: {
41991
+ name: propertyName,
41992
+ fmtid: "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}",
41993
+ pid
41994
+ },
41995
+ elements: [
41996
+ {
41997
+ type: "element",
41998
+ name: "vt:lpwstr",
41999
+ elements: [
42000
+ {
42001
+ type: "text",
42002
+ text: finalValue
42003
+ }
42004
+ ]
42005
+ }
42006
+ ]
42007
+ };
42008
+ properties.elements.push(property2);
41671
42009
  } else {
41672
- superdocVersion.elements[0].elements[0].elements[0].text = version2;
42010
+ property2.elements[0].elements[0].text = finalValue;
42011
+ }
42012
+ return finalValue;
42013
+ }
42014
+ static getStoredSuperdocVersion(docx) {
42015
+ return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
42016
+ }
42017
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "0.22.0") {
42018
+ return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
42019
+ }
42020
+ /**
42021
+ * Get document GUID from docx files (static method)
42022
+ * @static
42023
+ * @param {Array} docx - Array of docx file objects
42024
+ * @returns {string|null} The document GUID
42025
+ */
42026
+ static extractDocumentGuid(docx) {
42027
+ try {
42028
+ const settingsXml = docx.find((doc2) => doc2.name === "word/settings.xml");
42029
+ if (!settingsXml) return null;
42030
+ const converter = new _SuperConverter2();
42031
+ const settingsJson = converter.parseXmlToJson(settingsXml.content);
42032
+ const settings = settingsJson.elements?.[0];
42033
+ if (!settings) return null;
42034
+ const docIdElement = settings.elements?.find((el) => el.name === "w15:docId");
42035
+ if (docIdElement?.attributes?.["w15:val"]) {
42036
+ return docIdElement.attributes["w15:val"].replace(/[{}]/g, "");
42037
+ }
42038
+ } catch {
41673
42039
  }
41674
- return docx;
42040
+ return _SuperConverter2.getStoredCustomProperty(docx, "DocumentGuid");
42041
+ }
42042
+ /**
42043
+ * Get the permanent document GUID
42044
+ * @returns {string|null} The document GUID (only for modified documents)
42045
+ */
42046
+ getDocumentGuid() {
42047
+ return this.documentGuid;
42048
+ }
42049
+ /**
42050
+ * Get the SuperDoc version for this converter instance
42051
+ * @returns {string|null} The SuperDoc version or null if not available
42052
+ */
42053
+ getSuperdocVersion() {
42054
+ if (this.docx) {
42055
+ return _SuperConverter2.getStoredSuperdocVersion(this.docx);
42056
+ }
42057
+ return null;
42058
+ }
42059
+ /**
42060
+ * Resolve existing document GUID (synchronous)
42061
+ */
42062
+ resolveDocumentGuid() {
42063
+ const microsoftGuid = this.getMicrosoftDocId();
42064
+ if (microsoftGuid) {
42065
+ this.documentGuid = microsoftGuid;
42066
+ return;
42067
+ }
42068
+ const customGuid = _SuperConverter2.getStoredCustomProperty(this.docx, "DocumentGuid");
42069
+ if (customGuid) {
42070
+ this.documentGuid = customGuid;
42071
+ }
42072
+ }
42073
+ /**
42074
+ * Get Microsoft's docId from settings.xml (READ ONLY)
42075
+ */
42076
+ getMicrosoftDocId() {
42077
+ this.getDocumentInternalId();
42078
+ if (this.documentInternalId) {
42079
+ return this.documentInternalId.replace(/[{}]/g, "");
42080
+ }
42081
+ return null;
42082
+ }
42083
+ /**
42084
+ * Get document identifier (GUID or hash) - async for lazy hash generation
42085
+ */
42086
+ async getDocumentIdentifier() {
42087
+ if (this.documentGuid) {
42088
+ return this.documentGuid;
42089
+ }
42090
+ if (!this.documentHash && this.fileSource) {
42091
+ this.documentHash = await __privateMethod$2(this, _SuperConverter_instances, generateDocumentHash_fn).call(this);
42092
+ }
42093
+ return this.documentHash;
42094
+ }
42095
+ /**
42096
+ * Promote from hash to GUID on first edit
42097
+ */
42098
+ promoteToGuid() {
42099
+ if (this.documentGuid) return this.documentGuid;
42100
+ this.documentGuid = this.getMicrosoftDocId() || v4$1();
42101
+ this.documentModified = true;
42102
+ this.documentHash = null;
42103
+ return this.documentGuid;
41675
42104
  }
41676
42105
  getDocumentDefaultStyles() {
41677
42106
  const styles = this.convertedXml["word/styles.xml"];
@@ -41760,20 +42189,14 @@ Please report this to https://github.com/markedjs/marked.`, e) {
41760
42189
  getDocumentInternalId() {
41761
42190
  const settingsLocation = "word/settings.xml";
41762
42191
  if (!this.convertedXml[settingsLocation]) {
41763
- this.convertedXml[settingsLocation] = SETTINGS_CUSTOM_XML;
42192
+ return;
41764
42193
  }
41765
- const settings = Object.assign({}, this.convertedXml[settingsLocation]);
41766
- if (!settings.elements[0]?.elements?.length) {
41767
- const idElement = this.createDocumentIdElement(settings);
41768
- settings.elements[0].elements = [idElement];
41769
- if (!settings.elements[0].attributes["xmlns:w15"]) {
41770
- settings.elements[0].attributes["xmlns:w15"] = "http://schemas.microsoft.com/office/word/2012/wordml";
41771
- }
41772
- this.convertedXml[settingsLocation] = settings;
42194
+ const settings = this.convertedXml[settingsLocation];
42195
+ if (!settings.elements?.[0]?.elements?.length) {
41773
42196
  return;
41774
42197
  }
41775
42198
  const w15DocId = settings.elements[0].elements.find((el) => el.name === "w15:docId");
41776
- this.documentInternalId = w15DocId?.attributes["w15:val"];
42199
+ this.documentInternalId = w15DocId?.attributes?.["w15:val"];
41777
42200
  }
41778
42201
  createDocumentIdElement() {
41779
42202
  const docId = v4$1().toUpperCase();
@@ -41862,7 +42285,13 @@ Please report this to https://github.com/markedjs/marked.`, e) {
41862
42285
  this.convertedXml = { ...this.convertedXml, ...updatedXml };
41863
42286
  const headFootRels = __privateMethod$2(this, _SuperConverter_instances, exportProcessHeadersFooters_fn).call(this, { isFinalDoc });
41864
42287
  __privateMethod$2(this, _SuperConverter_instances, exportProcessNewRelationships_fn).call(this, [...params2.relationships, ...commentsRels, ...headFootRels]);
41865
- storeSuperdocVersion(this.convertedXml);
42288
+ _SuperConverter2.setStoredSuperdocVersion(this.convertedXml);
42289
+ if (this.documentModified || this.documentGuid) {
42290
+ if (!this.documentGuid) {
42291
+ this.documentGuid = this.getMicrosoftDocId() || v4$1();
42292
+ }
42293
+ _SuperConverter2.setStoredCustomProperty(this.convertedXml, "DocumentGuid", this.documentGuid, true);
42294
+ }
41866
42295
  __privateMethod$2(this, _SuperConverter_instances, exportNumberingFile_fn).call(this, params2);
41867
42296
  return xml;
41868
42297
  }
@@ -41897,8 +42326,38 @@ Please report this to https://github.com/markedjs/marked.`, e) {
41897
42326
  });
41898
42327
  return { result, params: params2 };
41899
42328
  }
42329
+ // Deprecated methods for backward compatibility
42330
+ static getStoredSuperdocId(docx) {
42331
+ console.warn("getStoredSuperdocId is deprecated, use getDocumentGuid instead");
42332
+ return _SuperConverter2.extractDocumentGuid(docx);
42333
+ }
42334
+ static updateDocumentVersion(docx, version2) {
42335
+ console.warn("updateDocumentVersion is deprecated, use setStoredSuperdocVersion instead");
42336
+ return _SuperConverter2.setStoredSuperdocVersion(docx, version2);
42337
+ }
41900
42338
  };
41901
42339
  _SuperConverter_instances = /* @__PURE__ */ new WeakSet();
42340
+ generateDocumentHash_fn = async function() {
42341
+ if (!this.fileSource) return `HASH-${Date.now()}`;
42342
+ try {
42343
+ let buffer2;
42344
+ if (Buffer2.isBuffer(this.fileSource)) {
42345
+ buffer2 = this.fileSource;
42346
+ } else if (this.fileSource instanceof ArrayBuffer) {
42347
+ buffer2 = Buffer2.from(this.fileSource);
42348
+ } else if (this.fileSource instanceof Blob || this.fileSource instanceof File) {
42349
+ const arrayBuffer = await this.fileSource.arrayBuffer();
42350
+ buffer2 = Buffer2.from(arrayBuffer);
42351
+ } else {
42352
+ return `HASH-${Date.now()}`;
42353
+ }
42354
+ const hash2 = index$2(buffer2);
42355
+ return `HASH-${hash2.toString("hex").toUpperCase()}`;
42356
+ } catch (e) {
42357
+ console.warn("Could not generate document hash:", e);
42358
+ return `HASH-${Date.now()}`;
42359
+ }
42360
+ };
41902
42361
  exportNumberingFile_fn = function() {
41903
42362
  const numberingPath = "word/numbering.xml";
41904
42363
  let numberingXml = this.convertedXml[numberingPath];
@@ -42119,52 +42578,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
42119
42578
  }));
42120
42579
  __publicField$2(_SuperConverter, "elements", /* @__PURE__ */ new Set(["w:document", "w:body", "w:p", "w:r", "w:t", "w:delText"]));
42121
42580
  let SuperConverter = _SuperConverter;
42122
- function storeSuperdocVersion(docx) {
42123
- const customLocation = "docProps/custom.xml";
42124
- if (!docx[customLocation]) docx[customLocation] = generateCustomXml();
42125
- const customXml = docx[customLocation];
42126
- const properties = customXml.elements.find((el) => el.name === "Properties");
42127
- if (!properties.elements) properties.elements = [];
42128
- const elements = properties.elements;
42129
- const cleanProperties = elements.filter((prop) => typeof prop === "object" && prop !== null).filter((prop) => {
42130
- const { attributes } = prop;
42131
- return attributes.name !== "SuperdocVersion";
42132
- });
42133
- let pid = 2;
42134
- try {
42135
- pid = cleanProperties.length ? Math.max(...elements.map((el) => el.attributes.pid)) + 1 : 2;
42136
- } catch {
42137
- }
42138
- cleanProperties.push(generateSuperdocVersion(pid));
42139
- properties.elements = cleanProperties;
42140
- return docx;
42141
- }
42142
42581
  function generateCustomXml() {
42143
42582
  return DEFAULT_CUSTOM_XML;
42144
42583
  }
42145
- function generateSuperdocVersion(pid = 2, version2 = "0.22.0") {
42146
- return {
42147
- type: "element",
42148
- name: "property",
42149
- attributes: {
42150
- name: "SuperdocVersion",
42151
- fmtid: "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}",
42152
- pid
42153
- },
42154
- elements: [
42155
- {
42156
- type: "element",
42157
- name: "vt:lpwstr",
42158
- elements: [
42159
- {
42160
- type: "text",
42161
- text: version2
42162
- }
42163
- ]
42164
- }
42165
- ]
42166
- };
42167
- }
42168
42584
  function commonjsRequire(path) {
42169
42585
  throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
42170
42586
  }
@@ -44480,7 +44896,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
44480
44896
  return jszip_min.exports;
44481
44897
  }
44482
44898
  var jszip_minExports = requireJszip_min();
44483
- const JSZip = /* @__PURE__ */ getDefaultExportFromCjs$1$1(jszip_minExports);
44899
+ const JSZip = /* @__PURE__ */ getDefaultExportFromCjs$2(jszip_minExports);
44484
44900
  const isXmlLike = (name) => /\.xml$|\.rels$/i.test(name);
44485
44901
  function sniffEncoding(u8) {
44486
44902
  if (u8.length >= 2) {
@@ -54435,15 +54851,39 @@ Please report this to https://github.com/markedjs/marked.`, e) {
54435
54851
  if (near) {
54436
54852
  const isSameAsTarget = nearKind === targetKind;
54437
54853
  if (isSameAsTarget) {
54438
- const { pos: pos2, node } = near;
54439
- const spanFromBefore2 = pos2;
54440
- const spanToBefore2 = pos2 + node.nodeSize;
54441
- const paras = [];
54442
- for (let i2 = 0; i2 < node.childCount; i2++) {
54443
- const li = node.child(i2);
54444
- paras.push(li.firstChild || editor.schema.nodes.paragraph.create());
54445
- }
54446
- tr.replaceWith(pos2, pos2 + node.nodeSize, paras);
54854
+ const candidateLists = collectIntersectingTopLists({ doc: doc2, selection, OrderedType, BulletType });
54855
+ let listsToUnwrap = candidateLists.filter(({ node }) => getEffectiveListKind(node) === targetKind);
54856
+ if (listsToUnwrap.length === 0 && getEffectiveListKind(near.node) === targetKind) {
54857
+ listsToUnwrap = [{ node: near.node, pos: near.pos, depth: near.depth ?? null }];
54858
+ }
54859
+ if (listsToUnwrap.length === 0) return false;
54860
+ let spanFromBefore2 = listsToUnwrap[0].pos;
54861
+ let spanToBefore2 = listsToUnwrap[0].pos + listsToUnwrap[0].node.nodeSize;
54862
+ for (let i2 = 1; i2 < listsToUnwrap.length; i2++) {
54863
+ const { node, pos: pos2 } = listsToUnwrap[i2];
54864
+ spanFromBefore2 = Math.min(spanFromBefore2, pos2);
54865
+ spanToBefore2 = Math.max(spanToBefore2, pos2 + node.nodeSize);
54866
+ }
54867
+ const ParagraphType = editor.schema.nodes.paragraph;
54868
+ listsToUnwrap.sort((a, b2) => b2.pos - a.pos);
54869
+ for (const { node, pos: pos2 } of listsToUnwrap) {
54870
+ const mappedFrom = tr.mapping.map(pos2, -1);
54871
+ const mappedTo = tr.mapping.map(pos2 + node.nodeSize, 1);
54872
+ const currentListNode = tr.doc.nodeAt(mappedFrom);
54873
+ const sourceListNode = currentListNode && (currentListNode.type === OrderedType || currentListNode.type === BulletType) ? currentListNode : node;
54874
+ const paragraphs = [];
54875
+ for (let i2 = 0; i2 < sourceListNode.childCount; i2++) {
54876
+ const li = sourceListNode.child(i2);
54877
+ if (li.type !== editor.schema.nodes.listItem) continue;
54878
+ const firstChild = li.firstChild;
54879
+ paragraphs.push(firstChild || ParagraphType.create());
54880
+ }
54881
+ if (paragraphs.length === 0) {
54882
+ paragraphs.push(ParagraphType.create());
54883
+ }
54884
+ const replacement = paragraphs.length === 1 ? paragraphs[0] : Fragment.from(paragraphs);
54885
+ tr.replaceWith(mappedFrom, mappedTo, replacement);
54886
+ }
54447
54887
  setMappedSelectionSpan(tr, spanFromBefore2, spanToBefore2);
54448
54888
  if (dispatch) dispatch(tr);
54449
54889
  return true;
@@ -59240,19 +59680,34 @@ Please report this to https://github.com/markedjs/marked.`, e) {
59240
59680
  * @returns {string} Document version
59241
59681
  */
59242
59682
  static getDocumentVersion(doc2) {
59243
- const version2 = SuperConverter.getStoredSuperdocVersion(doc2);
59244
- return version2;
59683
+ return SuperConverter.getStoredSuperdocVersion(doc2);
59245
59684
  }
59246
59685
  /**
59247
- * Update the document version
59686
+ * Set the document version
59248
59687
  * @static
59249
59688
  * @param {Object} doc - Document object
59250
59689
  * @param {string} version - New version
59251
- * @returns {Object}
59690
+ * @returns {string} The set version
59691
+ */
59692
+ static setDocumentVersion(doc2, version2) {
59693
+ return SuperConverter.setStoredSuperdocVersion(doc2, version2);
59694
+ }
59695
+ /**
59696
+ * Get the document GUID
59697
+ * @static
59698
+ * @param {Object} doc - Document object
59699
+ * @returns {string|null} Document GUID
59700
+ */
59701
+ static getDocumentGuid(doc2) {
59702
+ return SuperConverter.extractDocumentGuid(doc2);
59703
+ }
59704
+ // Deprecated
59705
+ /**
59706
+ * @deprecated use setDocumentVersion instead
59252
59707
  */
59253
59708
  static updateDocumentVersion(doc2, version2) {
59254
- const updatedContent = SuperConverter.updateDocumentVersion(doc2, version2);
59255
- return updatedContent;
59709
+ console.warn("updateDocumentVersion is deprecated, use setDocumentVersion instead");
59710
+ return _Editor2.setDocumentVersion(doc2, version2);
59256
59711
  }
59257
59712
  /**
59258
59713
  * Creates all node views.
@@ -59388,6 +59843,43 @@ Please report this to https://github.com/markedjs/marked.`, e) {
59388
59843
  }
59389
59844
  window.addEventListener("resize", () => handleResize);
59390
59845
  }
59846
+ /**
59847
+ * Get document identifier for telemetry (async - may generate hash)
59848
+ * @returns {Promise<string>} GUID for modified docs, hash for unmodified
59849
+ */
59850
+ async getDocumentIdentifier() {
59851
+ return await this.converter?.getDocumentIdentifier() || null;
59852
+ }
59853
+ /**
59854
+ * Get permanent document GUID (sync - only for modified documents)
59855
+ * @returns {string|null} GUID or null if document hasn't been modified
59856
+ */
59857
+ getDocumentGuid() {
59858
+ return this.converter?.documentGuid || null;
59859
+ }
59860
+ /**
59861
+ * Check if document has been modified
59862
+ * @returns {boolean}
59863
+ */
59864
+ isDocumentModified() {
59865
+ return this.converter?.documentModified || false;
59866
+ }
59867
+ /**
59868
+ * Get telemetry data (async because of lazy hash generation)
59869
+ */
59870
+ async getTelemetryData() {
59871
+ return {
59872
+ documentId: await this.getDocumentIdentifier(),
59873
+ isModified: this.isDocumentModified(),
59874
+ isPermanentId: !!this.converter?.documentGuid,
59875
+ version: this.converter?.getSuperdocVersion()
59876
+ };
59877
+ }
59878
+ // Deprecated for backward compatibility
59879
+ getDocumentId() {
59880
+ console.warn("getDocumentId is deprecated, use getDocumentGuid instead");
59881
+ return this.getDocumentGuid();
59882
+ }
59391
59883
  /**
59392
59884
  * Get attrs of the currently selected node or mark.
59393
59885
  * @param {String} nameOrType
@@ -59419,6 +59911,21 @@ Please report this to https://github.com/markedjs/marked.`, e) {
59419
59911
  getJSON() {
59420
59912
  return this.state.doc.toJSON();
59421
59913
  }
59914
+ /**
59915
+ * Get document metadata including GUID, modification status, and version
59916
+ * @returns {{
59917
+ * documentGuid: string | null,
59918
+ * isModified: boolean,
59919
+ * version: string | null
59920
+ * }} Document metadata
59921
+ */
59922
+ getMetadata() {
59923
+ return {
59924
+ documentGuid: this.converter?.documentGuid || null,
59925
+ isModified: this.isDocumentModified(),
59926
+ version: this.converter?.getSuperdocVersion() || null
59927
+ };
59928
+ }
59422
59929
  /**
59423
59930
  * Get the editor content as HTML
59424
59931
  * @param {Object} options - Options for the HTML serializer
@@ -59436,6 +59943,13 @@ Please report this to https://github.com/markedjs/marked.`, e) {
59436
59943
  }
59437
59944
  return html;
59438
59945
  }
59946
+ /**
59947
+ * Get the document version from the converter
59948
+ * @returns {string|null} The SuperDoc version stored in the document
59949
+ */
59950
+ getDocumentVersion() {
59951
+ return this.converter?.getSuperdocVersion() || null;
59952
+ }
59439
59953
  /**
59440
59954
  * Create a child editor linked to this editor.
59441
59955
  * This is useful for creating header/footer editors that are linked to the main editor.
@@ -59518,7 +60032,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
59518
60032
  if (exportXmlOnly || exportJsonOnly) return documentXml;
59519
60033
  const customXml = this.converter.schemaToXml(this.converter.convertedXml["docProps/custom.xml"].elements[0]);
59520
60034
  const styles = this.converter.schemaToXml(this.converter.convertedXml["word/styles.xml"].elements[0]);
59521
- const customSettings = this.converter.schemaToXml(this.converter.convertedXml["word/settings.xml"].elements[0]);
60035
+ const hasCustomSettings = !!this.converter.convertedXml["word/settings.xml"]?.elements?.length;
60036
+ const customSettings = hasCustomSettings ? this.converter.schemaToXml(this.converter.convertedXml["word/settings.xml"]?.elements?.[0]) : null;
59522
60037
  const rels = this.converter.schemaToXml(this.converter.convertedXml["word/_rels/document.xml.rels"].elements[0]);
59523
60038
  const media = this.converter.addedMedia;
59524
60039
  const updatedHeadersFooters = {};
@@ -59534,13 +60049,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
59534
60049
  ...this.options.customUpdatedFiles,
59535
60050
  "word/document.xml": String(documentXml),
59536
60051
  "docProps/custom.xml": String(customXml),
59537
- "word/settings.xml": String(customSettings),
59538
60052
  "word/_rels/document.xml.rels": String(rels),
59539
60053
  "word/numbering.xml": String(numbering),
59540
60054
  // Replace & with &amp; in styles.xml as DOCX viewers can't handle it
59541
60055
  "word/styles.xml": String(styles).replace(/&/gi, "&amp;"),
59542
60056
  ...updatedHeadersFooters
59543
60057
  };
60058
+ if (hasCustomSettings) {
60059
+ updatedDocs["word/settings.xml"] = String(customSettings);
60060
+ }
59544
60061
  if (comments.length) {
59545
60062
  const commentsXml = this.converter.schemaToXml(this.converter.convertedXml["word/comments.xml"].elements[0]);
59546
60063
  const commentsExtendedXml = this.converter.schemaToXml(
@@ -60160,6 +60677,13 @@ Please report this to https://github.com/markedjs/marked.`, e) {
60160
60677
  if (!transaction.docChanged) {
60161
60678
  return;
60162
60679
  }
60680
+ if (transaction.docChanged && this.converter) {
60681
+ if (!this.converter.documentGuid) {
60682
+ this.converter.promoteToGuid();
60683
+ console.debug("Document modified - assigned GUID:", this.converter.documentGuid);
60684
+ }
60685
+ this.converter.documentModified = true;
60686
+ }
60163
60687
  this.emit("update", {
60164
60688
  editor: this,
60165
60689
  transaction
@@ -73087,7 +73611,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
73087
73611
  }
73088
73612
  return formatList.filter((format) => Object.hasOwn(format, "type") && Object.hasOwn(format, "attrs"));
73089
73613
  };
73090
- const index$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
73614
+ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
73091
73615
  __proto__: null,
73092
73616
  addMarkStep,
73093
73617
  documentHelpers,
@@ -89793,7 +90317,7 @@ ${style2}
89793
90317
  return eventemitter3$1.exports;
89794
90318
  }
89795
90319
  var eventemitter3Exports$1 = requireEventemitter3$1();
89796
- const EventEmitter$1 = /* @__PURE__ */ getDefaultExportFromCjs$1$1(eventemitter3Exports$1);
90320
+ const EventEmitter$1 = /* @__PURE__ */ getDefaultExportFromCjs$2(eventemitter3Exports$1);
89797
90321
  const useToolbarItem = (options) => {
89798
90322
  const types2 = ["button", "options", "separator", "dropdown", "overflow"];
89799
90323
  if (!types2.includes(options.type)) {
@@ -94601,306 +95125,6 @@ ${style2}
94601
95125
  delete el.__clickOutsideHandler;
94602
95126
  }
94603
95127
  };
94604
- function getDefaultExportFromCjs$1(x) {
94605
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
94606
- }
94607
- const CRC_TABLE = new Int32Array([
94608
- 0,
94609
- 1996959894,
94610
- 3993919788,
94611
- 2567524794,
94612
- 124634137,
94613
- 1886057615,
94614
- 3915621685,
94615
- 2657392035,
94616
- 249268274,
94617
- 2044508324,
94618
- 3772115230,
94619
- 2547177864,
94620
- 162941995,
94621
- 2125561021,
94622
- 3887607047,
94623
- 2428444049,
94624
- 498536548,
94625
- 1789927666,
94626
- 4089016648,
94627
- 2227061214,
94628
- 450548861,
94629
- 1843258603,
94630
- 4107580753,
94631
- 2211677639,
94632
- 325883990,
94633
- 1684777152,
94634
- 4251122042,
94635
- 2321926636,
94636
- 335633487,
94637
- 1661365465,
94638
- 4195302755,
94639
- 2366115317,
94640
- 997073096,
94641
- 1281953886,
94642
- 3579855332,
94643
- 2724688242,
94644
- 1006888145,
94645
- 1258607687,
94646
- 3524101629,
94647
- 2768942443,
94648
- 901097722,
94649
- 1119000684,
94650
- 3686517206,
94651
- 2898065728,
94652
- 853044451,
94653
- 1172266101,
94654
- 3705015759,
94655
- 2882616665,
94656
- 651767980,
94657
- 1373503546,
94658
- 3369554304,
94659
- 3218104598,
94660
- 565507253,
94661
- 1454621731,
94662
- 3485111705,
94663
- 3099436303,
94664
- 671266974,
94665
- 1594198024,
94666
- 3322730930,
94667
- 2970347812,
94668
- 795835527,
94669
- 1483230225,
94670
- 3244367275,
94671
- 3060149565,
94672
- 1994146192,
94673
- 31158534,
94674
- 2563907772,
94675
- 4023717930,
94676
- 1907459465,
94677
- 112637215,
94678
- 2680153253,
94679
- 3904427059,
94680
- 2013776290,
94681
- 251722036,
94682
- 2517215374,
94683
- 3775830040,
94684
- 2137656763,
94685
- 141376813,
94686
- 2439277719,
94687
- 3865271297,
94688
- 1802195444,
94689
- 476864866,
94690
- 2238001368,
94691
- 4066508878,
94692
- 1812370925,
94693
- 453092731,
94694
- 2181625025,
94695
- 4111451223,
94696
- 1706088902,
94697
- 314042704,
94698
- 2344532202,
94699
- 4240017532,
94700
- 1658658271,
94701
- 366619977,
94702
- 2362670323,
94703
- 4224994405,
94704
- 1303535960,
94705
- 984961486,
94706
- 2747007092,
94707
- 3569037538,
94708
- 1256170817,
94709
- 1037604311,
94710
- 2765210733,
94711
- 3554079995,
94712
- 1131014506,
94713
- 879679996,
94714
- 2909243462,
94715
- 3663771856,
94716
- 1141124467,
94717
- 855842277,
94718
- 2852801631,
94719
- 3708648649,
94720
- 1342533948,
94721
- 654459306,
94722
- 3188396048,
94723
- 3373015174,
94724
- 1466479909,
94725
- 544179635,
94726
- 3110523913,
94727
- 3462522015,
94728
- 1591671054,
94729
- 702138776,
94730
- 2966460450,
94731
- 3352799412,
94732
- 1504918807,
94733
- 783551873,
94734
- 3082640443,
94735
- 3233442989,
94736
- 3988292384,
94737
- 2596254646,
94738
- 62317068,
94739
- 1957810842,
94740
- 3939845945,
94741
- 2647816111,
94742
- 81470997,
94743
- 1943803523,
94744
- 3814918930,
94745
- 2489596804,
94746
- 225274430,
94747
- 2053790376,
94748
- 3826175755,
94749
- 2466906013,
94750
- 167816743,
94751
- 2097651377,
94752
- 4027552580,
94753
- 2265490386,
94754
- 503444072,
94755
- 1762050814,
94756
- 4150417245,
94757
- 2154129355,
94758
- 426522225,
94759
- 1852507879,
94760
- 4275313526,
94761
- 2312317920,
94762
- 282753626,
94763
- 1742555852,
94764
- 4189708143,
94765
- 2394877945,
94766
- 397917763,
94767
- 1622183637,
94768
- 3604390888,
94769
- 2714866558,
94770
- 953729732,
94771
- 1340076626,
94772
- 3518719985,
94773
- 2797360999,
94774
- 1068828381,
94775
- 1219638859,
94776
- 3624741850,
94777
- 2936675148,
94778
- 906185462,
94779
- 1090812512,
94780
- 3747672003,
94781
- 2825379669,
94782
- 829329135,
94783
- 1181335161,
94784
- 3412177804,
94785
- 3160834842,
94786
- 628085408,
94787
- 1382605366,
94788
- 3423369109,
94789
- 3138078467,
94790
- 570562233,
94791
- 1426400815,
94792
- 3317316542,
94793
- 2998733608,
94794
- 733239954,
94795
- 1555261956,
94796
- 3268935591,
94797
- 3050360625,
94798
- 752459403,
94799
- 1541320221,
94800
- 2607071920,
94801
- 3965973030,
94802
- 1969922972,
94803
- 40735498,
94804
- 2617837225,
94805
- 3943577151,
94806
- 1913087877,
94807
- 83908371,
94808
- 2512341634,
94809
- 3803740692,
94810
- 2075208622,
94811
- 213261112,
94812
- 2463272603,
94813
- 3855990285,
94814
- 2094854071,
94815
- 198958881,
94816
- 2262029012,
94817
- 4057260610,
94818
- 1759359992,
94819
- 534414190,
94820
- 2176718541,
94821
- 4139329115,
94822
- 1873836001,
94823
- 414664567,
94824
- 2282248934,
94825
- 4279200368,
94826
- 1711684554,
94827
- 285281116,
94828
- 2405801727,
94829
- 4167216745,
94830
- 1634467795,
94831
- 376229701,
94832
- 2685067896,
94833
- 3608007406,
94834
- 1308918612,
94835
- 956543938,
94836
- 2808555105,
94837
- 3495958263,
94838
- 1231636301,
94839
- 1047427035,
94840
- 2932959818,
94841
- 3654703836,
94842
- 1088359270,
94843
- 936918e3,
94844
- 2847714899,
94845
- 3736837829,
94846
- 1202900863,
94847
- 817233897,
94848
- 3183342108,
94849
- 3401237130,
94850
- 1404277552,
94851
- 615818150,
94852
- 3134207493,
94853
- 3453421203,
94854
- 1423857449,
94855
- 601450431,
94856
- 3009837614,
94857
- 3294710456,
94858
- 1567103746,
94859
- 711928724,
94860
- 3020668471,
94861
- 3272380065,
94862
- 1510334235,
94863
- 755167117
94864
- ]);
94865
- function ensureBuffer(input) {
94866
- if (Buffer.isBuffer(input)) {
94867
- return input;
94868
- }
94869
- if (typeof input === "number") {
94870
- return Buffer.alloc(input);
94871
- } else if (typeof input === "string") {
94872
- return Buffer.from(input);
94873
- } else {
94874
- throw new Error("input must be buffer, number, or string, received " + typeof input);
94875
- }
94876
- }
94877
- function bufferizeInt(num) {
94878
- const tmp = ensureBuffer(4);
94879
- tmp.writeInt32BE(num, 0);
94880
- return tmp;
94881
- }
94882
- function _crc32(buf, previous) {
94883
- buf = ensureBuffer(buf);
94884
- if (Buffer.isBuffer(previous)) {
94885
- previous = previous.readUInt32BE(0);
94886
- }
94887
- let crc = ~~previous ^ -1;
94888
- for (var n = 0; n < buf.length; n++) {
94889
- crc = CRC_TABLE[(crc ^ buf[n]) & 255] ^ crc >>> 8;
94890
- }
94891
- return crc ^ -1;
94892
- }
94893
- function crc32() {
94894
- return bufferizeInt(_crc32.apply(null, arguments));
94895
- }
94896
- crc32.signed = function() {
94897
- return _crc32.apply(null, arguments);
94898
- };
94899
- crc32.unsigned = function() {
94900
- return _crc32.apply(null, arguments) >>> 0;
94901
- };
94902
- var bufferCrc32 = crc32;
94903
- const index = /* @__PURE__ */ getDefaultExportFromCjs$1(bufferCrc32);
94904
95128
  function randomBytes(length2) {
94905
95129
  const array = new Uint8Array(length2);
94906
95130
  for (let i2 = 0; i2 < length2; i2++) {
@@ -94912,7 +95136,9 @@ ${style2}
94912
95136
  /** @type {boolean} */
94913
95137
  enabled;
94914
95138
  /** @type {string} */
94915
- superdocId;
95139
+ documentGuid;
95140
+ /** @type {string} */
95141
+ documentIdentifier;
94916
95142
  /** @type {string} */
94917
95143
  superdocVersion;
94918
95144
  /** @type {string} */
@@ -94953,7 +95179,8 @@ ${style2}
94953
95179
  this.enabled = config2.enabled ?? true;
94954
95180
  this.licenseKey = config2.licenseKey ?? Telemetry.COMMUNITY_LICENSE_KEY;
94955
95181
  this.endpoint = config2.endpoint ?? Telemetry.DEFAULT_ENDPOINT;
94956
- this.superdocId = config2.superdocId;
95182
+ this.documentGuid = config2.documentGuid;
95183
+ this.documentIdentifier = config2.documentIdentifier;
94957
95184
  this.superdocVersion = config2.superdocVersion;
94958
95185
  this.sessionId = this.generateId();
94959
95186
  }
@@ -94985,7 +95212,10 @@ ${style2}
94985
95212
  type: "usage",
94986
95213
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
94987
95214
  sessionId: this.sessionId,
94988
- superdocId: this.superdocId,
95215
+ documentGuid: this.documentGuid,
95216
+ // Updated field name
95217
+ documentIdentifier: this.documentIdentifier,
95218
+ // Include both
94989
95219
  superdocVersion: this.superdocVersion,
94990
95220
  file: this.documentInfo,
94991
95221
  browser: this.getBrowserInfo(),
@@ -95052,13 +95282,17 @@ ${style2}
95052
95282
  * Track file structure
95053
95283
  * @param {Object} structure - File structure information
95054
95284
  * @param {File} fileSource - original file
95055
- * @param {String} documentId - document ID
95056
- * @param {string} internalId - document ID form settings.xml
95285
+ * @param {String} documentId - document GUID
95286
+ * @param {string} documentIdentifier - document identifier (GUID or hash)
95287
+ * @param {string} internalId - document ID from settings.xml
95057
95288
  */
95058
- async trackFileStructure(structure, fileSource, documentId, internalId) {
95289
+ async trackFileStructure(structure, fileSource, documentId, documentIdentifier, internalId) {
95059
95290
  this.fileStructure = structure;
95060
95291
  this.documentInfo = await this.processDocument(fileSource, {
95061
- id: documentId,
95292
+ guid: documentId,
95293
+ // Updated parameter name
95294
+ identifier: documentIdentifier,
95295
+ // New parameter
95062
95296
  internalId
95063
95297
  });
95064
95298
  }
@@ -95073,34 +95307,19 @@ ${style2}
95073
95307
  console.warn("Telemetry: missing file source");
95074
95308
  return {};
95075
95309
  }
95076
- let hash2 = "";
95077
- try {
95078
- hash2 = await this.generateCrc32Hash(file);
95079
- } catch (error) {
95080
- console.error("Failed to generate file hash:", error);
95081
- }
95082
95310
  return {
95083
- id: options.id,
95311
+ guid: options.guid,
95312
+ // Updated from 'id'
95313
+ identifier: options.identifier,
95314
+ // New field
95084
95315
  name: file.name,
95085
95316
  size: file.size,
95086
- crc32: hash2,
95087
95317
  lastModified: file.lastModified ? new Date(file.lastModified).toISOString() : null,
95088
95318
  type: file.type || "docx",
95089
95319
  internalId: options.internalId
95320
+ // Microsoft's GUID if present
95090
95321
  };
95091
95322
  }
95092
- /**
95093
- * Generate CRC32 hash for a file
95094
- * @param {File} file - File to hash
95095
- * @returns {Promise<string>} CRC32 hash
95096
- * @private
95097
- */
95098
- async generateCrc32Hash(file) {
95099
- const arrayBuffer = await file.arrayBuffer();
95100
- const buffer2 = Buffer.from(arrayBuffer);
95101
- const hashBuffer = index(buffer2);
95102
- return hashBuffer.toString("hex");
95103
- }
95104
95323
  isTelemetryDataChanged() {
95105
95324
  const initialStatistics = {};
95106
95325
  const initialFileStructure = {};
@@ -98103,7 +98322,7 @@ ${reason}`);
98103
98322
  }, 0);
98104
98323
  };
98105
98324
  const createCommentForTrackChanges = (editor) => {
98106
- let trackedChanges = index$2.getTrackChanges(editor.state);
98325
+ let trackedChanges = index.getTrackChanges(editor.state);
98107
98326
  const groupedChanges = groupChanges(trackedChanges);
98108
98327
  const { tr } = editor.view.state;
98109
98328
  const { dispatch } = editor.view;
@@ -112836,7 +113055,7 @@ ${style2}
112836
113055
  exports2.getRichTextExtensions = getRichTextExtensions;
112837
113056
  exports2.registeredHandlers = registeredHandlers;
112838
113057
  exports2.superEditorHelpers = helpers;
112839
- exports2.trackChangesHelpers = index$2;
113058
+ exports2.trackChangesHelpers = index;
112840
113059
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
112841
113060
  }));
112842
113061
  //# sourceMappingURL=superdoc.umd.js.map