@rebasepro/app 0.9.1-canary.fd3754b → 0.10.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/auth/index.d.ts +6 -5
- package/dist/contexts/AdminModeController.d.ts +1 -1
- package/dist/contexts/CollectionResolverContext.d.ts +23 -0
- package/dist/contexts/ModeController.d.ts +1 -1
- package/dist/contexts/index.d.ts +1 -0
- package/dist/hooks/useBuildAdminModeController.d.ts +1 -1
- package/dist/hooks/useBuildModeController.d.ts +1 -1
- package/dist/hooks/useNavigationBlocker.d.ts +29 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +240 -104
- package/dist/index.es.js.map +1 -1
- package/dist/util/previews.d.ts +9 -0
- package/package.json +14 -21
- package/src/auth/index.ts +6 -5
- package/src/components/LoginView/LoginView.tsx +7 -2
- package/src/components/UnsavedChangesDialog.tsx +1 -1
- package/src/components/common/useDataTableController.tsx +8 -2
- package/src/contexts/AdminModeController.tsx +1 -1
- package/src/contexts/CollectionResolverContext.tsx +24 -0
- package/src/contexts/ModeController.tsx +1 -1
- package/src/contexts/index.ts +1 -0
- package/src/core/Rebase.tsx +21 -5
- package/src/hooks/data/useCollection.tsx +2 -4
- package/src/hooks/data/useRelationSelector.tsx +10 -3
- package/src/hooks/useBuildAdminModeController.tsx +1 -1
- package/src/hooks/useBuildModeController.tsx +1 -1
- package/src/hooks/useNavigationBlocker.tsx +108 -0
- package/src/hooks/useUnsavedChangesDialog.tsx +7 -4
- package/src/index.ts +1 -0
- package/src/util/previews.ts +20 -0
- package/dist/index.umd.js +0 -17021
- package/dist/index.umd.js.map +0 -1
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Authentication controller for Rebase frontends.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* for communicating with a Rebase backend's JWT auth endpoints.
|
|
4
|
+
* Provides the `useRebaseAuthController` hook and API utilities for
|
|
5
|
+
* communicating with a Rebase backend's JWT auth endpoints.
|
|
7
6
|
*
|
|
8
|
-
*
|
|
7
|
+
* The generic LoginView and RebaseAuth components that render on top of this
|
|
8
|
+
* controller are in `../components`. Both are re-exported from the package
|
|
9
|
+
* root, which is where applications should import them from.
|
|
9
10
|
*/
|
|
10
11
|
export type { RebaseAuthController, RebaseAuthControllerProps, AuthTokens, DeviceSession, UserInfo, AuthResponse, RefreshResponse } from "./types";
|
|
11
12
|
export { useRebaseAuthController } from "./useRebaseAuthController";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { AdminModeController } from "../hooks";
|
|
2
|
+
import type { AdminModeController } from "../hooks/useAdminModeController";
|
|
3
3
|
export declare const AdminModeControllerContext: React.Context<AdminModeController>;
|
|
4
4
|
export declare const AdminModeControllerProvider: React.Provider<AdminModeController>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Look up a collection's config by slug.
|
|
4
|
+
*/
|
|
5
|
+
export type CollectionResolver = (slug: string) => {
|
|
6
|
+
properties?: Record<string, unknown>;
|
|
7
|
+
} | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Lets the layer that owns the collections hand a resolver *up* to the data
|
|
10
|
+
* layer, which needs a collection's primary keys to give its rows an address.
|
|
11
|
+
*
|
|
12
|
+
* The inversion is forced by the composition: `<Rebase client>` builds the data
|
|
13
|
+
* layer, and `<RebaseAdmin collections>` sits inside it — so the collections are
|
|
14
|
+
* not in scope where the data is created, and `Rebase` cannot take them as a
|
|
15
|
+
* prop without giving every headless BaaS app a collections argument it has no
|
|
16
|
+
* use for.
|
|
17
|
+
*
|
|
18
|
+
* Registration is a ref write, so it is safe to call during render — and it has
|
|
19
|
+
* to be. The views that fetch rows are *below* the registrar, and child effects
|
|
20
|
+
* run before parent effects, so registering in an effect would bind after the
|
|
21
|
+
* first page of rows had already been converted.
|
|
22
|
+
*/
|
|
23
|
+
export declare const CollectionResolverRegistrationContext: React.Context<(resolver: CollectionResolver | undefined) => void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { ModeController } from "../hooks";
|
|
2
|
+
import type { ModeController } from "../hooks/useModeController";
|
|
3
3
|
export declare const ModeControllerContext: React.Context<ModeController>;
|
|
4
4
|
export declare const ModeControllerProvider: React.Provider<ModeController>;
|
package/dist/contexts/index.d.ts
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Blocker, BlockerFunction } from "react-router-dom";
|
|
3
|
+
/**
|
|
4
|
+
* Owns the single React Router blocker for the whole app.
|
|
5
|
+
*
|
|
6
|
+
* React Router only honours **one** blocker at a time: `shouldBlockNavigation`
|
|
7
|
+
* picks the last-registered blocker function and silently ignores every other
|
|
8
|
+
* one (it only logs a dev warning). Because blockers register in a `useEffect`,
|
|
9
|
+
* the winner is whichever surface mounted most recently — so an unsaved-changes
|
|
10
|
+
* guard could be disabled by an unrelated component mounting after it.
|
|
11
|
+
*
|
|
12
|
+
* This provider registers the only `useBlocker` in the tree and multiplexes it,
|
|
13
|
+
* so every surface that needs to guard navigation gets a say regardless of
|
|
14
|
+
* mount order. Surfaces register through {@link useNavigationBlocker}.
|
|
15
|
+
*/
|
|
16
|
+
export declare function NavigationBlockerProvider({ children }: {
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
}): React.JSX.Element;
|
|
19
|
+
/**
|
|
20
|
+
* Guard navigation with `predicate`, sharing the app-wide blocker.
|
|
21
|
+
*
|
|
22
|
+
* Returns a {@link Blocker} that is only ever in the `blocked` state when *this*
|
|
23
|
+
* registration is what blocked the navigation — so several guards can coexist
|
|
24
|
+
* without each of them popping a dialog.
|
|
25
|
+
*
|
|
26
|
+
* Returns an idle blocker when no {@link NavigationBlockerProvider} is mounted
|
|
27
|
+
* above, rather than competing for React Router's single blocker slot.
|
|
28
|
+
*/
|
|
29
|
+
export declare function useNavigationBlocker(predicate: BlockerFunction): Blocker;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./contexts";
|
|
|
7
7
|
export { CONTAINER_FULL_WIDTH, ADDITIONAL_TAB_WIDTH, FORM_CONTAINER_WIDTH } from "./internal/common";
|
|
8
8
|
export { useRestoreScroll } from "./internal/useRestoreScroll";
|
|
9
9
|
export { useUnsavedChangesDialog } from "./hooks/useUnsavedChangesDialog";
|
|
10
|
+
export { NavigationBlockerProvider, useNavigationBlocker } from "./hooks/useNavigationBlocker";
|
|
10
11
|
export type { UnsavedChangesDialogProps } from "./components/UnsavedChangesDialog";
|
|
11
12
|
export { UnsavedChangesDialog } from "./components/UnsavedChangesDialog";
|
|
12
13
|
export * from "./i18n/RebaseI18nProvider";
|
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { createContext, lazy, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
1
|
+
import React, { createContext, lazy, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { Alert, AlertCircleIcon, AlertTriangleIcon, AppWindow, ArrowLeftIcon, Avatar, BooleanSwitch, Button, CHIP_COLORS, Card, CenteredView, CheckIcon, Checkbox, ChevronDownIcon, ChevronsLeftIcon, ChevronsRightIcon, Chip, CircleUserIcon, CircularProgress, ColumnsIcon, Container, Dialog, DialogActions, DialogContent, DialogTitle, ErrorBoundary, FileIcon, FileTextIcon, FilterChip, FilterIcon, FolderIcon, IconButton, KanbanIcon, KanbanView, LanguagesIcon, LayoutGridIcon, ListIcon, LoadingButton, LogOutIcon, MailIcon, Menu, MenuItem, MoonIcon, MultiSelect, MultiSelectItem, PanelLeftIcon, Paper, PencilIcon, PlusIcon, Popover, SearchBar, Select, SelectItem, Separator, SettingsIcon, Skeleton, SunIcon, SunMoonIcon, Tab, Table, TableBody, TableCell, TableHeader, TableRow, Tabs, TagIcon, TextField, ToggleButtonGroup, Tooltip, Trash2Icon, TypeIcon, Typography, UserIcon, Wand2Icon, cls, colorClassesMapping, coolIconKeys, defaultBorderMixin, getColorSchemeForSeed, iconKeys, iconSize, lucideIcons } from "@rebasepro/ui";
|
|
3
3
|
import { DEFAULT_DATA_SOURCE_KEY, DEFAULT_STORAGE_SOURCE_KEY, EntityReference, EntityRelation, GeoPoint, RebaseApiError, Vector, isLazyComponentRef } from "@rebasepro/types";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -296,6 +296,24 @@ function CollectionScopeProvider({ collection, children }) {
|
|
|
296
296
|
});
|
|
297
297
|
}
|
|
298
298
|
//#endregion
|
|
299
|
+
//#region src/contexts/CollectionResolverContext.tsx
|
|
300
|
+
/**
|
|
301
|
+
* Lets the layer that owns the collections hand a resolver *up* to the data
|
|
302
|
+
* layer, which needs a collection's primary keys to give its rows an address.
|
|
303
|
+
*
|
|
304
|
+
* The inversion is forced by the composition: `<Rebase client>` builds the data
|
|
305
|
+
* layer, and `<RebaseAdmin collections>` sits inside it — so the collections are
|
|
306
|
+
* not in scope where the data is created, and `Rebase` cannot take them as a
|
|
307
|
+
* prop without giving every headless BaaS app a collections argument it has no
|
|
308
|
+
* use for.
|
|
309
|
+
*
|
|
310
|
+
* Registration is a ref write, so it is safe to call during render — and it has
|
|
311
|
+
* to be. The views that fetch rows are *below* the registrar, and child effects
|
|
312
|
+
* run before parent effects, so registering in an effect would bind after the
|
|
313
|
+
* first page of rows had already been converted.
|
|
314
|
+
*/
|
|
315
|
+
var CollectionResolverRegistrationContext = React.createContext(() => void 0);
|
|
316
|
+
//#endregion
|
|
299
317
|
//#region src/hooks/data/useData.tsx
|
|
300
318
|
/**
|
|
301
319
|
* Use this hook to access the unified data API.
|
|
@@ -391,6 +409,94 @@ function SchemaDriftBanner({ className }) {
|
|
|
391
409
|
});
|
|
392
410
|
}
|
|
393
411
|
//#endregion
|
|
412
|
+
//#region src/util/previews.ts
|
|
413
|
+
function isReferenceProperty(property) {
|
|
414
|
+
if (!property) return null;
|
|
415
|
+
if (property.type === "reference") return true;
|
|
416
|
+
if (property.type === "array") if (Array.isArray(property.of)) return false;
|
|
417
|
+
else return property.of?.type === "reference";
|
|
418
|
+
return false;
|
|
419
|
+
}
|
|
420
|
+
function isRelationProperty(property) {
|
|
421
|
+
if (!property) return null;
|
|
422
|
+
if (property.type === "relation") return true;
|
|
423
|
+
if (property.type === "array") if (Array.isArray(property.of)) return false;
|
|
424
|
+
else return property.of?.type === "relation";
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
function isHiddenProperty(property) {
|
|
428
|
+
if (!property) return false;
|
|
429
|
+
return Boolean(property.ui?.hideFromCollection);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Returns true when the property holds file-storage content (single image,
|
|
433
|
+
* array of images, generic upload, …). These properties are rendered by the
|
|
434
|
+
* dedicated image-slot and should NOT appear as regular preview columns.
|
|
435
|
+
*/
|
|
436
|
+
function isStorageProperty(property) {
|
|
437
|
+
if (!property) return false;
|
|
438
|
+
if (property.type === "string" && property.storage) return true;
|
|
439
|
+
if (property.type === "string" && property.ui?.url === "image") return true;
|
|
440
|
+
if (property.type === "array" && property.of && !Array.isArray(property.of)) {
|
|
441
|
+
const inner = property.of;
|
|
442
|
+
if (inner.type === "string" && (inner.storage || inner.ui?.url === "image")) return true;
|
|
443
|
+
}
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
function getEntityPreviewKeys(authController, targetCollection, fields, previewProperties, limit = 3) {
|
|
447
|
+
const allProperties = Object.keys(targetCollection.properties);
|
|
448
|
+
let listProperties = previewProperties?.filter((p) => allProperties.includes(p));
|
|
449
|
+
if (!listProperties && targetCollection.previewProperties) listProperties = targetCollection.previewProperties?.filter((p) => allProperties.includes(p));
|
|
450
|
+
if (listProperties && listProperties.length > 0) return listProperties;
|
|
451
|
+
else {
|
|
452
|
+
listProperties = targetCollection.propertiesOrder || allProperties;
|
|
453
|
+
return listProperties.filter((key) => {
|
|
454
|
+
const prop = targetCollection.properties[key];
|
|
455
|
+
return !(prop && typeof prop === "object" && "isId" in prop && Boolean(prop.isId)) && key !== "id";
|
|
456
|
+
}).filter((key) => {
|
|
457
|
+
const property = targetCollection.properties[key];
|
|
458
|
+
return property && !isPropertyBuilder(property) && !isReferenceProperty(property) && !isRelationProperty(property) && !isHiddenProperty(property) && !isStorageProperty(property);
|
|
459
|
+
}).slice(0, limit);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
var INCLUDE_ALL_RELATIONS = ["*"];
|
|
463
|
+
/**
|
|
464
|
+
* The `include` params that eager-load a collection's relations in the same
|
|
465
|
+
* request as its rows, so previews never fetch once per relation cell.
|
|
466
|
+
*
|
|
467
|
+
* Only the REST transport reads `include`; the realtime transport embeds
|
|
468
|
+
* relation data unconditionally and ignores it. Passing it either way keeps a
|
|
469
|
+
* realtime-less deployment rendering the same cells as a realtime one.
|
|
470
|
+
*/
|
|
471
|
+
function getRelationIncludeParams(collection) {
|
|
472
|
+
if (!collection.properties) return void 0;
|
|
473
|
+
return Object.values(collection.properties).some((property) => property && !isPropertyBuilder(property) && (isRelationProperty(property) || isReferenceProperty(property))) ? INCLUDE_ALL_RELATIONS : void 0;
|
|
474
|
+
}
|
|
475
|
+
function getEntityTitlePropertyKey(collection, propertyConfigs) {
|
|
476
|
+
if (collection.titleProperty) return collection.titleProperty;
|
|
477
|
+
const orderToSearch = collection.propertiesOrder || Object.keys(collection.properties);
|
|
478
|
+
let firstStringCandidate;
|
|
479
|
+
for (const key of orderToSearch) {
|
|
480
|
+
const property = collection.properties[key];
|
|
481
|
+
if (property && !isPropertyBuilder(property)) {
|
|
482
|
+
const prop = property;
|
|
483
|
+
if (isHiddenProperty(prop)) continue;
|
|
484
|
+
if (prop.type === "string" && !prop.ui?.multiline && !prop.ui?.markdown && !prop.storage && !prop.isId) {
|
|
485
|
+
if (!firstStringCandidate) firstStringCandidate = key;
|
|
486
|
+
const lowerKey = key.toLowerCase();
|
|
487
|
+
if ([
|
|
488
|
+
"name",
|
|
489
|
+
"title",
|
|
490
|
+
"label",
|
|
491
|
+
"displayname",
|
|
492
|
+
"username"
|
|
493
|
+
].includes(lowerKey)) return key;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return firstStringCandidate;
|
|
498
|
+
}
|
|
499
|
+
//#endregion
|
|
394
500
|
//#region src/hooks/data/useCollection.tsx
|
|
395
501
|
/**
|
|
396
502
|
* This hook is used to fetch collections using a given collection
|
|
@@ -435,7 +541,7 @@ function useCollection({ path, collection, filterValues, sortBy, itemCount, offs
|
|
|
435
541
|
if (isSchemaDriftError(error)) reportSchemaDrift(error.message);
|
|
436
542
|
};
|
|
437
543
|
const accessor = dataClient.collection(path);
|
|
438
|
-
const includeParams =
|
|
544
|
+
const includeParams = getRelationIncludeParams(collection);
|
|
439
545
|
if (accessor.listen) return accessor.listen({
|
|
440
546
|
where: whereParams,
|
|
441
547
|
limit: itemCount,
|
|
@@ -810,6 +916,7 @@ function useRelationSelector({ path, collection, fixedFilter, pageSize = DEFAULT
|
|
|
810
916
|
unsubscribeRef.current = null;
|
|
811
917
|
}
|
|
812
918
|
}, []);
|
|
919
|
+
const includeParams = getRelationIncludeParams(collection);
|
|
813
920
|
const fetchData = useCallback(() => {
|
|
814
921
|
cleanupSubscription();
|
|
815
922
|
setError(void 0);
|
|
@@ -831,7 +938,8 @@ function useRelationSelector({ path, collection, fixedFilter, pageSize = DEFAULT
|
|
|
831
938
|
where: whereParams,
|
|
832
939
|
limit,
|
|
833
940
|
orderBy: void 0,
|
|
834
|
-
searchString: currentSearch
|
|
941
|
+
searchString: currentSearch,
|
|
942
|
+
include: includeParams
|
|
835
943
|
}, (res) => onEntitiesUpdate({
|
|
836
944
|
data: res.data,
|
|
837
945
|
meta: res.meta
|
|
@@ -842,7 +950,8 @@ function useRelationSelector({ path, collection, fixedFilter, pageSize = DEFAULT
|
|
|
842
950
|
limit,
|
|
843
951
|
offset: 0,
|
|
844
952
|
orderBy: void 0,
|
|
845
|
-
searchString: currentSearch
|
|
953
|
+
searchString: currentSearch,
|
|
954
|
+
include: includeParams
|
|
846
955
|
}).then((res) => onEntitiesUpdate({
|
|
847
956
|
data: res.data,
|
|
848
957
|
meta: res.meta
|
|
@@ -858,7 +967,8 @@ function useRelationSelector({ path, collection, fixedFilter, pageSize = DEFAULT
|
|
|
858
967
|
currentSearch,
|
|
859
968
|
entityToRelationItem,
|
|
860
969
|
cleanupSubscription,
|
|
861
|
-
setLoading
|
|
970
|
+
setLoading,
|
|
971
|
+
includeParams
|
|
862
972
|
]);
|
|
863
973
|
const search = useCallback((searchString) => {
|
|
864
974
|
if (searchTimeoutRef.current) clearTimeout(searchTimeoutRef.current);
|
|
@@ -970,6 +1080,91 @@ async function deleteEntityWithCallbacks({ data, entity, collection, callbacks,
|
|
|
970
1080
|
});
|
|
971
1081
|
}
|
|
972
1082
|
//#endregion
|
|
1083
|
+
//#region src/hooks/useNavigationBlocker.tsx
|
|
1084
|
+
var IDLE_BLOCKER = {
|
|
1085
|
+
state: "unblocked",
|
|
1086
|
+
proceed: void 0,
|
|
1087
|
+
reset: void 0,
|
|
1088
|
+
location: void 0
|
|
1089
|
+
};
|
|
1090
|
+
var NavigationBlockerContext = createContext(null);
|
|
1091
|
+
/**
|
|
1092
|
+
* Owns the single React Router blocker for the whole app.
|
|
1093
|
+
*
|
|
1094
|
+
* React Router only honours **one** blocker at a time: `shouldBlockNavigation`
|
|
1095
|
+
* picks the last-registered blocker function and silently ignores every other
|
|
1096
|
+
* one (it only logs a dev warning). Because blockers register in a `useEffect`,
|
|
1097
|
+
* the winner is whichever surface mounted most recently — so an unsaved-changes
|
|
1098
|
+
* guard could be disabled by an unrelated component mounting after it.
|
|
1099
|
+
*
|
|
1100
|
+
* This provider registers the only `useBlocker` in the tree and multiplexes it,
|
|
1101
|
+
* so every surface that needs to guard navigation gets a say regardless of
|
|
1102
|
+
* mount order. Surfaces register through {@link useNavigationBlocker}.
|
|
1103
|
+
*/
|
|
1104
|
+
function NavigationBlockerProvider({ children }) {
|
|
1105
|
+
const predicates = useRef(/* @__PURE__ */ new Map());
|
|
1106
|
+
const [blockedBy, setBlockedBy] = useState(null);
|
|
1107
|
+
const blocker = useBlocker(useCallback((args) => {
|
|
1108
|
+
for (const [id, predicate] of predicates.current) if (predicate(args)) {
|
|
1109
|
+
setBlockedBy(id);
|
|
1110
|
+
return true;
|
|
1111
|
+
}
|
|
1112
|
+
setBlockedBy(null);
|
|
1113
|
+
return false;
|
|
1114
|
+
}, []));
|
|
1115
|
+
const register = useCallback((id, predicate) => {
|
|
1116
|
+
predicates.current.set(id, predicate);
|
|
1117
|
+
}, []);
|
|
1118
|
+
const unregister = useCallback((id) => {
|
|
1119
|
+
predicates.current.delete(id);
|
|
1120
|
+
setBlockedBy((current) => current === id ? null : current);
|
|
1121
|
+
}, []);
|
|
1122
|
+
const value = useMemo(() => ({
|
|
1123
|
+
register,
|
|
1124
|
+
unregister,
|
|
1125
|
+
blocker,
|
|
1126
|
+
blockedBy
|
|
1127
|
+
}), [
|
|
1128
|
+
register,
|
|
1129
|
+
unregister,
|
|
1130
|
+
blocker,
|
|
1131
|
+
blockedBy
|
|
1132
|
+
]);
|
|
1133
|
+
return /* @__PURE__ */ jsx(NavigationBlockerContext.Provider, {
|
|
1134
|
+
value,
|
|
1135
|
+
children
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* Guard navigation with `predicate`, sharing the app-wide blocker.
|
|
1140
|
+
*
|
|
1141
|
+
* Returns a {@link Blocker} that is only ever in the `blocked` state when *this*
|
|
1142
|
+
* registration is what blocked the navigation — so several guards can coexist
|
|
1143
|
+
* without each of them popping a dialog.
|
|
1144
|
+
*
|
|
1145
|
+
* Returns an idle blocker when no {@link NavigationBlockerProvider} is mounted
|
|
1146
|
+
* above, rather than competing for React Router's single blocker slot.
|
|
1147
|
+
*/
|
|
1148
|
+
function useNavigationBlocker(predicate) {
|
|
1149
|
+
const context = useContext(NavigationBlockerContext);
|
|
1150
|
+
const id = useId();
|
|
1151
|
+
const predicateRef = useRef(predicate);
|
|
1152
|
+
predicateRef.current = predicate;
|
|
1153
|
+
const register = context?.register;
|
|
1154
|
+
const unregister = context?.unregister;
|
|
1155
|
+
useEffect(() => {
|
|
1156
|
+
if (!register || !unregister) return;
|
|
1157
|
+
register(id, (args) => predicateRef.current(args));
|
|
1158
|
+
return () => unregister(id);
|
|
1159
|
+
}, [
|
|
1160
|
+
register,
|
|
1161
|
+
unregister,
|
|
1162
|
+
id
|
|
1163
|
+
]);
|
|
1164
|
+
if (!context) return IDLE_BLOCKER;
|
|
1165
|
+
return context.blockedBy === id ? context.blocker : IDLE_BLOCKER;
|
|
1166
|
+
}
|
|
1167
|
+
//#endregion
|
|
973
1168
|
//#region src/hooks/useUnsavedChangesDialog.tsx
|
|
974
1169
|
/**
|
|
975
1170
|
* A single, unified hook to prevent navigation when there are unsaved changes.
|
|
@@ -980,7 +1175,7 @@ async function deleteEntityWithCallbacks({ data, entity, collection, callbacks,
|
|
|
980
1175
|
*/
|
|
981
1176
|
function useUnsavedChangesDialog(when, onOk) {
|
|
982
1177
|
const [manualDialogOpen, setManualDialogOpen] = useState(false);
|
|
983
|
-
const blocker =
|
|
1178
|
+
const blocker = useNavigationBlocker(useCallback(({ currentLocation, nextLocation }) => when && currentLocation.pathname !== nextLocation.pathname, [when]));
|
|
984
1179
|
useEffect(() => {
|
|
985
1180
|
if (!when) return;
|
|
986
1181
|
const handleBeforeUnload = (e) => {
|
|
@@ -2347,18 +2542,21 @@ function useDataTableController({ path, collection, scrollRestoration, entitiesD
|
|
|
2347
2542
|
const whereParams = filterValues && Object.keys(filterValues).length > 0 ? filterValues : void 0;
|
|
2348
2543
|
const orderByParams = sortBy ? [String(sortBy[0]), sortBy[1]] : void 0;
|
|
2349
2544
|
let unsubscribe;
|
|
2545
|
+
const includeParams = getRelationIncludeParams(collection);
|
|
2350
2546
|
if (accessor.listen) unsubscribe = accessor.listen({
|
|
2351
2547
|
where: whereParams,
|
|
2352
2548
|
limit: itemCount,
|
|
2353
2549
|
orderBy: orderByParams,
|
|
2354
|
-
searchString
|
|
2550
|
+
searchString,
|
|
2551
|
+
include: includeParams
|
|
2355
2552
|
}, (res) => onEntitiesUpdate(res.data), onError);
|
|
2356
2553
|
else {
|
|
2357
2554
|
accessor.find({
|
|
2358
2555
|
where: whereParams,
|
|
2359
2556
|
limit: itemCount,
|
|
2360
2557
|
orderBy: orderByParams,
|
|
2361
|
-
searchString
|
|
2558
|
+
searchString,
|
|
2559
|
+
include: includeParams
|
|
2362
2560
|
}).then((res) => onEntitiesUpdate(res.data)).catch(onError);
|
|
2363
2561
|
unsubscribe = () => void 0;
|
|
2364
2562
|
}
|
|
@@ -9080,10 +9278,10 @@ function LoginForm({ onClose, onForgotPassword, authController, registrationMode
|
|
|
9080
9278
|
};
|
|
9081
9279
|
}, [onClose]);
|
|
9082
9280
|
function handleEnterPassword() {
|
|
9083
|
-
if (email && password && authController.emailPasswordLogin) authController.emailPasswordLogin(email, password);
|
|
9281
|
+
if (email && password && authController.emailPasswordLogin) Promise.resolve(authController.emailPasswordLogin(email, password)).catch(() => void 0);
|
|
9084
9282
|
}
|
|
9085
9283
|
function handleRegistration() {
|
|
9086
|
-
if (email && password && authController.register) authController.register(email, password, displayName);
|
|
9284
|
+
if (email && password && authController.register) Promise.resolve(authController.register(email, password, displayName)).catch(() => void 0);
|
|
9087
9285
|
}
|
|
9088
9286
|
const handleSubmit = (event) => {
|
|
9089
9287
|
event.preventDefault();
|
|
@@ -15337,6 +15535,11 @@ function Rebase(props) {
|
|
|
15337
15535
|
const normalizedDataSources = useMemo(() => {
|
|
15338
15536
|
return dataSourcesProp ?? [];
|
|
15339
15537
|
}, [dataSourcesProp]);
|
|
15538
|
+
const collectionResolverRef = useRef(void 0);
|
|
15539
|
+
const registerCollectionResolver = React.useCallback((resolver) => {
|
|
15540
|
+
collectionResolverRef.current = resolver;
|
|
15541
|
+
}, []);
|
|
15542
|
+
const entityDataOptions = useMemo(() => ({ resolveCollection: (slug) => collectionResolverRef.current?.(slug) }), []);
|
|
15340
15543
|
const dataSourcesRef = useRef(null);
|
|
15341
15544
|
const dataSourcesValue = useMemo(() => {
|
|
15342
15545
|
const sig = normalizedDataSources.map((d) => ({
|
|
@@ -15355,7 +15558,7 @@ function Rebase(props) {
|
|
|
15355
15558
|
...definition,
|
|
15356
15559
|
transport: ds.transport ?? (driver ? "direct" : "server")
|
|
15357
15560
|
};
|
|
15358
|
-
if (driver) sources[ds.key] = buildRebaseData(driver);
|
|
15561
|
+
if (driver) sources[ds.key] = buildRebaseData(driver, entityDataOptions);
|
|
15359
15562
|
}
|
|
15360
15563
|
const value = {
|
|
15361
15564
|
registry,
|
|
@@ -15366,16 +15569,20 @@ function Rebase(props) {
|
|
|
15366
15569
|
value
|
|
15367
15570
|
};
|
|
15368
15571
|
return value;
|
|
15369
|
-
}, [normalizedDataSources]);
|
|
15572
|
+
}, [normalizedDataSources, entityDataOptions]);
|
|
15370
15573
|
const resolvedData = useMemo(() => {
|
|
15371
15574
|
const registeredDefault = dataSourcesValue.sources[DEFAULT_DATA_SOURCE_KEY];
|
|
15372
15575
|
if (registeredDefault) return registeredDefault;
|
|
15373
|
-
if (client?.data) return wrapAsEntityData(client.data);
|
|
15576
|
+
if (client?.data) return wrapAsEntityData(client.data, entityDataOptions);
|
|
15374
15577
|
const built = Object.values(dataSourcesValue.sources);
|
|
15375
15578
|
if (built.length === 1) return built[0];
|
|
15376
15579
|
if (built.length > 1) throw new Error("[Rebase] Several data sources are registered but none is the default. Pass a `client`, or key one `dataSources` entry \"(default)\".");
|
|
15377
15580
|
throw new Error("Rebase requires either `client` or a `dataSources` entry with a driver to be provided");
|
|
15378
|
-
}, [
|
|
15581
|
+
}, [
|
|
15582
|
+
client,
|
|
15583
|
+
dataSourcesValue,
|
|
15584
|
+
entityDataOptions
|
|
15585
|
+
]);
|
|
15379
15586
|
const resolvedStorage = storageSourceProp ?? client?.storage;
|
|
15380
15587
|
const [remoteStorageSources, setRemoteStorageSources] = useState([]);
|
|
15381
15588
|
const authUser = authController.user;
|
|
@@ -15448,6 +15655,7 @@ function Rebase(props) {
|
|
|
15448
15655
|
executeSql: wsAdmin.executeSql.bind(wsAdmin),
|
|
15449
15656
|
fetchAvailableDatabases: wsAdmin.fetchAvailableDatabases?.bind(wsAdmin),
|
|
15450
15657
|
fetchAvailableRoles: wsAdmin.fetchAvailableRoles?.bind(wsAdmin),
|
|
15658
|
+
fetchApplicationRoles: wsAdmin.fetchApplicationRoles?.bind(wsAdmin),
|
|
15451
15659
|
fetchCurrentDatabase: wsAdmin.fetchCurrentDatabase?.bind(wsAdmin),
|
|
15452
15660
|
fetchUnmappedTables: wsAdmin.fetchUnmappedTables?.bind(wsAdmin),
|
|
15453
15661
|
fetchTableMetadata: wsAdmin.fetchTableMetadata?.bind(wsAdmin),
|
|
@@ -15520,20 +15728,23 @@ function Rebase(props) {
|
|
|
15520
15728
|
value: storageSourcesValue,
|
|
15521
15729
|
children: /* @__PURE__ */ jsx(StorageSourceContext.Provider, {
|
|
15522
15730
|
value: resolvedStorage,
|
|
15523
|
-
children: /* @__PURE__ */ jsx(
|
|
15524
|
-
value:
|
|
15525
|
-
children: /* @__PURE__ */ jsx(
|
|
15526
|
-
value:
|
|
15527
|
-
children: /* @__PURE__ */ jsx(
|
|
15528
|
-
value:
|
|
15529
|
-
children: /* @__PURE__ */ jsx(
|
|
15530
|
-
value:
|
|
15531
|
-
children: /* @__PURE__ */ jsx(
|
|
15532
|
-
value:
|
|
15533
|
-
children: /* @__PURE__ */ jsx(
|
|
15534
|
-
|
|
15535
|
-
children
|
|
15536
|
-
|
|
15731
|
+
children: /* @__PURE__ */ jsx(CollectionResolverRegistrationContext.Provider, {
|
|
15732
|
+
value: registerCollectionResolver,
|
|
15733
|
+
children: /* @__PURE__ */ jsx(DataSourcesContext.Provider, {
|
|
15734
|
+
value: dataSourcesValue,
|
|
15735
|
+
children: /* @__PURE__ */ jsx(RebaseDataContext.Provider, {
|
|
15736
|
+
value: resolvedData,
|
|
15737
|
+
children: /* @__PURE__ */ jsx(DatabaseAdminContext.Provider, {
|
|
15738
|
+
value: resolvedDatabaseAdmin,
|
|
15739
|
+
children: /* @__PURE__ */ jsx(AuthControllerContext.Provider, {
|
|
15740
|
+
value: authController,
|
|
15741
|
+
children: /* @__PURE__ */ jsx(EffectiveRoleControllerContext.Provider, {
|
|
15742
|
+
value: activeEffectiveRoleController,
|
|
15743
|
+
children: /* @__PURE__ */ jsx(DialogsProvider, { children: /* @__PURE__ */ jsx(SchemaDriftProvider, { children: /* @__PURE__ */ jsx(RebaseRegistryProvider, { children: /* @__PURE__ */ jsx(RebaseInternal, {
|
|
15744
|
+
loading,
|
|
15745
|
+
children
|
|
15746
|
+
}) }) }) })
|
|
15747
|
+
})
|
|
15537
15748
|
})
|
|
15538
15749
|
})
|
|
15539
15750
|
})
|
|
@@ -16470,81 +16681,6 @@ async function resizeImage(file, imageResize) {
|
|
|
16470
16681
|
});
|
|
16471
16682
|
}
|
|
16472
16683
|
//#endregion
|
|
16473
|
-
//#region src/util/previews.ts
|
|
16474
|
-
function isReferenceProperty(property) {
|
|
16475
|
-
if (!property) return null;
|
|
16476
|
-
if (property.type === "reference") return true;
|
|
16477
|
-
if (property.type === "array") if (Array.isArray(property.of)) return false;
|
|
16478
|
-
else return property.of?.type === "reference";
|
|
16479
|
-
return false;
|
|
16480
|
-
}
|
|
16481
|
-
function isRelationProperty(property) {
|
|
16482
|
-
if (!property) return null;
|
|
16483
|
-
if (property.type === "relation") return true;
|
|
16484
|
-
if (property.type === "array") if (Array.isArray(property.of)) return false;
|
|
16485
|
-
else return property.of?.type === "relation";
|
|
16486
|
-
return false;
|
|
16487
|
-
}
|
|
16488
|
-
function isHiddenProperty(property) {
|
|
16489
|
-
if (!property) return false;
|
|
16490
|
-
return Boolean(property.ui?.hideFromCollection);
|
|
16491
|
-
}
|
|
16492
|
-
/**
|
|
16493
|
-
* Returns true when the property holds file-storage content (single image,
|
|
16494
|
-
* array of images, generic upload, …). These properties are rendered by the
|
|
16495
|
-
* dedicated image-slot and should NOT appear as regular preview columns.
|
|
16496
|
-
*/
|
|
16497
|
-
function isStorageProperty(property) {
|
|
16498
|
-
if (!property) return false;
|
|
16499
|
-
if (property.type === "string" && property.storage) return true;
|
|
16500
|
-
if (property.type === "string" && property.ui?.url === "image") return true;
|
|
16501
|
-
if (property.type === "array" && property.of && !Array.isArray(property.of)) {
|
|
16502
|
-
const inner = property.of;
|
|
16503
|
-
if (inner.type === "string" && (inner.storage || inner.ui?.url === "image")) return true;
|
|
16504
|
-
}
|
|
16505
|
-
return false;
|
|
16506
|
-
}
|
|
16507
|
-
function getEntityPreviewKeys(authController, targetCollection, fields, previewProperties, limit = 3) {
|
|
16508
|
-
const allProperties = Object.keys(targetCollection.properties);
|
|
16509
|
-
let listProperties = previewProperties?.filter((p) => allProperties.includes(p));
|
|
16510
|
-
if (!listProperties && targetCollection.previewProperties) listProperties = targetCollection.previewProperties?.filter((p) => allProperties.includes(p));
|
|
16511
|
-
if (listProperties && listProperties.length > 0) return listProperties;
|
|
16512
|
-
else {
|
|
16513
|
-
listProperties = targetCollection.propertiesOrder || allProperties;
|
|
16514
|
-
return listProperties.filter((key) => {
|
|
16515
|
-
const prop = targetCollection.properties[key];
|
|
16516
|
-
return !(prop && typeof prop === "object" && "isId" in prop && Boolean(prop.isId)) && key !== "id";
|
|
16517
|
-
}).filter((key) => {
|
|
16518
|
-
const property = targetCollection.properties[key];
|
|
16519
|
-
return property && !isPropertyBuilder(property) && !isReferenceProperty(property) && !isRelationProperty(property) && !isHiddenProperty(property) && !isStorageProperty(property);
|
|
16520
|
-
}).slice(0, limit);
|
|
16521
|
-
}
|
|
16522
|
-
}
|
|
16523
|
-
function getEntityTitlePropertyKey(collection, propertyConfigs) {
|
|
16524
|
-
if (collection.titleProperty) return collection.titleProperty;
|
|
16525
|
-
const orderToSearch = collection.propertiesOrder || Object.keys(collection.properties);
|
|
16526
|
-
let firstStringCandidate;
|
|
16527
|
-
for (const key of orderToSearch) {
|
|
16528
|
-
const property = collection.properties[key];
|
|
16529
|
-
if (property && !isPropertyBuilder(property)) {
|
|
16530
|
-
const prop = property;
|
|
16531
|
-
if (isHiddenProperty(prop)) continue;
|
|
16532
|
-
if (prop.type === "string" && !prop.ui?.multiline && !prop.ui?.markdown && !prop.storage && !prop.isId) {
|
|
16533
|
-
if (!firstStringCandidate) firstStringCandidate = key;
|
|
16534
|
-
const lowerKey = key.toLowerCase();
|
|
16535
|
-
if ([
|
|
16536
|
-
"name",
|
|
16537
|
-
"title",
|
|
16538
|
-
"label",
|
|
16539
|
-
"displayname",
|
|
16540
|
-
"username"
|
|
16541
|
-
].includes(lowerKey)) return key;
|
|
16542
|
-
}
|
|
16543
|
-
}
|
|
16544
|
-
}
|
|
16545
|
-
return firstStringCandidate;
|
|
16546
|
-
}
|
|
16547
|
-
//#endregion
|
|
16548
16684
|
//#region src/util/enums.ts
|
|
16549
16685
|
function getColorScheme(enumValues, key) {
|
|
16550
16686
|
const labelOrConfig = getLabelOrConfigFrom(enumValues, key);
|
|
@@ -16838,6 +16974,6 @@ function useBridgeRegistration(key, value) {
|
|
|
16838
16974
|
]);
|
|
16839
16975
|
}
|
|
16840
16976
|
//#endregion
|
|
16841
|
-
export { ADDITIONAL_TAB_WIDTH, AIIcon, AIModifiedIndicator, AdminModeControllerContext, AdminModeControllerProvider, AnalyticsContext, ApiConfigProvider, AuthApiError, AuthControllerContext, CONTAINER_FULL_WIDTH, CollectionComponentOverrideProvider, CollectionScopeContext, CollectionScopeProvider, ComponentOverrideContext, ConfirmationDialog, CrmDashboardDemo, CustomizationControllerContext, DEFAULT_PAGE_SIZE, DataDriverContext, DataSourcesContext, DialogsControllerContext, DialogsProvider, EffectiveRoleControllerContext, EffectiveRoleControllerProvider, ErrorTooltip, ErrorView, FORM_CONTAINER_WIDTH, GlobalComponentOverrideProvider, IconForView, LanguageToggle, LoginView, ModeControllerContext, ModeControllerProvider, NotFoundPage, PluginProviderStack, REBASE_LOCALE_STORAGE_KEY, Rebase, RebaseAuth, RebaseClientInstanceContext, RebaseDataContext, RebaseI18nProvider, RebaseLogo, RebaseRegistryProvider, RebaseRouter, RebaseRoutes, STUDIO_NAVIGATION_GROUPS, SchemaDriftBanner, SchemaDriftProvider, SnackbarProvider, StorageSourceContext, StorageSourcesContext, StudioBridgeContext, StudioBridgeProvider, StudioBridgeRegistryContext, StudioBridgeRegistryProvider, UIReferenceView, UIStyleGuide, UnsavedChangesDialog, UserConfigurationPersistenceContext, UserDisplay, UserSelectPopover, UserSettingsView, buildCollapsedDefaults, buildEnumLabel, clearAuthConfigCache, clearFetchCache, createAuthConfigCache, createFormexStub, deleteEntityWithCallbacks, en, es, fetchAuthConfig, flattenKeys, getColorScheme, getColumnKeysForProperty, getEntityFromCache, getEntityFromMemoryCache, getEntityPreviewKeys, getEntityTitlePropertyKey, getFormFieldKeys, getIcon, getRowHeight, getSubcollectionColumnId, iconsSearch, isEnumValueDisabled, isSchemaDriftError, populateFetchCache, removeEntityFromCache, removeEntityFromMemoryCache, resolveComponentRef, saveEntityToCache, saveEntityToMemoryCache, saveEntityWithCallbacks, useAdminModeController, useAnalyticsController, useApiConfig, useAuthController, useAuthSubscription, useBackendStorageSource, useBridgeRegistration, useBrowserTitleAndIcon, useBuildAdminModeController, useBuildEffectiveRoleController, useBuildLocalConfigurationPersistence, useBuildModeController, useClipboard, useCollapsedGroups, useCollection, useCollectionScope, useColumnIds, useComponentOverride, useCustomizationController, useData, useDataSources, useDataTableController, useDebouncedData, useDialogsController, useEffectiveRoleController, useFetch, useLargeLayout, useModeController, usePermissions, useRebaseAuthController, useRebaseClient, useRebaseContext, useRebaseRegistry, useRebaseRegistryDispatch, useRelationSelector, useResolvedComponent, useRestoreScroll, useSchemaDriftContext, useScrollRestoration, useSlot, useSnackbarController, useStorageSource, useStorageSources, useStorageUploadController, useStudioBreadcrumbs, useStudioCollectionRegistry, useStudioNavigationState, useStudioSidePanelController, useStudioUrlController, useTranslation, useUnsavedChangesDialog, useUserConfigurationPersistence };
|
|
16977
|
+
export { ADDITIONAL_TAB_WIDTH, AIIcon, AIModifiedIndicator, AdminModeControllerContext, AdminModeControllerProvider, AnalyticsContext, ApiConfigProvider, AuthApiError, AuthControllerContext, CONTAINER_FULL_WIDTH, CollectionComponentOverrideProvider, CollectionResolverRegistrationContext, CollectionScopeContext, CollectionScopeProvider, ComponentOverrideContext, ConfirmationDialog, CrmDashboardDemo, CustomizationControllerContext, DEFAULT_PAGE_SIZE, DataDriverContext, DataSourcesContext, DialogsControllerContext, DialogsProvider, EffectiveRoleControllerContext, EffectiveRoleControllerProvider, ErrorTooltip, ErrorView, FORM_CONTAINER_WIDTH, GlobalComponentOverrideProvider, IconForView, LanguageToggle, LoginView, ModeControllerContext, ModeControllerProvider, NavigationBlockerProvider, NotFoundPage, PluginProviderStack, REBASE_LOCALE_STORAGE_KEY, Rebase, RebaseAuth, RebaseClientInstanceContext, RebaseDataContext, RebaseI18nProvider, RebaseLogo, RebaseRegistryProvider, RebaseRouter, RebaseRoutes, STUDIO_NAVIGATION_GROUPS, SchemaDriftBanner, SchemaDriftProvider, SnackbarProvider, StorageSourceContext, StorageSourcesContext, StudioBridgeContext, StudioBridgeProvider, StudioBridgeRegistryContext, StudioBridgeRegistryProvider, UIReferenceView, UIStyleGuide, UnsavedChangesDialog, UserConfigurationPersistenceContext, UserDisplay, UserSelectPopover, UserSettingsView, buildCollapsedDefaults, buildEnumLabel, clearAuthConfigCache, clearFetchCache, createAuthConfigCache, createFormexStub, deleteEntityWithCallbacks, en, es, fetchAuthConfig, flattenKeys, getColorScheme, getColumnKeysForProperty, getEntityFromCache, getEntityFromMemoryCache, getEntityPreviewKeys, getEntityTitlePropertyKey, getFormFieldKeys, getIcon, getRelationIncludeParams, getRowHeight, getSubcollectionColumnId, iconsSearch, isEnumValueDisabled, isSchemaDriftError, populateFetchCache, removeEntityFromCache, removeEntityFromMemoryCache, resolveComponentRef, saveEntityToCache, saveEntityToMemoryCache, saveEntityWithCallbacks, useAdminModeController, useAnalyticsController, useApiConfig, useAuthController, useAuthSubscription, useBackendStorageSource, useBridgeRegistration, useBrowserTitleAndIcon, useBuildAdminModeController, useBuildEffectiveRoleController, useBuildLocalConfigurationPersistence, useBuildModeController, useClipboard, useCollapsedGroups, useCollection, useCollectionScope, useColumnIds, useComponentOverride, useCustomizationController, useData, useDataSources, useDataTableController, useDebouncedData, useDialogsController, useEffectiveRoleController, useFetch, useLargeLayout, useModeController, useNavigationBlocker, usePermissions, useRebaseAuthController, useRebaseClient, useRebaseContext, useRebaseRegistry, useRebaseRegistryDispatch, useRelationSelector, useResolvedComponent, useRestoreScroll, useSchemaDriftContext, useScrollRestoration, useSlot, useSnackbarController, useStorageSource, useStorageSources, useStorageUploadController, useStudioBreadcrumbs, useStudioCollectionRegistry, useStudioNavigationState, useStudioSidePanelController, useStudioUrlController, useTranslation, useUnsavedChangesDialog, useUserConfigurationPersistence };
|
|
16842
16978
|
|
|
16843
16979
|
//# sourceMappingURL=index.es.js.map
|