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.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MindCache, a as MindCacheOptions } from './CloudAdapter-CeGQhFk9.mjs';
2
- export { A as AccessLevel, C as CloudAdapter, j as CloudAdapterEvents, h as CloudConfig, i as ConnectionState, D as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, e as HistoryOptions, K as KeyAttributes, b as KeyType, L as Listener, f as MindCacheCloudOptions, g as MindCacheIndexedDBOptions, c as STM, d as STMEntry, S as SystemTag } from './CloudAdapter-CeGQhFk9.mjs';
1
+ import { M as MindCache, a as MindCacheOptions } from './CloudAdapter-WvuWM4fD.mjs';
2
+ export { A as AccessLevel, C as CloudAdapter, j as CloudAdapterEvents, h as CloudConfig, i as ConnectionState, D as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, e as HistoryOptions, K as KeyAttributes, b as KeyType, L as Listener, f as MindCacheCloudOptions, g as MindCacheIndexedDBOptions, c as STM, d as STMEntry, S as SystemTag } from './CloudAdapter-WvuWM4fD.mjs';
3
3
  import 'yjs';
4
4
 
5
5
  interface IndexedDBConfig {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MindCache, a as MindCacheOptions } from './CloudAdapter-CeGQhFk9.js';
2
- export { A as AccessLevel, C as CloudAdapter, j as CloudAdapterEvents, h as CloudConfig, i as ConnectionState, D as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, e as HistoryOptions, K as KeyAttributes, b as KeyType, L as Listener, f as MindCacheCloudOptions, g as MindCacheIndexedDBOptions, c as STM, d as STMEntry, S as SystemTag } from './CloudAdapter-CeGQhFk9.js';
1
+ import { M as MindCache, a as MindCacheOptions } from './CloudAdapter-WvuWM4fD.js';
2
+ export { A as AccessLevel, C as CloudAdapter, j as CloudAdapterEvents, h as CloudConfig, i as ConnectionState, D as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, e as HistoryOptions, K as KeyAttributes, b as KeyType, L as Listener, f as MindCacheCloudOptions, g as MindCacheIndexedDBOptions, c as STM, d as STMEntry, S as SystemTag } from './CloudAdapter-WvuWM4fD.js';
3
3
  import 'yjs';
4
4
 
5
5
  interface IndexedDBConfig {
package/dist/index.js CHANGED
@@ -548,14 +548,30 @@ var MindCache = class {
548
548
  break;
549
549
  }
550
550
  }
551
+ } else {
552
+ let current = event.target;
553
+ while (current && current.parent) {
554
+ if (current.parent.parent === this.rootMap) {
555
+ for (const [key, val] of this.rootMap) {
556
+ if (val === current.parent) {
557
+ keysAffected.add(key);
558
+ break;
559
+ }
560
+ }
561
+ break;
562
+ }
563
+ current = current.parent;
564
+ }
551
565
  }
552
566
  });
553
567
  keysAffected.forEach((key) => {
554
568
  const entryMap = this.rootMap.get(key);
555
569
  if (entryMap) {
556
570
  const value = entryMap.get("value");
571
+ const attrs = entryMap.get("attributes");
572
+ const resolvedValue = attrs?.type === "document" && value instanceof Y__namespace.Text ? value.toString() : value;
557
573
  if (this.listeners[key]) {
558
- this.listeners[key].forEach((l) => l(value));
574
+ this.listeners[key].forEach((l) => l(resolvedValue));
559
575
  }
560
576
  } else {
561
577
  if (this.listeners[key]) {
@@ -685,12 +701,19 @@ var MindCache = class {
685
701
  if (event.target === this.rootMap) {
686
702
  const mapEvent = event;
687
703
  mapEvent.keysChanged.forEach((key) => keysAffected.add(key));
688
- } else if (event.target.parent === this.rootMap) {
689
- for (const [key, val] of this.rootMap) {
690
- if (val === event.target) {
691
- keysAffected.add(key);
704
+ } else {
705
+ let current = event.target;
706
+ while (current && current.parent) {
707
+ if (current.parent === this.rootMap) {
708
+ for (const [key, val] of this.rootMap) {
709
+ if (val === current) {
710
+ keysAffected.add(key);
711
+ break;
712
+ }
713
+ }
692
714
  break;
693
715
  }
716
+ current = current.parent;
694
717
  }
695
718
  }
696
719
  });
@@ -1087,11 +1110,15 @@ var MindCache = class {
1087
1110
  const existingAttrs = existingEntry.get("attributes");
1088
1111
  if (existingAttrs?.type === "document") {
1089
1112
  if (typeof value === "string") {
1090
- this.replace_document_text(key, value);
1113
+ this._replaceDocumentText(key, value);
1091
1114
  }
1092
1115
  return;
1093
1116
  }
1094
1117
  }
1118
+ if (!existingEntry && attributes?.type === "document") {
1119
+ this.set_document(key, typeof value === "string" ? value : "", attributes);
1120
+ return;
1121
+ }
1095
1122
  let entryMap = this.rootMap.get(key);
1096
1123
  const isNewEntry = !entryMap;
1097
1124
  if (isNewEntry) {
@@ -1832,14 +1859,6 @@ var MindCache = class {
1832
1859
  }
1833
1860
  return void 0;
1834
1861
  }
1835
- /**
1836
- * Get plain text content of a document key.
1837
- * For collaborative editing, use get_document() and bind to an editor.
1838
- */
1839
- get_document_text(key) {
1840
- const yText = this.get_document(key);
1841
- return yText?.toString();
1842
- }
1843
1862
  /**
1844
1863
  * Insert text at a position in a document key.
1845
1864
  */
@@ -1859,15 +1878,11 @@ var MindCache = class {
1859
1878
  }
1860
1879
  }
1861
1880
  /**
1862
- * Replace all text in a document key.
1881
+ * Replace all text in a document key (private - use set_value for public API).
1863
1882
  * Uses diff-based updates when changes are < diffThreshold (default 80%).
1864
1883
  * This preserves concurrent edits and provides better undo granularity.
1865
- *
1866
- * @param key - The document key
1867
- * @param newText - The new text content
1868
- * @param diffThreshold - Percentage (0-1) of change above which full replace is used (default: 0.8)
1869
1884
  */
1870
- replace_document_text(key, newText, diffThreshold = 0.8) {
1885
+ _replaceDocumentText(key, newText, diffThreshold = 0.8) {
1871
1886
  const yText = this.get_document(key);
1872
1887
  if (!yText) {
1873
1888
  return;
@@ -1973,7 +1988,7 @@ var MindCache = class {
1973
1988
  },
1974
1989
  execute: async ({ value }) => {
1975
1990
  if (isDocument) {
1976
- this.replace_document_text(key, value);
1991
+ this._replaceDocumentText(key, value);
1977
1992
  } else {
1978
1993
  this.set_value(key, value);
1979
1994
  }
@@ -2129,7 +2144,7 @@ var MindCache = class {
2129
2144
  switch (action) {
2130
2145
  case "write":
2131
2146
  if (isDocument) {
2132
- this.replace_document_text(key, value);
2147
+ this._replaceDocumentText(key, value);
2133
2148
  } else {
2134
2149
  this.set_value(key, value);
2135
2150
  }