mindcache 3.3.2 → 3.4.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.
@@ -406,11 +406,6 @@ declare class MindCache {
406
406
  * @returns Y.Text or undefined if key doesn't exist or isn't a document
407
407
  */
408
408
  get_document(key: string): Y.Text | undefined;
409
- /**
410
- * Get plain text content of a document key.
411
- * For collaborative editing, use get_document() and bind to an editor.
412
- */
413
- get_document_text(key: string): string | undefined;
414
409
  /**
415
410
  * Insert text at a position in a document key.
416
411
  */
@@ -420,15 +415,11 @@ declare class MindCache {
420
415
  */
421
416
  delete_text(key: string, index: number, length: number): void;
422
417
  /**
423
- * Replace all text in a document key.
418
+ * Replace all text in a document key (private - use set_value for public API).
424
419
  * Uses diff-based updates when changes are < diffThreshold (default 80%).
425
420
  * This preserves concurrent edits and provides better undo granularity.
426
- *
427
- * @param key - The document key
428
- * @param newText - The new text content
429
- * @param diffThreshold - Percentage (0-1) of change above which full replace is used (default: 0.8)
430
421
  */
431
- replace_document_text(key: string, newText: string, diffThreshold?: number): void;
422
+ private _replaceDocumentText;
432
423
  subscribe(key: string, listener: Listener): () => void;
433
424
  subscribeToAll(listener: GlobalListener): () => void;
434
425
  unsubscribeFromAll(listener: GlobalListener): void;
@@ -406,11 +406,6 @@ declare class MindCache {
406
406
  * @returns Y.Text or undefined if key doesn't exist or isn't a document
407
407
  */
408
408
  get_document(key: string): Y.Text | undefined;
409
- /**
410
- * Get plain text content of a document key.
411
- * For collaborative editing, use get_document() and bind to an editor.
412
- */
413
- get_document_text(key: string): string | undefined;
414
409
  /**
415
410
  * Insert text at a position in a document key.
416
411
  */
@@ -420,15 +415,11 @@ declare class MindCache {
420
415
  */
421
416
  delete_text(key: string, index: number, length: number): void;
422
417
  /**
423
- * Replace all text in a document key.
418
+ * Replace all text in a document key (private - use set_value for public API).
424
419
  * Uses diff-based updates when changes are < diffThreshold (default 80%).
425
420
  * This preserves concurrent edits and provides better undo granularity.
426
- *
427
- * @param key - The document key
428
- * @param newText - The new text content
429
- * @param diffThreshold - Percentage (0-1) of change above which full replace is used (default: 0.8)
430
421
  */
431
- replace_document_text(key: string, newText: string, diffThreshold?: number): void;
422
+ private _replaceDocumentText;
432
423
  subscribe(key: string, listener: Listener): () => void;
433
424
  subscribeToAll(listener: GlobalListener): () => void;
434
425
  unsubscribeFromAll(listener: GlobalListener): void;
@@ -1,5 +1,5 @@
1
- import { M as MindCache, h as CloudConfig, C as CloudAdapter } from '../CloudAdapter-CeGQhFk9.mjs';
2
- export { m as ClearOperation, j as CloudAdapterEvents, i as ConnectionState, l as DeleteOperation, O as Operation, k as SetOperation } from '../CloudAdapter-CeGQhFk9.mjs';
1
+ import { M as MindCache, h as CloudConfig, C as CloudAdapter } from '../CloudAdapter-WvuWM4fD.mjs';
2
+ export { m as ClearOperation, j as CloudAdapterEvents, i as ConnectionState, l as DeleteOperation, O as Operation, k as SetOperation } from '../CloudAdapter-WvuWM4fD.mjs';
3
3
  import 'yjs';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { M as MindCache, h as CloudConfig, C as CloudAdapter } from '../CloudAdapter-CeGQhFk9.js';
2
- export { m as ClearOperation, j as CloudAdapterEvents, i as ConnectionState, l as DeleteOperation, O as Operation, k as SetOperation } from '../CloudAdapter-CeGQhFk9.js';
1
+ import { M as MindCache, h as CloudConfig, C as CloudAdapter } from '../CloudAdapter-WvuWM4fD.js';
2
+ export { m as ClearOperation, j as CloudAdapterEvents, i as ConnectionState, l as DeleteOperation, O as Operation, k as SetOperation } from '../CloudAdapter-WvuWM4fD.js';
3
3
  import 'yjs';
4
4
 
5
5
  /**
@@ -547,14 +547,30 @@ var MindCache = class {
547
547
  break;
548
548
  }
549
549
  }
550
+ } else {
551
+ let current = event.target;
552
+ while (current && current.parent) {
553
+ if (current.parent.parent === this.rootMap) {
554
+ for (const [key, val] of this.rootMap) {
555
+ if (val === current.parent) {
556
+ keysAffected.add(key);
557
+ break;
558
+ }
559
+ }
560
+ break;
561
+ }
562
+ current = current.parent;
563
+ }
550
564
  }
551
565
  });
552
566
  keysAffected.forEach((key) => {
553
567
  const entryMap = this.rootMap.get(key);
554
568
  if (entryMap) {
555
569
  const value = entryMap.get("value");
570
+ const attrs = entryMap.get("attributes");
571
+ const resolvedValue = attrs?.type === "document" && value instanceof Y__namespace.Text ? value.toString() : value;
556
572
  if (this.listeners[key]) {
557
- this.listeners[key].forEach((l) => l(value));
573
+ this.listeners[key].forEach((l) => l(resolvedValue));
558
574
  }
559
575
  } else {
560
576
  if (this.listeners[key]) {
@@ -684,12 +700,19 @@ var MindCache = class {
684
700
  if (event.target === this.rootMap) {
685
701
  const mapEvent = event;
686
702
  mapEvent.keysChanged.forEach((key) => keysAffected.add(key));
687
- } else if (event.target.parent === this.rootMap) {
688
- for (const [key, val] of this.rootMap) {
689
- if (val === event.target) {
690
- keysAffected.add(key);
703
+ } else {
704
+ let current = event.target;
705
+ while (current && current.parent) {
706
+ if (current.parent === this.rootMap) {
707
+ for (const [key, val] of this.rootMap) {
708
+ if (val === current) {
709
+ keysAffected.add(key);
710
+ break;
711
+ }
712
+ }
691
713
  break;
692
714
  }
715
+ current = current.parent;
693
716
  }
694
717
  }
695
718
  });
@@ -1086,11 +1109,15 @@ var MindCache = class {
1086
1109
  const existingAttrs = existingEntry.get("attributes");
1087
1110
  if (existingAttrs?.type === "document") {
1088
1111
  if (typeof value === "string") {
1089
- this.replace_document_text(key, value);
1112
+ this._replaceDocumentText(key, value);
1090
1113
  }
1091
1114
  return;
1092
1115
  }
1093
1116
  }
1117
+ if (!existingEntry && attributes?.type === "document") {
1118
+ this.set_document(key, typeof value === "string" ? value : "", attributes);
1119
+ return;
1120
+ }
1094
1121
  let entryMap = this.rootMap.get(key);
1095
1122
  const isNewEntry = !entryMap;
1096
1123
  if (isNewEntry) {
@@ -1831,14 +1858,6 @@ var MindCache = class {
1831
1858
  }
1832
1859
  return void 0;
1833
1860
  }
1834
- /**
1835
- * Get plain text content of a document key.
1836
- * For collaborative editing, use get_document() and bind to an editor.
1837
- */
1838
- get_document_text(key) {
1839
- const yText = this.get_document(key);
1840
- return yText?.toString();
1841
- }
1842
1861
  /**
1843
1862
  * Insert text at a position in a document key.
1844
1863
  */
@@ -1858,15 +1877,11 @@ var MindCache = class {
1858
1877
  }
1859
1878
  }
1860
1879
  /**
1861
- * Replace all text in a document key.
1880
+ * Replace all text in a document key (private - use set_value for public API).
1862
1881
  * Uses diff-based updates when changes are < diffThreshold (default 80%).
1863
1882
  * This preserves concurrent edits and provides better undo granularity.
1864
- *
1865
- * @param key - The document key
1866
- * @param newText - The new text content
1867
- * @param diffThreshold - Percentage (0-1) of change above which full replace is used (default: 0.8)
1868
1883
  */
1869
- replace_document_text(key, newText, diffThreshold = 0.8) {
1884
+ _replaceDocumentText(key, newText, diffThreshold = 0.8) {
1870
1885
  const yText = this.get_document(key);
1871
1886
  if (!yText) {
1872
1887
  return;
@@ -1972,7 +1987,7 @@ var MindCache = class {
1972
1987
  },
1973
1988
  execute: async ({ value }) => {
1974
1989
  if (isDocument) {
1975
- this.replace_document_text(key, value);
1990
+ this._replaceDocumentText(key, value);
1976
1991
  } else {
1977
1992
  this.set_value(key, value);
1978
1993
  }
@@ -2128,7 +2143,7 @@ var MindCache = class {
2128
2143
  switch (action) {
2129
2144
  case "write":
2130
2145
  if (isDocument) {
2131
- this.replace_document_text(key, value);
2146
+ this._replaceDocumentText(key, value);
2132
2147
  } else {
2133
2148
  this.set_value(key, value);
2134
2149
  }