@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.
- package/dist/abracadabra-provider.cjs +38 -50
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +35 -47
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +13 -10
- package/package.json +2 -2
- package/src/DocConverters.ts +13 -16
- package/src/DocumentManager.ts +13 -10
- package/src/TreeTimestamps.ts +17 -8
|
@@ -15921,7 +15921,7 @@ function patchEntry(treeMap, id, patch, removeKeys = [], opts = {}) {
|
|
|
15921
15921
|
//#region packages/provider/src/TreeTimestamps.ts
|
|
15922
15922
|
/**
|
|
15923
15923
|
* Attach an observer that writes `updatedAt` to the root doc-tree entry for
|
|
15924
|
-
* `childDocId` whenever the child doc receives a
|
|
15924
|
+
* `childDocId` whenever the child doc receives a local edit.
|
|
15925
15925
|
*
|
|
15926
15926
|
* @param treeMap The root doc's "doc-tree" Y.Map.
|
|
15927
15927
|
* @param childDocId The child document's UUID (key in treeMap).
|
|
@@ -15951,8 +15951,10 @@ function attachUpdatedAtObserver(treeMap, childDocId, childDoc, offlineStore, op
|
|
|
15951
15951
|
pendingTs = 0;
|
|
15952
15952
|
writeTs(ts);
|
|
15953
15953
|
}
|
|
15954
|
-
function handler(
|
|
15955
|
-
if (
|
|
15954
|
+
function handler(tr) {
|
|
15955
|
+
if (!tr.local) return;
|
|
15956
|
+
if (offlineStore !== null && tr.origin === offlineStore) return;
|
|
15957
|
+
if (tr.changed.size === 0) return;
|
|
15956
15958
|
const now = Date.now();
|
|
15957
15959
|
if (now - lastFlushedAt >= throttleMs) {
|
|
15958
15960
|
writeTs(now);
|
|
@@ -15961,9 +15963,9 @@ function attachUpdatedAtObserver(treeMap, childDocId, childDoc, offlineStore, op
|
|
|
15961
15963
|
pendingTs = now;
|
|
15962
15964
|
if (timer === null) timer = setTimeout(flushPending, throttleMs - (now - lastFlushedAt));
|
|
15963
15965
|
}
|
|
15964
|
-
childDoc.on("
|
|
15966
|
+
childDoc.on("afterTransaction", handler);
|
|
15965
15967
|
return () => {
|
|
15966
|
-
childDoc.off("
|
|
15968
|
+
childDoc.off("afterTransaction", handler);
|
|
15967
15969
|
if (timer !== null) {
|
|
15968
15970
|
clearTimeout(timer);
|
|
15969
15971
|
flushPending();
|
|
@@ -19415,17 +19417,14 @@ function xmlTextToMarkdown(xmlText) {
|
|
|
19415
19417
|
}
|
|
19416
19418
|
function elementTextContent(el) {
|
|
19417
19419
|
const parts = [];
|
|
19418
|
-
for (
|
|
19419
|
-
|
|
19420
|
-
if (child
|
|
19421
|
-
|
|
19422
|
-
if (
|
|
19423
|
-
|
|
19424
|
-
if (docId) parts.push(`[[${docId}]]`);
|
|
19425
|
-
continue;
|
|
19426
|
-
}
|
|
19427
|
-
parts.push(elementTextContent(child));
|
|
19420
|
+
for (const child of el.toArray()) if (child instanceof Y.XmlText) parts.push(xmlTextToMarkdown(child));
|
|
19421
|
+
else if (child instanceof Y.XmlElement) {
|
|
19422
|
+
if (child.nodeName === "docLink") {
|
|
19423
|
+
const docId = child.getAttribute("docId");
|
|
19424
|
+
if (docId) parts.push(`[[${docId}]]`);
|
|
19425
|
+
continue;
|
|
19428
19426
|
}
|
|
19427
|
+
parts.push(elementTextContent(child));
|
|
19429
19428
|
}
|
|
19430
19429
|
return parts.join("");
|
|
19431
19430
|
}
|
|
@@ -19523,8 +19522,9 @@ function serializeElement(el, indent = "") {
|
|
|
19523
19522
|
}
|
|
19524
19523
|
function serializeList(el, type, indent) {
|
|
19525
19524
|
const lines = [];
|
|
19526
|
-
|
|
19527
|
-
|
|
19525
|
+
const items = el.toArray();
|
|
19526
|
+
for (let i = 0; i < items.length; i++) {
|
|
19527
|
+
const item = items[i];
|
|
19528
19528
|
if (item instanceof Y.XmlElement && item.nodeName === "listItem") {
|
|
19529
19529
|
const prefix = type === "bullet" ? "- " : `${i + 1}. `;
|
|
19530
19530
|
const content = elementTextContent(item);
|
|
@@ -19535,27 +19535,20 @@ function serializeList(el, type, indent) {
|
|
|
19535
19535
|
}
|
|
19536
19536
|
function serializeTaskList(el, indent) {
|
|
19537
19537
|
const lines = [];
|
|
19538
|
-
for (
|
|
19539
|
-
const
|
|
19540
|
-
|
|
19541
|
-
|
|
19542
|
-
|
|
19543
|
-
const content = elementTextContent(item);
|
|
19544
|
-
lines.push(`${indent}- ${marker} ${content}`);
|
|
19545
|
-
}
|
|
19538
|
+
for (const item of el.toArray()) if (item instanceof Y.XmlElement && item.nodeName === "taskItem") {
|
|
19539
|
+
const checked = item.getAttribute("checked");
|
|
19540
|
+
const marker = checked === true || checked === "true" ? "[x]" : "[ ]";
|
|
19541
|
+
const content = elementTextContent(item);
|
|
19542
|
+
lines.push(`${indent}- ${marker} ${content}`);
|
|
19546
19543
|
}
|
|
19547
19544
|
return lines.join("\n");
|
|
19548
19545
|
}
|
|
19549
19546
|
function serializeTable(el) {
|
|
19550
19547
|
const rows = [];
|
|
19551
|
-
for (
|
|
19552
|
-
const row = el.get(i);
|
|
19548
|
+
for (const row of el.toArray()) {
|
|
19553
19549
|
if (!(row instanceof Y.XmlElement) || row.nodeName !== "tableRow") continue;
|
|
19554
19550
|
const cells = [];
|
|
19555
|
-
for (
|
|
19556
|
-
const cell = row.get(j);
|
|
19557
|
-
if (cell instanceof Y.XmlElement) cells.push(elementTextContent(cell));
|
|
19558
|
-
}
|
|
19551
|
+
for (const cell of row.toArray()) if (cell instanceof Y.XmlElement) cells.push(elementTextContent(cell));
|
|
19559
19552
|
rows.push(cells);
|
|
19560
19553
|
}
|
|
19561
19554
|
if (!rows.length) return "";
|
|
@@ -19583,15 +19576,12 @@ function serializeSlottedComponent(el, componentName, childNodeName, slotName) {
|
|
|
19583
19576
|
}
|
|
19584
19577
|
function serializeChildren(el, indent) {
|
|
19585
19578
|
const parts = [];
|
|
19586
|
-
for (
|
|
19587
|
-
const
|
|
19588
|
-
if (
|
|
19589
|
-
|
|
19590
|
-
|
|
19591
|
-
|
|
19592
|
-
const text = xmlTextToMarkdown(child);
|
|
19593
|
-
if (text) parts.push(text);
|
|
19594
|
-
}
|
|
19579
|
+
for (const child of el.toArray()) if (child instanceof Y.XmlElement) {
|
|
19580
|
+
const serialized = serializeElement(child, indent);
|
|
19581
|
+
if (serialized) parts.push(serialized);
|
|
19582
|
+
} else if (child instanceof Y.XmlText) {
|
|
19583
|
+
const text = xmlTextToMarkdown(child);
|
|
19584
|
+
if (text) parts.push(text);
|
|
19595
19585
|
}
|
|
19596
19586
|
return parts.join("\n\n");
|
|
19597
19587
|
}
|
|
@@ -19604,8 +19594,7 @@ function serializeChildren(el, indent) {
|
|
|
19604
19594
|
function yjsToMarkdown(fragment) {
|
|
19605
19595
|
let title = "Untitled";
|
|
19606
19596
|
const bodyParts = [];
|
|
19607
|
-
for (
|
|
19608
|
-
const child = fragment.get(i);
|
|
19597
|
+
for (const child of fragment.toArray()) {
|
|
19609
19598
|
if (!(child instanceof Y.XmlElement)) continue;
|
|
19610
19599
|
if (child.nodeName === "documentHeader") {
|
|
19611
19600
|
title = elementTextContent(child) || "Untitled";
|
|
@@ -20616,8 +20605,7 @@ function buildBlocksFromMarkdown(markdown) {
|
|
|
20616
20605
|
}
|
|
20617
20606
|
function readBlocksFromFragment(fragment) {
|
|
20618
20607
|
const result = [];
|
|
20619
|
-
for (
|
|
20620
|
-
const child = fragment.get(i);
|
|
20608
|
+
for (const child of fragment.toArray()) {
|
|
20621
20609
|
if (!(child instanceof Y.XmlElement)) continue;
|
|
20622
20610
|
const name = child.nodeName;
|
|
20623
20611
|
if (name === "documentHeader" || name === "documentMeta") continue;
|
|
@@ -21042,11 +21030,11 @@ var DocumentManager = class {
|
|
|
21042
21030
|
return this._rootDocId;
|
|
21043
21031
|
}
|
|
21044
21032
|
/**
|
|
21045
|
-
* Whether the TreeManager in-memory index is enabled
|
|
21046
|
-
*
|
|
21033
|
+
* Whether the TreeManager in-memory index is enabled.
|
|
21034
|
+
* On by default — see {@link DocumentManagerConfig.treeIndex}.
|
|
21047
21035
|
*/
|
|
21048
21036
|
get treeIndexEnabled() {
|
|
21049
|
-
return this._config.treeIndex ??
|
|
21037
|
+
return this._config.treeIndex ?? true;
|
|
21050
21038
|
}
|
|
21051
21039
|
get rootDocument() {
|
|
21052
21040
|
return this._rootDoc;
|