tinybase 4.1.0-beta.1 → 4.1.0-beta.3
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/bin/cli.js +1 -1
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/cjs/checkpoints.cjs +1 -1
- package/lib/cjs/checkpoints.cjs.gz +0 -0
- package/lib/cjs/indexes.cjs +1 -1
- package/lib/cjs/indexes.cjs.gz +0 -0
- package/lib/cjs/metrics.cjs +1 -1
- package/lib/cjs/metrics.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-browser.cjs +1 -1
- package/lib/cjs/persisters/persister-browser.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-cr-sqlite-wasm.cjs +1 -1
- package/lib/cjs/persisters/persister-cr-sqlite-wasm.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-file.cjs +1 -1
- package/lib/cjs/persisters/persister-file.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-remote.cjs +1 -1
- package/lib/cjs/persisters/persister-remote.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-sqlite-wasm.cjs +1 -1
- package/lib/cjs/persisters/persister-sqlite-wasm.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-sqlite3.cjs +1 -1
- package/lib/cjs/persisters/persister-sqlite3.cjs.gz +0 -0
- package/lib/cjs/queries.cjs +1 -1
- package/lib/cjs/queries.cjs.gz +0 -0
- package/lib/cjs/relationships.cjs +1 -1
- package/lib/cjs/relationships.cjs.gz +0 -0
- package/lib/cjs/store.cjs +1 -1
- package/lib/cjs/store.cjs.gz +0 -0
- package/lib/cjs/tinybase.cjs +1 -1
- package/lib/cjs/tinybase.cjs.gz +0 -0
- package/lib/cjs/tools.cjs +1 -1
- package/lib/cjs/tools.cjs.gz +0 -0
- package/lib/cjs/ui-react-dom.cjs +1 -1
- package/lib/cjs/ui-react-dom.cjs.gz +0 -0
- package/lib/cjs/ui-react.cjs +1 -1
- package/lib/cjs/ui-react.cjs.gz +0 -0
- package/lib/cjs-es6/checkpoints.cjs +1 -1
- package/lib/cjs-es6/checkpoints.cjs.gz +0 -0
- package/lib/cjs-es6/indexes.cjs +1 -1
- package/lib/cjs-es6/indexes.cjs.gz +0 -0
- package/lib/cjs-es6/metrics.cjs +1 -1
- package/lib/cjs-es6/metrics.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-browser.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-browser.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-cr-sqlite-wasm.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-cr-sqlite-wasm.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-file.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-file.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-remote.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-remote.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-sqlite-wasm.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-sqlite-wasm.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-sqlite3.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-sqlite3.cjs.gz +0 -0
- package/lib/cjs-es6/queries.cjs +1 -1
- package/lib/cjs-es6/queries.cjs.gz +0 -0
- package/lib/cjs-es6/relationships.cjs +1 -1
- package/lib/cjs-es6/relationships.cjs.gz +0 -0
- package/lib/cjs-es6/store.cjs +1 -1
- package/lib/cjs-es6/store.cjs.gz +0 -0
- package/lib/cjs-es6/tinybase.cjs +1 -1
- package/lib/cjs-es6/tinybase.cjs.gz +0 -0
- package/lib/cjs-es6/tools.cjs +1 -1
- package/lib/cjs-es6/tools.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react-dom.cjs +1 -1
- package/lib/cjs-es6/ui-react-dom.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 +6 -6
- package/lib/debug/indexes.js +7 -7
- package/lib/debug/metrics.js +12 -12
- package/lib/debug/persisters/persister-browser.js +10 -19
- package/lib/debug/persisters/persister-cr-sqlite-wasm.js +6 -15
- package/lib/debug/persisters/persister-file.js +10 -19
- package/lib/debug/persisters/persister-remote.js +10 -19
- package/lib/debug/persisters/persister-sqlite-wasm.js +6 -15
- package/lib/debug/persisters/persister-sqlite3.js +6 -15
- package/lib/debug/persisters.js +4 -4
- package/lib/debug/queries.js +1 -0
- package/lib/debug/relationships.js +7 -7
- package/lib/debug/store.js +16 -24
- package/lib/debug/tinybase.js +21 -28
- package/lib/debug/tools.js +14 -13
- package/lib/debug/ui-react-dom.js +253 -33
- package/lib/debug/ui-react.js +26 -4
- package/lib/es6/checkpoints.js +1 -1
- package/lib/es6/checkpoints.js.gz +0 -0
- package/lib/es6/indexes.js +1 -1
- package/lib/es6/indexes.js.gz +0 -0
- package/lib/es6/metrics.js +1 -1
- package/lib/es6/metrics.js.gz +0 -0
- package/lib/es6/persisters/persister-browser.js +1 -1
- package/lib/es6/persisters/persister-browser.js.gz +0 -0
- package/lib/es6/persisters/persister-cr-sqlite-wasm.js +1 -1
- package/lib/es6/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
- package/lib/es6/persisters/persister-file.js +1 -1
- package/lib/es6/persisters/persister-file.js.gz +0 -0
- package/lib/es6/persisters/persister-remote.js +1 -1
- package/lib/es6/persisters/persister-remote.js.gz +0 -0
- package/lib/es6/persisters/persister-sqlite-wasm.js +1 -1
- package/lib/es6/persisters/persister-sqlite-wasm.js.gz +0 -0
- package/lib/es6/persisters/persister-sqlite3.js +1 -1
- package/lib/es6/persisters/persister-sqlite3.js.gz +0 -0
- package/lib/es6/queries.js +1 -1
- package/lib/es6/queries.js.gz +0 -0
- package/lib/es6/relationships.js +1 -1
- package/lib/es6/relationships.js.gz +0 -0
- package/lib/es6/store.js +1 -1
- package/lib/es6/store.js.gz +0 -0
- package/lib/es6/tinybase.js +1 -1
- package/lib/es6/tinybase.js.gz +0 -0
- package/lib/es6/tools.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/es6/ui-react-dom.js +1 -1
- package/lib/es6/ui-react-dom.js.gz +0 -0
- package/lib/es6/ui-react.js +1 -1
- package/lib/es6/ui-react.js.gz +0 -0
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/persisters/persister-browser.js +1 -1
- package/lib/persisters/persister-browser.js.gz +0 -0
- package/lib/persisters/persister-cr-sqlite-wasm.js +1 -1
- package/lib/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
- package/lib/persisters/persister-file.js +1 -1
- package/lib/persisters/persister-file.js.gz +0 -0
- package/lib/persisters/persister-remote.js +1 -1
- package/lib/persisters/persister-remote.js.gz +0 -0
- package/lib/persisters/persister-sqlite-wasm.js +1 -1
- package/lib/persisters/persister-sqlite-wasm.js.gz +0 -0
- package/lib/persisters/persister-sqlite3.js +1 -1
- package/lib/persisters/persister-sqlite3.js.gz +0 -0
- package/lib/queries.js +1 -1
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/tools.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/types/queries.d.ts +167 -0
- package/lib/types/ui-react-dom.d.ts +568 -70
- package/lib/types/ui-react.d.ts +269 -58
- package/lib/types/with-schemas/internal/ui-react.d.ts +32 -22
- package/lib/types/with-schemas/queries.d.ts +185 -0
- package/lib/types/with-schemas/ui-react-dom.d.ts +647 -93
- package/lib/types/with-schemas/ui-react.d.ts +281 -50
- package/lib/ui-react-dom.js +1 -1
- package/lib/ui-react-dom.js.gz +0 -0
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.js +1 -1
- package/lib/umd/checkpoints.js.gz +0 -0
- package/lib/umd/indexes.js +1 -1
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/metrics.js +1 -1
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/persisters/persister-browser.js +1 -1
- package/lib/umd/persisters/persister-browser.js.gz +0 -0
- package/lib/umd/persisters/persister-cr-sqlite-wasm.js +1 -1
- package/lib/umd/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
- package/lib/umd/persisters/persister-file.js +1 -1
- package/lib/umd/persisters/persister-file.js.gz +0 -0
- package/lib/umd/persisters/persister-remote.js +1 -1
- package/lib/umd/persisters/persister-remote.js.gz +0 -0
- package/lib/umd/persisters/persister-sqlite-wasm.js +1 -1
- package/lib/umd/persisters/persister-sqlite-wasm.js.gz +0 -0
- package/lib/umd/persisters/persister-sqlite3.js +1 -1
- package/lib/umd/persisters/persister-sqlite3.js.gz +0 -0
- package/lib/umd/queries.js +1 -1
- package/lib/umd/queries.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd/ui-react-dom.js +1 -1
- package/lib/umd/ui-react-dom.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/checkpoints.js +1 -1
- package/lib/umd-es6/checkpoints.js.gz +0 -0
- package/lib/umd-es6/indexes.js +1 -1
- package/lib/umd-es6/indexes.js.gz +0 -0
- package/lib/umd-es6/metrics.js +1 -1
- package/lib/umd-es6/metrics.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-browser.js +1 -1
- package/lib/umd-es6/persisters/persister-browser.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-cr-sqlite-wasm.js +1 -1
- package/lib/umd-es6/persisters/persister-cr-sqlite-wasm.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-file.js +1 -1
- package/lib/umd-es6/persisters/persister-file.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-remote.js +1 -1
- package/lib/umd-es6/persisters/persister-remote.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-sqlite-wasm.js +1 -1
- package/lib/umd-es6/persisters/persister-sqlite-wasm.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-sqlite3.js +1 -1
- package/lib/umd-es6/persisters/persister-sqlite3.js.gz +0 -0
- package/lib/umd-es6/queries.js +1 -1
- package/lib/umd-es6/queries.js.gz +0 -0
- package/lib/umd-es6/relationships.js +1 -1
- package/lib/umd-es6/relationships.js.gz +0 -0
- package/lib/umd-es6/store.js +1 -1
- package/lib/umd-es6/store.js.gz +0 -0
- package/lib/umd-es6/tinybase.js +1 -1
- package/lib/umd-es6/tinybase.js.gz +0 -0
- package/lib/umd-es6/tools.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/lib/umd-es6/ui-react-dom.js +1 -1
- package/lib/umd-es6/ui-react-dom.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 +17 -17
- package/readme.md +2 -2
|
@@ -14,14 +14,79 @@
|
|
|
14
14
|
import {CellIdFromSchema, TableIdFromSchema} from './internal/store';
|
|
15
15
|
import {
|
|
16
16
|
CellProps,
|
|
17
|
+
CellPropsForTableIdAndCellId,
|
|
17
18
|
ComponentReturnType,
|
|
18
19
|
ExtraProps,
|
|
20
|
+
QueriesOrQueriesId,
|
|
21
|
+
ResultCellProps,
|
|
19
22
|
StoreOrStoreId,
|
|
20
23
|
ValueProps,
|
|
21
24
|
} from './internal/ui-react';
|
|
25
|
+
import {Id, Ids} from './common';
|
|
22
26
|
import {ComponentType} from 'react';
|
|
23
|
-
import {
|
|
24
|
-
|
|
27
|
+
import {OptionalSchemas} from './store';
|
|
28
|
+
|
|
29
|
+
// CustomCell
|
|
30
|
+
export type CustomCell<
|
|
31
|
+
Schemas extends OptionalSchemas,
|
|
32
|
+
TableId extends TableIdFromSchema<Schemas[0]>,
|
|
33
|
+
CellId extends CellIdFromSchema<Schemas[0], TableId>,
|
|
34
|
+
> = {
|
|
35
|
+
/**
|
|
36
|
+
* An optional string that will be used as the label at the top of the table
|
|
37
|
+
* column for this Cell.
|
|
38
|
+
*/
|
|
39
|
+
readonly label?: string;
|
|
40
|
+
/**
|
|
41
|
+
* An optional custom component for rendering each Cell in the Table (to
|
|
42
|
+
* override the default CellView component).
|
|
43
|
+
*/
|
|
44
|
+
readonly component?: ComponentType<
|
|
45
|
+
CellPropsForTableIdAndCellId<Schemas, TableId, CellId>
|
|
46
|
+
>;
|
|
47
|
+
/**
|
|
48
|
+
* An optional function for generating extra props for each custom Cell
|
|
49
|
+
* component based on Row and Cell Id.
|
|
50
|
+
*/
|
|
51
|
+
readonly getComponentProps?: (rowId: Id, cellId: CellId) => ExtraProps;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// CustomResultCell
|
|
55
|
+
export type CustomResultCell<Schemas extends OptionalSchemas> = {
|
|
56
|
+
/**
|
|
57
|
+
* An optional string that will be used as the label at the top of the table
|
|
58
|
+
* column for this Cell.
|
|
59
|
+
*/
|
|
60
|
+
readonly label?: string;
|
|
61
|
+
/**
|
|
62
|
+
* An optional custom component for rendering each Cell in the ResultTable (to
|
|
63
|
+
* override the default ResultCellView component).
|
|
64
|
+
*/
|
|
65
|
+
readonly component?: ComponentType<ResultCellProps<Schemas>>;
|
|
66
|
+
/**
|
|
67
|
+
* An optional function for generating extra props for each custom Cell
|
|
68
|
+
* component based on Row and Cell Id.
|
|
69
|
+
*/
|
|
70
|
+
readonly getComponentProps?: (rowId: Id, cellId: Id) => ExtraProps;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// HtmlTableProps
|
|
74
|
+
export type HtmlTableProps = {
|
|
75
|
+
/**
|
|
76
|
+
* A string className to use on the root of the resulting element.
|
|
77
|
+
*/
|
|
78
|
+
readonly className?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Whether a header row should be rendered at the top of the table, defaulting
|
|
81
|
+
* to `true`.
|
|
82
|
+
*/
|
|
83
|
+
readonly headerRow?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Whether an Id column should be rendered on the left of the table,
|
|
86
|
+
* defaulting to `true`.
|
|
87
|
+
*/
|
|
88
|
+
readonly idColumn?: boolean;
|
|
89
|
+
};
|
|
25
90
|
|
|
26
91
|
// TableInHtmlTableProps
|
|
27
92
|
export type TableInHtmlTableProps<
|
|
@@ -42,34 +107,25 @@ export type TableInHtmlTableProps<
|
|
|
42
107
|
*/
|
|
43
108
|
readonly store?: StoreOrStoreId<Schemas>;
|
|
44
109
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
|
|
48
|
-
readonly cellComponent?: ComponentType<CellProps<Schemas>>;
|
|
49
|
-
/**
|
|
50
|
-
* A function for generating extra props for each custom Cell component based
|
|
51
|
-
* on its Id.
|
|
52
|
-
*/
|
|
53
|
-
readonly getCellComponentProps?: (rowId: Id, cellId: Id) => ExtraProps;
|
|
54
|
-
/**
|
|
55
|
-
* A string className to use on the root of the resulting element.
|
|
56
|
-
*/
|
|
57
|
-
readonly className?: string;
|
|
58
|
-
/**
|
|
59
|
-
* Whether a header row should be rendered at the top of the table, defaulting
|
|
60
|
-
* to `true`.
|
|
61
|
-
*/
|
|
62
|
-
readonly headerRow?: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Whether an Id column should be rendered on the left of the table,
|
|
65
|
-
* defaulting to `true`.
|
|
110
|
+
* Whether the Cells should be editable. This affects the default CellView
|
|
111
|
+
* component (to use the EditableCellView component instead) but of course
|
|
112
|
+
* will not affect custom Cell components if you have set them.
|
|
66
113
|
*/
|
|
67
|
-
readonly
|
|
114
|
+
readonly editable?: boolean;
|
|
68
115
|
/**
|
|
69
116
|
* An optional list of Cell Ids to use for rendering a prescribed set of the
|
|
70
|
-
*
|
|
117
|
+
* Table's Cells in a given order. This can also be an object with the desired
|
|
118
|
+
* Cell Ids as keys, and with a value that can either be a string label to
|
|
119
|
+
* show in the column header, or a CustomCell object to further configure the
|
|
120
|
+
* column.
|
|
71
121
|
*/
|
|
72
|
-
readonly
|
|
122
|
+
readonly customCells?:
|
|
123
|
+
| CellIdFromSchema<Schemas[0], TableId>[]
|
|
124
|
+
| {
|
|
125
|
+
[CellId in CellIdFromSchema<Schemas[0], TableId>]?:
|
|
126
|
+
| string
|
|
127
|
+
| CustomCell<Schemas, TableId, CellId>;
|
|
128
|
+
};
|
|
73
129
|
}
|
|
74
130
|
: never
|
|
75
131
|
: never;
|
|
@@ -91,7 +147,7 @@ export type SortedTableInHtmlTableProps<
|
|
|
91
147
|
* The Id of the Cell whose values are used for the sorting. If omitted, the
|
|
92
148
|
* view will sort the Row Id itself.
|
|
93
149
|
*/
|
|
94
|
-
readonly cellId?:
|
|
150
|
+
readonly cellId?: CellIdFromSchema<Schemas[0], TableId>;
|
|
95
151
|
/**
|
|
96
152
|
* Whether the sorting should be in descending order.
|
|
97
153
|
*/
|
|
@@ -110,34 +166,25 @@ export type SortedTableInHtmlTableProps<
|
|
|
110
166
|
*/
|
|
111
167
|
readonly store?: StoreOrStoreId<Schemas>;
|
|
112
168
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
|
|
116
|
-
readonly cellComponent?: ComponentType<CellProps<Schemas>>;
|
|
117
|
-
/**
|
|
118
|
-
* A function for generating extra props for each custom Cell component based
|
|
119
|
-
* on its Id.
|
|
120
|
-
*/
|
|
121
|
-
readonly getCellComponentProps?: (rowId: Id, cellId: Id) => ExtraProps;
|
|
122
|
-
/**
|
|
123
|
-
* A string className to use on the root of the resulting element.
|
|
124
|
-
*/
|
|
125
|
-
readonly className?: string;
|
|
126
|
-
/**
|
|
127
|
-
* Whether a header row should be rendered at the top of the table, defaulting
|
|
128
|
-
* to `true`.
|
|
169
|
+
* Whether the Cells should be editable. This affects the default CellView
|
|
170
|
+
* component (to use the EditableCellView component instead) but of course
|
|
171
|
+
* will not affect custom Cell components if you have set them.
|
|
129
172
|
*/
|
|
130
|
-
readonly
|
|
131
|
-
/**
|
|
132
|
-
* Whether an Id column should be rendered on the left of the table,
|
|
133
|
-
* defaulting to `true`.
|
|
134
|
-
*/
|
|
135
|
-
readonly idColumn?: boolean;
|
|
173
|
+
readonly editable?: boolean;
|
|
136
174
|
/**
|
|
137
175
|
* An optional list of Cell Ids to use for rendering a prescribed set of the
|
|
138
|
-
*
|
|
176
|
+
* Table's Cells in a given order. This can also be an object with the desired
|
|
177
|
+
* Cell Ids as keys, and with a value that can either be a string label to
|
|
178
|
+
* show in the column header, or a CustomCell object to further configure the
|
|
179
|
+
* column.
|
|
139
180
|
*/
|
|
140
|
-
readonly
|
|
181
|
+
readonly customCells?:
|
|
182
|
+
| CellIdFromSchema<Schemas[0], TableId>[]
|
|
183
|
+
| {
|
|
184
|
+
[CellId in CellIdFromSchema<Schemas[0], TableId>]?:
|
|
185
|
+
| string
|
|
186
|
+
| CustomCell<Schemas, TableId, CellId>;
|
|
187
|
+
};
|
|
141
188
|
/**
|
|
142
189
|
* Whether the table should be interactive such that clicking a header changes
|
|
143
190
|
* the sorting and/or direction.
|
|
@@ -147,6 +194,79 @@ export type SortedTableInHtmlTableProps<
|
|
|
147
194
|
: never
|
|
148
195
|
: never;
|
|
149
196
|
|
|
197
|
+
// ResultTableInHtmlTableProps
|
|
198
|
+
export type ResultTableInHtmlTableProps<Schemas extends OptionalSchemas> = {
|
|
199
|
+
/**
|
|
200
|
+
* The Id of the query in the Queries object for which the ResultTable will be
|
|
201
|
+
* rendered.
|
|
202
|
+
*/
|
|
203
|
+
readonly queryId: Id;
|
|
204
|
+
/**
|
|
205
|
+
* The Queries object to be accessed: omit for the default context Queries
|
|
206
|
+
* object, provide an Id for a named context Queries object, or provide an
|
|
207
|
+
* explicit reference.
|
|
208
|
+
*/
|
|
209
|
+
readonly queries?: QueriesOrQueriesId<Schemas>;
|
|
210
|
+
/**
|
|
211
|
+
* An optional list of Cell Ids to use for rendering a prescribed set of the
|
|
212
|
+
* ResultTable's Cells in a given order. This can also be an object with the
|
|
213
|
+
* desired Cell Ids as keys, and with a value that can either be a string
|
|
214
|
+
* label to show in the column header, or a ResultCustomCell object to further
|
|
215
|
+
* configure the column.
|
|
216
|
+
*/
|
|
217
|
+
readonly customCells?:
|
|
218
|
+
| Ids
|
|
219
|
+
| {[cellId: Id]: string | CustomResultCell<Schemas>};
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// ResultSortedTableInHtmlTableProps
|
|
223
|
+
export type ResultSortedTableInHtmlTableProps<Schemas extends OptionalSchemas> =
|
|
224
|
+
{
|
|
225
|
+
/**
|
|
226
|
+
* The Id of the query in the Queries object for which the ResultTable will be
|
|
227
|
+
* rendered.
|
|
228
|
+
*/
|
|
229
|
+
readonly queryId: Id;
|
|
230
|
+
/**
|
|
231
|
+
* The Id of the Cell whose values are used for the sorting. If omitted, the
|
|
232
|
+
* view will sort the Row Id itself.
|
|
233
|
+
*/
|
|
234
|
+
readonly cellId?: Id;
|
|
235
|
+
/**
|
|
236
|
+
* Whether the sorting should be in descending order.
|
|
237
|
+
*/
|
|
238
|
+
readonly descending?: boolean;
|
|
239
|
+
/**
|
|
240
|
+
* The number of Row Ids to skip for pagination purposes.
|
|
241
|
+
*/
|
|
242
|
+
readonly offset?: number;
|
|
243
|
+
/**
|
|
244
|
+
* The maximum number of Row Ids to return.
|
|
245
|
+
*/
|
|
246
|
+
readonly limit?: number;
|
|
247
|
+
/**
|
|
248
|
+
* The Queries object to be accessed: omit for the default context Queries
|
|
249
|
+
* object, provide an Id for a named context Queries object, or provide an
|
|
250
|
+
* explicit reference.
|
|
251
|
+
*/
|
|
252
|
+
readonly queries?: QueriesOrQueriesId<Schemas>;
|
|
253
|
+
/**
|
|
254
|
+
* An optional list of Cell Ids to use for rendering a prescribed set of the
|
|
255
|
+
* ResultTable's Cells in a given order. This can also be an object with the
|
|
256
|
+
* desired Cell Ids as keys, and with a value that can either be a string
|
|
257
|
+
* label to show in the column header, or a ResultCustomCell object to further
|
|
258
|
+
* configure the column.
|
|
259
|
+
*/
|
|
260
|
+
readonly customCells?:
|
|
261
|
+
| Ids
|
|
262
|
+
| {[cellId: Id]: string | CustomResultCell<Schemas>};
|
|
263
|
+
/**
|
|
264
|
+
* Whether the table should be interactive such that clicking a header changes
|
|
265
|
+
* the sorting and/or direction.
|
|
266
|
+
*/
|
|
267
|
+
readonly sortOnClick?: boolean;
|
|
268
|
+
};
|
|
269
|
+
|
|
150
270
|
// ValuesInHtmlTableProps
|
|
151
271
|
export type ValuesInHtmlTableProps<Schemas extends OptionalSchemas> = {
|
|
152
272
|
/**
|
|
@@ -154,6 +274,12 @@ export type ValuesInHtmlTableProps<Schemas extends OptionalSchemas> = {
|
|
|
154
274
|
* for a named context Store, or provide an explicit reference.
|
|
155
275
|
*/
|
|
156
276
|
readonly store?: StoreOrStoreId<Schemas>;
|
|
277
|
+
/**
|
|
278
|
+
* Whether the Values should be editable. This affects the default ValueView
|
|
279
|
+
* component (to use the EditableValueView component instead) but of course
|
|
280
|
+
* will not affect a custom valueComponent if you have set one.
|
|
281
|
+
*/
|
|
282
|
+
readonly editable?: boolean;
|
|
157
283
|
/**
|
|
158
284
|
* A custom component for rendering each Value in the Store (to override the
|
|
159
285
|
* default ValueView component).
|
|
@@ -164,20 +290,6 @@ export type ValuesInHtmlTableProps<Schemas extends OptionalSchemas> = {
|
|
|
164
290
|
* on its Id.
|
|
165
291
|
*/
|
|
166
292
|
readonly getValueComponentProps?: (valueId: Id) => ExtraProps;
|
|
167
|
-
/**
|
|
168
|
-
* A string className to use on the root of the resulting element.
|
|
169
|
-
*/
|
|
170
|
-
readonly className?: string;
|
|
171
|
-
/**
|
|
172
|
-
* Whether a header row should be rendered at the top of the table, defaulting
|
|
173
|
-
* to `true`.
|
|
174
|
-
*/
|
|
175
|
-
readonly headerRow?: boolean;
|
|
176
|
-
/**
|
|
177
|
-
* Whether an Id column should be rendered on the left of the table,
|
|
178
|
-
* defaulting to `true`.
|
|
179
|
-
*/
|
|
180
|
-
readonly idColumn?: boolean;
|
|
181
293
|
};
|
|
182
294
|
|
|
183
295
|
export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
@@ -190,7 +302,7 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
190
302
|
*
|
|
191
303
|
* ```ts override
|
|
192
304
|
* TableInHtmlTable(
|
|
193
|
-
* props: TableInHtmlTableProps,
|
|
305
|
+
* props: TableInHtmlTableProps & HtmlTableProps,
|
|
194
306
|
* ): ComponentReturnType;
|
|
195
307
|
* ```
|
|
196
308
|
*
|
|
@@ -201,11 +313,11 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
201
313
|
* See the <TableInHtmlTable /> demo for this component in action.
|
|
202
314
|
*
|
|
203
315
|
* This component renders a Table by iterating over its Row objects. By default
|
|
204
|
-
*
|
|
205
|
-
* override this behavior by providing a `
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
316
|
+
* the Cells are in turn rendered with the CellView component, but you can
|
|
317
|
+
* override this behavior by providing a `component` for each Cell in the
|
|
318
|
+
* `customCells` prop. You can pass additional props to that custom component
|
|
319
|
+
* with the `getComponentProps` callback. See the CustomCell type for more
|
|
320
|
+
* details.
|
|
209
321
|
*
|
|
210
322
|
* This component uses the useRowIds hook under the covers, which means that any
|
|
211
323
|
* changes to the structure of the Table will cause a re-render.
|
|
@@ -214,7 +326,6 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
214
326
|
* appear in a <th> element at the top of the table, and the start of each row.
|
|
215
327
|
* @param props The props for this component.
|
|
216
328
|
* @returns A rendering of the Table in a <table> element.
|
|
217
|
-
* @see <TableInHtmlTable /> demo
|
|
218
329
|
* @example
|
|
219
330
|
* This example creates a Provider context into which a default Store is
|
|
220
331
|
* provided. The TableInHtmlTable component within it then renders the Table in
|
|
@@ -260,8 +371,9 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
260
371
|
* @example
|
|
261
372
|
* This example creates a Provider context into which a default Store is
|
|
262
373
|
* provided. The TableInHtmlTable component within it then renders the Table
|
|
263
|
-
* with a custom
|
|
264
|
-
* the top of the table and the Id column at the start of each
|
|
374
|
+
* with a custom component and a custom props callback for the `species` Cell.
|
|
375
|
+
* The header row at the top of the table and the Id column at the start of each
|
|
376
|
+
* row is removed.
|
|
265
377
|
*
|
|
266
378
|
* ```jsx
|
|
267
379
|
* const App = ({store}) => (
|
|
@@ -272,18 +384,24 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
272
384
|
* const Pane = () => (
|
|
273
385
|
* <TableInHtmlTable
|
|
274
386
|
* tableId="pets"
|
|
275
|
-
*
|
|
276
|
-
* getCellComponentProps={(rowId, cellId) => ({bold: rowId == 'fido'})}
|
|
387
|
+
* customCells={customCells}
|
|
277
388
|
* headerRow={false}
|
|
278
389
|
* idColumn={false}
|
|
279
390
|
* />
|
|
280
391
|
* );
|
|
392
|
+
*
|
|
281
393
|
* const FormattedCellView = ({tableId, rowId, cellId, bold}) => (
|
|
282
394
|
* <>
|
|
283
395
|
* {bold ? <b>{rowId}</b> : rowId}:
|
|
284
396
|
* <CellView tableId={tableId} rowId={rowId} cellId={cellId} />
|
|
285
397
|
* </>
|
|
286
398
|
* );
|
|
399
|
+
* const customCells = {
|
|
400
|
+
* species: {
|
|
401
|
+
* component: FormattedCellView,
|
|
402
|
+
* getComponentProps: (rowId, cellId) => ({bold: rowId == 'fido'}),
|
|
403
|
+
* },
|
|
404
|
+
* };
|
|
287
405
|
*
|
|
288
406
|
* const store = createStore().setTable('pets', {
|
|
289
407
|
* fido: {species: 'dog'},
|
|
@@ -310,7 +428,7 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
310
428
|
* @since v4.1.0
|
|
311
429
|
*/
|
|
312
430
|
TableInHtmlTable: (
|
|
313
|
-
props: TableInHtmlTableProps<Schemas
|
|
431
|
+
props: TableInHtmlTableProps<Schemas> & HtmlTableProps,
|
|
314
432
|
) => ComponentReturnType;
|
|
315
433
|
|
|
316
434
|
/**
|
|
@@ -322,7 +440,7 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
322
440
|
*
|
|
323
441
|
* ```ts override
|
|
324
442
|
* SortedTableInHtmlTable(
|
|
325
|
-
* props: SortedTableInHtmlTableProps,
|
|
443
|
+
* props: SortedTableInHtmlTableProps & HtmlTableProps,
|
|
326
444
|
* ): ComponentReturnType;
|
|
327
445
|
* ```
|
|
328
446
|
*
|
|
@@ -335,12 +453,12 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
335
453
|
*
|
|
336
454
|
* See the <SortedTableInHtmlTable /> demo for this component in action.
|
|
337
455
|
*
|
|
338
|
-
* This component renders a
|
|
339
|
-
* order dictated by the sort parameters. By default
|
|
340
|
-
* with the
|
|
341
|
-
* providing a `
|
|
342
|
-
*
|
|
343
|
-
*
|
|
456
|
+
* This component renders a ResultTable by iterating over its Row objects, in
|
|
457
|
+
* the order dictated by the sort parameters. By default the Cells are in turn
|
|
458
|
+
* rendered with the CellView component, but you can override this behavior by
|
|
459
|
+
* providing a `component` for each Cell in the `customCells` prop. You can pass
|
|
460
|
+
* additional props to that custom component with the `getComponentProps`
|
|
461
|
+
* callback. See the CustomCell type for more details.
|
|
344
462
|
*
|
|
345
463
|
* This component uses the useSortedRowIds hook under the covers, which means
|
|
346
464
|
* that any changes to the structure or sorting of the Table will cause a
|
|
@@ -408,9 +526,9 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
408
526
|
* @example
|
|
409
527
|
* This example creates a Provider context into which a default Store is
|
|
410
528
|
* provided. The SortedTableInHtmlTable component within it then renders the
|
|
411
|
-
* Table with a custom
|
|
412
|
-
* at the top of the table and the Id column at the start
|
|
413
|
-
* removed.
|
|
529
|
+
* Table with a custom component and a custom props callback for the `species`
|
|
530
|
+
* Cell. The header row at the top of the table and the Id column at the start
|
|
531
|
+
* of each row is removed.
|
|
414
532
|
*
|
|
415
533
|
* ```jsx
|
|
416
534
|
* const App = ({store}) => (
|
|
@@ -418,22 +536,29 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
418
536
|
* <Pane />
|
|
419
537
|
* </Provider>
|
|
420
538
|
* );
|
|
539
|
+
*
|
|
421
540
|
* const Pane = () => (
|
|
422
541
|
* <SortedTableInHtmlTable
|
|
423
542
|
* tableId="pets"
|
|
424
543
|
* cellId="species"
|
|
425
|
-
*
|
|
426
|
-
* getCellComponentProps={(rowId, cellId) => ({bold: rowId == 'fido'})}
|
|
544
|
+
* customCells={customCells}
|
|
427
545
|
* headerRow={false}
|
|
428
546
|
* idColumn={false}
|
|
429
547
|
* />
|
|
430
548
|
* );
|
|
549
|
+
*
|
|
431
550
|
* const FormattedCellView = ({tableId, rowId, cellId, bold}) => (
|
|
432
551
|
* <>
|
|
433
552
|
* {bold ? <b>{rowId}</b> : rowId}:
|
|
434
553
|
* <CellView tableId={tableId} rowId={rowId} cellId={cellId} />
|
|
435
554
|
* </>
|
|
436
555
|
* );
|
|
556
|
+
* const customCells = {
|
|
557
|
+
* species: {
|
|
558
|
+
* component: FormattedCellView,
|
|
559
|
+
* getComponentProps: (rowId, cellId) => ({bold: rowId == 'fido'}),
|
|
560
|
+
* },
|
|
561
|
+
* };
|
|
437
562
|
*
|
|
438
563
|
* const store = createStore().setTables({
|
|
439
564
|
* pets: {
|
|
@@ -462,7 +587,7 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
462
587
|
* @since v4.1.0
|
|
463
588
|
*/
|
|
464
589
|
SortedTableInHtmlTable: (
|
|
465
|
-
props: SortedTableInHtmlTableProps<Schemas
|
|
590
|
+
props: SortedTableInHtmlTableProps<Schemas> & HtmlTableProps,
|
|
466
591
|
) => ComponentReturnType;
|
|
467
592
|
|
|
468
593
|
/**
|
|
@@ -474,7 +599,7 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
474
599
|
*
|
|
475
600
|
* ```ts override
|
|
476
601
|
* ValuesInHtmlTable(
|
|
477
|
-
* props: ValuesInHtmlTableProps,
|
|
602
|
+
* props: ValuesInHtmlTableProps & HtmlTableProps,
|
|
478
603
|
* ): ComponentReturnType;
|
|
479
604
|
* ```
|
|
480
605
|
*
|
|
@@ -485,7 +610,7 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
485
610
|
* See the <ValuesInHtmlTable /> demo for this component in action.
|
|
486
611
|
*
|
|
487
612
|
* This component renders a Store by iterating over its Value objects. By
|
|
488
|
-
* default
|
|
613
|
+
* default the Values are in turn rendered with the ValueView component, but you
|
|
489
614
|
* can override this behavior by providing a `valueComponent` prop, a custom
|
|
490
615
|
* component of your own that will render a Value based on ValueProps. You can
|
|
491
616
|
* also pass additional props to your custom component with the
|
|
@@ -585,6 +710,435 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
585
710
|
* @since v4.1.0
|
|
586
711
|
*/
|
|
587
712
|
ValuesInHtmlTable: (
|
|
588
|
-
props: ValuesInHtmlTableProps<Schemas
|
|
713
|
+
props: ValuesInHtmlTableProps<Schemas> & HtmlTableProps,
|
|
714
|
+
) => ComponentReturnType;
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* The ResultTableInHtmlTable component renders the contents of a single query's
|
|
718
|
+
* ResultTable in a Queries object as an HTML <table> element, and registers a
|
|
719
|
+
* listener so that any changes to that result will cause a re-render.
|
|
720
|
+
*
|
|
721
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
722
|
+
*
|
|
723
|
+
* ```ts override
|
|
724
|
+
* ResultTableInHtmlTable(
|
|
725
|
+
* props: ResultTableInHtmlTableProps & HtmlTableProps,
|
|
726
|
+
* ): ComponentReturnType;
|
|
727
|
+
* ```
|
|
728
|
+
*
|
|
729
|
+
* The component's props identify which ResultTable to render based on query Id,
|
|
730
|
+
* and Queries object (which is either the default context Queries object, a
|
|
731
|
+
* named context Queries object, or by explicit reference).
|
|
732
|
+
*
|
|
733
|
+
* See the <ResultTableInHtmlTable /> demo for this component in action.
|
|
734
|
+
*
|
|
735
|
+
* This component renders a ResultTable by iterating over its Row objects. By
|
|
736
|
+
* default the Cells are in turn rendered with the CellView component, but you
|
|
737
|
+
* can override this behavior by providing a `component` for each Cell in the
|
|
738
|
+
* `customCells` prop. You can pass additional props to that custom
|
|
739
|
+
* component with the `getComponentProps` callback. See the ResultCustomCell
|
|
740
|
+
* type for more details.
|
|
741
|
+
*
|
|
742
|
+
* This component uses the useRowIds hook under the covers, which means that any
|
|
743
|
+
* changes to the structure of the Table will cause a re-render.
|
|
744
|
+
*
|
|
745
|
+
* You can use the `headerRow` and `idColumn` props to control whether the Ids
|
|
746
|
+
* appear in a <th> element at the top of the table, and the start of each row.
|
|
747
|
+
* @param props The props for this component.
|
|
748
|
+
* @returns A rendering of the ResultTable in a <table> element.
|
|
749
|
+
* @example
|
|
750
|
+
* This example creates a Provider context into which a default Queries object
|
|
751
|
+
* is provided. The ResultTableInHtmlTable component within it then renders the
|
|
752
|
+
* ResultTable in a <table> element with a CSS class.
|
|
753
|
+
*
|
|
754
|
+
* ```jsx
|
|
755
|
+
* const App = ({queries}) => (
|
|
756
|
+
* <Provider queries={queries}>
|
|
757
|
+
* <Pane />
|
|
758
|
+
* </Provider>
|
|
759
|
+
* );
|
|
760
|
+
* const Pane = () => (
|
|
761
|
+
* <ResultTableInHtmlTable queryId="petColors" className="table" />
|
|
762
|
+
* );
|
|
763
|
+
*
|
|
764
|
+
* const queries = createQueries(
|
|
765
|
+
* createStore().setTable('pets', {
|
|
766
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
767
|
+
* felix: {species: 'cat', color: 'black'},
|
|
768
|
+
* }),
|
|
769
|
+
* ).setQueryDefinition('petColors', 'pets', ({select}) => select('color'));
|
|
770
|
+
* const app = document.createElement('div');
|
|
771
|
+
* ReactDOMClient.createRoot(app).render(<App queries={queries} />); // !act
|
|
772
|
+
* console.log(app.innerHTML);
|
|
773
|
+
* // ->
|
|
774
|
+
* `
|
|
775
|
+
* <table class="table">
|
|
776
|
+
* <thead>
|
|
777
|
+
* <tr>
|
|
778
|
+
* <th>Id</th>
|
|
779
|
+
* <th>color</th>
|
|
780
|
+
* </tr>
|
|
781
|
+
* </thead>
|
|
782
|
+
* <tbody>
|
|
783
|
+
* <tr>
|
|
784
|
+
* <th>fido</th>
|
|
785
|
+
* <td>brown</td>
|
|
786
|
+
* </tr>
|
|
787
|
+
* <tr>
|
|
788
|
+
* <th>felix</th>
|
|
789
|
+
* <td>black</td>
|
|
790
|
+
* </tr>
|
|
791
|
+
* </tbody>
|
|
792
|
+
* </table>
|
|
793
|
+
* `;
|
|
794
|
+
* ```
|
|
795
|
+
* @example
|
|
796
|
+
* This example creates a Provider context into which a default Queries object
|
|
797
|
+
* is provided. The ResultTableInHtmlTable component within it then renders the
|
|
798
|
+
* ResultTable with a custom component and a custom props callback for the
|
|
799
|
+
* `color` Cell. The header row at the top of the table and the Id column at
|
|
800
|
+
* the start of each row is removed.
|
|
801
|
+
*
|
|
802
|
+
* ```jsx
|
|
803
|
+
* const App = ({queries}) => (
|
|
804
|
+
* <Provider queries={queries}>
|
|
805
|
+
* <Pane />
|
|
806
|
+
* </Provider>
|
|
807
|
+
* );
|
|
808
|
+
* const Pane = () => (
|
|
809
|
+
* <ResultTableInHtmlTable
|
|
810
|
+
* queryId="petColors"
|
|
811
|
+
* customCells={customCells}
|
|
812
|
+
* headerRow={false}
|
|
813
|
+
* idColumn={false}
|
|
814
|
+
* />
|
|
815
|
+
* );
|
|
816
|
+
*
|
|
817
|
+
* const FormattedResultCellView = ({queryId, rowId, cellId, bold}) => (
|
|
818
|
+
* <>
|
|
819
|
+
* {bold ? <b>{rowId}</b> : rowId}:
|
|
820
|
+
* <ResultCellView queryId={queryId} rowId={rowId} cellId={cellId} />
|
|
821
|
+
* </>
|
|
822
|
+
* );
|
|
823
|
+
* const customCells = {
|
|
824
|
+
* color: {
|
|
825
|
+
* component: FormattedResultCellView,
|
|
826
|
+
* getComponentProps: (rowId, cellId) => ({bold: rowId == 'fido'}),
|
|
827
|
+
* },
|
|
828
|
+
* };
|
|
829
|
+
*
|
|
830
|
+
* const queries = createQueries(
|
|
831
|
+
* createStore().setTable('pets', {
|
|
832
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
833
|
+
* felix: {species: 'cat', color: 'black'},
|
|
834
|
+
* }),
|
|
835
|
+
* ).setQueryDefinition('petColors', 'pets', ({select}) => select('color'));
|
|
836
|
+
* const app = document.createElement('div');
|
|
837
|
+
* ReactDOMClient.createRoot(app).render(<App queries={queries} />); // !act
|
|
838
|
+
* console.log(app.innerHTML);
|
|
839
|
+
* // ->
|
|
840
|
+
* `
|
|
841
|
+
* <table>
|
|
842
|
+
* <tbody>
|
|
843
|
+
* <tr>
|
|
844
|
+
* <td><b>fido</b>:brown</td>
|
|
845
|
+
* </tr>
|
|
846
|
+
* <tr>
|
|
847
|
+
* <td>felix:black</td>
|
|
848
|
+
* </tr>
|
|
849
|
+
* </tbody>
|
|
850
|
+
* </table>
|
|
851
|
+
* `;
|
|
852
|
+
* ```
|
|
853
|
+
* @category Store components
|
|
854
|
+
* @since v4.1.0
|
|
855
|
+
*/
|
|
856
|
+
ResultTableInHtmlTable: (
|
|
857
|
+
props: ResultTableInHtmlTableProps<Schemas> & HtmlTableProps,
|
|
858
|
+
) => ComponentReturnType;
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* The SortedTableInHtmlTable component renders the contents of a single query's
|
|
862
|
+
* sorted ResultTable in a Queries object as an HTML <table> element, and
|
|
863
|
+
* registers a listener so that any changes to that result will cause a
|
|
864
|
+
* re-render.
|
|
865
|
+
*
|
|
866
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
867
|
+
*
|
|
868
|
+
* ```ts override
|
|
869
|
+
* ResultSortedTableInHtmlTable(
|
|
870
|
+
* props: ResultSortedTableInHtmlTableProps & HtmlTableProps,
|
|
871
|
+
* ): ComponentReturnType;
|
|
872
|
+
* ```
|
|
873
|
+
*
|
|
874
|
+
* The component's props identify which ResultTable to render based on query Id,
|
|
875
|
+
* and Queries object (which is either the default context Queries object, a
|
|
876
|
+
* named context Queries object, or by explicit reference). It also takes a Cell
|
|
877
|
+
* Id to sort by and a boolean to indicate that the sorting should be in
|
|
878
|
+
* descending order. The `offset` and `limit` props are used to paginate
|
|
879
|
+
* results, but default to `0` and `undefined` to return all available Row Ids
|
|
880
|
+
* if not specified.
|
|
881
|
+
*
|
|
882
|
+
* See the <ResultSortedTableInHtmlTable /> demo for this component in action.
|
|
883
|
+
*
|
|
884
|
+
* This component renders a ResultTable by iterating over its Row objects, in
|
|
885
|
+
* the order dictated by the sort parameters. By default the Cells are in turn
|
|
886
|
+
* rendered with the CellView component, but you can override this behavior by
|
|
887
|
+
* providing a `component` for each Cell in the `customCells` prop. You
|
|
888
|
+
* can pass additional props to that custom component with the
|
|
889
|
+
* `getComponentProps` callback. See the ResultCustomCell type for more details.
|
|
890
|
+
*
|
|
891
|
+
* This component uses the useSortedRowIds hook under the covers, which means
|
|
892
|
+
* that any changes to the structure or sorting of the ResultTable will cause a
|
|
893
|
+
* re-render.
|
|
894
|
+
*
|
|
895
|
+
* You can use the `headerRow` and `idColumn` props to control whether the Ids
|
|
896
|
+
* appear in a <th> element at the top of the table, and the start of each row.
|
|
897
|
+
*
|
|
898
|
+
* The `sortOnClick` prop makes the table's sorting interactive such that the
|
|
899
|
+
* user can click on a column heading to sort by that column. The style classes
|
|
900
|
+
* `sorted` and `ascending` (or `descending`) are added so that you can provide
|
|
901
|
+
* hints to the user how the sorting is being applied.
|
|
902
|
+
* @param props The props for this component.
|
|
903
|
+
* @returns A rendering of the ResultTable in a <table> element.
|
|
904
|
+
* @example
|
|
905
|
+
* This example creates a Provider context into which a default Queries object
|
|
906
|
+
* is provided. The ResultSortedTableInHtmlTable component within it then
|
|
907
|
+
* renders the ResultTable in a <table> element with a CSS class.
|
|
908
|
+
*
|
|
909
|
+
* ```jsx
|
|
910
|
+
* const App = ({queries}) => (
|
|
911
|
+
* <Provider queries={queries}>
|
|
912
|
+
* <Pane />
|
|
913
|
+
* </Provider>
|
|
914
|
+
* );
|
|
915
|
+
* const Pane = () => (
|
|
916
|
+
* <ResultSortedTableInHtmlTable
|
|
917
|
+
* queryId="petColors"
|
|
918
|
+
* cellId="color"
|
|
919
|
+
* className="table"
|
|
920
|
+
* />
|
|
921
|
+
* );
|
|
922
|
+
*
|
|
923
|
+
* const queries = createQueries(
|
|
924
|
+
* createStore().setTable('pets', {
|
|
925
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
926
|
+
* felix: {species: 'cat', color: 'black'},
|
|
927
|
+
* }),
|
|
928
|
+
* ).setQueryDefinition('petColors', 'pets', ({select}) => select('color'));
|
|
929
|
+
* const app = document.createElement('div');
|
|
930
|
+
* ReactDOMClient.createRoot(app).render(<App queries={queries} />); // !act
|
|
931
|
+
* console.log(app.innerHTML);
|
|
932
|
+
* // ->
|
|
933
|
+
* `
|
|
934
|
+
* <table class="table">
|
|
935
|
+
* <thead>
|
|
936
|
+
* <tr>
|
|
937
|
+
* <th>Id</th>
|
|
938
|
+
* <th class="sorted ascending">color</th>
|
|
939
|
+
* </tr>
|
|
940
|
+
* </thead>
|
|
941
|
+
* <tbody>
|
|
942
|
+
* <tr>
|
|
943
|
+
* <th>felix</th>
|
|
944
|
+
* <td>black</td>
|
|
945
|
+
* </tr>
|
|
946
|
+
* <tr>
|
|
947
|
+
* <th>fido</th>
|
|
948
|
+
* <td>brown</td>
|
|
949
|
+
* </tr>
|
|
950
|
+
* </tbody>
|
|
951
|
+
* </table>
|
|
952
|
+
* `;
|
|
953
|
+
* ```
|
|
954
|
+
* @example
|
|
955
|
+
* This example creates a Provider context into which a default Queries object
|
|
956
|
+
* is provided. The ResultSortedTableInHtmlTable component within it then
|
|
957
|
+
* renders the ResultTable with a custom component and a custom props callback
|
|
958
|
+
* for the `color` Cell. The header row at the top of the table and the Id
|
|
959
|
+
* column at the start of each row is removed.
|
|
960
|
+
*
|
|
961
|
+
* ```jsx
|
|
962
|
+
* const App = ({queries}) => (
|
|
963
|
+
* <Provider queries={queries}>
|
|
964
|
+
* <Pane />
|
|
965
|
+
* </Provider>
|
|
966
|
+
* );
|
|
967
|
+
*
|
|
968
|
+
* const Pane = () => (
|
|
969
|
+
* <ResultSortedTableInHtmlTable
|
|
970
|
+
* queryId="petColors"
|
|
971
|
+
* cellId="color"
|
|
972
|
+
* customCells={customCells}
|
|
973
|
+
* headerRow={false}
|
|
974
|
+
* idColumn={false}
|
|
975
|
+
* />
|
|
976
|
+
* );
|
|
977
|
+
*
|
|
978
|
+
* const FormattedResultCellView = ({queryId, rowId, cellId, bold}) => (
|
|
979
|
+
* <>
|
|
980
|
+
* {bold ? <b>{rowId}</b> : rowId}:
|
|
981
|
+
* <ResultCellView queryId={queryId} rowId={rowId} cellId={cellId} />
|
|
982
|
+
* </>
|
|
983
|
+
* );
|
|
984
|
+
* const customCells = {
|
|
985
|
+
* color: {
|
|
986
|
+
* component: FormattedResultCellView,
|
|
987
|
+
* getComponentProps: (rowId, cellId) => ({bold: rowId == 'fido'}),
|
|
988
|
+
* },
|
|
989
|
+
* };
|
|
990
|
+
*
|
|
991
|
+
* const queries = createQueries(
|
|
992
|
+
* createStore().setTable('pets', {
|
|
993
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
994
|
+
* felix: {species: 'cat', color: 'black'},
|
|
995
|
+
* }),
|
|
996
|
+
* ).setQueryDefinition('petColors', 'pets', ({select}) => select('color'));
|
|
997
|
+
* const app = document.createElement('div');
|
|
998
|
+
* ReactDOMClient.createRoot(app).render(<App queries={queries} />); // !act
|
|
999
|
+
* console.log(app.innerHTML);
|
|
1000
|
+
* // ->
|
|
1001
|
+
* `
|
|
1002
|
+
* <table>
|
|
1003
|
+
* <tbody>
|
|
1004
|
+
* <tr>
|
|
1005
|
+
* <td>felix:black</td>
|
|
1006
|
+
* </tr>
|
|
1007
|
+
* <tr>
|
|
1008
|
+
* <td><b>fido</b>:brown</td>
|
|
1009
|
+
* </tr>
|
|
1010
|
+
* </tbody>
|
|
1011
|
+
* </table>
|
|
1012
|
+
* `;
|
|
1013
|
+
* ```
|
|
1014
|
+
* @category Store components
|
|
1015
|
+
* @since v4.1.0
|
|
1016
|
+
*/
|
|
1017
|
+
ResultSortedTableInHtmlTable: (
|
|
1018
|
+
props: ResultSortedTableInHtmlTableProps<Schemas> & HtmlTableProps,
|
|
1019
|
+
) => ComponentReturnType;
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* The EditableCellView component renders the value of a single Cell in a way
|
|
1023
|
+
* that can be edited in a web browser, and registers a listener so that any
|
|
1024
|
+
* changes to that result will cause a re-render.
|
|
1025
|
+
*
|
|
1026
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1027
|
+
*
|
|
1028
|
+
* ```ts override
|
|
1029
|
+
* EditableCellView(
|
|
1030
|
+
* props: CellProps & {readonly className?: string},
|
|
1031
|
+
* ): ComponentReturnType;
|
|
1032
|
+
* ```
|
|
1033
|
+
*
|
|
1034
|
+
* The component's props identify which Cell to render based on Table Id, Row
|
|
1035
|
+
* Id, Cell Id, and Store (which is either the default context Store, a named
|
|
1036
|
+
* context Store, or an explicit reference).
|
|
1037
|
+
*
|
|
1038
|
+
* A Cell contains a string, number, or boolean, so the value is rendered in an
|
|
1039
|
+
* appropriate <input> tag and a button lets the user change type, if possible.
|
|
1040
|
+
*
|
|
1041
|
+
* This component uses the useCell hook under the covers, which means that any
|
|
1042
|
+
* changes to the specified Cell outside of this component will cause a
|
|
1043
|
+
* re-render.
|
|
1044
|
+
*
|
|
1045
|
+
* You can provide a custom className prop which well be used on the root of the
|
|
1046
|
+
* resulting element. If omitted the element's class will be `editableCell`. The
|
|
1047
|
+
* debugIds prop has no effect on this component.
|
|
1048
|
+
* @param props The props for this component.
|
|
1049
|
+
* @returns An editable rendering of the Cell.
|
|
1050
|
+
* @example
|
|
1051
|
+
* This example creates a Provider context into which a default Store is
|
|
1052
|
+
* provided. The EditableCellView component within it then renders an editable
|
|
1053
|
+
* Cell.
|
|
1054
|
+
*
|
|
1055
|
+
* ```jsx
|
|
1056
|
+
* const App = ({store}) => (
|
|
1057
|
+
* <Provider store={store}>
|
|
1058
|
+
* <Pane />
|
|
1059
|
+
* </Provider>
|
|
1060
|
+
* );
|
|
1061
|
+
* const Pane = () => (
|
|
1062
|
+
* <EditableCellView tableId="pets" rowId="fido" cellId="color" />
|
|
1063
|
+
* );
|
|
1064
|
+
*
|
|
1065
|
+
* const store = createStore().setCell('pets', 'fido', 'color', 'brown');
|
|
1066
|
+
* const app = document.createElement('div');
|
|
1067
|
+
* ReactDOMClient.createRoot(app).render(<App store={store} />); // !act
|
|
1068
|
+
* console.log(app.innerHTML);
|
|
1069
|
+
* // ->
|
|
1070
|
+
* `
|
|
1071
|
+
* <div class="editableCell">
|
|
1072
|
+
* <button type="button" class="string">string</button>
|
|
1073
|
+
* <input value="brown">
|
|
1074
|
+
* </div>
|
|
1075
|
+
* `;
|
|
1076
|
+
* ```
|
|
1077
|
+
* @category Store components
|
|
1078
|
+
* @since v4.1.0
|
|
1079
|
+
*/
|
|
1080
|
+
EditableCellView: (
|
|
1081
|
+
props: CellProps<Schemas> & {className?: string},
|
|
1082
|
+
) => ComponentReturnType;
|
|
1083
|
+
|
|
1084
|
+
/**
|
|
1085
|
+
* The EditableValueView component renders the value of a single Value in a way
|
|
1086
|
+
* that can be edited in a web browser, and registers a listener so that any
|
|
1087
|
+
* changes to that result will cause a re-render.
|
|
1088
|
+
*
|
|
1089
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1090
|
+
*
|
|
1091
|
+
* ```ts override
|
|
1092
|
+
* EditableValueView(
|
|
1093
|
+
* props: ValueProps & {readonly className?: string},
|
|
1094
|
+
* ): ComponentReturnType;
|
|
1095
|
+
* ```
|
|
1096
|
+
*
|
|
1097
|
+
* The component's props identify which Value to render based on Table Id, Row
|
|
1098
|
+
* Id, Value Id, and Store (which is either the default context Store, a named
|
|
1099
|
+
* context Store, or an explicit reference).
|
|
1100
|
+
*
|
|
1101
|
+
* A Value contains a string, number, or boolean, so the value is rendered in an
|
|
1102
|
+
* appropriate <input> tag and a button lets the user change type, if possible.
|
|
1103
|
+
*
|
|
1104
|
+
* This component uses the useValue hook under the covers, which means that any
|
|
1105
|
+
* changes to the specified Value outside of this component will cause a
|
|
1106
|
+
* re-render.
|
|
1107
|
+
*
|
|
1108
|
+
* You can provide a custom className prop which well be used on the root of the
|
|
1109
|
+
* resulting element. If omitted the element's class will be `editableValue`.
|
|
1110
|
+
* The debugIds prop has no effect on this component.
|
|
1111
|
+
* @param props The props for this component.
|
|
1112
|
+
* @returns An editable rendering of the Value.
|
|
1113
|
+
* @example
|
|
1114
|
+
* This example creates a Provider context into which a default Store is
|
|
1115
|
+
* provided. The EditableValueView component within it then renders an editable
|
|
1116
|
+
* Value.
|
|
1117
|
+
*
|
|
1118
|
+
* ```jsx
|
|
1119
|
+
* const App = ({store}) => (
|
|
1120
|
+
* <Provider store={store}>
|
|
1121
|
+
* <Pane />
|
|
1122
|
+
* </Provider>
|
|
1123
|
+
* );
|
|
1124
|
+
* const Pane = () => <EditableValueView valueId="employees" />;
|
|
1125
|
+
*
|
|
1126
|
+
* const store = createStore().setValue('employees', 3);
|
|
1127
|
+
* const app = document.createElement('div');
|
|
1128
|
+
* ReactDOMClient.createRoot(app).render(<App store={store} />); // !act
|
|
1129
|
+
* console.log(app.innerHTML);
|
|
1130
|
+
* // ->
|
|
1131
|
+
* `
|
|
1132
|
+
* <div class="editableValue">
|
|
1133
|
+
* <button type="button" class="number">number</button>
|
|
1134
|
+
* <input type="number" value="3">
|
|
1135
|
+
* </div>
|
|
1136
|
+
* `;
|
|
1137
|
+
* ```
|
|
1138
|
+
* @category Store components
|
|
1139
|
+
* @since v4.1.0
|
|
1140
|
+
*/
|
|
1141
|
+
EditableValueView: (
|
|
1142
|
+
props: ValueProps<Schemas> & {className?: string},
|
|
589
1143
|
) => ComponentReturnType;
|
|
590
1144
|
};
|