tinybase 0.9.1 → 0.9.2

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 (48) hide show
  1. package/lib/checkpoints.js +1 -1
  2. package/lib/checkpoints.js.gz +0 -0
  3. package/lib/debug/checkpoints.js +1 -1
  4. package/lib/debug/indexes.js +1 -1
  5. package/lib/debug/metrics.js +1 -1
  6. package/lib/debug/persisters.js +1 -1
  7. package/lib/debug/relationships.js +1 -1
  8. package/lib/debug/store.js +1 -1
  9. package/lib/debug/tinybase.js +2 -1021
  10. package/lib/debug/{react.d.ts → ui-react.d.ts} +1 -1
  11. package/lib/debug/{react.js → ui-react.js} +4 -4
  12. package/lib/indexes.js +1 -1
  13. package/lib/indexes.js.gz +0 -0
  14. package/lib/metrics.js +1 -1
  15. package/lib/metrics.js.gz +0 -0
  16. package/lib/persisters.js +1 -1
  17. package/lib/persisters.js.gz +0 -0
  18. package/lib/relationships.js +1 -1
  19. package/lib/relationships.js.gz +0 -0
  20. package/lib/store.js +1 -1
  21. package/lib/store.js.gz +0 -0
  22. package/lib/tinybase.js +1 -1
  23. package/lib/tinybase.js.gz +0 -0
  24. package/lib/{react.d.ts → ui-react.d.ts} +1 -1
  25. package/lib/ui-react.js +1 -0
  26. package/lib/ui-react.js.gz +0 -0
  27. package/lib/umd/checkpoints.js +1 -1
  28. package/lib/umd/checkpoints.js.gz +0 -0
  29. package/lib/umd/indexes.js +1 -1
  30. package/lib/umd/indexes.js.gz +0 -0
  31. package/lib/umd/metrics.js +1 -1
  32. package/lib/umd/metrics.js.gz +0 -0
  33. package/lib/umd/persisters.js +1 -1
  34. package/lib/umd/persisters.js.gz +0 -0
  35. package/lib/umd/relationships.js +1 -1
  36. package/lib/umd/relationships.js.gz +0 -0
  37. package/lib/umd/store.js +1 -1
  38. package/lib/umd/store.js.gz +0 -0
  39. package/lib/umd/tinybase.js +1 -1
  40. package/lib/umd/tinybase.js.gz +0 -0
  41. package/lib/umd/ui-react.js +1 -0
  42. package/lib/umd/ui-react.js.gz +0 -0
  43. package/package.json +10 -5
  44. package/readme.md +4 -4
  45. package/lib/react.js +0 -1
  46. package/lib/react.js.gz +0 -0
  47. package/lib/umd/react.js +0 -1
  48. package/lib/umd/react.js.gz +0 -0
@@ -1,5 +1,4 @@
1
1
  import {promises, watch} from 'fs';
2
- import React from 'react';
3
2
 
4
3
  const getTypeOf = (thing) => typeof thing;
5
4
  const EMPTY_OBJECT = '{}';
@@ -23,7 +22,6 @@ const arrayIsSorted = (array, sorter) =>
23
22
  );
24
23
  const arraySort = (array, sorter) => array.sort(sorter);
25
24
  const arrayForEach = (array, cb) => array.forEach(cb);
26
- const arrayMap = (array, cb) => array.map(cb);
27
25
  const arraySum = (array) => arrayReduce(array, (i, j) => i + j, 0);
28
26
  const arrayLength = (array) => array.length;
29
27
  const arrayIsEmpty = (array) => arrayLength(array) == 0;
