tinybase 8.5.0-beta.0 → 8.5.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.
Files changed (131) hide show
  1. package/@types/ui-react-dom-charts/index.d.ts +242 -0
  2. package/@types/ui-react-dom-charts/with-schemas/index.d.ts +296 -0
  3. package/common/index.js +3 -2
  4. package/common/with-schemas/index.js +3 -2
  5. package/index.js +5 -3
  6. package/mergeable-store/index.js +5 -3
  7. package/mergeable-store/with-schemas/index.js +5 -3
  8. package/metrics/index.js +1 -1
  9. package/metrics/with-schemas/index.js +1 -1
  10. package/min/common/index.js +1 -1
  11. package/min/common/index.js.gz +0 -0
  12. package/min/common/with-schemas/index.js +1 -1
  13. package/min/common/with-schemas/index.js.gz +0 -0
  14. package/min/index.js +1 -1
  15. package/min/index.js.gz +0 -0
  16. package/min/mergeable-store/index.js +1 -1
  17. package/min/mergeable-store/index.js.gz +0 -0
  18. package/min/mergeable-store/with-schemas/index.js +1 -1
  19. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  20. package/min/omni/index.js +1 -1
  21. package/min/omni/index.js.gz +0 -0
  22. package/min/omni/with-schemas/index.js +1 -1
  23. package/min/omni/with-schemas/index.js.gz +0 -0
  24. package/min/persisters/persister-durable-object-sql-storage/index.js +1 -1
  25. package/min/persisters/persister-durable-object-sql-storage/index.js.gz +0 -0
  26. package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js +1 -1
  27. package/min/persisters/persister-durable-object-sql-storage/with-schemas/index.js.gz +0 -0
  28. package/min/persisters/persister-partykit-server/index.js +1 -1
  29. package/min/persisters/persister-partykit-server/index.js.gz +0 -0
  30. package/min/persisters/persister-partykit-server/with-schemas/index.js +1 -1
  31. package/min/persisters/persister-partykit-server/with-schemas/index.js.gz +0 -0
  32. package/min/queries/index.js +1 -1
  33. package/min/queries/index.js.gz +0 -0
  34. package/min/queries/with-schemas/index.js +1 -1
  35. package/min/queries/with-schemas/index.js.gz +0 -0
  36. package/min/synchronizers/index.js +1 -1
  37. package/min/synchronizers/index.js.gz +0 -0
  38. package/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -1
  39. package/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
  40. package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -1
  41. package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
  42. package/min/synchronizers/synchronizer-local/index.js +1 -1
  43. package/min/synchronizers/synchronizer-local/index.js.gz +0 -0
  44. package/min/synchronizers/synchronizer-local/with-schemas/index.js +1 -1
  45. package/min/synchronizers/synchronizer-local/with-schemas/index.js.gz +0 -0
  46. package/min/synchronizers/synchronizer-ws-client/index.js +1 -1
  47. package/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
  48. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  49. package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
  50. package/min/synchronizers/synchronizer-ws-server/index.js +1 -1
  51. package/min/synchronizers/synchronizer-ws-server/index.js.gz +0 -0
  52. package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js +1 -1
  53. package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js.gz +0 -0
  54. package/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
  55. package/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
  56. package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
  57. package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
  58. package/min/synchronizers/with-schemas/index.js +1 -1
  59. package/min/synchronizers/with-schemas/index.js.gz +0 -0
  60. package/min/ui-react-dom/index.js +1 -1
  61. package/min/ui-react-dom/index.js.gz +0 -0
  62. package/min/ui-react-dom/with-schemas/index.js +1 -1
  63. package/min/ui-react-dom/with-schemas/index.js.gz +0 -0
  64. package/min/ui-react-dom-charts/index.js +1 -0
  65. package/min/ui-react-dom-charts/index.js.gz +0 -0
  66. package/min/ui-react-dom-charts/with-schemas/index.js +1 -0
  67. package/min/ui-react-dom-charts/with-schemas/index.js.gz +0 -0
  68. package/min/ui-react-inspector/index.js +1 -1
  69. package/min/ui-react-inspector/index.js.gz +0 -0
  70. package/min/ui-react-inspector/with-schemas/index.js +1 -1
  71. package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  72. package/min/ui-solid-dom/index.js +1 -1
  73. package/min/ui-solid-dom/index.js.gz +0 -0
  74. package/min/ui-solid-dom/with-schemas/index.js +1 -1
  75. package/min/ui-solid-dom/with-schemas/index.js.gz +0 -0
  76. package/min/ui-solid-inspector/index.js +1 -1
  77. package/min/ui-solid-inspector/index.js.gz +0 -0
  78. package/min/ui-solid-inspector/with-schemas/index.js +1 -1
  79. package/min/ui-solid-inspector/with-schemas/index.js.gz +0 -0
  80. package/min/ui-svelte-dom/index.js +1 -1
  81. package/min/ui-svelte-dom/index.js.gz +0 -0
  82. package/min/ui-svelte-dom/with-schemas/index.js +1 -1
  83. package/min/ui-svelte-dom/with-schemas/index.js.gz +0 -0
  84. package/min/ui-svelte-inspector/index.js +1 -1
  85. package/min/ui-svelte-inspector/index.js.gz +0 -0
  86. package/min/ui-svelte-inspector/with-schemas/index.js +1 -1
  87. package/min/ui-svelte-inspector/with-schemas/index.js.gz +0 -0
  88. package/min/with-schemas/index.js +1 -1
  89. package/min/with-schemas/index.js.gz +0 -0
  90. package/omni/index.js +7 -4
  91. package/omni/with-schemas/index.js +7 -4
  92. package/package.json +50 -14
  93. package/persisters/persister-durable-object-sql-storage/index.js +13 -11
  94. package/persisters/persister-durable-object-sql-storage/with-schemas/index.js +13 -11
  95. package/persisters/persister-partykit-client/index.js +2 -1
  96. package/persisters/persister-partykit-client/with-schemas/index.js +2 -1
  97. package/persisters/persister-partykit-server/index.js +2 -1
  98. package/persisters/persister-partykit-server/with-schemas/index.js +2 -1
  99. package/queries/index.js +1 -1
  100. package/queries/with-schemas/index.js +1 -1
  101. package/readme.md +18 -14
  102. package/releases.md +91 -58
  103. package/synchronizers/index.js +3 -2
  104. package/synchronizers/synchronizer-broadcast-channel/index.js +3 -2
  105. package/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +3 -2
  106. package/synchronizers/synchronizer-local/index.js +3 -2
  107. package/synchronizers/synchronizer-local/with-schemas/index.js +3 -2
  108. package/synchronizers/synchronizer-ws-client/index.js +3 -2
  109. package/synchronizers/synchronizer-ws-client/with-schemas/index.js +3 -2
  110. package/synchronizers/synchronizer-ws-server/index.js +3 -2
  111. package/synchronizers/synchronizer-ws-server/with-schemas/index.js +3 -2
  112. package/synchronizers/synchronizer-ws-server-durable-object/index.js +3 -2
  113. package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +3 -2
  114. package/synchronizers/with-schemas/index.js +3 -2
  115. package/ui-react-dom/index.js +10 -7
  116. package/ui-react-dom/with-schemas/index.js +10 -7
  117. package/ui-react-dom-charts/index.js +1229 -0
  118. package/ui-react-dom-charts/with-schemas/index.js +1229 -0
  119. package/ui-react-inspector/index.js +16 -10
  120. package/ui-react-inspector/with-schemas/index.js +16 -10
  121. package/ui-solid-dom/index.js +10 -7
  122. package/ui-solid-dom/with-schemas/index.js +10 -7
  123. package/ui-solid-inspector/index.js +16 -10
  124. package/ui-solid-inspector/with-schemas/index.js +16 -10
  125. package/ui-svelte/index.js +5 -5
  126. package/ui-svelte/with-schemas/index.js +5 -5
  127. package/ui-svelte-dom/index.js +162 -164
  128. package/ui-svelte-dom/with-schemas/index.js +162 -164
  129. package/ui-svelte-inspector/index.js +192 -196
  130. package/ui-svelte-inspector/with-schemas/index.js +192 -196
  131. package/with-schemas/index.js +5 -3
