tinybase 7.2.0 → 7.3.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/ui-react/index.d.ts +533 -1
- package/@types/ui-react/with-schemas/index.d.ts +620 -2
- package/min/omni/index.js +1 -1
- package/min/omni/index.js.gz +0 -0
- package/min/omni/with-schemas/index.js +1 -1
- package/min/omni/with-schemas/index.js.gz +0 -0
- package/min/ui-react/index.js +1 -1
- package/min/ui-react/index.js.gz +0 -0
- package/min/ui-react/with-schemas/index.js +1 -1
- package/min/ui-react/with-schemas/index.js.gz +0 -0
- package/min/ui-react-dom/index.js +1 -1
- package/min/ui-react-dom/index.js.gz +0 -0
- package/min/ui-react-dom/with-schemas/index.js +1 -1
- package/min/ui-react-dom/with-schemas/index.js.gz +0 -0
- package/min/ui-react-inspector/index.js +1 -1
- package/min/ui-react-inspector/index.js.gz +0 -0
- package/min/ui-react-inspector/with-schemas/index.js +1 -1
- package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
- package/omni/index.js +53 -15
- package/omni/with-schemas/index.js +53 -15
- package/package.json +4 -4
- package/readme.md +13 -13
- package/releases.md +40 -40
- package/ui-react/index.js +41 -0
- package/ui-react/with-schemas/index.js +41 -0
- package/ui-react-dom/index.js +21 -15
- package/ui-react-dom/with-schemas/index.js +21 -15
- package/ui-react-inspector/index.js +21 -15
- package/ui-react-inspector/with-schemas/index.js +21 -15
|
@@ -848,6 +848,72 @@ export function useHasTables(storeOrStoreId?: StoreOrStoreId): boolean;
|
|
|
848
848
|
*/
|
|
849
849
|
export function useTables(storeOrStoreId?: StoreOrStoreId): Tables;
|
|
850
850
|
|
|
851
|
+
/**
|
|
852
|
+
* The useTablesState hook returns a Tables object and a function to set it,
|
|
853
|
+
* following the same pattern as React's useState hook.
|
|
854
|
+
*
|
|
855
|
+
* This is a convenience hook that combines the useTables and
|
|
856
|
+
* useSetTablesCallback hooks. It's useful when you need both read and write
|
|
857
|
+
* access to all Tables in a single component.
|
|
858
|
+
*
|
|
859
|
+
* A Provider component is used to wrap part of an application in a context,
|
|
860
|
+
* and it can contain a default Store or a set of Store objects named by Id.
|
|
861
|
+
* The useTablesState hook lets you indicate which Store to use: omit the
|
|
862
|
+
* parameter for the default context Store, provide an Id for a named context
|
|
863
|
+
* Store, or provide a Store explicitly by reference.
|
|
864
|
+
* @param storeOrStoreId The Store to be accessed: omit for the default
|
|
865
|
+
* context Store, provide an Id for a named context Store, or provide an
|
|
866
|
+
* explicit reference.
|
|
867
|
+
* @returns An array containing the Tables object and a function to set it.
|
|
868
|
+
* @example
|
|
869
|
+
* This example creates a Store outside the application, which is used in the
|
|
870
|
+
* useTablesState hook by reference. A button updates the Tables when clicked.
|
|
871
|
+
*
|
|
872
|
+
* ```jsx
|
|
873
|
+
* import {createStore} from 'tinybase';
|
|
874
|
+
* import React from 'react';
|
|
875
|
+
* import {createRoot} from 'react-dom/client';
|
|
876
|
+
* import {useTablesState} from 'tinybase/ui-react';
|
|
877
|
+
*
|
|
878
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
879
|
+
* const App = () => {
|
|
880
|
+
* const [tables, setTables] = useTablesState(store);
|
|
881
|
+
* return (
|
|
882
|
+
* <div>
|
|
883
|
+
* {JSON.stringify(tables)}
|
|
884
|
+
* <button
|
|
885
|
+
* onClick={() => setTables({...tables, species: {dog: {price: 5}}})}
|
|
886
|
+
* >
|
|
887
|
+
* Add
|
|
888
|
+
* </button>
|
|
889
|
+
* </div>
|
|
890
|
+
* );
|
|
891
|
+
* };
|
|
892
|
+
*
|
|
893
|
+
* const app = document.createElement('div');
|
|
894
|
+
* const root = createRoot(app);
|
|
895
|
+
* root.render(<App />); // !act
|
|
896
|
+
* console.log(app.innerHTML);
|
|
897
|
+
* // -> '<div>{"pets":{"fido":{"species":"dog"}}}<button>Add</button></div>'
|
|
898
|
+
*
|
|
899
|
+
* const _button = app.querySelector('button');
|
|
900
|
+
* // -> _button MouseEvent('click', {bubbles: true})
|
|
901
|
+
* console.log(app.innerHTML);
|
|
902
|
+
* // ->
|
|
903
|
+
* `
|
|
904
|
+
* <div>
|
|
905
|
+
* {"pets":{"fido":{"species":"dog"}},"species":{"dog":{"price":5}}}
|
|
906
|
+
* <button>Add</button>
|
|
907
|
+
* </div>
|
|
908
|
+
* `;
|
|
909
|
+
* ```
|
|
910
|
+
* @category State hooks
|
|
911
|
+
* @since v7.3.0
|
|
912
|
+
*/
|
|
913
|
+
export function useTablesState(
|
|
914
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
915
|
+
): [Tables, (tables: Tables) => void];
|
|
916
|
+
|
|
851
917
|
/**
|
|
852
918
|
* The useTableIds hook returns the Ids of every Table in a Store, and registers
|
|
853
919
|
* a listener so that any changes to that result will cause a re-render.
|
|
@@ -1135,6 +1201,74 @@ export function useHasTable(
|
|
|
1135
1201
|
*/
|
|
1136
1202
|
export function useTable(tableId: Id, storeOrStoreId?: StoreOrStoreId): Table;
|
|
1137
1203
|
|
|
1204
|
+
/**
|
|
1205
|
+
* The useTableState hook returns a Table and a function to set it, following
|
|
1206
|
+
* the same pattern as React's useState hook.
|
|
1207
|
+
*
|
|
1208
|
+
* This is a convenience hook that combines the useTable and useSetTableCallback
|
|
1209
|
+
* hooks. It's useful when you need both read and write access to a Table in a
|
|
1210
|
+
* single component.
|
|
1211
|
+
*
|
|
1212
|
+
* A Provider component is used to wrap part of an application in a context,
|
|
1213
|
+
* and it can contain a default Store or a set of Store objects named by Id.
|
|
1214
|
+
* The useTableState hook lets you indicate which Store to use: omit the final
|
|
1215
|
+
* parameter for the default context Store, provide an Id for a named context
|
|
1216
|
+
* Store, or provide a Store explicitly by reference.
|
|
1217
|
+
* @param tableId The Id of the Table in the Store.
|
|
1218
|
+
* @param storeOrStoreId The Store to be accessed: omit for the default
|
|
1219
|
+
* context Store, provide an Id for a named context Store, or provide an
|
|
1220
|
+
* explicit reference.
|
|
1221
|
+
* @returns An array containing the Table and a function to set it.
|
|
1222
|
+
* @example
|
|
1223
|
+
* This example creates a Store outside the application, which is used in the
|
|
1224
|
+
* useTableState hook by reference. A button updates the Table when clicked.
|
|
1225
|
+
*
|
|
1226
|
+
* ```jsx
|
|
1227
|
+
* import {createStore} from 'tinybase';
|
|
1228
|
+
* import React from 'react';
|
|
1229
|
+
* import {createRoot} from 'react-dom/client';
|
|
1230
|
+
* import {useTableState} from 'tinybase/ui-react';
|
|
1231
|
+
*
|
|
1232
|
+
* const store = createStore().setTable('pets', {fido: {species: 'dog'}});
|
|
1233
|
+
* const App = () => {
|
|
1234
|
+
* const [table, setTable] = useTableState('pets', store);
|
|
1235
|
+
* return (
|
|
1236
|
+
* <div>
|
|
1237
|
+
* {JSON.stringify(table)}
|
|
1238
|
+
* <button
|
|
1239
|
+
* onClick={() => setTable({...table, felix: {species: 'cat'}})}
|
|
1240
|
+
* >
|
|
1241
|
+
* Add
|
|
1242
|
+
* </button>
|
|
1243
|
+
* </div>
|
|
1244
|
+
* );
|
|
1245
|
+
* };
|
|
1246
|
+
*
|
|
1247
|
+
* const app = document.createElement('div');
|
|
1248
|
+
* const root = createRoot(app);
|
|
1249
|
+
* root.render(<App />); // !act
|
|
1250
|
+
* console.log(app.innerHTML);
|
|
1251
|
+
* // -> '<div>{"fido":{"species":"dog"}}<button>Add</button></div>'
|
|
1252
|
+
*
|
|
1253
|
+
* const _button = app.querySelector('button');
|
|
1254
|
+
* // -> _button MouseEvent('click', {bubbles: true})
|
|
1255
|
+
* console.log(app.innerHTML);
|
|
1256
|
+
* // ->
|
|
1257
|
+
* `
|
|
1258
|
+
* <div>
|
|
1259
|
+
* {"fido":{"species":"dog"},"felix":{"species":"cat"}}
|
|
1260
|
+
* <button>Add</button>
|
|
1261
|
+
* </div>
|
|
1262
|
+
* `;
|
|
1263
|
+
* ```
|
|
1264
|
+
* @category State hooks
|
|
1265
|
+
* @since v7.3.0
|
|
1266
|
+
*/
|
|
1267
|
+
export function useTableState(
|
|
1268
|
+
tableId: Id,
|
|
1269
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
1270
|
+
): [Table, (table: Table) => void];
|
|
1271
|
+
|
|
1138
1272
|
/**
|
|
1139
1273
|
* The useTableCellIds hook returns the Ids of every Cell used across the whole
|
|
1140
1274
|
* Table, and registers a listener so that any changes to that result will cause
|
|
@@ -1924,6 +2058,68 @@ export function useRow(
|
|
|
1924
2058
|
storeOrStoreId?: StoreOrStoreId,
|
|
1925
2059
|
): Row;
|
|
1926
2060
|
|
|
2061
|
+
/**
|
|
2062
|
+
* The useRowState hook returns a Row and a function to set it, following the
|
|
2063
|
+
* same pattern as React's useState hook.
|
|
2064
|
+
*
|
|
2065
|
+
* This is a convenience hook that combines the useRow and useSetRowCallback
|
|
2066
|
+
* hooks. It's useful when you need both read and write access to a Row in a
|
|
2067
|
+
* single component.
|
|
2068
|
+
*
|
|
2069
|
+
* A Provider component is used to wrap part of an application in a context,
|
|
2070
|
+
* and it can contain a default Store or a set of Store objects named by Id.
|
|
2071
|
+
* The useRowState hook lets you indicate which Store to use: omit the final
|
|
2072
|
+
* parameter for the default context Store, provide an Id for a named context
|
|
2073
|
+
* Store, or provide a Store explicitly by reference.
|
|
2074
|
+
* @param tableId The Id of the Table in the Store.
|
|
2075
|
+
* @param rowId The Id of the Row in the Table.
|
|
2076
|
+
* @param storeOrStoreId The Store to be accessed: omit for the default
|
|
2077
|
+
* context Store, provide an Id for a named context Store, or provide an
|
|
2078
|
+
* explicit reference.
|
|
2079
|
+
* @returns An array containing the Row and a function to set it.
|
|
2080
|
+
* @example
|
|
2081
|
+
* This example creates a Store outside the application, which is used in the
|
|
2082
|
+
* useRowState hook by reference. A button updates the Row when clicked.
|
|
2083
|
+
*
|
|
2084
|
+
* ```jsx
|
|
2085
|
+
* import {createStore} from 'tinybase';
|
|
2086
|
+
* import React from 'react';
|
|
2087
|
+
* import {createRoot} from 'react-dom/client';
|
|
2088
|
+
* import {useRowState} from 'tinybase/ui-react';
|
|
2089
|
+
*
|
|
2090
|
+
* const store = createStore().setTable('t1', {r1: {c1: 'Alice', c2: 30}});
|
|
2091
|
+
* const App = () => {
|
|
2092
|
+
* const [row, setRow] = useRowState('t1', 'r1', store);
|
|
2093
|
+
* return (
|
|
2094
|
+
* <div>
|
|
2095
|
+
* {JSON.stringify(row)}
|
|
2096
|
+
* <button onClick={() => setRow({...row, c2: (row.c2 || 0) + 1})}>
|
|
2097
|
+
* Birthday
|
|
2098
|
+
* </button>
|
|
2099
|
+
* </div>
|
|
2100
|
+
* );
|
|
2101
|
+
* };
|
|
2102
|
+
*
|
|
2103
|
+
* const app = document.createElement('div');
|
|
2104
|
+
* const root = createRoot(app);
|
|
2105
|
+
* root.render(<App />); // !act
|
|
2106
|
+
* console.log(app.innerHTML);
|
|
2107
|
+
* // -> '<div>{\"c1\":\"Alice\",\"c2\":30}<button>Birthday</button></div>'
|
|
2108
|
+
*
|
|
2109
|
+
* const _button = app.querySelector('button');
|
|
2110
|
+
* // -> _button MouseEvent('click', {bubbles: true})
|
|
2111
|
+
* console.log(app.innerHTML);
|
|
2112
|
+
* // -> '<div>{\"c1\":\"Alice\",\"c2\":31}<button>Birthday</button></div>'
|
|
2113
|
+
* ```
|
|
2114
|
+
* @category State hooks
|
|
2115
|
+
* @since v7.3.0
|
|
2116
|
+
*/
|
|
2117
|
+
export function useRowState(
|
|
2118
|
+
tableId: Id,
|
|
2119
|
+
rowId: Id,
|
|
2120
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
2121
|
+
): [Row, (row: Row) => void];
|
|
2122
|
+
|
|
1927
2123
|
/**
|
|
1928
2124
|
* The useCellIds hook returns the Ids of every Cell in a given Row, in a given
|
|
1929
2125
|
* Table, and registers a listener so that any changes to that result will cause
|
|
@@ -2240,6 +2436,71 @@ export function useCell(
|
|
|
2240
2436
|
storeOrStoreId?: StoreOrStoreId,
|
|
2241
2437
|
): CellOrUndefined;
|
|
2242
2438
|
|
|
2439
|
+
/**
|
|
2440
|
+
* The useCellState hook returns a Cell from a Store and a callback to set it,
|
|
2441
|
+
* following the common React `useState` convention.
|
|
2442
|
+
*
|
|
2443
|
+
* This hook is useful for creating components that read and write a Cell in a
|
|
2444
|
+
* single line, similar to how you would use React's `useState` hook.
|
|
2445
|
+
*
|
|
2446
|
+
* The component this is used in will re-render when the Cell changes.
|
|
2447
|
+
* @param tableId The Id of the Table in the Store.
|
|
2448
|
+
* @param rowId The Id of the Row in the Table.
|
|
2449
|
+
* @param cellId The Id of the Cell in the Row.
|
|
2450
|
+
* @param storeOrStoreId The Store to get data from: omit for the default
|
|
2451
|
+
* context Store, provide an Id for a named context Store, or provide an
|
|
2452
|
+
* explicit reference.
|
|
2453
|
+
* @returns A tuple containing the current Cell and a setter callback that can
|
|
2454
|
+
* be called with a new Cell value.
|
|
2455
|
+
* @example
|
|
2456
|
+
* This example creates a Store outside the application, which is used in the
|
|
2457
|
+
* useCellState hook by reference.
|
|
2458
|
+
*
|
|
2459
|
+
* ```jsx
|
|
2460
|
+
* import {createRoot} from 'react-dom/client';
|
|
2461
|
+
* import {createStore} from 'tinybase';
|
|
2462
|
+
* import React from 'react';
|
|
2463
|
+
* import {useCellState} from 'tinybase/ui-react';
|
|
2464
|
+
*
|
|
2465
|
+
* const store = createStore().setCell('pets', 'fido', 'visits', 0);
|
|
2466
|
+
* const App = () => {
|
|
2467
|
+
* const [visits, setVisits] = useCellState(
|
|
2468
|
+
* 'pets',
|
|
2469
|
+
* 'fido',
|
|
2470
|
+
* 'visits',
|
|
2471
|
+
* store,
|
|
2472
|
+
* );
|
|
2473
|
+
* return (
|
|
2474
|
+
* <span>
|
|
2475
|
+
* Visits: {visits}
|
|
2476
|
+
* <button onClick={() => setVisits(visits + 1)}>Visit</button>
|
|
2477
|
+
* </span>
|
|
2478
|
+
* );
|
|
2479
|
+
* };
|
|
2480
|
+
*
|
|
2481
|
+
* const app = document.createElement('div');
|
|
2482
|
+
* const root = createRoot(app);
|
|
2483
|
+
* root.render(<App />); // !act
|
|
2484
|
+
* console.log(app.innerHTML);
|
|
2485
|
+
* // -> '<span>Visits: 0<button>Visit</button></span>'
|
|
2486
|
+
*
|
|
2487
|
+
* const _button = app.querySelector('button');
|
|
2488
|
+
* // -> _button MouseEvent('click', {bubbles: true})
|
|
2489
|
+
* console.log(app.innerHTML);
|
|
2490
|
+
* // -> '<span>Visits: 1<button>Visit</button></span>'
|
|
2491
|
+
*
|
|
2492
|
+
* root.unmount(); // !act
|
|
2493
|
+
* ```
|
|
2494
|
+
* @category State hooks
|
|
2495
|
+
* @since v7.3.0
|
|
2496
|
+
*/
|
|
2497
|
+
export function useCellState(
|
|
2498
|
+
tableId: Id,
|
|
2499
|
+
rowId: Id,
|
|
2500
|
+
cellId: Id,
|
|
2501
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
2502
|
+
): [CellOrUndefined, (cell: Cell) => void];
|
|
2503
|
+
|
|
2243
2504
|
/**
|
|
2244
2505
|
* The useHasValues hook returns a boolean indicating whether any Values exist
|
|
2245
2506
|
* in the Store, and registers a listener so that any changes to that result
|
|
@@ -2425,6 +2686,64 @@ export function useHasValues(storeOrStoreId?: StoreOrStoreId): boolean;
|
|
|
2425
2686
|
*/
|
|
2426
2687
|
export function useValues(storeOrStoreId?: StoreOrStoreId): Values;
|
|
2427
2688
|
|
|
2689
|
+
/**
|
|
2690
|
+
* The useValuesState hook returns a Values object and a function to set it,
|
|
2691
|
+
* following the same pattern as React's useState hook.
|
|
2692
|
+
*
|
|
2693
|
+
* This is a convenience hook that combines the useValues and
|
|
2694
|
+
* useSetValuesCallback hooks. It's useful when you need both read and write
|
|
2695
|
+
* access to all Values in a single component.
|
|
2696
|
+
*
|
|
2697
|
+
* A Provider component is used to wrap part of an application in a context,
|
|
2698
|
+
* and it can contain a default Store or a set of Store objects named by Id.
|
|
2699
|
+
* The useValuesState hook lets you indicate which Store to use: omit the
|
|
2700
|
+
* parameter for the default context Store, provide an Id for a named context
|
|
2701
|
+
* Store, or provide a Store explicitly by reference.
|
|
2702
|
+
* @param storeOrStoreId The Store to be accessed: omit for the default
|
|
2703
|
+
* context Store, provide an Id for a named context Store, or provide an
|
|
2704
|
+
* explicit reference.
|
|
2705
|
+
* @returns An array containing the Values object and a function to set it.
|
|
2706
|
+
* @example
|
|
2707
|
+
* This example creates a Store outside the application, which is used in the
|
|
2708
|
+
* useValuesState hook by reference. A button updates the Values when clicked.
|
|
2709
|
+
*
|
|
2710
|
+
* ```jsx
|
|
2711
|
+
* import {createStore} from 'tinybase';
|
|
2712
|
+
* import React from 'react';
|
|
2713
|
+
* import {createRoot} from 'react-dom/client';
|
|
2714
|
+
* import {useValuesState} from 'tinybase/ui-react';
|
|
2715
|
+
*
|
|
2716
|
+
* const store = createStore().setValues({open: true});
|
|
2717
|
+
* const App = () => {
|
|
2718
|
+
* const [values, setValues] = useValuesState(store);
|
|
2719
|
+
* return (
|
|
2720
|
+
* <div>
|
|
2721
|
+
* {JSON.stringify(values)}
|
|
2722
|
+
* <button onClick={() => setValues({...values, employees: 3})}>
|
|
2723
|
+
* Add
|
|
2724
|
+
* </button>
|
|
2725
|
+
* </div>
|
|
2726
|
+
* );
|
|
2727
|
+
* };
|
|
2728
|
+
*
|
|
2729
|
+
* const app = document.createElement('div');
|
|
2730
|
+
* const root = createRoot(app);
|
|
2731
|
+
* root.render(<App />); // !act
|
|
2732
|
+
* console.log(app.innerHTML);
|
|
2733
|
+
* // -> '<div>{"open":true}<button>Add</button></div>'
|
|
2734
|
+
*
|
|
2735
|
+
* const _button = app.querySelector('button');
|
|
2736
|
+
* // -> _button MouseEvent('click', {bubbles: true})
|
|
2737
|
+
* console.log(app.innerHTML);
|
|
2738
|
+
* // -> '<div>{"open":true,"employees":3}<button>Add</button></div>'
|
|
2739
|
+
* ```
|
|
2740
|
+
* @category State hooks
|
|
2741
|
+
* @since v7.3.0
|
|
2742
|
+
*/
|
|
2743
|
+
export function useValuesState(
|
|
2744
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
2745
|
+
): [Values, (values: Values) => void];
|
|
2746
|
+
|
|
2428
2747
|
/**
|
|
2429
2748
|
* The useValueIds hook returns the Ids of every Value in a Store, and registers
|
|
2430
2749
|
* a listener so that any changes to that result will cause a re-render.
|
|
@@ -2716,6 +3035,63 @@ export function useValue(
|
|
|
2716
3035
|
storeOrStoreId?: StoreOrStoreId,
|
|
2717
3036
|
): ValueOrUndefined;
|
|
2718
3037
|
|
|
3038
|
+
/**
|
|
3039
|
+
* The useValueState hook returns a Value from a Store and a callback to set it,
|
|
3040
|
+
* following the common React `useState` convention.
|
|
3041
|
+
*
|
|
3042
|
+
* This hook is useful for creating components that read and write a Value in a
|
|
3043
|
+
* single line, similar to how you would use React's `useState` hook.
|
|
3044
|
+
*
|
|
3045
|
+
* The component this is used in will re-render when the Value changes.
|
|
3046
|
+
* @param valueId The Id of the Value.
|
|
3047
|
+
* @param storeOrStoreId The Store to get data from: omit for the default
|
|
3048
|
+
* context Store, provide an Id for a named context Store, or provide an
|
|
3049
|
+
* explicit reference.
|
|
3050
|
+
* @returns A tuple containing the current Value and a setter callback that can
|
|
3051
|
+
* be called with a new Value.
|
|
3052
|
+
* @example
|
|
3053
|
+
* This example creates a Store outside the application, which is used in the
|
|
3054
|
+
* useValueState hook by reference.
|
|
3055
|
+
*
|
|
3056
|
+
* ```jsx
|
|
3057
|
+
* import {createRoot} from 'react-dom/client';
|
|
3058
|
+
* import {createStore} from 'tinybase';
|
|
3059
|
+
* import React from 'react';
|
|
3060
|
+
* import {useValueState} from 'tinybase/ui-react';
|
|
3061
|
+
*
|
|
3062
|
+
* const store = createStore().setValues({employees: 3});
|
|
3063
|
+
* const App = () => {
|
|
3064
|
+
* const [employees, setEmployees] = useValueState('employees', store);
|
|
3065
|
+
* return (
|
|
3066
|
+
* <span>
|
|
3067
|
+
* Employees: {employees}
|
|
3068
|
+
* <button onClick={() => setEmployees(employees + 1)}>Hire</button>
|
|
3069
|
+
* </span>
|
|
3070
|
+
* );
|
|
3071
|
+
* };
|
|
3072
|
+
*
|
|
3073
|
+
* const app = document.createElement('div');
|
|
3074
|
+
* const root = createRoot(app);
|
|
3075
|
+
* root.render(<App />); // !act
|
|
3076
|
+
* console.log(app.innerHTML);
|
|
3077
|
+
* // -> '<span>Employees: 3<button>Hire</button></span>'
|
|
3078
|
+
*
|
|
3079
|
+
* const _button = app.querySelector('button');
|
|
3080
|
+
* // -> _button MouseEvent('click', {bubbles: true})
|
|
3081
|
+
*
|
|
3082
|
+
* console.log(app.innerHTML);
|
|
3083
|
+
* // -> '<span>Employees: 4<button>Hire</button></span>'
|
|
3084
|
+
*
|
|
3085
|
+
* root.unmount(); // !act
|
|
3086
|
+
* ```
|
|
3087
|
+
* @category State hooks
|
|
3088
|
+
* @since v7.3.0
|
|
3089
|
+
*/
|
|
3090
|
+
export function useValueState(
|
|
3091
|
+
valueId: Id,
|
|
3092
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
3093
|
+
): [value: ValueOrUndefined, setValue: (value: Value) => void];
|
|
3094
|
+
|
|
2719
3095
|
/**
|
|
2720
3096
|
* The useSetTablesCallback hook returns a parameterized callback that can be
|
|
2721
3097
|
* used to set the tabular data of a Store.
|
|
@@ -10878,7 +11254,84 @@ export function useResultCellListener(
|
|
|
10878
11254
|
export function useParamValues(
|
|
10879
11255
|
queryId: Id,
|
|
10880
11256
|
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
10881
|
-
): ParamValues
|
|
11257
|
+
): ParamValues;
|
|
11258
|
+
|
|
11259
|
+
/**
|
|
11260
|
+
* The useParamValuesState hook returns an array containing all the parameter
|
|
11261
|
+
* values for a query, and a callback for changing them, providing an easy way
|
|
11262
|
+
* to bind a query's parameters to a user-controlled component.
|
|
11263
|
+
*
|
|
11264
|
+
* This is a convenience hook that combines the useParamValues and
|
|
11265
|
+
* useSetParamValuesCallback hooks. It's useful when you need both read and
|
|
11266
|
+
* write access to query parameters in a single component.
|
|
11267
|
+
*
|
|
11268
|
+
* A Provider component is used to wrap part of an application in a context,
|
|
11269
|
+
* and it can contain a default Queries object or a set of Queries objects
|
|
11270
|
+
* named by Id. The useParamValuesState hook lets you indicate which Queries
|
|
11271
|
+
* object to use: omit the final parameter for the default context Queries
|
|
11272
|
+
* object, provide an Id for a named context Queries object, or provide an
|
|
11273
|
+
* explicit reference.
|
|
11274
|
+
* @param queryId The Id of the query.
|
|
11275
|
+
* @param queriesOrQueriesId The Queries object to be accessed: omit for the
|
|
11276
|
+
* default context Queries object, provide an Id for a named context Queries
|
|
11277
|
+
* object, or provide an explicit reference.
|
|
11278
|
+
* @returns An array containing the parameter values and a function to set them.
|
|
11279
|
+
* @example
|
|
11280
|
+
* This example creates a Queries object outside the application, which is used
|
|
11281
|
+
* in the useParamValuesState hook by reference. A button updates the parameters
|
|
11282
|
+
* when clicked.
|
|
11283
|
+
*
|
|
11284
|
+
* ```jsx
|
|
11285
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
11286
|
+
* import React from 'react';
|
|
11287
|
+
* import {createRoot} from 'react-dom/client';
|
|
11288
|
+
* import {useParamValuesState} from 'tinybase/ui-react';
|
|
11289
|
+
*
|
|
11290
|
+
* const store = createStore().setTable('pets', {
|
|
11291
|
+
* fido: {species: 'dog'},
|
|
11292
|
+
* felix: {species: 'cat'},
|
|
11293
|
+
* cujo: {species: 'dog'},
|
|
11294
|
+
* });
|
|
11295
|
+
* const queries = createQueries(store);
|
|
11296
|
+
* queries.setQueryDefinition(
|
|
11297
|
+
* 'petsBySpecies',
|
|
11298
|
+
* 'pets',
|
|
11299
|
+
* ({select, where, param}) => {
|
|
11300
|
+
* select('species');
|
|
11301
|
+
* where('species', param('species'));
|
|
11302
|
+
* },
|
|
11303
|
+
* {species: 'dog'},
|
|
11304
|
+
* );
|
|
11305
|
+
*
|
|
11306
|
+
* const App = () => {
|
|
11307
|
+
* const [paramValues, setParamValues] = useParamValuesState(
|
|
11308
|
+
* 'petsBySpecies',
|
|
11309
|
+
* queries,
|
|
11310
|
+
* );
|
|
11311
|
+
* return (
|
|
11312
|
+
* <button onClick={() => setParamValues({species: 'cat'})}>
|
|
11313
|
+
* {JSON.stringify(paramValues)}
|
|
11314
|
+
* </button>
|
|
11315
|
+
* );
|
|
11316
|
+
* };
|
|
11317
|
+
*
|
|
11318
|
+
* const app = document.createElement('div');
|
|
11319
|
+
* createRoot(app).render(<App />); // !act
|
|
11320
|
+
* console.log(app.innerHTML);
|
|
11321
|
+
* // -> '<button>{"species":"dog"}</button>'
|
|
11322
|
+
*
|
|
11323
|
+
* const _button = app.querySelector('button');
|
|
11324
|
+
* // -> _button MouseEvent('click', {bubbles: true})
|
|
11325
|
+
* console.log(app.innerHTML);
|
|
11326
|
+
* // -> '<button>{"species":"cat"}</button>'
|
|
11327
|
+
* ```
|
|
11328
|
+
* @category State hooks
|
|
11329
|
+
* @since v7.3.0
|
|
11330
|
+
*/
|
|
11331
|
+
export function useParamValuesState(
|
|
11332
|
+
queryId: Id,
|
|
11333
|
+
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
11334
|
+
): [ParamValues, (paramValues: ParamValues) => void];
|
|
10882
11335
|
|
|
10883
11336
|
/**
|
|
10884
11337
|
* The useParamValue hook returns the current value of a single parameter in a
|
|
@@ -11027,6 +11480,85 @@ export function useParamValue(
|
|
|
11027
11480
|
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
11028
11481
|
): ParamValue | undefined;
|
|
11029
11482
|
|
|
11483
|
+
/**
|
|
11484
|
+
* The useParamValueState hook returns a parameter value and a function to set
|
|
11485
|
+
* it, following the same pattern as React's useState hook.
|
|
11486
|
+
*
|
|
11487
|
+
* This is a convenience hook that combines the useParamValue and
|
|
11488
|
+
* useSetParamValueCallback hooks. It's useful when you need both read and write
|
|
11489
|
+
* access to a query parameter in a single component.
|
|
11490
|
+
*
|
|
11491
|
+
* A Provider component is used to wrap part of an application in a context,
|
|
11492
|
+
* and it can contain a default Queries object or a set of Queries objects
|
|
11493
|
+
* named by Id. The useParamValueState hook lets you indicate which Queries
|
|
11494
|
+
* object to use: omit the final parameter for the default context Queries
|
|
11495
|
+
* object, provide an Id for a named context Queries object, or provide an
|
|
11496
|
+
* explicit reference.
|
|
11497
|
+
* @param queryId The Id of the query.
|
|
11498
|
+
* @param paramId The Id of the parameter.
|
|
11499
|
+
* @param queriesOrQueriesId The Queries object to be accessed: omit for the
|
|
11500
|
+
* default context Queries object, provide an Id for a named context Queries
|
|
11501
|
+
* object, or provide an explicit reference.
|
|
11502
|
+
* @returns An array containing the parameter value and a function to set it.
|
|
11503
|
+
* @example
|
|
11504
|
+
* This example creates a Queries object outside the application, which is used
|
|
11505
|
+
* in the useParamValueState hook by reference. A button updates the parameter
|
|
11506
|
+
* when clicked.
|
|
11507
|
+
*
|
|
11508
|
+
* ```jsx
|
|
11509
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
11510
|
+
* import React from 'react';
|
|
11511
|
+
* import {createRoot} from 'react-dom/client';
|
|
11512
|
+
* import {useParamValueState} from 'tinybase/ui-react';
|
|
11513
|
+
*
|
|
11514
|
+
* const store = createStore().setTable('pets', {
|
|
11515
|
+
* fido: {species: 'dog'},
|
|
11516
|
+
* felix: {species: 'cat'},
|
|
11517
|
+
* });
|
|
11518
|
+
* const queries = createQueries(store);
|
|
11519
|
+
* queries.setQueryDefinition(
|
|
11520
|
+
* 'petsBySpecies',
|
|
11521
|
+
* 'pets',
|
|
11522
|
+
* ({select, where, param}) => {
|
|
11523
|
+
* select('species');
|
|
11524
|
+
* where('species', param('species'));
|
|
11525
|
+
* },
|
|
11526
|
+
* {species: 'dog'},
|
|
11527
|
+
* );
|
|
11528
|
+
* const App = () => {
|
|
11529
|
+
* const [species, setSpecies] = useParamValueState(
|
|
11530
|
+
* 'petsBySpecies',
|
|
11531
|
+
* 'species',
|
|
11532
|
+
* queries,
|
|
11533
|
+
* );
|
|
11534
|
+
* return (
|
|
11535
|
+
* <div>
|
|
11536
|
+
* Species: {species}
|
|
11537
|
+
* <button onClick={() => setSpecies('cat')}>Change</button>
|
|
11538
|
+
* </div>
|
|
11539
|
+
* );
|
|
11540
|
+
* };
|
|
11541
|
+
*
|
|
11542
|
+
* const app = document.createElement('div');
|
|
11543
|
+
* const root = createRoot(app);
|
|
11544
|
+
* root.render(<App />); // !act
|
|
11545
|
+
* console.log(app.innerHTML);
|
|
11546
|
+
* // -> '<div>Species: dog<button>Change</button></div>'
|
|
11547
|
+
*
|
|
11548
|
+
* const _button = app.querySelector('button');
|
|
11549
|
+
* // -> _button MouseEvent('click', {bubbles: true})
|
|
11550
|
+
* console.log(app.innerHTML);
|
|
11551
|
+
* // -> '<div>Species: cat<button>Change</button></div>'
|
|
11552
|
+
* ```
|
|
11553
|
+
* @category State hooks
|
|
11554
|
+
* @since v7.3.0
|
|
11555
|
+
*/
|
|
11556
|
+
export function useParamValueState(
|
|
11557
|
+
queryId: Id,
|
|
11558
|
+
paramId: Id,
|
|
11559
|
+
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
11560
|
+
): [ParamValue | undefined, (paramValue: ParamValue) => void];
|
|
11561
|
+
|
|
11030
11562
|
/**
|
|
11031
11563
|
* The useParamValuesListener hook registers a listener function with a Queries
|
|
11032
11564
|
* object that will be called whenever the parameter values for a query change.
|