@harbour-enterprises/superdoc 0.12.20 → 0.12.22

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.
@@ -30664,7 +30664,7 @@
30664
30664
  return;
30665
30665
  }
30666
30666
  }
30667
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.12.20") {
30667
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.12.22") {
30668
30668
  const customLocation = "docProps/custom.xml";
30669
30669
  if (!docx[customLocation]) {
30670
30670
  docx[customLocation] = generateCustomXml();
@@ -31130,7 +31130,7 @@
31130
31130
  function generateCustomXml() {
31131
31131
  return DEFAULT_CUSTOM_XML;
31132
31132
  }
31133
- function generateSuperdocVersion(pid = 2, version2 = "0.12.20") {
31133
+ function generateSuperdocVersion(pid = 2, version2 = "0.12.22") {
31134
31134
  return {
31135
31135
  type: "element",
31136
31136
  name: "property",
@@ -46334,6 +46334,27 @@
46334
46334
  const alpha = activeThreadId == threadId ? "44" : "22";
46335
46335
  return `${color}${alpha}`;
46336
46336
  };
46337
+ const updateYdocDocxData = async (editor) => {
46338
+ if (!editor.options.ydoc) return;
46339
+ const metaMap = editor.options.ydoc.getMap("meta");
46340
+ const docx = [...metaMap.get("docx")];
46341
+ const newXml = await editor.exportDocx({ getUpdatedDocs: true });
46342
+ Object.keys(newXml).forEach((key) => {
46343
+ if (key.includes("header") || key.includes("footer")) {
46344
+ const fileIndex = docx.findIndex((item) => item.name === key);
46345
+ if (fileIndex > -1) {
46346
+ docx.splice(fileIndex, 1);
46347
+ }
46348
+ docx.push({
46349
+ name: key,
46350
+ content: newXml[key]
46351
+ });
46352
+ }
46353
+ });
46354
+ editor.options.ydoc.transact(() => {
46355
+ metaMap.set("docx", docx);
46356
+ }, { event: "docx-update", user: editor.options.user });
46357
+ };
46337
46358
  const PaginationPluginKey = new PluginKey("paginationPlugin");
46338
46359
  const initPaginationData = async (editor) => {
46339
46360
  if (!editor.converter) return;
@@ -46492,27 +46513,6 @@
46492
46513
  const setEditorToolbar = ({ editor }, mainEditor) => {
46493
46514
  editor.setToolbar(mainEditor.toolbar);
46494
46515
  };
46495
- const updateYdocDocxData = async (editor) => {
46496
- if (!editor.options.ydoc) return;
46497
- const metaMap = editor.options.ydoc.getMap("meta");
46498
- const docx = [...metaMap.get("docx")];
46499
- const newXml = await editor.exportDocx({ getUpdatedDocs: true });
46500
- Object.keys(newXml).forEach((key) => {
46501
- if (key.includes("header") || key.includes("footer")) {
46502
- const fileIndex = docx.findIndex((item) => item.name === key);
46503
- if (fileIndex > -1) {
46504
- docx.splice(fileIndex, 1);
46505
- }
46506
- docx.push({
46507
- name: key,
46508
- content: newXml[key]
46509
- });
46510
- }
46511
- });
46512
- editor.options.ydoc.transact(() => {
46513
- metaMap.set("docx", docx);
46514
- });
46515
- };
46516
46516
  const TRACK_CHANGE_MARKS = [TrackInsertMarkName, TrackDeleteMarkName, TrackFormatMarkName];
46517
46517
  const CommentsPluginKey = new PluginKey("comments");
46518
46518
  const CommentsPlugin = Extension.create({
@@ -47544,6 +47544,7 @@
47544
47544
  const undoPlugin = createUndoPlugin();
47545
47545
  initDocumentLockHandler(this.options.ydoc, this.editor);
47546
47546
  initSyncListener(this.options.ydoc, this.editor, this);
47547
+ initDocumentListener({ ydoc: this.options.ydoc, editor: this.editor });
47547
47548
  const [syncPlugin, fragment] = createSyncPlugin(this.options.ydoc, this.editor);
47548
47549
  this.options.fragment = fragment;
47549
47550
  const metaMap = this.options.ydoc.getMap("media");
@@ -47625,6 +47626,33 @@
47625
47626
  editor.emit("locked", { editor, isLocked, lockedBy });
47626
47627
  });
47627
47628
  };
47629
+ const checkDocxChanged = (transaction) => {
47630
+ for (const [key, value] of transaction.changed?.entries()) {
47631
+ if (value instanceof Set && value.has("docx")) {
47632
+ return true;
47633
+ }
47634
+ }
47635
+ return false;
47636
+ };
47637
+ const initDocumentListener = ({ ydoc, editor }) => {
47638
+ const debouncedUpdate = debounce$2((editor2) => {
47639
+ updateYdocDocxData(editor2);
47640
+ }, 1e3);
47641
+ ydoc.on("afterTransaction", (transaction) => {
47642
+ const { local } = transaction;
47643
+ const hasChangedDocx = checkDocxChanged(transaction);
47644
+ if (!hasChangedDocx && transaction.changed?.size && local) {
47645
+ debouncedUpdate(editor);
47646
+ }
47647
+ });
47648
+ };
47649
+ const debounce$2 = (fn2, wait) => {
47650
+ let timeout2 = null;
47651
+ return (...args) => {
47652
+ clearTimeout(timeout2);
47653
+ timeout2 = setTimeout(() => fn2.apply(void 0, args), wait);
47654
+ };
47655
+ };
47628
47656
  const initSyncListener = (ydoc, editor, extension) => {
47629
47657
  const provider2 = editor.options.collaborationProvider;
47630
47658
  if (!provider2) return;
@@ -48285,7 +48313,7 @@
48285
48313
  * @returns {Object | void} Migration results
48286
48314
  */
48287
48315
  processCollaborationMigrations() {
48288
- console.debug("[checkVersionMigrations] Current editor version", "0.12.20");
48316
+ console.debug("[checkVersionMigrations] Current editor version", "0.12.22");
48289
48317
  if (!this.options.ydoc) return;
48290
48318
  const metaMap = this.options.ydoc.getMap("meta");
48291
48319
  let docVersion = metaMap.get("version");
@@ -89464,7 +89492,7 @@ ${style2}
89464
89492
  this.config.colors = shuffleArray(this.config.colors);
89465
89493
  this.userColorMap = /* @__PURE__ */ new Map();
89466
89494
  this.colorIndex = 0;
89467
- this.version = "0.12.20";
89495
+ this.version = "0.12.22";
89468
89496
  console.debug("🦋 [superdoc] Using SuperDoc version:", this.version);
89469
89497
  this.superdocId = config.superdocId || v4();
89470
89498
  this.colors = this.config.colors;