@harbour-enterprises/superdoc 1.3.1-next.1 → 1.3.1-next.2

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.
@@ -36435,7 +36435,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36435
36435
  static getStoredSuperdocVersion(docx) {
36436
36436
  return SuperConverter.getStoredCustomProperty(docx, "SuperdocVersion");
36437
36437
  }
36438
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.3.1-next.1") {
36438
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.3.1-next.2") {
36439
36439
  return SuperConverter.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
36440
36440
  }
36441
36441
  /**
@@ -62245,7 +62245,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62245
62245
  return false;
62246
62246
  }
62247
62247
  };
62248
- const summaryVersion = "1.3.1-next.1";
62248
+ const summaryVersion = "1.3.1-next.2";
62249
62249
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
62250
62250
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
62251
62251
  function mapAttributes(attrs) {
@@ -64878,7 +64878,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
64878
64878
  * Process collaboration migrations
64879
64879
  */
64880
64880
  processCollaborationMigrations() {
64881
- console.debug("[checkVersionMigrations] Current editor version", "1.3.1-next.1");
64881
+ console.debug("[checkVersionMigrations] Current editor version", "1.3.1-next.2");
64882
64882
  if (!this.options.ydoc) return;
64883
64883
  const metaMap = this.options.ydoc.getMap("meta");
64884
64884
  let docVersion = metaMap.get("version");
@@ -71894,6 +71894,7 @@ ${l}
71894
71894
  this.layoutVersion = 0;
71895
71895
  this.layoutEpoch = 0;
71896
71896
  this.processedLayoutVersion = -1;
71897
+ this.currentMapping = null;
71897
71898
  this.onScrollHandler = null;
71898
71899
  this.onWindowScrollHandler = null;
71899
71900
  this.onResizeHandler = null;
@@ -71999,7 +72000,7 @@ ${l}
71999
72000
  this.blockLookup = nextLookup;
72000
72001
  this.changedBlocks = changed;
72001
72002
  }
72002
- paint(layout, mount2) {
72003
+ paint(layout, mount2, mapping) {
72003
72004
  if (!(mount2 instanceof HTMLElement)) {
72004
72005
  throw new Error("DomPainter.paint requires a valid HTMLElement mount");
72005
72006
  }
@@ -72008,6 +72009,13 @@ ${l}
72008
72009
  throw new Error("DomPainter.paint requires a DOM-like document");
72009
72010
  }
72010
72011
  this.doc = doc2;
72012
+ const isSimpleTransaction = mapping && mapping.maps.length === 1;
72013
+ if (mapping && !isSimpleTransaction) {
72014
+ this.blockLookup.forEach((_2, id) => this.changedBlocks.add(id));
72015
+ this.currentMapping = null;
72016
+ } else {
72017
+ this.currentMapping = mapping ?? null;
72018
+ }
72011
72019
  ensurePrintStyles(doc2);
72012
72020
  ensureLinkStyles(doc2);
72013
72021
  ensureTrackChangeStyles(doc2);
@@ -72034,6 +72042,7 @@ ${l}
72034
72042
  this.currentLayout = layout;
72035
72043
  this.pageStates = [];
72036
72044
  this.changedBlocks.clear();
72045
+ this.currentMapping = null;
72037
72046
  return;
72038
72047
  }
72039
72048
  if (mode === "book") {
@@ -72042,6 +72051,7 @@ ${l}
72042
72051
  this.currentLayout = layout;
72043
72052
  this.pageStates = [];
72044
72053
  this.changedBlocks.clear();
72054
+ this.currentMapping = null;
72045
72055
  return;
72046
72056
  }
72047
72057
  applyStyles$2(mount2, containerStyles);
@@ -72050,6 +72060,7 @@ ${l}
72050
72060
  this.renderVirtualized(layout, mount2);
72051
72061
  this.currentLayout = layout;
72052
72062
  this.changedBlocks.clear();
72063
+ this.currentMapping = null;
72053
72064
  return;
72054
72065
  }
72055
72066
  mount2.style.gap = `${this.pageGap}px`;
@@ -72060,6 +72071,7 @@ ${l}
72060
72071
  }
