@flipdish/ui-library 0.55.0 → 0.56.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/forms/__internal__/formField/hooks/useFormField.d.ts +1 -1
- package/dist/components/forms/__internal__/formField/hooks/useFormField.d.ts.map +1 -1
- package/dist/components/forms/fields/FormCheckbox/index.cjs +1 -1
- package/dist/components/forms/fields/FormCheckbox/index.d.ts +1 -1
- package/dist/components/forms/fields/FormCheckbox/index.js +1 -1
- package/dist/components/forms/validation/index.cjs +1 -1
- package/dist/components/forms/validation/index.d.ts +2 -2
- package/dist/components/forms/validation/index.d.ts.map +1 -1
- package/dist/components/forms/validation/index.js +1 -1
- package/dist/providers/UIProvider/hooks/useBrowserRouter.cjs +14 -40
- package/dist/providers/UIProvider/hooks/useBrowserRouter.cjs.map +1 -1
- package/dist/providers/UIProvider/hooks/useBrowserRouter.d.ts.map +1 -1
- package/dist/providers/UIProvider/hooks/useBrowserRouter.js +14 -40
- package/dist/providers/UIProvider/hooks/useBrowserRouter.js.map +1 -1
- package/dist/providers/UIProvider/utilities/historyIndex.utils.cjs +133 -0
- package/dist/providers/UIProvider/utilities/historyIndex.utils.cjs.map +1 -0
- package/dist/providers/UIProvider/utilities/historyIndex.utils.d.ts +44 -0
- package/dist/providers/UIProvider/utilities/historyIndex.utils.d.ts.map +1 -0
- package/dist/providers/UIProvider/utilities/historyIndex.utils.js +130 -0
- package/dist/providers/UIProvider/utilities/historyIndex.utils.js.map +1 -0
- package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.cjs +1 -1
- package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.d.ts +1 -1
- package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.js +1 -1
- package/package.json +1 -1
- package/dist/components/forms/fields/FormToggle/index.cjs +0 -32
- package/dist/components/forms/fields/FormToggle/index.cjs.map +0 -1
- package/dist/components/forms/fields/FormToggle/index.d.ts +0 -19
- package/dist/components/forms/fields/FormToggle/index.d.ts.map +0 -1
- package/dist/components/forms/fields/FormToggle/index.js +0 -30
- package/dist/components/forms/fields/FormToggle/index.js.map +0 -1
- package/dist/native/components/forms/fields/FormToggle/index.d.ts +0 -12
|
@@ -11,7 +11,7 @@ export interface FormField<TValue> {
|
|
|
11
11
|
onDraft: (value: TValue) => void;
|
|
12
12
|
/** For a control the user types into: sets the value, and re-validates while the field is invalid. */
|
|
13
13
|
onChange: (value: TValue) => void;
|
|
14
|
-
/** For a control where one action is the whole edit (a choice, a
|
|
14
|
+
/** For a control where one action is the whole edit (a choice, a ticked box, a picked date): sets the value and validates it. */
|
|
15
15
|
onCommit: (value: TValue) => void;
|
|
16
16
|
isInvalid: boolean;
|
|
17
17
|
/** The message validation gave the field's error. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormField.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFormField.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAiC,MAAM,iBAAiB,CAAC;AAOpH,kEAAkE;AAClE,MAAM,WAAW,SAAS,CAAC,MAAM;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,sFAAsF;IACtF,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,8FAA8F;IAC9F,GAAG,EAAE,WAAW,CAAC;IACjB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,2GAA2G;IAC3G,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,sGAAsG;IACtG,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,
|
|
1
|
+
{"version":3,"file":"useFormField.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFormField.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAiC,MAAM,iBAAiB,CAAC;AAOpH,kEAAkE;AAClE,MAAM,WAAW,SAAS,CAAC,MAAM;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,sFAAsF;IACtF,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,8FAA8F;IAC9F,GAAG,EAAE,WAAW,CAAC;IACjB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,2GAA2G;IAC3G,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,sGAAsG;IACtG,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,iIAAiI;IACjI,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,qDAAqD;IACrD,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,mEAAmE;IACnE,UAAU,EAAE,OAAO,CAAC;IACpB,8GAA8G;IAC9G,QAAQ,EAAE,OAAO,CAAC;CACnB;AAOD;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,SAAS,WAAW,EAAE,MAAM,GAAG,OAAO,EACxE,MAAM,SAAS,CAAC,OAAO,CAAC,EACxB,cAAc,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,EAAE,KACtD,SAAS,CAAC,MAAM,CAkIlB,CAAC"}
|
|
@@ -7,7 +7,7 @@ var useFormField = require('../../__internal__/formField/hooks/useFormField.cjs'
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A `Checkbox` bound to a react-hook-form field: ticking it writes a boolean to the form and validates it at once, and
|
|
10
|
-
* the field's error shows in place of `hint`. Use it for a single yes or no choice in a form built with react-hook-form.
|
|
10
|
+
* the field's error shows in place of `hint`. Use it for a single yes or no choice, or a setting turned on or off, in a form built with react-hook-form.
|
|
11
11
|
*
|
|
12
12
|
* @summary checkbox bound to a react-hook-form field
|
|
13
13
|
*/
|
|
@@ -11,7 +11,7 @@ export interface FormCheckboxProps<TValues extends FieldValues = FieldValues> ex
|
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* A `Checkbox` bound to a react-hook-form field: ticking it writes a boolean to the form and validates it at once, and
|
|
14
|
-
* the field's error shows in place of `hint`. Use it for a single yes or no choice in a form built with react-hook-form.
|
|
14
|
+
* the field's error shows in place of `hint`. Use it for a single yes or no choice, or a setting turned on or off, in a form built with react-hook-form.
|
|
15
15
|
*
|
|
16
16
|
* @summary checkbox bound to a react-hook-form field
|
|
17
17
|
*/
|
|
@@ -5,7 +5,7 @@ import { useFormField } from '../../__internal__/formField/hooks/useFormField.js
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* A `Checkbox` bound to a react-hook-form field: ticking it writes a boolean to the form and validates it at once, and
|
|
8
|
-
* the field's error shows in place of `hint`. Use it for a single yes or no choice in a form built with react-hook-form.
|
|
8
|
+
* the field's error shows in place of `hint`. Use it for a single yes or no choice, or a setting turned on or off, in a form built with react-hook-form.
|
|
9
9
|
*
|
|
10
10
|
* @summary checkbox bound to a react-hook-form field
|
|
11
11
|
*/
|
|
@@ -363,7 +363,7 @@ const asCrossFieldRule = (rule) => {
|
|
|
363
363
|
};
|
|
364
364
|
/**
|
|
365
365
|
* Adds the rules that read more than one field, such as a postcode whose shape depends on the country, or a date that
|
|
366
|
-
* is needed only while a
|
|
366
|
+
* is needed only while a checkbox is ticked. Each rule runs as soon as the fields it reads are valid: left to itself zod
|
|
367
367
|
* skips it while any field in the form fails, so its error would only show on a second save. In a form validated
|
|
368
368
|
* through `useSchemaResolver`, a `Form*` field a rule reads re-validates the field the rule reports on as it changes.
|
|
369
369
|
* That holds for a schema refined further, but not for one wrapped afterwards, as `.transform()` and `.optional()` do.
|
|
@@ -258,13 +258,13 @@ export interface ConditionalRule<TSchema extends z.ZodObject> {
|
|
|
258
258
|
/** Not for a rule with `when` and `rules`: they replace the `check`. */
|
|
259
259
|
check?: never;
|
|
260
260
|
}
|
|
261
|
-
/** The fields of a schema that hold a boolean, such as a
|
|
261
|
+
/** The fields of a schema that hold a boolean, such as a checkbox. */
|
|
262
262
|
type BooleanFieldName<TSchema extends z.ZodObject> = {
|
|
263
263
|
[TName in keyof z.output<TSchema> & string]: z.output<TSchema>[TName] extends boolean ? TName : never;
|
|
264
264
|
}[keyof z.output<TSchema> & string];
|
|
265
265
|
/**
|
|
266
266
|
* Adds the rules that read more than one field, such as a postcode whose shape depends on the country, or a date that
|
|
267
|
-
* is needed only while a
|
|
267
|
+
* is needed only while a checkbox is ticked. Each rule runs as soon as the fields it reads are valid: left to itself zod
|
|
268
268
|
* skips it while any field in the form fails, so its error would only show on a second save. In a form validated
|
|
269
269
|
* through `useSchemaResolver`, a `Form*` field a rule reads re-validates the field the rule reports on as it changes.
|
|
270
270
|
* That holds for a schema refined further, but not for one wrapped afterwards, as `.transform()` and `.optional()` do.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/validation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEnE;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,MAAM,IAAI,MAAM,GAAG,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAEnF;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,CAAC;AAE5C,MAAM,WAAW,eAAe;IAC9B,8GAA8G;IAC9G,QA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C,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC;IAC9D,wEAAwE;IACxE,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,sEAAsE;AACtE,KAAK,gBAAgB,CAAC,OAAO,SAAS,CAAC,CAAC,SAAS,IAAI;KAClD,KAAK,IAAI,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,SAAS,OAAO,GAAG,KAAK,GAAG,KAAK;CACtG,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC;AA2BpC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,SAAS,CAAC,CAAC,SAAS,EACzD,QAAQ,OAAO,EACf,GAAG,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC,EAAE,KAC/D,OAoBS,CAAC"}
|
|
@@ -361,7 +361,7 @@ const asCrossFieldRule = (rule) => {
|
|
|
361
361
|
};
|
|
362
362
|
/**
|
|
363
363
|
* Adds the rules that read more than one field, such as a postcode whose shape depends on the country, or a date that
|
|
364
|
-
* is needed only while a
|
|
364
|
+
* is needed only while a checkbox is ticked. Each rule runs as soon as the fields it reads are valid: left to itself zod
|
|
365
365
|
* skips it while any field in the form fails, so its error would only show on a second save. In a form validated
|
|
366
366
|
* through `useSchemaResolver`, a `Form*` field a rule reads re-validates the field the rule reports on as it changes.
|
|
367
367
|
* That holds for a schema refined further, but not for one wrapped afterwards, as `.transform()` and `.optional()` do.
|
|
@@ -2,43 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var React = require('react');
|
|
4
4
|
var reactRouter = require('react-router');
|
|
5
|
+
var historyIndex_utils = require('../utilities/historyIndex.utils.cjs');
|
|
5
6
|
|
|
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
7
|
/**
|
|
43
8
|
* Owns a react-router data router for the lifetime of the component: created on mount and whenever `basename` changes,
|
|
44
9
|
* disposed on unmount so a StrictMode or host re-mount never leaves a `popstate` listener behind. A new `basename` is a
|
|
@@ -52,13 +17,22 @@ const useBrowserRouter = (routes, basename) => {
|
|
|
52
17
|
const [current, setCurrent] = React.useState(null);
|
|
53
18
|
// biome-ignore lint/correctness/useExhaustiveDependencies: the route table is read once per router, so a new array must not rebuild it
|
|
54
19
|
React.useLayoutEffect(() => {
|
|
55
|
-
// Started first, so the router reads an index on the entry it mounts on.
|
|
56
|
-
const
|
|
57
|
-
|
|
20
|
+
// Started first, so the router reads an index on the entry it mounts on, and on each entry it lands on after.
|
|
21
|
+
const historyIndex = historyIndex_utils.keepHistoryIndex();
|
|
22
|
+
let created;
|
|
23
|
+
try {
|
|
24
|
+
created = reactRouter.createBrowserRouter(routes, { basename });
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
// No cleanup runs for an effect that throws, and the listener would go on numbering entries for an app that is gone.
|
|
28
|
+
historyIndex.stop();
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
historyIndex.follow(created);
|
|
58
32
|
setCurrent({ router: created, basename });
|
|
59
33
|
return () => {
|
|
60
34
|
created.dispose();
|
|
61
|
-
|
|
35
|
+
historyIndex.stop();
|
|
62
36
|
};
|
|
63
37
|
}, [basename]);
|
|
64
38
|
// `RouterProvider` keeps the state of the first router it is given, so a router built for another basename is never
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBrowserRouter.cjs","sources":["../../../../src/providers/UIProvider/hooks/useBrowserRouter.ts"],"sourcesContent":[null],"names":["useState","useLayoutEffect","createBrowserRouter"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useBrowserRouter.cjs","sources":["../../../../src/providers/UIProvider/hooks/useBrowserRouter.ts"],"sourcesContent":[null],"names":["useState","useLayoutEffect","keepHistoryIndex","createBrowserRouter"],"mappings":";;;;;;AAMA;;;;;;;;AAQG;MACU,gBAAgB,GAAG,CAAC,MAAqB,EAAE,QAAiB,KAAuB;IAC9F,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAGA,cAAQ,CAAmD,IAAI,CAAC;;IAG9FC,qBAAe,CAAC,MAAK;;AAEnB,QAAA,MAAM,YAAY,GAAGC,mCAAgB,EAAE;AACvC,QAAA,IAAI,OAAmB;AACvB,QAAA,IAAI;YACF,OAAO,GAAGC,+BAAmB,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC;QACrD;QAAE,OAAO,KAAK,EAAE;;YAEd,YAAY,CAAC,IAAI,EAAE;AACnB,YAAA,MAAM,KAAK;QACb;AACA,QAAA,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC;QAC5B,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACzC,QAAA,OAAO,MAAK;YACV,OAAO,CAAC,OAAO,EAAE;YACjB,YAAY,CAAC,IAAI,EAAE;AACrB,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;;"}
|
|
@@ -1 +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;
|
|
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;AAGtF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,WAAW,EAAE,EAAE,WAAW,MAAM,KAAG,UAAU,GAAG,IA0BxF,CAAC"}
|
|
@@ -1,42 +1,7 @@
|
|
|
1
1
|
import { useState, useLayoutEffect } from 'react';
|
|
2
2
|
import { createBrowserRouter } from 'react-router';
|
|
3
|
+
import { keepHistoryIndex } from '../utilities/historyIndex.utils.js';
|
|
3
4
|
|
|
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
5
|
/**
|
|
41
6
|
* Owns a react-router data router for the lifetime of the component: created on mount and whenever `basename` changes,
|
|
42
7
|
* disposed on unmount so a StrictMode or host re-mount never leaves a `popstate` listener behind. A new `basename` is a
|
|
@@ -50,13 +15,22 @@ const useBrowserRouter = (routes, basename) => {
|
|
|
50
15
|
const [current, setCurrent] = useState(null);
|
|
51
16
|
// biome-ignore lint/correctness/useExhaustiveDependencies: the route table is read once per router, so a new array must not rebuild it
|
|
52
17
|
useLayoutEffect(() => {
|
|
53
|
-
// Started first, so the router reads an index on the entry it mounts on.
|
|
54
|
-
const
|
|
55
|
-
|
|
18
|
+
// Started first, so the router reads an index on the entry it mounts on, and on each entry it lands on after.
|
|
19
|
+
const historyIndex = keepHistoryIndex();
|
|
20
|
+
let created;
|
|
21
|
+
try {
|
|
22
|
+
created = createBrowserRouter(routes, { basename });
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
// No cleanup runs for an effect that throws, and the listener would go on numbering entries for an app that is gone.
|
|
26
|
+
historyIndex.stop();
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
historyIndex.follow(created);
|
|
56
30
|
setCurrent({ router: created, basename });
|
|
57
31
|
return () => {
|
|
58
32
|
created.dispose();
|
|
59
|
-
|
|
33
|
+
historyIndex.stop();
|
|
60
34
|
};
|
|
61
35
|
}, [basename]);
|
|
62
36
|
// `RouterProvider` keeps the state of the first router it is given, so a router built for another basename is never
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBrowserRouter.js","sources":["../../../../src/providers/UIProvider/hooks/useBrowserRouter.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useBrowserRouter.js","sources":["../../../../src/providers/UIProvider/hooks/useBrowserRouter.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAMA;;;;;;;;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,YAAY,GAAG,gBAAgB,EAAE;AACvC,QAAA,IAAI,OAAmB;AACvB,QAAA,IAAI;YACF,OAAO,GAAG,mBAAmB,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC;QACrD;QAAE,OAAO,KAAK,EAAE;;YAEd,YAAY,CAAC,IAAI,EAAE;AACnB,YAAA,MAAM,KAAK;QACb;AACA,QAAA,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC;QAC5B,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACzC,QAAA,OAAO,MAAK;YACV,OAAO,CAAC,OAAO,EAAE;YACjB,YAAY,CAAC,IAAI,EAAE;AACrB,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,133 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const indexOf = (state) => state?.idx;
|
|
4
|
+
const finiteIndexOf = (state) => {
|
|
5
|
+
const idx = indexOf(state);
|
|
6
|
+
return typeof idx === 'number' && Number.isFinite(idx) ? idx : undefined;
|
|
7
|
+
};
|
|
8
|
+
// History's length less the index of its last entry, once learnt: an entry where the two differ by this has none ahead of it.
|
|
9
|
+
let endOffset;
|
|
10
|
+
/**
|
|
11
|
+
* Decides the index of an entry a `popstate` has landed on, where the browser has no Navigation API to say where the
|
|
12
|
+
* entry sits. It answers only for the one entry a host has just pushed from the last entry in history, whose index is
|
|
13
|
+
* known: a missing index lets a back or forward move through, while a wrong one holds the move and puts the user back on
|
|
14
|
+
* the wrong entry.
|
|
15
|
+
*
|
|
16
|
+
* @param move The `popstate` and what was known before it.
|
|
17
|
+
* @returns The index to write on the entry, or `undefined` to leave the entry as it is.
|
|
18
|
+
*/
|
|
19
|
+
const hostEntryIndex = ({ state, isTrusted, left, length }) => {
|
|
20
|
+
const idx = indexOf(state);
|
|
21
|
+
const isPlainObject = typeof state === 'object' && state !== null && Object.getPrototypeOf(state) === Object.prototype;
|
|
22
|
+
// An index already there is never changed, and only nothing or a plain object can take one, as with the Navigation API.
|
|
23
|
+
if ((idx !== undefined && idx !== null) || !(state === null || isPlainObject))
|
|
24
|
+
return undefined;
|
|
25
|
+
// Only a `popstate` the host dispatched itself, which is not trusted, says it has just navigated; a browser move could be from anywhere.
|
|
26
|
+
if (isTrusted || !left)
|
|
27
|
+
return undefined;
|
|
28
|
+
// With entries ahead, several pushes heard as one drop them and can leave history one longer, just as a single push does.
|
|
29
|
+
if (!left.isAtEnd)
|
|
30
|
+
return undefined;
|
|
31
|
+
// Portal also dispatches after a replace, which keeps the length, and two pushes from the last entry grow it by two.
|
|
32
|
+
// Still wrong for several pushes one below the browser's limit or with a wrong `isAtEnd`, and for a replace after an iframe step grew the length.
|
|
33
|
+
if (length !== left.length + 1)
|
|
34
|
+
return undefined;
|
|
35
|
+
return left.idx + 1;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Numbers the entries a host pushes where the browser has no Navigation API, by the rule in `hostEntryIndex`. Call it
|
|
39
|
+
* before the router is created, so its `popstate` listener runs before the router's and it sees whether the entry is new.
|
|
40
|
+
*
|
|
41
|
+
* @returns The keeper; `follow` is given the router once it is created, and `stop` ends it.
|
|
42
|
+
*/
|
|
43
|
+
const keepHistoryIndexByPopState = () => {
|
|
44
|
+
// An entry nothing has numbered is the one a host has just pushed or the browser has just loaded: the last in history.
|
|
45
|
+
const isOnNewEntry = indexOf(window.history.state) === undefined || indexOf(window.history.state) === null;
|
|
46
|
+
// The last entry seen with an index: the host's next push is numbered from it.
|
|
47
|
+
let known;
|
|
48
|
+
// The key of the entry last read, which tells the router's push apart from its later word about the same entry.
|
|
49
|
+
let seenKey;
|
|
50
|
+
let unfollow = () => { };
|
|
51
|
+
const read = () => {
|
|
52
|
+
const state = window.history.state;
|
|
53
|
+
const idx = finiteIndexOf(state);
|
|
54
|
+
const { length } = window.history;
|
|
55
|
+
seenKey = state?.key;
|
|
56
|
+
known = idx === undefined ? undefined : { idx, length, isAtEnd: length - idx === endOffset };
|
|
57
|
+
};
|
|
58
|
+
const markEnd = () => {
|
|
59
|
+
const idx = finiteIndexOf(window.history.state);
|
|
60
|
+
if (idx !== undefined)
|
|
61
|
+
endOffset = window.history.length - idx;
|
|
62
|
+
};
|
|
63
|
+
const number = (event) => {
|
|
64
|
+
const state = window.history.state;
|
|
65
|
+
const idx = hostEntryIndex({ state, isTrusted: event.isTrusted, left: known, length: window.history.length });
|
|
66
|
+
if (idx !== undefined)
|
|
67
|
+
window.history.replaceState({ ...state, idx }, '');
|
|
68
|
+
// Forgets the entry left unless this one has an index to count from, so nothing later is numbered from a stale one.
|
|
69
|
+
read();
|
|
70
|
+
};
|
|
71
|
+
// Capture phase, so the entry is numbered before react-router reads it even where another listener was added first.
|
|
72
|
+
window.addEventListener('popstate', number, true);
|
|
73
|
+
return {
|
|
74
|
+
follow: (router) => {
|
|
75
|
+
// The router has numbered the entry it was created on by now.
|
|
76
|
+
if (isOnNewEntry)
|
|
77
|
+
markEnd();
|
|
78
|
+
read();
|
|
79
|
+
// The router numbers its own pushes with no event, and tells its subscribers once a push has landed.
|
|
80
|
+
unfollow = router.subscribe(({ historyAction, location }) => {
|
|
81
|
+
const key = window.history.state?.key;
|
|
82
|
+
// A push makes its entry the last in history, whatever was ahead before it.
|
|
83
|
+
if (historyAction === 'PUSH' && key === location.key && key !== seenKey)
|
|
84
|
+
markEnd();
|
|
85
|
+
read();
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
stop: () => {
|
|
89
|
+
unfollow();
|
|
90
|
+
window.removeEventListener('popstate', number, true);
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Gives every history entry the app lands on the index react-router expects there. A host such as Portal pushes entries
|
|
96
|
+
* without one, and react-router then cannot tell how far a back or forward move went, so it could not hold one.
|
|
97
|
+
*
|
|
98
|
+
* @returns The keeper; `follow` is given the router once it is created, and `stop` ends it.
|
|
99
|
+
*/
|
|
100
|
+
const keepHistoryIndex = () => {
|
|
101
|
+
const { navigation } = window;
|
|
102
|
+
if (!navigation)
|
|
103
|
+
return keepHistoryIndexByPopState();
|
|
104
|
+
// The last entry seen with an index, and where the browser says it sits: the next one is numbered from it.
|
|
105
|
+
let known;
|
|
106
|
+
const number = () => {
|
|
107
|
+
const position = navigation.currentEntry?.index ?? -1;
|
|
108
|
+
const state = window.history.state;
|
|
109
|
+
// Only a plain object can take one more field and stay what it was; anything else is the host's own to keep.
|
|
110
|
+
const isPlainObject = typeof state === 'object' && state !== null && Object.getPrototypeOf(state) === Object.prototype;
|
|
111
|
+
if (position < 0 || !(state === null || isPlainObject))
|
|
112
|
+
return;
|
|
113
|
+
const idx = state?.idx;
|
|
114
|
+
// An index already there is never changed: another router on the page may count from it, and a `NaN`, which
|
|
115
|
+
// react-router writes after an entry it could not count from, marks a move it cannot rewind.
|
|
116
|
+
if (idx !== undefined && idx !== null) {
|
|
117
|
+
if (typeof idx === 'number' && Number.isFinite(idx))
|
|
118
|
+
known = { idx, position };
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const next = known ? known.idx + position - known.position : position;
|
|
122
|
+
known = { idx: next, position };
|
|
123
|
+
window.history.replaceState({ ...state, idx: next }, '');
|
|
124
|
+
};
|
|
125
|
+
// Fires for every push, replace and back or forward move, before any `popstate` listener reads the entry.
|
|
126
|
+
navigation.addEventListener('currententrychange', number);
|
|
127
|
+
number();
|
|
128
|
+
return { follow: () => { }, stop: () => navigation.removeEventListener('currententrychange', number) };
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
exports.hostEntryIndex = hostEntryIndex;
|
|
132
|
+
exports.keepHistoryIndex = keepHistoryIndex;
|
|
133
|
+
//# sourceMappingURL=historyIndex.utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"historyIndex.utils.cjs","sources":["../../../../src/providers/UIProvider/utilities/historyIndex.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAqCA,MAAM,OAAO,GAAG,CAAC,KAAc,KAAe,KAAkC,EAAE,GAAG;AAErF,MAAM,aAAa,GAAG,CAAC,KAAc,KAAwB;AAC3D,IAAA,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC;AAC1B,IAAA,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,SAAS;AAC1E,CAAC;AAED;AACA,IAAI,SAA6B;AAEjC;;;;;;;;AAQG;AACI,MAAM,cAAc,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAe,KAAwB;AACpG,IAAA,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC;IAC1B,MAAM,aAAa,GAAG,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,SAAS;;AAEtH,IAAA,IAAI,CAAC,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,KAAK,EAAE,KAAK,KAAK,IAAI,IAAI,aAAa,CAAC;AAAE,QAAA,OAAO,SAAS;;IAE/F,IAAI,SAAS,IAAI,CAAC,IAAI;AAAE,QAAA,OAAO,SAAS;;IAExC,IAAI,CAAC,IAAI,CAAC,OAAO;AAAE,QAAA,OAAO,SAAS;;;AAGnC,IAAA,IAAI,MAAM,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC;AAAE,QAAA,OAAO,SAAS;AAChD,IAAA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AAa,GAAG,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,SAAS;QACtH,IAAI,QAAQ,GAAG,CAAC,IAAI,EAAE,KAAK,KAAK,IAAI,IAAI,aAAa,CAAC;YAAE;AACxD,QAAA,MAAM,GAAG,GAAI,KAAkC,EAAE,GAAG;;;QAGpD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE;YACrC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;AAAE,gBAAA,KAAK,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE;YAC9E;QACF;AACA,QAAA,MAAM,IAAI,GAAG,KAAK,GAAG,KAAK,CAAC,GAAG,GAAG,QAAQ,GAAG,KAAK,CAAC,QAAQ,GAAG,QAAQ;QACrE,KAAK,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE;AAC/B,QAAA,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AAC1D,IAAA,CAAC;;AAGD,IAAA,UAAU,CAAC,gBAAgB,CAAC,oBAAoB,EAAE,MAAM,CAAC;AACzD,IAAA,MAAM,EAAE;IACR,OAAO,EAAE,MAAM,EAAE,MAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,MAAM,CAAC,EAAE;AACvG;;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { DataRouter } from 'react-router';
|
|
2
|
+
/** What keeps react-router's index on the history entries a host pushes; see `keepHistoryIndex`. */
|
|
3
|
+
export interface HistoryIndexKeeper {
|
|
4
|
+
/** Reads the index again after each navigation the router makes, which no event announces. */
|
|
5
|
+
follow: (router: Pick<DataRouter, 'subscribe'>) => void;
|
|
6
|
+
/** Removes every listener it added. */
|
|
7
|
+
stop: () => void;
|
|
8
|
+
}
|
|
9
|
+
/** An entry seen with an index, and how long history was then. */
|
|
10
|
+
export interface KnownHistoryEntry {
|
|
11
|
+
idx: number;
|
|
12
|
+
length: number;
|
|
13
|
+
/** Whether it was known to be the last entry in history, with none ahead of it. */
|
|
14
|
+
isAtEnd: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** A `popstate`, as `hostEntryIndex` reads it. */
|
|
17
|
+
export interface HistoryMove {
|
|
18
|
+
/** The state of the entry the move landed on. */
|
|
19
|
+
state: unknown;
|
|
20
|
+
/** Whether the browser made the move; `false` for a `popstate` the host dispatched itself. */
|
|
21
|
+
isTrusted: boolean;
|
|
22
|
+
/** The last entry seen with an index before the move, or `undefined` when none is known. */
|
|
23
|
+
left: KnownHistoryEntry | undefined;
|
|
24
|
+
/** How long history is after the move. */
|
|
25
|
+
length: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Decides the index of an entry a `popstate` has landed on, where the browser has no Navigation API to say where the
|
|
29
|
+
* entry sits. It answers only for the one entry a host has just pushed from the last entry in history, whose index is
|
|
30
|
+
* known: a missing index lets a back or forward move through, while a wrong one holds the move and puts the user back on
|
|
31
|
+
* the wrong entry.
|
|
32
|
+
*
|
|
33
|
+
* @param move The `popstate` and what was known before it.
|
|
34
|
+
* @returns The index to write on the entry, or `undefined` to leave the entry as it is.
|
|
35
|
+
*/
|
|
36
|
+
export declare const hostEntryIndex: ({ state, isTrusted, left, length }: HistoryMove) => number | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Gives every history entry the app lands on the index react-router expects there. A host such as Portal pushes entries
|
|
39
|
+
* without one, and react-router then cannot tell how far a back or forward move went, so it could not hold one.
|
|
40
|
+
*
|
|
41
|
+
* @returns The keeper; `follow` is given the router once it is created, and `stop` ends it.
|
|
42
|
+
*/
|
|
43
|
+
export declare const keepHistoryIndex: () => HistoryIndexKeeper;
|
|
44
|
+
//# sourceMappingURL=historyIndex.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"historyIndex.utils.d.ts","sourceRoot":"","sources":["../../../../src/providers/UIProvider/utilities/historyIndex.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAS/C,oGAAoG;AACpG,MAAM,WAAW,kBAAkB;IACjC,8FAA8F;IAC9F,MAAM,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,KAAK,IAAI,CAAC;IACxD,uCAAuC;IACvC,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB;AAED,kEAAkE;AAClE,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,mFAAmF;IACnF,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,kDAAkD;AAClD,MAAM,WAAW,WAAW;IAC1B,iDAAiD;IACjD,KAAK,EAAE,OAAO,CAAC;IACf,8FAA8F;IAC9F,SAAS,EAAE,OAAO,CAAC;IACnB,4FAA4F;IAC5F,IAAI,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACpC,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;CAChB;AAYD;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAI,oCAAoC,WAAW,KAAG,MAAM,GAAG,SAazF,CAAC;AA4DF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAO,kBA4BnC,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
const indexOf = (state) => state?.idx;
|
|
2
|
+
const finiteIndexOf = (state) => {
|
|
3
|
+
const idx = indexOf(state);
|
|
4
|
+
return typeof idx === 'number' && Number.isFinite(idx) ? idx : undefined;
|
|
5
|
+
};
|
|
6
|
+
// History's length less the index of its last entry, once learnt: an entry where the two differ by this has none ahead of it.
|
|
7
|
+
let endOffset;
|
|
8
|
+
/**
|
|
9
|
+
* Decides the index of an entry a `popstate` has landed on, where the browser has no Navigation API to say where the
|
|
10
|
+
* entry sits. It answers only for the one entry a host has just pushed from the last entry in history, whose index is
|
|
11
|
+
* known: a missing index lets a back or forward move through, while a wrong one holds the move and puts the user back on
|
|
12
|
+
* the wrong entry.
|
|
13
|
+
*
|
|
14
|
+
* @param move The `popstate` and what was known before it.
|
|
15
|
+
* @returns The index to write on the entry, or `undefined` to leave the entry as it is.
|
|
16
|
+
*/
|
|
17
|
+
const hostEntryIndex = ({ state, isTrusted, left, length }) => {
|
|
18
|
+
const idx = indexOf(state);
|
|
19
|
+
const isPlainObject = typeof state === 'object' && state !== null && Object.getPrototypeOf(state) === Object.prototype;
|
|
20
|
+
// An index already there is never changed, and only nothing or a plain object can take one, as with the Navigation API.
|
|
21
|
+
if ((idx !== undefined && idx !== null) || !(state === null || isPlainObject))
|
|
22
|
+
return undefined;
|
|
23
|
+
// Only a `popstate` the host dispatched itself, which is not trusted, says it has just navigated; a browser move could be from anywhere.
|
|
24
|
+
if (isTrusted || !left)
|
|
25
|
+
return undefined;
|
|
26
|
+
// With entries ahead, several pushes heard as one drop them and can leave history one longer, just as a single push does.
|
|
27
|
+
if (!left.isAtEnd)
|
|
28
|
+
return undefined;
|
|
29
|
+
// Portal also dispatches after a replace, which keeps the length, and two pushes from the last entry grow it by two.
|
|
30
|
+
// Still wrong for several pushes one below the browser's limit or with a wrong `isAtEnd`, and for a replace after an iframe step grew the length.
|
|
31
|
+
if (length !== left.length + 1)
|
|
32
|
+
return undefined;
|
|
33
|
+
return left.idx + 1;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Numbers the entries a host pushes where the browser has no Navigation API, by the rule in `hostEntryIndex`. Call it
|
|
37
|
+
* before the router is created, so its `popstate` listener runs before the router's and it sees whether the entry is new.
|
|
38
|
+
*
|
|
39
|
+
* @returns The keeper; `follow` is given the router once it is created, and `stop` ends it.
|
|
40
|
+
*/
|
|
41
|
+
const keepHistoryIndexByPopState = () => {
|
|
42
|
+
// An entry nothing has numbered is the one a host has just pushed or the browser has just loaded: the last in history.
|
|
43
|
+
const isOnNewEntry = indexOf(window.history.state) === undefined || indexOf(window.history.state) === null;
|
|
44
|
+
// The last entry seen with an index: the host's next push is numbered from it.
|
|
45
|
+
let known;
|
|
46
|
+
// The key of the entry last read, which tells the router's push apart from its later word about the same entry.
|
|
47
|
+
let seenKey;
|
|
48
|
+
let unfollow = () => { };
|
|
49
|
+
const read = () => {
|
|
50
|
+
const state = window.history.state;
|
|
51
|
+
const idx = finiteIndexOf(state);
|
|
52
|
+
const { length } = window.history;
|
|
53
|
+
seenKey = state?.key;
|
|
54
|
+
known = idx === undefined ? undefined : { idx, length, isAtEnd: length - idx === endOffset };
|
|
55
|
+
};
|
|
56
|
+
const markEnd = () => {
|
|
57
|
+
const idx = finiteIndexOf(window.history.state);
|
|
58
|
+
if (idx !== undefined)
|
|
59
|
+
endOffset = window.history.length - idx;
|
|
60
|
+
};
|
|
61
|
+
const number = (event) => {
|
|
62
|
+
const state = window.history.state;
|
|
63
|
+
const idx = hostEntryIndex({ state, isTrusted: event.isTrusted, left: known, length: window.history.length });
|
|
64
|
+
if (idx !== undefined)
|
|
65
|
+
window.history.replaceState({ ...state, idx }, '');
|
|
66
|
+
// Forgets the entry left unless this one has an index to count from, so nothing later is numbered from a stale one.
|
|
67
|
+
read();
|
|
68
|
+
};
|
|
69
|
+
// Capture phase, so the entry is numbered before react-router reads it even where another listener was added first.
|
|
70
|
+
window.addEventListener('popstate', number, true);
|
|
71
|
+
return {
|
|
72
|
+
follow: (router) => {
|
|
73
|
+
// The router has numbered the entry it was created on by now.
|
|
74
|
+
if (isOnNewEntry)
|
|
75
|
+
markEnd();
|
|
76
|
+
read();
|
|
77
|
+
// The router numbers its own pushes with no event, and tells its subscribers once a push has landed.
|
|
78
|
+
unfollow = router.subscribe(({ historyAction, location }) => {
|
|
79
|
+
const key = window.history.state?.key;
|
|
80
|
+
// A push makes its entry the last in history, whatever was ahead before it.
|
|
81
|
+
if (historyAction === 'PUSH' && key === location.key && key !== seenKey)
|
|
82
|
+
markEnd();
|
|
83
|
+
read();
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
stop: () => {
|
|
87
|
+
unfollow();
|
|
88
|
+
window.removeEventListener('popstate', number, true);
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Gives every history entry the app lands on the index react-router expects there. A host such as Portal pushes entries
|
|
94
|
+
* without one, and react-router then cannot tell how far a back or forward move went, so it could not hold one.
|
|
95
|
+
*
|
|
96
|
+
* @returns The keeper; `follow` is given the router once it is created, and `stop` ends it.
|
|
97
|
+
*/
|
|
98
|
+
const keepHistoryIndex = () => {
|
|
99
|
+
const { navigation } = window;
|
|
100
|
+
if (!navigation)
|
|
101
|
+
return keepHistoryIndexByPopState();
|
|
102
|
+
// The last entry seen with an index, and where the browser says it sits: the next one is numbered from it.
|
|
103
|
+
let known;
|
|
104
|
+
const number = () => {
|
|
105
|
+
const position = navigation.currentEntry?.index ?? -1;
|
|
106
|
+
const state = window.history.state;
|
|
107
|
+
// Only a plain object can take one more field and stay what it was; anything else is the host's own to keep.
|
|
108
|
+
const isPlainObject = typeof state === 'object' && state !== null && Object.getPrototypeOf(state) === Object.prototype;
|
|
109
|
+
if (position < 0 || !(state === null || isPlainObject))
|
|
110
|
+
return;
|
|
111
|
+
const idx = state?.idx;
|
|
112
|
+
// An index already there is never changed: another router on the page may count from it, and a `NaN`, which
|
|
113
|
+
// react-router writes after an entry it could not count from, marks a move it cannot rewind.
|
|
114
|
+
if (idx !== undefined && idx !== null) {
|
|
115
|
+
if (typeof idx === 'number' && Number.isFinite(idx))
|
|
116
|
+
known = { idx, position };
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const next = known ? known.idx + position - known.position : position;
|
|
120
|
+
known = { idx: next, position };
|
|
121
|
+
window.history.replaceState({ ...state, idx: next }, '');
|
|
122
|
+
};
|
|
123
|
+
// Fires for every push, replace and back or forward move, before any `popstate` listener reads the entry.
|
|
124
|
+
navigation.addEventListener('currententrychange', number);
|
|
125
|
+
number();
|
|
126
|
+
return { follow: () => { }, stop: () => navigation.removeEventListener('currententrychange', number) };
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export { hostEntryIndex, keepHistoryIndex };
|
|
130
|
+
//# sourceMappingURL=historyIndex.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"historyIndex.utils.js","sources":["../../../../src/providers/UIProvider/utilities/historyIndex.utils.ts"],"sourcesContent":[null],"names":[],"mappings":"AAqCA,MAAM,OAAO,GAAG,CAAC,KAAc,KAAe,KAAkC,EAAE,GAAG;AAErF,MAAM,aAAa,GAAG,CAAC,KAAc,KAAwB;AAC3D,IAAA,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC;AAC1B,IAAA,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,SAAS;AAC1E,CAAC;AAED;AACA,IAAI,SAA6B;AAEjC;;;;;;;;AAQG;AACI,MAAM,cAAc,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAe,KAAwB;AACpG,IAAA,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC;IAC1B,MAAM,aAAa,GAAG,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,SAAS;;AAEtH,IAAA,IAAI,CAAC,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,KAAK,EAAE,KAAK,KAAK,IAAI,IAAI,aAAa,CAAC;AAAE,QAAA,OAAO,SAAS;;IAE/F,IAAI,SAAS,IAAI,CAAC,IAAI;AA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dNavigationGuard;
|
|
|
9
9
|
/**
|
|
10
10
|
* Reads the index react-router stores on the current history entry.
|
|
11
11
|
*
|
|
12
|
-
* @returns The index; missing or `NaN` on and after
|
|
12
|
+
* @returns The index; missing or `NaN` on and after a host's own entry that could not be numbered.
|
|
13
13
|
*/
|
|
14
14
|
const historyIndex = () => window.history.state?.idx;
|
|
15
15
|
/**
|
|
@@ -8,7 +8,7 @@ export declare const hostGuard: () => FdNavigationGuard | undefined;
|
|
|
8
8
|
/**
|
|
9
9
|
* Reads the index react-router stores on the current history entry.
|
|
10
10
|
*
|
|
11
|
-
* @returns The index; missing or `NaN` on and after
|
|
11
|
+
* @returns The index; missing or `NaN` on and after a host's own entry that could not be numbered.
|
|
12
12
|
*/
|
|
13
13
|
export declare const historyIndex: () => unknown;
|
|
14
14
|
/**
|
|
@@ -7,7 +7,7 @@ const hostGuard = () => window.fdNavigationGuard;
|
|
|
7
7
|
/**
|
|
8
8
|
* Reads the index react-router stores on the current history entry.
|
|
9
9
|
*
|
|
10
|
-
* @returns The index; missing or `NaN` on and after
|
|
10
|
+
* @returns The index; missing or `NaN` on and after a host's own entry that could not be numbered.
|
|
11
11
|
*/
|
|
12
12
|
const historyIndex = () => window.history.state?.idx;
|
|
13
13
|
/**
|
package/package.json
CHANGED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var Toggle = require('@flipdish/ui-library/components/atoms/Toggle');
|
|
5
|
-
var useFocusTarget = require('../../__internal__/formField/hooks/useFocusTarget.cjs');
|
|
6
|
-
var useFormField = require('../../__internal__/formField/hooks/useFormField.cjs');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A `Toggle` bound to a react-hook-form field: flipping it writes a boolean to the form and validates it at once, and
|
|
10
|
-
* the field's error shows in place of `hint`. Use it for a single on or off setting in a form built with react-hook-form.
|
|
11
|
-
*
|
|
12
|
-
* @summary toggle bound to a react-hook-form field
|
|
13
|
-
*/
|
|
14
|
-
const FormToggle = ({ name, revalidates, hint, ...toggleProps }) => {
|
|
15
|
-
const { value, ref, onCommit, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField.useFormField(name, revalidates);
|
|
16
|
-
// react-aria's switch sets `aria-invalid` on its input from `isInvalid`, which the types of `Switch` leave out.
|
|
17
|
-
const invalidProps = { isInvalid };
|
|
18
|
-
// `Toggle` takes no ref, so a layout-neutral wrapper hands the form the input inside it.
|
|
19
|
-
const focusRef = useFocusTarget.useFocusTarget(ref, 'input');
|
|
20
|
-
return (jsxRuntime.jsx("div", { ref: focusRef, className: "contents", children: jsxRuntime.jsx(Toggle.Toggle, { ...toggleProps, ...invalidProps, name: name,
|
|
21
|
-
// An unset field is `undefined`, which would flip the toggle between uncontrolled and controlled.
|
|
22
|
-
isSelected: value ?? false, onChange: onCommit, onBlur: onBlur, isDisabled: toggleProps.isDisabled || isDisabled,
|
|
23
|
-
// Read-only while the form submits: the field keeps its focus and its value, and nothing typed meanwhile is lost to the save.
|
|
24
|
-
isReadOnly: toggleProps.isReadOnly || isLocked,
|
|
25
|
-
// The control gives its hint no error colour, so the message brings its own.
|
|
26
|
-
hint: errorMessage ? (
|
|
27
|
-
// An alert, since the error can appear while focus stays on the control, where a changed label is not announced.
|
|
28
|
-
jsxRuntime.jsx("span", { role: "alert", className: "text-error-primary", children: errorMessage })) : (hint) }) }));
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
exports.FormToggle = FormToggle;
|
|
32
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../../../src/components/forms/fields/FormToggle/index.tsx"],"sourcesContent":[null],"names":["useFormField","useFocusTarget","_jsx","Toggle"],"mappings":";;;;;;;AAkBA;;;;;AAKG;AACI,MAAM,UAAU,GAAG,CAA4C,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,WAAW,EAA4B,KAAI;IAC7I,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAGA,yBAAY,CAAmB,IAAI,EAAE,WAAW,CAAC;;AAEzI,IAAA,MAAM,YAAY,GAAG,EAAE,SAAS,EAA0B;;IAE1D,MAAM,QAAQ,GAAGC,6BAAc,CAAC,GAAG,EAAE,OAAO,CAAC;AAE7C,IAAA,QACEC,cAAA,CAAA,KAAA,EAAA,EAAK,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAC,UAAU,YACtCA,cAAA,CAACC,aAAM,OACD,WAAW,EAAA,GACX,YAAY,EAChB,IAAI,EAAE,IAAI;;AAEV,YAAA,UAAU,EAAE,KAAK,IAAI,KAAK,EAC1B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,UAAU;;AAEhD,YAAA,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,QAAQ;;AAE9C,YAAA,IAAI,EACF,YAAY;;YAEVD,cAAA,CAAA,MAAA,EAAA,EAAM,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,oBAAoB,YAC9C,YAAY,EAAA,CACR,KAEP,IAAI,CACL,EAAA,CAEH,EAAA,CACE;AAEV;;"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type ToggleProps } from '@flipdish/ui-library/components/atoms/Toggle';
|
|
2
|
-
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
3
|
-
export interface FormToggleProps<TValues extends FieldValues = FieldValues> extends Omit<ToggleProps, 'name' | 'isSelected' | 'defaultSelected' | 'onChange' | 'onBlur' | 'ref'> {
|
|
4
|
-
/** The field's path in the form values, such as `isPublished` or `notifications.email`. */
|
|
5
|
-
name: FieldPath<TValues>;
|
|
6
|
-
/**
|
|
7
|
-
* Other fields to re-validate when this changes. A `crossFieldRules` rule validated through `useSchemaResolver` names them
|
|
8
|
-
* itself, so pass this only for a rule written another way, such as a zod `superRefine` in the same schema, or for a nested field.
|
|
9
|
-
*/
|
|
10
|
-
revalidates?: FieldPath<TValues> | FieldPath<TValues>[];
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* A `Toggle` bound to a react-hook-form field: flipping it writes a boolean to the form and validates it at once, and
|
|
14
|
-
* the field's error shows in place of `hint`. Use it for a single on or off setting in a form built with react-hook-form.
|
|
15
|
-
*
|
|
16
|
-
* @summary toggle bound to a react-hook-form field
|
|
17
|
-
*/
|
|
18
|
-
export declare const FormToggle: <TValues extends FieldValues = FieldValues>({ name, revalidates, hint, ...toggleProps }: FormToggleProps<TValues>) => import("react").JSX.Element;
|
|
19
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/forms/fields/FormToggle/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9D,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,WAAW,GAAG,WAAW,CACxE,SAAQ,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,GAAG,iBAAiB,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAC;IACpG,2FAA2F;IAC3F,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IACzB;;;OAGG;IACH,WAAW,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;CACzD;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,SAAS,WAAW,GAAG,WAAW,EAAE,6CAA6C,eAAe,CAAC,OAAO,CAAC,gCAkC1I,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { Toggle } from '@flipdish/ui-library/components/atoms/Toggle';
|
|
3
|
-
import { useFocusTarget } from '../../__internal__/formField/hooks/useFocusTarget.js';
|
|
4
|
-
import { useFormField } from '../../__internal__/formField/hooks/useFormField.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A `Toggle` bound to a react-hook-form field: flipping it writes a boolean to the form and validates it at once, and
|
|
8
|
-
* the field's error shows in place of `hint`. Use it for a single on or off setting in a form built with react-hook-form.
|
|
9
|
-
*
|
|
10
|
-
* @summary toggle bound to a react-hook-form field
|
|
11
|
-
*/
|
|
12
|
-
const FormToggle = ({ name, revalidates, hint, ...toggleProps }) => {
|
|
13
|
-
const { value, ref, onCommit, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField(name, revalidates);
|
|
14
|
-
// react-aria's switch sets `aria-invalid` on its input from `isInvalid`, which the types of `Switch` leave out.
|
|
15
|
-
const invalidProps = { isInvalid };
|
|
16
|
-
// `Toggle` takes no ref, so a layout-neutral wrapper hands the form the input inside it.
|
|
17
|
-
const focusRef = useFocusTarget(ref, 'input');
|
|
18
|
-
return (jsx("div", { ref: focusRef, className: "contents", children: jsx(Toggle, { ...toggleProps, ...invalidProps, name: name,
|
|
19
|
-
// An unset field is `undefined`, which would flip the toggle between uncontrolled and controlled.
|
|
20
|
-
isSelected: value ?? false, onChange: onCommit, onBlur: onBlur, isDisabled: toggleProps.isDisabled || isDisabled,
|
|
21
|
-
// Read-only while the form submits: the field keeps its focus and its value, and nothing typed meanwhile is lost to the save.
|
|
22
|
-
isReadOnly: toggleProps.isReadOnly || isLocked,
|
|
23
|
-
// The control gives its hint no error colour, so the message brings its own.
|
|
24
|
-
hint: errorMessage ? (
|
|
25
|
-
// An alert, since the error can appear while focus stays on the control, where a changed label is not announced.
|
|
26
|
-
jsx("span", { role: "alert", className: "text-error-primary", children: errorMessage })) : (hint) }) }));
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export { FormToggle };
|
|
30
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../src/components/forms/fields/FormToggle/index.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;;AAkBA;;;;;AAKG;AACI,MAAM,UAAU,GAAG,CAA4C,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,WAAW,EAA4B,KAAI;IAC7I,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAmB,IAAI,EAAE,WAAW,CAAC;;AAEzI,IAAA,MAAM,YAAY,GAAG,EAAE,SAAS,EAA0B;;IAE1D,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC;AAE7C,IAAA,QACEA,GAAA,CAAA,KAAA,EAAA,EAAK,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAC,UAAU,YACtCA,GAAA,CAAC,MAAM,OACD,WAAW,EAAA,GACX,YAAY,EAChB,IAAI,EAAE,IAAI;;AAEV,YAAA,UAAU,EAAE,KAAK,IAAI,KAAK,EAC1B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,UAAU;;AAEhD,YAAA,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,QAAQ;;AAE9C,YAAA,IAAI,EACF,YAAY;;YAEVA,GAAA,CAAA,MAAA,EAAA,EAAM,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,oBAAoB,YAC9C,YAAY,EAAA,CACR,KAEP,IAAI,CACL,EAAA,CAEH,EAAA,CACE;AAEV;;"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `FormToggle` 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/forms/fields/FormToggle` 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 `FormToggle` 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;
|