ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
81 lines • 4.73 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoreAdminUI = void 0;
const React = __importStar(require("react"));
const react_1 = require("react");
const react_error_boundary_1 = require("react-error-boundary");
const CoreAdminRoutes_1 = require("./CoreAdminRoutes.cjs");
const routing_1 = require("../routing/index.cjs");
const util_1 = require("../util/index.cjs");
const DefaultTitleContext_1 = require("./DefaultTitleContext.cjs");
const DefaultLayout = ({ children }) => (React.createElement(React.Fragment, null, children));
const DefaultError = ({ error, errorInfo, resetErrorBoundary }) => {
(0, routing_1.useResetErrorBoundaryOnLocationChange)(resetErrorBoundary);
return (React.createElement("div", null,
React.createElement("h1", null, "Error"),
React.createElement("pre", null,
error.message,
errorInfo?.componentStack)));
};
const CoreAdminUI = (props) => {
const [errorInfo, setErrorInfo] = (0, react_1.useState)({});
const { Route, Routes } = (0, routing_1.useRouterProvider)();
const { authCallbackPage: LoginCallbackPage = false, catchAll = Noop, children, dashboard, disableTelemetry = false, error: ErrorComponent = DefaultError, layout = DefaultLayout, loading = Noop, loginPage: LoginPage = false, ready = util_1.Ready, requireAuth = false, title = 'React Admin', authenticationError = Noop, accessDenied = Noop, } = props;
(0, react_1.useEffect)(() => {
if (disableTelemetry ||
process.env.NODE_ENV !== 'production' ||
typeof window === 'undefined' ||
typeof window.location === 'undefined' ||
typeof Image === 'undefined') {
return;
}
const img = new Image();
img.src = `https://react-admin-telemetry.marmelab.com/react-admin-telemetry?domain=${window.location.hostname}`;
}, [disableTelemetry]);
const handleError = (error, info) => setErrorInfo(info);
return (React.createElement(DefaultTitleContext_1.DefaultTitleContextProvider, { value: title },
React.createElement(react_error_boundary_1.ErrorBoundary, { onError: handleError, fallbackRender: ({ error, resetErrorBoundary }) => (React.createElement("div", { style: { minHeight: '100vh' } },
React.createElement(ErrorComponent, { error: error, errorInfo: errorInfo, resetErrorBoundary: resetErrorBoundary }))) },
React.createElement(Routes, null,
LoginPage !== false && LoginPage !== true ? (React.createElement(Route, { path: "/login", element: createOrGetElement(LoginPage) })) : null,
LoginCallbackPage !== false &&
LoginCallbackPage !== true ? (React.createElement(Route, { path: "/auth-callback", element: createOrGetElement(LoginCallbackPage) })) : null,
React.createElement(Route, { path: "/*", element: React.createElement(CoreAdminRoutes_1.CoreAdminRoutes, { catchAll: catchAll, dashboard: dashboard, layout: layout, loading: loading, requireAuth: requireAuth, ready: ready, authenticationError: authenticationError, accessDenied: accessDenied }, children) })))));
};
exports.CoreAdminUI = CoreAdminUI;
const createOrGetElement = el => ((0, react_1.isValidElement)(el) ? el : (0, react_1.createElement)(el));
const Noop = () => null;
//# sourceMappingURL=CoreAdminUI.js.map