@@ -0,0 +1,242 @@
1
+ /**
2
+ * The ui-react-dom-charts module of the TinyBase project provides components
3
+ * to make it easy to create web-based reactive charts with Store and Queries
4
+ * objects.
5
+ *
6
+ * The components in this module use the react-dom module and so are not
7
+ * appropriate for environments like React Native (although those in the
8
+ * lower-level ui-react module are).
9
+ *
10
+ * For a full list of SVG class names that can be styled with CSS, see the
11
+ * Using Charts guide.
12
+ * @packageDocumentation
13
+ * @module ui-react-dom-charts
14
+ * @since v8.5.0
15
+ */
16
+ import type {Id} from '../common/index.d.ts';
17
+ import type {
18
+ ComponentReturnType,
19
+ QueriesOrQueriesId,
20
+ StoreOrStoreId,
21
+ } from '../ui-react/index.d.ts';
22
+
23
+ /**
24
+ * The ChartProps type describes the props that are used to configure the
25
+ * chart element that renders a chart.
26
+ * @category Configuration
27
+ * @since v8.5.0
28
+ */
29
+ export type ChartProps = {
30
+ /**
31
+ * An optional string that will be used as the class attribute of the chart's
32
+ * SVG element. This can be used as the root selector for styling chart
33
+ * internals, as shown in the Using Charts guide.
34
+ * @category Prop
35
+ * @since v8.5.0
36
+ */
37
+ readonly className?: string;
38
+ };
39
+
40
+ /**
41
+ * The ChartTableSourceProps type describes the props that bind a chart to a
42
+ * Table in a Store.
43
+ * @category Configuration
44
+ * @since v8.5.0
45
+ */
46
+ export type ChartTableSourceProps = {
47
+ /**
48
+ * The Id of the Table in the Store to chart.
49
+ * @category Prop
50
+ * @since v8.5.0
51
+ */
52
+ readonly tableId: Id;
53
+ /**
54
+ * The Store to chart, or the Id of a Store that is registered with the
55
+ * Provider component.
56
+ * @category Prop
57
+ * @since v8.5.0
58
+ */
59
+ readonly store?: StoreOrStoreId;
60
+ /**
61
+ * This prop is not used when binding a chart to a Table.
62
+ * @category Prop
63
+ * @since v8.5.0
64
+ */
65
+ readonly queryId?: never;
66
+ /**
67
+ * This prop is not used when binding a chart to a Table.
68
+ * @category Prop
69
+ * @since v8.5.0
70
+ */
71
+ readonly queries?: never;
72
+ };
73
+
74
+ /**
75
+ * The ChartQuerySourceProps type describes the props that bind a chart to a
76
+ * Query in a Queries object.
77
+ * @category Configuration
78
+ * @since v8.5.0
79
+ */
80
+ export type ChartQuerySourceProps = {
81
+ /**
82
+ * The Id of the query in the Queries object to chart.
83
+ * @category Prop
84
+ * @since v8.5.0
85
+ */
86
+ readonly queryId: Id;
87
+ /**
88
+ * The Queries object to chart, or the Id of a Queries object that is
89
+ * registered with the Provider component.
90
+ * @category Prop
91
+ * @since v8.5.0
92
+ */
93
+ readonly queries?: QueriesOrQueriesId;
94
+ /**
95
+ * This prop is not used when binding a chart to a Query.
96
+ * @category Prop
97
+ * @since v8.5.0
98
+ */
99
+ readonly tableId?: never;
100
+ /**
101
+ * This prop is not used when binding a chart to a Query.
102
+ * @category Prop
103
+ * @since v8.5.0
104
+ */
105
+ readonly store?: never;
106
+ };
107
+
108
+ /**
109
+ * The ChartBindingProps type describes the props that bind a chart to Cell
110
+ * values in TinyBase data.
111
+ * @category Configuration
112
+ * @since v8.5.0
113
+ */
114
+ export type ChartBindingProps = {
115
+ /**
116
+ * The Id of the Cell that provides each data point's x value.
117
+ * @category Prop
118
+ * @since v8.5.0
119
+ */
120
+ readonly xCellId: Id;
121
+ /**
122
+ * The Id of the Cell that provides each data point's y value.
123
+ * @category Prop
124
+ * @since v8.5.0
125
+ */
126
+ readonly yCellId: Id;
127
+ /**
128
+ * The Id of the Cell used to sort the charted rows.
129
+ * @category Prop
130
+ * @since v8.5.0
131
+ */
132
+ readonly sortCellId?: Id;
133
+ /**
134
+ * Whether the charted rows should be sorted in descending order.
135
+ * @category Prop
136
+ * @since v8.5.0
137
+ */
138
+ readonly descending?: boolean;
139
+ /**
140
+ * The number of sorted rows to skip before charting.
141
+ * @category Prop
142
+ * @since v8.5.0
143
+ */
144
+ readonly offset?: number;
145
+ /**
146
+ * The maximum number of sorted rows to chart.
147
+ * @category Prop
148
+ * @since v8.5.0
149
+ */
150
+ readonly limit?: number;
151
+ };
152
+
153
+ /**
154
+ * The LineChart component renders a line chart from TinyBase data.
155
+ * @category Store components
156
+ * @since v8.5.0
157
+ * @example
158
+ * This example creates a Provider context into which a default Store is
159
+ * provided. The LineChart component then renders an SVG chart from Cells in the
160
+ * `pets` Table.
161
+ *
162
+ * ```jsx
163
+ * import React from 'react';
164
+ * import {createRoot} from 'react-dom/client';
165
+ * import {createStore} from 'tinybase';
166
+ * import {Provider} from 'tinybase/ui-react';
167
+ * import {LineChart} from 'tinybase/ui-react-dom-charts';
168
+ *
169
+ * const App = ({store}) => (
170
+ * <Provider store={store}>
171
+ * <LineChart
172
+ * tableId="pets"
173
+ * xCellId="order"
174
+ * yCellId="sold"
175
+ * className="sales"
176
+ * />
177
+ * </Provider>
178
+ * );
179
+ *
180
+ * const store = createStore().setTable('pets', {
181
+ * hamsters: {order: 1, sold: 12},
182
+ * rabbits: {order: 2, sold: 9},
183
+ * });
184
+ * const app = document.createElement('div');
185
+ * createRoot(app).render(<App store={store} />); // !act
186
+ * console.log(app.firstChild?.nodeName.toLowerCase());
187
+ * // -> 'svg'
188
+ * console.log(app.firstChild?.getAttribute('class'));
189
+ * // -> 'sales'
190
+ * ```
191
+ */
192
+ export function LineChart(
193
+ props: (ChartTableSourceProps | ChartQuerySourceProps) &
194
+ ChartBindingProps &
195
+ ChartProps,
196
+ ): ComponentReturnType;
197
+
198
+ /**
199
+ * The BarChart component renders a bar chart from TinyBase data.
200
+ * @category Store components
201
+ * @since v8.5.0
202
+ * @example
203
+ * This example creates a Queries object and provides it through Provider
204
+ * context. The BarChart component then renders an SVG chart from Cells in the
205
+ * `bySpecies` query.
206
+ *
207
+ * ```jsx
208
+ * import React from 'react';
209
+ * import {createRoot} from 'react-dom/client';
210
+ * import {createQueries, createStore} from 'tinybase';
211
+ * import {Provider} from 'tinybase/ui-react';
212
+ * import {BarChart} from 'tinybase/ui-react-dom-charts';
213
+ *
214
+ * const App = ({queries}) => (
215
+ * <Provider queries={queries}>
216
+ * <BarChart queryId="bySpecies" xCellId="species" yCellId="sold" />
217
+ * </Provider>
218
+ * );
219
+ *
220
+ * const store = createStore().setTable('pets', {
221
+ * hamsters: {species: 'hamster', sold: 12},
222
+ * rabbits: {species: 'rabbit', sold: 9},
223
+ * });
224
+ * const queries = createQueries(store).setQueryDefinition(
225
+ * 'bySpecies',
226
+ * 'pets',
227
+ * ({select}) => {
228
+ * select('species');
229
+ * select('sold');
230
+ * },
231
+ * );
232
+ * const app = document.createElement('div');
233
+ * createRoot(app).render(<App queries={queries} />); // !act
234
+ * console.log(app.firstChild?.nodeName.toLowerCase());
235
+ * // -> 'svg'
236
+ * ```
237
+ */
238
+ export function BarChart(
239
+ props: (ChartTableSourceProps | ChartQuerySourceProps) &
240
+ ChartBindingProps &
241
+ ChartProps,
242
+ ): ComponentReturnType;
@@ -0,0 +1,296 @@
1
+ /**
2
+ * The ui-react-dom-charts module of the TinyBase project provides components
3
+ * to make it easy to create web-based reactive charts with Store and Queries
4
+ * objects.
5
+ *
6
+ * The components in this module use the react-dom module and so are not
7
+ * appropriate for environments like React Native (although those in the
8
+ * lower-level ui-react module are).
9
+ *
10
+ * For a full list of SVG class names that can be styled with CSS, see the
11
+ * Using Charts guide.
12
+ * @packageDocumentation
13
+ * @module ui-react-dom-charts
14
+ * @since v8.5.0
15
+ */
16
+ import type {
17
+ CellIdFromSchema,
18
+ TableIdFromSchema,
19
+ } from '../../_internal/store/with-schemas/index.d.ts';
20
+ import type {ComponentReturnType} from '../../_internal/ui-react/with-schemas/index.d.ts';
21
+ import type {
22
+ QueriesOrQueriesId,
23
+ StoreOrStoreId,
24
+ } from '../../_internal/ui/with-schemas/index.d.ts';
25
+ import type {Id} from '../../common/with-schemas/index.d.ts';
26
+ import type {OptionalSchemas} from '../../store/with-schemas/index.d.ts';
27
+
28
+ /**
29
+ * The ChartProps type describes the props that are used to configure the
30
+ * chart element that renders a chart.
31
+ * @category Configuration
32
+ * @since v8.5.0
33
+ */
34
+ export type ChartProps = {
35
+ /**
36
+ * An optional string that will be used as the class attribute of the chart's
37
+ * SVG element. This can be used as the root selector for styling chart
38
+ * internals, as shown in the Using Charts guide.
39
+ * @category Prop
40
+ * @since v8.5.0
41
+ */
42
+ readonly className?: string;
43
+ };
44
+
45
+ /**
46
+ * The ChartTableSourceProps type describes the props that bind a chart to a
47
+ * Table in a Store.
48
+ * @category Configuration
49
+ * @since v8.5.0
50
+ */
51
+ export type ChartTableSourceProps<
52
+ Schemas extends OptionalSchemas,
53
+ TableIds extends TableIdFromSchema<Schemas[0]> = TableIdFromSchema<
54
+ Schemas[0]
55
+ >,
56
+ > = TableIds extends infer TableId
57
+ ? TableId extends TableIdFromSchema<Schemas[0]>
58
+ ? {
59
+ /**
60
+ * The Id of the Table in the Store to chart.
61
+ * @category Prop
62
+ * @since v8.5.0
63
+ */
64
+ readonly tableId: TableId;
65
+ /**
66
+ * The Store to chart, or the Id of a Store that is registered with the
67
+ * Provider component.
68
+ * @category Prop
69
+ * @since v8.5.0
70
+ */
71
+ readonly store?: StoreOrStoreId<Schemas>;
72
+ /**
73
+ * This prop is not used when binding a chart to a Table.
74
+ * @category Prop
75
+ * @since v8.5.0
76
+ */
77
+ readonly queryId?: never;
78
+ /**
79
+ * This prop is not used when binding a chart to a Table.
80
+ * @category Prop
81
+ * @since v8.5.0
82
+ */
83
+ readonly queries?: never;
84
+ }
85
+ : never
86
+ : never;
87
+
88
+ /**
89
+ * The ChartQuerySourceProps type describes the props that bind a chart to a
90
+ * Query in a Queries object.
91
+ * @category Configuration
92
+ * @since v8.5.0
93
+ */
94
+ export type ChartQuerySourceProps<Schemas extends OptionalSchemas> = {
95
+ /**
96
+ * The Id of the query in the Queries object to chart.
97
+ * @category Prop
98
+ * @since v8.5.0
99
+ */
100
+ readonly queryId: Id;
101
+ /**
102
+ * The Queries object to chart, or the Id of a Queries object that is
103
+ * registered with the Provider component.
104
+ * @category Prop
105
+ * @since v8.5.0
106
+ */
107
+ readonly queries?: QueriesOrQueriesId<Schemas>;
108
+ /**
109
+ * This prop is not used when binding a chart to a Query.
110
+ * @category Prop
111
+ * @since v8.5.0
112
+ */
113
+ readonly tableId?: never;
114
+ /**
115
+ * This prop is not used when binding a chart to a Query.
116
+ * @category Prop
117
+ * @since v8.5.0
118
+ */
119
+ readonly store?: never;
120
+ };
121
+
122
+ /**
123
+ * The ChartBindingProps type describes the props that bind a chart to Cell
124
+ * values in TinyBase data.
125
+ * @category Configuration
126
+ * @since v8.5.0
127
+ */
128
+ export type ChartBindingProps<CellId extends Id = Id> = {
129
+ /**
130
+ * The Id of the Cell that provides each data point's x value.
131
+ * @category Prop
132
+ * @since v8.5.0
133
+ */
134
+ readonly xCellId: CellId;
135
+ /**
136
+ * The Id of the Cell that provides each data point's y value.
137
+ * @category Prop
138
+ * @since v8.5.0
139
+ */
140
+ readonly yCellId: CellId;
141
+ /**
142
+ * The Id of the Cell used to sort the charted rows.
143
+ * @category Prop
144
+ * @since v8.5.0
145
+ */
146
+ readonly sortCellId?: CellId;
147
+ /**
148
+ * Whether the charted rows should be sorted in descending order.
149
+ * @category Prop
150
+ * @since v8.5.0
151
+ */
152
+ readonly descending?: boolean;
153
+ /**
154
+ * The number of sorted rows to skip before charting.
155
+ * @category Prop
156
+ * @since v8.5.0
157
+ */
158
+ readonly offset?: number;
159
+ /**
160
+ * The maximum number of sorted rows to chart.
161
+ * @category Prop
162
+ * @since v8.5.0
163
+ */
164
+ readonly limit?: number;
165
+ };
166
+
167
+ type ChartTableBindingProps<
168
+ Schemas extends OptionalSchemas,
169
+ TableIds extends TableIdFromSchema<Schemas[0]> = TableIdFromSchema<
170
+ Schemas[0]
171
+ >,
172
+ > = TableIds extends infer TableId
173
+ ? TableId extends TableIdFromSchema<Schemas[0]>
174
+ ? ChartTableSourceProps<Schemas, TableId> &
175
+ ChartBindingProps<CellIdFromSchema<Schemas[0], TableId>>
176
+ : never
177
+ : never;
178
+
179
+ /**
180
+ * The WithSchemas type provides a version of this module that is typed with
181
+ * schemas.
182
+ * @category Development
183
+ * @since v8.5.0
184
+ */
185
+ export type WithSchemas<Schemas extends OptionalSchemas> = {
186
+ /**
187
+ * The LineChart component renders a line chart from TinyBase data.
188
+ * @category Store components
189
+ * @since v8.5.0
190
+ * @example
191
+ * This example creates a Provider context into which a default Store is
192
+ * provided. The LineChart component then renders an SVG chart from Cells in the
193
+ * `pets` Table.
194
+ *
195
+ * This has schema-based typing. The following is a simplified representation:
196
+ *
197
+ * ```ts override
198
+ * LineChart(
199
+ * props: (ChartTableSourceProps | ChartQuerySourceProps) &
200
+ * ChartBindingProps &
201
+ * ChartProps,
202
+ * ): ComponentReturnType;
203
+ * ```
204
+ *
205
+ * ```jsx
206
+ * import React from 'react';
207
+ * import {createRoot} from 'react-dom/client';
208
+ * import {createStore} from 'tinybase';
209
+ * import {Provider} from 'tinybase/ui-react';
210
+ * import {LineChart} from 'tinybase/ui-react-dom-charts';
211
+ *
212
+ * const App = ({store}) => (
213
+ * <Provider store={store}>
214
+ * <LineChart
215
+ * tableId="pets"
216
+ * xCellId="order"
217
+ * yCellId="sold"
218
+ * className="sales"
219
+ * />
220
+ * </Provider>
221
+ * );
222
+ *
223
+ * const store = createStore().setTable('pets', {
224
+ * hamsters: {order: 1, sold: 12},
225
+ * rabbits: {order: 2, sold: 9},
226
+ * });
227
+ * const app = document.createElement('div');
228
+ * createRoot(app).render(<App store={store} />); // !act
229
+ * console.log(app.firstChild?.nodeName.toLowerCase());
230
+ * // -> 'svg'
231
+ * console.log(app.firstChild?.getAttribute('class'));
232
+ * // -> 'sales'
233
+ * ```
234
+ */
235
+ LineChart: (
236
+ props:
237
+ | (ChartTableBindingProps<Schemas> & ChartProps)
238
+ | (ChartQuerySourceProps<Schemas> & ChartBindingProps & ChartProps),
239
+ ) => ComponentReturnType;
240
+
241
+ /**
242
+ * The BarChart component renders a bar chart from TinyBase data.
243
+ * @category Store components
244
+ * @since v8.5.0
245
+ * @example
246
+ * This example creates a Queries object and provides it through Provider
247
+ * context. The BarChart component then renders an SVG chart from Cells in the
248
+ * `bySpecies` query.
249
+ *
250
+ * This has schema-based typing. The following is a simplified representation:
251
+ *
252
+ * ```ts override
253
+ * BarChart(
254
+ * props: (ChartTableSourceProps | ChartQuerySourceProps) &
255
+ * ChartBindingProps &
256
+ * ChartProps,
257
+ * ): ComponentReturnType;
258
+ * ```
259
+ *
260
+ * ```jsx
261
+ * import React from 'react';
262
+ * import {createRoot} from 'react-dom/client';
263
+ * import {createQueries, createStore} from 'tinybase';
264
+ * import {Provider} from 'tinybase/ui-react';
265
+ * import {BarChart} from 'tinybase/ui-react-dom-charts';
266
+ *
267
+ * const App = ({queries}) => (
268
+ * <Provider queries={queries}>
269
+ * <BarChart queryId="bySpecies" xCellId="species" yCellId="sold" />
270
+ * </Provider>
271
+ * );
272
+ *
273
+ * const store = createStore().setTable('pets', {
274
+ * hamsters: {species: 'hamster', sold: 12},
275
+ * rabbits: {species: 'rabbit', sold: 9},
276
+ * });
277
+ * const queries = createQueries(store).setQueryDefinition(
278
+ * 'bySpecies',
279
+ * 'pets',
280
+ * ({select}) => {
281
+ * select('species');
282
+ * select('sold');
283
+ * },
284
+ * );
285
+ * const app = document.createElement('div');
286
+ * createRoot(app).render(<App queries={queries} />); // !act
287
+ * console.log(app.firstChild?.nodeName.toLowerCase());
288
+ * // -> 'svg'
289
+ * ```
290
+ */
291
+ BarChart: (
292
+ props:
293
+ | (ChartTableBindingProps<Schemas> & ChartProps)
294
+ | (ChartQuerySourceProps<Schemas> & ChartBindingProps & ChartProps),
295
+ ) => ComponentReturnType;
296
+ };
package/common/index.js CHANGED
@@ -2,15 +2,16 @@ const EMPTY_STRING = '';
2
2
  const strSplit = (str, separator = EMPTY_STRING, limit) =>
