mindcache 3.3.2 → 3.4.1
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/{CloudAdapter-CeGQhFk9.d.mts → CloudAdapter-C0UyG6OY.d.mts} +2 -13
- package/dist/{CloudAdapter-CeGQhFk9.d.ts → CloudAdapter-C0UyG6OY.d.ts} +2 -13
- package/dist/cloud/index.d.mts +2 -2
- package/dist/cloud/index.d.ts +2 -2
- package/dist/cloud/index.js +60 -31
- package/dist/cloud/index.js.map +1 -1
- package/dist/cloud/index.mjs +60 -31
- package/dist/cloud/index.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +60 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as MindCache, a as MindCacheOptions } from './CloudAdapter-
|
|
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-
|
|
1
|
+
import { M as MindCache, a as MindCacheOptions } from './CloudAdapter-C0UyG6OY.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-C0UyG6OY.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-
|
|
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-
|
|
1
|
+
import { M as MindCache, a as MindCacheOptions } from './CloudAdapter-C0UyG6OY.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-C0UyG6OY.js';
|
|
3
3
|
import 'yjs';
|
|
4
4
|
|
|
5
5
|
interface IndexedDBConfig {
|
package/dist/index.js
CHANGED
|
@@ -74,7 +74,7 @@ var init_IndexedDBAdapter = __esm({
|
|
|
74
74
|
await this.initDB();
|
|
75
75
|
await this.load();
|
|
76
76
|
const listener = () => {
|
|
77
|
-
if (this.mindcache
|
|
77
|
+
if (this.mindcache) {
|
|
78
78
|
this.scheduleSave();
|
|
79
79
|
}
|
|
80
80
|
};
|
|
@@ -478,7 +478,6 @@ var MindCache = class {
|
|
|
478
478
|
version = "3.3.2";
|
|
479
479
|
// Internal flag to prevent sync loops when receiving remote updates
|
|
480
480
|
// (Less critical with Yjs but kept for API compat)
|
|
481
|
-
_isRemoteUpdate = false;
|
|
482
481
|
normalizeSystemTags(tags) {
|
|
483
482
|
const normalized = [];
|
|
484
483
|
let hasSystemPrompt = false;
|
|
@@ -548,14 +547,30 @@ var MindCache = class {
|
|
|
548
547
|
break;
|
|
549
548
|
}
|
|
550
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
|
+
}
|
|
551
564
|
}
|
|
552
565
|
});
|
|
553
566
|
keysAffected.forEach((key) => {
|
|
554
567
|
const entryMap = this.rootMap.get(key);
|
|
555
568
|
if (entryMap) {
|
|
556
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;
|
|
557
572
|
if (this.listeners[key]) {
|
|
558
|
-
this.listeners[key].forEach((l) => l(
|
|
573
|
+
this.listeners[key].forEach((l) => l(resolvedValue));
|
|
559
574
|
}
|
|
560
575
|
} else {
|
|
561
576
|
if (this.listeners[key]) {
|
|
@@ -685,12 +700,19 @@ var MindCache = class {
|
|
|
685
700
|
if (event.target === this.rootMap) {
|
|
686
701
|
const mapEvent = event;
|
|
687
702
|
mapEvent.keysChanged.forEach((key) => keysAffected.add(key));
|
|
688
|
-
} else
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
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
|
+
}
|
|
692
713
|
break;
|
|
693
714
|
}
|
|
715
|
+
current = current.parent;
|
|
694
716
|
}
|
|
695
717
|
}
|
|
696
718
|
});
|
|
@@ -877,10 +899,6 @@ var MindCache = class {
|
|
|
877
899
|
this._idbProvider = null;
|
|
878
900
|
}
|
|
879
901
|
}
|
|
880
|
-
// Legacy bridge
|
|
881
|
-
isRemoteUpdate() {
|
|
882
|
-
return false;
|
|
883
|
-
}
|
|
884
902
|
// Serialize state
|
|
885
903
|
serialize() {
|
|
886
904
|
const json = {};
|
|
@@ -1076,6 +1094,14 @@ var MindCache = class {
|
|
|
1076
1094
|
mergedAttrs.systemTags = this.normalizeSystemTags(mergedAttrs.systemTags);
|
|
1077
1095
|
}
|
|
1078
1096
|
entryMap.set("attributes", mergedAttrs);
|
|
1097
|
+
const currentValue = entryMap.get("value");
|
|
1098
|
+
if (mergedAttrs.type === "document" && !(currentValue instanceof Y__namespace.Text)) {
|
|
1099
|
+
const strValue = typeof currentValue === "string" ? currentValue : String(currentValue ?? "");
|
|
1100
|
+
entryMap.set("value", new Y__namespace.Text(strValue));
|
|
1101
|
+
this.getUndoManager(key);
|
|
1102
|
+
} else if (mergedAttrs.type !== "document" && currentValue instanceof Y__namespace.Text) {
|
|
1103
|
+
entryMap.set("value", currentValue.toString());
|
|
1104
|
+
}
|
|
1079
1105
|
});
|
|
1080
1106
|
}
|
|
1081
1107
|
set_value(key, value, attributes) {
|
|
@@ -1086,12 +1112,21 @@ var MindCache = class {
|
|
|
1086
1112
|
if (existingEntry) {
|
|
1087
1113
|
const existingAttrs = existingEntry.get("attributes");
|
|
1088
1114
|
if (existingAttrs?.type === "document") {
|
|
1089
|
-
if (
|
|
1090
|
-
|
|
1115
|
+
if (!attributes?.type || attributes.type === "document") {
|
|
1116
|
+
if (typeof value === "string") {
|
|
1117
|
+
this._replaceDocumentText(key, value);
|
|
1118
|
+
}
|
|
1119
|
+
if (attributes) {
|
|
1120
|
+
this.set_attributes(key, attributes);
|
|
1121
|
+
}
|
|
1122
|
+
return;
|
|
1091
1123
|
}
|
|
1092
|
-
return;
|
|
1093
1124
|
}
|
|
1094
1125
|
}
|
|
1126
|
+
if (!existingEntry && attributes?.type === "document") {
|
|
1127
|
+
this.set_document(key, typeof value === "string" ? value : "", attributes);
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1095
1130
|
let entryMap = this.rootMap.get(key);
|
|
1096
1131
|
const isNewEntry = !entryMap;
|
|
1097
1132
|
if (isNewEntry) {
|
|
@@ -1117,7 +1152,13 @@ var MindCache = class {
|
|
|
1117
1152
|
normalizedAttributes.systemTags.push("template");
|
|
1118
1153
|
}
|
|
1119
1154
|
}
|
|
1120
|
-
|
|
1155
|
+
let valueToSet = value;
|
|
1156
|
+
if (normalizedAttributes.type === "document" && !(valueToSet instanceof Y__namespace.Text)) {
|
|
1157
|
+
valueToSet = new Y__namespace.Text(typeof value === "string" ? value : String(value ?? ""));
|
|
1158
|
+
} else if (normalizedAttributes.type !== "document" && valueToSet instanceof Y__namespace.Text) {
|
|
1159
|
+
valueToSet = valueToSet.toString();
|
|
1160
|
+
}
|
|
1161
|
+
entryMap.set("value", valueToSet);
|
|
1121
1162
|
entryMap.set("attributes", normalizedAttributes);
|
|
1122
1163
|
});
|
|
1123
1164
|
}
|
|
@@ -1832,14 +1873,6 @@ var MindCache = class {
|
|
|
1832
1873
|
}
|
|
1833
1874
|
return void 0;
|
|
1834
1875
|
}
|
|
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
1876
|
/**
|
|
1844
1877
|
* Insert text at a position in a document key.
|
|
1845
1878
|
*/
|
|
@@ -1859,15 +1892,11 @@ var MindCache = class {
|
|
|
1859
1892
|
}
|
|
1860
1893
|
}
|
|
1861
1894
|
/**
|
|
1862
|
-
* Replace all text in a document key.
|
|
1895
|
+
* Replace all text in a document key (private - use set_value for public API).
|
|
1863
1896
|
* Uses diff-based updates when changes are < diffThreshold (default 80%).
|
|
1864
1897
|
* 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
1898
|
*/
|
|
1870
|
-
|
|
1899
|
+
_replaceDocumentText(key, newText, diffThreshold = 0.8) {
|
|
1871
1900
|
const yText = this.get_document(key);
|
|
1872
1901
|
if (!yText) {
|
|
1873
1902
|
return;
|
|
@@ -1973,7 +2002,7 @@ var MindCache = class {
|
|
|
1973
2002
|
},
|
|
1974
2003
|
execute: async ({ value }) => {
|
|
1975
2004
|
if (isDocument) {
|
|
1976
|
-
this.
|
|
2005
|
+
this._replaceDocumentText(key, value);
|
|
1977
2006
|
} else {
|
|
1978
2007
|
this.set_value(key, value);
|
|
1979
2008
|
}
|
|
@@ -2129,7 +2158,7 @@ var MindCache = class {
|
|
|
2129
2158
|
switch (action) {
|
|
2130
2159
|
case "write":
|
|
2131
2160
|
if (isDocument) {
|
|
2132
|
-
this.
|
|
2161
|
+
this._replaceDocumentText(key, value);
|
|
2133
2162
|
} else {
|
|
2134
2163
|
this.set_value(key, value);
|
|
2135
2164
|
}
|