@@ -251,7 +249,7 @@ const getListenerFunctions = (getThing) => {
251
249
  const listenerPool = [];
252
250
  const allListeners = mapNew();
253
251
  const addListener = (listener, deepSet, idOrNulls = []) => {
254
- thing ?? (thing = getThing());
252
+ thing ??= getThing();
255
253
  const id = listenerPool.pop() ?? '' + nextId++;
256
254
  mapSet(allListeners, id, [listener, deepSet, idOrNulls]);
257
255
  addDeepSet(deepSet, id, idOrNulls);
@@ -861,7 +859,7 @@ const createCustomPersister = (
861
859
  };
862
860
 
863
861
  const STORAGE = 'storage';
864
- const WINDOW = window;
862
+ const WINDOW = globalThis.window;
865
863
  const getStoragePersister = (store, storageName, storage) => {
866
864
  let listener;
867
865
  const getPersisted = async () => storage.getItem(storageName);
@@ -966,951 +964,6 @@ const createRemotePersister = (
966
964
  );
967
965
  };
968
966
 
969
- const {createContext, useContext} = React ?? {};
970
- const Context = createContext?.([]);
971
- const useThing = (id, offset) => {
972
- const thingsAndThingsById = useContext(Context);
973
- return isUndefined(id)
974
- ? thingsAndThingsById[offset]
975
- : objGet(thingsAndThingsById[offset + 1], id);
976
- };
977
- const useThingOrThingId = (thingOrThingId, offset) => {
978
- const thing = useThing(thingOrThingId, offset);
979
- if (isUndefined(thingOrThingId) || isString(thingOrThingId)) {
980
- return thing;
981
- }
982
- return thingOrThingId;
983
- };
984
- const useStore = (id) => useThing(id, 0);
985
- const useMetrics = (id) => useThing(id, 2);
986
- const useIndexes = (id) => useThing(id, 4);
987
- const useRelationships = (id) => useThing(id, 6);
988
- const useCheckpoints = (id) => useThing(id, 8);
989
- const useStoreOrStoreId = (storeOrStoreId) =>
990
- useThingOrThingId(storeOrStoreId, 0);
991
- const useMetricsOrMetricsId = (metricsOrMetricsId) =>
992
- useThingOrThingId(metricsOrMetricsId, 2);
993
- const useIndexesOrIndexesId = (indexesOrIndexesId) =>
994
- useThingOrThingId(indexesOrIndexesId, 4);
995
- const useRelationshipsOrRelationshipsId = (relationshipsOrRelationshipsId) =>
996
- useThingOrThingId(relationshipsOrRelationshipsId, 6);
997
- const useCheckpointsOrCheckpointsId = (checkpointsOrCheckpointsId) =>
998
- useThingOrThingId(checkpointsOrCheckpointsId, 8);
999
-
1000
- const {useCallback, useEffect, useMemo: useMemo$1, useState} = React ?? {};
1001
- const useCreate = (store, create, createDeps = []) =>
1002
- useMemo$1(() => create(store), [store, ...createDeps]);
1003
- const useListenable = (listenable, thing, defaulted, ...args) => {
1004
- const getListenable = thing?.['get' + listenable] ?? (() => defaulted);
1005
- const immediateListenable = getListenable(...args);
1006
- const [, setListenable] = useState(immediateListenable);
1007
- useEffect(() => {
1008
- const listenerId = thing?.[`add${listenable}Listener`]?.(
1009
- ...args,
1010
- () => setListenable(getListenable(...args)),
1011
- false,
1012
- );
1013
- return () => thing?.delListener(listenerId);
1014
- }, [thing, listenable, setListenable, getListenable, ...args]);
1015
- return immediateListenable;
1016
- };
1017
- const useListener = (
1018
- listenable,
1019
- thing,
1020
- listener,
1021
- listenerDeps = [],
1022
- mutator,
1023
- ...args
1024
- ) => {
1025
- useEffect(() => {
1026
- const listenerId = thing?.[`add${listenable}Listener`]?.(
1027
- ...args,
1028
- listener,
1029
- mutator,
1030
- );
1031
- return () => thing?.delListener(listenerId);
1032
- }, [thing, listenable, ...listenerDeps, mutator, ...args]);
1033
- };
1034
- const useSetCallback = (
1035
- storeOrStoreId,
1036
- settable,
1037
- get,
1038
- getDeps = [],
1039
- then = getUndefined,
1040
- thenDeps = [],
1041
- ...args
1042
- ) => {
1043
- const store = useStoreOrStoreId(storeOrStoreId);
1044
- return useCallback(
1045
- (parameter) =>
1046
- ifNotUndefined(store, (store2) =>
1047
- ifNotUndefined(get(parameter, store2), (value) =>
1048
- then(store2['set' + settable](...args, value), value),
1049
- ),
1050
- ),
1051
- [store, settable, ...getDeps, ...thenDeps, ...args],
1052
- );
1053
- };
1054
- const useDel = (
1055
- storeOrStoreId,
1056
- deletable,
1057
- then = getUndefined,
1058
- thenDeps = [],
1059
- ...args
1060
- ) => {
1061
- const store = useStoreOrStoreId(storeOrStoreId);
1062
- return useCallback(
1063
- () => then(store?.['del' + deletable](...args)),
1064
- [store, deletable, ...thenDeps, ...args],
1065
- );
1066
- };
1067
- const useCheckpointAction = (checkpointsOrCheckpointsId, action, arg) => {
1068
- const checkpoints = useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId);
1069
- return useCallback(
1070
- () => checkpoints?.[action](arg),
1071
- [checkpoints, action, arg],
1072
- );
1073
- };
1074
- const useCreateStore = (create, createDeps = []) =>
1075
- useMemo$1(create, createDeps);
1076
- const useTables = (storeOrStoreId) =>
1077
- useListenable('Tables', useStoreOrStoreId(storeOrStoreId), {});
1078
- const useTableIds = (storeOrStoreId) =>
1079
- useListenable('TableIds', useStoreOrStoreId(storeOrStoreId), []);
1080
- const useTable = (tableId, storeOrStoreId) =>
1081
- useListenable('Table', useStoreOrStoreId(storeOrStoreId), {}, tableId);
1082
- const useRowIds = (tableId, storeOrStoreId) =>
1083
- useListenable('RowIds', useStoreOrStoreId(storeOrStoreId), [], tableId);
1084
- const useRow = (tableId, rowId, storeOrStoreId) =>
1085
- useListenable('Row', useStoreOrStoreId(storeOrStoreId), {}, tableId, rowId);
1086
- const useCellIds = (tableId, rowId, storeOrStoreId) =>
1087
- useListenable(
1088
- 'CellIds',
1089
- useStoreOrStoreId(storeOrStoreId),
1090
- [],
1091
- tableId,
1092
- rowId,
1093
- );
1094
- const useCell = (tableId, rowId, cellId, storeOrStoreId) =>
1095
- useListenable(
1096
- 'Cell',
1097
- useStoreOrStoreId(storeOrStoreId),
1098
- void 0,
1099
- tableId,
1100
- rowId,
1101
- cellId,
1102
- );
1103
- const useSetTablesCallback = (
1104
- getTables,
1105
- getTablesDeps,
1106
- storeOrStoreId,
1107
- then,
1108
- thenDeps,
1109
- ) =>
1110
- useSetCallback(
1111
- storeOrStoreId,
1112
- 'Tables',
1113
- getTables,
1114
- getTablesDeps,
1115
- then,
1116
- thenDeps,
1117
- );
1118
- const useSetTableCallback = (
1119
- tableId,
1120
- getTable,
1121
- getTableDeps,
1122
- storeOrStoreId,
1123
- then,
1124
- thenDeps,
1125
- ) =>
1126
- useSetCallback(
1127
- storeOrStoreId,
1128
- 'Table',
1129
- getTable,
1130
- getTableDeps,
1131
- then,
1132
- thenDeps,
1133
- tableId,
1134
- );
1135
- const useSetRowCallback = (
1136
- tableId,
1137
- rowId,
1138
- getRow,
1139
- getRowDeps,
1140
- storeOrStoreId,
1141
- then,
1142
- thenDeps,
1143
- ) =>
1144
- useSetCallback(
1145
- storeOrStoreId,
1146
- 'Row',
1147
- getRow,
1148
- getRowDeps,
1149
- then,
1150
- thenDeps,
1151
- tableId,
1152
- rowId,
1153
- );
1154
- const useAddRowCallback = (
1155
- tableId,
1156
- getRow,
1157
- getRowDeps = [],
1158
- storeOrStoreId,
1159
- then = getUndefined,
1160
- thenDeps = [],
1161
- ) => {
1162
- const store = useStoreOrStoreId(storeOrStoreId);
1163
- return useCallback(
1164
- (parameter) =>
1165
- ifNotUndefined(store, (store2) =>
1166
- ifNotUndefined(getRow(parameter, store2), (row) =>
1167
- then(store2.addRow(tableId, row), store2, row),
1168
- ),
1169
- ),
1170
- [store, tableId, ...getRowDeps, ...thenDeps],
1171
- );
1172
- };
1173
- const useSetPartialRowCallback = (
1174
- tableId,
1175
- rowId,
1176
- getPartialRow,
1177
- getPartialRowDeps,
1178
- storeOrStoreId,
1179
- then,
1180
- thenDeps,
1181
- ) =>
1182
- useSetCallback(
1183
- storeOrStoreId,
1184
- 'PartialRow',
1185
- getPartialRow,
1186
- getPartialRowDeps,
1187
- then,
1188
- thenDeps,
1189
- tableId,
1190
- rowId,
1191
- );
1192
- const useSetCellCallback = (
1193
- tableId,
1194
- rowId,
1195
- cellId,
1196
- getCell,
1197
- getCellDeps,
1198
- storeOrStoreId,
1199
- then,
1200
- thenDeps,
1201
- ) =>
1202
- useSetCallback(
1203
- storeOrStoreId,
1204
- 'Cell',
1205
- getCell,
1206
- getCellDeps,
1207
- then,
1208
- thenDeps,
1209
- tableId,
1210
- rowId,
1211
- cellId,
1212
- );
1213
- const useDelTablesCallback = (storeOrStoreId, then, thenDeps) =>
1214
- useDel(storeOrStoreId, 'Tables', then, thenDeps);
1215
- const useDelTableCallback = (tableId, storeOrStoreId, then, thenDeps) =>
1216
- useDel(storeOrStoreId, 'Table', then, thenDeps, tableId);
1217
- const useDelRowCallback = (tableId, rowId, storeOrStoreId, then, thenDeps) =>
1218
- useDel(storeOrStoreId, 'Row', then, thenDeps, tableId, rowId);
1219
- const useDelCellCallback = (
1220
- tableId,
1221
- rowId,
1222
- cellId,
1223
- forceDel,
1224
- storeOrStoreId,
1225
- then,
1226
- thenDeps,
1227
- ) =>
1228
- useDel(
1229
- storeOrStoreId,
1230
- 'Cell',
1231
- then,
1232
- thenDeps,
1233
- tableId,
1234
- rowId,
1235
- cellId,
1236
- forceDel,
1237
- );
1238
- const useTablesListener = (listener, listenerDeps, mutator, storeOrStoreId) =>
1239
- useListener(
1240
- 'Tables',
1241
- useStoreOrStoreId(storeOrStoreId),
1242
- listener,
1243
- listenerDeps,
1244
- mutator,
1245
- );
1246
- const useTableIdsListener = (listener, listenerDeps, mutator, storeOrStoreId) =>
1247
- useListener(
1248
- 'TableIds',
1249
- useStoreOrStoreId(storeOrStoreId),
1250
- listener,
1251
- listenerDeps,
1252
- mutator,
1253
- );
1254
- const useTableListener = (
1255
- tableId,
1256
- listener,
1257
- listenerDeps,
1258
- mutator,
1259
- storeOrStoreId,
1260
- ) =>
1261
- useListener(
1262
- 'Table',
1263
- useStoreOrStoreId(storeOrStoreId),
1264
- listener,
1265
- listenerDeps,
1266
- mutator,
1267
- tableId,
1268
- );
1269
- const useRowIdsListener = (
1270
- tableId,
1271
- listener,
1272
- listenerDeps,
1273
- mutator,
1274
- storeOrStoreId,
1275
- ) =>
1276
- useListener(
1277
- 'RowIds',
1278
- useStoreOrStoreId(storeOrStoreId),
1279
- listener,
1280
- listenerDeps,
1281
- mutator,
1282
- tableId,
1283
- );
1284
- const useRowListener = (
1285
- tableId,
1286
- rowId,
1287
- listener,
1288
- listenerDeps,
1289
- mutator,
1290
- storeOrStoreId,
1291
- ) =>
1292
- useListener(
1293
- 'Row',
1294
- useStoreOrStoreId(storeOrStoreId),
1295
- listener,
1296
- listenerDeps,
1297
- mutator,
1298
- tableId,
1299
- rowId,
1300
- );
1301
- const useCellIdsListener = (
1302
- tableId,
1303
- rowId,
1304
- listener,
1305
- listenerDeps,
1306
- mutator,
1307
- storeOrStoreId,
1308
- ) =>
1309
- useListener(
1310
- 'CellIds',
1311
- useStoreOrStoreId(storeOrStoreId),
1312
- listener,
1313
- listenerDeps,
1314
- mutator,
1315
- tableId,
1316
- rowId,
1317
- );
1318
- const useCellListener = (
1319
- tableId,
1320
- rowId,
1321
- cellId,
1322
- listener,
1323
- listenerDeps,
1324
- mutator,
1325
- storeOrStoreId,
1326
- ) =>
1327
- useListener(
1328
- 'Cell',
1329
- useStoreOrStoreId(storeOrStoreId),
1330
- listener,
1331
- listenerDeps,
1332
- mutator,
1333
- tableId,
1334
- rowId,
1335
- cellId,
1336
- );
1337
- const useCreateMetrics = (store, create, createDeps) =>
1338
- useCreate(store, create, createDeps);
1339
- const useMetric = (metricId, metricsOrMetricsId) =>
1340
- useListenable(
1341
- 'Metric',
1342
- useMetricsOrMetricsId(metricsOrMetricsId),
1343
- void 0,
1344
- metricId,
1345
- );
1346
- const useMetricListener = (
1347
- metricId,
1348
- listener,
1349
- listenerDeps,
1350
- metricsOrMetricsId,
1351
- ) =>
1352
- useListener(
1353
- 'Metric',
1354
- useMetricsOrMetricsId(metricsOrMetricsId),
1355
- listener,
1356
- listenerDeps,
1357
- void 0,
1358
- metricId,
1359
- );
1360
- const useCreateIndexes = (store, create, createDeps) =>
1361
- useCreate(store, create, createDeps);
1362
- const useSliceIds = (indexId, indexesOrIndexesId) =>
1363
- useListenable(
1364
- 'SliceIds',
1365
- useIndexesOrIndexesId(indexesOrIndexesId),
1366
- [],
1367
- indexId,
1368
- );
1369
- const useSliceRowIds = (indexId, sliceId, indexesOrIndexesId) =>
1370
- useListenable(
1371
- 'SliceRowIds',
1372
- useIndexesOrIndexesId(indexesOrIndexesId),
1373
- [],
1374
- indexId,
1375
- sliceId,
1376
- );
1377
- const useSliceIdsListener = (
1378
- indexId,
1379
- listener,
1380
- listenerDeps,
1381
- indexesOrIndexesId,
1382
- ) =>
1383
- useListener(
1384
- 'SliceIds',
1385
- useIndexesOrIndexesId(indexesOrIndexesId),
1386
- listener,
1387
- listenerDeps,
1388
- void 0,
1389
- indexId,
1390
- );
1391
- const useSliceRowIdsListener = (
1392
- indexId,
1393
- sliceId,
1394
- listener,
1395
- listenerDeps,
1396
- indexesOrIndexesId,
1397
- ) =>
1398
- useListener(
1399
- 'SliceRowIds',
1400
- useIndexesOrIndexesId(indexesOrIndexesId),
1401
- listener,
1402
- listenerDeps,
1403
- void 0,
1404
- indexId,
1405
- sliceId,
1406
- );
1407
- const useCreateRelationships = (store, create, createDeps) =>
1408
- useCreate(store, create, createDeps);
1409
- const useRemoteRowId = (
1410
- relationshipId,
1411
- localRowId,
1412
- relationshipsOrRelationshipsId,
1413
- ) =>
1414
- useListenable(
1415
- 'RemoteRowId',
1416
- useRelationshipsOrRelationshipsId(relationshipsOrRelationshipsId),
1417
- void 0,
1418
- relationshipId,
1419
- localRowId,
1420
- );
1421
- const useLocalRowIds = (
1422
- relationshipId,
1423
- remoteRowId,
1424
- relationshipsOrRelationshipsId,
1425
- ) =>
1426
- useListenable(
1427
- 'LocalRowIds',
1428
- useRelationshipsOrRelationshipsId(relationshipsOrRelationshipsId),
1429
- [],
1430
- relationshipId,
1431
- remoteRowId,
1432
- );
1433
- const useLinkedRowIds = (
1434
- relationshipId,
1435
- firstRowId,
1436
- relationshipsOrRelationshipsId,
1437
- ) =>
1438
- useListenable(
1439
- 'LinkedRowIds',
1440
- useRelationshipsOrRelationshipsId(relationshipsOrRelationshipsId),
1441
- [],
1442
- relationshipId,
1443
- firstRowId,
1444
- );
1445
- const useRemoteRowIdListener = (
1446
- relationshipId,
1447
- localRowId,
1448
- listener,
1449
- listenerDeps,
1450
- relationshipsOrRelationshipsId,
1451
- ) =>
1452
- useListener(
1453
- 'RemoteRowId',
1454
- useRelationshipsOrRelationshipsId(relationshipsOrRelationshipsId),
1455
- listener,
1456
- listenerDeps,
1457
- void 0,
1458
- relationshipId,
1459
- localRowId,
1460
- );
1461
- const useLocalRowIdsListener = (
1462
- relationshipId,
1463
- remoteRowId,
1464
- listener,
1465
- listenerDeps,
1466
- relationshipsOrRelationshipsId,
1467
- ) =>
1468
- useListener(
1469
- 'LocalRowIds',
1470
- useRelationshipsOrRelationshipsId(relationshipsOrRelationshipsId),
1471
- listener,
1472
- listenerDeps,
1473
- void 0,
1474
- relationshipId,
1475
- remoteRowId,
1476
- );
1477
- const useLinkedRowIdsListener = (
1478
- relationshipId,
1479
- firstRowId,
1480
- listener,
1481
- listenerDeps,
1482
- relationshipsOrRelationshipsId,
1483
- ) =>
1484
- useListener(
1485
- 'LinkedRowIds',
1486
- useRelationshipsOrRelationshipsId(relationshipsOrRelationshipsId),
1487
- listener,
1488
- listenerDeps,
1489
- void 0,
1490
- relationshipId,
1491
- firstRowId,
1492
- );
1493
- const useCreateCheckpoints = (store, create, createDeps) =>
1494
- useCreate(store, create, createDeps);
1495
- const useCheckpointIds = (checkpointsOrCheckpointsId) =>
1496
- useListenable(
1497
- 'CheckpointIds',
1498
- useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId),
1499
- [[], void 0, []],
1500
- );
1501
- const useCheckpoint = (checkpointId, checkpointsOrCheckpointsId) =>
1502
- useListenable(
1503
- 'Checkpoint',
1504
- useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId),
1505
- void 0,
1506
- checkpointId,
1507
- );
1508
- const useSetCheckpointCallback = (
1509
- getCheckpoint = getUndefined,
1510
- getCheckpointDeps = [],
1511
- checkpointsOrCheckpointsId,
1512
- then = getUndefined,
1513
- thenDeps = [],
1514
- ) => {
1515
- const checkpoints = useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId);
1516
- return useCallback(
1517
- (parameter) =>
1518
- ifNotUndefined(checkpoints, (checkpoints2) => {
1519
- const label = getCheckpoint(parameter);
1520
- then(checkpoints2.addCheckpoint(label), checkpoints2, label);
1521
- }),
1522
- [checkpoints, ...getCheckpointDeps, ...thenDeps],
1523
- );
1524
- };
1525
- const useGoBackwardCallback = (checkpointsOrCheckpointsId) =>
1526
- useCheckpointAction(checkpointsOrCheckpointsId, 'goBackward');
1527
- const useGoForwardCallback = (checkpointsOrCheckpointsId) =>
1528
- useCheckpointAction(checkpointsOrCheckpointsId, 'goForward');
1529
- const useGoToCallback = (
1530
- getCheckpointId,
1531
- getCheckpointIdDeps = [],
1532
- checkpointsOrCheckpointsId,
1533
- then = getUndefined,
1534
- thenDeps = [],
1535
- ) => {
1536
- const checkpoints = useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId);
1537
- return useCallback(
1538
- (parameter) =>
1539
- ifNotUndefined(checkpoints, (checkpoints2) =>
1540
- ifNotUndefined(getCheckpointId(parameter), (checkpointId) =>
1541
- then(checkpoints2.goTo(checkpointId), checkpointId),
1542
- ),
1543
- ),
1544
- [checkpoints, ...getCheckpointIdDeps, ...thenDeps],
1545
- );
1546
- };
1547
- const useUndoInformation = (checkpointsOrCheckpointsId) => {
1548
- const checkpoints = useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId);
1549
- const [backwardIds, currentId] = useCheckpointIds(checkpoints);
1550
- return [
1551
- !arrayIsEmpty(backwardIds),
1552
- useGoBackwardCallback(checkpoints),
1553
- currentId,
1554
- ifNotUndefined(currentId, (id) => checkpoints?.getCheckpoint(id)) ?? '',
1555
- ];
1556
- };
1557
- const useRedoInformation = (checkpointsOrCheckpointsId) => {
1558
- const checkpoints = useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId);
1559
- const [, , [forwardId]] = useCheckpointIds(checkpoints);
1560
- return [
1561
- !isUndefined(forwardId),
1562
- useGoForwardCallback(checkpoints),
1563
- forwardId,
1564
- ifNotUndefined(forwardId, (id) => checkpoints?.getCheckpoint(id)) ?? '',
1565
- ];
1566
- };
1567
- const useCheckpointIdsListener = (
1568
- listener,
1569
- listenerDeps,
1570
- checkpointsOrCheckpointsId,
1571
- ) =>
1572
- useListener(
1573
- 'CheckpointIds',
1574
- useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId),
1575
- listener,
1576
- listenerDeps,
1577
- );
1578
- const useCheckpointListener = (
1579
- checkpointId,
1580
- listener,
1581
- listenerDeps,
1582
- checkpointsOrCheckpointsId,
1583
- ) =>
1584
- useListener(
1585
- 'Checkpoint',
1586
- useCheckpointsOrCheckpointsId(checkpointsOrCheckpointsId),
1587
- listener,
1588
- listenerDeps,
1589
- void 0,
1590
- checkpointId,
1591
- );
1592
- const useCreatePersister = (
1593
- store,
1594
- create,
1595
- createDeps = [],
1596
- then,
1597
- thenDeps = [],
1598
- ) => {
1599
- const [, setDone] = useState();
1600
- const persister = useMemo$1(() => create(store), [store, ...createDeps]);
1601
- useEffect(() => {
1602
- (async () => {
1603
- await then?.(persister);
1604
- setDone(1);
1605
- return;
1606
- })();
1607
- }, [persister, ...thenDeps]);
1608
- return persister;
1609
- };
1610
-
1611
- const {createElement, useMemo} = React ?? {};
1612
- const useRelationshipsStoreTableId = (relationships) => {
1613
- const resolvedRelationships =
1614
- useRelationshipsOrRelationshipsId(relationships);
1615
- return [resolvedRelationships, resolvedRelationships?.getStore()];
1616
- };
1617
- const useComponentPerRow = (
1618
- {
1619
- relationshipId,
1620
- relationships,
1621
- rowComponent: Row = RowView,
1622
- getRowComponentProps,
1623
- separator,
1624
- debugIds,
1625
- },
1626
- getRowIdsHook,
1627
- rowId,
1628
- ) => {
1629
- const [resolvedRelationships, store] =
1630
- useRelationshipsStoreTableId(relationships);
1631
- const tableId = resolvedRelationships?.getLocalTableId(relationshipId);
1632
- const rowIds = getRowIdsHook(relationshipId, rowId, resolvedRelationships);
1633
- return wrap(
1634
- arrayMap(rowIds, (rowId2) =>
1635
- /* @__PURE__ */ createElement(Row, {
1636
- ...getProps(getRowComponentProps, rowId2),
1637
- key: rowId2,
1638
- tableId,
1639
- rowId: rowId2,
1640
- store,
1641
- debugIds,
1642
- }),
1643
- ),
1644
- separator,
1645
- debugIds,
1646
- rowId,
1647
- );
1648
- };
1649
- const getUseCheckpointView =
1650
- (getCheckpoints) =>
1651
- ({
1652
- checkpoints,
1653
- checkpointComponent: Checkpoint = CheckpointView,
1654
- getCheckpointComponentProps,
1655
- separator,
1656
- debugIds,
1657
- }) => {
1658
- const resolvedCheckpoints = useCheckpointsOrCheckpointsId(checkpoints);
1659
- return wrap(
1660
- arrayMap(
1661
- getCheckpoints(useCheckpointIds(resolvedCheckpoints)),
1662
- (checkpointId) =>
1663
- /* @__PURE__ */ createElement(Checkpoint, {
1664
- ...getProps(getCheckpointComponentProps, checkpointId),
1665
- key: checkpointId,
1666
- checkpoints: resolvedCheckpoints,
1667
- checkpointId,
1668
- debugIds,
1669
- }),
1670
- ),
1671
- separator,
1672
- );
1673
- };
1674
- const getProps = (getProps2, id) =>
1675
- isUndefined(getProps2) ? {} : getProps2(id);
1676
- const Provider = ({
1677
- store,
1678
- storesById,
1679
- metrics,
1680
- metricsById,
1681
- indexes,
1682
- indexesById,
1683
- relationships,
1684
- relationshipsById,
1685
- checkpoints,
1686
- checkpointsById,
1687
- children,
1688
- }) =>
1689
- /* @__PURE__ */ createElement(
1690
- Context.Provider,
1691
- {
1692
- value: useMemo(
1693
- () => [
1694
- store,
1695
- storesById,
1696
- metrics,
1697
- metricsById,
1698
- indexes,
1699
- indexesById,
1700
- relationships,
1701
- relationshipsById,
1702
- checkpoints,
1703
- checkpointsById,
1704
- ],
1705
- [
1706
- store,
1707
- storesById,
1708
- metrics,
1709
- metricsById,
1710
- indexes,
1711
- indexesById,
1712
- relationships,
1713
- relationshipsById,
1714
- checkpoints,
1715
- checkpointsById,
1716
- ],
1717
- ),
1718
- },
1719
- children,
1720
- );
1721
- const wrap = (children, separator, encloseWithId, id) => {
1722
- const separatedChildren =
1723
- isUndefined(separator) || !Array.isArray(children)
1724
- ? children
1725
- : arrayMap(children, (child, c) => (c > 0 ? [separator, child] : child));
1726
- return encloseWithId ? [id, ':{', separatedChildren, '}'] : separatedChildren;
1727
- };
1728
- const CellView = ({tableId, rowId, cellId, store, debugIds}) =>
1729
- wrap(
1730
- EMPTY_STRING + (useCell(tableId, rowId, cellId, store) ?? EMPTY_STRING),
1731
- void 0,
1732
- debugIds,
1733
- cellId,
1734
- );
1735
- const RowView = ({
1736
- tableId,
1737
- rowId,
1738
- store,
1739
- cellComponent: Cell = CellView,
1740
- getCellComponentProps,
1741
- separator,
1742
- debugIds,
1743
- }) =>
1744
- wrap(
1745
- arrayMap(useCellIds(tableId, rowId, store), (cellId) =>
1746
- /* @__PURE__ */ createElement(Cell, {
1747
- ...getProps(getCellComponentProps, cellId),
1748
- key: cellId,
1749
- tableId,
1750
- rowId,
1751
- cellId,
1752
- store,
1753
- debugIds,
1754
- }),
1755
- ),
1756
- separator,
1757
- debugIds,
1758
- rowId,
1759
- );
1760
- const TableView = ({
1761
- tableId,
1762
- store,
1763
- rowComponent: Row = RowView,
1764
- getRowComponentProps,
1765
- separator,
1766
- debugIds,
1767
- }) =>
1768
- wrap(
1769
- arrayMap(useRowIds(tableId, store), (rowId) =>
1770
- /* @__PURE__ */ createElement(Row, {
1771
- ...getProps(getRowComponentProps, rowId),
1772
- key: rowId,
1773
- tableId,
1774
- rowId,
1775
- store,
1776
- debugIds,
1777
- }),
1778
- ),
1779
- separator,
1780
- debugIds,
1781
- tableId,
1782
- );
1783
- const TablesView = ({
1784
- store,
1785
- tableComponent: Table = TableView,
1786
- getTableComponentProps,
1787
- separator,
1788
- debugIds,
1789
- }) =>
1790
- wrap(
1791
- arrayMap(useTableIds(store), (tableId) =>
1792
- /* @__PURE__ */ createElement(Table, {
1793
- ...getProps(getTableComponentProps, tableId),
1794
- key: tableId,
1795
- tableId,
1796
- store,
1797
- debugIds,
1798
- }),
1799
- ),
1800
- separator,
1801
- );
1802
- const MetricView = ({metricId, metrics, debugIds}) =>
1803
- wrap(
1804
- useMetric(metricId, metrics) ?? EMPTY_STRING,
1805
- void 0,
1806
- debugIds,
1807
- metricId,
1808
- );
1809
- const SliceView = ({
1810
- indexId,
1811
- sliceId,
1812
- indexes,
1813
- rowComponent: Row = RowView,
1814
- getRowComponentProps,
1815
- separator,
1816
- debugIds,
1817
- }) => {
1818
- const resolvedIndexes = useIndexesOrIndexesId(indexes);
1819
- const store = resolvedIndexes?.getStore();
1820
- const tableId = resolvedIndexes?.getTableId(indexId);
1821
- const rowIds = useSliceRowIds(indexId, sliceId, resolvedIndexes);
1822
- return wrap(
1823
- arrayMap(rowIds, (rowId) =>
1824
- /* @__PURE__ */ createElement(Row, {
1825
- ...getProps(getRowComponentProps, rowId),
1826
- key: rowId,
1827
- tableId,
1828
- rowId,
1829
- store,
1830
- debugIds,
1831
- }),
1832
- ),
1833
- separator,
1834
- debugIds,
1835
- sliceId,
1836
- );
1837
- };
1838
- const IndexView = ({
1839
- indexId,
1840
- indexes,
1841
- sliceComponent: Slice = SliceView,
1842
- getSliceComponentProps,
1843
- separator,
1844
- debugIds,
1845
- }) =>
1846
- wrap(
1847
- arrayMap(useSliceIds(indexId, indexes), (sliceId) =>
1848
- /* @__PURE__ */ createElement(Slice, {
1849
- ...getProps(getSliceComponentProps, sliceId),
1850
- key: sliceId,
1851
- indexId,
1852
- sliceId,
1853
- indexes,
1854
- debugIds,
1855
- }),
1856
- ),
1857
- separator,
1858
- debugIds,
1859
- indexId,
1860
- );
1861
- const RemoteRowView = ({
1862
- relationshipId,
1863
- localRowId,
1864
- relationships,
1865
- rowComponent: Row = RowView,
1866
- getRowComponentProps,
1867
- debugIds,
1868
- }) => {
1869
- const [resolvedRelationships, store] =
1870
- useRelationshipsStoreTableId(relationships);
1871
- const tableId = resolvedRelationships?.getRemoteTableId(relationshipId);
1872
- const rowId = useRemoteRowId(
1873
- relationshipId,
1874
- localRowId,
1875
- resolvedRelationships,
1876
- );
1877
- return wrap(
1878
- isUndefined(tableId) || isUndefined(rowId)
1879
- ? null
1880
- : /* @__PURE__ */ createElement(Row, {
1881
- ...getProps(getRowComponentProps, rowId),
1882
- key: rowId,
1883
- tableId,
1884
- rowId,
1885
- store,
1886
- debugIds,
1887
- }),
1888
- void 0,
1889
- debugIds,
1890
- localRowId,
1891
- );
1892
- };
1893
- const LocalRowsView = (props) =>
1894
- useComponentPerRow(props, useLocalRowIds, props.remoteRowId);
1895
- const LinkedRowsView = (props) =>
1896
- useComponentPerRow(props, useLinkedRowIds, props.firstRowId);
1897
- const CheckpointView = ({checkpoints, checkpointId, debugIds}) =>
1898
- wrap(
1899
- useCheckpoint(checkpointId, checkpoints) ?? '',
1900
- void 0,
1901
- debugIds,
1902
- checkpointId,
1903
- );
1904
- const BackwardCheckpointsView = getUseCheckpointView(
1905
- (checkpointIds) => checkpointIds[0],
1906
- );
1907
- const CurrentCheckpointView = getUseCheckpointView((checkpointIds) =>
1908
- isUndefined(checkpointIds[1]) ? [] : [checkpointIds[1]],
1909
- );
1910
- const ForwardCheckpointsView = getUseCheckpointView(
1911
- (checkpointIds) => checkpointIds[2],
1912
- );
1913
-
1914
967
  const createRelationships = getCreateFunction((store) => {
1915
968
  const remoteTableIds = mapNew();
1916
969
  const remoteRowIdListeners = mapNew();
@@ -2641,21 +1694,6 @@ const createStore = () => {
2641
1694
  };
2642
1695
 
2643
1696
  export {
2644
- BackwardCheckpointsView,
2645
- CellView,
2646
- CheckpointView,
2647
- CurrentCheckpointView,
2648
- ForwardCheckpointsView,
2649
- IndexView,
2650
- LinkedRowsView,
2651
- LocalRowsView,
2652
- MetricView,
2653
- Provider,
2654
- RemoteRowView,
2655
- RowView,
2656
- SliceView,
2657
- TableView,
2658
- TablesView,
2659
1697
  createCheckpoints,
2660
1698
  createCustomPersister,
2661
1699
  createFilePersister,
@@ -2667,61 +1705,4 @@ export {
2667
1705
  createSessionPersister,
2668
1706
  createStore,
2669
1707
  defaultSorter,
2670
- useAddRowCallback,
2671
- useCell,
2672
- useCellIds,
2673
- useCellIdsListener,
2674
- useCellListener,
2675
- useCheckpoint,
2676
- useCheckpointIds,
2677
- useCheckpointIdsListener,
2678
- useCheckpointListener,
2679
- useCheckpoints,
2680
- useCreateCheckpoints,
2681
- useCreateIndexes,
2682
- useCreateMetrics,
2683
- useCreatePersister,
2684
- useCreateRelationships,
2685
- useCreateStore,
2686
- useDelCellCallback,
2687
- useDelRowCallback,
2688
- useDelTableCallback,
2689
- useDelTablesCallback,
2690
- useGoBackwardCallback,
2691
- useGoForwardCallback,
2692
- useGoToCallback,
2693
- useIndexes,
2694
- useLinkedRowIds,
2695
- useLinkedRowIdsListener,
2696
- useLocalRowIds,
2697
- useLocalRowIdsListener,
2698
- useMetric,
2699
- useMetricListener,
2700
- useMetrics,
2701
- useRedoInformation,
2702
- useRelationships,
2703
- useRemoteRowId,
2704
- useRemoteRowIdListener,
2705
- useRow,
2706
- useRowIds,
2707
- useRowIdsListener,
2708
- useRowListener,
2709
- useSetCellCallback,
2710
- useSetCheckpointCallback,
2711
- useSetPartialRowCallback,
2712
- useSetRowCallback,
2713
- useSetTableCallback,
2714
- useSetTablesCallback,
2715
- useSliceIds,
2716
- useSliceIdsListener,
2717
- useSliceRowIds,
2718
- useSliceRowIdsListener,
2719
- useStore,
2720
- useTable,
2721
- useTableIds,
2722
- useTableIdsListener,
2723
- useTableListener,
2724
- useTables,
2725
- useTablesListener,
2726
- useUndoInformation,
2727
1708
  };