3
3
  str.split(separator, limit);
4
4
 
5
+ const math = Math;
5
6
  const getIfNotFunction = (predicate) => (value, then, otherwise) =>
6
7
  predicate(value)
7
8
  ? /* istanbul ignore next */
8
9
  otherwise?.()
9
10
  : then(value);
10
11
  const GLOBAL = globalThis;
11
- const math = Math;
12
12
  const mathMax = math.max;
13
13
  const mathFloor = math.floor;
14
+ const mathRandom = math.random;
14
15
  const isInstanceOf = (thing, cls) => thing instanceof cls;
15
16
  const isUndefined = (thing) => thing === void 0;
16
17
  const ifNotUndefined = getIfNotFunction(isUndefined);
@@ -38,7 +39,7 @@ const decode = (str, pos) => mapGet(DECODE, str[pos]) ?? 0;
38
39
  const getRandomValues = GLOBAL.crypto
39
40
  ? (array) => GLOBAL.crypto.getRandomValues(array)
40
41
  : /* istanbul ignore next */
41
- (array) => arrayMap(array, () => mathFloor(math.random() * 256));
42
+ (array) => arrayMap(array, () => mathFloor(mathRandom() * 256));
42
43
  const getUniqueId = (length = 16) =>
43
44
  arrayReduce(
44
45
  getRandomValues(new Uint8Array(length)),
@@ -2,15 +2,16 @@ const EMPTY_STRING = '';
2
2
  const strSplit = (str, separator = EMPTY_STRING, limit) =>
3
3
  str.split(separator, limit);
4
4
 
5
+ const math = Math;
5
6
  const getIfNotFunction = (predicate) => (value, then, otherwise) =>
6
7
  predicate(value)
7
8
  ? /* istanbul ignore next */
8
9
  otherwise?.()
9
10
  : then(value);
10
11
  const GLOBAL = globalThis;
11
- const math = Math;
12
12
  const mathMax = math.max;
13
13
  const mathFloor = math.floor;
14
+ const mathRandom = math.random;
14
15
  const isInstanceOf = (thing, cls) => thing instanceof cls;
15
16
  const isUndefined = (thing) => thing === void 0;
16
17
  const ifNotUndefined = getIfNotFunction(isUndefined);
@@ -38,7 +39,7 @@ const decode = (str, pos) => mapGet(DECODE, str[pos]) ?? 0;
38
39
  const getRandomValues = GLOBAL.crypto
39
40
  ? (array) => GLOBAL.crypto.getRandomValues(array)
40
41
  : /* istanbul ignore next */
41
- (array) => arrayMap(array, () => mathFloor(math.random() * 256));
42
+ (array) => arrayMap(array, () => mathFloor(mathRandom() * 256));
42
43
  const getUniqueId = (length = 16) =>
43
44
  arrayReduce(
44
45
  getRandomValues(new Uint8Array(length)),
package/index.js CHANGED
@@ -42,16 +42,17 @@ const strEndsWith = (str, suffix) => str.endsWith(suffix);
42
42
  const strSplit = (str, separator = EMPTY_STRING, limit) =>
43
43
  str.split(separator, limit);
44
44
 
45
+ const math = Math;
45
46
  const getIfNotFunction = (predicate) => (value, then, otherwise) =>
46
47
  predicate(value)
47
48
  ? /* istanbul ignore next */
48
49
  otherwise?.()
49
50
  : then(value);
50
51
  const GLOBAL = globalThis;
51
- const math = Math;
52
52
  const mathMax = math.max;
53
53
  const mathMin = math.min;
54
54
  const mathFloor = math.floor;
55
+ const mathRandom = math.random;
55
56
  const isFiniteNumber = isFinite;
56
57
  const isInstanceOf = (thing, cls) => thing instanceof cls;
57
58
  const isNullish = (thing) => thing == null;
@@ -63,6 +64,7 @@ const ifNotNullish = getIfNotFunction(isNullish);
63
64
  const ifNotUndefined = getIfNotFunction(isUndefined);
64
65
  const isTypeStringOrBoolean = (type) => type == STRING || type == BOOLEAN;
65
66
  const isString = (thing) => getTypeOf(thing) == STRING;
67
+ const isNumber = (thing) => getTypeOf(thing) == NUMBER;
66
68
  const isFunction = (thing) => getTypeOf(thing) == FUNCTION;
67
69
  const isArray = (thing) => Array.isArray(thing);
68
70
  const slice = (arrayOrString, start, end) => arrayOrString.slice(start, end);
@@ -785,7 +787,7 @@ const decode = (str, pos) => mapGet(DECODE, str[pos]) ?? 0;
785
787
  const getRandomValues = GLOBAL.crypto
786
788
  ? (array) => GLOBAL.crypto.getRandomValues(array)
787
789
  : /* istanbul ignore next */
788
- (array) => arrayMap(array, () => mathFloor(math.random() * 256));
790
+ (array) => arrayMap(array, () => mathFloor(mathRandom() * 256));
789
791
  const getUniqueId = (length = 16) =>
790
792
  arrayReduce(
791
793
  getRandomValues(new Uint8Array(length)),
@@ -1191,7 +1193,7 @@ const stampValidate = (stamp, validateThing) =>
1191
1193
  isArray(stamp) &&
1192
1194
  size(stamp) == 3 &&
1193
1195
  isString(stamp[1]) &&
1194
- getTypeOf(stamp[2]) == NUMBER &&
1196
+ isNumber(stamp[2]) &&
1195
1197
  isFiniteNumber(stamp[2]) &&
1196
1198
  validateThing(stamp[0]);
1197
1199
 
@@ -35,15 +35,16 @@ const strEndsWith = (str, suffix) => str.endsWith(suffix);
35
35
  const strSplit = (str, separator = EMPTY_STRING, limit) =>
36
36
  str.split(separator, limit);
37
37
 
38
+ const math = Math;
38
39
  const getIfNotFunction = (predicate) => (value, then, otherwise) =>
39
40
  predicate(value)
40
41
  ? /* istanbul ignore next */
41
42
  otherwise?.()
42
43
  : then(value);
43
44
  const GLOBAL = globalThis;
44
- const math = Math;
45
45
  const mathMax = math.max;
46
46
  const mathFloor = math.floor;
47
+ const mathRandom = math.random;
47
48
  const isFiniteNumber = isFinite;
48
49
  const isInstanceOf = (thing, cls) => thing instanceof cls;
49
50
  const isNullish = (thing) => thing == null;
@@ -53,6 +54,7 @@ const ifNotNullish = getIfNotFunction(isNullish);
53
54
  const ifNotUndefined = getIfNotFunction(isUndefined);
54
55
  const isTypeStringOrBoolean = (type) => type == STRING || type == BOOLEAN;
55
56
  const isString = (thing) => getTypeOf(thing) == STRING;
57
+ const isNumber = (thing) => getTypeOf(thing) == NUMBER;
56
58
  const isFunction = (thing) => getTypeOf(thing) == FUNCTION;
57
59
  const isArray = (thing) => Array.isArray(thing);
58
60
  const slice = (arrayOrString, start, end) => arrayOrString.slice(start, end);
@@ -307,7 +309,7 @@ const decode = (str, pos) => mapGet(DECODE, str[pos]) ?? 0;
307
309
  const getRandomValues = GLOBAL.crypto
308
310
  ? (array) => GLOBAL.crypto.getRandomValues(array)
309
311
  : /* istanbul ignore next */
310
- (array) => arrayMap(array, () => mathFloor(math.random() * 256));
312
+ (array) => arrayMap(array, () => mathFloor(mathRandom() * 256));
311
313
  const getUniqueId = (length = 16) =>
312
314
  arrayReduce(
313
315
  getRandomValues(new Uint8Array(length)),
@@ -432,7 +434,7 @@ const stampValidate = (stamp, validateThing) =>
432
434
  isArray(stamp) &&
433
435
  size(stamp) == 3 &&
434
436
  isString(stamp[1]) &&
435
- getTypeOf(stamp[2]) == NUMBER &&
437
+ isNumber(stamp[2]) &&
436
438
  isFiniteNumber(stamp[2]) &&
437
439
  validateThing(stamp[0]);
438
440