tinybase 4.4.1 → 4.4.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.
- package/lib/cjs/ui-react.cjs +1 -1
- package/lib/cjs/ui-react.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react.cjs +1 -1
- package/lib/cjs-es6/ui-react.cjs.gz +0 -0
- package/lib/debug/checkpoints.js +8 -8
- package/lib/debug/indexes.js +8 -8
- package/lib/debug/metrics.js +8 -8
- package/lib/debug/persisters/persister-automerge.js +23 -23
- package/lib/debug/persisters/persister-yjs.js +23 -23
- package/lib/debug/queries.js +10 -10
- package/lib/debug/relationships.js +6 -6
- package/lib/debug/store.js +10 -10
- package/lib/debug/tinybase.js +24 -24
- package/lib/debug/tools.js +2 -2
- package/lib/debug/ui-react-dom.js +12 -12
- package/lib/debug/ui-react.js +56 -22
- package/lib/es6/ui-react.js +1 -1
- package/lib/es6/ui-react.js.gz +0 -0
- package/lib/types/metrics.d.ts +2 -2
- package/lib/types/queries.d.ts +2 -45
- package/lib/types/ui-react.d.ts +53 -0
- package/lib/types/with-schemas/metrics.d.ts +2 -2
- package/lib/types/with-schemas/queries.d.ts +2 -45
- package/lib/types/with-schemas/store.d.ts +8 -8
- package/lib/types/with-schemas/ui-react.d.ts +59 -0
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/lib/umd-es6/ui-react.js +1 -1
- package/lib/umd-es6/ui-react.js.gz +0 -0
- package/package.json +19 -19
- package/readme.md +2 -2
|
@@ -575,8 +575,8 @@ const RelationshipInHtmlRow = ({
|
|
|
575
575
|
tableId === localTableId
|
|
576
576
|
? localRowId
|
|
577
577
|
: tableId === remoteTableId
|
|
578
|
-
|
|
579
|
-
|
|
578
|
+
? remoteRowId
|
|
579
|
+
: null;
|
|
580
580
|
return isUndefined(rowId)
|
|
581
581
|
? null
|
|
582
582
|
: /* @__PURE__ */ createElement(
|
|
@@ -1796,8 +1796,8 @@ const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
|
1796
1796
|
p == size(path)
|
|
1797
1797
|
? arrayPush(leaves, node)
|
|
1798
1798
|
: path[p] === null
|
|
1799
|
-
|
|
1800
|
-
|
|
1799
|
+
? collForEach(node, (node2) => deep(node2, p + 1))
|
|
1800
|
+
: arrayForEach([path[p], null], (id) => deep(mapGet(node, id), p + 1));
|
|
1801
1801
|
deep(deepIdSet, 0);
|
|
1802
1802
|
return leaves;
|
|
1803
1803
|
};
|
|
@@ -1849,10 +1849,10 @@ const getListenerFunctions = (getThing) => {
|
|
|
1849
1849
|
index == size(path)
|
|
1850
1850
|
? listener(thing, ...ids, ...extraArgsGetter(ids))
|
|
1851
1851
|
: isUndefined(path[index])
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1852
|
+
? arrayForEach(pathGetters[index]?.(...ids) ?? [], (id2) =>
|
|
1853
|
+
callWithIds(...ids, id2),
|
|
1854
|
+
)
|
|
1855
|
+
: callWithIds(...ids, path[index]);
|
|
1856
1856
|
};
|
|
1857
1857
|
callWithIds();
|
|
1858
1858
|
},
|
|
@@ -1995,8 +1995,8 @@ const createStore = () => {
|
|
|
1995
1995
|
() => cellInvalid(tableId, rowId, cellId, cell),
|
|
1996
1996
|
)
|
|
1997
1997
|
: isUndefined(getCellOrValueType(cell))
|
|
1998
|
-
|
|
1999
|
-
|
|
1998
|
+
? cellInvalid(tableId, rowId, cellId, cell)
|
|
1999
|
+
: cell;
|
|
2000
2000
|
const validateValues = (values, skipDefaults) =>
|
|
2001
2001
|
validate(
|
|
2002
2002
|
skipDefaults ? values : addDefaultsToValues(values),
|
|
@@ -2022,8 +2022,8 @@ const createStore = () => {
|
|
|
2022
2022
|
() => valueInvalid(valueId, value),
|
|
2023
2023
|
)
|
|
2024
2024
|
: isUndefined(getCellOrValueType(value))
|
|
2025
|
-
|
|
2026
|
-
|
|
2025
|
+
? valueInvalid(valueId, value)
|
|
2026
|
+
: value;
|
|
2027
2027
|
const addDefaultsToRow = (row, tableId, rowId) => {
|
|
2028
2028
|
ifNotUndefined(
|
|
2029
2029
|
mapGet(tablesSchemaRowCache, tableId),
|
package/lib/debug/ui-react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
3
|
const getTypeOf = (thing) => typeof thing;
|
|
4
4
|
const EMPTY_STRING = '';
|
|
@@ -37,16 +37,20 @@ const arrayIsEmpty = (array) => size(array) == 0;
|
|
|
37
37
|
const object = Object;
|
|
38
38
|
const objIds = object.keys;
|
|
39
39
|
const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
|
|
40
|
+
const objDel = (obj, id) => {
|
|
41
|
+
delete obj[id];
|
|
42
|
+
return obj;
|
|
43
|
+
};
|
|
40
44
|
|
|
41
|
-
const {createContext, useContext} = React;
|
|
45
|
+
const {createContext, useContext: useContext$1, useEffect: useEffect$1} = React;
|
|
42
46
|
const Context = createContext([]);
|
|
43
47
|
const useThing = (id, offset) => {
|
|
44
|
-
const contextValue = useContext(Context);
|
|
48
|
+
const contextValue = useContext$1(Context);
|
|
45
49
|
return isUndefined(id)
|
|
46
50
|
? contextValue[offset]
|
|
47
51
|
: isString(id)
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
? objGet(contextValue[offset + 1] ?? {}, id)
|
|
53
|
+
: id;
|
|
50
54
|
};
|
|
51
55
|
const useThingOrThingById = (thingOrThingId, offset) => {
|
|
52
56
|
const thing = useThing(thingOrThingId, offset);
|
|
@@ -54,10 +58,17 @@ const useThingOrThingById = (thingOrThingId, offset) => {
|
|
|
54
58
|
? thing
|
|
55
59
|
: thingOrThingId;
|
|
56
60
|
};
|
|
57
|
-
const useThingIds = (offset) => objIds(useContext(Context)[offset] ?? {});
|
|
61
|
+
const useThingIds = (offset) => objIds(useContext$1(Context)[offset] ?? {});
|
|
58
62
|
const useStore = (id) => useThing(id, 0);
|
|
59
63
|
const useStoreOrStoreById = (storeOrStoreId) =>
|
|
60
64
|
useThingOrThingById(storeOrStoreId, 0);
|
|
65
|
+
const useProvideStore = (storeId, store) => {
|
|
66
|
+
const {12: addExtraStore, 13: delExtraStore} = useContext$1(Context);
|
|
67
|
+
useEffect$1(() => {
|
|
68
|
+
addExtraStore?.(storeId, store);
|
|
69
|
+
return () => delExtraStore?.(storeId);
|
|
70
|
+
}, [addExtraStore, storeId, store, delExtraStore]);
|
|
71
|
+
};
|
|
61
72
|
const useMetrics = (id) => useThing(id, 2);
|
|
62
73
|
const useMetricsOrMetricsById = (metricsOrMetricsId) =>
|
|
63
74
|
useThingOrThingById(metricsOrMetricsId, 2);
|
|
@@ -80,12 +91,12 @@ const TRANSACTION = 'Transaction';
|
|
|
80
91
|
lower(TRANSACTION);
|
|
81
92
|
|
|
82
93
|
const {
|
|
83
|
-
useCallback: useCallback$
|
|
94
|
+
useCallback: useCallback$2,
|
|
84
95
|
useEffect,
|
|
85
96
|
useMemo: useMemo$1,
|
|
86
97
|
useLayoutEffect: useLayoutEffect$1,
|
|
87
98
|
useRef: useRef$1,
|
|
88
|
-
useState: useState$
|
|
99
|
+
useState: useState$2,
|
|
89
100
|
} = React;
|
|
90
101
|
const EMPTY_ARRAY = [];
|
|
91
102
|
const EMPTY_OBJECT = {};
|
|
@@ -108,8 +119,8 @@ const useListenable = (
|
|
|
108
119
|
getterPrefix = GET,
|
|
109
120
|
listenerPrefix = EMPTY_STRING,
|
|
110
121
|
) => {
|
|
111
|
-
const [, rerender] = useState$
|
|
112
|
-
const getResult = useCallback$
|
|
122
|
+
const [, rerender] = useState$2();
|
|
123
|
+
const getResult = useCallback$2(
|
|
113
124
|
() => thing?.[getterPrefix + listenable]?.(...args) ?? defaulted,
|
|
114
125
|
/* eslint-disable-next-line react-hooks/exhaustive-deps */
|
|
115
126
|
[thing, listenable, ...args, defaulted],
|
|
@@ -156,7 +167,7 @@ const useSetCallback = (
|
|
|
156
167
|
...args
|
|
157
168
|
) => {
|
|
158
169
|
const store = useStoreOrStoreById(storeOrStoreId);
|
|
159
|
-
return useCallback$
|
|
170
|
+
return useCallback$2(
|
|
160
171
|
(parameter) =>
|
|
161
172
|
ifNotUndefined(store, (store2) =>
|
|
162
173
|
ifNotUndefined(get(parameter, store2), (thing) =>
|
|
@@ -175,7 +186,7 @@ const useDel = (
|
|
|
175
186
|
...args
|
|
176
187
|
) => {
|
|
177
188
|
const store = useStoreOrStoreById(storeOrStoreId);
|
|
178
|
-
return useCallback$
|
|
189
|
+
return useCallback$2(
|
|
179
190
|
() => then(store?.['del' + deletable](...args)),
|
|
180
191
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
181
192
|
[store, deletable, ...thenDeps, ...args],
|
|
@@ -185,7 +196,7 @@ const useCheckpointAction = (checkpointsOrCheckpointsId, action, arg) => {
|
|
|
185
196
|
const checkpoints = useCheckpointsOrCheckpointsById(
|
|
186
197
|
checkpointsOrCheckpointsId,
|
|
187
198
|
);
|
|
188
|
-
return useCallback$
|
|
199
|
+
return useCallback$2(
|
|
189
200
|
() => checkpoints?.[action](arg),
|
|
190
201
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
191
202
|
[checkpoints, action, arg],
|
|
@@ -385,7 +396,7 @@ const useAddRowCallback = (
|
|
|
385
396
|
reuseRowIds = true,
|
|
386
397
|
) => {
|
|
387
398
|
const store = useStoreOrStoreById(storeOrStoreId);
|
|
388
|
-
return useCallback$
|
|
399
|
+
return useCallback$2(
|
|
389
400
|
(parameter) =>
|
|
390
401
|
ifNotUndefined(store, (store2) =>
|
|
391
402
|
ifNotUndefined(getRow(parameter, store2), (row) =>
|
|
@@ -1198,7 +1209,7 @@ const useSetCheckpointCallback = (
|
|
|
1198
1209
|
const checkpoints = useCheckpointsOrCheckpointsById(
|
|
1199
1210
|
checkpointsOrCheckpointsId,
|
|
1200
1211
|
);
|
|
1201
|
-
return useCallback$
|
|
1212
|
+
return useCallback$2(
|
|
1202
1213
|
(parameter) =>
|
|
1203
1214
|
ifNotUndefined(checkpoints, (checkpoints2) => {
|
|
1204
1215
|
const label = getCheckpoint(parameter);
|
|
@@ -1222,7 +1233,7 @@ const useGoToCallback = (
|
|
|
1222
1233
|
const checkpoints = useCheckpointsOrCheckpointsById(
|
|
1223
1234
|
checkpointsOrCheckpointsId,
|
|
1224
1235
|
);
|
|
1225
|
-
return useCallback$
|
|
1236
|
+
return useCallback$2(
|
|
1226
1237
|
(parameter) =>
|
|
1227
1238
|
ifNotUndefined(checkpoints, (checkpoints2) =>
|
|
1228
1239
|
ifNotUndefined(getCheckpointId(parameter), (checkpointId) =>
|
|
@@ -1292,7 +1303,7 @@ const useCreatePersister = (
|
|
|
1292
1303
|
destroy,
|
|
1293
1304
|
destroyDeps = EMPTY_ARRAY,
|
|
1294
1305
|
) => {
|
|
1295
|
-
const [, rerender] = useState$
|
|
1306
|
+
const [, rerender] = useState$2();
|
|
1296
1307
|
const persister = useMemo$1(
|
|
1297
1308
|
() => create(store),
|
|
1298
1309
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -1321,10 +1332,10 @@ const {
|
|
|
1321
1332
|
PureComponent,
|
|
1322
1333
|
Fragment,
|
|
1323
1334
|
createElement,
|
|
1324
|
-
useCallback,
|
|
1335
|
+
useCallback: useCallback$1,
|
|
1325
1336
|
useLayoutEffect,
|
|
1326
1337
|
useRef,
|
|
1327
|
-
useState,
|
|
1338
|
+
useState: useState$1,
|
|
1328
1339
|
} = React;
|
|
1329
1340
|
const getProps = (getProps2, ...ids) =>
|
|
1330
1341
|
isUndefined(getProps2) ? {} : getProps2(...ids);
|
|
@@ -1340,7 +1351,7 @@ const getIndexStoreTableId = (indexes, indexId) => [
|
|
|
1340
1351
|
indexes?.getTableId(indexId),
|
|
1341
1352
|
];
|
|
1342
1353
|
|
|
1343
|
-
const {useMemo} = React;
|
|
1354
|
+
const {useCallback, useContext, useMemo, useState} = React;
|
|
1344
1355
|
const tableView = (
|
|
1345
1356
|
{
|
|
1346
1357
|
tableId,
|
|
@@ -1469,14 +1480,31 @@ const Provider = ({
|
|
|
1469
1480
|
checkpointsById,
|
|
1470
1481
|
children,
|
|
1471
1482
|
}) => {
|
|
1472
|
-
const parentValue = useContext
|
|
1483
|
+
const parentValue = useContext(Context);
|
|
1484
|
+
const [extraStoresById, setExtraStoresById] = useState({});
|
|
1485
|
+
const addExtraStore = useCallback(
|
|
1486
|
+
(id, store2) =>
|
|
1487
|
+
setExtraStoresById((extraStoresById2) =>
|
|
1488
|
+
objGet(extraStoresById2, id) == store2
|
|
1489
|
+
? extraStoresById2
|
|
1490
|
+
: {...extraStoresById2, [id]: store2},
|
|
1491
|
+
),
|
|
1492
|
+
[],
|
|
1493
|
+
);
|
|
1494
|
+
const delExtraStore = useCallback(
|
|
1495
|
+
(id) =>
|
|
1496
|
+
setExtraStoresById((extraStoresById2) => ({
|
|
1497
|
+
...objDel(extraStoresById2, id),
|
|
1498
|
+
})),
|
|
1499
|
+
[],
|
|
1500
|
+
);
|
|
1473
1501
|
return /* @__PURE__ */ createElement(
|
|
1474
1502
|
Context.Provider,
|
|
1475
1503
|
{
|
|
1476
1504
|
value: useMemo(
|
|
1477
1505
|
() => [
|
|
1478
1506
|
store ?? parentValue[0],
|
|
1479
|
-
{...parentValue[1], ...storesById},
|
|
1507
|
+
{...parentValue[1], ...storesById, ...extraStoresById},
|
|
1480
1508
|
metrics ?? parentValue[2],
|
|
1481
1509
|
{...parentValue[3], ...metricsById},
|
|
1482
1510
|
indexes ?? parentValue[4],
|
|
@@ -1487,10 +1515,13 @@ const Provider = ({
|
|
|
1487
1515
|
{...parentValue[9], ...queriesById},
|
|
1488
1516
|
checkpoints ?? parentValue[10],
|
|
1489
1517
|
{...parentValue[11], ...checkpointsById},
|
|
1518
|
+
addExtraStore,
|
|
1519
|
+
delExtraStore,
|
|
1490
1520
|
],
|
|
1491
1521
|
[
|
|
1492
1522
|
store,
|
|
1493
1523
|
storesById,
|
|
1524
|
+
extraStoresById,
|
|
1494
1525
|
metrics,
|
|
1495
1526
|
metricsById,
|
|
1496
1527
|
indexes,
|
|
@@ -1502,6 +1533,8 @@ const Provider = ({
|
|
|
1502
1533
|
checkpoints,
|
|
1503
1534
|
checkpointsById,
|
|
1504
1535
|
parentValue,
|
|
1536
|
+
addExtraStore,
|
|
1537
|
+
delExtraStore,
|
|
1505
1538
|
],
|
|
1506
1539
|
),
|
|
1507
1540
|
},
|
|
@@ -1855,6 +1888,7 @@ export {
|
|
|
1855
1888
|
useMetrics,
|
|
1856
1889
|
useMetricsIds,
|
|
1857
1890
|
useMetricsOrMetricsById,
|
|
1891
|
+
useProvideStore,
|
|
1858
1892
|
useQueries,
|
|
1859
1893
|
useQueriesIds,
|
|
1860
1894
|
useQueriesOrQueriesById,
|
package/lib/es6/ui-react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{useContext as t}from"react";const o=e=>typeof e,r="",n=o(r),d="Listener",l="Result",s="Has",u="has",i="Ids",a="Table",c=a+"s",I=a+i,p="Row",v=p+"Count",b=p+i,g="Sorted"+p+i,m="Cell",y=m+i,C="Value",w=C+"s",f=C+i,h=e=>null==e,k=(e,t,o)=>h(e)?null==o?void 0:o():t(e),R=e=>o(e)==n,P=()=>{},x=(e,t)=>e.map(t),q=Object.keys,{createContext:O,useContext:S}=e,L=O([]),j=(e,t)=>{var o;const r=S(L);return h(e)?r[t]:R(e)?((e,t)=>k(e,(e=>e[t])))(null!=(o=r[t+1])?o:{},e):e},B=(e,t)=>{const o=j(e,t);return h(e)||R(e)?o:e},T=e=>{var t;return q(null!=(t=S(L)[e])?t:{})},E=e=>j(e,0),M=e=>B(e,0),F=e=>j(e,2),V=e=>B(e,2),A=e=>j(e,4),D=e=>B(e,4),H=e=>j(e,6),Q=e=>B(e,6),W=e=>j(e,8),z=e=>B(e,8),G=e=>j(e,10),J=e=>B(e,10),K=e=>e.toLowerCase();K(d);const N="Transaction";K(N);const{useCallback:U,useEffect:X,useMemo:Y,useLayoutEffect:Z,useRef:$,useState:_}=e,ee=[],te={},oe=[[],void 0,[]],re=(e,t,o=ee)=>{const r=Y((()=>t(e)),[e,...o]);return X((()=>()=>r.destroy()),[r]),r},ne=(e,t,o,r=ee,n,d="get",l="")=>{const[,s]=_(),u=U((()=>{var n,l;return null!=(l=null==(n=null==t?void 0:t[d+e])?void 0:n.call(t,...r))?l:o}),[t,e,...r,o]),i=$();return Y((()=>i.current=u()),[u]),de(l+e,t,((...e)=>{i.current=h(n)?u():e[n],s([])}),[u,n],r),i.current},de=(e,t,o,r=ee,n=ee,...l)=>Z((()=>{var r;const s=null==(r=null==t?void 0:t["add"+e+d])?void 0:r.call(t,...n,o,...l);return()=>null==t?void 0:t.delListener(s)}),[t,e,...n,...r,...l]),le=(e,t,o,r=ee,n=P,d=ee,...l)=>{const s=M(e);return U((e=>k(s,(r=>k(o(e,r),(e=>n(r["set"+t](...l,e),e)))))),[s,t,...r,...d,...l])},se=(e,t,o=P,r=ee,...n)=>{const d=M(e);return U((()=>o(null==d?void 0:d["del"+t](...n))),[d,t,...r,...n])},ue=(e,t,o)=>{const r=J(e);return U((()=>null==r?void 0:r[t](o)),[r,t,o])},ie=(e,t=ee)=>Y(e,t),ae=()=>T(1),ce=e=>ne(c,M(e),!1,[],1,u,s),Ie=e=>ne(c,M(e),te),pe=e=>ne(I,M(e),ee),ve=(e,t)=>ne(a,M(t),!1,[e],2,u,s),be=(e,t)=>ne(a,M(t),te,[e]),ge=(e,t)=>ne(a+y,M(t),ee,[e]),me=(e,t,o)=>ne(a+m,M(o),!1,[e,t],3,u,s),ye=(e,t)=>ne(v,M(t),0,[e]),Ce=(e,t)=>ne(b,M(t),ee,[e]),we=(e,t,o,r=0,n,d)=>ne(g,M(d),ee,[e,t,o,r,n],6),fe=(e,t,o)=>ne(p,M(o),!1,[e,t],3,u,s),he=(e,t,o)=>ne(p,M(o),te,[e,t]),ke=(e,t,o)=>ne(y,M(o),ee,[e,t]),Re=(e,t,o,r)=>ne(m,M(r),!1,[e,t,o],4,u,s),Pe=(e,t,o,r)=>ne(m,M(r),void 0,[e,t,o],4),xe=e=>ne(w,M(e),!1,[],1,u,s),qe=e=>ne(w,M(e),te),Oe=e=>ne(f,M(e),ee),Se=(e,t)=>ne(C,M(t),!1,[e],2,u,s),Le=(e,t)=>ne(C,M(t),void 0,[e]),je=(e,t,o,r,n)=>le(o,c,e,t,r,n),Be=(e,t,o,r,n,d)=>le(r,a,t,o,n,d,e),Te=(e,t,o,r,n,d,l)=>le(n,p,o,r,d,l,e,t),Ee=(e,t,o=ee,r,n=P,d=ee,l=!0)=>{const s=M(r);return U((o=>k(s,(r=>k(t(o,r),(t=>n(r.addRow(e,t,l),r,t)))))),[s,e,...o,...d,l])},Me=(e,t,o,r,n,d,l)=>le(n,"PartialRow",o,r,d,l,e,t),Fe=(e,t,o,r,n,d,l,s)=>le(d,m,r,n,l,s,e,t,o),Ve=(e,t,o,r,n)=>le(o,w,e,t,r,n),Ae=(e,t,o,r,n)=>le(o,"PartialValues",e,t,r,n),De=(e,t,o,r,n,d)=>le(r,C,t,o,n,d,e),He=(e,t,o)=>se(e,c,t,o),Qe=(e,t,o,r)=>se(t,a,o,r,e),We=(e,t,o,r,n)=>se(o,p,r,n,e,t),ze=(e,t,o,r,n,d,l)=>se(n,m,d,l,e,t,o,r),Ge=(e,t,o)=>se(e,w,t,o),Je=(e,t,o,r)=>se(t,C,o,r,e),Ke=(e,t,o,r)=>de(s+c,M(r),e,t,[],o),Ne=(e,t,o,r)=>de(c,M(r),e,t,ee,o),Ue=(e,t,o,r)=>de(I,M(r),e,t,ee,o),Xe=(e,t,o,r,n)=>de(s+a,M(n),t,o,[e],r),Ye=(e,t,o,r,n)=>de(a,M(n),t,o,[e],r),Ze=(e,t,o,r,n)=>de(a+y,M(n),t,o,[e],r),$e=(e,t,o,r,n,d)=>de(s+a+m,M(d),o,r,[e,t],n),_e=(e,t,o,r,n)=>de(v,M(n),t,o,[e],r),et=(e,t,o,r,n)=>de(b,M(n),t,o,[e],r),tt=(e,t,o,r,n,d,l,s,u)=>de(g,M(u),d,l,[e,t,o,r,n],s),ot=(e,t,o,r,n,d)=>de(s+p,M(d),o,r,[e,t],n),rt=(e,t,o,r,n,d)=>de(p,M(d),o,r,[e,t],n),nt=(e,t,o,r,n,d)=>de(y,M(d),o,r,[e,t],n),dt=(e,t,o,r,n,d,l)=>de(s+m,M(l),r,n,[e,t,o],d),lt=(e,t,o,r,n,d,l)=>de(m,M(l),r,n,[e,t,o],d),st=(e,t,o,r)=>de(s+w,M(r),e,t,[],o),ut=(e,t,o,r)=>de(w,M(r),e,t,ee,o),it=(e,t,o,r)=>de(f,M(r),e,t,ee,o),at=(e,t,o,r,n)=>de(s+C,M(n),t,o,[e],r),ct=(e,t,o,r,n)=>de(C,M(n),t,o,[e],r),It=(e,t,o)=>de("Start"+N,M(o),e,t),pt=(e,t,o)=>de("WillFinish"+N,M(o),e,t),vt=(e,t,o)=>de("DidFinish"+N,M(o),e,t),bt=(e,t,o)=>re(e,t,o),gt=()=>T(3),mt=e=>ne("MetricIds",V(e),ee),yt=(e,t)=>ne("Metric",V(t),void 0,[e]),Ct=(e,t,o,r)=>de("Metric",V(r),t,o,[e]),wt=(e,t,o)=>re(e,t,o),ft=()=>T(5),ht=(e,t)=>ne("SliceIds",D(t),ee,[e]),kt=e=>ne("IndexIds",D(e),ee),Rt=(e,t,o)=>ne("Slice"+b,D(o),ee,[e,t]),Pt=(e,t,o,r)=>de("SliceIds",D(r),t,o,[e]),xt=(e,t,o,r,n)=>de("Slice"+b,D(n),o,r,[e,t]),qt=(e,t,o)=>re(e,t,o),Ot=()=>T(7),St=e=>ne("RelationshipIds",Q(e),ee),Lt=(e,t,o)=>ne("RemoteRowId",Q(o),void 0,[e,t]),jt=(e,t,o)=>ne("Local"+b,Q(o),ee,[e,t]),Bt=(e,t,o)=>ne("Linked"+b,Q(o),ee,[e,t]),Tt=(e,t,o,r,n)=>de("RemoteRowId",Q(n),o,r,[e,t]),Et=(e,t,o,r,n)=>de("Local"+b,Q(n),o,r,[e,t]),Mt=(e,t,o,r,n)=>de("Linked"+b,Q(n),o,r,[e,t]),Ft=(e,t,o)=>re(e,t,o),Vt=()=>T(9),At=e=>ne("QueryIds",z(e),ee),Dt=(e,t)=>ne(l+a,z(t),te,[e]),Ht=(e,t)=>ne(l+a+y,z(t),ee,[e]),Qt=(e,t)=>ne(l+v,z(t),0,[e]),Wt=(e,t)=>ne(l+b,z(t),ee,[e]),zt=(e,t,o,r=0,n,d)=>ne(l+g,z(d),ee,[e,t,o,r,n],6),Gt=(e,t,o)=>ne(l+p,z(o),te,[e,t]),Jt=(e,t,o)=>ne(l+y,z(o),ee,[e,t]),Kt=(e,t,o,r)=>ne(l+m,z(r),void 0,[e,t,o]),Nt=(e,t,o,r)=>de(l+a,z(r),t,o,[e]),Ut=(e,t,o,r)=>de(l+a+y,z(r),t,o,[e]),Xt=(e,t,o,r)=>de(l+v,z(r),t,o,[e]),Yt=(e,t,o,r)=>de(l+b,z(r),t,o,[e]),Zt=(e,t,o,r,n,d,s,u)=>de(l+g,z(u),d,s,[e,t,o,r,n]),$t=(e,t,o,r,n)=>de(l+p,z(n),o,r,[e,t]),_t=(e,t,o,r,n)=>de(l+y,z(n),o,r,[e,t]),eo=(e,t,o,r,n,d)=>de(l+m,z(d),r,n,[e,t,o]),to=(e,t,o)=>re(e,t,o),oo=()=>T(11),ro=e=>ne("CheckpointIds",J(e),oe),no=(e,t)=>ne("Checkpoint",J(t),void 0,[e]),lo=(e=P,t=ee,o,r=P,n=ee)=>{const d=J(o);return U((t=>k(d,(o=>{const n=e(t);r(o.addCheckpoint(n),o,n)}))),[d,...t,...n])},so=e=>ue(e,"goBackward"),uo=e=>ue(e,"goForward"),io=(e,t=ee,o,r=P,n=ee)=>{const d=J(o);return U((t=>k(d,(o=>k(e(t),(e=>r(o.goTo(e),e)))))),[d,...t,...n])},ao=e=>{var t;const o=J(e),[n,d]=ro(o);return[(l=n,!(0==l.length)),so(o),d,null!=(t=k(d,(e=>null==o?void 0:o.getCheckpoint(e))))?t:r];var l},co=e=>{var t;const o=J(e),[,,[n]]=ro(o);return[!h(n),uo(o),n,null!=(t=k(n,(e=>null==o?void 0:o.getCheckpoint(e))))?t:r]},Io=(e,t,o)=>de("CheckpointIds",J(o),e,t),po=(e,t,o,r)=>de("Checkpoint",J(r),t,o,[e]),vo=(e,t,o=ee,r,n=ee,d,l=ee)=>{const[,s]=_(),u=Y((()=>t(e)),[e,...o]);return X((()=>{var e;return e=function*(){r&&(yield r(u),s([]))},new Promise(((t,o)=>{var r=t=>{try{d(e.next(t))}catch(e){o(e)}},n=t=>{try{d(e.throw(t))}catch(e){o(e)}},d=e=>e.done?t(e.value):Promise.resolve(e.value).then(r,n);d((e=e.apply(void 0,null)).next())})),()=>{null==u||u.destroy(),null==d||d(u)}}),[u,...n,...l]),u},{PureComponent:bo,Fragment:go,createElement:mo,useCallback:yo,useLayoutEffect:Co,useRef:wo,useState:fo}=e,ho=(e,...t)=>h(e)?{}:e(...t),ko=(e,t)=>[e,null==e?void 0:e.getStore(),null==e?void 0:e.getLocalTableId(t),null==e?void 0:e.getRemoteTableId(t)];var Ro=Object.defineProperty,Po=Object.defineProperties,xo=Object.getOwnPropertyDescriptors,qo=Object.getOwnPropertySymbols,Oo=Object.prototype.hasOwnProperty,So=Object.prototype.propertyIsEnumerable,Lo=(e,t,o)=>t in e?Ro(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,jo=(e,t)=>{for(var o in t||(t={}))Oo.call(t,o)&&Lo(e,o,t[o]);if(qo)for(var o of qo(t))So.call(t,o)&&Lo(e,o,t[o]);return e},Bo=(e,t)=>Po(e,xo(t)),To=(e,t)=>{var o={};for(var r in e)Oo.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(null!=e&&qo)for(var r of qo(e))t.indexOf(r)<0&&So.call(e,r)&&(o[r]=e[r]);return o};const{useMemo:Eo}=e,Mo=({tableId:e,store:t,rowComponent:o=Wo,getRowComponentProps:r,customCellIds:n,separator:d,debugIds:l},s)=>Ho(x(s,(d=>mo(o,Bo(jo({},ho(r,d)),{key:d,tableId:e,rowId:d,customCellIds:n,store:t,debugIds:l})))),d,l,e),Fo=({queryId:e,queries:t,resultRowComponent:o=tr,getResultRowComponentProps:r,separator:n,debugIds:d},l)=>Ho(x(l,(n=>mo(o,Bo(jo({},ho(r,n)),{key:n,queryId:e,rowId:n,queries:t,debugIds:d})))),n,d,e),Vo=({relationshipId:e,relationships:t,rowComponent:o=Wo,getRowComponentProps:r,separator:n,debugIds:d},l,s)=>{const[u,i,a]=ko(Q(t),e),c=l(e,s,u);return Ho(x(c,(e=>mo(o,Bo(jo({},ho(r,e)),{key:e,tableId:a,rowId:e,store:i,debugIds:d})))),n,d,s)},Ao=e=>({checkpoints:t,checkpointComponent:o=nr,getCheckpointComponentProps:r,separator:n,debugIds:d})=>{const l=J(t);return Ho(x(e(ro(l)),(e=>mo(o,Bo(jo({},ho(r,e)),{key:e,checkpoints:l,checkpointId:e,debugIds:d})))),n)},Do=({store:e,storesById:o,metrics:r,metricsById:n,indexes:d,indexesById:l,relationships:s,relationshipsById:u,queries:i,queriesById:a,checkpoints:c,checkpointsById:I,children:p})=>{const v=t(L);return mo(L.Provider,{value:Eo((()=>[null!=e?e:v[0],jo(jo({},v[1]),o),null!=r?r:v[2],jo(jo({},v[3]),n),null!=d?d:v[4],jo(jo({},v[5]),l),null!=s?s:v[6],jo(jo({},v[7]),u),null!=i?i:v[8],jo(jo({},v[9]),a),null!=c?c:v[10],jo(jo({},v[11]),I)]),[e,o,r,n,d,l,s,u,i,a,c,I,v])},p)},Ho=(e,t,o,r)=>{const n=h(t)||!Array.isArray(e)?e:x(e,((e,o)=>o>0?[t,e]:e));return o?[r,":{",n,"}"]:n},Qo=({tableId:e,rowId:t,cellId:o,store:n,debugIds:d})=>{var l;return Ho(r+(null!=(l=Pe(e,t,o,n))?l:r),void 0,d,o)},Wo=({tableId:e,rowId:t,store:o,cellComponent:r=Qo,getCellComponentProps:n,customCellIds:d,separator:l,debugIds:s})=>Ho(x(((e,t,o,r)=>{const n=ke(t,o,r);return null!=e?e:n})(d,e,t,o),(d=>mo(r,Bo(jo({},ho(n,d)),{key:d,tableId:e,rowId:t,cellId:d,store:o,debugIds:s})))),l,s,t),zo=e=>Mo(e,Ce(e.tableId,e.store)),Go=e=>{var t=e,{cellId:o,descending:r,offset:n,limit:d}=t,l=To(t,["cellId","descending","offset","limit"]);return Mo(l,we(l.tableId,o,r,n,d,l.store))},Jo=({store:e,tableComponent:t=zo,getTableComponentProps:o,separator:r,debugIds:n})=>Ho(x(pe(e),(r=>mo(t,Bo(jo({},ho(o,r)),{key:r,tableId:r,store:e,debugIds:n})))),r),Ko=({valueId:e,store:t,debugIds:o})=>{var n;return Ho(r+(null!=(n=Le(e,t))?n:r),void 0,o,e)},No=({store:e,valueComponent:t=Ko,getValueComponentProps:o,separator:r,debugIds:n})=>Ho(x(Oe(e),(r=>mo(t,Bo(jo({},ho(o,r)),{key:r,valueId:r,store:e,debugIds:n})))),r),Uo=({metricId:e,metrics:t,debugIds:o})=>{var n;return Ho(null!=(n=yt(e,t))?n:r,void 0,o,e)},Xo=({indexId:e,sliceId:t,indexes:o,rowComponent:r=Wo,getRowComponentProps:n,separator:d,debugIds:l})=>{const[s,u,i]=((e,t)=>[e,null==e?void 0:e.getStore(),null==e?void 0:e.getTableId(t)])(D(o),e),a=Rt(e,t,s);return Ho(x(a,(e=>mo(r,Bo(jo({},ho(n,e)),{key:e,tableId:i,rowId:e,store:u,debugIds:l})))),d,l,t)},Yo=({indexId:e,indexes:t,sliceComponent:o=Xo,getSliceComponentProps:r,separator:n,debugIds:d})=>Ho(x(ht(e,t),(n=>mo(o,Bo(jo({},ho(r,n)),{key:n,indexId:e,sliceId:n,indexes:t,debugIds:d})))),n,d,e),Zo=({relationshipId:e,localRowId:t,relationships:o,rowComponent:r=Wo,getRowComponentProps:n,debugIds:d})=>{const[l,s,,u]=ko(Q(o),e),i=Lt(e,t,l);return Ho(h(u)||h(i)?null:mo(r,Bo(jo({},ho(n,i)),{key:i,tableId:u,rowId:i,store:s,debugIds:d})),void 0,d,t)},$o=e=>Vo(e,jt,e.remoteRowId),_o=e=>Vo(e,Bt,e.firstRowId),er=({queryId:e,rowId:t,cellId:o,queries:n,debugIds:d})=>{var l;return Ho(r+(null!=(l=Kt(e,t,o,n))?l:r),void 0,d,o)},tr=({queryId:e,rowId:t,queries:o,resultCellComponent:r=er,getResultCellComponentProps:n,separator:d,debugIds:l})=>Ho(x(Jt(e,t,o),(d=>mo(r,Bo(jo({},ho(n,d)),{key:d,queryId:e,rowId:t,cellId:d,queries:o,debugIds:l})))),d,l,t),or=e=>Fo(e,Wt(e.queryId,e.queries)),rr=e=>{var t=e,{cellId:o,descending:r,offset:n,limit:d}=t,l=To(t,["cellId","descending","offset","limit"]);return Fo(l,zt(l.queryId,o,r,n,d,l.queries))},nr=({checkpoints:e,checkpointId:t,debugIds:o})=>{var n;return Ho(null!=(n=no(t,e))?n:r,void 0,o,t)},dr=Ao((e=>e[0])),lr=Ao((e=>h(e[1])?[]:[e[1]])),sr=Ao((e=>e[2]));export{dr as BackwardCheckpointsView,Qo as CellView,nr as CheckpointView,lr as CurrentCheckpointView,sr as ForwardCheckpointsView,Yo as IndexView,_o as LinkedRowsView,$o as LocalRowsView,Uo as MetricView,Do as Provider,Zo as RemoteRowView,er as ResultCellView,tr as ResultRowView,rr as ResultSortedTableView,or as ResultTableView,Wo as RowView,Xo as SliceView,Go as SortedTableView,zo as TableView,Jo as TablesView,Ko as ValueView,No as ValuesView,Ee as useAddRowCallback,Pe as useCell,ke as useCellIds,nt as useCellIdsListener,lt as useCellListener,no as useCheckpoint,ro as useCheckpointIds,Io as useCheckpointIdsListener,po as useCheckpointListener,G as useCheckpoints,oo as useCheckpointsIds,J as useCheckpointsOrCheckpointsById,to as useCreateCheckpoints,wt as useCreateIndexes,bt as useCreateMetrics,vo as useCreatePersister,Ft as useCreateQueries,qt as useCreateRelationships,ie as useCreateStore,ze as useDelCellCallback,We as useDelRowCallback,Qe as useDelTableCallback,He as useDelTablesCallback,Je as useDelValueCallback,Ge as useDelValuesCallback,vt as useDidFinishTransactionListener,so as useGoBackwardCallback,uo as useGoForwardCallback,io as useGoToCallback,Re as useHasCell,dt as useHasCellListener,fe as useHasRow,ot as useHasRowListener,ve as useHasTable,me as useHasTableCell,$e as useHasTableCellListener,Xe as useHasTableListener,ce as useHasTables,Ke as useHasTablesListener,Se as useHasValue,at as useHasValueListener,xe as useHasValues,st as useHasValuesListener,kt as useIndexIds,A as useIndexes,ft as useIndexesIds,D as useIndexesOrIndexesById,Bt as useLinkedRowIds,Mt as useLinkedRowIdsListener,jt as useLocalRowIds,Et as useLocalRowIdsListener,yt as useMetric,mt as useMetricIds,Ct as useMetricListener,F as useMetrics,gt as useMetricsIds,V as useMetricsOrMetricsById,W as useQueries,Vt as useQueriesIds,z as useQueriesOrQueriesById,At as useQueryIds,co as useRedoInformation,St as useRelationshipIds,H as useRelationships,Ot as useRelationshipsIds,Q as useRelationshipsOrRelationshipsById,Lt as useRemoteRowId,Tt as useRemoteRowIdListener,Kt as useResultCell,Jt as useResultCellIds,_t as useResultCellIdsListener,eo as useResultCellListener,Gt as useResultRow,Qt as useResultRowCount,Xt as useResultRowCountListener,Wt as useResultRowIds,Yt as useResultRowIdsListener,$t as useResultRowListener,zt as useResultSortedRowIds,Zt as useResultSortedRowIdsListener,Dt as useResultTable,Ht as useResultTableCellIds,Ut as useResultTableCellIdsListener,Nt as useResultTableListener,he as useRow,ye as useRowCount,_e as useRowCountListener,Ce as useRowIds,et as useRowIdsListener,rt as useRowListener,Fe as useSetCellCallback,lo as useSetCheckpointCallback,Me as useSetPartialRowCallback,Ae as useSetPartialValuesCallback,Te as useSetRowCallback,Be as useSetTableCallback,je as useSetTablesCallback,De as useSetValueCallback,Ve as useSetValuesCallback,ht as useSliceIds,Pt as useSliceIdsListener,Rt as useSliceRowIds,xt as useSliceRowIdsListener,we as useSortedRowIds,tt as useSortedRowIdsListener,It as useStartTransactionListener,E as useStore,ae as useStoreIds,M as useStoreOrStoreById,be as useTable,ge as useTableCellIds,Ze as useTableCellIdsListener,pe as useTableIds,Ue as useTableIdsListener,Ye as useTableListener,Ie as useTables,Ne as useTablesListener,ao as useUndoInformation,Le as useValue,Oe as useValueIds,it as useValueIdsListener,ct as useValueListener,qe as useValues,ut as useValuesListener,pt as useWillFinishTransactionListener};
|
|
1
|
+
import e from"react";const t=e=>typeof e,o="",r=t(o),n="Listener",l="Result",d="Has",s="has",u="Ids",i="Table",a=i+"s",c=i+u,I="Row",p=I+"Count",v=I+u,b="Sorted"+I+u,g="Cell",m=g+u,C="Value",y=C+"s",w=C+u,f=e=>null==e,k=(e,t,o)=>f(e)?null==o?void 0:o():t(e),h=e=>t(e)==r,R=()=>{},P=(e,t)=>e.map(t),x=Object.keys,q=(e,t)=>k(e,(e=>e[t])),{createContext:S,useContext:O,useEffect:L}=e,j=S([]),B=(e,t)=>{var o;const r=O(j);return f(e)?r[t]:h(e)?q(null!=(o=r[t+1])?o:{},e):e},T=(e,t)=>{const o=B(e,t);return f(e)||h(e)?o:e},E=e=>{var t;return x(null!=(t=O(j)[e])?t:{})},M=e=>B(e,0),F=e=>T(e,0),V=(e,t)=>{const{12:o,13:r}=O(j);L((()=>(null==o||o(e,t),()=>null==r?void 0:r(e))),[o,e,t,r])},A=e=>B(e,2),D=e=>T(e,2),H=e=>B(e,4),Q=e=>T(e,4),W=e=>B(e,6),z=e=>T(e,6),G=e=>B(e,8),J=e=>T(e,8),K=e=>B(e,10),N=e=>T(e,10),U=e=>e.toLowerCase();U(n);const X="Transaction";U(X);const{useCallback:Y,useEffect:Z,useMemo:$,useLayoutEffect:_,useRef:ee,useState:te}=e,oe=[],re={},ne=[[],void 0,[]],le=(e,t,o=oe)=>{const r=$((()=>t(e)),[e,...o]);return Z((()=>()=>r.destroy()),[r]),r},de=(e,t,o,r=oe,n,l="get",d="")=>{const[,s]=te(),u=Y((()=>{var n,d;return null!=(d=null==(n=null==t?void 0:t[l+e])?void 0:n.call(t,...r))?d:o}),[t,e,...r,o]),i=ee();return $((()=>i.current=u()),[u]),se(d+e,t,((...e)=>{i.current=f(n)?u():e[n],s([])}),[u,n],r),i.current},se=(e,t,o,r=oe,l=oe,...d)=>_((()=>{var r;const s=null==(r=null==t?void 0:t["add"+e+n])?void 0:r.call(t,...l,o,...d);return()=>null==t?void 0:t.delListener(s)}),[t,e,...l,...r,...d]),ue=(e,t,o,r=oe,n=R,l=oe,...d)=>{const s=F(e);return Y((e=>k(s,(r=>k(o(e,r),(e=>n(r["set"+t](...d,e),e)))))),[s,t,...r,...l,...d])},ie=(e,t,o=R,r=oe,...n)=>{const l=F(e);return Y((()=>o(null==l?void 0:l["del"+t](...n))),[l,t,...r,...n])},ae=(e,t,o)=>{const r=N(e);return Y((()=>null==r?void 0:r[t](o)),[r,t,o])},ce=(e,t=oe)=>$(e,t),Ie=()=>E(1),pe=e=>de(a,F(e),!1,[],1,s,d),ve=e=>de(a,F(e),re),be=e=>de(c,F(e),oe),ge=(e,t)=>de(i,F(t),!1,[e],2,s,d),me=(e,t)=>de(i,F(t),re,[e]),Ce=(e,t)=>de(i+m,F(t),oe,[e]),ye=(e,t,o)=>de(i+g,F(o),!1,[e,t],3,s,d),we=(e,t)=>de(p,F(t),0,[e]),fe=(e,t)=>de(v,F(t),oe,[e]),ke=(e,t,o,r=0,n,l)=>de(b,F(l),oe,[e,t,o,r,n],6),he=(e,t,o)=>de(I,F(o),!1,[e,t],3,s,d),Re=(e,t,o)=>de(I,F(o),re,[e,t]),Pe=(e,t,o)=>de(m,F(o),oe,[e,t]),xe=(e,t,o,r)=>de(g,F(r),!1,[e,t,o],4,s,d),qe=(e,t,o,r)=>de(g,F(r),void 0,[e,t,o],4),Se=e=>de(y,F(e),!1,[],1,s,d),Oe=e=>de(y,F(e),re),Le=e=>de(w,F(e),oe),je=(e,t)=>de(C,F(t),!1,[e],2,s,d),Be=(e,t)=>de(C,F(t),void 0,[e]),Te=(e,t,o,r,n)=>ue(o,a,e,t,r,n),Ee=(e,t,o,r,n,l)=>ue(r,i,t,o,n,l,e),Me=(e,t,o,r,n,l,d)=>ue(n,I,o,r,l,d,e,t),Fe=(e,t,o=oe,r,n=R,l=oe,d=!0)=>{const s=F(r);return Y((o=>k(s,(r=>k(t(o,r),(t=>n(r.addRow(e,t,d),r,t)))))),[s,e,...o,...l,d])},Ve=(e,t,o,r,n,l,d)=>ue(n,"PartialRow",o,r,l,d,e,t),Ae=(e,t,o,r,n,l,d,s)=>ue(l,g,r,n,d,s,e,t,o),De=(e,t,o,r,n)=>ue(o,y,e,t,r,n),He=(e,t,o,r,n)=>ue(o,"PartialValues",e,t,r,n),Qe=(e,t,o,r,n,l)=>ue(r,C,t,o,n,l,e),We=(e,t,o)=>ie(e,a,t,o),ze=(e,t,o,r)=>ie(t,i,o,r,e),Ge=(e,t,o,r,n)=>ie(o,I,r,n,e,t),Je=(e,t,o,r,n,l,d)=>ie(n,g,l,d,e,t,o,r),Ke=(e,t,o)=>ie(e,y,t,o),Ne=(e,t,o,r)=>ie(t,C,o,r,e),Ue=(e,t,o,r)=>se(d+a,F(r),e,t,[],o),Xe=(e,t,o,r)=>se(a,F(r),e,t,oe,o),Ye=(e,t,o,r)=>se(c,F(r),e,t,oe,o),Ze=(e,t,o,r,n)=>se(d+i,F(n),t,o,[e],r),$e=(e,t,o,r,n)=>se(i,F(n),t,o,[e],r),_e=(e,t,o,r,n)=>se(i+m,F(n),t,o,[e],r),et=(e,t,o,r,n,l)=>se(d+i+g,F(l),o,r,[e,t],n),tt=(e,t,o,r,n)=>se(p,F(n),t,o,[e],r),ot=(e,t,o,r,n)=>se(v,F(n),t,o,[e],r),rt=(e,t,o,r,n,l,d,s,u)=>se(b,F(u),l,d,[e,t,o,r,n],s),nt=(e,t,o,r,n,l)=>se(d+I,F(l),o,r,[e,t],n),lt=(e,t,o,r,n,l)=>se(I,F(l),o,r,[e,t],n),dt=(e,t,o,r,n,l)=>se(m,F(l),o,r,[e,t],n),st=(e,t,o,r,n,l,s)=>se(d+g,F(s),r,n,[e,t,o],l),ut=(e,t,o,r,n,l,d)=>se(g,F(d),r,n,[e,t,o],l),it=(e,t,o,r)=>se(d+y,F(r),e,t,[],o),at=(e,t,o,r)=>se(y,F(r),e,t,oe,o),ct=(e,t,o,r)=>se(w,F(r),e,t,oe,o),It=(e,t,o,r,n)=>se(d+C,F(n),t,o,[e],r),pt=(e,t,o,r,n)=>se(C,F(n),t,o,[e],r),vt=(e,t,o)=>se("Start"+X,F(o),e,t),bt=(e,t,o)=>se("WillFinish"+X,F(o),e,t),gt=(e,t,o)=>se("DidFinish"+X,F(o),e,t),mt=(e,t,o)=>le(e,t,o),Ct=()=>E(3),yt=e=>de("MetricIds",D(e),oe),wt=(e,t)=>de("Metric",D(t),void 0,[e]),ft=(e,t,o,r)=>se("Metric",D(r),t,o,[e]),kt=(e,t,o)=>le(e,t,o),ht=()=>E(5),Rt=(e,t)=>de("SliceIds",Q(t),oe,[e]),Pt=e=>de("IndexIds",Q(e),oe),xt=(e,t,o)=>de("Slice"+v,Q(o),oe,[e,t]),qt=(e,t,o,r)=>se("SliceIds",Q(r),t,o,[e]),St=(e,t,o,r,n)=>se("Slice"+v,Q(n),o,r,[e,t]),Ot=(e,t,o)=>le(e,t,o),Lt=()=>E(7),jt=e=>de("RelationshipIds",z(e),oe),Bt=(e,t,o)=>de("RemoteRowId",z(o),void 0,[e,t]),Tt=(e,t,o)=>de("Local"+v,z(o),oe,[e,t]),Et=(e,t,o)=>de("Linked"+v,z(o),oe,[e,t]),Mt=(e,t,o,r,n)=>se("RemoteRowId",z(n),o,r,[e,t]),Ft=(e,t,o,r,n)=>se("Local"+v,z(n),o,r,[e,t]),Vt=(e,t,o,r,n)=>se("Linked"+v,z(n),o,r,[e,t]),At=(e,t,o)=>le(e,t,o),Dt=()=>E(9),Ht=e=>de("QueryIds",J(e),oe),Qt=(e,t)=>de(l+i,J(t),re,[e]),Wt=(e,t)=>de(l+i+m,J(t),oe,[e]),zt=(e,t)=>de(l+p,J(t),0,[e]),Gt=(e,t)=>de(l+v,J(t),oe,[e]),Jt=(e,t,o,r=0,n,d)=>de(l+b,J(d),oe,[e,t,o,r,n],6),Kt=(e,t,o)=>de(l+I,J(o),re,[e,t]),Nt=(e,t,o)=>de(l+m,J(o),oe,[e,t]),Ut=(e,t,o,r)=>de(l+g,J(r),void 0,[e,t,o]),Xt=(e,t,o,r)=>se(l+i,J(r),t,o,[e]),Yt=(e,t,o,r)=>se(l+i+m,J(r),t,o,[e]),Zt=(e,t,o,r)=>se(l+p,J(r),t,o,[e]),$t=(e,t,o,r)=>se(l+v,J(r),t,o,[e]),_t=(e,t,o,r,n,d,s,u)=>se(l+b,J(u),d,s,[e,t,o,r,n]),eo=(e,t,o,r,n)=>se(l+I,J(n),o,r,[e,t]),to=(e,t,o,r,n)=>se(l+m,J(n),o,r,[e,t]),oo=(e,t,o,r,n,d)=>se(l+g,J(d),r,n,[e,t,o]),ro=(e,t,o)=>le(e,t,o),no=()=>E(11),lo=e=>de("CheckpointIds",N(e),ne),so=(e,t)=>de("Checkpoint",N(t),void 0,[e]),uo=(e=R,t=oe,o,r=R,n=oe)=>{const l=N(o);return Y((t=>k(l,(o=>{const n=e(t);r(o.addCheckpoint(n),o,n)}))),[l,...t,...n])},io=e=>ae(e,"goBackward"),ao=e=>ae(e,"goForward"),co=(e,t=oe,o,r=R,n=oe)=>{const l=N(o);return Y((t=>k(l,(o=>k(e(t),(e=>r(o.goTo(e),e)))))),[l,...t,...n])},Io=e=>{var t;const r=N(e),[n,l]=lo(r);return[(d=n,!(0==d.length)),io(r),l,null!=(t=k(l,(e=>null==r?void 0:r.getCheckpoint(e))))?t:o];var d},po=e=>{var t;const r=N(e),[,,[n]]=lo(r);return[!f(n),ao(r),n,null!=(t=k(n,(e=>null==r?void 0:r.getCheckpoint(e))))?t:o]},vo=(e,t,o)=>se("CheckpointIds",N(o),e,t),bo=(e,t,o,r)=>se("Checkpoint",N(r),t,o,[e]),go=(e,t,o=oe,r,n=oe,l,d=oe)=>{const[,s]=te(),u=$((()=>t(e)),[e,...o]);return Z((()=>{var e;return e=function*(){r&&(yield r(u),s([]))},new Promise(((t,o)=>{var r=t=>{try{l(e.next(t))}catch(e){o(e)}},n=t=>{try{l(e.throw(t))}catch(e){o(e)}},l=e=>e.done?t(e.value):Promise.resolve(e.value).then(r,n);l((e=e.apply(void 0,null)).next())})),()=>{null==u||u.destroy(),null==l||l(u)}}),[u,...n,...d]),u},{PureComponent:mo,Fragment:Co,createElement:yo,useCallback:wo,useLayoutEffect:fo,useRef:ko,useState:ho}=e,Ro=(e,...t)=>f(e)?{}:e(...t),Po=(e,t)=>[e,null==e?void 0:e.getStore(),null==e?void 0:e.getLocalTableId(t),null==e?void 0:e.getRemoteTableId(t)];var xo=Object.defineProperty,qo=Object.defineProperties,So=Object.getOwnPropertyDescriptors,Oo=Object.getOwnPropertySymbols,Lo=Object.prototype.hasOwnProperty,jo=Object.prototype.propertyIsEnumerable,Bo=(e,t,o)=>t in e?xo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,To=(e,t)=>{for(var o in t||(t={}))Lo.call(t,o)&&Bo(e,o,t[o]);if(Oo)for(var o of Oo(t))jo.call(t,o)&&Bo(e,o,t[o]);return e},Eo=(e,t)=>qo(e,So(t)),Mo=(e,t)=>{var o={};for(var r in e)Lo.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(null!=e&&Oo)for(var r of Oo(e))t.indexOf(r)<0&&jo.call(e,r)&&(o[r]=e[r]);return o};const{useCallback:Fo,useContext:Vo,useMemo:Ao,useState:Do}=e,Ho=({tableId:e,store:t,rowComponent:o=No,getRowComponentProps:r,customCellIds:n,separator:l,debugIds:d},s)=>Jo(P(s,(l=>yo(o,Eo(To({},Ro(r,l)),{key:l,tableId:e,rowId:l,customCellIds:n,store:t,debugIds:d})))),l,d,e),Qo=({queryId:e,queries:t,resultRowComponent:o=dr,getResultRowComponentProps:r,separator:n,debugIds:l},d)=>Jo(P(d,(n=>yo(o,Eo(To({},Ro(r,n)),{key:n,queryId:e,rowId:n,queries:t,debugIds:l})))),n,l,e),Wo=({relationshipId:e,relationships:t,rowComponent:o=No,getRowComponentProps:r,separator:n,debugIds:l},d,s)=>{const[u,i,a]=Po(z(t),e),c=d(e,s,u);return Jo(P(c,(e=>yo(o,Eo(To({},Ro(r,e)),{key:e,tableId:a,rowId:e,store:i,debugIds:l})))),n,l,s)},zo=e=>({checkpoints:t,checkpointComponent:o=ir,getCheckpointComponentProps:r,separator:n,debugIds:l})=>{const d=N(t);return Jo(P(e(lo(d)),(e=>yo(o,Eo(To({},Ro(r,e)),{key:e,checkpoints:d,checkpointId:e,debugIds:l})))),n)},Go=({store:e,storesById:t,metrics:o,metricsById:r,indexes:n,indexesById:l,relationships:d,relationshipsById:s,queries:u,queriesById:i,checkpoints:a,checkpointsById:c,children:I})=>{const p=Vo(j),[v,b]=Do({}),g=Fo(((e,t)=>b((o=>q(o,e)==t?o:Eo(To({},o),{[e]:t})))),[]),m=Fo((e=>b((t=>To({},((e,t)=>(delete e[t],e))(t,e))))),[]);return yo(j.Provider,{value:Ao((()=>[null!=e?e:p[0],To(To(To({},p[1]),t),v),null!=o?o:p[2],To(To({},p[3]),r),null!=n?n:p[4],To(To({},p[5]),l),null!=d?d:p[6],To(To({},p[7]),s),null!=u?u:p[8],To(To({},p[9]),i),null!=a?a:p[10],To(To({},p[11]),c),g,m]),[e,t,v,o,r,n,l,d,s,u,i,a,c,p,g,m])},I)},Jo=(e,t,o,r)=>{const n=f(t)||!Array.isArray(e)?e:P(e,((e,o)=>o>0?[t,e]:e));return o?[r,":{",n,"}"]:n},Ko=({tableId:e,rowId:t,cellId:r,store:n,debugIds:l})=>{var d;return Jo(o+(null!=(d=qe(e,t,r,n))?d:o),void 0,l,r)},No=({tableId:e,rowId:t,store:o,cellComponent:r=Ko,getCellComponentProps:n,customCellIds:l,separator:d,debugIds:s})=>Jo(P(((e,t,o,r)=>{const n=Pe(t,o,r);return null!=e?e:n})(l,e,t,o),(l=>yo(r,Eo(To({},Ro(n,l)),{key:l,tableId:e,rowId:t,cellId:l,store:o,debugIds:s})))),d,s,t),Uo=e=>Ho(e,fe(e.tableId,e.store)),Xo=e=>{var t=e,{cellId:o,descending:r,offset:n,limit:l}=t,d=Mo(t,["cellId","descending","offset","limit"]);return Ho(d,ke(d.tableId,o,r,n,l,d.store))},Yo=({store:e,tableComponent:t=Uo,getTableComponentProps:o,separator:r,debugIds:n})=>Jo(P(be(e),(r=>yo(t,Eo(To({},Ro(o,r)),{key:r,tableId:r,store:e,debugIds:n})))),r),Zo=({valueId:e,store:t,debugIds:r})=>{var n;return Jo(o+(null!=(n=Be(e,t))?n:o),void 0,r,e)},$o=({store:e,valueComponent:t=Zo,getValueComponentProps:o,separator:r,debugIds:n})=>Jo(P(Le(e),(r=>yo(t,Eo(To({},Ro(o,r)),{key:r,valueId:r,store:e,debugIds:n})))),r),_o=({metricId:e,metrics:t,debugIds:r})=>{var n;return Jo(null!=(n=wt(e,t))?n:o,void 0,r,e)},er=({indexId:e,sliceId:t,indexes:o,rowComponent:r=No,getRowComponentProps:n,separator:l,debugIds:d})=>{const[s,u,i]=((e,t)=>[e,null==e?void 0:e.getStore(),null==e?void 0:e.getTableId(t)])(Q(o),e),a=xt(e,t,s);return Jo(P(a,(e=>yo(r,Eo(To({},Ro(n,e)),{key:e,tableId:i,rowId:e,store:u,debugIds:d})))),l,d,t)},tr=({indexId:e,indexes:t,sliceComponent:o=er,getSliceComponentProps:r,separator:n,debugIds:l})=>Jo(P(Rt(e,t),(n=>yo(o,Eo(To({},Ro(r,n)),{key:n,indexId:e,sliceId:n,indexes:t,debugIds:l})))),n,l,e),or=({relationshipId:e,localRowId:t,relationships:o,rowComponent:r=No,getRowComponentProps:n,debugIds:l})=>{const[d,s,,u]=Po(z(o),e),i=Bt(e,t,d);return Jo(f(u)||f(i)?null:yo(r,Eo(To({},Ro(n,i)),{key:i,tableId:u,rowId:i,store:s,debugIds:l})),void 0,l,t)},rr=e=>Wo(e,Tt,e.remoteRowId),nr=e=>Wo(e,Et,e.firstRowId),lr=({queryId:e,rowId:t,cellId:r,queries:n,debugIds:l})=>{var d;return Jo(o+(null!=(d=Ut(e,t,r,n))?d:o),void 0,l,r)},dr=({queryId:e,rowId:t,queries:o,resultCellComponent:r=lr,getResultCellComponentProps:n,separator:l,debugIds:d})=>Jo(P(Nt(e,t,o),(l=>yo(r,Eo(To({},Ro(n,l)),{key:l,queryId:e,rowId:t,cellId:l,queries:o,debugIds:d})))),l,d,t),sr=e=>Qo(e,Gt(e.queryId,e.queries)),ur=e=>{var t=e,{cellId:o,descending:r,offset:n,limit:l}=t,d=Mo(t,["cellId","descending","offset","limit"]);return Qo(d,Jt(d.queryId,o,r,n,l,d.queries))},ir=({checkpoints:e,checkpointId:t,debugIds:r})=>{var n;return Jo(null!=(n=so(t,e))?n:o,void 0,r,t)},ar=zo((e=>e[0])),cr=zo((e=>f(e[1])?[]:[e[1]])),Ir=zo((e=>e[2]));export{ar as BackwardCheckpointsView,Ko as CellView,ir as CheckpointView,cr as CurrentCheckpointView,Ir as ForwardCheckpointsView,tr as IndexView,nr as LinkedRowsView,rr as LocalRowsView,_o as MetricView,Go as Provider,or as RemoteRowView,lr as ResultCellView,dr as ResultRowView,ur as ResultSortedTableView,sr as ResultTableView,No as RowView,er as SliceView,Xo as SortedTableView,Uo as TableView,Yo as TablesView,Zo as ValueView,$o as ValuesView,Fe as useAddRowCallback,qe as useCell,Pe as useCellIds,dt as useCellIdsListener,ut as useCellListener,so as useCheckpoint,lo as useCheckpointIds,vo as useCheckpointIdsListener,bo as useCheckpointListener,K as useCheckpoints,no as useCheckpointsIds,N as useCheckpointsOrCheckpointsById,ro as useCreateCheckpoints,kt as useCreateIndexes,mt as useCreateMetrics,go as useCreatePersister,At as useCreateQueries,Ot as useCreateRelationships,ce as useCreateStore,Je as useDelCellCallback,Ge as useDelRowCallback,ze as useDelTableCallback,We as useDelTablesCallback,Ne as useDelValueCallback,Ke as useDelValuesCallback,gt as useDidFinishTransactionListener,io as useGoBackwardCallback,ao as useGoForwardCallback,co as useGoToCallback,xe as useHasCell,st as useHasCellListener,he as useHasRow,nt as useHasRowListener,ge as useHasTable,ye as useHasTableCell,et as useHasTableCellListener,Ze as useHasTableListener,pe as useHasTables,Ue as useHasTablesListener,je as useHasValue,It as useHasValueListener,Se as useHasValues,it as useHasValuesListener,Pt as useIndexIds,H as useIndexes,ht as useIndexesIds,Q as useIndexesOrIndexesById,Et as useLinkedRowIds,Vt as useLinkedRowIdsListener,Tt as useLocalRowIds,Ft as useLocalRowIdsListener,wt as useMetric,yt as useMetricIds,ft as useMetricListener,A as useMetrics,Ct as useMetricsIds,D as useMetricsOrMetricsById,V as useProvideStore,G as useQueries,Dt as useQueriesIds,J as useQueriesOrQueriesById,Ht as useQueryIds,po as useRedoInformation,jt as useRelationshipIds,W as useRelationships,Lt as useRelationshipsIds,z as useRelationshipsOrRelationshipsById,Bt as useRemoteRowId,Mt as useRemoteRowIdListener,Ut as useResultCell,Nt as useResultCellIds,to as useResultCellIdsListener,oo as useResultCellListener,Kt as useResultRow,zt as useResultRowCount,Zt as useResultRowCountListener,Gt as useResultRowIds,$t as useResultRowIdsListener,eo as useResultRowListener,Jt as useResultSortedRowIds,_t as useResultSortedRowIdsListener,Qt as useResultTable,Wt as useResultTableCellIds,Yt as useResultTableCellIdsListener,Xt as useResultTableListener,Re as useRow,we as useRowCount,tt as useRowCountListener,fe as useRowIds,ot as useRowIdsListener,lt as useRowListener,Ae as useSetCellCallback,uo as useSetCheckpointCallback,Ve as useSetPartialRowCallback,He as useSetPartialValuesCallback,Me as useSetRowCallback,Ee as useSetTableCallback,Te as useSetTablesCallback,Qe as useSetValueCallback,De as useSetValuesCallback,Rt as useSliceIds,qt as useSliceIdsListener,xt as useSliceRowIds,St as useSliceRowIdsListener,ke as useSortedRowIds,rt as useSortedRowIdsListener,vt as useStartTransactionListener,M as useStore,Ie as useStoreIds,F as useStoreOrStoreById,me as useTable,Ce as useTableCellIds,_e as useTableCellIdsListener,be as useTableIds,Ye as useTableIdsListener,$e as useTableListener,ve as useTables,Xe as useTablesListener,Io as useUndoInformation,Be as useValue,Le as useValueIds,ct as useValueIdsListener,pt as useValueListener,Oe as useValues,at as useValuesListener,bt as useWillFinishTransactionListener};
|
package/lib/es6/ui-react.js.gz
CHANGED
|
Binary file
|
package/lib/types/metrics.d.ts
CHANGED
|
@@ -380,8 +380,8 @@ export interface Metrics {
|
|
|
380
380
|
* remove == metric
|
|
381
381
|
* ? undefined
|
|
382
382
|
* : add > 2
|
|
383
|
-
*
|
|
384
|
-
*
|
|
383
|
+
* ? Math.min(metric, add)
|
|
384
|
+
* : metric,
|
|
385
385
|
* );
|
|
386
386
|
*
|
|
387
387
|
* console.log(metrics.getMetric('lowestPriceOver2'));
|
package/lib/types/queries.d.ts
CHANGED
|
@@ -1313,49 +1313,6 @@ export type Where = {
|
|
|
1313
1313
|
* ```js
|
|
1314
1314
|
* const store = createStore()
|
|
1315
1315
|
* .setTable('pets', {
|
|
1316
|
-
* fido: {species: 'dog', color: 'brown', owner: 'alice'},
|
|
1317
|
-
* felix: {species: 'cat', color: 'black', owner: 'bob'},
|
|
1318
|
-
* cujo: {species: 'dog', color: 'black', owner: 'bob'},
|
|
1319
|
-
* lowly: {species: 'worm', color: 'brown', owner: 'alice'},
|
|
1320
|
-
* carnaby: {species: 'parrot', color: 'black', owner: 'bob'},
|
|
1321
|
-
* polly: {species: 'parrot', color: 'red', owner: 'alice'},
|
|
1322
|
-
* })
|
|
1323
|
-
* .setTable('species', {
|
|
1324
|
-
* dog: {price: 5, legs: 4},
|
|
1325
|
-
* cat: {price: 4, legs: 4},
|
|
1326
|
-
* parrot: {price: 3, legs: 2},
|
|
1327
|
-
* worm: {price: 1, legs: 0},
|
|
1328
|
-
* });
|
|
1329
|
-
*
|
|
1330
|
-
* const queries = createQueries(store);
|
|
1331
|
-
* queries.setQueryDefinition('query', 'pets', ({select, join, group}) => {
|
|
1332
|
-
* select('pets', 'color'); // group by
|
|
1333
|
-
* select('pets', 'owner'); // group by
|
|
1334
|
-
* select('species', 'price'); // grouped
|
|
1335
|
-
* select('species', 'legs'); // grouped
|
|
1336
|
-
* // from pets
|
|
1337
|
-
* join('species', 'species');
|
|
1338
|
-
* group('price', 'avg').as('avgPrice');
|
|
1339
|
-
* group('legs', 'sum').as('sumLegs');
|
|
1340
|
-
* });
|
|
1341
|
-
*
|
|
1342
|
-
* queries.forEachResultRow('query', (rowId) => {
|
|
1343
|
-
* console.log({[rowId]: queries.getResultRow('query', rowId)});
|
|
1344
|
-
* });
|
|
1345
|
-
* // -> {0: {color: 'brown', owner: 'alice', avgPrice: 3, sumLegs: 4}}
|
|
1346
|
-
* // -> {1: {color: 'black', owner: 'bob', avgPrice: 4, sumLegs: 10}}
|
|
1347
|
-
* // -> {2: {color: 'red', owner: 'alice', avgPrice: 3, sumLegs: 2}}
|
|
1348
|
-
* ```
|
|
1349
|
-
* @example
|
|
1350
|
-
* This example shows a query that calculates the a custom aggregate of one
|
|
1351
|
-
* Cell's values, grouped by another. Note how `aggregateAdd`,
|
|
1352
|
-
* `aggregateRemove`, and `aggregateReplace` parameters are provided to make the
|
|
1353
|
-
* custom aggregation more efficient as individual values are added, removed, or
|
|
1354
|
-
* replaced during the lifecycle of the Table.
|
|
1355
|
-
*
|
|
1356
|
-
* ```js
|
|
1357
|
-
* const store = createStore()
|
|
1358
|
-
* .setTable('pets', {
|
|
1359
1316
|
* fido: {species: 'dog', owner: 'alice'},
|
|
1360
1317
|
* felix: {species: 'cat', owner: 'bob'},
|
|
1361
1318
|
* cujo: {species: 'dog', owner: 'bob'},
|
|
@@ -1385,8 +1342,8 @@ export type Where = {
|
|
|
1385
1342
|
* remove == current
|
|
1386
1343
|
* ? undefined
|
|
1387
1344
|
* : add > 2
|
|
1388
|
-
*
|
|
1389
|
-
*
|
|
1345
|
+
* ? Math.min(current, add)
|
|
1346
|
+
* : current,
|
|
1390
1347
|
* ).as('lowestPriceOver2');
|
|
1391
1348
|
* });
|
|
1392
1349
|
*
|
package/lib/types/ui-react.d.ts
CHANGED
|
@@ -427,6 +427,59 @@ export function useStoreOrStoreById(
|
|
|
427
427
|
storeOrStoreId?: StoreOrStoreId,
|
|
428
428
|
): Store | undefined;
|
|
429
429
|
|
|
430
|
+
/**
|
|
431
|
+
* The useProvideStore hook is used to add a Store object by Id to a Provider
|
|
432
|
+
* component, but imperatively from a component within it.
|
|
433
|
+
*
|
|
434
|
+
* Normally you will register a Store by Id in a context by using the
|
|
435
|
+
* `storesById` prop of the top-level Provider component. This hook, however,
|
|
436
|
+
* lets you dynamically add a new Store to the context, from within a descendent
|
|
437
|
+
* component. This is useful for applications where the set of Stores is not
|
|
438
|
+
* known at the time of the first render of the root Provider.
|
|
439
|
+
*
|
|
440
|
+
* A Store added to the Provider context in this way will be available to other
|
|
441
|
+
* components within the context (using the useStore hook and so on). If you use
|
|
442
|
+
* the same Id as an existing Store registration, the new one will take priority
|
|
443
|
+
* over one provided by the `storesById` prop.
|
|
444
|
+
*
|
|
445
|
+
* Note that other components that consume a Store registered like this should
|
|
446
|
+
* defend against it being undefined at first. On the first render, the other
|
|
447
|
+
* component will likely not yet have completed the registration. In the example
|
|
448
|
+
* below, we use the null-safe `useStore('petStore')?.getTableIds()` to do this.
|
|
449
|
+
* @param storeId The Id of the Store object to be registered with the Provider.
|
|
450
|
+
* @param store The Store object to be registered.
|
|
451
|
+
* @example
|
|
452
|
+
* This example creates a Provider context. A child component registers a Store
|
|
453
|
+
* into it which is then consumable by a peer child component.
|
|
454
|
+
* ```jsx
|
|
455
|
+
* const App = () => (
|
|
456
|
+
* <Provider>
|
|
457
|
+
* <RegisterStore />
|
|
458
|
+
* <ConsumeStore />
|
|
459
|
+
* </Provider>
|
|
460
|
+
* );
|
|
461
|
+
* const RegisterStore = () => {
|
|
462
|
+
* const store = useCreateStore(() =>
|
|
463
|
+
* createStore().setCell('pets', 'fido', 'color', 'brown'),
|
|
464
|
+
* );
|
|
465
|
+
* useProvideStore('petStore', store);
|
|
466
|
+
* return null;
|
|
467
|
+
* };
|
|
468
|
+
* const ConsumeStore = () => (
|
|
469
|
+
* <span>{JSON.stringify(useStore('petStore')?.getTableIds())}</span>
|
|
470
|
+
* );
|
|
471
|
+
*
|
|
472
|
+
* const app = document.createElement('div');
|
|
473
|
+
* const root = ReactDOMClient.createRoot(app);
|
|
474
|
+
* root.render(<App />); // !act
|
|
475
|
+
* console.log(app.innerHTML);
|
|
476
|
+
* // -> '<span>["pets"]</span>'
|
|
477
|
+
* ```
|
|
478
|
+
* @category Store hooks
|
|
479
|
+
* @since v4.4.2
|
|
480
|
+
*/
|
|
481
|
+
export function useProvideStore(storeId: Id, store: Store): void;
|
|
482
|
+
|
|
430
483
|
/**
|
|
431
484
|
* The useHasTables hook returns a boolean indicating whether any Table objects
|
|
432
485
|
* exist in the Store, and registers a listener so that any changes to that
|
|
@@ -413,8 +413,8 @@ export interface Metrics<in out Schemas extends OptionalSchemas> {
|
|
|
413
413
|
* remove == metric
|
|
414
414
|
* ? undefined
|
|
415
415
|
* : add > 2
|
|
416
|
-
*
|
|
417
|
-
*
|
|
416
|
+
* ? Math.min(metric, add)
|
|
417
|
+
* : metric,
|
|
418
418
|
* );
|
|
419
419
|
*
|
|
420
420
|
* console.log(metrics.getMetric('lowestPriceOver2'));
|
|
@@ -1500,49 +1500,6 @@ export type Where<
|
|
|
1500
1500
|
* ```js
|
|
1501
1501
|
* const store = createStore()
|
|
1502
1502
|
* .setTable('pets', {
|
|
1503
|
-
* fido: {species: 'dog', color: 'brown', owner: 'alice'},
|
|
1504
|
-
* felix: {species: 'cat', color: 'black', owner: 'bob'},
|
|
1505
|
-
* cujo: {species: 'dog', color: 'black', owner: 'bob'},
|
|
1506
|
-
* lowly: {species: 'worm', color: 'brown', owner: 'alice'},
|
|
1507
|
-
* carnaby: {species: 'parrot', color: 'black', owner: 'bob'},
|
|
1508
|
-
* polly: {species: 'parrot', color: 'red', owner: 'alice'},
|
|
1509
|
-
* })
|
|
1510
|
-
* .setTable('species', {
|
|
1511
|
-
* dog: {price: 5, legs: 4},
|
|
1512
|
-
* cat: {price: 4, legs: 4},
|
|
1513
|
-
* parrot: {price: 3, legs: 2},
|
|
1514
|
-
* worm: {price: 1, legs: 0},
|
|
1515
|
-
* });
|
|
1516
|
-
*
|
|
1517
|
-
* const queries = createQueries(store);
|
|
1518
|
-
* queries.setQueryDefinition('query', 'pets', ({select, join, group}) => {
|
|
1519
|
-
* select('pets', 'color'); // group by
|
|
1520
|
-
* select('pets', 'owner'); // group by
|
|
1521
|
-
* select('species', 'price'); // grouped
|
|
1522
|
-
* select('species', 'legs'); // grouped
|
|
1523
|
-
* // from pets
|
|
1524
|
-
* join('species', 'species');
|
|
1525
|
-
* group('price', 'avg').as('avgPrice');
|
|
1526
|
-
* group('legs', 'sum').as('sumLegs');
|
|
1527
|
-
* });
|
|
1528
|
-
*
|
|
1529
|
-
* queries.forEachResultRow('query', (rowId) => {
|
|
1530
|
-
* console.log({[rowId]: queries.getResultRow('query', rowId)});
|
|
1531
|
-
* });
|
|
1532
|
-
* // -> {0: {color: 'brown', owner: 'alice', avgPrice: 3, sumLegs: 4}}
|
|
1533
|
-
* // -> {1: {color: 'black', owner: 'bob', avgPrice: 4, sumLegs: 10}}
|
|
1534
|
-
* // -> {2: {color: 'red', owner: 'alice', avgPrice: 3, sumLegs: 2}}
|
|
1535
|
-
* ```
|
|
1536
|
-
* @example
|
|
1537
|
-
* This example shows a query that calculates the a custom aggregate of one
|
|
1538
|
-
* Cell's values, grouped by another. Note how `aggregateAdd`,
|
|
1539
|
-
* `aggregateRemove`, and `aggregateReplace` parameters are provided to make the
|
|
1540
|
-
* custom aggregation more efficient as individual values are added, removed, or
|
|
1541
|
-
* replaced during the lifecycle of the Table.
|
|
1542
|
-
*
|
|
1543
|
-
* ```js
|
|
1544
|
-
* const store = createStore()
|
|
1545
|
-
* .setTable('pets', {
|
|
1546
1503
|
* fido: {species: 'dog', owner: 'alice'},
|
|
1547
1504
|
* felix: {species: 'cat', owner: 'bob'},
|
|
1548
1505
|
* cujo: {species: 'dog', owner: 'bob'},
|
|
@@ -1572,8 +1529,8 @@ export type Where<
|
|
|
1572
1529
|
* remove == current
|
|
1573
1530
|
* ? undefined
|
|
1574
1531
|
* : add > 2
|
|
1575
|
-
*
|
|
1576
|
-
*
|
|
1532
|
+
* ? Math.min(current, add)
|
|
1533
|
+
* : current,
|
|
1577
1534
|
* ).as('lowestPriceOver2');
|
|
1578
1535
|
* });
|
|
1579
1536
|
*
|
|
@@ -304,10 +304,10 @@ export type Cell<
|
|
|
304
304
|
> = CellType extends 'string'
|
|
305
305
|
? string
|
|
306
306
|
: CellType extends 'number'
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
307
|
+
? number
|
|
308
|
+
: CellType extends 'boolean'
|
|
309
|
+
? boolean
|
|
310
|
+
: string | number | boolean;
|
|
311
311
|
|
|
312
312
|
/**
|
|
313
313
|
* The CellOrUndefined type is a data structure representing the data in a
|
|
@@ -400,10 +400,10 @@ export type Value<
|
|
|
400
400
|
> = ValueType extends 'string'
|
|
401
401
|
? string
|
|
402
402
|
: ValueType extends 'number'
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
403
|
+
? number
|
|
404
|
+
: ValueType extends 'boolean'
|
|
405
|
+
? boolean
|
|
406
|
+
: string | number | boolean;
|
|
407
407
|
|
|
408
408
|
/**
|
|
409
409
|
* The ValueOrUndefined type is a data structure representing the data in a
|
|
@@ -531,6 +531,65 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
531
531
|
storeOrStoreId?: StoreOrStoreId<Schemas>,
|
|
532
532
|
) => Store<Schemas> | undefined;
|
|
533
533
|
|
|
534
|
+
/**
|
|
535
|
+
* The useProvideStore hook is used to add a Store object by Id to a Provider
|
|
536
|
+
* component, but imperatively from a component within it.
|
|
537
|
+
*
|
|
538
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
539
|
+
*
|
|
540
|
+
* ```ts override
|
|
541
|
+
* useProvideStore(storeId: Id, store: Store): void;
|
|
542
|
+
* ```
|
|
543
|
+
*
|
|
544
|
+
* Normally you will register a Store by Id in a context by using the
|
|
545
|
+
* `storesById` prop of the top-level Provider component. This hook, however,
|
|
546
|
+
* lets you dynamically add a new Store to the context, from within a descendent
|
|
547
|
+
* component. This is useful for applications where the set of Stores is not
|
|
548
|
+
* known at the time of the first render of the root Provider.
|
|
549
|
+
*
|
|
550
|
+
* A Store added to the Provider context in this way will be available to other
|
|
551
|
+
* components within the context (using the useStore hook and so on). If you use
|
|
552
|
+
* the same Id as an existing Store registration, the new one will take priority
|
|
553
|
+
* over one provided by the `storesById` prop.
|
|
554
|
+
*
|
|
555
|
+
* Note that other components that consume a Store registered like this should
|
|
556
|
+
* defend against it being undefined at first. On the first render, the other
|
|
557
|
+
* component will likely not yet have completed the registration. In the example
|
|
558
|
+
* below, we use the null-safe `useStore('petStore')?.getTableIds()` to do this.
|
|
559
|
+
* @param storeId The Id of the Store object to be registered with the Provider.
|
|
560
|
+
* @param store The Store object to be registered.
|
|
561
|
+
* @example
|
|
562
|
+
* This example creates a Provider context. A child component registers a Store
|
|
563
|
+
* into it which is then consumable by a peer child component.
|
|
564
|
+
* ```jsx
|
|
565
|
+
* const App = () => (
|
|
566
|
+
* <Provider>
|
|
567
|
+
* <RegisterStore />
|
|
568
|
+
* <ConsumeStore />
|
|
569
|
+
* </Provider>
|
|
570
|
+
* );
|
|
571
|
+
* const RegisterStore = () => {
|
|
572
|
+
* const store = useCreateStore(() =>
|
|
573
|
+
* createStore().setCell('pets', 'fido', 'color', 'brown'),
|
|
574
|
+
* );
|
|
575
|
+
* useProvideStore('petStore', store);
|
|
576
|
+
* return null;
|
|
577
|
+
* };
|
|
578
|
+
* const ConsumeStore = () => (
|
|
579
|
+
* <span>{JSON.stringify(useStore('petStore')?.getTableIds())}</span>
|
|
580
|
+
* );
|
|
581
|
+
*
|
|
582
|
+
* const app = document.createElement('div');
|
|
583
|
+
* const root = ReactDOMClient.createRoot(app);
|
|
584
|
+
* root.render(<App />); // !act
|
|
585
|
+
* console.log(app.innerHTML);
|
|
586
|
+
* // -> '<span>["pets"]</span>'
|
|
587
|
+
* ```
|
|
588
|
+
* @category Store hooks
|
|
589
|
+
* @since v4.4.2
|
|
590
|
+
*/
|
|
591
|
+
useProvideStore: (storeId: Id, store: Store<Schemas>) => void;
|
|
592
|
+
|
|
534
593
|
/**
|
|
535
594
|
* The useHasTables hook returns a boolean indicating whether any Table objects
|
|
536
595
|
* exist in the Store, and registers a listener so that any changes to that
|