tinybase 7.3.3 → 7.3.4

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.
Files changed (244) hide show
  1. package/checkpoints/index.js +12 -11
  2. package/checkpoints/with-schemas/index.js +12 -11
  3. package/common/index.js +3 -2
  4. package/common/with-schemas/index.js +3 -2
  5. package/index.js +92 -64
  6. package/indexes/index.js +13 -12
  7. package/indexes/with-schemas/index.js +13 -12
  8. package/mergeable-store/index.js +92 -64
  9. package/mergeable-store/with-schemas/index.js +92 -64
  10. package/metrics/index.js +13 -12
  11. package/metrics/with-schemas/index.js +13 -12
  12. package/min/checkpoints/index.js +1 -1
  13. package/min/checkpoints/index.js.gz +0 -0
  14. package/min/checkpoints/with-schemas/index.js +1 -1
  15. package/min/checkpoints/with-schemas/index.js.gz +0 -0
  16. package/min/common/index.js +1 -1
  17. package/min/common/index.js.gz +0 -0
  18. package/min/common/with-schemas/index.js +1 -1
  19. package/min/common/with-schemas/index.js.gz +0 -0
  20. package/min/index.js +1 -1
  21. package/min/index.js.gz +0 -0
  22. package/min/indexes/index.js +1 -1
  23. package/min/indexes/index.js.gz +0 -0
  24. package/min/indexes/with-schemas/index.js +1 -1
  25. package/min/indexes/with-schemas/index.js.gz +0 -0
  26. package/min/mergeable-store/index.js +1 -1
  27. package/min/mergeable-store/index.js.gz +0 -0
  28. package/min/mergeable-store/with-schemas/index.js +1 -1
  29. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  30. package/min/metrics/index.js +1 -1
  31. package/min/metrics/index.js.gz +0 -0
  32. package/min/metrics/with-schemas/index.js +1 -1
  33. package/min/metrics/with-schemas/index.js.gz +0 -0
  34. package/min/omni/index.js +1 -1
  35. package/min/omni/index.js.gz +0 -0
  36. package/min/omni/with-schemas/index.js +1 -1
  37. package/min/omni/with-schemas/index.js.gz +0 -0
  38. package/min/persisters/index.js +1 -1
  39. package/min/persisters/index.js.gz +0 -0
  40. package/min/persisters/persister-automerge/index.js +1 -1
  41. package/min/persisters/persister-automerge/index.js.gz +0 -0
  42. package/min/persisters/persister-automerge/with-schemas/index.js +1 -1
  43. package/min/persisters/persister-automerge/with-schemas/index.js.gz +0 -0
  44. package/min/persisters/persister-browser/index.js +1 -1
  45. package/min/persisters/persister-browser/index.js.gz +0 -0
  46. package/min/persisters/persister-browser/with-schemas/index.js +1 -1
  47. package/min/persisters/persister-browser/with-schemas/index.js.gz +0 -0
  48. package/min/persisters/persister-cr-sqlite-wasm/index.js +1 -1
  49. package/min/persisters/persister-cr-sqlite-wasm/index.js.gz +0 -0
  50. package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +1 -1
  51. package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js.gz +0 -0
  52. package/min/persisters/persister-durable-object-sql-storage/index.js +1 -1
  53. package/min/persisters/persister-durable-object-sql-storage/index.js.gz +0 -0
  54. package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js +1 -1
  55. package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js.gz +0 -0
  56. package/min/persisters/persister-durable-object-storage/index.js +1 -1
  57. package/min/persisters/persister-durable-object-storage/index.js.gz +0 -0
  58. package/min/persisters/persister-durable-object-storage/with-schemas/index.js +1 -1
  59. package/min/persisters/persister-durable-object-storage/with-schemas/index.js.gz +0 -0
  60. package/min/persisters/persister-electric-sql/index.js +1 -1
  61. package/min/persisters/persister-electric-sql/index.js.gz +0 -0
  62. package/min/persisters/persister-electric-sql/with-schemas/index.js +1 -1
  63. package/min/persisters/persister-electric-sql/with-schemas/index.js.gz +0 -0
  64. package/min/persisters/persister-expo-sqlite/index.js +1 -1
  65. package/min/persisters/persister-expo-sqlite/index.js.gz +0 -0
  66. package/min/persisters/persister-expo-sqlite/with-schemas/index.js +1 -1
  67. package/min/persisters/persister-expo-sqlite/with-schemas/index.js.gz +0 -0
  68. package/min/persisters/persister-file/index.js +1 -1
  69. package/min/persisters/persister-file/index.js.gz +0 -0
  70. package/min/persisters/persister-file/with-schemas/index.js +1 -1
  71. package/min/persisters/persister-file/with-schemas/index.js.gz +0 -0
  72. package/min/persisters/persister-indexed-db/index.js +1 -1
  73. package/min/persisters/persister-indexed-db/index.js.gz +0 -0
  74. package/min/persisters/persister-indexed-db/with-schemas/index.js +1 -1
  75. package/min/persisters/persister-indexed-db/with-schemas/index.js.gz +0 -0
  76. package/min/persisters/persister-libsql/index.js +1 -1
  77. package/min/persisters/persister-libsql/index.js.gz +0 -0
  78. package/min/persisters/persister-libsql/with-schemas/index.js +1 -1
  79. package/min/persisters/persister-libsql/with-schemas/index.js.gz +0 -0
  80. package/min/persisters/persister-partykit-client/index.js +1 -1
  81. package/min/persisters/persister-partykit-client/index.js.gz +0 -0
  82. package/min/persisters/persister-partykit-client/with-schemas/index.js +1 -1
  83. package/min/persisters/persister-partykit-client/with-schemas/index.js.gz +0 -0
  84. package/min/persisters/persister-pglite/index.js +1 -1
  85. package/min/persisters/persister-pglite/index.js.gz +0 -0
  86. package/min/persisters/persister-pglite/with-schemas/index.js +1 -1
  87. package/min/persisters/persister-pglite/with-schemas/index.js.gz +0 -0
  88. package/min/persisters/persister-postgres/index.js +1 -1
  89. package/min/persisters/persister-postgres/index.js.gz +0 -0
  90. package/min/persisters/persister-postgres/with-schemas/index.js +1 -1
  91. package/min/persisters/persister-postgres/with-schemas/index.js.gz +0 -0
  92. package/min/persisters/persister-powersync/index.js +1 -1
  93. package/min/persisters/persister-powersync/index.js.gz +0 -0
  94. package/min/persisters/persister-powersync/with-schemas/index.js +1 -1
  95. package/min/persisters/persister-powersync/with-schemas/index.js.gz +0 -0
  96. package/min/persisters/persister-react-native-mmkv/index.js +1 -1
  97. package/min/persisters/persister-react-native-mmkv/index.js.gz +0 -0
  98. package/min/persisters/persister-react-native-mmkv/with-schemas/index.js +1 -1
  99. package/min/persisters/persister-react-native-mmkv/with-schemas/index.js.gz +0 -0
  100. package/min/persisters/persister-react-native-sqlite/index.js +1 -1
  101. package/min/persisters/persister-react-native-sqlite/index.js.gz +0 -0
  102. package/min/persisters/persister-react-native-sqlite/with-schemas/index.js +1 -1
  103. package/min/persisters/persister-react-native-sqlite/with-schemas/index.js.gz +0 -0
  104. package/min/persisters/persister-remote/index.js +1 -1
  105. package/min/persisters/persister-remote/index.js.gz +0 -0
  106. package/min/persisters/persister-remote/with-schemas/index.js +1 -1
  107. package/min/persisters/persister-remote/with-schemas/index.js.gz +0 -0
  108. package/min/persisters/persister-sqlite-bun/index.js +1 -1
  109. package/min/persisters/persister-sqlite-bun/index.js.gz +0 -0
  110. package/min/persisters/persister-sqlite-bun/with-schemas/index.js +1 -1
  111. package/min/persisters/persister-sqlite-bun/with-schemas/index.js.gz +0 -0
  112. package/min/persisters/persister-sqlite-wasm/index.js +1 -1
  113. package/min/persisters/persister-sqlite-wasm/index.js.gz +0 -0
  114. package/min/persisters/persister-sqlite-wasm/with-schemas/index.js +1 -1
  115. package/min/persisters/persister-sqlite-wasm/with-schemas/index.js.gz +0 -0
  116. package/min/persisters/persister-sqlite3/index.js +1 -1
  117. package/min/persisters/persister-sqlite3/index.js.gz +0 -0
  118. package/min/persisters/persister-sqlite3/with-schemas/index.js +1 -1
  119. package/min/persisters/persister-sqlite3/with-schemas/index.js.gz +0 -0
  120. package/min/persisters/persister-yjs/index.js +1 -1
  121. package/min/persisters/persister-yjs/index.js.gz +0 -0
  122. package/min/persisters/persister-yjs/with-schemas/index.js +1 -1
  123. package/min/persisters/persister-yjs/with-schemas/index.js.gz +0 -0
  124. package/min/persisters/with-schemas/index.js +1 -1
  125. package/min/persisters/with-schemas/index.js.gz +0 -0
  126. package/min/queries/index.js +1 -1
  127. package/min/queries/index.js.gz +0 -0
  128. package/min/queries/with-schemas/index.js +1 -1
  129. package/min/queries/with-schemas/index.js.gz +0 -0
  130. package/min/relationships/index.js +1 -1
  131. package/min/relationships/index.js.gz +0 -0
  132. package/min/relationships/with-schemas/index.js +1 -1
  133. package/min/relationships/with-schemas/index.js.gz +0 -0
  134. package/min/store/index.js +1 -1
  135. package/min/store/index.js.gz +0 -0
  136. package/min/store/with-schemas/index.js +1 -1
  137. package/min/store/with-schemas/index.js.gz +0 -0
  138. package/min/synchronizers/index.js +1 -1
  139. package/min/synchronizers/index.js.gz +0 -0
  140. package/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -1
  141. package/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
  142. package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -1
  143. package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
  144. package/min/synchronizers/synchronizer-local/index.js +1 -1
  145. package/min/synchronizers/synchronizer-local/index.js.gz +0 -0
  146. package/min/synchronizers/synchronizer-local/with-schemas/index.js +1 -1
  147. package/min/synchronizers/synchronizer-local/with-schemas/index.js.gz +0 -0
  148. package/min/synchronizers/synchronizer-ws-client/index.js +1 -1
  149. package/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
  150. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  151. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
  152. package/min/synchronizers/synchronizer-ws-server/index.js +1 -1
  153. package/min/synchronizers/synchronizer-ws-server/index.js.gz +0 -0
  154. package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js +1 -1
  155. package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js.gz +0 -0
  156. package/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
  157. package/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
  158. package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
  159. package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
  160. package/min/synchronizers/synchronizer-ws-server-simple/index.js +1 -1
  161. package/min/synchronizers/synchronizer-ws-server-simple/index.js.gz +0 -0
  162. package/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +1 -1
  163. package/min/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js.gz +0 -0
  164. package/min/synchronizers/with-schemas/index.js +1 -1
  165. package/min/synchronizers/with-schemas/index.js.gz +0 -0
  166. package/min/ui-react-inspector/index.js +1 -1
  167. package/min/ui-react-inspector/index.js.gz +0 -0
  168. package/min/ui-react-inspector/with-schemas/index.js +1 -1
  169. package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  170. package/min/with-schemas/index.js +1 -1
  171. package/min/with-schemas/index.js.gz +0 -0
  172. package/omni/index.js +99 -64
  173. package/omni/with-schemas/index.js +99 -64
  174. package/package.json +3 -3
  175. package/persisters/index.js +19 -11
  176. package/persisters/persister-automerge/index.js +17 -9
  177. package/persisters/persister-automerge/with-schemas/index.js +17 -9
  178. package/persisters/persister-browser/index.js +17 -9
  179. package/persisters/persister-browser/with-schemas/index.js +17 -9
  180. package/persisters/persister-cr-sqlite-wasm/index.js +19 -11
  181. package/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +19 -11
  182. package/persisters/persister-durable-object-sql-storage/index.js +19 -11
  183. package/persisters/persister-durable-object-sql-storage/with-schemas/index.js +19 -11
  184. package/persisters/persister-durable-object-storage/index.js +19 -11
  185. package/persisters/persister-durable-object-storage/with-schemas/index.js +19 -11
  186. package/persisters/persister-electric-sql/index.js +19 -11
  187. package/persisters/persister-electric-sql/with-schemas/index.js +19 -11
  188. package/persisters/persister-expo-sqlite/index.js +19 -11
  189. package/persisters/persister-expo-sqlite/with-schemas/index.js +19 -11
  190. package/persisters/persister-file/index.js +17 -9
  191. package/persisters/persister-file/with-schemas/index.js +17 -9
  192. package/persisters/persister-indexed-db/index.js +17 -9
  193. package/persisters/persister-indexed-db/with-schemas/index.js +17 -9
  194. package/persisters/persister-libsql/index.js +19 -11
  195. package/persisters/persister-libsql/with-schemas/index.js +19 -11
  196. package/persisters/persister-partykit-client/index.js +17 -9
  197. package/persisters/persister-partykit-client/with-schemas/index.js +17 -9
  198. package/persisters/persister-partykit-server/index.js +2 -2
  199. package/persisters/persister-partykit-server/with-schemas/index.js +2 -2
  200. package/persisters/persister-pglite/index.js +19 -11
  201. package/persisters/persister-pglite/with-schemas/index.js +19 -11
  202. package/persisters/persister-postgres/index.js +19 -11
  203. package/persisters/persister-postgres/with-schemas/index.js +19 -11
  204. package/persisters/persister-powersync/index.js +19 -11
  205. package/persisters/persister-powersync/with-schemas/index.js +19 -11
  206. package/persisters/persister-react-native-mmkv/index.js +17 -9
  207. package/persisters/persister-react-native-mmkv/with-schemas/index.js +17 -9
  208. package/persisters/persister-react-native-sqlite/index.js +19 -11
  209. package/persisters/persister-react-native-sqlite/with-schemas/index.js +19 -11
  210. package/persisters/persister-remote/index.js +17 -9
  211. package/persisters/persister-remote/with-schemas/index.js +17 -9
  212. package/persisters/persister-sqlite-bun/index.js +19 -11
  213. package/persisters/persister-sqlite-bun/with-schemas/index.js +19 -11
  214. package/persisters/persister-sqlite-wasm/index.js +19 -11
  215. package/persisters/persister-sqlite-wasm/with-schemas/index.js +19 -11
  216. package/persisters/persister-sqlite3/index.js +19 -11
  217. package/persisters/persister-sqlite3/with-schemas/index.js +19 -11
  218. package/persisters/persister-yjs/index.js +19 -11
  219. package/persisters/persister-yjs/with-schemas/index.js +19 -11
  220. package/persisters/with-schemas/index.js +19 -11
  221. package/queries/index.js +15 -14
  222. package/queries/with-schemas/index.js +15 -14
  223. package/readme.md +2 -2
  224. package/relationships/index.js +13 -12
  225. package/relationships/with-schemas/index.js +13 -12
  226. package/store/index.js +74 -60
  227. package/store/with-schemas/index.js +74 -60
  228. package/synchronizers/index.js +17 -9
  229. package/synchronizers/synchronizer-broadcast-channel/index.js +17 -9
  230. package/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +17 -9
  231. package/synchronizers/synchronizer-local/index.js +19 -11
  232. package/synchronizers/synchronizer-local/with-schemas/index.js +19 -11
  233. package/synchronizers/synchronizer-ws-client/index.js +17 -9
  234. package/synchronizers/synchronizer-ws-client/with-schemas/index.js +17 -9
  235. package/synchronizers/synchronizer-ws-server/index.js +20 -12
  236. package/synchronizers/synchronizer-ws-server/with-schemas/index.js +20 -12
  237. package/synchronizers/synchronizer-ws-server-durable-object/index.js +17 -9
  238. package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +17 -9
  239. package/synchronizers/synchronizer-ws-server-simple/index.js +11 -10
  240. package/synchronizers/synchronizer-ws-server-simple/with-schemas/index.js +11 -10
  241. package/synchronizers/with-schemas/index.js +17 -9
  242. package/ui-react-inspector/index.js +81 -60
  243. package/ui-react-inspector/with-schemas/index.js +81 -60
  244. package/with-schemas/index.js +92 -64
