tinybase 2.0.1 → 2.1.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.
Files changed (71) hide show
  1. package/lib/checkpoints.js +1 -1
  2. package/lib/checkpoints.js.gz +0 -0
  3. package/lib/debug/checkpoints.js +7 -1
  4. package/lib/debug/indexes.d.ts +37 -10
  5. package/lib/debug/indexes.js +57 -25
  6. package/lib/debug/metrics.js +19 -2
  7. package/lib/debug/queries.js +18 -2
  8. package/lib/debug/relationships.js +19 -2
  9. package/lib/debug/store.js +7 -1
  10. package/lib/debug/tinybase.js +52 -25
  11. package/lib/debug/ui-react.js +2 -1
  12. package/lib/es6/checkpoints.js +1 -1
  13. package/lib/es6/checkpoints.js.gz +0 -0
  14. package/lib/es6/indexes.d.ts +37 -10
  15. package/lib/es6/indexes.js +1 -1
  16. package/lib/es6/indexes.js.gz +0 -0
  17. package/lib/es6/metrics.js +1 -1
  18. package/lib/es6/metrics.js.gz +0 -0
  19. package/lib/es6/queries.js +1 -1
  20. package/lib/es6/queries.js.gz +0 -0
  21. package/lib/es6/relationships.js +1 -1
  22. package/lib/es6/relationships.js.gz +0 -0
  23. package/lib/es6/store.js +1 -1
  24. package/lib/es6/store.js.gz +0 -0
  25. package/lib/es6/tinybase.js +1 -1
  26. package/lib/es6/tinybase.js.gz +0 -0
  27. package/lib/indexes.d.ts +37 -10
  28. package/lib/indexes.js +1 -1
  29. package/lib/indexes.js.gz +0 -0
  30. package/lib/metrics.js +1 -1
  31. package/lib/metrics.js.gz +0 -0
  32. package/lib/queries.js +1 -1
  33. package/lib/queries.js.gz +0 -0
  34. package/lib/relationships.js +1 -1
  35. package/lib/relationships.js.gz +0 -0
  36. package/lib/store.js +1 -1
  37. package/lib/store.js.gz +0 -0
  38. package/lib/tinybase.js +1 -1
  39. package/lib/tinybase.js.gz +0 -0
  40. package/lib/umd/checkpoints.js +1 -1
  41. package/lib/umd/checkpoints.js.gz +0 -0
  42. package/lib/umd/indexes.d.ts +37 -10
  43. package/lib/umd/indexes.js +1 -1
  44. package/lib/umd/indexes.js.gz +0 -0
  45. package/lib/umd/metrics.js +1 -1
  46. package/lib/umd/metrics.js.gz +0 -0
  47. package/lib/umd/queries.js +1 -1
  48. package/lib/umd/queries.js.gz +0 -0
  49. package/lib/umd/relationships.js +1 -1
  50. package/lib/umd/relationships.js.gz +0 -0
  51. package/lib/umd/store.js +1 -1
  52. package/lib/umd/store.js.gz +0 -0
  53. package/lib/umd/tinybase.js +1 -1
  54. package/lib/umd/tinybase.js.gz +0 -0
  55. package/lib/umd-es6/checkpoints.js +1 -1
  56. package/lib/umd-es6/checkpoints.js.gz +0 -0
  57. package/lib/umd-es6/indexes.d.ts +37 -10
  58. package/lib/umd-es6/indexes.js +1 -1
  59. package/lib/umd-es6/indexes.js.gz +0 -0
  60. package/lib/umd-es6/metrics.js +1 -1
  61. package/lib/umd-es6/metrics.js.gz +0 -0
  62. package/lib/umd-es6/queries.js +1 -1
  63. package/lib/umd-es6/queries.js.gz +0 -0
  64. package/lib/umd-es6/relationships.js +1 -1
  65. package/lib/umd-es6/relationships.js.gz +0 -0
  66. package/lib/umd-es6/store.js +1 -1
  67. package/lib/umd-es6/store.js.gz +0 -0
  68. package/lib/umd-es6/tinybase.js +1 -1
  69. package/lib/umd-es6/tinybase.js.gz +0 -0
  70. package/package.json +17 -16
  71. package/readme.md +2 -2
