@plumile/backoffice-react 0.2.7 → 0.2.8

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 (30) hide show
  1. package/README.md +23 -0
  2. package/lib/esm/auth/backofficeAuthHeaders.js +2 -9
  3. package/lib/esm/auth/backofficeAuthHeaders.js.map +1 -1
  4. package/lib/esm/hooks/useAuthenticatedRouter.js +79 -0
  5. package/lib/esm/hooks/useAuthenticatedRouter.js.map +1 -0
  6. package/lib/esm/index.js +26 -24
  7. package/lib/esm/provider/BackofficeProvider.js +141 -140
  8. package/lib/esm/provider/BackofficeProvider.js.map +1 -1
  9. package/lib/esm/provider/BackofficeRouterBoundary.js +22 -0
  10. package/lib/esm/provider/BackofficeRouterBoundary.js.map +1 -0
  11. package/lib/esm/router/createBackofficeRoutes.js +188 -184
  12. package/lib/esm/router/createBackofficeRoutes.js.map +1 -1
  13. package/lib/types/auth/backofficeAuthHeaders.d.ts +1 -1
  14. package/lib/types/auth/backofficeAuthHeaders.d.ts.map +1 -1
  15. package/lib/types/hooks/useAuthenticatedRouter.d.ts +18 -0
  16. package/lib/types/hooks/useAuthenticatedRouter.d.ts.map +1 -0
  17. package/lib/types/index.d.ts +2 -0
  18. package/lib/types/index.d.ts.map +1 -1
  19. package/lib/types/provider/BackofficeProvider.d.ts.map +1 -1
  20. package/lib/types/provider/BackofficeRouterBoundary.d.ts +9 -0
  21. package/lib/types/provider/BackofficeRouterBoundary.d.ts.map +1 -0
  22. package/lib/types/provider/types.d.ts +2 -1
  23. package/lib/types/provider/types.d.ts.map +1 -1
  24. package/lib/types/router/createBackofficeRoutes.d.ts +3 -2
  25. package/lib/types/router/createBackofficeRoutes.d.ts.map +1 -1
  26. package/package.json +11 -11
  27. package/lib/esm/provider/useBackofficeAuthRouteGate.js +0 -39
  28. package/lib/esm/provider/useBackofficeAuthRouteGate.js.map +0 -1
  29. package/lib/types/provider/useBackofficeAuthRouteGate.d.ts +0 -2
  30. package/lib/types/provider/useBackofficeAuthRouteGate.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"BackofficeProvider.js","names":[],"sources":["../../../src/provider/BackofficeProvider.tsx"],"sourcesContent":["import {\n StrictMode,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ContextType,\n type JSX,\n} from 'react';\nimport { createInstance } from 'i18next';\nimport { I18nextProvider } from 'react-i18next';\nimport createRouter from '@plumile/router/routing/createRouter.js';\nimport RouterRenderer from '@plumile/router/routing/RouterRenderer.js';\nimport RoutingContext from '@plumile/router/routing/RoutingContext.js';\nimport { BackofficeThemeProvider, RoutePendingBar } from '@plumile/ui';\n\nimport { type BackofficeEntityManifestMap } from '@plumile/backoffice-core/types.js';\nimport {\n RelayProvider,\n configureRelayEnvironment,\n useRelayOperationActivity,\n} from '@plumile/relay';\n\nimport { createI18nInstance } from '../i18n/createI18nInstance.js';\nimport { withBackofficeReactI18nResources } from '../i18n/resources.js';\nimport { useRelayEnvironment } from '../relay/useRelayEnvironment.js';\nimport { BackofficeConfigProvider } from './BackofficeConfigContext.js';\nimport {\n createBackofficeRoutes,\n type BackofficeRouterContext,\n} from '../router/createBackofficeRoutes.js';\nimport type { BackofficeProviderProps } from './types.js';\nimport { validateBackofficeDashboardRegistrations } from './dashboardRegistrations.js';\nimport {\n BackofficeRouteFallback,\n BackofficeStaticRouteFallback,\n} from '../components/backoffice/routing/BackofficeRouteFallback.js';\nimport { createBackofficeEntityRegistry } from './entityRegistry.js';\nimport { useBackofficeAuthRouteGate } from './useBackofficeAuthRouteGate.js';\n\nconst normalizeAbsolutePath = (value: string): string => {\n if (value.trim() === '' || value === '/') {\n return '/';\n }\n if (!value.startsWith('/')) {\n return `/${value}`;\n }\n if (value.endsWith('/')) {\n return value.slice(0, -1);\n }\n return value;\n};\n\nconst prefixRoutePath = (basePath: string, value: string): string => {\n const normalizedPath = normalizeAbsolutePath(value);\n const normalizedBasePath = normalizeAbsolutePath(basePath);\n if (normalizedBasePath === '/') {\n return normalizedPath;\n }\n if (\n normalizedPath === normalizedBasePath ||\n normalizedPath.startsWith(`${normalizedBasePath}/`)\n ) {\n return normalizedPath;\n }\n if (normalizedPath === '/') {\n return normalizedBasePath;\n }\n return `${normalizedBasePath}${normalizedPath}`;\n};\n\nconst resolveEntityManifest = (\n manifest: BackofficeEntityManifestMap,\n basePath: string,\n): BackofficeEntityManifestMap => {\n return Object.fromEntries(\n Object.entries(manifest).map(([entityId, item]) => {\n return [\n entityId,\n {\n ...item,\n routes: {\n list: prefixRoutePath(basePath, item.routes.list),\n detail: (id: string) => {\n return prefixRoutePath(basePath, item.routes.detail(id));\n },\n detailPage: (id: string, pageId: string) => {\n return prefixRoutePath(\n basePath,\n item.routes.detailPage(id, pageId),\n );\n },\n },\n } satisfies BackofficeEntityManifestMap[string],\n ] as const;\n }),\n );\n};\n\ntype RouterShellProps = {\n routes: ReturnType<typeof createBackofficeRoutes>;\n instrumentations?: BackofficeProviderProps['instrumentations'];\n};\n\ntype BackofficeRouterInstance = {\n context: NonNullable<ContextType<typeof RoutingContext>>;\n cleanup: () => void;\n};\n\nconst useBackofficeRouterInstance = ({\n routes,\n context,\n instrumentations,\n}: {\n routes: ReturnType<typeof createBackofficeRoutes>;\n context: BackofficeRouterContext;\n instrumentations?: BackofficeProviderProps['instrumentations'];\n}): BackofficeRouterInstance | null => {\n const [router, setRouter] = useState<BackofficeRouterInstance | null>(null);\n const routerRef = useRef<BackofficeRouterInstance | null>(null);\n\n useEffect(() => {\n const nextRouter = createRouter(routes, {\n context,\n instrumentations,\n });\n routerRef.current = nextRouter;\n setRouter(nextRouter);\n\n return () => {\n if (routerRef.current === nextRouter) {\n routerRef.current = null;\n }\n nextRouter.cleanup();\n };\n }, [context, instrumentations, routes]);\n\n return router;\n};\n\nconst RouterShell = ({\n routes,\n instrumentations,\n}: RouterShellProps): JSX.Element => {\n const relayEnvironment = useRelayEnvironment();\n const relayOperationActivity = useRelayOperationActivity();\n\n const routerContext = useMemo(() => {\n return { relayEnvironment };\n }, [relayEnvironment]);\n\n const router = useBackofficeRouterInstance({\n routes,\n context: routerContext,\n instrumentations,\n });\n\n if (router == null) {\n return <BackofficeRouteFallback />;\n }\n\n return (\n <RoutingContext.Provider value={router.context}>\n <RouterRenderer\n enableTransition\n externalPending={relayOperationActivity.pendingCount > 0}\n fallback={<BackofficeRouteFallback />}\n pending={<RoutePendingBar />}\n />\n </RoutingContext.Provider>\n );\n};\n\nexport const BackofficeProvider = (\n props: BackofficeProviderProps,\n): JSX.Element => {\n const basePath = normalizeAbsolutePath(props.basePath ?? '/');\n const canMountRouter = useBackofficeAuthRouteGate(basePath);\n\n const entityManifest = useMemo(() => {\n return resolveEntityManifest(props.entityManifest, basePath);\n }, [basePath, props.entityManifest]);\n const entityRegistry = useMemo(() => {\n return createBackofficeEntityRegistry(entityManifest, { basePath });\n }, [basePath, entityManifest]);\n\n const graphQLConfig = props.graphql;\n const dashboards = useMemo(() => {\n return validateBackofficeDashboardRegistrations(props.dashboards);\n }, [props.dashboards]);\n\n useEffect(() => {\n const httpUrl = graphQLConfig.httpUrl ?? graphQLConfig.endpoint;\n const wsUrl = graphQLConfig.wsUrl ?? graphQLConfig.wsEndpoint;\n configureRelayEnvironment({\n httpUrl,\n wsUrl,\n getDataId: graphQLConfig.getDataId,\n logEvents: graphQLConfig.logEvents,\n getAuthHeaders: graphQLConfig.getAuthHeaders,\n });\n }, [\n graphQLConfig.endpoint,\n graphQLConfig.getAuthHeaders,\n graphQLConfig.getDataId,\n graphQLConfig.httpUrl,\n graphQLConfig.logEvents,\n graphQLConfig.wsEndpoint,\n graphQLConfig.wsUrl,\n ]);\n\n const mergedResources = useMemo(() => {\n return withBackofficeReactI18nResources(props.i18n?.resources ?? {});\n }, [props.i18n?.resources]);\n\n const i18nInstance = useMemo(() => {\n return props.i18n?.instance ?? createInstance();\n }, [props.i18n?.instance]);\n const [isI18nReady, setIsI18nReady] = useState(i18nInstance.isInitialized);\n\n useEffect(() => {\n let isCurrent = true;\n const markI18nReady = (): void => {\n if (isCurrent) {\n setIsI18nReady(true);\n }\n };\n\n i18nInstance.on('initialized', markI18nReady);\n if (i18nInstance.isInitialized) {\n markI18nReady();\n return () => {\n isCurrent = false;\n i18nInstance.off('initialized', markI18nReady);\n };\n }\n\n const readyCheck = globalThis.setTimeout(() => {\n if (i18nInstance.isInitialized) {\n markI18nReady();\n }\n }, 0);\n\n const initOptions = props.i18n?.initOptions ?? {};\n const defaultNs = initOptions.defaultNS ?? 'translations';\n const ns = initOptions.ns ?? ['backofficeReact', 'translations', 'ui'];\n createI18nInstance({\n resources: mergedResources,\n lng: props.i18n?.lng,\n fallbackLng: props.i18n?.fallbackLng,\n initOptions: {\n ...initOptions,\n defaultNS: defaultNs,\n ns,\n react: {\n useSuspense: false,\n ...initOptions.react,\n },\n },\n instance: i18nInstance,\n useLanguageDetector: props.i18n?.useLanguageDetector,\n detection: props.i18n?.detection,\n })\n .then(markI18nReady)\n .catch((error: unknown) => {\n markI18nReady();\n // eslint-disable-next-line no-console\n console.error(error);\n });\n\n return () => {\n isCurrent = false;\n globalThis.clearTimeout(readyCheck);\n i18nInstance.off('initialized', markI18nReady);\n };\n }, [\n i18nInstance,\n mergedResources,\n props.i18n?.initOptions,\n props.i18n?.detection,\n props.i18n?.fallbackLng,\n props.i18n?.lng,\n props.i18n?.useLanguageDetector,\n ]);\n\n const configValue = useMemo(() => {\n return {\n basePath,\n entities: entityManifest,\n entityManifest,\n entityRegistry,\n filterColumnAliases: props.filterColumnAliases,\n sidebar: props.sidebar,\n dashboard: props.dashboard,\n dashboards,\n auth: props.auth,\n graphql: props.graphql,\n };\n }, [\n basePath,\n props.auth,\n props.dashboard,\n dashboards,\n entityManifest,\n entityRegistry,\n props.filterColumnAliases,\n props.graphql,\n props.sidebar,\n ]);\n\n const routes = useMemo(() => {\n return createBackofficeRoutes({\n basePath,\n entityManifest,\n entityRegistry,\n sidebar: props.sidebar,\n auth: props.auth,\n dashboard: props.dashboard,\n dashboards,\n toolsOperationPage: props.toolsOperationPage,\n });\n }, [\n basePath,\n entityManifest,\n entityRegistry,\n props.auth,\n props.dashboard,\n dashboards,\n props.toolsOperationPage,\n props.sidebar,\n ]);\n\n let contentNode = <BackofficeStaticRouteFallback label=\"Loading...\" />;\n if (isI18nReady && canMountRouter) {\n contentNode = (\n <BackofficeThemeProvider {...props.theme}>\n <RelayProvider>\n <BackofficeConfigProvider value={configValue}>\n {props.overlay}\n <RouterShell\n routes={routes}\n instrumentations={props.instrumentations}\n />\n </BackofficeConfigProvider>\n </RelayProvider>\n </BackofficeThemeProvider>\n );\n }\n\n return (\n <StrictMode>\n <I18nextProvider i18n={i18nInstance}>{contentNode}</I18nextProvider>\n </StrictMode>\n );\n};\n\nexport default BackofficeProvider;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwCA,IAAM,KAAyB,MACzB,EAAM,KAAK,MAAM,MAAM,MAAU,MAC5B,MAEJ,EAAM,WAAW,GAAG,IAGrB,EAAM,SAAS,GAAG,IACb,EAAM,MAAM,GAAG,EAAE,IAEnB,IALE,IAAI,KAQT,KAAmB,GAAkB,MAA0B;CACnE,IAAM,IAAiB,EAAsB,CAAK,GAC5C,IAAqB,EAAsB,CAAQ;CAazD,OAZI,MAAuB,OAIzB,MAAmB,KACnB,EAAe,WAAW,GAAG,EAAmB,EAAE,IAE3C,IAEL,MAAmB,MACd,IAEF,GAAG,IAAqB;AACjC,GAEM,KACJ,GACA,MAEO,OAAO,YACZ,OAAO,QAAQ,CAAQ,CAAC,CAAC,KAAK,CAAC,GAAU,OAChC,CACL,GACA;CACE,GAAG;CACH,QAAQ;EACN,MAAM,EAAgB,GAAU,EAAK,OAAO,IAAI;EAChD,SAAS,MACA,EAAgB,GAAU,EAAK,OAAO,OAAO,CAAE,CAAC;EAEzD,aAAa,GAAY,MAChB,EACL,GACA,EAAK,OAAO,WAAW,GAAI,CAAM,CACnC;CAEJ;AACF,CACF,CACD,CACH,GAaI,KAA+B,EACnC,WACA,YACA,0BAKqC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,EAAM,MAAM;EACZ,EAAM,MAAM;EACZ,EAAM,MAAM;EACZ,EAAM,MAAM;CACd,CAAC;CAED,IAAM,IAAc,SACX;EACL;EACA,UAAU;EACV;EACA;EACA,qBAAqB,EAAM;EAC3B,SAAS,EAAM;EACf,WAAW,EAAM;EACjB;EACA,MAAM,EAAM;EACZ,SAAS,EAAM;CACjB,IACC;EACD;EACA,EAAM;EACN,EAAM;EACN;EACA;EACA;EACA,EAAM;EACN,EAAM;EACN,EAAM;CACR,CAAC,GAEK,IAAS,QACN,EAAuB;EAC5B;EACA;EACA;EACA,SAAS,EAAM;EACf,MAAM,EAAM;EACZ,WAAW,EAAM;EACjB;EACA,oBAAoB,EAAM;CAC5B,CAAC,GACA;EACD;EACA;EACA;EACA,EAAM;EACN,EAAM;EACN;EACA,EAAM;EACN,EAAM;CACR,CAAC,GAEG,IAAc,kBAAC,GAAD,EAA+B,OAAM,aAAc,CAAA;CAiBrE,OAhBI,KAAe,MACjB,IACE,kBAAC,GAAD;EAAyB,GAAI,EAAM;EACjC,UAAA,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD;GAA0B,OAAO;GAAjC,UAAA,CACG,EAAM,SACP,kBAAC,GAAD;IACU;IACR,kBAAkB,EAAM;GACzB,CAAA,CACuB;EACb,CAAA,EAAA,CAAA;CACQ,CAAA,IAK3B,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD;EAAiB,MAAM;EAAe,UAAA;CAA6B,CAAA,EACzD,CAAA;AAEhB"}
