@abraca/dabra 2.25.0 → 2.27.0

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.
@@ -15961,9 +15961,9 @@ function patchEntry(treeMap, id, patch, removeKeys = [], opts = {}) {
15961
15961
  /**
15962
15962
  * TreeTimestamps
15963
15963
  *
15964
- * Attaches an afterUpdate observer on a child Y.Doc so that whenever a
15965
- * non-offline update is applied, the `updatedAt` timestamp on the
15966
- * corresponding entry in the root doc's `doc-tree` map is written.
15964
+ * Attaches an afterTransaction observer on a child Y.Doc so that whenever a
15965
+ * LOCAL edit is made, the `updatedAt` timestamp on the corresponding entry
15966
+ * in the root doc's `doc-tree` map is written.
15967
15967
  *
15968
15968
  * This propagates "last edited" timestamps to all peers via the root CRDT,
15969
15969
  * without requiring any server-side changes.
@@ -15974,7 +15974,7 @@ function patchEntry(treeMap, id, patch, removeKeys = [], opts = {}) {
15974
15974
  */
15975
15975
  /**
15976
15976
  * Attach an observer that writes `updatedAt` to the root doc-tree entry for
15977
- * `childDocId` whenever the child doc receives a non-offline update.
15977
+ * `childDocId` whenever the child doc receives a local edit.
15978
15978
  *
15979
15979
  * @param treeMap The root doc's "doc-tree" Y.Map.
15980
15980
  * @param childDocId The child document's UUID (key in treeMap).
@@ -16004,8 +16004,10 @@ function attachUpdatedAtObserver(treeMap, childDocId, childDoc, offlineStore, op
16004
16004
  pendingTs = 0;
16005
16005
  writeTs(ts);
16006
16006
  }
16007
- function handler(_update, origin) {
16008
- if (offlineStore !== null && origin === offlineStore) return;
16007
+ function handler(tr) {
16008
+ if (!tr.local) return;
16009
+ if (offlineStore !== null && tr.origin === offlineStore) return;
16010
+ if (tr.changed.size === 0) return;
16009
16011
  const now = Date.now();
16010
16012
  if (now - lastFlushedAt >= throttleMs) {
16011
16013
  writeTs(now);
@@ -16014,9 +16016,9 @@ function attachUpdatedAtObserver(treeMap, childDocId, childDoc, offlineStore, op
16014
16016
  pendingTs = now;
16015
16017
  if (timer === null) timer = setTimeout(flushPending, throttleMs - (now - lastFlushedAt));
16016
16018
  }
16017
- childDoc.on("update", handler);
16019
+ childDoc.on("afterTransaction", handler);
16018
16020
  return () => {
16019
- childDoc.off("update", handler);
16021
+ childDoc.off("afterTransaction", handler);
16020
16022
  if (timer !== null) {
16021
16023
  clearTimeout(timer);
16022
16024
  flushPending();
@@ -19475,17 +19477,14 @@ function xmlTextToMarkdown(xmlText) {
19475
19477
  }
19476
19478
  function elementTextContent(el) {
19477
19479
  const parts = [];
19478
- for (let i = 0; i < el.length; i++) {
19479
- const child = el.get(i);
19480
- if (child instanceof yjs.XmlText) parts.push(xmlTextToMarkdown(child));
19481
- else if (child instanceof yjs.XmlElement) {
19482
- if (child.nodeName === "docLink") {
19483
- const docId = child.getAttribute("docId");
19484
- if (docId) parts.push(`[[${docId}]]`);
19485
- continue;
19486
- }
19487
- parts.push(elementTextContent(child));
19480
+ for (const child of el.toArray()) if (child instanceof yjs.XmlText) parts.push(xmlTextToMarkdown(child));
19481
+ else if (child instanceof yjs.XmlElement) {
19482
+ if (child.nodeName === "docLink") {
19483
+ const docId = child.getAttribute("docId");
19484
+ if (docId) parts.push(`[[${docId}]]`);
19485
+ continue;
19488
19486
  }
19487
+ parts.push(elementTextContent(child));
19489
19488
  }
19490
19489
  return parts.join("");
19491
19490
  }
@@ -19583,8 +19582,9 @@ function serializeElement(el, indent = "") {
19583
19582
  }
19584
19583
  function serializeList(el, type, indent) {
19585
19584
  const lines = [];
19586
- for (let i = 0; i < el.length; i++) {
19587
- const item = el.get(i);
19585
+ const items = el.toArray();
19586
+ for (let i = 0; i < items.length; i++) {
19587
+ const item = items[i];
19588
19588
  if (item instanceof yjs.XmlElement && item.nodeName === "listItem") {
19589
19589
  const prefix = type === "bullet" ? "- " : `${i + 1}. `;
19590
19590
  const content = elementTextContent(item);
@@ -19595,27 +19595,20 @@ function serializeList(el, type, indent) {
19595
19595
  }
19596
19596
  function serializeTaskList(el, indent) {
19597
19597
  const lines = [];
19598
- for (let i = 0; i < el.length; i++) {
19599
- const item = el.get(i);
19600
- if (item instanceof yjs.XmlElement && item.nodeName === "taskItem") {
19601
- const checked = item.getAttribute("checked");
19602
- const marker = checked === true || checked === "true" ? "[x]" : "[ ]";
19603
- const content = elementTextContent(item);
19604
- lines.push(`${indent}- ${marker} ${content}`);
19605
- }
19598
+ for (const item of el.toArray()) if (item instanceof yjs.XmlElement && item.nodeName === "taskItem") {
19599
+ const checked = item.getAttribute("checked");
19600
+ const marker = checked === true || checked === "true" ? "[x]" : "[ ]";
19601
+ const content = elementTextContent(item);
19602
+ lines.push(`${indent}- ${marker} ${content}`);
19606
19603
  }
19607
19604
  return lines.join("\n");
19608
19605
  }
19609
19606
  function serializeTable(el) {
19610
19607
  const rows = [];
19611
- for (let i = 0; i < el.length; i++) {
19612
- const row = el.get(i);
19608
+ for (const row of el.toArray()) {
19613
19609
  if (!(row instanceof yjs.XmlElement) || row.nodeName !== "tableRow") continue;
19614
19610
  const cells = [];
19615
- for (let j = 0; j < row.length; j++) {
19616
- const cell = row.get(j);
19617
- if (cell instanceof yjs.XmlElement) cells.push(elementTextContent(cell));
19618
- }
19611
+ for (const cell of row.toArray()) if (cell instanceof yjs.XmlElement) cells.push(elementTextContent(cell));
19619
19612
  rows.push(cells);
19620
19613
  }
19621
19614
  if (!rows.length) return "";
@@ -19643,15 +19636,12 @@ function serializeSlottedComponent(el, componentName, childNodeName, slotName) {
19643
19636
  }
19644
19637
  function serializeChildren(el, indent) {
19645
19638
  const parts = [];
19646
- for (let i = 0; i < el.length; i++) {
19647
- const child = el.get(i);
19648
- if (child instanceof yjs.XmlElement) {
19649
- const serialized = serializeElement(child, indent);
19650
- if (serialized) parts.push(serialized);
19651
- } else if (child instanceof yjs.XmlText) {
19652
- const text = xmlTextToMarkdown(child);
19653
- if (text) parts.push(text);
19654
- }
19639
+ for (const child of el.toArray()) if (child instanceof yjs.XmlElement) {
19640
+ const serialized = serializeElement(child, indent);
19641
+ if (serialized) parts.push(serialized);
19642
+ } else if (child instanceof yjs.XmlText) {
19643
+ const text = xmlTextToMarkdown(child);
19644
+ if (text) parts.push(text);
19655
19645
  }
19656
19646
  return parts.join("\n\n");
19657
19647
  }
@@ -19664,8 +19654,7 @@ function serializeChildren(el, indent) {
19664
19654
  function yjsToMarkdown(fragment) {
19665
19655
  let title = "Untitled";
19666
19656
  const bodyParts = [];
19667
- for (let i = 0; i < fragment.length; i++) {
19668
- const child = fragment.get(i);
19657
+ for (const child of fragment.toArray()) {
19669
19658
  if (!(child instanceof yjs.XmlElement)) continue;
19670
19659
  if (child.nodeName === "documentHeader") {
19671
19660
  title = elementTextContent(child) || "Untitled";
@@ -20676,8 +20665,7 @@ function buildBlocksFromMarkdown(markdown) {
20676
20665
  }
20677
20666
  function readBlocksFromFragment(fragment) {
20678
20667
  const result = [];
20679
- for (let i = 0; i < fragment.length; i++) {
20680
- const child = fragment.get(i);
20668
+ for (const child of fragment.toArray()) {
20681
20669
  if (!(child instanceof yjs.XmlElement)) continue;
20682
20670
  const name = child.nodeName;
20683
20671
  if (name === "documentHeader" || name === "documentMeta") continue;
@@ -21107,11 +21095,11 @@ var DocumentManager = class {
21107
21095
  return this._rootDocId;
21108
21096
  }
21109
21097
  /**
21110
- * Whether the TreeManager in-memory index is enabled (Path-1 prototype).
21111
- * Off by default — see {@link DocumentManagerConfig.treeIndex}.
21098
+ * Whether the TreeManager in-memory index is enabled.
21099
+ * On by default — see {@link DocumentManagerConfig.treeIndex}.
21112
21100
  */
21113
21101
  get treeIndexEnabled() {
21114
- return this._config.treeIndex ?? false;
21102
+ return this._config.treeIndex ?? true;
21115
21103
  }
21116
21104
  get rootDocument() {
21117
21105
  return this._rootDoc;