@@ -1 +1 @@
1
- const e=(e,t)=>e.includes(t),t=(e,t)=>e.forEach(t),n=e=>e.length,r=e=>0==n(e),o=(e,...t)=>e.push(...t),s=e=>e.pop(),l=e=>e.shift(),c=e=>null==e,i=(e,t,n)=>c(e)?n?.():t(e),d=(e,t)=>e?.has(t)??!1,a=e=>c(e)||0==(e=>e.size)(e),u=(e,t)=>e?.forEach(t),h=(e,t)=>e?.delete(t),p=e=>new Map(e),C=(e,t)=>e?.get(t),g=(e,t,n)=>c(n)?(h(e,t),e):e?.set(t,n),k=(e,t,n)=>(d(e,t)||g(e,t,n()),C(e,t)),f=(e,t,r,o,s=0)=>i((r?k:C)(e,t[s],s>n(t)-2?r:p),(l=>{if(s>n(t)-2)return o?.(l)&&g(e,t[s]),l;const c=f(l,t,r,o,s+1);return a(l)&&g(e,t[s]),c})),v=e=>new Set(e),L=/^\d+$/,w=e=>{let r;const[s,d]=(()=>{const e=[];let t=0;return[()=>l(e)??""+t++,t=>{L.test(t)&&n(e)<1e3&&o(e,t)}]})(),k=p();return[(t,n,o)=>{r??=e();const l=s();var c,i;return g(k,l,[t,n,o]),c=f(n,o??[""],v),i=l,c?.add(i),l},(e,s,...l)=>t(((e,r=[""])=>{const s=[],l=(e,c)=>c==n(r)?o(s,e):null===r[c]?u(e,(e=>l(e,c+1))):t([r[c],null],(t=>l(C(e,t),c+1)));return l(e,0),s})(e,s),(e=>u(e,(e=>C(k,e)[0](r,...s??[],...l))))),e=>i(C(k,e),(([,t,n])=>(f(t,n??[""],void 0,(t=>(h(t,e),a(t)?1:0))),g(k,e),d(e),n))),(e,o,s)=>i(C(k,e),(([e,,l=[]])=>{const i=(...d)=>{const a=n(d);a==n(l)?e(r,...d,...s(d)):c(l[a])?t(o[a](...d),(e=>i(...d,e))):i(...d,l[a])};i()}))]},S=Object.freeze,z=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((h=>{let f,v,L,z=100,E=p(),I=1;const M=p(),b=p(),[j,x,y]=w((()=>Q)),B=p(),F=p(),O=[],T=[],W=(e,t)=>{I=0,h.transaction((()=>u(C(B,t),((t,n)=>u(t,((t,r)=>u(t,((t,o)=>((e,t,n,r,o)=>c(o)?e.delCell(t,n,r,!0):e.setCell(t,n,r,o))(h,n,r,o,t[e]))))))))),I=1},$=e=>{g(B,e),g(F,e),x(b,[e])},m=(e,r)=>t(((e,t)=>e.splice(0,t))(e,r??n(e)),$),q=()=>m(O,n(O)-z),A=h.addCellListener(null,null,null,((e,t,n,r,l,c)=>{if(I){i(f,(()=>{o(O,f),q(),m(T),f=void 0,L=1}));const e=k(E,t,p),d=k(e,n,p),u=k(d,r,(()=>[c,void 0]));u[1]=l,u[0]===l&&a(g(d,r))&&a(g(e,n))&&a(g(E,t))&&(f=s(O),L=1),J()}})),D=(e="")=>(c(f)&&(f=""+v++,g(B,f,E),N(f,e),E=p(),L=1),f),G=()=>{r(O)||(T.unshift(D()),W(0,f),f=s(O),L=1)},H=()=>{r(T)||(o(O,f),f=l(T),W(1,f),L=1)},J=()=>{L&&(x(M),L=0)},K=e=>{const t=D(e);return J(),t},N=(e,t)=>(P(e)&&C(F,e)!==t&&(g(F,e,t),x(b,[e])),Q),P=e=>d(B,e),Q={setSize:e=>(z=e,q(),Q),addCheckpoint:K,setCheckpoint:N,getStore:()=>h,getCheckpointIds:()=>[[...O],f,[...T]],forEachCheckpoint:e=>{return t=e,u(F,((e,n)=>t(n,e)));var t},hasCheckpoint:P,getCheckpoint:e=>C(F,e),goBackward:()=>(G(),J(),Q),goForward:()=>(H(),J(),Q),goTo:t=>{const n=e(O,t)?G:e(T,t)?H:null;for(;!c(n)&&t!=f;)n();return J(),Q},addCheckpointIdsListener:e=>j(e,M),addCheckpointListener:(e,t)=>j(t,b,[e]),delListener:e=>(y(e),Q),clear:()=>(m(O),m(T),c(f)||$(f),f=void 0,v=0,K(),Q),destroy:()=>{h.delListener(A)},getListenerStats:()=>({})};return S(Q.clear())}));export{z as createCheckpoints};
1
+ const e=(e,t)=>e.includes(t),t=(e,t)=>e.forEach(t),n=e=>e.length,r=e=>0==n(e),s=(e,...t)=>e.push(...t),o=e=>e.pop(),l=e=>e.shift(),c=e=>null==e,i=(e,t,n)=>c(e)?n?.():t(e),a=(e,t)=>e?.has(t)??!1,d=e=>c(e)||0==(e=>e.size)(e),u=(e,t)=>e?.forEach(t),h=(e,t)=>e?.delete(t),p=e=>new Map(e),C=(e,t)=>e?.get(t),g=(e,t,n)=>c(n)?(h(e,t),e):e?.set(t,n),k=(e,t,n)=>(a(e,t)||g(e,t,n()),C(e,t)),f=(e,t,r,s,o=0)=>i((r?k:C)(e,t[o],o>n(t)-2?r:p),(l=>{if(o>n(t)-2)return s?.(l)&&g(e,t[o]),l;const c=f(l,t,r,s,o+1);return d(l)&&g(e,t[o]),c})),v=e=>new Set(Array.isArray(e)||c(e)?e:[e]),L=/^\d+$/,w=e=>{let r;const[o,a]=(()=>{const e=[];let t=0;return[()=>l(e)??""+t++,t=>{L.test(t)&&n(e)<1e3&&s(e,t)}]})(),k=p();return[(t,n,s)=>{r??=e();const l=o();var c,i;return g(k,l,[t,n,s]),c=f(n,s??[""],v),i=l,c?.add(i),l},(e,o,...l)=>t(((e,r=[""])=>{const o=[],l=(e,c)=>c==n(r)?s(o,e):null===r[c]?u(e,(e=>l(e,c+1))):t([r[c],null],(t=>l(C(e,t),c+1)));return l(e,0),o})(e,o),(e=>u(e,(e=>C(k,e)[0](r,...o??[],...l))))),e=>i(C(k,e),(([,t,n])=>(f(t,n??[""],void 0,(t=>(h(t,e),d(t)?1:0))),g(k,e),a(e),n))),(e,s,o)=>i(C(k,e),(([e,,l=[]])=>{const i=(...a)=>{const d=n(a);d==n(l)?e(r,...a,...o(a)):c(l[d])?t(s[d](...a),(e=>i(...a,e))):i(...a,l[d])};i()}))]},S=Object.freeze,y=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((h=>{let f,v,L,y=100,z=p(),E=1;const A=p(),I=p(),[M,b,j]=w((()=>Q)),x=p(),B=p(),F=[],O=[],T=(e,t)=>{E=0,h.transaction((()=>u(C(x,t),((t,n)=>u(t,((t,r)=>u(t,((t,s)=>((e,t,n,r,s)=>c(s)?e.delCell(t,n,r,!0):e.setCell(t,n,r,s))(h,n,r,s,t[e]))))))))),E=1},W=e=>{g(x,e),g(B,e),b(I,[e])},$=(e,r)=>t(((e,t)=>e.splice(0,t))(e,r??n(e)),W),m=()=>$(F,n(F)-y),q=h.addCellListener(null,null,null,((e,t,n,r,l,c)=>{if(E){i(f,(()=>{s(F,f),m(),$(O),f=void 0,L=1}));const e=k(z,t,p),a=k(e,n,p),u=k(a,r,(()=>[c,void 0]));u[1]=l,u[0]===l&&d(g(a,r))&&d(g(e,n))&&d(g(z,t))&&(f=o(F),L=1),J()}})),D=(e="")=>(c(f)&&(f=""+v++,g(x,f,z),N(f,e),z=p(),L=1),f),G=()=>{r(F)||(O.unshift(D()),T(0,f),f=o(F),L=1)},H=()=>{r(O)||(s(F,f),f=l(O),T(1,f),L=1)},J=()=>{L&&(b(A),L=0)},K=e=>{const t=D(e);return J(),t},N=(e,t)=>(P(e)&&C(B,e)!==t&&(g(B,e,t),b(I,[e])),Q),P=e=>a(x,e),Q={setSize:e=>(y=e,m(),Q),addCheckpoint:K,setCheckpoint:N,getStore:()=>h,getCheckpointIds:()=>[[...F],f,[...O]],forEachCheckpoint:e=>{return t=e,u(B,((e,n)=>t(n,e)));var t},hasCheckpoint:P,getCheckpoint:e=>C(B,e),goBackward:()=>(G(),J(),Q),goForward:()=>(H(),J(),Q),goTo:t=>{const n=e(F,t)?G:e(O,t)?H:null;for(;!c(n)&&t!=f;)n();return J(),Q},addCheckpointIdsListener:e=>M(e,A),addCheckpointListener:(e,t)=>M(t,I,[e]),delListener:e=>(j(e),Q),clear:()=>($(F),$(O),c(f)||W(f),f=void 0,v=0,K(),Q),destroy:()=>{h.delListener(q)},getListenerStats:()=>({})};return S(Q.clear())}));export{y as createCheckpoints};
Binary file
@@ -13,6 +13,7 @@ const arrayShift = (array) => array.shift();
13
13
  const isUndefined = (thing) => thing == void 0;