1
+ {"version":3,"file":"BackofficeProvider.js","names":[],"sources":["../../../src/provider/BackofficeProvider.tsx"],"sourcesContent":["import {\n StrictMode,\n useCallback,\n useEffect,\n useMemo,\n useState,\n type JSX,\n} from 'react';\nimport { createInstance } from 'i18next';\nimport { I18nextProvider } from 'react-i18next';\nimport RouterRenderer from '@plumile/router/routing/RouterRenderer.js';\nimport RoutingContext from '@plumile/router/routing/RoutingContext.js';\nimport {\n BackofficeThemeProvider,\n ErrorState,\n RoutePendingBar,\n} from '@plumile/ui';\n\nimport { type BackofficeEntityManifestMap } from '@plumile/backoffice-core/types.js';\nimport {\n RelayProvider,\n configureRelayEnvironment,\n useRelayOperationActivity,\n} from '@plumile/relay';\n\nimport { createI18nInstance } from '../i18n/createI18nInstance.js';\nimport { withBackofficeReactI18nResources } from '../i18n/resources.js';\nimport { useRelayEnvironment } from '../relay/useRelayEnvironment.js';\nimport { BackofficeConfigProvider } from './BackofficeConfigContext.js';\nimport { createBackofficeRoutes } from '../router/createBackofficeRoutes.js';\nimport type { BackofficeProviderProps } from './types.js';\nimport { validateBackofficeDashboardRegistrations } from './dashboardRegistrations.js';\nimport {\n BackofficeRouteFallback,\n BackofficeStaticRouteFallback,\n} from '../components/backoffice/routing/BackofficeRouteFallback.js';\nimport { createBackofficeEntityRegistry } from './entityRegistry.js';\nimport { BackofficeRouterBoundary } from './BackofficeRouterBoundary.js';\nimport { useAuthenticatedRouter } from '../hooks/useAuthenticatedRouter.js';\nimport {\n getBackofficeLoginPath,\n isBackofficeAuthPath,\n} from '../router/backofficeAuthPaths.js';\n\nconst normalizeAbsolutePath = (value: string): string => {\n if (value.trim() === '' || value === '/') {\n return '/';\n }\n if (!value.startsWith('/')) {\n return `/${value}`;\n }\n if (value.endsWith('/')) {\n return value.slice(0, -1);\n }\n return value;\n};\n\nconst prefixRoutePath = (basePath: string, value: string): string => {\n const normalizedPath = normalizeAbsolutePath(value);\n const normalizedBasePath = normalizeAbsolutePath(basePath);\n if (normalizedBasePath === '/') {\n return normalizedPath;\n }\n if (\n normalizedPath === normalizedBasePath ||\n normalizedPath.startsWith(`${normalizedBasePath}/`)\n ) {\n return normalizedPath;\n }\n if (normalizedPath === '/') {\n return normalizedBasePath;\n }\n return `${normalizedBasePath}${normalizedPath}`;\n};\n\nconst resolveEntityManifest = (\n manifest: BackofficeEntityManifestMap,\n basePath: string,\n): BackofficeEntityManifestMap => {\n return Object.fromEntries(\n Object.entries(manifest).map(([entityId, item]) => {\n return [\n entityId,\n {\n ...item,\n routes: {\n list: prefixRoutePath(basePath, item.routes.list),\n detail: (id: string) => {\n return prefixRoutePath(basePath, item.routes.detail(id));\n },\n detailPage: (id: string, pageId: string) => {\n return prefixRoutePath(\n basePath,\n item.routes.detailPage(id, pageId),\n );\n },\n },\n } satisfies BackofficeEntityManifestMap[string],\n ] as const;\n }),\n );\n};\n\ntype RouterShellProps = {\n routes: ReturnType<typeof createBackofficeRoutes>;\n instrumentations?: BackofficeProviderProps['instrumentations'];\n basePath: string;\n};\n\nconst RouterShell = ({\n routes,\n instrumentations,\n basePath,\n}: RouterShellProps): JSX.Element => {\n const relayEnvironment = useRelayEnvironment();\n const relayOperationActivity = useRelayOperationActivity();\n\n const routerContext = useMemo(() => {\n return { relayEnvironment };\n }, [relayEnvironment]);\n\n const createOptions = useCallback(() => {\n return {\n context: routerContext,\n instrumentations,\n };\n }, [instrumentations, routerContext]);\n const access = useMemo(() => {\n return {\n loginPath: getBackofficeLoginPath(basePath),\n isPublicPath: (pathname: string) => {\n return isBackofficeAuthPath(basePath, pathname);\n },\n };\n }, [basePath]);\n const { router, retry, error } = useAuthenticatedRouter({\n routes,\n createOptions,\n access,\n });\n\n if (error != null) {\n return <ErrorState variant=\"plain\" onRetry={retry} />;\n }\n\n if (router == null) {\n return <BackofficeRouteFallback />;\n }\n\n return (\n <RoutingContext.Provider value={router.context}>\n <BackofficeRouterBoundary onRetry={retry}>\n <RouterRenderer\n enableTransition\n externalPending={relayOperationActivity.pendingCount > 0}\n fallback={<BackofficeRouteFallback />}\n pending={<RoutePendingBar />}\n />\n </BackofficeRouterBoundary>\n </RoutingContext.Provider>\n );\n};\n\nexport const BackofficeProvider = (\n props: BackofficeProviderProps,\n): JSX.Element => {\n const basePath = normalizeAbsolutePath(props.basePath ?? '/');\n\n const entityManifest = useMemo(() => {\n return resolveEntityManifest(props.entityManifest, basePath);\n }, [basePath, props.entityManifest]);\n const entityRegistry = useMemo(() => {\n return createBackofficeEntityRegistry(entityManifest, { basePath });\n }, [basePath, entityManifest]);\n\n const graphQLConfig = props.graphql;\n const dashboards = useMemo(() => {\n return validateBackofficeDashboardRegistrations(props.dashboards);\n }, [props.dashboards]);\n\n useEffect(() => {\n const httpUrl = graphQLConfig.httpUrl ?? graphQLConfig.endpoint;\n const wsUrl = graphQLConfig.wsUrl ?? graphQLConfig.wsEndpoint;\n configureRelayEnvironment({\n httpUrl,\n wsUrl,\n getDataId: graphQLConfig.getDataId,\n logEvents: graphQLConfig.logEvents,\n getAuthHeaders: graphQLConfig.getAuthHeaders,\n fetchImpl: graphQLConfig.fetchImpl,\n });\n }, [\n graphQLConfig.endpoint,\n graphQLConfig.fetchImpl,\n graphQLConfig.getAuthHeaders,\n graphQLConfig.getDataId,\n graphQLConfig.httpUrl,\n graphQLConfig.logEvents,\n graphQLConfig.wsEndpoint,\n graphQLConfig.wsUrl,\n ]);\n\n const mergedResources = useMemo(() => {\n return withBackofficeReactI18nResources(props.i18n?.resources ?? {});\n }, [props.i18n?.resources]);\n\n const i18nInstance = useMemo(() => {\n return props.i18n?.instance ?? createInstance();\n }, [props.i18n?.instance]);\n const [isI18nReady, setIsI18nReady] = useState(i18nInstance.isInitialized);\n\n useEffect(() => {\n let isCurrent = true;\n const markI18nReady = (): void => {\n if (isCurrent) {\n setIsI18nReady(true);\n }\n };\n\n i18nInstance.on('initialized', markI18nReady);\n if (i18nInstance.isInitialized) {\n markI18nReady();\n return () => {\n isCurrent = false;\n i18nInstance.off('initialized', markI18nReady);\n };\n }\n\n const readyCheck = globalThis.setTimeout(() => {\n if (i18nInstance.isInitialized) {\n markI18nReady();\n }\n }, 0);\n\n const initOptions = props.i18n?.initOptions ?? {};\n const defaultNs = initOptions.defaultNS ?? 'translations';\n const ns = initOptions.ns ?? ['backofficeReact', 'translations', 'ui'];\n createI18nInstance({\n resources: mergedResources,\n lng: props.i18n?.lng,\n fallbackLng: props.i18n?.fallbackLng,\n initOptions: {\n ...initOptions,\n defaultNS: defaultNs,\n ns,\n react: {\n useSuspense: false,\n ...initOptions.react,\n },\n },\n instance: i18nInstance,\n useLanguageDetector: props.i18n?.useLanguageDetector,\n detection: props.i18n?.detection,\n })\n .then(markI18nReady)\n .catch((error: unknown) => {\n markI18nReady();\n // eslint-disable-next-line no-console\n console.error(error);\n });\n\n return () => {\n isCurrent = false;\n globalThis.clearTimeout(readyCheck);\n i18nInstance.off('initialized', markI18nReady);\n };\n }, [\n i18nInstance,\n mergedResources,\n props.i18n?.initOptions,\n props.i18n?.detection,\n props.i18n?.fallbackLng,\n props.i18n?.lng,\n props.i18n?.useLanguageDetector,\n ]);\n\n const configValue = useMemo(() => {\n return {\n basePath,\n entities: entityManifest,\n entityManifest,\n entityRegistry,\n filterColumnAliases: props.filterColumnAliases,\n sidebar: props.sidebar,\n dashboard: props.dashboard,\n dashboards,\n auth: props.auth,\n graphql: props.graphql,\n };\n }, [\n basePath,\n props.auth,\n props.dashboard,\n dashboards,\n entityManifest,\n entityRegistry,\n props.filterColumnAliases,\n props.graphql,\n props.sidebar,\n ]);\n\n const routes = useMemo(() => {\n return createBackofficeRoutes({\n basePath,\n entityManifest,\n entityRegistry,\n sidebar: props.sidebar,\n auth: props.auth,\n dashboard: props.dashboard,\n dashboards,\n toolsOperationPage: props.toolsOperationPage,\n });\n }, [\n basePath,\n entityManifest,\n entityRegistry,\n props.auth,\n props.dashboard,\n dashboards,\n props.toolsOperationPage,\n props.sidebar,\n ]);\n\n let contentNode = <BackofficeStaticRouteFallback label=\"Loading...\" />;\n if (isI18nReady) {\n contentNode = (\n <BackofficeThemeProvider {...props.theme}>\n <RelayProvider>\n <BackofficeConfigProvider value={configValue}>\n {props.overlay}\n <RouterShell\n routes={routes}\n basePath={basePath}\n instrumentations={props.instrumentations}\n />\n </BackofficeConfigProvider>\n </RelayProvider>\n </BackofficeThemeProvider>\n );\n }\n\n return (\n <StrictMode>\n <I18nextProvider i18n={i18nInstance}>{contentNode}</I18nextProvider>\n </StrictMode>\n );\n};\n\nexport default BackofficeProvider;\n"],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AM;EACN;EACA,EAAM;EACN,EAAM;CACR,CAAC,GAEG,IAAc,kBAAC,GAAD,EAA+B,OAAM,aAAc,CAAA;CAkBrE,OAjBI,MACF,IACE,kBAAC,GAAD;EAAyB,GAAI,EAAM;EACjC,UAAA,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD;GAA0B,OAAO;GAAjC,UAAA,CACG,EAAM,SACP,kBAAC,GAAD;IACU;IACE;IACV,kBAAkB,EAAM;GACzB,CAAA,CACuB;EACb,CAAA,EAAA,CAAA;CACQ,CAAA,IAK3B,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD;EAAiB,MAAM;EAAe,UAAA;CAA6B,CAAA,EACzD,CAAA;AAEhB"}
@@ -0,0 +1,22 @@
1
+ import { BackofficeErrorBoundary as e } from "../components/backoffice/errors/BackofficeErrorBoundary.js";
2
+ import { ErrorState as t } from "@plumile/ui";
3
+ import { jsx as n } from "react/jsx-runtime";
4
+ import r from "@plumile/router/routing/useLocation.js";
5
+ //#region src/provider/BackofficeRouterBoundary.tsx
6
+ var i = ({ children: i, onRetry: a, onError: o }) => {
7
+ let s = r();
8
+ return /* @__PURE__ */ n(e, {
9
+ resetKey: JSON.stringify(s),
10
+ onReset: a,
11
+ onError: o,
12
+ fallback: ({ reset: e }) => /* @__PURE__ */ n(t, {
13
+ variant: "plain",
14
+ onRetry: e
15
+ }),
16
+ children: i
17
+ });
18
+ };
19
+ //#endregion
20
+ export { i as BackofficeRouterBoundary };
21
+
22
+ //# sourceMappingURL=BackofficeRouterBoundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackofficeRouterBoundary.js","names":[],"sources":["../../../src/provider/BackofficeRouterBoundary.tsx"],"sourcesContent":["import type { JSX, ReactNode } from 'react';\nimport useLocation from '@plumile/router/routing/useLocation.js';\nimport { ErrorState } from '@plumile/ui';\nimport {\n BackofficeErrorBoundary,\n type BackofficeErrorBoundaryProps,\n} from '../components/backoffice/errors/BackofficeErrorBoundary.js';\n\nexport type BackofficeRouterBoundaryProps = {\n children: ReactNode;\n onRetry: () => void;\n onError?: BackofficeErrorBoundaryProps['onError'];\n};\n\nexport const BackofficeRouterBoundary = ({\n children,\n onRetry,\n onError,\n}: BackofficeRouterBoundaryProps): JSX.Element => {\n const location = useLocation();\n return (\n <BackofficeErrorBoundary\n resetKey={JSON.stringify(location)}\n onReset={onRetry}\n onError={onError}\n fallback={({ reset }) => {\n return <ErrorState variant=\"plain\" onRetry={reset} />;\n }}\n >\n {children}\n </BackofficeErrorBoundary>\n );\n};\n"],"mappings":";;;;;AAcA,IAAa,KAA4B,EACvC,aACA,YACA,iBACgD;CAChD,IAAM,IAAW,EAAY;CAC7B,OACE,kBAAC,GAAD;EACE,UAAU,KAAK,UAAU,CAAQ;EACjC,SAAS;EACA;EACT,WAAW,EAAE,eACJ,kBAAC,GAAD;GAAY,SAAQ;GAAQ,SAAS;EAAQ,CAAA;EAGrD;CACsB,CAAA;AAE7B"}