@@ -140,31 +140,32 @@ const objValidate = (obj, validateChild, onInvalidObj, emptyIsValid = 0) => {
140
140
  return emptyIsValid ? true : !objIsEmpty(obj);
141
141
  };
142
142
 
143
- const mapNew = (entries) => new Map(entries);
144
- const mapKeys = (map) => [...(map?.keys() ?? [])];
145
- const mapGet = (map, key) => map?.get(key);
146
- const mapForEach = (map, cb) =>
147
- collForEach(map, (value, key) => cb(key, value));
143
+ const map = Map;
144
+ const mapNew = (entries) => new map(entries);
145
+ const mapKeys = (map2) => [...(map2?.keys() ?? [])];
146
+ const mapGet = (map2, key) => map2?.get(key);
147
+ const mapForEach = (map2, cb) =>
148
+ collForEach(map2, (value, key) => cb(key, value));
148
149
  const mapMap = (coll, cb) =>
149
150
  arrayMap([...(coll?.entries() ?? [])], ([key, value]) => cb(value, key));
150
- const mapSet = (map, key, value) =>
151
- isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
152
- const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
153
- if (!collHas(map, key)) {
154
- mapSet(map, key, getDefaultValue());
151
+ const mapSet = (map2, key, value) =>
152
+ isUndefined(value) ? (collDel(map2, key), map2) : map2?.set(key, value);
153
+ const mapEnsure = (map2, key, getDefaultValue, hadExistingValue) => {
154
+ if (!collHas(map2, key)) {
155
+ mapSet(map2, key, getDefaultValue());
155
156
  } else {
156
- hadExistingValue?.(mapGet(map, key));
157
+ hadExistingValue?.(mapGet(map2, key));
157
158
  }
158
- return mapGet(map, key);
159
+ return mapGet(map2, key);
159
160
  };
160
- const mapMatch = (map, obj, set, del = mapSet) => {
161
- objMap(obj, (value, id) => set(map, id, value));
162
- mapForEach(map, (id) => (objHas(obj, id) ? 0 : del(map, id)));
163
- return map;
161
+ const mapMatch = (map2, obj, set, del = mapSet) => {
162
+ objMap(obj, (value, id) => set(map2, id, value));
163
+ mapForEach(map2, (id) => (objHas(obj, id) ? 0 : del(map2, id)));
164
+ return map2;
164
165
  };
165
- const mapToObj = (map, valueMapper, excludeMapValue, excludeObjValue) => {
166
+ const mapToObj = (map2, valueMapper, excludeMapValue, excludeObjValue) => {
166
167
  const obj = {};
167
- collForEach(map, (mapValue, id) => {
168
+ collForEach(map2, (mapValue, id) => {
168
169
  if (!excludeMapValue?.(mapValue, id)) {
169
170
  const objValue = valueMapper ? valueMapper(mapValue, id) : mapValue;
170
171
  if (!excludeObjValue?.(objValue)) {
@@ -174,27 +175,27 @@ const mapToObj = (map, valueMapper, excludeMapValue, excludeObjValue) => {
174
175
  });
175
176
  return obj;
176
177
  };
177
- const mapToObj2 = (map, valueMapper, excludeMapValue) =>
178
+ const mapToObj2 = (map2, valueMapper, excludeMapValue) =>
178
179
  mapToObj(
179
- map,
180
+ map2,
180
181
  (childMap) => mapToObj(childMap, valueMapper, excludeMapValue),
181
182
  collIsEmpty,
182
183
  objIsEmpty,
183
184
  );
184
- const mapToObj3 = (map, valueMapper, excludeMapValue) =>
185
+ const mapToObj3 = (map2, valueMapper, excludeMapValue) =>
185
186
  mapToObj(
186
- map,
187
+ map2,
187
188
  (childMap) => mapToObj2(childMap, valueMapper, excludeMapValue),
188
189
  collIsEmpty,
189
190
  objIsEmpty,
190
191
  );
191
- const mapClone = (map, mapValue) => {
192
- const map2 = mapNew();
193
- collForEach(map, (value, key) => map2.set(key, mapValue?.(value) ?? value));
194
- return map2;
192
+ const mapClone = (map2, mapValue) => {
193
+ const map22 = mapNew();
194
+ collForEach(map2, (value, key) => map22.set(key, mapValue?.(value) ?? value));
195
+ return map22;
195
196
  };
196
- const mapClone2 = (map) => mapClone(map, mapClone);
197
- const mapClone3 = (map) => mapClone(map, mapClone2);
197
+ const mapClone2 = (map2) => mapClone(map2, mapClone);
198
+ const mapClone3 = (map2) => mapClone(map2, mapClone2);
198
199
  const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
199
200
  ifNotUndefined(
200
201
  (ensureLeaf ? mapEnsure : mapGet)(
@@ -340,6 +341,7 @@ const createStore = () => {
340
341
  let hadValues = false;
341
342
  let transactions = 0;
342
343
  let internalListeners = [];
344
+ let mutating = 0;
343
345
  const changedTableIds = mapNew();
344
346
  const changedTableCellIds = mapNew();
345
347
  const changedRowCount = mapNew();
@@ -744,13 +746,13 @@ const createStore = () => {
744
746
  cellId,
745
747
  () => [oldCell, 0],
746
748
  )[1] = newCell;
747
- internalListeners[3]?.(tableId, rowId, cellId, newCell);
749
+ internalListeners[3]?.(tableId, rowId, cellId, newCell, mutating);
748
750
  };
749
751
  const valueIdsChanged = (valueId, addedOrRemoved) =>
750
752
  idsChanged(changedValueIds, valueId, addedOrRemoved);
751
753
  const valueChanged = (valueId, oldValue, newValue) => {
752
754
  mapEnsure(changedValues, valueId, () => [oldValue, 0])[1] = newValue;
753
- internalListeners[4]?.(valueId, newValue);
755
+ internalListeners[4]?.(valueId, newValue, mutating);
754
756
  };
755
757
  const cellInvalid = (tableId, rowId, cellId, invalidCell, defaultedCell) => {
756
758
  arrayPush(
@@ -825,14 +827,11 @@ const createStore = () => {
825
827
  }
826
828
  };
827
829
  const callTabularListenersForChanges = (mutator) => {
828
- const hasTablesNow = hasTables();
829
- if (hasTablesNow != hadTables) {
830
- callListeners(hasTablesListeners[mutator], void 0, hasTablesNow);
831
- }
832
- const emptySortedRowIdListeners = collIsEmpty(
830
+ const hasHasTablesListeners = !collIsEmpty(hasTablesListeners[mutator]);
831
+ const hasSortedRowIdListeners = !collIsEmpty(
833
832
  sortedRowIdsListeners[mutator],
834
833
  );
835
- const emptyIdAndHasListeners =
834
+ const hasIdOrHasListeners = !(
836
835
  collIsEmpty(cellIdsListeners[mutator]) &&
837
836
  collIsEmpty(hasCellListeners[mutator]) &&
838
837
  collIsEmpty(rowIdsListeners[mutator]) &&
@@ -840,15 +839,17 @@ const createStore = () => {
840
839
  collIsEmpty(tableCellIdsListeners[mutator]) &&
841
840
  collIsEmpty(hasTableCellListeners[mutator]) &&
842
841
  collIsEmpty(rowCountListeners[mutator]) &&
843
- emptySortedRowIdListeners &&
842
+ !hasSortedRowIdListeners &&
844
843
  collIsEmpty(tableIdsListeners[mutator]) &&
845
- collIsEmpty(hasTableListeners[mutator]);
846
- const emptyOtherListeners =
844
+ collIsEmpty(hasTableListeners[mutator])
845
+ );
846
+ const hasOtherListeners = !(
847
847
  collIsEmpty(cellListeners[mutator]) &&
848
848
  collIsEmpty(rowListeners[mutator]) &&
849
849
  collIsEmpty(tableListeners[mutator]) &&
850
- collIsEmpty(tablesListeners[mutator]);
851
- if (!emptyIdAndHasListeners || !emptyOtherListeners) {
850
+ collIsEmpty(tablesListeners[mutator])
851
+ );
852
+ if (hasHasTablesListeners || hasIdOrHasListeners || hasOtherListeners) {
852
853
  const changes = mutator
853
854
  ? [
854
855
  mapClone(changedTableIds),
@@ -856,7 +857,9 @@ const createStore = () => {
856
857
  mapClone(changedRowCount),
857
858
  mapClone2(changedRowIds),
858
859
  mapClone3(changedCellIds),
859
- mapClone3(changedCells),
860
+ mapClone(changedCells, (map) =>
861
+ mapClone(map, (map2) => mapClone(map2, pairClone)),
862
+ ),
860
863
  ]
861
864
  : [
862
865
  changedTableIds,
@@ -866,7 +869,13 @@ const createStore = () => {
866
869
  changedCellIds,
867
870
  changedCells,
868
871
  ];
869
- if (!emptyIdAndHasListeners) {
872
+ if (hasHasTablesListeners) {
873
+ const hasTablesNow = hasTables();
874
+ if (hasTablesNow != hadTables) {
875
+ callListeners(hasTablesListeners[mutator], void 0, hasTablesNow);
876
+ }
877
+ }
878
+ if (hasIdOrHasListeners) {
870
879
  callIdsAndHasListenersIfChanged(
871
880
  changes[0],
872
881
  tableIdsListeners[mutator],
@@ -898,13 +907,13 @@ const createStore = () => {
898
907
  hasRowListeners[mutator],
899
908
  [tableId],
900
909
  ) &&
901
- !emptySortedRowIdListeners
910
+ hasSortedRowIdListeners
902
911
  ) {
903
912
  callListeners(sortedRowIdsListeners[mutator], [tableId, null]);
904
913
  setAdd(calledSortableTableIds, tableId);
905
914
  }
906
915
  });
907
- if (!emptySortedRowIdListeners) {
916
+ if (hasSortedRowIdListeners) {
908
917
  collForEach(changes[5], (rows, tableId) => {
909
918
  if (!collHas(calledSortableTableIds, tableId)) {
910
919
  const sortableCellIds = setNew();
@@ -935,7 +944,7 @@ const createStore = () => {
935
944
  ),
936
945
  );
937
946
  }
938
- if (!emptyOtherListeners) {
947
+ if (hasOtherListeners) {
939
948
  let tablesChanged;
940
949
  collForEach(changes[5], (rows, tableId) => {
941
950
  let tableChanged;
@@ -972,28 +981,31 @@ const createStore = () => {
972
981
  }
973
982
  };
974
983
  const callValuesListenersForChanges = (mutator) => {
975
- const hasValuesNow = hasValues();
976
- if (hasValuesNow != hadValues) {
977
- callListeners(hasValuesListeners[mutator], void 0, hasValuesNow);
978
- }
979
- const emptyIdAndHasListeners =
980
- collIsEmpty(valueIdsListeners[mutator]) &&
981
- collIsEmpty(hasValueListeners[mutator]);
982
- const emptyOtherListeners =
983
- collIsEmpty(valueListeners[mutator]) &&
984
- collIsEmpty(valuesListeners[mutator]);
985
- if (!emptyIdAndHasListeners || !emptyOtherListeners) {
984
+ const hasHasValuesListeners = !collIsEmpty(hasValuesListeners[mutator]);
985
+ const hasIdOrHasListeners =
986
+ !collIsEmpty(valueIdsListeners[mutator]) ||
987
+ !collIsEmpty(hasValueListeners[mutator]);
988
+ const hasOtherListeners =
989
+ !collIsEmpty(valueListeners[mutator]) ||
990
+ !collIsEmpty(valuesListeners[mutator]);
991
+ if (hasHasValuesListeners || hasIdOrHasListeners || hasOtherListeners) {
986
992
  const changes = mutator
987
- ? [mapClone(changedValueIds), mapClone(changedValues)]
993
+ ? [mapClone(changedValueIds), mapClone(changedValues, pairClone)]
988
994
  : [changedValueIds, changedValues];
989
- if (!emptyIdAndHasListeners) {
995
+ if (hasHasValuesListeners) {
996
+ const hasValuesNow = hasValues();
997
+ if (hasValuesNow != hadValues) {
998
+ callListeners(hasValuesListeners[mutator], void 0, hasValuesNow);
999
+ }
1000
+ }
1001
+ if (hasIdOrHasListeners) {
990
1002
  callIdsAndHasListenersIfChanged(
991
1003
  changes[0],
992
1004
  valueIdsListeners[mutator],
993
1005
  hasValueListeners[mutator],
994
1006
  );
995
1007
  }
996
- if (!emptyOtherListeners) {
1008
+ if (hasOtherListeners) {
997
1009
  let valuesChanged;
998
1010
  collForEach(changes[1], ([oldValue, newValue], valueId) => {
999
1011
  if (newValue !== oldValue) {
@@ -1390,6 +1402,7 @@ const createStore = () => {
1390
1402
  transactions--;
1391
1403
  if (transactions == 0) {
1392
1404
  transactions = 1;
1405
+ mutating = 1;
1393
1406
  callInvalidCellListeners(1);
1394
1407
  if (!collIsEmpty(changedCells)) {
1395
1408
  callTabularListenersForChanges(1);
@@ -1398,6 +1411,7 @@ const createStore = () => {
1398
1411
  if (!collIsEmpty(changedValues)) {
1399
1412
  callValuesListenersForChanges(1);
1400
1413
  }
1414
+ mutating = 0;
1401
1415
  if (doRollback?.(store)) {
1402
1416
  collForEach(changedCells, (table, tableId) =>
1403
1417
  collForEach(table, (row, rowId) =>
@@ -75,17 +75,18 @@ const objEnsure = (obj, id, getDefaultValue) => {
75
75
  return obj[id];
76
76
  };
77
77
 
78
- const mapNew = (entries) => new Map(entries);
79
- const mapGet = (map, key) => map?.get(key);
80
- const mapSet = (map, key, value) =>
81
- isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
82
- const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
83
- if (!collHas(map, key)) {
84
- mapSet(map, key, getDefaultValue());
78
+ const map = Map;
79
+ const mapNew = (entries) => new map(entries);
80
+ const mapGet = (map2, key) => map2?.get(key);
81
+ const mapSet = (map2, key, value) =>
82
+ isUndefined(value) ? (collDel(map2, key), map2) : map2?.set(key, value);
83
+ const mapEnsure = (map2, key, getDefaultValue, hadExistingValue) => {
84
+ if (!collHas(map2, key)) {
85
+ mapSet(map2, key, getDefaultValue());
85
86
  } else {
86
- hadExistingValue?.(mapGet(map, key));
87
+ hadExistingValue?.(mapGet(map2, key));
87
88
  }
88
- return mapGet(map, key);
89
+ return mapGet(map2, key);
89
90
  };
90
91
  const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
91
92
  ifNotUndefined(
@@ -309,6 +310,11 @@ const createCustomPersister = (
309
310
  ? store.applyChanges
310
311
  : store.setContent)(contentOrChanges);
311
312
  };
313
+ const saveAfterMutated = async () => {
314
+ if (isAutoSaving() && store.hadMutated?.()) {
315
+ await save();
316
+ }
317
+ };
312
318
  const load = async (initialContent) => {
313
319
  /* istanbul ignore else */
314
320
  if (status != 2 /* Saving */) {
@@ -333,6 +339,7 @@ const createCustomPersister = (
333
339
  },
334
340
  );
335
341
  setStatus(0 /* Idle */);
342
+ await saveAfterMutated();
336
343
  });
337
344
  }
338
345
  return persister;
@@ -351,6 +358,7 @@ const createCustomPersister = (
351
358
  loads++;
352
359
  setContentOrChanges(changes ?? content);
353
360
  setStatus(0 /* Idle */);
361
+ await saveAfterMutated();
354
362
  }
355
363
  } else {
356
364
  await load();
@@ -75,17 +75,18 @@ const objEnsure = (obj, id, getDefaultValue) => {
75
75
  return obj[id];
76
76
  };
77
77
 
78
- const mapNew = (entries) => new Map(entries);
79
- const mapGet = (map, key) => map?.get(key);
80
- const mapSet = (map, key, value) =>
81
- isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
82
- const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
83
- if (!collHas(map, key)) {
84
- mapSet(map, key, getDefaultValue());
78
+ const map = Map;
79
+ const mapNew = (entries) => new map(entries);
80
+ const mapGet = (map2, key) => map2?.get(key);
81
+ const mapSet = (map2, key, value) =>
82
+ isUndefined(value) ? (collDel(map2, key), map2) : map2?.set(key, value);
83
+ const mapEnsure = (map2, key, getDefaultValue, hadExistingValue) => {
84
+ if (!collHas(map2, key)) {
85
+ mapSet(map2, key, getDefaultValue());
85
86
  } else {
86
- hadExistingValue?.(mapGet(map, key));
87
+ hadExistingValue?.(mapGet(map2, key));
87
88
  }
88
- return mapGet(map, key);
89
+ return mapGet(map2, key);
89
90
  };
90
91
  const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
91
92
  ifNotUndefined(
@@ -309,6 +310,11 @@ const createCustomPersister = (
309
310
  ? store.applyChanges
310
311
  : store.setContent)(contentOrChanges);
311
312
  };
313
+ const saveAfterMutated = async () => {
314
+ if (isAutoSaving() && store.hadMutated?.()) {
315
+ await save();
316
+ }
317
+ };
312
318
  const load = async (initialContent) => {
313
319
  /* istanbul ignore else */
314
320
  if (status != 2 /* Saving */) {
@@ -333,6 +339,7 @@ const createCustomPersister = (
333
339
  },
334
340
  );
335
341
  setStatus(0 /* Idle */);
342
+ await saveAfterMutated();
336
343
  });
337
344
  }
338
345
  return persister;
@@ -351,6 +358,7 @@ const createCustomPersister = (
351
358
  loads++;
352
359
  setContentOrChanges(changes ?? content);
353
360
  setStatus(0 /* Idle */);
361
+ await saveAfterMutated();
354
362
  }
355
363
  } else {
356
364
  await load();
@@ -75,17 +75,18 @@ const objEnsure = (obj, id, getDefaultValue) => {
75
75
  return obj[id];
76
76
  };
77
77
 
78
- const mapNew = (entries) => new Map(entries);
79
- const mapGet = (map, key) => map?.get(key);
80
- const mapSet = (map, key, value) =>
81
- isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
82
- const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
83
- if (!collHas(map, key)) {
84
- mapSet(map, key, getDefaultValue());
78
+ const map = Map;
79
+ const mapNew = (entries) => new map(entries);
80
+ const mapGet = (map2, key) => map2?.get(key);
81
+ const mapSet = (map2, key, value) =>
82
+ isUndefined(value) ? (collDel(map2, key), map2) : map2?.set(key, value);
83
+ const mapEnsure = (map2, key, getDefaultValue, hadExistingValue) => {
84
+ if (!collHas(map2, key)) {
85
+ mapSet(map2, key, getDefaultValue());
85
86
  } else {
86
- hadExistingValue?.(mapGet(map, key));
87
+ hadExistingValue?.(mapGet(map2, key));
87
88
  }
88
- return mapGet(map, key);
89
+ return mapGet(map2, key);
89
90
  };
90
91
  const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
91
92
  ifNotUndefined(
@@ -309,6 +310,11 @@ const createCustomPersister = (
309
310
  ? store.applyChanges
310
311
  : store.setContent)(contentOrChanges);
311
312
  };
313
+ const saveAfterMutated = async () => {
314
+ if (isAutoSaving() && store.hadMutated?.()) {
315
+ await save();
316
+ }
317
+ };
312
318
  const load = async (initialContent) => {
313
319
  /* istanbul ignore else */
314
320
  if (status != 2 /* Saving */) {
@@ -333,6 +339,7 @@ const createCustomPersister = (
333
339
  },
334
340
  );
335
341
  setStatus(0 /* Idle */);
342
+ await saveAfterMutated();
336
343
  });
337
344
  }
338
345
  return persister;
@@ -351,6 +358,7 @@ const createCustomPersister = (
351
358
  loads++;
352
359
  setContentOrChanges(changes ?? content);
353
360
  setStatus(0 /* Idle */);
361
+ await saveAfterMutated();
354
362
  }
355
363
  } else {
356
364
  await load();
@@ -75,19 +75,20 @@ const objEnsure = (obj, id, getDefaultValue) => {
75
75
  return obj[id];
76
76
  };
77
77
 
78
- const mapNew = (entries) => new Map(entries);
79
- const mapGet = (map, key) => map?.get(key);
80
- const mapForEach = (map, cb) =>
81
- collForEach(map, (value, key) => cb(key, value));
82
- const mapSet = (map, key, value) =>
83
- isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
84
- const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
85
- if (!collHas(map, key)) {
86
- mapSet(map, key, getDefaultValue());
78
+ const map = Map;
79
+ const mapNew = (entries) => new map(entries);
80
+ const mapGet = (map2, key) => map2?.get(key);
81
+ const mapForEach = (map2, cb) =>
82
+ collForEach(map2, (value, key) => cb(key, value));
83
+ const mapSet = (map2, key, value) =>
84
+ isUndefined(value) ? (collDel(map2, key), map2) : map2?.set(key, value);
85
+ const mapEnsure = (map2, key, getDefaultValue, hadExistingValue) => {
86
+ if (!collHas(map2, key)) {
87
+ mapSet(map2, key, getDefaultValue());
87
88
  } else {
88
- hadExistingValue?.(mapGet(map, key));
89
+ hadExistingValue?.(mapGet(map2, key));
89
90
  }
90
- return mapGet(map, key);
91
+ return mapGet(map2, key);
91
92
  };
92
93
  const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
93
94
  ifNotUndefined(
@@ -311,6 +312,11 @@ const createCustomPersister = (
311
312
  ? store.applyChanges
312
313
  : store.setContent)(contentOrChanges);
313
314
  };
315
+ const saveAfterMutated = async () => {
316
+ if (isAutoSaving() && store.hadMutated?.()) {
317
+ await save();
318
+ }
319
+ };
314
320
  const load = async (initialContent) => {
315
321
  /* istanbul ignore else */
316
322
  if (status != 2 /* Saving */) {
@@ -335,6 +341,7 @@ const createCustomPersister = (
335
341
  },
336
342
  );
337
343
  setStatus(0 /* Idle */);
344
+ await saveAfterMutated();
338
345
  });
339
346
  }
340
347
  return persister;
@@ -353,6 +360,7 @@ const createCustomPersister = (
353
360
  loads++;
354
361
  setContentOrChanges(changes ?? content);
355
362
  setStatus(0 /* Idle */);
363
+ await saveAfterMutated();
356
364
  }
357
365
  } else {
358
366
  await load();
@@ -75,19 +75,20 @@ const objEnsure = (obj, id, getDefaultValue) => {
75
75
  return obj[id];
76
76
  };
77
77
 
78
- const mapNew = (entries) => new Map(entries);
79
- const mapGet = (map, key) => map?.get(key);
80
- const mapForEach = (map, cb) =>
81
- collForEach(map, (value, key) => cb(key, value));
82
- const mapSet = (map, key, value) =>
83
- isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
84
- const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
85
- if (!collHas(map, key)) {
86
- mapSet(map, key, getDefaultValue());
78
+ const map = Map;
79
+ const mapNew = (entries) => new map(entries);
80
+ const mapGet = (map2, key) => map2?.get(key);
81
+ const mapForEach = (map2, cb) =>
82
+ collForEach(map2, (value, key) => cb(key, value));
83
+ const mapSet = (map2, key, value) =>
84
+ isUndefined(value) ? (collDel(map2, key), map2) : map2?.set(key, value);
85
+ const mapEnsure = (map2, key, getDefaultValue, hadExistingValue) => {
86
+ if (!collHas(map2, key)) {
87
+ mapSet(map2, key, getDefaultValue());
87
88
  } else {
88
- hadExistingValue?.(mapGet(map, key));
89
+ hadExistingValue?.(mapGet(map2, key));
89
90
  }
90
- return mapGet(map, key);
91
+ return mapGet(map2, key);
91
92
  };
92
93
  const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
93
94
  ifNotUndefined(
@@ -311,6 +312,11 @@ const createCustomPersister = (
311
312
  ? store.applyChanges
312
313
  : store.setContent)(contentOrChanges);
313
314
  };
315
+ const saveAfterMutated = async () => {
316
+ if (isAutoSaving() && store.hadMutated?.()) {
317
+ await save();
318
+ }
319
+ };
314
320
  const load = async (initialContent) => {
315
321
  /* istanbul ignore else */
316
322
  if (status != 2 /* Saving */) {
@@ -335,6 +341,7 @@ const createCustomPersister = (
335
341
  },
336
342
  );
337
343
  setStatus(0 /* Idle */);
344
+ await saveAfterMutated();
338
345
  });
339
346
  }
340
347
  return persister;
@@ -353,6 +360,7 @@ const createCustomPersister = (
353
360
  loads++;
354
361
  setContentOrChanges(changes ?? content);
355
362
  setStatus(0 /* Idle */);
363
+ await saveAfterMutated();
356
364
  }
357
365
  } else {
358
366
  await load();
@@ -117,17 +117,18 @@ const collIsEmpty = (coll) => isUndefined(coll) || collSize(coll) == 0;
117
117
  const collForEach = (coll, cb) => coll?.forEach(cb);
118
118
  const collDel = (coll, keyOrValue) => coll?.delete(keyOrValue);
119
119
 
120
- const mapNew = (entries) => new Map(entries);
121
- const mapGet = (map, key) => map?.get(key);
122
- const mapSet = (map, key, value) =>
123
- isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
124
- const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
125
- if (!collHas(map, key)) {
126
- mapSet(map, key, getDefaultValue());
120
+ const map = Map;
121
+ const mapNew = (entries) => new map(entries);
122
+ const mapGet = (map2, key) => map2?.get(key);
123
+ const mapSet = (map2, key, value) =>
124
+ isUndefined(value) ? (collDel(map2, key), map2) : map2?.set(key, value);
125
+ const mapEnsure = (map2, key, getDefaultValue, hadExistingValue) => {
126
+ if (!collHas(map2, key)) {
127
+ mapSet(map2, key, getDefaultValue());
127
128
  } else {
128
- hadExistingValue?.(mapGet(map, key));
129
+ hadExistingValue?.(mapGet(map2, key));
129
130
  }
130
- return mapGet(map, key);
131
+ return mapGet(map2, key);
131
132
  };
132
133
  const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
133
134
  ifNotUndefined(
@@ -351,6 +352,11 @@ const createCustomPersister = (
351
352
  ? store.applyChanges
352
353
  : store.setContent)(contentOrChanges);
353
354
  };
355
+ const saveAfterMutated = async () => {
356
+ if (isAutoSaving() && store.hadMutated?.()) {
357
+ await save();
358
+ }
359
+ };
354
360
  const load = async (initialContent) => {
355
361
  /* istanbul ignore else */
356
362
  if (status != 2 /* Saving */) {
@@ -375,6 +381,7 @@ const createCustomPersister = (
375
381
  },
376
382
  );
377
383
  setStatus(0 /* Idle */);
384
+ await saveAfterMutated();
378
385
  });
379
386
  }
380
387
  return persister;
@@ -393,6 +400,7 @@ const createCustomPersister = (
393
400
  loads++;
394
401
  setContentOrChanges(changes ?? content);
395
402
  setStatus(0 /* Idle */);
403
+ await saveAfterMutated();
396
404
  }
397
405
  } else {
398
406
  await load();
@@ -117,17 +117,18 @@ const collIsEmpty = (coll) => isUndefined(coll) || collSize(coll) == 0;
117
117
  const collForEach = (coll, cb) => coll?.forEach(cb);
118
118
  const collDel = (coll, keyOrValue) => coll?.delete(keyOrValue);
119
119
 
120
- const mapNew = (entries) => new Map(entries);
121
- const mapGet = (map, key) => map?.get(key);
122
- const mapSet = (map, key, value) =>
123
- isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
124
- const mapEnsure = (map, key, getDefaultValue, hadExistingValue) => {
125
- if (!collHas(map, key)) {
126
- mapSet(map, key, getDefaultValue());
120
+ const map = Map;
121
+ const mapNew = (entries) => new map(entries);
122
+ const mapGet = (map2, key) => map2?.get(key);
123
+ const mapSet = (map2, key, value) =>
124
+ isUndefined(value) ? (collDel(map2, key), map2) : map2?.set(key, value);
125
+ const mapEnsure = (map2, key, getDefaultValue, hadExistingValue) => {
126
+ if (!collHas(map2, key)) {
127
+ mapSet(map2, key, getDefaultValue());
127
128
  } else {
128
- hadExistingValue?.(mapGet(map, key));
129
+ hadExistingValue?.(mapGet(map2, key));
129
130
  }
130
- return mapGet(map, key);
131
+ return mapGet(map2, key);
131
132
  };
132
133
  const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
133
134
  ifNotUndefined(
@@ -351,6 +352,11 @@ const createCustomPersister = (
351
352
  ? store.applyChanges
352
353
  : store.setContent)(contentOrChanges);
353
354
  };
355
+ const saveAfterMutated = async () => {
356
+ if (isAutoSaving() && store.hadMutated?.()) {
357
+ await save();
358
+ }
359
+ };
354
360
  const load = async (initialContent) => {
355
361
  /* istanbul ignore else */
356
362
  if (status != 2 /* Saving */) {
@@ -375,6 +381,7 @@ const createCustomPersister = (
375
381
  },
376
382
  );
377
383
  setStatus(0 /* Idle */);
384
+ await saveAfterMutated();
378
385
  });
379
386
  }
380
387
  return persister;
@@ -393,6 +400,7 @@ const createCustomPersister = (
393
400
  loads++;
394
401
  setContentOrChanges(changes ?? content);
395
402
  setStatus(0 /* Idle */);
403
+ await saveAfterMutated();
396
404
  }
397
405
  } else {
398
406
  await load();