@flipdish/ui-library 0.50.0 → 0.51.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/atoms/Checkbox/index.cjs +8 -2
- package/dist/components/atoms/Checkbox/index.cjs.map +1 -1
- package/dist/components/atoms/Checkbox/index.d.ts.map +1 -1
- package/dist/components/atoms/Checkbox/index.js +9 -3
- package/dist/components/atoms/Checkbox/index.js.map +1 -1
- package/dist/components/molecules/Alert/index.cjs +5 -25
- package/dist/components/molecules/Alert/index.cjs.map +1 -1
- package/dist/components/molecules/Alert/index.d.ts +9 -94
- package/dist/components/molecules/Alert/index.d.ts.map +1 -1
- package/dist/components/molecules/Alert/index.js +5 -25
- package/dist/components/molecules/Alert/index.js.map +1 -1
- package/dist/components/molecules/Alerts/components/Alert.cjs +39 -0
- package/dist/components/molecules/Alerts/components/Alert.cjs.map +1 -0
- package/dist/components/molecules/Alerts/components/Alert.d.ts +104 -0
- package/dist/components/molecules/Alerts/components/Alert.d.ts.map +1 -0
- package/dist/components/molecules/Alerts/components/Alert.js +36 -0
- package/dist/components/molecules/Alerts/components/Alert.js.map +1 -0
- package/dist/components/molecules/Alerts/components/SaveErrorAlert.cjs +26 -0
- package/dist/components/molecules/Alerts/components/SaveErrorAlert.cjs.map +1 -0
- package/dist/components/molecules/Alerts/components/SaveErrorAlert.d.ts +25 -0
- package/dist/components/molecules/Alerts/components/SaveErrorAlert.d.ts.map +1 -0
- package/dist/components/molecules/Alerts/components/SaveErrorAlert.js +24 -0
- package/dist/components/molecules/Alerts/components/SaveErrorAlert.js.map +1 -0
- package/dist/components/molecules/Alerts/hooks/useAlertActions.cjs +26 -0
- package/dist/components/molecules/Alerts/hooks/useAlertActions.cjs.map +1 -0
- package/dist/components/molecules/Alerts/hooks/useAlertActions.d.ts +13 -0
- package/dist/components/molecules/Alerts/hooks/useAlertActions.d.ts.map +1 -0
- package/dist/components/molecules/Alerts/hooks/useAlertActions.js +24 -0
- package/dist/components/molecules/Alerts/hooks/useAlertActions.js.map +1 -0
- package/dist/components/molecules/Alerts/index.cjs +11 -0
- package/dist/components/molecules/Alerts/index.cjs.map +1 -0
- package/dist/components/molecules/Alerts/index.d.ts +12 -0
- package/dist/components/molecules/Alerts/index.d.ts.map +1 -0
- package/dist/components/molecules/Alerts/index.js +3 -0
- package/dist/components/molecules/Alerts/index.js.map +1 -0
- package/dist/components/molecules/Modal/index.cjs +9 -39
- package/dist/components/molecules/Modal/index.cjs.map +1 -1
- package/dist/components/molecules/Modal/index.d.ts +13 -36
- package/dist/components/molecules/Modal/index.d.ts.map +1 -1
- package/dist/components/molecules/Modal/index.js +8 -38
- package/dist/components/molecules/Modal/index.js.map +1 -1
- package/dist/components/molecules/Modals/components/ConfirmationModal.cjs +32 -0
- package/dist/components/molecules/Modals/components/ConfirmationModal.cjs.map +1 -0
- package/dist/components/molecules/Modals/components/ConfirmationModal.d.ts +28 -0
- package/dist/components/molecules/Modals/components/ConfirmationModal.d.ts.map +1 -0
- package/dist/components/molecules/Modals/components/ConfirmationModal.js +30 -0
- package/dist/components/molecules/Modals/components/ConfirmationModal.js.map +1 -0
- package/dist/components/molecules/Modals/components/Modal.cjs +48 -0
- package/dist/components/molecules/Modals/components/Modal.cjs.map +1 -0
- package/dist/components/molecules/Modals/components/Modal.d.ts +37 -0
- package/dist/components/molecules/Modals/components/Modal.d.ts.map +1 -0
- package/dist/components/molecules/Modals/components/Modal.js +43 -0
- package/dist/components/molecules/Modals/components/Modal.js.map +1 -0
- package/dist/components/molecules/Modals/components/UnsavedChangesModal.cjs +30 -0
- package/dist/components/molecules/Modals/components/UnsavedChangesModal.cjs.map +1 -0
- package/dist/components/molecules/Modals/components/UnsavedChangesModal.d.ts +14 -0
- package/dist/components/molecules/Modals/components/UnsavedChangesModal.d.ts.map +1 -0
- package/dist/components/molecules/Modals/components/UnsavedChangesModal.js +28 -0
- package/dist/components/molecules/Modals/components/UnsavedChangesModal.js.map +1 -0
- package/dist/components/molecules/Modals/index.cjs +15 -0
- package/dist/components/molecules/Modals/index.cjs.map +1 -0
- package/dist/components/molecules/Modals/index.d.ts +14 -0
- package/dist/components/molecules/Modals/index.d.ts.map +1 -0
- package/dist/components/molecules/Modals/index.js +4 -0
- package/dist/components/molecules/Modals/index.js.map +1 -0
- package/dist/components/organisms/DatePicker/components/CalendarOverlay.cjs +2 -2
- package/dist/components/organisms/DatePicker/components/CalendarOverlay.cjs.map +1 -1
- package/dist/components/organisms/DatePicker/components/CalendarOverlay.js +1 -1
- package/dist/components/organisms/DatePicker/components/DateRangePicker.cjs +4 -1
- package/dist/components/organisms/DatePicker/components/DateRangePicker.cjs.map +1 -1
- package/dist/components/organisms/DatePicker/components/DateRangePicker.d.ts.map +1 -1
- package/dist/components/organisms/DatePicker/components/DateRangePicker.js +5 -2
- package/dist/components/organisms/DatePicker/components/DateRangePicker.js.map +1 -1
- package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.cjs +48 -0
- package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.cjs.map +1 -0
- package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.d.ts +23 -0
- package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.d.ts.map +1 -0
- package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.js +45 -0
- package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.js.map +1 -0
- package/dist/hooks/useUnsavedChangesGuard/index.cjs +28 -0
- package/dist/hooks/useUnsavedChangesGuard/index.cjs.map +1 -0
- package/dist/hooks/useUnsavedChangesGuard/index.d.ts +18 -0
- package/dist/hooks/useUnsavedChangesGuard/index.d.ts.map +1 -0
- package/dist/hooks/useUnsavedChangesGuard/index.js +26 -0
- package/dist/hooks/useUnsavedChangesGuard/index.js.map +1 -0
- package/dist/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.cjs +8 -0
- package/dist/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.cjs.map +1 -0
- package/dist/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.d.ts +13 -0
- package/dist/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.d.ts.map +1 -0
- package/dist/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.js +6 -0
- package/dist/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.js.map +1 -0
- package/dist/native/components/molecules/Alerts/index.d.ts +12 -0
- package/dist/native/components/molecules/Modals/index.d.ts +12 -0
- package/dist/native/hooks/useUnsavedChangesGuard/index.d.ts +12 -0
- package/dist/native/providers/UnsavedChangesGuardProvider/index.d.ts +12 -0
- package/dist/providers/UIProvider/hooks/useBrowserRouter.cjs +70 -0
- package/dist/providers/UIProvider/hooks/useBrowserRouter.cjs.map +1 -0
- package/dist/providers/UIProvider/hooks/useBrowserRouter.d.ts +12 -0
- package/dist/providers/UIProvider/hooks/useBrowserRouter.d.ts.map +1 -0
- package/dist/providers/UIProvider/hooks/useBrowserRouter.js +68 -0
- package/dist/providers/UIProvider/hooks/useBrowserRouter.js.map +1 -0
- package/dist/providers/UIProvider/index.cjs +19 -6
- package/dist/providers/UIProvider/index.cjs.map +1 -1
- package/dist/providers/UIProvider/index.d.ts +2 -2
- package/dist/providers/UIProvider/index.d.ts.map +1 -1
- package/dist/providers/UIProvider/index.js +20 -7
- package/dist/providers/UIProvider/index.js.map +1 -1
- package/dist/providers/UnsavedChangesGuardProvider/index.cjs +191 -0
- package/dist/providers/UnsavedChangesGuardProvider/index.cjs.map +1 -0
- package/dist/providers/UnsavedChangesGuardProvider/index.d.ts +10 -0
- package/dist/providers/UnsavedChangesGuardProvider/index.d.ts.map +1 -0
- package/dist/providers/UnsavedChangesGuardProvider/index.js +189 -0
- package/dist/providers/UnsavedChangesGuardProvider/index.js.map +1 -0
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.constants.cjs +7 -0
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.constants.cjs.map +1 -0
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.constants.d.ts +3 -0
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.constants.d.ts.map +1 -0
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.constants.js +5 -0
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.constants.js.map +1 -0
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.types.d.ts +21 -0
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.types.d.ts.map +1 -0
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.cjs +97 -0
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.cjs.map +1 -0
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.d.ts +62 -0
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.d.ts.map +1 -0
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.js +88 -0
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useContext, useId, useLayoutEffect, useCallback } from 'react';
|
|
2
|
+
import { UnsavedChangesGuardContext } from './providers/UnsavedChangesGuard.context.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Stops unsaved changes being lost to navigation: it holds router navigation and the back button, makes the browser
|
|
6
|
+
* prompt on refresh or tab close, and has a host such as Portal ask before it navigates away. Render a confirm dialog
|
|
7
|
+
* from the result, or use `UnsavedChangesModal`, which does that for you; needs `UIProvider` above it.
|
|
8
|
+
*
|
|
9
|
+
* @param options What to guard: `hasUnsavedChanges` says whether there is anything to lose.
|
|
10
|
+
* @returns `isPromptOpen` while a navigation is waiting on the user, with `stay` to cancel it and `discard` to let it go.
|
|
11
|
+
*/
|
|
12
|
+
const useUnsavedChangesGuard = ({ hasUnsavedChanges }) => {
|
|
13
|
+
const guard = useContext(UnsavedChangesGuardContext);
|
|
14
|
+
if (!guard)
|
|
15
|
+
throw new Error('useUnsavedChangesGuard needs UIProvider above it, or UnsavedChangesGuardProvider inside your own data router.');
|
|
16
|
+
const { register, promptOwner, isPromptOpen, answer } = guard;
|
|
17
|
+
const id = useId();
|
|
18
|
+
// A layout effect, so the provider counts the changes before the browser paints the edit that made them.
|
|
19
|
+
useLayoutEffect(() => (hasUnsavedChanges ? register(id) : undefined), [hasUnsavedChanges, register, id]);
|
|
20
|
+
const stay = useCallback(() => answer(false), [answer]);
|
|
21
|
+
const discard = useCallback(() => answer(true), [answer]);
|
|
22
|
+
return { isPromptOpen: isPromptOpen && promptOwner === id, stay, discard };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { useUnsavedChangesGuard };
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/hooks/useUnsavedChangesGuard/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAUA;;;;;;;AAOG;MACU,sBAAsB,GAAG,CAAC,EAAE,iBAAiB,EAAiC,KAAI;AAC7F,IAAA,MAAM,KAAK,GAAG,UAAU,CAAC,0BAA0B,CAAC;AACpD,IAAA,IAAI,CAAC,KAAK;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,+GAA+G,CAAC;IAC5I,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,KAAK;AAC7D,IAAA,MAAM,EAAE,GAAG,KAAK,EAAE;;IAGlB,eAAe,CAAC,OAAO,iBAAiB,GAAG,QAAQ,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC,iBAAiB,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;AAExG,IAAA,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;AACvD,IAAA,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;AAEzD,IAAA,OAAO,EAAE,YAAY,EAAE,YAAY,IAAI,WAAW,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;AAC5E;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnsavedChangesGuard.context.cjs","sources":["../../../../src/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.ts"],"sourcesContent":[null],"names":["createContext"],"mappings":";;;;MAca,0BAA0B,GAAGA,mBAAa,CAAyC,IAAI;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** What `UnsavedChangesGuardProvider` shares with every `useUnsavedChangesGuard` beneath it. */
|
|
2
|
+
export interface UnsavedChangesGuardContextValue {
|
|
3
|
+
/** Marks one guard as having unsaved changes; returns the function that clears it. */
|
|
4
|
+
register: (id: string) => () => void;
|
|
5
|
+
/** The guard that shows the prompt, so two forms with unsaved changes still ask once. */
|
|
6
|
+
promptOwner: string | undefined;
|
|
7
|
+
/** Whether a navigation is waiting on the user's decision. */
|
|
8
|
+
isPromptOpen: boolean;
|
|
9
|
+
/** Settles the waiting navigation: `true` lets it go, `false` cancels it. */
|
|
10
|
+
answer: (leave: boolean) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const UnsavedChangesGuardContext: import("react").Context<UnsavedChangesGuardContextValue | null>;
|
|
13
|
+
//# sourceMappingURL=UnsavedChangesGuard.context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnsavedChangesGuard.context.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.ts"],"names":[],"mappings":"AAEA,gGAAgG;AAChG,MAAM,WAAW,+BAA+B;IAC9C,sFAAsF;IACtF,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,IAAI,CAAC;IACrC,yFAAyF;IACzF,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,8DAA8D;IAC9D,YAAY,EAAE,OAAO,CAAC;IACtB,6EAA6E;IAC7E,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAClC;AAED,eAAO,MAAM,0BAA0B,iEAA8D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnsavedChangesGuard.context.js","sources":["../../../../src/hooks/useUnsavedChangesGuard/providers/UnsavedChangesGuard.context.ts"],"sourcesContent":[null],"names":[],"mappings":";;MAca,0BAA0B,GAAG,aAAa,CAAyC,IAAI;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Alerts` has no React Native implementation.
|
|
3
|
+
*
|
|
4
|
+
* This is a generated types-only stub (scripts/emit-native-stubs.mjs). It exists so
|
|
5
|
+
* that importing `@flipdish/ui-library/components/molecules/Alerts` from React Native fails at
|
|
6
|
+
* compile time rather than resolving to the web build's types. There is no
|
|
7
|
+
* matching `index.js`, so Metro cannot bundle this module either.
|
|
8
|
+
*
|
|
9
|
+
* To make `Alerts` available on React Native, add an `index.native.tsx` beside
|
|
10
|
+
* its `index.tsx` — the build picks it up automatically and this stub disappears.
|
|
11
|
+
*/
|
|
12
|
+
export declare const __NO_REACT_NATIVE_IMPLEMENTATION__: never;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Modals` has no React Native implementation.
|
|
3
|
+
*
|
|
4
|
+
* This is a generated types-only stub (scripts/emit-native-stubs.mjs). It exists so
|
|
5
|
+
* that importing `@flipdish/ui-library/components/molecules/Modals` from React Native fails at
|
|
6
|
+
* compile time rather than resolving to the web build's types. There is no
|
|
7
|
+
* matching `index.js`, so Metro cannot bundle this module either.
|
|
8
|
+
*
|
|
9
|
+
* To make `Modals` available on React Native, add an `index.native.tsx` beside
|
|
10
|
+
* its `index.tsx` — the build picks it up automatically and this stub disappears.
|
|
11
|
+
*/
|
|
12
|
+
export declare const __NO_REACT_NATIVE_IMPLEMENTATION__: never;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useUnsavedChangesGuard` has no React Native implementation.
|
|
3
|
+
*
|
|
4
|
+
* This is a generated types-only stub (scripts/emit-native-stubs.mjs). It exists so
|
|
5
|
+
* that importing `@flipdish/ui-library/hooks/useUnsavedChangesGuard` from React Native fails at
|
|
6
|
+
* compile time rather than resolving to the web build's types. There is no
|
|
7
|
+
* matching `index.js`, so Metro cannot bundle this module either.
|
|
8
|
+
*
|
|
9
|
+
* To make `useUnsavedChangesGuard` available on React Native, add an `index.native.tsx` beside
|
|
10
|
+
* its `index.tsx` — the build picks it up automatically and this stub disappears.
|
|
11
|
+
*/
|
|
12
|
+
export declare const __NO_REACT_NATIVE_IMPLEMENTATION__: never;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `UnsavedChangesGuardProvider` has no React Native implementation.
|
|
3
|
+
*
|
|
4
|
+
* This is a generated types-only stub (scripts/emit-native-stubs.mjs). It exists so
|
|
5
|
+
* that importing `@flipdish/ui-library/providers/UnsavedChangesGuardProvider` from React Native fails at
|
|
6
|
+
* compile time rather than resolving to the web build's types. There is no
|
|
7
|
+
* matching `index.js`, so Metro cannot bundle this module either.
|
|
8
|
+
*
|
|
9
|
+
* To make `UnsavedChangesGuardProvider` available on React Native, add an `index.native.tsx` beside
|
|
10
|
+
* its `index.tsx` — the build picks it up automatically and this stub disappears.
|
|
11
|
+
*/
|
|
12
|
+
export declare const __NO_REACT_NATIVE_IMPLEMENTATION__: never;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactRouter = require('react-router');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Gives every history entry the app lands on the index react-router expects there. A host such as Portal pushes entries
|
|
8
|
+
* without one, and react-router then cannot tell how far a back or forward move went, so it could not hold one.
|
|
9
|
+
*
|
|
10
|
+
* @returns The function that stops it.
|
|
11
|
+
*/
|
|
12
|
+
const keepHistoryIndex = () => {
|
|
13
|
+
const { navigation } = window;
|
|
14
|
+
if (!navigation)
|
|
15
|
+
return () => { };
|
|
16
|
+
// The last entry seen with an index, and where the browser says it sits: the next one is numbered from it.
|
|
17
|
+
let known;
|
|
18
|
+
const number = () => {
|
|
19
|
+
const position = navigation.currentEntry?.index ?? -1;
|
|
20
|
+
const state = window.history.state;
|
|
21
|
+
// Only a plain object can take one more field and stay what it was; anything else is the host's own to keep.
|
|
22
|
+
const isPlainObject = typeof state === 'object' && state !== null && Object.getPrototypeOf(state) === Object.prototype;
|
|
23
|
+
if (position < 0 || !(state === null || isPlainObject))
|
|
24
|
+
return;
|
|
25
|
+
const idx = state?.idx;
|
|
26
|
+
// An index already there is never changed: another router on the page may count from it, and a `NaN`, which
|
|
27
|
+
// react-router writes after an entry it could not count from, marks a move it cannot rewind.
|
|
28
|
+
if (idx !== undefined && idx !== null) {
|
|
29
|
+
if (typeof idx === 'number' && Number.isFinite(idx))
|
|
30
|
+
known = { idx, position };
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const next = known ? known.idx + position - known.position : position;
|
|
34
|
+
known = { idx: next, position };
|
|
35
|
+
window.history.replaceState({ ...state, idx: next }, '');
|
|
36
|
+
};
|
|
37
|
+
// Fires for every push, replace and back or forward move, before any `popstate` listener reads the entry.
|
|
38
|
+
navigation.addEventListener('currententrychange', number);
|
|
39
|
+
number();
|
|
40
|
+
return () => navigation.removeEventListener('currententrychange', number);
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Owns a react-router data router for the lifetime of the component: created on mount and whenever `basename` changes,
|
|
44
|
+
* disposed on unmount so a StrictMode or host re-mount never leaves a `popstate` listener behind. A new `basename` is a
|
|
45
|
+
* new router, so the tree beneath it mounts again.
|
|
46
|
+
*
|
|
47
|
+
* @param routes The route table; pass a module-level constant, since the router reads it once when it is created.
|
|
48
|
+
* @param basename The path the app is mounted under, such as a micro-frontend's Portal base URL.
|
|
49
|
+
* @returns The router, or `null` until the layout effect has built the one for this `basename`, which is still before the paint.
|
|
50
|
+
*/
|
|
51
|
+
const useBrowserRouter = (routes, basename) => {
|
|
52
|
+
const [current, setCurrent] = React.useState(null);
|
|
53
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the route table is read once per router, so a new array must not rebuild it
|
|
54
|
+
React.useLayoutEffect(() => {
|
|
55
|
+
// Started first, so the router reads an index on the entry it mounts on.
|
|
56
|
+
const stopKeepingIndex = keepHistoryIndex();
|
|
57
|
+
const created = reactRouter.createBrowserRouter(routes, { basename });
|
|
58
|
+
setCurrent({ router: created, basename });
|
|
59
|
+
return () => {
|
|
60
|
+
created.dispose();
|
|
61
|
+
stopKeepingIndex();
|
|
62
|
+
};
|
|
63
|
+
}, [basename]);
|
|
64
|
+
// `RouterProvider` keeps the state of the first router it is given, so a router built for another basename is never
|
|
65
|
+
// handed over: the provider unmounts for that render and mounts again with the new router's own state.
|
|
66
|
+
return current && current.basename === basename ? current.router : null;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
exports.useBrowserRouter = useBrowserRouter;
|
|
70
|
+
//# sourceMappingURL=useBrowserRouter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBrowserRouter.cjs","sources":["../../../../src/providers/UIProvider/hooks/useBrowserRouter.ts"],"sourcesContent":[null],"names":["useState","useLayoutEffect","createBrowserRouter"],"mappings":";;;;;AAYA;;;;;AAKG;AACH,MAAM,gBAAgB,GAAG,MAAmB;AAC1C,IAAA,MAAM,EAAE,UAAU,EAAE,GAAG,MAAiD;AACxE,IAAA,IAAI,CAAC,UAAU;AAAE,QAAA,OAAO,MAAK,EAAE,CAAC;;AAEhC,IAAA,IAAI,KAAoD;IAExD,MAAM,MAA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A,cAAQ,CAAmD,IAAI,CAAC;;IAG9FC,qBAAe,CAAC,MAAK;;AAEnB,QAAA,MAAM,gBAAgB,GAAG,gBAAgB,EAAE;QAC3C,MAAM,OAAO,GAAGC,+BAAmB,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC;QACzD,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACzC,QAAA,OAAO,MAAK;YACV,OAAO,CAAC,OAAO,EAAE;AACjB,YAAA,gBAAgB,EAAE;AACpB,QAAA,CAAC;AACH,IAAA,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;;;AAId,IAAA,OAAO,OAAO,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI;AACzE;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type DataRouter, type RouteObject } from 'react-router';
|
|
2
|
+
/**
|
|
3
|
+
* Owns a react-router data router for the lifetime of the component: created on mount and whenever `basename` changes,
|
|
4
|
+
* disposed on unmount so a StrictMode or host re-mount never leaves a `popstate` listener behind. A new `basename` is a
|
|
5
|
+
* new router, so the tree beneath it mounts again.
|
|
6
|
+
*
|
|
7
|
+
* @param routes The route table; pass a module-level constant, since the router reads it once when it is created.
|
|
8
|
+
* @param basename The path the app is mounted under, such as a micro-frontend's Portal base URL.
|
|
9
|
+
* @returns The router, or `null` until the layout effect has built the one for this `basename`, which is still before the paint.
|
|
10
|
+
*/
|
|
11
|
+
export declare const useBrowserRouter: (routes: RouteObject[], basename?: string) => DataRouter | null;
|
|
12
|
+
//# sourceMappingURL=useBrowserRouter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBrowserRouter.d.ts","sourceRoot":"","sources":["../../../../src/providers/UIProvider/hooks/useBrowserRouter.ts"],"names":[],"mappings":"AAGA,OAAO,EAAuB,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AA6CtF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,WAAW,EAAE,EAAE,WAAW,MAAM,KAAG,UAAU,GAAG,IAkBxF,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useState, useLayoutEffect } from 'react';
|
|
2
|
+
import { createBrowserRouter } from 'react-router';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Gives every history entry the app lands on the index react-router expects there. A host such as Portal pushes entries
|
|
6
|
+
* without one, and react-router then cannot tell how far a back or forward move went, so it could not hold one.
|
|
7
|
+
*
|
|
8
|
+
* @returns The function that stops it.
|
|
9
|
+
*/
|
|
10
|
+
const keepHistoryIndex = () => {
|
|
11
|
+
const { navigation } = window;
|
|
12
|
+
if (!navigation)
|
|
13
|
+
return () => { };
|
|
14
|
+
// The last entry seen with an index, and where the browser says it sits: the next one is numbered from it.
|
|
15
|
+
let known;
|
|
16
|
+
const number = () => {
|
|
17
|
+
const position = navigation.currentEntry?.index ?? -1;
|
|
18
|
+
const state = window.history.state;
|
|
19
|
+
// Only a plain object can take one more field and stay what it was; anything else is the host's own to keep.
|
|
20
|
+
const isPlainObject = typeof state === 'object' && state !== null && Object.getPrototypeOf(state) === Object.prototype;
|
|
21
|
+
if (position < 0 || !(state === null || isPlainObject))
|
|
22
|
+
return;
|
|
23
|
+
const idx = state?.idx;
|
|
24
|
+
// An index already there is never changed: another router on the page may count from it, and a `NaN`, which
|
|
25
|
+
// react-router writes after an entry it could not count from, marks a move it cannot rewind.
|
|
26
|
+
if (idx !== undefined && idx !== null) {
|
|
27
|
+
if (typeof idx === 'number' && Number.isFinite(idx))
|
|
28
|
+
known = { idx, position };
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const next = known ? known.idx + position - known.position : position;
|
|
32
|
+
known = { idx: next, position };
|
|
33
|
+
window.history.replaceState({ ...state, idx: next }, '');
|
|
34
|
+
};
|
|
35
|
+
// Fires for every push, replace and back or forward move, before any `popstate` listener reads the entry.
|
|
36
|
+
navigation.addEventListener('currententrychange', number);
|
|
37
|
+
number();
|
|
38
|
+
return () => navigation.removeEventListener('currententrychange', number);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Owns a react-router data router for the lifetime of the component: created on mount and whenever `basename` changes,
|
|
42
|
+
* disposed on unmount so a StrictMode or host re-mount never leaves a `popstate` listener behind. A new `basename` is a
|
|
43
|
+
* new router, so the tree beneath it mounts again.
|
|
44
|
+
*
|
|
45
|
+
* @param routes The route table; pass a module-level constant, since the router reads it once when it is created.
|
|
46
|
+
* @param basename The path the app is mounted under, such as a micro-frontend's Portal base URL.
|
|
47
|
+
* @returns The router, or `null` until the layout effect has built the one for this `basename`, which is still before the paint.
|
|
48
|
+
*/
|
|
49
|
+
const useBrowserRouter = (routes, basename) => {
|
|
50
|
+
const [current, setCurrent] = useState(null);
|
|
51
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the route table is read once per router, so a new array must not rebuild it
|
|
52
|
+
useLayoutEffect(() => {
|
|
53
|
+
// Started first, so the router reads an index on the entry it mounts on.
|
|
54
|
+
const stopKeepingIndex = keepHistoryIndex();
|
|
55
|
+
const created = createBrowserRouter(routes, { basename });
|
|
56
|
+
setCurrent({ router: created, basename });
|
|
57
|
+
return () => {
|
|
58
|
+
created.dispose();
|
|
59
|
+
stopKeepingIndex();
|
|
60
|
+
};
|
|
61
|
+
}, [basename]);
|
|
62
|
+
// `RouterProvider` keeps the state of the first router it is given, so a router built for another basename is never
|
|
63
|
+
// handed over: the provider unmounts for that render and mounts again with the new router's own state.
|
|
64
|
+
return current && current.basename === basename ? current.router : null;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export { useBrowserRouter };
|
|
68
|
+
//# sourceMappingURL=useBrowserRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBrowserRouter.js","sources":["../../../../src/providers/UIProvider/hooks/useBrowserRouter.ts"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MAAM,CAAC;AACzD,IAAA,MAAM,EAAE;IACR,OAAO,MAAM,UAAU,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,MAAM,CAAC;AAC3E,CAAC;AAED;;;;;;;;AAQG;MACU,gBAAgB,GAAG,CAAC,MAAqB,EAAE,QAAiB,KAAuB;IAC9F,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAmD,IAAI,CAAC;;IAG9F,eAAe,CAAC,MAAK;;AAEnB,QAAA,MAAM,gBAAgB,GAAG,gBAAgB,EAAE;QAC3C,MAAM,OAAO,GAAG,mBAAmB,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC;QACzD,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACzC,QAAA,OAAO,MAAK;YACV,OAAO,CAAC,OAAO,EAAE;AACjB,YAAA,gBAAgB,EAAE;AACpB,QAAA,CAAC;AACH,IAAA,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;;;AAId,IAAA,OAAO,OAAO,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI;AACzE;;"}
|
|
@@ -5,26 +5,39 @@ var ErrorBoundary = require('@flipdish/ui-library/providers/ErrorBoundary');
|
|
|
5
5
|
var PortalContainer = require('@flipdish/ui-library/providers/PortalContainer');
|
|
6
6
|
var RouteProvider = require('@flipdish/ui-library/providers/RouteProvider');
|
|
7
7
|
var ThemeProvider = require('@flipdish/ui-library/providers/ThemeProvider');
|
|
8
|
+
var UnsavedChangesGuardProvider = require('@flipdish/ui-library/providers/UnsavedChangesGuardProvider');
|
|
9
|
+
var React = require('react');
|
|
8
10
|
var reactRouter = require('react-router');
|
|
11
|
+
var useBrowserRouter = require('./hooks/useBrowserRouter.cjs');
|
|
9
12
|
var usePortalAnchor = require('./hooks/usePortalAnchor.cjs');
|
|
10
13
|
|
|
14
|
+
// A data router takes a static route table, so the app's tree reaches the catch-all route through context.
|
|
15
|
+
const RoutedTreeContext = React.createContext(null);
|
|
16
|
+
// What `BrowserRouter` gives its children: no matched route, so a relative link outside the app's `<Routes>` resolves from
|
|
17
|
+
// the base path and not from the current URL, as it would beneath the catch-all route.
|
|
18
|
+
const NO_MATCHED_ROUTE = { outlet: null, matches: [], isDataRoute: false };
|
|
19
|
+
const RoutedTree = () => (jsxRuntime.jsx(reactRouter.UNSAFE_RouteContext, { value: NO_MATCHED_ROUTE, children: jsxRuntime.jsx(RouteProvider.RouteProvider, { children: jsxRuntime.jsx(UnsavedChangesGuardProvider.UnsavedChangesGuardProvider, { children: React.useContext(RoutedTreeContext) }) }) }));
|
|
20
|
+
// One catch-all route: the app's own `<Routes>` match beneath it as before, and `useBlocker` works for the whole tree.
|
|
21
|
+
const ROUTES = [{ path: '*', Component: RoutedTree }];
|
|
11
22
|
const UIProviderInner = ({ children, baseUrl, errorBoundary, scopeId, portalContainer, }) => {
|
|
12
23
|
const { themeRoot, resolvedMode } = ThemeProvider.useTheme();
|
|
13
24
|
const getContainer = usePortalAnchor.usePortalAnchor({ portalContainer, scopeId, themeRoot, resolvedMode });
|
|
14
|
-
|
|
25
|
+
const router = useBrowserRouter.useBrowserRouter(ROUTES, baseUrl);
|
|
26
|
+
const tree = (jsxRuntime.jsx(ErrorBoundary.ErrorBoundary, { ...errorBoundary, children: jsxRuntime.jsx(PortalContainer.PortalContainer, { getContainer: getContainer, children: children }) }));
|
|
27
|
+
if (!router)
|
|
28
|
+
return null;
|
|
29
|
+
return (jsxRuntime.jsx(RoutedTreeContext, { value: tree, children: jsxRuntime.jsx(reactRouter.RouterProvider, { router: router }) }));
|
|
15
30
|
};
|
|
16
31
|
/**
|
|
17
|
-
* Single entry-point provider that composes `ThemeProvider`, `RouteProvider`, `ErrorBoundary
|
|
32
|
+
* Single entry-point provider that composes `ThemeProvider`, `RouteProvider`, `ErrorBoundary`,
|
|
18
33
|
* and overlay portalling for a consuming app. Wire it once at the root and pass `scopeId` when the
|
|
19
34
|
* app ships CSS scoped to `[data-mfe-scope]`; overlays then portal into a scoped anchor on `body`.
|
|
20
35
|
*
|
|
21
36
|
* @summary root provider composing theme, routing, errors and portals
|
|
22
37
|
*/
|
|
23
38
|
const UIProvider = ({ children, themeModeOverride, scopeId, ...rest }) => {
|
|
24
|
-
// TODO(i18n): add an internal
|
|
25
|
-
//
|
|
26
|
-
// consuming app needing to pass text props. This is purely internal — consuming apps
|
|
27
|
-
// own their own translation layer and wrap their content inside UIProvider as usual.
|
|
39
|
+
// TODO(i18n): add an internal translation context so components source their own built-in text ("Discard", "Rows per
|
|
40
|
+
// page") in the host's language. Apps keep their own translation layer; form messages reach it through `useSchemaResolver`.
|
|
28
41
|
return (jsxRuntime.jsx(ThemeProvider.ThemeProvider, { themeModeOverride: themeModeOverride, scopeId: scopeId, children: jsxRuntime.jsx(UIProviderInner, { scopeId: scopeId, ...rest, children: children }) }));
|
|
29
42
|
};
|
|
30
43
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../src/providers/UIProvider/index.tsx"],"sourcesContent":[null],"names":["
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/providers/UIProvider/index.tsx"],"sourcesContent":[null],"names":["createContext","_jsx","UNSAFE_RouteContext","RouteProvider","UnsavedChangesGuardProvider","useContext","useTheme","usePortalAnchor","useBrowserRouter","ErrorBoundary","PortalContainer","DataRouterProvider","ThemeProvider"],"mappings":";;;;;;;;;;;;;AAmDA;AACA,MAAM,iBAAiB,GAAGA,mBAAa,CAAY,IAAI,CAAC;AACxD;AACA;AACA,MAAM,gBAAgB,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE;AAC1E,MAAM,UAAU,GAAG,OACjBC,cAAA,CAACC,+BAAmB,EAAA,EAAC,KAAK,EAAE,gBAAgB,EAAA,QAAA,EAC1CD,cAAA,CAACE,2BAAa,EAAA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AAC,OAAO,EAAE,OAAO,EAAA,GAAM,IAAI,EAAA,QAAA,EACxC,QAAQ,EAAA,CACO,EAAA,CACJ;AAEpB;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ErrorBoundaryProps } from '@flipdish/ui-library/providers/ErrorBoundary';
|
|
2
|
-
import type
|
|
2
|
+
import { type PropsWithChildren } from 'react';
|
|
3
3
|
export interface UIProviderProps {
|
|
4
4
|
/**
|
|
5
5
|
* Controlled theme override. When set, the tree renders in this mode and theme
|
|
@@ -39,7 +39,7 @@ export interface UIProviderProps {
|
|
|
39
39
|
portalContainer?: (() => HTMLElement | null) | null;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
* Single entry-point provider that composes `ThemeProvider`, `RouteProvider`, `ErrorBoundary
|
|
42
|
+
* Single entry-point provider that composes `ThemeProvider`, `RouteProvider`, `ErrorBoundary`,
|
|
43
43
|
* and overlay portalling for a consuming app. Wire it once at the root and pass `scopeId` when the
|
|
44
44
|
* app ships CSS scoped to `[data-mfe-scope]`; overlays then portal into a scoped anchor on `body`.
|
|
45
45
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/UIProvider/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/UIProvider/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAKtG,OAAO,EAAiB,KAAK,iBAAiB,EAA8B,MAAM,OAAO,CAAC;AAK1F,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACrC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;OAOG;IACH,aAAa,EAAE,IAAI,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;IACpD;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;;OAQG;IACH,eAAe,CAAC,EAAE,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;CACrD;AA2CD;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,mDAAmD,iBAAiB,CAAC,eAAe,CAAC,gCAU/G,CAAC"}
|
|
@@ -3,26 +3,39 @@ import { ErrorBoundary } from '@flipdish/ui-library/providers/ErrorBoundary';
|
|
|
3
3
|
import { PortalContainer } from '@flipdish/ui-library/providers/PortalContainer';
|
|
4
4
|
import { RouteProvider } from '@flipdish/ui-library/providers/RouteProvider';
|
|
5
5
|
import { ThemeProvider, useTheme } from '@flipdish/ui-library/providers/ThemeProvider';
|
|
6
|
-
import {
|
|
6
|
+
import { UnsavedChangesGuardProvider } from '@flipdish/ui-library/providers/UnsavedChangesGuardProvider';
|
|
7
|
+
import { createContext, useContext } from 'react';
|
|
8
|
+
import { RouterProvider, UNSAFE_RouteContext } from 'react-router';
|
|
9
|
+
import { useBrowserRouter } from './hooks/useBrowserRouter.js';
|
|
7
10
|
import { usePortalAnchor } from './hooks/usePortalAnchor.js';
|
|
8
11
|
|
|
12
|
+
// A data router takes a static route table, so the app's tree reaches the catch-all route through context.
|
|
13
|
+
const RoutedTreeContext = createContext(null);
|
|
14
|
+
// What `BrowserRouter` gives its children: no matched route, so a relative link outside the app's `<Routes>` resolves from
|
|
15
|
+
// the base path and not from the current URL, as it would beneath the catch-all route.
|
|
16
|
+
const NO_MATCHED_ROUTE = { outlet: null, matches: [], isDataRoute: false };
|
|
17
|
+
const RoutedTree = () => (jsx(UNSAFE_RouteContext, { value: NO_MATCHED_ROUTE, children: jsx(RouteProvider, { children: jsx(UnsavedChangesGuardProvider, { children: useContext(RoutedTreeContext) }) }) }));
|
|
18
|
+
// One catch-all route: the app's own `<Routes>` match beneath it as before, and `useBlocker` works for the whole tree.
|
|
19
|
+
const ROUTES = [{ path: '*', Component: RoutedTree }];
|
|
9
20
|
const UIProviderInner = ({ children, baseUrl, errorBoundary, scopeId, portalContainer, }) => {
|
|
10
21
|
const { themeRoot, resolvedMode } = useTheme();
|
|
11
22
|
const getContainer = usePortalAnchor({ portalContainer, scopeId, themeRoot, resolvedMode });
|
|
12
|
-
|
|
23
|
+
const router = useBrowserRouter(ROUTES, baseUrl);
|
|
24
|
+
const tree = (jsx(ErrorBoundary, { ...errorBoundary, children: jsx(PortalContainer, { getContainer: getContainer, children: children }) }));
|
|
25
|
+
if (!router)
|
|
26
|
+
return null;
|
|
27
|
+
return (jsx(RoutedTreeContext, { value: tree, children: jsx(RouterProvider, { router: router }) }));
|
|
13
28
|
};
|
|
14
29
|
/**
|
|
15
|
-
* Single entry-point provider that composes `ThemeProvider`, `RouteProvider`, `ErrorBoundary
|
|
30
|
+
* Single entry-point provider that composes `ThemeProvider`, `RouteProvider`, `ErrorBoundary`,
|
|
16
31
|
* and overlay portalling for a consuming app. Wire it once at the root and pass `scopeId` when the
|
|
17
32
|
* app ships CSS scoped to `[data-mfe-scope]`; overlays then portal into a scoped anchor on `body`.
|
|
18
33
|
*
|
|
19
34
|
* @summary root provider composing theme, routing, errors and portals
|
|
20
35
|
*/
|
|
21
36
|
const UIProvider = ({ children, themeModeOverride, scopeId, ...rest }) => {
|
|
22
|
-
// TODO(i18n): add an internal
|
|
23
|
-
//
|
|
24
|
-
// consuming app needing to pass text props. This is purely internal — consuming apps
|
|
25
|
-
// own their own translation layer and wrap their content inside UIProvider as usual.
|
|
37
|
+
// TODO(i18n): add an internal translation context so components source their own built-in text ("Discard", "Rows per
|
|
38
|
+
// page") in the host's language. Apps keep their own translation layer; form messages reach it through `useSchemaResolver`.
|
|
26
39
|
return (jsx(ThemeProvider, { themeModeOverride: themeModeOverride, scopeId: scopeId, children: jsx(UIProviderInner, { scopeId: scopeId, ...rest, children: children }) }));
|
|
27
40
|
};
|
|
28
41
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/providers/UIProvider/index.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/providers/UIProvider/index.tsx"],"sourcesContent":[null],"names":["_jsx","DataRouterProvider"],"mappings":";;;;;;;;;;;AAmDA;AACA,MAAM,iBAAiB,GAAG,aAAa,CAAY,IAAI,CAAC;AACxD;AACA;AACA,MAAM,gBAAgB,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE;AAC1E,MAAM,UAAU,GAAG,OACjBA,GAAA,CAAC,mBAAmB,EAAA,EAAC,KAAK,EAAE,gBAAgB,EAAA,QAAA,EAC1CA,GAAA,CAAC,aAAa,EAAA,EAAA,QAAA,EACZA,GAAA,CAAC,2BAA2B,EAAA,EAAA,QAAA,EAAE,UAAU,CAAC,iBAAiB,CAAC,EAAA,CAA+B,EAAA,CAC5E,EAAA,CACI,CACvB;AACD;AACA,MAAM,MAAM,GAAG,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AAErD,MAAM,eAAe,GAAG,CAAC,EACvB,QAAQ,EACR,OAAO,EACP,aAAa,EACb,OAAO,EACP,eAAe,GAC+C,KAAI;IAClE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,QAAQ,EAAE;AAC9C,IAAA,MAAM,YAAY,GAAG,eAAe,CAAC,EAAE,eAAe,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC;IAE3F,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC;AAEhD,IAAA,MAAM,IAAI,IACRA,IAAC,aAAa,EAAA,EAAA,GAAK,aAAa,EAAA,QAAA,EAC9BA,GAAA,CAAC,eAAe,EAAA,EAAC,YAA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