14
14
  const ifNotUndefined = (value, then, otherwise) =>
15
15
  isUndefined(value) ? otherwise?.() : then(value);
16
+ const isArray = (thing) => Array.isArray(thing);
16
17
 
17
18
  const collSizeN = (collSizer) => (coll) =>
18
19
  arrayReduce(collValues(coll), (total, coll2) => total + collSizer(coll2), 0);
@@ -58,7 +59,12 @@ const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
58
59
  },
59
60
  );
60
61
 
61
- const setNew = (entries) => new Set(entries);
62
+ const setNew = (entryOrEntries) =>
63
+ new Set(
64
+ isArray(entryOrEntries) || isUndefined(entryOrEntries)
65
+ ? entryOrEntries
66
+ : [entryOrEntries],
67
+ );
62
68
  const setAdd = (set, value) => set?.add(value);
63
69
 
64
70
  const getCreateFunction = (getFunction) => {
@@ -1,6 +1,6 @@
1
1
  /**
2
- * The indexes module of the TinyBase project provides the ability to create
3
- * and track indexes of the data in Store objects.
2
+ * The indexes module of the TinyBase project provides the ability to create and
3
+ * track indexes of the data in Store objects.
4
4
  *
5
5
  * The main entry point to this module is the createIndexes function, which
6
6
  * returns a new Indexes object. From there, you can create new Index
@@ -192,6 +192,7 @@ export type IndexesListenerStats = {
192
192
  * @see Rolling Dice demos
193
193
  * @see Country demo
194
194
  * @see Todo App demos
195
+ * @see Word Frequencies demo
195
196
  * @category Indexes
196
197
  */
197
198
  export interface Indexes {
@@ -209,11 +210,12 @@ export interface Indexes {
209
210
  * derived string value in common, as described by this method. Those values
210
211
  * are used as the key for each Slice in the overall Index object.
211
212
  *
212
- * Without the third `getSliceId` parameter, the Index will simply have a
213
+ * Without the third `getSliceIdOrIds` parameter, the Index will simply have a
213
214
  * single Slice, keyed by an empty string. But more often you will specify a
214
215
  * Cell value containing the Slice Id that the Row should belong to.
215
216
  * Alternatively, a custom function can be provided that produces your own
216
- * Slice Id from the local Row as a whole.
217
+ * Slice Id from the local Row as a whole. Since v2.1, the custom function can
218
+ * return an array of Slice Ids, each of which the Row will then belong to.
217
219
  *
218
220
  * The fourth `getSortKey` parameter specifies a Cell Id to get a value (or a
219
221
  * function that processes a whole Row to get a value) that is used to sort
@@ -241,11 +243,13 @@ export interface Indexes {
241
243
  *
242
244
  * @param indexId The Id of the Index to define.
243
245
  * @param tableId The Id of the Table the Index will be generated from.
244
- * @param getSliceId Either the Id of the Cell containing, or a function that
245
- * produces, the Id that is used to indicate which Slice in the Index the Row
246
- * Id should be in. Defaults to a function that returns `''` (meaning that if
247
- * this `getSliceId` parameter is omitted, the Index will simply contain a
248
- * single Slice containing all the Row Ids in the Table).
246
+ * @param getSliceIdOrIds Either the Id of the Cell containing, or a function
247
+ * that produces, the Id that is used to indicate which Slice in the Index the
248
+ * Row Id should be in. Defaults to a function that returns `''` (meaning that
249
+ * if this `getSliceIdOrIds` parameter is omitted, the Index will simply
250
+ * contain a single Slice containing all the Row Ids in the Table). Since
251
+ * v2.1, this can return an array of Slice Ids, each of which the Row will
252
+ * then belong to.
249
253
  * @param getSortKey Either the Id of the Cell containing, or a function that
250
254
  * produces, the value that is used to sort the Row Ids in each Slice.
251
255
  * @param sliceIdSorter A function that takes two Slice Id values and returns
@@ -294,6 +298,29 @@ export interface Indexes {
294
298
  * ```
295
299
  * @example
296
300
  * This example creates a Store, creates an Indexes object, and defines an
301
+ * Index based on each of the letters present in the pets' names.
302
+ *
303
+ * ```js
304
+ * const store = createStore().setTable('pets', {
305
+ * fido: {species: 'dog'},
306
+ * felix: {species: 'cat'},
307
+ * rex: {species: 'dog'},
308
+ * });
309
+ *
310
+ * const indexes = createIndexes(store);
311
+ * indexes.setIndexDefinition('containsLetter', 'pets', (_, rowId) =>
312
+ * rowId.split(''),
313
+ * );
314
+ *
315
+ * console.log(indexes.getSliceIds('containsLetter'));
316
+ * // -> ['f', 'i', 'd', 'o', 'e', 'l', 'x', 'r']
317
+ * console.log(indexes.getSliceRowIds('containsLetter', 'i'));
318
+ * // -> ['fido', 'felix']
319
+ * console.log(indexes.getSliceRowIds('containsLetter', 'x'));
320
+ * // -> ['felix', 'rex']
321
+ * ```
322
+ * @example
323
+ * This example creates a Store, creates an Indexes object, and defines an
297
324
  * Index based on the first letter of the pets' names. The Slice Ids (and Row
298
325
  * Ids within them) are alphabetically sorted.
299
326
  *
@@ -324,7 +351,7 @@ export interface Indexes {
324
351
  setIndexDefinition(
325
352
  indexId: Id,
326
353
  tableId: Id,
327
- getSliceId?: Id | ((getCell: GetCell, rowId: Id) => Id),
354
+ getSliceIdOrIds?: Id | ((getCell: GetCell, rowId: Id) => Id | Ids),
328
355
  getSortKey?: Id | ((getCell: GetCell, rowId: Id) => SortKey),
329
356
  sliceIdSorter?: (sliceId1: Id, sliceId2: Id) => number,
330
357
  rowIdSorter?: (sortKey1: SortKey, sortKey2: SortKey, sliceId: Id) => number,
@@ -1,8 +1,12 @@
1
1
  const getTypeOf = (thing) => typeof thing;
2
2
  const EMPTY_STRING = '';
3
3
  const STRING = getTypeOf(EMPTY_STRING);
4
+ const id = (key) => EMPTY_STRING + key;
4
5
 
5
6
  const arrayEvery = (array, cb) => array.every(cb);
7
+ const arrayIsEqual = (array1, array2) =>
8
+ arrayLength(array1) === arrayLength(array2) &&
9
+ arrayEvery(array1, (value1, index) => array2[index] === value1);
6
10
  const arrayIsSorted = (array, sorter) =>
7
11
  arrayEvery(
8
12
  array,
@@ -10,6 +14,7 @@ const arrayIsSorted = (array, sorter) =>
10
14
  );
11
15
  const arraySort = (array, sorter) => array.sort(sorter);
12
16
  const arrayForEach = (array, cb) => array.forEach(cb);
17
+ const arrayMap = (array, cb) => array.map(cb);
13
18
  const arrayLength = (array) => array.length;
14
19
  const arrayIsEmpty = (array) => arrayLength(array) == 0;
15
20
  const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
@@ -20,6 +25,7 @@ const isUndefined = (thing) => thing == void 0;
20
25
  const ifNotUndefined = (value, then, otherwise) =>
21
26
  isUndefined(value) ? otherwise?.() : then(value);
22
27
  const isString = (thing) => getTypeOf(thing) == STRING;
28
+ const isArray = (thing) => Array.isArray(thing);
23
29
 
24
30
  const collSizeN = (collSizer) => (coll) =>
25
31
  arrayReduce(collValues(coll), (total, coll2) => total + collSizer(coll2), 0);
@@ -68,7 +74,12 @@ const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
68
74
  },
69
75
  );
70
76
 
71
- const setNew = (entries) => new Set(entries);
77
+ const setNew = (entryOrEntries) =>
78
+ new Set(
79
+ isArray(entryOrEntries) || isUndefined(entryOrEntries)
80
+ ? entryOrEntries
81
+ : [entryOrEntries],
82
+ );
72
83
  const setAdd = (set, value) => set?.add(value);
73
84
 
74
85
  const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
@@ -133,7 +144,14 @@ const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
133
144
  const newRowValue = hasRow(tableId, rowId)
134
145
  ? validateRowValue(getRowValue(getCell, rowId))
135
146
  : void 0;
136
- if (oldRowValue != newRowValue) {
147
+ if (
148
+ !(
149
+ oldRowValue === newRowValue ||
150
+ (isArray(oldRowValue) &&
151
+ isArray(newRowValue) &&
152
+ arrayIsEqual(oldRowValue, newRowValue))
153
+ )
154
+ ) {
137
155
  mapSet(changedRowValues, rowId, [oldRowValue, newRowValue]);
138
156
  }
139
157
  if (!isUndefined(getSortKey)) {
@@ -312,7 +330,11 @@ const createIndexes = getCreateFunction((store) => {
312
330
  delDefinition,
313
331
  destroy,
314
332
  ] = getDefinableFunctions(store, mapNew, (value) =>
315
- isUndefined(value) ? EMPTY_STRING : value + EMPTY_STRING,
333
+ isUndefined(value)
334
+ ? EMPTY_STRING
335
+ : isArray(value)
336
+ ? arrayMap(value, id)
337
+ : id(value),
316
338
  );
317
339
  const [addListener, callListeners, delListenerImpl] = getListenerFunctions(
318
340
  () => indexes,
@@ -321,7 +343,7 @@ const createIndexes = getCreateFunction((store) => {
321
343
  const setIndexDefinition = (
322
344
  indexId,
323
345
  tableId,
324
- getSliceId,
346
+ getSliceIdOrIds,
325
347
  getSortKey,
326
348
  sliceIdSorter,
327
349
  rowIdSorter = defaultSorter,
@@ -337,29 +359,39 @@ const createIndexes = getCreateFunction((store) => {
337
359
  const changedSlices = setNew();
338
360
  const unsortedSlices = setNew();
339
361
  const index = getIndex(indexId);
340
- collForEach(changedSliceIds, ([oldSliceId, newSliceId], rowId) => {
341
- if (!isUndefined(oldSliceId)) {
342
- setAdd(changedSlices, oldSliceId);
343
- ifNotUndefined(mapGet(index, oldSliceId), (oldSlice) => {
344
- collDel(oldSlice, rowId);
345
- if (collIsEmpty(oldSlice)) {
346
- mapSet(index, oldSliceId);
362
+ collForEach(
363
+ changedSliceIds,
364
+ ([oldSliceIdOrIds, newSliceIdOrIds], rowId) => {
365
+ const oldSliceIds = setNew(oldSliceIdOrIds);
366
+ const newSliceIds = setNew(newSliceIdOrIds);
367
+ collForEach(oldSliceIds, (oldSliceId) =>
368
+ collDel(newSliceIds, oldSliceId)
369
+ ? collDel(oldSliceIds, oldSliceId)
370
+ : 0,
371
+ );
372
+ collForEach(oldSliceIds, (oldSliceId) => {
373
+ setAdd(changedSlices, oldSliceId);
374
+ ifNotUndefined(mapGet(index, oldSliceId), (oldSlice) => {
375
+ collDel(oldSlice, rowId);
376
+ if (collIsEmpty(oldSlice)) {
377
+ mapSet(index, oldSliceId);
378
+ sliceIdsChanged = 1;
379
+ }
380
+ });
381
+ });
382
+ collForEach(newSliceIds, (newSliceId) => {
383
+ setAdd(changedSlices, newSliceId);
384
+ if (!collHas(index, newSliceId)) {
385
+ mapSet(index, newSliceId, setNew());
347
386
  sliceIdsChanged = 1;
348
387
  }
388
+ setAdd(mapGet(index, newSliceId), rowId);
389
+ if (!isUndefined(getSortKey)) {
390
+ setAdd(unsortedSlices, newSliceId);
391
+ }
349
392
  });
350
- }
351
- if (!isUndefined(newSliceId)) {
352
- setAdd(changedSlices, newSliceId);
353
- if (!collHas(index, newSliceId)) {
354
- mapSet(index, newSliceId, setNew());
355
- sliceIdsChanged = 1;
356
- }
357
- setAdd(mapGet(index, newSliceId), rowId);
358
- if (!isUndefined(getSortKey)) {
359
- setAdd(unsortedSlices, newSliceId);
360
- }
361
- }
362
- });
393
+ },
394
+ );
363
395
  change();
364
396
  if (!collIsEmpty(sortKeys)) {
365
397
  if (force) {
@@ -408,7 +440,7 @@ const createIndexes = getCreateFunction((store) => {
408
440
  callListeners(sliceRowIdsListeners, [indexId, sliceId]),
409
441
  );
410
442
  },
411
- getRowCellFunction(getSliceId),
443
+ getRowCellFunction(getSliceIdOrIds),
412
444
  ifNotUndefined(getSortKey, getRowCellFunction),
413
445
  );
414
446
  return indexes;
@@ -7,6 +7,10 @@ const AVG = 'avg';
7
7
  const MIN = 'min';
8
8
  const MAX = 'max';
9
9
 
10
+ const arrayEvery = (array, cb) => array.every(cb);
11
+ const arrayIsEqual = (array1, array2) =>
12
+ arrayLength(array1) === arrayLength(array2) &&
13
+ arrayEvery(array1, (value1, index) => array2[index] === value1);
10
14
  const arrayForEach = (array, cb) => array.forEach(cb);
11
15
  const arraySum = (array) => arrayReduce(array, (i, j) => i + j, 0);
12
16
  const arrayLength = (array) => array.length;
@@ -23,6 +27,7 @@ const ifNotUndefined = (value, then, otherwise) =>
23
27
  isUndefined(value) ? otherwise?.() : then(value);
24
28
  const isString = (thing) => getTypeOf(thing) == STRING;
25
29
  const isFunction = (thing) => getTypeOf(thing) == FUNCTION;
30
+ const isArray = (thing) => Array.isArray(thing);
26
31
  const getUndefined = () => void 0;
27
32
 
28
33
  const collSizeN = (collSizer) => (coll) =>
@@ -140,7 +145,12 @@ const getAggregateValue = (
140
145
  : aggregateValue;
141
146
  };
142
147
 
143
- const setNew = (entries) => new Set(entries);
148
+ const setNew = (entryOrEntries) =>
149
+ new Set(
150
+ isArray(entryOrEntries) || isUndefined(entryOrEntries)
151
+ ? entryOrEntries
152
+ : [entryOrEntries],
153
+ );
144
154
  const setAdd = (set, value) => set?.add(value);
145
155
 
146
156
  const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
@@ -205,7 +215,14 @@ const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
205
215
  const newRowValue = hasRow(tableId, rowId)
206
216
  ? validateRowValue(getRowValue(getCell, rowId))
207
217
  : void 0;
208
- if (oldRowValue != newRowValue) {
218
+ if (
219
+ !(
220
+ oldRowValue === newRowValue ||
221
+ (isArray(oldRowValue) &&
222
+ isArray(newRowValue) &&
223
+ arrayIsEqual(oldRowValue, newRowValue))
224
+ )
225
+ ) {
209
226
  mapSet(changedRowValues, rowId, [oldRowValue, newRowValue]);
210
227
  }
211
228
  if (!isUndefined(getSortKey)) {
@@ -20,6 +20,9 @@ const CELL_IDS = 'CellIds';
20
20
  const CELL = 'Cell';
21
21
 
22
22
  const arrayEvery = (array, cb) => array.every(cb);
23
+ const arrayIsEqual = (array1, array2) =>
24
+ arrayLength(array1) === arrayLength(array2) &&
25
+ arrayEvery(array1, (value1, index) => array2[index] === value1);
23
26
  const arrayForEach = (array, cb) => array.forEach(cb);
24
27
  const arraySum = (array) => arrayReduce(array, (i, j) => i + j, 0);
25
28
  const arrayLength = (array) => array.length;
@@ -36,6 +39,7 @@ const ifNotUndefined = (value, then, otherwise) =>
36
39
  isUndefined(value) ? otherwise?.() : then(value);
37
40
  const isTypeStringOrBoolean = (type) => type == STRING || type == BOOLEAN;
38
41
  const isFunction = (thing) => getTypeOf(thing) == FUNCTION;
42
+ const isArray = (thing) => Array.isArray(thing);
39
43
  const getUndefined = () => void 0;
40
44
 
41
45
  const collSize = (coll) => coll.size;
@@ -81,7 +85,12 @@ const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
81
85
  },
82
86
  );
83
87
 
84
- const setNew = (entries) => new Set(entries);
88
+ const setNew = (entryOrEntries) =>
89
+ new Set(
90
+ isArray(entryOrEntries) || isUndefined(entryOrEntries)
91
+ ? entryOrEntries
92
+ : [entryOrEntries],
93
+ );
85
94
  const setAdd = (set, value) => set?.add(value);
86
95
 
87
96
  const numericAggregators = mapNew([
@@ -226,7 +235,14 @@ const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
226
235
  const newRowValue = hasRow(tableId, rowId)
227
236
  ? validateRowValue(getRowValue(getCell, rowId))
228
237
  : void 0;
229
- if (oldRowValue != newRowValue) {
238
+ if (
239
+ !(
240
+ oldRowValue === newRowValue ||
241
+ (isArray(oldRowValue) &&
242
+ isArray(newRowValue) &&
243
+ arrayIsEqual(oldRowValue, newRowValue))
244
+ )
245
+ ) {
230
246
  mapSet(changedRowValues, rowId, [oldRowValue, newRowValue]);
231
247
  }
232
248
  if (!isUndefined(getSortKey)) {
@@ -2,6 +2,10 @@ const getTypeOf = (thing) => typeof thing;
2
2
  const EMPTY_STRING = '';
3
3
  const STRING = getTypeOf(EMPTY_STRING);
4
4
 
5
+ const arrayEvery = (array, cb) => array.every(cb);
6
+ const arrayIsEqual = (array1, array2) =>
7
+ arrayLength(array1) === arrayLength(array2) &&
8
+ arrayEvery(array1, (value1, index) => array2[index] === value1);
5
9
  const arrayForEach = (array, cb) => array.forEach(cb);
6
10
  const arrayLength = (array) => array.length;
7
11
  const arrayIsEmpty = (array) => arrayLength(array) == 0;
@@ -13,6 +17,7 @@ const isUndefined = (thing) => thing == void 0;
13
17
  const ifNotUndefined = (value, then, otherwise) =>
14
18
  isUndefined(value) ? otherwise?.() : then(value);
15
19
  const isString = (thing) => getTypeOf(thing) == STRING;
20
+ const isArray = (thing) => Array.isArray(thing);
16
21
 
17
22
  const collSizeN = (collSizer) => (coll) =>
18
23
  arrayReduce(collValues(coll), (total, coll2) => total + collSizer(coll2), 0);
@@ -61,7 +66,12 @@ const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
61
66
  },
62
67
  );
63
68
 
64
- const setNew = (entries) => new Set(entries);
69
+ const setNew = (entryOrEntries) =>
70
+ new Set(
71
+ isArray(entryOrEntries) || isUndefined(entryOrEntries)
72
+ ? entryOrEntries
73
+ : [entryOrEntries],
74
+ );
65
75
  const setAdd = (set, value) => set?.add(value);
66
76
 
67
77
  const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
@@ -126,7 +136,14 @@ const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
126
136
  const newRowValue = hasRow(tableId, rowId)
127
137
  ? validateRowValue(getRowValue(getCell, rowId))
128
138
  : void 0;
129
- if (oldRowValue != newRowValue) {
139
+ if (
140
+ !(
141
+ oldRowValue === newRowValue ||
142
+ (isArray(oldRowValue) &&
143
+ isArray(newRowValue) &&
144
+ arrayIsEqual(oldRowValue, newRowValue))
145
+ )
146
+ ) {
130
147
  mapSet(changedRowValues, rowId, [oldRowValue, newRowValue]);
131
148
  }
132
149
  if (!isUndefined(getSortKey)) {
@@ -55,6 +55,7 @@ const ifNotUndefined = (value, then, otherwise) =>
55
55
  isUndefined(value) ? otherwise?.() : then(value);
56
56
  const isTypeStringOrBoolean = (type) => type == STRING || type == BOOLEAN;
57
57
  const isFunction = (thing) => getTypeOf(thing) == FUNCTION;
58
+ const isArray = (thing) => Array.isArray(thing);
58
59
 
59
60
  const collSizeN = (collSizer) => (coll) =>
60
61
  arrayReduce(collValues(coll), (total, coll2) => total + collSizer(coll2), 0);
@@ -134,7 +135,12 @@ const objForEach = (obj, cb) =>
134
135
  arrayForEach(object.entries(obj), ([id, value]) => cb(value, id));
135
136
  const objIsEmpty = (obj) => arrayIsEmpty(objIds(obj));
136
137
 
137
- const setNew = (entries) => new Set(entries);
138
+ const setNew = (entryOrEntries) =>
139
+ new Set(
140
+ isArray(entryOrEntries) || isUndefined(entryOrEntries)
141
+ ? entryOrEntries
142
+ : [entryOrEntries],
143
+ );
138
144
  const setAdd = (set, value) => set?.add(value);
139
145
 
140
146
  const INTEGER = /^\d+$/;
@@ -76,6 +76,7 @@ const ifNotUndefined = (value, then, otherwise) =>
76
76
  const isTypeStringOrBoolean = (type) => type == STRING || type == BOOLEAN;
77
77
  const isString = (thing) => getTypeOf(thing) == STRING;
78
78
  const isFunction = (thing) => getTypeOf(thing) == FUNCTION;
79
+ const isArray = (thing) => Array.isArray(thing);
79
80
  const getUndefined = () => void 0;
80
81
 
81
82
  const collSizeN = (collSizer) => (coll) =>
@@ -143,7 +144,12 @@ const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
143
144
  },
144
145
  );
145
146
 
146
- const setNew = (entries) => new Set(entries);
147
+ const setNew = (entryOrEntries) =>
148
+ new Set(
149
+ isArray(entryOrEntries) || isUndefined(entryOrEntries)
150
+ ? entryOrEntries
151
+ : [entryOrEntries],
152
+ );
147
153
  const setAdd = (set, value) => set?.add(value);
148
154
 
149
155
  const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
@@ -208,7 +214,14 @@ const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
208
214
  const newRowValue = hasRow(tableId, rowId)
209
215
  ? validateRowValue(getRowValue(getCell, rowId))
210
216
  : void 0;
211
- if (oldRowValue != newRowValue) {
217
+ if (
218
+ !(
219
+ oldRowValue === newRowValue ||
220
+ (isArray(oldRowValue) &&
221
+ isArray(newRowValue) &&
222
+ arrayIsEqual(oldRowValue, newRowValue))
223
+ )
224
+ ) {
212
225
  mapSet(changedRowValues, rowId, [oldRowValue, newRowValue]);
213
226
  }
214
227
  if (!isUndefined(getSortKey)) {
@@ -605,7 +618,11 @@ const createIndexes = getCreateFunction((store) => {
605
618
  delDefinition,
606
619
  destroy,
607
620
  ] = getDefinableFunctions(store, mapNew, (value) =>
608
- isUndefined(value) ? EMPTY_STRING : value + EMPTY_STRING,
621
+ isUndefined(value)
622
+ ? EMPTY_STRING
623
+ : isArray(value)
624
+ ? arrayMap(value, id)
625
+ : id(value),
609
626
  );
610
627
  const [addListener, callListeners, delListenerImpl] = getListenerFunctions(
611
628
  () => indexes,
@@ -614,7 +631,7 @@ const createIndexes = getCreateFunction((store) => {
614
631
  const setIndexDefinition = (
615
632
  indexId,
616
633
  tableId,
617
- getSliceId,
634
+ getSliceIdOrIds,
618
635
  getSortKey,
619
636
  sliceIdSorter,
620
637
  rowIdSorter = defaultSorter,
@@ -630,29 +647,39 @@ const createIndexes = getCreateFunction((store) => {
630
647
  const changedSlices = setNew();
631
648
  const unsortedSlices = setNew();
632
649
  const index = getIndex(indexId);
633
- collForEach(changedSliceIds, ([oldSliceId, newSliceId], rowId) => {
634
- if (!isUndefined(oldSliceId)) {
635
- setAdd(changedSlices, oldSliceId);
636
- ifNotUndefined(mapGet(index, oldSliceId), (oldSlice) => {
637
- collDel(oldSlice, rowId);
638
- if (collIsEmpty(oldSlice)) {
639
- mapSet(index, oldSliceId);
650
+ collForEach(
651
+ changedSliceIds,
652
+ ([oldSliceIdOrIds, newSliceIdOrIds], rowId) => {
653
+ const oldSliceIds = setNew(oldSliceIdOrIds);
654
+ const newSliceIds = setNew(newSliceIdOrIds);
655
+ collForEach(oldSliceIds, (oldSliceId) =>
656
+ collDel(newSliceIds, oldSliceId)
657
+ ? collDel(oldSliceIds, oldSliceId)
658
+ : 0,
659
+ );
660
+ collForEach(oldSliceIds, (oldSliceId) => {
661
+ setAdd(changedSlices, oldSliceId);
662
+ ifNotUndefined(mapGet(index, oldSliceId), (oldSlice) => {
663
+ collDel(oldSlice, rowId);
664
+ if (collIsEmpty(oldSlice)) {
665
+ mapSet(index, oldSliceId);
666
+ sliceIdsChanged = 1;
667
+ }
668
+ });
669
+ });
670
+ collForEach(newSliceIds, (newSliceId) => {
671
+ setAdd(changedSlices, newSliceId);
672
+ if (!collHas(index, newSliceId)) {
673
+ mapSet(index, newSliceId, setNew());
640
674
  sliceIdsChanged = 1;
641
675
  }
676
+ setAdd(mapGet(index, newSliceId), rowId);
677
+ if (!isUndefined(getSortKey)) {
678
+ setAdd(unsortedSlices, newSliceId);
679
+ }
642
680
  });
643
- }
644
- if (!isUndefined(newSliceId)) {
645
- setAdd(changedSlices, newSliceId);
646
- if (!collHas(index, newSliceId)) {
647
- mapSet(index, newSliceId, setNew());
648
- sliceIdsChanged = 1;
649
- }
650
- setAdd(mapGet(index, newSliceId), rowId);
651
- if (!isUndefined(getSortKey)) {
652
- setAdd(unsortedSlices, newSliceId);
653
- }
654
- }
655
- });
681
+ },
682
+ );
656
683
  change();
657
684
  if (!collIsEmpty(sortKeys)) {
658
685
  if (force) {
@@ -701,7 +728,7 @@ const createIndexes = getCreateFunction((store) => {
701
728
  callListeners(sliceRowIdsListeners, [indexId, sliceId]),
702
729
  );
703
730
  },
704
- getRowCellFunction(getSliceId),
731
+ getRowCellFunction(getSliceIdOrIds),
705
732
  ifNotUndefined(getSortKey, getRowCellFunction),
706
733
  );
707
734
  return indexes;
@@ -23,6 +23,7 @@ const isUndefined = (thing) => thing == void 0;
23
23
  const ifNotUndefined = (value, then, otherwise) =>
24
24
  isUndefined(value) ? otherwise?.() : then(value);
25
25
  const isString = (thing) => getTypeOf(thing) == STRING;
26
+ const isArray = (thing) => Array.isArray(thing);
26
27
  const getUndefined = () => void 0;
27
28
 
28
29
  const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
@@ -1012,7 +1013,7 @@ const Provider = ({
1012
1013
  };
1013
1014
  const wrap = (children, separator, encloseWithId, id) => {
1014
1015
  const separatedChildren =
1015
- isUndefined(separator) || !Array.isArray(children)
1016
+ isUndefined(separator) || !isArray(children)
1016
1017
  ? children
1017
1018
  : arrayMap(children, (child, c) => (c > 0 ? [separator, child] : child));
1018
1019
  return encloseWithId ? [id, ':{', separatedChildren, '}'] : separatedChildren;
@@ -1 +1 @@
1
- const e=(e,n)=>e.includes(n),n=(e,n)=>e.forEach(n),t=e=>e.length,l=e=>0==t(e),r=(e,...n)=>e.push(...n),o=e=>e.pop(),s=e=>e.shift(),u=e=>null==e,i=(e,n,t)=>u(e)?null==t?void 0:t():n(e),d=(e,n)=>{var t;return null!=(t=null==e?void 0:e.has(n))&&t},c=e=>u(e)||0==(e=>e.size)(e),a=(e,n)=>null==e?void 0:e.forEach(n),h=(e,n)=>null==e?void 0:e.delete(n),p=e=>new Map(e),v=(e,n)=>null==e?void 0:e.get(n),C=(e,n,t)=>u(t)?(h(e,n),e):null==e?void 0:e.set(n,t),g=(e,n,t)=>(d(e,n)||C(e,n,t()),v(e,n)),k=(e,n,l,r,o=0)=>i((l?g:v)(e,n[o],o>t(n)-2?l:p),(s=>{if(o>t(n)-2)return(null==r?void 0:r(s))&&C(e,n[o]),s;const u=k(s,n,l,r,o+1);return c(s)&&C(e,n[o]),u})),f=e=>new Set(e),L=/^\d+$/,w=e=>{let l;const[o,d]=(()=>{const e=[];let n=0;return[()=>{var t;return null!=(t=s(e))?t:""+n++},n=>{L.test(n)&&t(e)<1e3&&r(e,n)}]})(),g=p();return[(n,t,r)=>{null!=l||(l=e());const s=o();var u,i;return C(g,s,[n,t,r]),u=k(t,null!=r?r:[""],f),i=s,null==u||u.add(i),s},(e,o,...s)=>n(((e,l=[""])=>{const o=[],s=(e,u)=>u==t(l)?r(o,e):null===l[u]?a(e,(e=>s(e,u+1))):n([l[u],null],(n=>s(v(e,n),u+1)));return s(e,0),o})(e,o),(e=>a(e,(e=>v(g,e)[0](l,...null!=o?o:[],...s))))),e=>i(v(g,e),(([,n,t])=>(k(n,null!=t?t:[""],void 0,(n=>(h(n,e),c(n)?1:0))),C(g,e),d(e),t))),(e,r,o)=>i(v(g,e),(([e,,s=[]])=>{const i=(...d)=>{const c=t(d);c==t(s)?e(l,...d,...o(d)):u(s[c])?n(r[c](...d),(e=>i(...d,e))):i(...d,s[c])};i()}))]},S=Object.freeze,z=(e=>{const n=new WeakMap;return t=>(n.has(t)||n.set(t,e(t)),n.get(t))})((h=>{let k,f,L,z=100,E=p(),I=1;const M=p(),b=p(),[j,x,y]=w((()=>Q)),B=p(),F=p(),O=[],T=[],W=(e,n)=>{I=0,h.transaction((()=>a(v(B,n),((n,t)=>a(n,((n,l)=>a(n,((n,r)=>((e,n,t,l,r)=>u(r)?e.delCell(n,t,l,!0):e.setCell(n,t,l,r))(h,t,l,r,n[e]))))))))),I=1},$=e=>{C(B,e),C(F,e),x(b,[e])},m=(e,l)=>n(((e,n)=>e.splice(0,n))(e,null!=l?l:t(e)),$),q=()=>m(O,t(O)-z),A=h.addCellListener(null,null,null,((e,n,t,l,s,u)=>{if(I){i(k,(()=>{r(O,k),q(),m(T),k=void 0,L=1}));const e=g(E,n,p),d=g(e,t,p),a=g(d,l,(()=>[u,void 0]));a[1]=s,a[0]===s&&c(C(d,l))&&c(C(e,t))&&c(C(E,n))&&(k=o(O),L=1),J()}})),D=(e="")=>(u(k)&&(k=""+f++,C(B,k,E),N(k,e),E=p(),L=1),k),G=()=>{l(O)||(T.unshift(D()),W(0,k),k=o(O),L=1)},H=()=>{l(T)||(r(O,k),k=s(T),W(1,k),L=1)},J=()=>{L&&(x(M),L=0)},K=e=>{const n=D(e);return J(),n},N=(e,n)=>(P(e)&&v(F,e)!==n&&(C(F,e,n),x(b,[e])),Q),P=e=>d(B,e),Q={setSize:e=>(z=e,q(),Q),addCheckpoint:K,setCheckpoint:N,getStore:()=>h,getCheckpointIds:()=>[[...O],k,[...T]],forEachCheckpoint:e=>{return n=e,a(F,((e,t)=>n(t,e)));var n},hasCheckpoint:P,getCheckpoint:e=>v(F,e),goBackward:()=>(G(),J(),Q),goForward:()=>(H(),J(),Q),goTo:n=>{const t=e(O,n)?G:e(T,n)?H:null;for(;!u(t)&&n!=k;)t();return J(),Q},addCheckpointIdsListener:e=>j(e,M),addCheckpointListener:(e,n)=>j(n,b,[e]),delListener:e=>(y(e),Q),clear:()=>(m(O),m(T),u(k)||$(k),k=void 0,f=0,K(),Q),destroy:()=>{h.delListener(A)},getListenerStats:()=>({})};return S(Q.clear())}));export{z as createCheckpoints};
1
+ const e=(e,n)=>e.includes(n),n=(e,n)=>e.forEach(n),t=e=>e.length,l=e=>0==t(e),r=(e,...n)=>e.push(...n),o=e=>e.pop(),s=e=>e.shift(),u=e=>null==e,i=(e,n,t)=>u(e)?null==t?void 0:t():n(e),d=(e,n)=>{var t;return null!=(t=null==e?void 0:e.has(n))&&t},c=e=>u(e)||0==(e=>e.size)(e),a=(e,n)=>null==e?void 0:e.forEach(n),h=(e,n)=>null==e?void 0:e.delete(n),p=e=>new Map(e),v=(e,n)=>null==e?void 0:e.get(n),C=(e,n,t)=>u(t)?(h(e,n),e):null==e?void 0:e.set(n,t),g=(e,n,t)=>(d(e,n)||C(e,n,t()),v(e,n)),k=(e,n,l,r,o=0)=>i((l?g:v)(e,n[o],o>t(n)-2?l:p),(s=>{if(o>t(n)-2)return(null==r?void 0:r(s))&&C(e,n[o]),s;const u=k(s,n,l,r,o+1);return c(s)&&C(e,n[o]),u})),f=e=>new Set(Array.isArray(e)||u(e)?e:[e]),L=/^\d+$/,w=e=>{let l;const[o,d]=(()=>{const e=[];let n=0;return[()=>{var t;return null!=(t=s(e))?t:""+n++},n=>{L.test(n)&&t(e)<1e3&&r(e,n)}]})(),g=p();return[(n,t,r)=>{null!=l||(l=e());const s=o();var u,i;return C(g,s,[n,t,r]),u=k(t,null!=r?r:[""],f),i=s,null==u||u.add(i),s},(e,o,...s)=>n(((e,l=[""])=>{const o=[],s=(e,u)=>u==t(l)?r(o,e):null===l[u]?a(e,(e=>s(e,u+1))):n([l[u],null],(n=>s(v(e,n),u+1)));return s(e,0),o})(e,o),(e=>a(e,(e=>v(g,e)[0](l,...null!=o?o:[],...s))))),e=>i(v(g,e),(([,n,t])=>(k(n,null!=t?t:[""],void 0,(n=>(h(n,e),c(n)?1:0))),C(g,e),d(e),t))),(e,r,o)=>i(v(g,e),(([e,,s=[]])=>{const i=(...d)=>{const c=t(d);c==t(s)?e(l,...d,...o(d)):u(s[c])?n(r[c](...d),(e=>i(...d,e))):i(...d,s[c])};i()}))]},S=Object.freeze,y=(e=>{const n=new WeakMap;return t=>(n.has(t)||n.set(t,e(t)),n.get(t))})((h=>{let k,f,L,y=100,z=p(),E=1;const A=p(),I=p(),[M,b,j]=w((()=>Q)),x=p(),B=p(),F=[],O=[],T=(e,n)=>{E=0,h.transaction((()=>a(v(x,n),((n,t)=>a(n,((n,l)=>a(n,((n,r)=>((e,n,t,l,r)=>u(r)?e.delCell(n,t,l,!0):e.setCell(n,t,l,r))(h,t,l,r,n[e]))))))))),E=1},W=e=>{C(x,e),C(B,e),b(I,[e])},$=(e,l)=>n(((e,n)=>e.splice(0,n))(e,null!=l?l:t(e)),W),m=()=>$(F,t(F)-y),q=h.addCellListener(null,null,null,((e,n,t,l,s,u)=>{if(E){i(k,(()=>{r(F,k),m(),$(O),k=void 0,L=1}));const e=g(z,n,p),d=g(e,t,p),a=g(d,l,(()=>[u,void 0]));a[1]=s,a[0]===s&&c(C(d,l))&&c(C(e,t))&&c(C(z,n))&&(k=o(F),L=1),J()}})),D=(e="")=>(u(k)&&(k=""+f++,C(x,k,z),N(k,e),z=p(),L=1),k),G=()=>{l(F)||(O.unshift(D()),T(0,k),k=o(F),L=1)},H=()=>{l(O)||(r(F,k),k=s(O),T(1,k),L=1)},J=()=>{L&&(b(A),L=0)},K=e=>{const n=D(e);return J(),n},N=(e,n)=>(P(e)&&v(B,e)!==n&&(C(B,e,n),b(I,[e])),Q),P=e=>d(x,e),Q={setSize:e=>(y=e,m(),Q),addCheckpoint:K,setCheckpoint:N,getStore:()=>h,getCheckpointIds:()=>[[...F],k,[...O]],forEachCheckpoint:e=>{return n=e,a(B,((e,t)=>n(t,e)));var n},hasCheckpoint:P,getCheckpoint:e=>v(B,e),goBackward:()=>(G(),J(),Q),goForward:()=>(H(),J(),Q),goTo:n=>{const t=e(F,n)?G:e(O,n)?H:null;for(;!u(t)&&n!=k;)t();return J(),Q},addCheckpointIdsListener:e=>M(e,A),addCheckpointListener:(e,n)=>M(n,I,[e]),delListener:e=>(j(e),Q),clear:()=>($(F),$(O),u(k)||W(k),k=void 0,f=0,K(),Q),destroy:()=>{h.delListener(q)},getListenerStats:()=>({})};return S(Q.clear())}));export{y as createCheckpoints};
Binary file