72061
72072
  this.currentLayout = layout;
72062
72073
  this.changedBlocks.clear();
72074
+ this.currentMapping = null;
72063
72075
  }
72064
72076
  // ----------------
72065
72077
  // Virtualized path
@@ -72591,6 +72603,8 @@ ${l}
72591
72603
  pageEl.replaceChild(replacement, current.element);
72592
72604
  current.element = replacement;
72593
72605
  current.signature = fragmentSignature(fragment, this.blockLookup);
72606
+ } else if (this.currentMapping) {
72607
+ this.updatePositionAttributes(current.element, this.currentMapping);
72594
72608
  }
72595
72609
  this.updateFragmentElement(current.element, fragment, contextBase.section);
72596
72610
  current.fragment = fragment;
@@ -72619,6 +72633,45 @@ ${l}
72619
72633
  state.fragments = nextFragments;
72620
72634
  this.renderDecorationsForPage(pageEl, page);
72621
72635
  }
72636
+ /**
72637
+ * Updates data-pm-start/data-pm-end attributes on all elements within a fragment
72638
+ * using the transaction's mapping. Skips header/footer content (separate PM coordinate space).
72639
+ * Also skips fragments that end before the edit point (their positions don't change).
72640
+ */
72641
+ updatePositionAttributes(fragmentEl, mapping) {
72642
+ if (fragmentEl.closest(".superdoc-page-header, .superdoc-page-footer")) {
72643
+ return;
72644
+ }
72645
+ try {
72646
+ const fragEnd = fragmentEl.dataset.pmEnd;
72647
+ if (fragEnd !== void 0 && fragEnd !== "") {
72648
+ const endNum = Number(fragEnd);
72649
+ if (Number.isFinite(endNum) && mapping.map(endNum, -1) === endNum) {
72650
+ return;
72651
+ }
72652
+ }
72653
+ const elements = fragmentEl.querySelectorAll("[data-pm-start], [data-pm-end]");
72654
+ const allElements = [fragmentEl, ...Array.from(elements)];
72655
+ for (const el of allElements) {
72656
+ const oldStart = el.dataset.pmStart;
72657
+ const oldEnd = el.dataset.pmEnd;
72658
+ if (oldStart !== void 0 && oldStart !== "") {
72659
+ const num = Number(oldStart);
72660
+ if (Number.isFinite(num)) {
72661
+ el.dataset.pmStart = String(mapping.map(num));
72662
+ }
72663
+ }
72664
+ if (oldEnd !== void 0 && oldEnd !== "") {
72665
+ const num = Number(oldEnd);
72666
+ if (Number.isFinite(num)) {
72667
+ el.dataset.pmEnd = String(mapping.map(num, -1));
72668
+ }
72669
+ }
72670
+ }
72671
+ } catch (error) {
72672
+ console.error("Error updating position attributes with mapping:", error);
72673
+ }
72674
+ }
72622
72675
  createPageState(page, pageSize) {
72623
72676
  if (!this.doc) {
72624
72677
  throw new Error("DomPainter.createPageState requires a document");
@@ -74996,8 +75049,6 @@ ${l}
74996
75049
  base2,
74997
75050
  fragment.fromLine,
74998
75051
  fragment.toLine,
74999
- fragment.pmStart ?? "",
75000
- fragment.pmEnd ?? "",
75001
75052
  fragment.continuesFromPrev ? 1 : 0,
75002
75053
  fragment.continuesOnNext ? 1 : 0,
75003
75054
  fragment.markerWidth ?? ""
@@ -75089,16 +75140,15 @@ ${l}
75089
75140
  imgRun.distTop ?? "",
75090
75141
  imgRun.distBottom ?? "",
75091
75142
  imgRun.distLeft ?? "",
75092
- imgRun.distRight ?? "",
75093
- imgRun.pmStart ?? "",
75094
- imgRun.pmEnd ?? ""
75143
+ imgRun.distRight ?? ""
75144
+ // Note: pmStart/pmEnd intentionally excluded to prevent O(n) change detection
75095
75145
  ].join(",");
75096
75146
  }
