@rebasepro/core 0.2.5 → 0.4.0
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/dist/components/common/types.d.ts +3 -3
- package/dist/index.es.js +42 -36
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +42 -36
- package/dist/index.umd.js.map +1 -1
- package/package.json +6 -6
- package/src/components/common/types.tsx +3 -3
- package/src/components/common/useDataTableController.tsx +47 -35
- package/src/hooks/useResolvedComponent.tsx +3 -3
- package/src/locales/en.ts +2 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"description": "Rebase core — framework-agnostic runtime for data-driven admin panels",
|
|
6
6
|
"funding": {
|
|
7
7
|
"url": "https://github.com/sponsors/rebaseco"
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"notistack": "^3.0.2",
|
|
54
54
|
"react-compiler-runtime": "1.0.0",
|
|
55
55
|
"react-i18next": "^14.1.3",
|
|
56
|
-
"@rebasepro/
|
|
57
|
-
"@rebasepro/
|
|
58
|
-
"@rebasepro/
|
|
59
|
-
"@rebasepro/
|
|
60
|
-
"@rebasepro/utils": "0.
|
|
56
|
+
"@rebasepro/types": "0.4.0",
|
|
57
|
+
"@rebasepro/common": "0.4.0",
|
|
58
|
+
"@rebasepro/ui": "0.4.0",
|
|
59
|
+
"@rebasepro/formex": "0.4.0",
|
|
60
|
+
"@rebasepro/utils": "0.4.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"react": ">=19.0.0",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Property } from "@rebasepro/types";
|
|
1
|
+
import type { Property, Entity } from "@rebasepro/types";
|
|
2
2
|
import { CollectionSize, SelectedCellProps } from "@rebasepro/types";
|
|
3
3
|
|
|
4
4
|
export type EntityCollectionTableController<M extends Record<string, unknown>> = {
|
|
@@ -25,7 +25,7 @@ export type EntityCollectionTableController<M extends Record<string, unknown>> =
|
|
|
25
25
|
* Callback used when the value of a cell has changed.
|
|
26
26
|
* @param params
|
|
27
27
|
*/
|
|
28
|
-
onValueChange?: (params: OnCellValueChangeParams<unknown, M
|
|
28
|
+
onValueChange?: (params: OnCellValueChangeParams<unknown, Entity<M>>) => void;
|
|
29
29
|
/**
|
|
30
30
|
* Size of the elements in the collection
|
|
31
31
|
*/
|
|
@@ -58,7 +58,7 @@ export type UniqueFieldValidator = (props: {
|
|
|
58
58
|
* Callback when a cell has changed in a table
|
|
59
59
|
* @group Collection components
|
|
60
60
|
*/
|
|
61
|
-
export type OnCellValueChange<T, M extends Record<string, unknown>> = (params: OnCellValueChangeParams<T, M
|
|
61
|
+
export type OnCellValueChange<T, M extends Record<string, unknown>> = (params: OnCellValueChangeParams<T, Entity<M>>) => Promise<void> | void;
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* @group Collection components
|
|
@@ -246,16 +246,22 @@ export function useDataTableController<M extends Record<string, any> = any, USER
|
|
|
246
246
|
if (filterValues) {
|
|
247
247
|
Object.entries(filterValues).forEach(([key, value]) => {
|
|
248
248
|
if (value && Array.isArray(value)) {
|
|
249
|
-
const [
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
249
|
+
const conditions: [WhereFilterOp, unknown][] = Array.isArray(value[0])
|
|
250
|
+
? (value as [WhereFilterOp, unknown][])
|
|
251
|
+
: [value as [WhereFilterOp, unknown]];
|
|
252
|
+
|
|
253
|
+
const [op, val] = conditions[0] || [];
|
|
254
|
+
if (op) {
|
|
255
|
+
const postgrestOp = op === "==" ? "eq" : op === "!=" ? "neq" : op === ">" ? "gt" : op === ">=" ? "gte" : op === "<" ? "lt" : op === "<=" ? "lte" : op === "in" ? "in" : op === "not-in" ? "nin" : op === "array-contains" ? "cs" : op === "array-contains-any" ? "csa" : "eq";
|
|
256
|
+
|
|
257
|
+
let stringVal: string;
|
|
258
|
+
if (Array.isArray(val)) {
|
|
259
|
+
stringVal = `(${val.join(",")})`;
|
|
260
|
+
} else {
|
|
261
|
+
stringVal = String(val);
|
|
262
|
+
}
|
|
263
|
+
whereMap[key] = `${postgrestOp}.${stringVal}`;
|
|
257
264
|
}
|
|
258
|
-
whereMap[key] = `${postgrestOp}.${stringVal}`;
|
|
259
265
|
}
|
|
260
266
|
});
|
|
261
267
|
}
|
|
@@ -388,34 +394,40 @@ function encodeFilterAndSort(filterValues?: FilterValues<string>, sortBy?: [stri
|
|
|
388
394
|
if (filterValues) {
|
|
389
395
|
Object.entries(filterValues).forEach(([key, value]) => {
|
|
390
396
|
if (value) {
|
|
391
|
-
const [
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
397
|
+
const conditions: [WhereFilterOp, unknown][] = Array.isArray(value[0])
|
|
398
|
+
? (value as [WhereFilterOp, unknown][])
|
|
399
|
+
: [value as [WhereFilterOp, unknown]];
|
|
400
|
+
|
|
401
|
+
const [op, val] = conditions[0] || [];
|
|
402
|
+
if (op) {
|
|
403
|
+
let encodedValue: unknown = val;
|
|
404
|
+
try {
|
|
405
|
+
if (typeof val === "object") {
|
|
406
|
+
if (val instanceof Date) {
|
|
407
|
+
encodedValue = val.toISOString();
|
|
408
|
+
} else if (Array.isArray(val)) {
|
|
409
|
+
encodedValue = JSON.stringify(val, (k, v) => {
|
|
410
|
+
if (v instanceof EntityRelation) {
|
|
411
|
+
return encodeRelation(v);
|
|
412
|
+
}
|
|
413
|
+
if (v instanceof EntityReference) {
|
|
414
|
+
return encodeReference(v);
|
|
415
|
+
}
|
|
416
|
+
return v;
|
|
417
|
+
});
|
|
418
|
+
} else if (val instanceof EntityRelation) {
|
|
419
|
+
encodedValue = encodeRelation(val);
|
|
420
|
+
} else if (val instanceof EntityReference) {
|
|
421
|
+
encodedValue = encodeReference(val);
|
|
422
|
+
}
|
|
411
423
|
}
|
|
424
|
+
} catch (e) {
|
|
425
|
+
encodedValue = val;
|
|
426
|
+
}
|
|
427
|
+
if (encodedValue !== undefined) {
|
|
428
|
+
entries[encodeURIComponent(`${key}_op`)] = encodeURIComponent(op);
|
|
429
|
+
entries[encodeURIComponent(`${key}_value`)] = encodedValue ? encodeURIComponent(String(encodedValue)) : "null";
|
|
412
430
|
}
|
|
413
|
-
} catch (e) {
|
|
414
|
-
encodedValue = val;
|
|
415
|
-
}
|
|
416
|
-
if (encodedValue !== undefined) {
|
|
417
|
-
entries[encodeURIComponent(`${key}_op`)] = encodeURIComponent(op);
|
|
418
|
-
entries[encodeURIComponent(`${key}_value`)] = encodedValue ? encodeURIComponent(String(encodedValue)) : "null";
|
|
419
431
|
}
|
|
420
432
|
}
|
|
421
433
|
});
|
|
@@ -14,7 +14,7 @@ import { isLazyComponentRef } from "@rebasepro/types";
|
|
|
14
14
|
* plain Map since they can't be WeakMap keys.
|
|
15
15
|
*/
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
-
const lazyCache = new WeakMap<object |
|
|
17
|
+
const lazyCache = new WeakMap<object | ((...args: any[]) => any), React.ComponentType<any>>();
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Resolves a `ComponentRef` into a renderable `React.ComponentType`.
|
|
@@ -63,7 +63,7 @@ export function useResolvedComponent<P = unknown>(
|
|
|
63
63
|
* same loader always returns the same lazy component identity.
|
|
64
64
|
*/
|
|
65
65
|
function getOrCreateLazy<P>(
|
|
66
|
-
key: object |
|
|
66
|
+
key: object | ((...args: any[]) => any),
|
|
67
67
|
loader: () => Promise<{ default: React.ComponentType<P> }>
|
|
68
68
|
): React.ComponentType<P> {
|
|
69
69
|
const cached = lazyCache.get(key);
|
|
@@ -109,7 +109,7 @@ export function resolveComponentRef<P = unknown>(
|
|
|
109
109
|
|
|
110
110
|
// 3. Function — either a React component or a lazy import loader.
|
|
111
111
|
if (typeof ref === "function") {
|
|
112
|
-
const fn = ref as
|
|
112
|
+
const fn = ref as (...args: any[]) => any;
|
|
113
113
|
|
|
114
114
|
// Class components (React.Component / PureComponent) have this flag
|
|
115
115
|
if (fn.prototype?.isReactComponent) {
|
package/src/locales/en.ts
CHANGED
|
@@ -406,14 +406,14 @@ export const en: RebaseTranslations = {
|
|
|
406
406
|
data_imported_successfully: "Data imported successfully",
|
|
407
407
|
export: "Export",
|
|
408
408
|
export_data: "Export data",
|
|
409
|
-
download_table_csv: "Download the
|
|
409
|
+
download_table_csv: "Download the content of this table as a CSV",
|
|
410
410
|
csv: "CSV",
|
|
411
411
|
json: "JSON",
|
|
412
412
|
dates_as_timestamps: "Dates as timestamps",
|
|
413
413
|
dates_as_strings: "Dates as strings",
|
|
414
414
|
flatten_arrays: "Flatten arrays",
|
|
415
415
|
download: "Download",
|
|
416
|
-
large_number_of_documents: "This
|
|
416
|
+
large_number_of_documents: "This collection has a large number of documents ({{count}}).",
|
|
417
417
|
include_undefined_values: "Include undefined values",
|
|
418
418
|
submit: "Submit",
|
|
419
419
|
|