75097
75147
  if (run2.kind === "lineBreak") {
75098
- return ["linebreak", run2.pmStart ?? "", run2.pmEnd ?? ""].join(",");
75148
+ return "linebreak";
75099
75149
  }
75100
75150
  if (run2.kind === "tab") {
75101
- return [run2.text ?? "", "tab", run2.pmStart ?? "", run2.pmEnd ?? ""].join(",");
75151
+ return [run2.text ?? "", "tab"].join(",");
75102
75152
  }
75103
75153
  const textRun = run2;
75104
75154
  return [
@@ -75114,8 +75164,7 @@ ${l}
75114
75164
  textRun.strike ? 1 : 0,
75115
75165
  textRun.highlight ?? "",
75116
75166
  textRun.letterSpacing != null ? textRun.letterSpacing : "",
75117
- textRun.pmStart ?? "",
75118
- textRun.pmEnd ?? "",
75167
+ // Note: pmStart/pmEnd intentionally excluded to prevent O(n) change detection
75119
75168
  textRun.token ?? "",
75120
75169
  // Tracked changes - force re-render when added or removed tracked change
75121
75170
  textRun.trackedChange ? 1 : 0,
@@ -75571,8 +75620,8 @@ ${l}
75571
75620
  ruler: options.ruler
75572
75621
  });
75573
75622
  return {
75574
- paint(layout, mount2) {
75575
- painter.paint(layout, mount2);
75623
+ paint(layout, mount2, mapping) {
75624
+ painter.paint(layout, mount2, mapping);
75576
75625
  },
75577
75626
  setData(blocks2, measures, headerBlocks, headerMeasures, footerBlocks, footerMeasures) {
75578
75627
  painter.setData(blocks2, measures, headerBlocks, headerMeasures, footerBlocks, footerMeasures);
@@ -96981,6 +97030,7 @@ ${l}
96981
97030
  #telemetryEmitter = null;
96982
97031
  #renderScheduled = false;
96983
97032
  #pendingDocChange = false;
97033
+ #pendingMapping = null;
96984
97034
  #isRerendering = false;
96985
97035
  #selectionSync = new SelectionSyncCoordinator();
96986
97036
  #remoteCursorUpdateScheduled = false;
@@ -98585,6 +98635,15 @@ ${l}
98585
98635
  }
98586
98636
  if (trackedChangesChanged || transaction?.docChanged) {
98587
98637
  this.#pendingDocChange = true;
98638
+ if (transaction?.docChanged) {
98639
+ if (this.#pendingMapping !== null) {
98640
+ const combined = this.#pendingMapping.slice();
98641
+ combined.appendMapping(transaction.mapping);
98642
+ this.#pendingMapping = combined;
98643
+ } else {
98644
+ this.#pendingMapping = transaction.mapping;
98645
+ }
98646
+ }
98588
98647
  this.#selectionSync.onLayoutStart();
98589
98648
  this.#scheduleRerender();
98590
98649
  }
@@ -100151,7 +100210,9 @@ ${l}
100151
100210
  footerMeasures.length > 0 ? footerMeasures : void 0
100152
100211
  );
100153
100212
  this.#domIndexObserverManager?.pause();
100154
- painter.paint(layout, this.#painterHost);
100213
+ const mapping = this.#pendingMapping;
100214
+ this.#pendingMapping = null;
100215
+ painter.paint(layout, this.#painterHost, mapping ?? void 0);
100155
100216
  this.#applyVertAlignToLayout();
100156
100217
  this.#rebuildDomPositionIndex();
100157
100218
  this.#domIndexObserverManager?.resume();
@@ -144557,7 +144618,7 @@ ${reason}`);
144557
144618
  this.config.colors = shuffleArray(this.config.colors);
144558
144619
  this.userColorMap = /* @__PURE__ */ new Map();
144559
144620
  this.colorIndex = 0;
144560
- this.version = "1.3.1-next.1";
144621
+ this.version = "1.3.1-next.2";
144561
144622
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
144562
144623
  this.superdocId = config2.superdocId || v4();
144563
144624
  this.colors = this.config.colors;