fix: prevent asset conflicts between React and Grid.js versions

Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-04-18 17:02:14 +07:00
parent bd9cdac02e
commit e8fbfb14c1
74973 changed files with 6658406 additions and 71 deletions

View File

@@ -0,0 +1,20 @@
/**
* WordPress dependencies
*/
import { createContext } from '@wordpress/element';
/**
* Internal dependencies
*/
const initialContextValue = {
location: {},
goTo: () => {},
goBack: () => {},
goToParent: () => {},
addScreen: () => {},
removeScreen: () => {},
params: {}
};
export const NavigatorContext = createContext(initialContextValue);
//# sourceMappingURL=context.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["createContext","initialContextValue","location","goTo","goBack","goToParent","addScreen","removeScreen","params","NavigatorContext"],"sources":["@wordpress/components/src/navigator/context.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { NavigatorContext as NavigatorContextType } from './types';\n\nconst initialContextValue: NavigatorContextType = {\n\tlocation: {},\n\tgoTo: () => {},\n\tgoBack: () => {},\n\tgoToParent: () => {},\n\taddScreen: () => {},\n\tremoveScreen: () => {},\n\tparams: {},\n};\nexport const NavigatorContext = createContext( initialContextValue );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAa,QAAQ,oBAAoB;;AAElD;AACA;AACA;;AAGA,MAAMC,mBAAyC,GAAG;EACjDC,QAAQ,EAAE,CAAC,CAAC;EACZC,IAAI,EAAEA,CAAA,KAAM,CAAC,CAAC;EACdC,MAAM,EAAEA,CAAA,KAAM,CAAC,CAAC;EAChBC,UAAU,EAAEA,CAAA,KAAM,CAAC,CAAC;EACpBC,SAAS,EAAEA,CAAA,KAAM,CAAC,CAAC;EACnBC,YAAY,EAAEA,CAAA,KAAM,CAAC,CAAC;EACtBC,MAAM,EAAE,CAAC;AACV,CAAC;AACD,OAAO,MAAMC,gBAAgB,GAAGT,aAAa,CAAEC,mBAAoB,CAAC"}

View File

@@ -0,0 +1,7 @@
export { NavigatorProvider } from './navigator-provider';
export { NavigatorScreen } from './navigator-screen';
export { NavigatorButton } from './navigator-button';
export { NavigatorBackButton } from './navigator-back-button';
export { NavigatorToParentButton } from './navigator-to-parent-button';
export { default as useNavigator } from './use-navigator';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["NavigatorProvider","NavigatorScreen","NavigatorButton","NavigatorBackButton","NavigatorToParentButton","default","useNavigator"],"sources":["@wordpress/components/src/navigator/index.ts"],"sourcesContent":["export { NavigatorProvider } from './navigator-provider';\nexport { NavigatorScreen } from './navigator-screen';\nexport { NavigatorButton } from './navigator-button';\nexport { NavigatorBackButton } from './navigator-back-button';\nexport { NavigatorToParentButton } from './navigator-to-parent-button';\nexport { default as useNavigator } from './use-navigator';\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,sBAAsB;AACxD,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,uBAAuB,QAAQ,8BAA8B;AACtE,SAASC,OAAO,IAAIC,YAAY,QAAQ,iBAAiB"}

View File

@@ -0,0 +1,57 @@
import { createElement } from "react";
/**
* External dependencies
*/
/**
* Internal dependencies
*/
import { contextConnect } from '../../context';
import { View } from '../../view';
import { useNavigatorBackButton } from './hook';
function UnconnectedNavigatorBackButton(props, forwardedRef) {
const navigatorBackButtonProps = useNavigatorBackButton(props);
return createElement(View, {
ref: forwardedRef,
...navigatorBackButtonProps
});
}
/**
* The `NavigatorBackButton` component can be used to navigate to a screen and
* should be used in combination with the `NavigatorProvider`, the
* `NavigatorScreen` and the `NavigatorButton` components (or the `useNavigator`
* hook).
*
* @example
* ```jsx
* import {
* __experimentalNavigatorProvider as NavigatorProvider,
* __experimentalNavigatorScreen as NavigatorScreen,
* __experimentalNavigatorButton as NavigatorButton,
* __experimentalNavigatorBackButton as NavigatorBackButton,
* } from '@wordpress/components';
*
* const MyNavigation = () => (
* <NavigatorProvider initialPath="/">
* <NavigatorScreen path="/">
* <p>This is the home screen.</p>
* <NavigatorButton path="/child">
* Navigate to child screen.
* </NavigatorButton>
* </NavigatorScreen>
*
* <NavigatorScreen path="/child">
* <p>This is the child screen.</p>
* <NavigatorBackButton>
* Go back
* </NavigatorBackButton>
* </NavigatorScreen>
* </NavigatorProvider>
* );
* ```
*/
export const NavigatorBackButton = contextConnect(UnconnectedNavigatorBackButton, 'NavigatorBackButton');
export default NavigatorBackButton;
//# sourceMappingURL=component.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["contextConnect","View","useNavigatorBackButton","UnconnectedNavigatorBackButton","props","forwardedRef","navigatorBackButtonProps","createElement","ref","NavigatorBackButton"],"sources":["@wordpress/components/src/navigator/navigator-back-button/component.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../../context';\nimport { contextConnect } from '../../context';\nimport { View } from '../../view';\nimport { useNavigatorBackButton } from './hook';\nimport type { NavigatorBackButtonProps } from '../types';\n\nfunction UnconnectedNavigatorBackButton(\n\tprops: WordPressComponentProps< NavigatorBackButtonProps, 'button' >,\n\tforwardedRef: ForwardedRef< any >\n) {\n\tconst navigatorBackButtonProps = useNavigatorBackButton( props );\n\n\treturn <View ref={ forwardedRef } { ...navigatorBackButtonProps } />;\n}\n\n/**\n * The `NavigatorBackButton` component can be used to navigate to a screen and\n * should be used in combination with the `NavigatorProvider`, the\n * `NavigatorScreen` and the `NavigatorButton` components (or the `useNavigator`\n * hook).\n *\n * @example\n * ```jsx\n * import {\n * __experimentalNavigatorProvider as NavigatorProvider,\n * __experimentalNavigatorScreen as NavigatorScreen,\n * __experimentalNavigatorButton as NavigatorButton,\n * __experimentalNavigatorBackButton as NavigatorBackButton,\n * } from '@wordpress/components';\n *\n * const MyNavigation = () => (\n * <NavigatorProvider initialPath=\"/\">\n * <NavigatorScreen path=\"/\">\n * <p>This is the home screen.</p>\n * <NavigatorButton path=\"/child\">\n * Navigate to child screen.\n * </NavigatorButton>\n * </NavigatorScreen>\n *\n * <NavigatorScreen path=\"/child\">\n * <p>This is the child screen.</p>\n * <NavigatorBackButton>\n * Go back\n * </NavigatorBackButton>\n * </NavigatorScreen>\n * </NavigatorProvider>\n * );\n * ```\n */\nexport const NavigatorBackButton = contextConnect(\n\tUnconnectedNavigatorBackButton,\n\t'NavigatorBackButton'\n);\n\nexport default NavigatorBackButton;\n"],"mappings":";AAAA;AACA;AACA;;AAGA;AACA;AACA;;AAEA,SAASA,cAAc,QAAQ,eAAe;AAC9C,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,sBAAsB,QAAQ,QAAQ;AAG/C,SAASC,8BAA8BA,CACtCC,KAAoE,EACpEC,YAAiC,EAChC;EACD,MAAMC,wBAAwB,GAAGJ,sBAAsB,CAAEE,KAAM,CAAC;EAEhE,OAAOG,aAAA,CAACN,IAAI;IAACO,GAAG,EAAGH,YAAc;IAAA,GAAMC;EAAwB,CAAI,CAAC;AACrE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,mBAAmB,GAAGT,cAAc,CAChDG,8BAA8B,EAC9B,qBACD,CAAC;AAED,eAAeM,mBAAmB"}

View File

@@ -0,0 +1,39 @@
/**
* WordPress dependencies
*/
import { useCallback } from '@wordpress/element';
/**
* Internal dependencies
*/
import { useContextSystem } from '../../context';
import Button from '../../button';
import useNavigator from '../use-navigator';
export function useNavigatorBackButton(props) {
const {
onClick,
as = Button,
goToParent: goToParentProp = false,
...otherProps
} = useContextSystem(props, 'NavigatorBackButton');
const {
goBack,
goToParent
} = useNavigator();
const handleClick = useCallback(e => {
e.preventDefault();
if (goToParentProp) {
goToParent();
} else {
goBack();
}
onClick?.(e);
}, [goToParentProp, goToParent, goBack, onClick]);
return {
as,
onClick: handleClick,
...otherProps
};
}
//# sourceMappingURL=hook.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["useCallback","useContextSystem","Button","useNavigator","useNavigatorBackButton","props","onClick","as","goToParent","goToParentProp","otherProps","goBack","handleClick","e","preventDefault"],"sources":["@wordpress/components/src/navigator/navigator-back-button/hook.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../../context';\nimport { useContextSystem } from '../../context';\nimport Button from '../../button';\nimport useNavigator from '../use-navigator';\nimport type { NavigatorBackButtonHookProps } from '../types';\n\nexport function useNavigatorBackButton(\n\tprops: WordPressComponentProps< NavigatorBackButtonHookProps, 'button' >\n) {\n\tconst {\n\t\tonClick,\n\t\tas = Button,\n\t\tgoToParent: goToParentProp = false,\n\t\t...otherProps\n\t} = useContextSystem( props, 'NavigatorBackButton' );\n\n\tconst { goBack, goToParent } = useNavigator();\n\tconst handleClick: React.MouseEventHandler< HTMLButtonElement > =\n\t\tuseCallback(\n\t\t\t( e ) => {\n\t\t\t\te.preventDefault();\n\t\t\t\tif ( goToParentProp ) {\n\t\t\t\t\tgoToParent();\n\t\t\t\t} else {\n\t\t\t\t\tgoBack();\n\t\t\t\t}\n\t\t\t\tonClick?.( e );\n\t\t\t},\n\t\t\t[ goToParentProp, goToParent, goBack, onClick ]\n\t\t);\n\n\treturn {\n\t\tas,\n\t\tonClick: handleClick,\n\t\t...otherProps,\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,oBAAoB;;AAEhD;AACA;AACA;;AAEA,SAASC,gBAAgB,QAAQ,eAAe;AAChD,OAAOC,MAAM,MAAM,cAAc;AACjC,OAAOC,YAAY,MAAM,kBAAkB;AAG3C,OAAO,SAASC,sBAAsBA,CACrCC,KAAwE,EACvE;EACD,MAAM;IACLC,OAAO;IACPC,EAAE,GAAGL,MAAM;IACXM,UAAU,EAAEC,cAAc,GAAG,KAAK;IAClC,GAAGC;EACJ,CAAC,GAAGT,gBAAgB,CAAEI,KAAK,EAAE,qBAAsB,CAAC;EAEpD,MAAM;IAAEM,MAAM;IAAEH;EAAW,CAAC,GAAGL,YAAY,CAAC,CAAC;EAC7C,MAAMS,WAAyD,GAC9DZ,WAAW,CACRa,CAAC,IAAM;IACRA,CAAC,CAACC,cAAc,CAAC,CAAC;IAClB,IAAKL,cAAc,EAAG;MACrBD,UAAU,CAAC,CAAC;IACb,CAAC,MAAM;MACNG,MAAM,CAAC,CAAC;IACT;IACAL,OAAO,GAAIO,CAAE,CAAC;EACf,CAAC,EACD,CAAEJ,cAAc,EAAED,UAAU,EAAEG,MAAM,EAAEL,OAAO,CAC9C,CAAC;EAEF,OAAO;IACNC,EAAE;IACFD,OAAO,EAAEM,WAAW;IACpB,GAAGF;EACJ,CAAC;AACF"}

View File

@@ -0,0 +1,2 @@
export { default as NavigatorBackButton } from './component';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["default","NavigatorBackButton"],"sources":["@wordpress/components/src/navigator/navigator-back-button/index.ts"],"sourcesContent":["export { default as NavigatorBackButton } from './component';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,mBAAmB,QAAQ,aAAa"}

View File

@@ -0,0 +1,56 @@
import { createElement } from "react";
/**
* External dependencies
*/
/**
* Internal dependencies
*/
import { contextConnect } from '../../context';
import { View } from '../../view';
import { useNavigatorButton } from './hook';
function UnconnectedNavigatorButton(props, forwardedRef) {
const navigatorButtonProps = useNavigatorButton(props);
return createElement(View, {
ref: forwardedRef,
...navigatorButtonProps
});
}
/**
* The `NavigatorButton` component can be used to navigate to a screen and should
* be used in combination with the `NavigatorProvider`, the `NavigatorScreen`
* and the `NavigatorBackButton` components (or the `useNavigator` hook).
*
* @example
* ```jsx
* import {
* __experimentalNavigatorProvider as NavigatorProvider,
* __experimentalNavigatorScreen as NavigatorScreen,
* __experimentalNavigatorButton as NavigatorButton,
* __experimentalNavigatorBackButton as NavigatorBackButton,
* } from '@wordpress/components';
*
* const MyNavigation = () => (
* <NavigatorProvider initialPath="/">
* <NavigatorScreen path="/">
* <p>This is the home screen.</p>
* <NavigatorButton path="/child">
* Navigate to child screen.
* </NavigatorButton>
* </NavigatorScreen>
*
* <NavigatorScreen path="/child">
* <p>This is the child screen.</p>
* <NavigatorBackButton>
* Go back
* </NavigatorBackButton>
* </NavigatorScreen>
* </NavigatorProvider>
* );
* ```
*/
export const NavigatorButton = contextConnect(UnconnectedNavigatorButton, 'NavigatorButton');
export default NavigatorButton;
//# sourceMappingURL=component.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["contextConnect","View","useNavigatorButton","UnconnectedNavigatorButton","props","forwardedRef","navigatorButtonProps","createElement","ref","NavigatorButton"],"sources":["@wordpress/components/src/navigator/navigator-button/component.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../../context';\nimport { contextConnect } from '../../context';\nimport { View } from '../../view';\nimport { useNavigatorButton } from './hook';\nimport type { NavigatorButtonProps } from '../types';\n\nfunction UnconnectedNavigatorButton(\n\tprops: WordPressComponentProps< NavigatorButtonProps, 'button' >,\n\tforwardedRef: ForwardedRef< any >\n) {\n\tconst navigatorButtonProps = useNavigatorButton( props );\n\n\treturn <View ref={ forwardedRef } { ...navigatorButtonProps } />;\n}\n\n/**\n * The `NavigatorButton` component can be used to navigate to a screen and should\n * be used in combination with the `NavigatorProvider`, the `NavigatorScreen`\n * and the `NavigatorBackButton` components (or the `useNavigator` hook).\n *\n * @example\n * ```jsx\n * import {\n * __experimentalNavigatorProvider as NavigatorProvider,\n * __experimentalNavigatorScreen as NavigatorScreen,\n * __experimentalNavigatorButton as NavigatorButton,\n * __experimentalNavigatorBackButton as NavigatorBackButton,\n * } from '@wordpress/components';\n *\n * const MyNavigation = () => (\n * <NavigatorProvider initialPath=\"/\">\n * <NavigatorScreen path=\"/\">\n * <p>This is the home screen.</p>\n * <NavigatorButton path=\"/child\">\n * Navigate to child screen.\n * </NavigatorButton>\n * </NavigatorScreen>\n *\n * <NavigatorScreen path=\"/child\">\n * <p>This is the child screen.</p>\n * <NavigatorBackButton>\n * Go back\n * </NavigatorBackButton>\n * </NavigatorScreen>\n * </NavigatorProvider>\n * );\n * ```\n */\nexport const NavigatorButton = contextConnect(\n\tUnconnectedNavigatorButton,\n\t'NavigatorButton'\n);\n\nexport default NavigatorButton;\n"],"mappings":";AAAA;AACA;AACA;;AAGA;AACA;AACA;;AAEA,SAASA,cAAc,QAAQ,eAAe;AAC9C,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,kBAAkB,QAAQ,QAAQ;AAG3C,SAASC,0BAA0BA,CAClCC,KAAgE,EAChEC,YAAiC,EAChC;EACD,MAAMC,oBAAoB,GAAGJ,kBAAkB,CAAEE,KAAM,CAAC;EAExD,OAAOG,aAAA,CAACN,IAAI;IAACO,GAAG,EAAGH,YAAc;IAAA,GAAMC;EAAoB,CAAI,CAAC;AACjE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,eAAe,GAAGT,cAAc,CAC5CG,0BAA0B,EAC1B,iBACD,CAAC;AAED,eAAeM,eAAe"}

View File

@@ -0,0 +1,41 @@
/**
* WordPress dependencies
*/
import { useCallback } from '@wordpress/element';
import { escapeAttribute } from '@wordpress/escape-html';
/**
* Internal dependencies
*/
import { useContextSystem } from '../../context';
import Button from '../../button';
import useNavigator from '../use-navigator';
const cssSelectorForAttribute = (attrName, attrValue) => `[${attrName}="${attrValue}"]`;
export function useNavigatorButton(props) {
const {
path,
onClick,
as = Button,
attributeName = 'id',
...otherProps
} = useContextSystem(props, 'NavigatorButton');
const escapedPath = escapeAttribute(path);
const {
goTo
} = useNavigator();
const handleClick = useCallback(e => {
e.preventDefault();
goTo(escapedPath, {
focusTargetSelector: cssSelectorForAttribute(attributeName, escapedPath)
});
onClick?.(e);
}, [goTo, onClick, attributeName, escapedPath]);
return {
as,
onClick: handleClick,
...otherProps,
[attributeName]: escapedPath
};
}
//# sourceMappingURL=hook.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["useCallback","escapeAttribute","useContextSystem","Button","useNavigator","cssSelectorForAttribute","attrName","attrValue","useNavigatorButton","props","path","onClick","as","attributeName","otherProps","escapedPath","goTo","handleClick","e","preventDefault","focusTargetSelector"],"sources":["@wordpress/components/src/navigator/navigator-button/hook.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { escapeAttribute } from '@wordpress/escape-html';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../../context';\nimport { useContextSystem } from '../../context';\nimport Button from '../../button';\nimport useNavigator from '../use-navigator';\nimport type { NavigatorButtonProps } from '../types';\n\nconst cssSelectorForAttribute = ( attrName: string, attrValue: string ) =>\n\t`[${ attrName }=\"${ attrValue }\"]`;\n\nexport function useNavigatorButton(\n\tprops: WordPressComponentProps< NavigatorButtonProps, 'button' >\n) {\n\tconst {\n\t\tpath,\n\t\tonClick,\n\t\tas = Button,\n\t\tattributeName = 'id',\n\t\t...otherProps\n\t} = useContextSystem( props, 'NavigatorButton' );\n\n\tconst escapedPath = escapeAttribute( path );\n\n\tconst { goTo } = useNavigator();\n\tconst handleClick: React.MouseEventHandler< HTMLButtonElement > =\n\t\tuseCallback(\n\t\t\t( e ) => {\n\t\t\t\te.preventDefault();\n\t\t\t\tgoTo( escapedPath, {\n\t\t\t\t\tfocusTargetSelector: cssSelectorForAttribute(\n\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\tescapedPath\n\t\t\t\t\t),\n\t\t\t\t} );\n\t\t\t\tonClick?.( e );\n\t\t\t},\n\t\t\t[ goTo, onClick, attributeName, escapedPath ]\n\t\t);\n\n\treturn {\n\t\tas,\n\t\tonClick: handleClick,\n\t\t...otherProps,\n\t\t[ attributeName ]: escapedPath,\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,oBAAoB;AAChD,SAASC,eAAe,QAAQ,wBAAwB;;AAExD;AACA;AACA;;AAEA,SAASC,gBAAgB,QAAQ,eAAe;AAChD,OAAOC,MAAM,MAAM,cAAc;AACjC,OAAOC,YAAY,MAAM,kBAAkB;AAG3C,MAAMC,uBAAuB,GAAGA,CAAEC,QAAgB,EAAEC,SAAiB,KACnE,IAAID,QAAU,KAAKC,SAAW,IAAG;AAEnC,OAAO,SAASC,kBAAkBA,CACjCC,KAAgE,EAC/D;EACD,MAAM;IACLC,IAAI;IACJC,OAAO;IACPC,EAAE,GAAGT,MAAM;IACXU,aAAa,GAAG,IAAI;IACpB,GAAGC;EACJ,CAAC,GAAGZ,gBAAgB,CAAEO,KAAK,EAAE,iBAAkB,CAAC;EAEhD,MAAMM,WAAW,GAAGd,eAAe,CAAES,IAAK,CAAC;EAE3C,MAAM;IAAEM;EAAK,CAAC,GAAGZ,YAAY,CAAC,CAAC;EAC/B,MAAMa,WAAyD,GAC9DjB,WAAW,CACRkB,CAAC,IAAM;IACRA,CAAC,CAACC,cAAc,CAAC,CAAC;IAClBH,IAAI,CAAED,WAAW,EAAE;MAClBK,mBAAmB,EAAEf,uBAAuB,CAC3CQ,aAAa,EACbE,WACD;IACD,CAAE,CAAC;IACHJ,OAAO,GAAIO,CAAE,CAAC;EACf,CAAC,EACD,CAAEF,IAAI,EAAEL,OAAO,EAAEE,aAAa,EAAEE,WAAW,CAC5C,CAAC;EAEF,OAAO;IACNH,EAAE;IACFD,OAAO,EAAEM,WAAW;IACpB,GAAGH,UAAU;IACb,CAAED,aAAa,GAAIE;EACpB,CAAC;AACF"}

View File

@@ -0,0 +1,2 @@
export { default as NavigatorButton } from './component';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["default","NavigatorButton"],"sources":["@wordpress/components/src/navigator/navigator-button/index.ts"],"sourcesContent":["export { default as NavigatorButton } from './component';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,eAAe,QAAQ,aAAa"}

View File

@@ -0,0 +1,203 @@
import { createElement } from "react";
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
import { useMemo, useState, useCallback, useReducer, useRef, useEffect } from '@wordpress/element';
import isShallowEqual from '@wordpress/is-shallow-equal';
/**
* Internal dependencies
*/
import { contextConnect, useContextSystem } from '../../context';
import { useCx } from '../../utils/hooks/use-cx';
import { patternMatch, findParent } from '../utils/router';
import { View } from '../../view';
import { NavigatorContext } from '../context';
import * as styles from '../styles';
const MAX_HISTORY_LENGTH = 50;
function screensReducer(state = [], action) {
switch (action.type) {
case 'add':
return [...state, action.screen];
case 'remove':
return state.filter(s => s.id !== action.screen.id);
}
return state;
}
function UnconnectedNavigatorProvider(props, forwardedRef) {
const {
initialPath,
children,
className,
...otherProps
} = useContextSystem(props, 'NavigatorProvider');
const [locationHistory, setLocationHistory] = useState([{
path: initialPath
}]);
const currentLocationHistory = useRef([]);
const [screens, dispatch] = useReducer(screensReducer, []);
const currentScreens = useRef([]);
useEffect(() => {
currentScreens.current = screens;
}, [screens]);
useEffect(() => {
currentLocationHistory.current = locationHistory;
}, [locationHistory]);
const currentMatch = useRef();
const matchedPath = useMemo(() => {
let currentPath;
if (locationHistory.length === 0 || (currentPath = locationHistory[locationHistory.length - 1].path) === undefined) {
currentMatch.current = undefined;
return undefined;
}
const resolvePath = path => {
const newMatch = patternMatch(path, screens);
// If the new match is the same as the current match,
// return the previous one for performance reasons.
if (currentMatch.current && newMatch && isShallowEqual(newMatch.params, currentMatch.current.params) && newMatch.id === currentMatch.current.id) {
return currentMatch.current;
}
return newMatch;
};
const newMatch = resolvePath(currentPath);
currentMatch.current = newMatch;
return newMatch;
}, [screens, locationHistory]);
const addScreen = useCallback(screen => dispatch({
type: 'add',
screen
}), []);
const removeScreen = useCallback(screen => dispatch({
type: 'remove',
screen
}), []);
const goBack = useCallback(() => {
setLocationHistory(prevLocationHistory => {
if (prevLocationHistory.length <= 1) {
return prevLocationHistory;
}
return [...prevLocationHistory.slice(0, -2), {
...prevLocationHistory[prevLocationHistory.length - 2],
isBack: true,
hasRestoredFocus: false
}];
});
}, []);
const goTo = useCallback((path, options = {}) => {
const {
focusTargetSelector,
isBack = false,
skipFocus = false,
replace = false,
...restOptions
} = options;
const isNavigatingToPreviousPath = isBack && currentLocationHistory.current.length > 1 && currentLocationHistory.current[currentLocationHistory.current.length - 2].path === path;
if (isNavigatingToPreviousPath) {
goBack();
return;
}
setLocationHistory(prevLocationHistory => {
const newLocation = {
...restOptions,
path,
isBack,
hasRestoredFocus: false,
skipFocus
};
if (prevLocationHistory.length === 0) {
return replace ? [] : [newLocation];
}
const newLocationHistory = prevLocationHistory.slice(prevLocationHistory.length > MAX_HISTORY_LENGTH - 1 ? 1 : 0, -1);
if (!replace) {
newLocationHistory.push(
// Assign `focusTargetSelector` to the previous location in history
// (the one we just navigated from).
{
...prevLocationHistory[prevLocationHistory.length - 1],
focusTargetSelector
});
}
newLocationHistory.push(newLocation);
return newLocationHistory;
});
}, [goBack]);
const goToParent = useCallback((options = {}) => {
const currentPath = currentLocationHistory.current[currentLocationHistory.current.length - 1].path;
if (currentPath === undefined) {
return;
}
const parentPath = findParent(currentPath, currentScreens.current);
if (parentPath === undefined) {
return;
}
goTo(parentPath, {
...options,
isBack: true
});
}, [goTo]);
const navigatorContextValue = useMemo(() => ({
location: {
...locationHistory[locationHistory.length - 1],
isInitial: locationHistory.length === 1
},
params: matchedPath ? matchedPath.params : {},
match: matchedPath ? matchedPath.id : undefined,
goTo,
goBack,
goToParent,
addScreen,
removeScreen
}), [locationHistory, matchedPath, goTo, goBack, goToParent, addScreen, removeScreen]);
const cx = useCx();
const classes = useMemo(() => cx(styles.navigatorProviderWrapper, className), [className, cx]);
return createElement(View, {
ref: forwardedRef,
className: classes,
...otherProps
}, createElement(NavigatorContext.Provider, {
value: navigatorContextValue
}, children));
}
/**
* The `NavigatorProvider` component allows rendering nested views/panels/menus
* (via the `NavigatorScreen` component and navigate between these different
* view (via the `NavigatorButton` and `NavigatorBackButton` components or the
* `useNavigator` hook).
*
* ```jsx
* import {
* __experimentalNavigatorProvider as NavigatorProvider,
* __experimentalNavigatorScreen as NavigatorScreen,
* __experimentalNavigatorButton as NavigatorButton,
* __experimentalNavigatorBackButton as NavigatorBackButton,
* } from '@wordpress/components';
*
* const MyNavigation = () => (
* <NavigatorProvider initialPath="/">
* <NavigatorScreen path="/">
* <p>This is the home screen.</p>
* <NavigatorButton path="/child">
* Navigate to child screen.
* </NavigatorButton>
* </NavigatorScreen>
*
* <NavigatorScreen path="/child">
* <p>This is the child screen.</p>
* <NavigatorBackButton>
* Go back
* </NavigatorBackButton>
* </NavigatorScreen>
* </NavigatorProvider>
* );
* ```
*/
export const NavigatorProvider = contextConnect(UnconnectedNavigatorProvider, 'NavigatorProvider');
export default NavigatorProvider;
//# sourceMappingURL=component.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
export { default as NavigatorProvider } from './component';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["default","NavigatorProvider"],"sources":["@wordpress/components/src/navigator/navigator-provider/index.ts"],"sourcesContent":["export { default as NavigatorProvider } from './component';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,iBAAiB,QAAQ,aAAa"}

View File

@@ -0,0 +1,144 @@
import { createElement } from "react";
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
import { focus } from '@wordpress/dom';
import { useContext, useEffect, useMemo, useRef, useId } from '@wordpress/element';
import { useMergeRefs } from '@wordpress/compose';
import { isRTL as isRTLFn } from '@wordpress/i18n';
import { escapeAttribute } from '@wordpress/escape-html';
/**
* Internal dependencies
*/
import { contextConnect, useContextSystem } from '../../context';
import { useCx } from '../../utils/hooks/use-cx';
import { View } from '../../view';
import { NavigatorContext } from '../context';
import * as styles from '../styles';
function UnconnectedNavigatorScreen(props, forwardedRef) {
const screenId = useId();
const {
children,
className,
path,
...otherProps
} = useContextSystem(props, 'NavigatorScreen');
const {
location,
match,
addScreen,
removeScreen
} = useContext(NavigatorContext);
const isMatch = match === screenId;
const wrapperRef = useRef(null);
useEffect(() => {
const screen = {
id: screenId,
path: escapeAttribute(path)
};
addScreen(screen);
return () => removeScreen(screen);
}, [screenId, path, addScreen, removeScreen]);
const isRTL = isRTLFn();
const {
isInitial,
isBack
} = location;
const cx = useCx();
const classes = useMemo(() => cx(styles.navigatorScreen({
isInitial,
isBack,
isRTL
}), className), [className, cx, isInitial, isBack, isRTL]);
const locationRef = useRef(location);
useEffect(() => {
locationRef.current = location;
}, [location]);
// Focus restoration
const isInitialLocation = location.isInitial && !location.isBack;
useEffect(() => {
// Only attempt to restore focus:
// - if the current location is not the initial one (to avoid moving focus on page load)
// - when the screen becomes visible
// - if the wrapper ref has been assigned
// - if focus hasn't already been restored for the current location
// - if the `skipFocus` option is not set to `true`. This is useful when we trigger the navigation outside of NavigatorScreen.
if (isInitialLocation || !isMatch || !wrapperRef.current || locationRef.current.hasRestoredFocus || location.skipFocus) {
return;
}
const activeElement = wrapperRef.current.ownerDocument.activeElement;
// If an element is already focused within the wrapper do not focus the
// element. This prevents inputs or buttons from losing focus unnecessarily.
if (wrapperRef.current.contains(activeElement)) {
return;
}
let elementToFocus = null;
// When navigating back, if a selector is provided, use it to look for the
// target element (assumed to be a node inside the current NavigatorScreen)
if (location.isBack && location?.focusTargetSelector) {
elementToFocus = wrapperRef.current.querySelector(location.focusTargetSelector);
}
// If the previous query didn't run or find any element to focus, fallback
// to the first tabbable element in the screen (or the screen itself).
if (!elementToFocus) {
const firstTabbable = focus.tabbable.find(wrapperRef.current)[0];
elementToFocus = firstTabbable !== null && firstTabbable !== void 0 ? firstTabbable : wrapperRef.current;
}
locationRef.current.hasRestoredFocus = true;
elementToFocus.focus();
}, [isInitialLocation, isMatch, location.isBack, location.focusTargetSelector, location.skipFocus]);
const mergedWrapperRef = useMergeRefs([forwardedRef, wrapperRef]);
return isMatch ? createElement(View, {
ref: mergedWrapperRef,
className: classes,
...otherProps
}, children) : null;
}
/**
* The `NavigatorScreen` component represents a single view/screen/panel and
* should be used in combination with the `NavigatorProvider`, the
* `NavigatorButton` and the `NavigatorBackButton` components (or the `useNavigator`
* hook).
*
* @example
* ```jsx
* import {
* __experimentalNavigatorProvider as NavigatorProvider,
* __experimentalNavigatorScreen as NavigatorScreen,
* __experimentalNavigatorButton as NavigatorButton,
* __experimentalNavigatorBackButton as NavigatorBackButton,
* } from '@wordpress/components';
*
* const MyNavigation = () => (
* <NavigatorProvider initialPath="/">
* <NavigatorScreen path="/">
* <p>This is the home screen.</p>
* <NavigatorButton path="/child">
* Navigate to child screen.
* </NavigatorButton>
* </NavigatorScreen>
*
* <NavigatorScreen path="/child">
* <p>This is the child screen.</p>
* <NavigatorBackButton>
* Go back
* </NavigatorBackButton>
* </NavigatorScreen>
* </NavigatorProvider>
* );
* ```
*/
export const NavigatorScreen = contextConnect(UnconnectedNavigatorScreen, 'NavigatorScreen');
export default NavigatorScreen;
//# sourceMappingURL=component.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
export { default as NavigatorScreen } from './component';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["default","NavigatorScreen"],"sources":["@wordpress/components/src/navigator/navigator-screen/index.ts"],"sourcesContent":["export { default as NavigatorScreen } from './component';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,eAAe,QAAQ,aAAa"}

View File

@@ -0,0 +1,60 @@
import { createElement } from "react";
/**
* External dependencies
*/
/**
* Internal dependencies
*/
import { contextConnect } from '../../context';
import { View } from '../../view';
import { useNavigatorBackButton } from '../navigator-back-button/hook';
function UnconnectedNavigatorToParentButton(props, forwardedRef) {
const navigatorToParentButtonProps = useNavigatorBackButton({
...props,
goToParent: true
});
return createElement(View, {
ref: forwardedRef,
...navigatorToParentButtonProps
});
}
/*
* The `NavigatorToParentButton` component can be used to navigate to a screen and
* should be used in combination with the `NavigatorProvider`, the
* `NavigatorScreen` and the `NavigatorButton` components (or the `useNavigator`
* hook).
*
* @example
* ```jsx
* import {
* __experimentalNavigatorProvider as NavigatorProvider,
* __experimentalNavigatorScreen as NavigatorScreen,
* __experimentalNavigatorButton as NavigatorButton,
* __experimentalNavigatorToParentButton as NavigatorToParentButton,
* } from '@wordpress/components';
*
* const MyNavigation = () => (
* <NavigatorProvider initialPath="/">
* <NavigatorScreen path="/">
* <p>This is the home screen.</p>
* <NavigatorButton path="/child">
* Navigate to child screen.
* </NavigatorButton>
* </NavigatorScreen>
*
* <NavigatorScreen path="/child">
* <p>This is the child screen.</p>
* <NavigatorToParentButton>
* Go to parent
* </NavigatorToParentButton>
* </NavigatorScreen>
* </NavigatorProvider>
* );
* ```
*/
export const NavigatorToParentButton = contextConnect(UnconnectedNavigatorToParentButton, 'NavigatorToParentButton');
export default NavigatorToParentButton;
//# sourceMappingURL=component.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["contextConnect","View","useNavigatorBackButton","UnconnectedNavigatorToParentButton","props","forwardedRef","navigatorToParentButtonProps","goToParent","createElement","ref","NavigatorToParentButton"],"sources":["@wordpress/components/src/navigator/navigator-to-parent-button/component.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../../context';\nimport { contextConnect } from '../../context';\nimport { View } from '../../view';\nimport { useNavigatorBackButton } from '../navigator-back-button/hook';\nimport type { NavigatorToParentButtonProps } from '../types';\n\nfunction UnconnectedNavigatorToParentButton(\n\tprops: WordPressComponentProps< NavigatorToParentButtonProps, 'button' >,\n\tforwardedRef: ForwardedRef< any >\n) {\n\tconst navigatorToParentButtonProps = useNavigatorBackButton( {\n\t\t...props,\n\t\tgoToParent: true,\n\t} );\n\n\treturn <View ref={ forwardedRef } { ...navigatorToParentButtonProps } />;\n}\n\n/*\n * The `NavigatorToParentButton` component can be used to navigate to a screen and\n * should be used in combination with the `NavigatorProvider`, the\n * `NavigatorScreen` and the `NavigatorButton` components (or the `useNavigator`\n * hook).\n *\n * @example\n * ```jsx\n * import {\n * __experimentalNavigatorProvider as NavigatorProvider,\n * __experimentalNavigatorScreen as NavigatorScreen,\n * __experimentalNavigatorButton as NavigatorButton,\n * __experimentalNavigatorToParentButton as NavigatorToParentButton,\n * } from '@wordpress/components';\n *\n * const MyNavigation = () => (\n * <NavigatorProvider initialPath=\"/\">\n * <NavigatorScreen path=\"/\">\n * <p>This is the home screen.</p>\n * <NavigatorButton path=\"/child\">\n * Navigate to child screen.\n * </NavigatorButton>\n * </NavigatorScreen>\n *\n * <NavigatorScreen path=\"/child\">\n * <p>This is the child screen.</p>\n * <NavigatorToParentButton>\n * Go to parent\n * </NavigatorToParentButton>\n * </NavigatorScreen>\n * </NavigatorProvider>\n * );\n * ```\n */\nexport const NavigatorToParentButton = contextConnect(\n\tUnconnectedNavigatorToParentButton,\n\t'NavigatorToParentButton'\n);\n\nexport default NavigatorToParentButton;\n"],"mappings":";AAAA;AACA;AACA;;AAGA;AACA;AACA;;AAEA,SAASA,cAAc,QAAQ,eAAe;AAC9C,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,sBAAsB,QAAQ,+BAA+B;AAGtE,SAASC,kCAAkCA,CAC1CC,KAAwE,EACxEC,YAAiC,EAChC;EACD,MAAMC,4BAA4B,GAAGJ,sBAAsB,CAAE;IAC5D,GAAGE,KAAK;IACRG,UAAU,EAAE;EACb,CAAE,CAAC;EAEH,OAAOC,aAAA,CAACP,IAAI;IAACQ,GAAG,EAAGJ,YAAc;IAAA,GAAMC;EAA4B,CAAI,CAAC;AACzE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,uBAAuB,GAAGV,cAAc,CACpDG,kCAAkC,EAClC,yBACD,CAAC;AAED,eAAeO,uBAAuB"}

View File

@@ -0,0 +1,2 @@
export { default as NavigatorToParentButton } from './component';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["default","NavigatorToParentButton"],"sources":["@wordpress/components/src/navigator/navigator-to-parent-button/index.ts"],"sourcesContent":["export { default as NavigatorToParentButton } from './component';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,uBAAuB,QAAQ,aAAa"}

View File

@@ -0,0 +1,47 @@
function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
/**
* External dependencies
*/
import { css, keyframes } from '@emotion/react';
export const navigatorProviderWrapper = process.env.NODE_ENV === "production" ? {
name: "xpkswc",
styles: "overflow-x:hidden;contain:content"
} : {
name: "1qbsmur-navigatorProviderWrapper",
styles: "overflow-x:hidden;contain:content;label:navigatorProviderWrapper;",
map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkB3b3JkcHJlc3MvY29tcG9uZW50cy9zcmMvbmF2aWdhdG9yL3N0eWxlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQ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gY3NzYFxuXHQvKiBFbnN1cmVzIGhvcml6b250YWwgb3ZlcmZsb3cgaXMgdmlzdWFsbHkgYWNjZXNzaWJsZSAqL1xuXHRvdmVyZmxvdy14OiBhdXRvO1xuXHQvKiBJbiBjYXNlIHRoZSByb290IGhhcyBhIGhlaWdodCwgaXQgc2hvdWxkIG5vdCBiZSBleGNlZWRlZCAqL1xuXHRtYXgtaGVpZ2h0OiAxMDAlO1xuXG5cdCR7IG5hdmlnYXRvclNjcmVlbkFuaW1hdGlvbiggcHJvcHMgKSB9XG5gO1xuIl19 */",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
};
const fadeInFromRight = keyframes({
'0%': {
opacity: 0,
transform: `translateX( 50px )`
},
'100%': {
opacity: 1,
transform: 'none'
}
});
const fadeInFromLeft = keyframes({
'0%': {
opacity: 0,
transform: `translateX( -50px )`
},
'100%': {
opacity: 1,
transform: 'none'
}
});
const navigatorScreenAnimation = ({
isInitial,
isBack,
isRTL
}) => {
if (isInitial && !isBack) {
return;
}
const animationName = isRTL && isBack || !isRTL && !isBack ? fadeInFromRight : fadeInFromLeft;
return /*#__PURE__*/css("animation-duration:0.14s;animation-timing-function:ease-in-out;will-change:transform,opacity;animation-name:", animationName, ";@media ( prefers-reduced-motion ){animation-duration:0s;}" + (process.env.NODE_ENV === "production" ? "" : ";label:navigatorScreenAnimation;"), process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkB3b3JkcHJlc3MvY29tcG9uZW50cy9zcmMvbmF2aWdhdG9yL3N0eWxlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFtRFciLCJmaWxlIjoiQHdvcmRwcmVzcy9jb21wb25lbnRzL3NyYy9uYXZpZ2F0b3Ivc3R5bGVzLnRzIiwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBFeHRlcm5hbCBkZXBlbmRlbmNpZXNcbiA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IGhlaWdodCwgaXQgc2hvdWxkIG5vdCBiZSBleGNlZWRlZCAqL1xuXHRtYXgtaGVpZ2h0OiAxMDAlO1xuXG5cdCR7IG5hdmlnYXRvclNjcmVlbkFuaW1hdGlvbiggcHJvcHMgKSB9XG5gO1xuIl19 */");
};
export const navigatorScreen = props => /*#__PURE__*/css("overflow-x:auto;max-height:100%;", navigatorScreenAnimation(props), ";" + (process.env.NODE_ENV === "production" ? "" : ";label:navigatorScreen;"), process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkB3b3JkcHJlc3MvY29tcG9uZW50cy9zcmMvbmF2aWdhdG9yL3N0eWxlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUErRDhFIiwiZmlsZSI6IkB3b3JkcHJlc3MvY29tcG9uZW50cy9zcmMvbmF2aWdhdG9yL3N0eWxlcy50cyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogRXh0ZXJuYWwgZGVwZW5kZW5jaWVzXG4gKi9cbmltcG9ydCB7IGNzcywga2V5ZnJhbWVzIH0gZnJvbSAnQGVtb3Rpb24vcmVhY3QnO1xuXG5leHBvcnQgY29uc3QgbmF2aWdhdG9yUHJvdmlkZXJXcmFwcGVyID0gY3NzYFxuXHQvKiBQcmV2ZW50cyBob3Jpem9udGFsIG92ZXJmbG93IHdoaWxlIGFuaW1hdGluZyBzY3JlZW4gdHJhbnNpdGlvbnMgKi9cblx0b3ZlcmZsb3cteDogaGlkZGVuO1xuXHQvKiBNYXJrIHRoaXMgc3Vic2VjdGlvbiBvZiB0aGUgRE9NIGFzIGlzb2xhdGVkLCBwcm92aWRpbmcgcGVyZm9ybWFuY2UgYmVuZWZpdHNcblx0ICogYnkgbGltaXRpbmcgY2FsY3VsYXRpb25zIG9mIGxheW91dCwgc3R5bGUgYW5kIHBhaW50IHRvIGEgRE9NIHN1YnRyZWUgcmF0aGVy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2Bcblx0XHRhbmltYXRpb24tZHVyYXRpb246IDAuMTRzO1xuXHRcdGFuaW1hdGlvbi10aW1pbmctZnVuY3Rpb246IGVhc2UtaW4tb3V0O1xuXHRcdHdpbGwtY2hhbmdlOiB0cmFuc2Zvcm0sIG9wYWNpdHk7XG5cdFx0YW5pbWF0aW9uLW5hbWU6ICR7IGFuaW1hdGlvbk5hbWUgfTtcblxuXHRcdEBtZWRpYSAoIHByZWZlcnMtcmVkdWNlZC1tb3Rpb24gKSB7XG5cdFx0XHRhbmltYXRpb24tZHVyYXRpb246IDBzO1xuXHRcdH1cblx0YDtcbn07XG5cbmV4cG9ydCBjb25zdCBuYXZpZ2F0b3JTY3JlZW4gPSAoIHByb3BzOiBOYXZpZ2F0b3JTY3JlZW5BbmltYXRpb25Qcm9wcyApID0+IGNzc2Bcblx0LyogRW5zdXJlcyBob3Jpem9udGFsIG92ZXJmbG93IGlzIHZpc3VhbGx5IGFjY2Vzc2libGUgKi9cblx0b3ZlcmZsb3cteDogYXV0bztcblx0LyogSW4gY2FzZSB0aGUgcm9vdCBoYXMgYSBoZWlnaHQsIGl0IHNob3VsZCBub3QgYmUgZXhjZWVkZWQgKi9cblx0bWF4LWhlaWdodDogMTAwJTtcblxuXHQkeyBuYXZpZ2F0b3JTY3JlZW5BbmltYXRpb24oIHByb3BzICkgfVxuYDtcbiJdfQ== */");
//# sourceMappingURL=styles.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["css","keyframes","navigatorProviderWrapper","process","env","NODE_ENV","name","styles","map","toString","_EMOTION_STRINGIFIED_CSS_ERROR__","fadeInFromRight","opacity","transform","fadeInFromLeft","navigatorScreenAnimation","isInitial","isBack","isRTL","animationName","navigatorScreen","props"],"sources":["@wordpress/components/src/navigator/styles.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport { css, keyframes } from '@emotion/react';\n\nexport const navigatorProviderWrapper = css`\n\t/* Prevents horizontal overflow while animating screen transitions */\n\toverflow-x: hidden;\n\t/* Mark this subsection of the DOM as isolated, providing performance benefits\n\t * by limiting calculations of layout, style and paint to a DOM subtree rather\n\t * than the entire page.\n\t */\n\tcontain: content;\n`;\n\nconst fadeInFromRight = keyframes( {\n\t'0%': {\n\t\topacity: 0,\n\t\ttransform: `translateX( 50px )`,\n\t},\n\t'100%': { opacity: 1, transform: 'none' },\n} );\n\nconst fadeInFromLeft = keyframes( {\n\t'0%': {\n\t\topacity: 0,\n\t\ttransform: `translateX( -50px )`,\n\t},\n\t'100%': { opacity: 1, transform: 'none' },\n} );\n\ntype NavigatorScreenAnimationProps = {\n\tisInitial?: boolean;\n\tisBack?: boolean;\n\tisRTL: boolean;\n};\n\nconst navigatorScreenAnimation = ( {\n\tisInitial,\n\tisBack,\n\tisRTL,\n}: NavigatorScreenAnimationProps ) => {\n\tif ( isInitial && ! isBack ) {\n\t\treturn;\n\t}\n\n\tconst animationName =\n\t\t( isRTL && isBack ) || ( ! isRTL && ! isBack )\n\t\t\t? fadeInFromRight\n\t\t\t: fadeInFromLeft;\n\n\treturn css`\n\t\tanimation-duration: 0.14s;\n\t\tanimation-timing-function: ease-in-out;\n\t\twill-change: transform, opacity;\n\t\tanimation-name: ${ animationName };\n\n\t\t@media ( prefers-reduced-motion ) {\n\t\t\tanimation-duration: 0s;\n\t\t}\n\t`;\n};\n\nexport const navigatorScreen = ( props: NavigatorScreenAnimationProps ) => css`\n\t/* Ensures horizontal overflow is visually accessible */\n\toverflow-x: auto;\n\t/* In case the root has a height, it should not be exceeded */\n\tmax-height: 100%;\n\n\t${ navigatorScreenAnimation( props ) }\n`;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,GAAG,EAAEC,SAAS,QAAQ,gBAAgB;AAE/C,OAAO,MAAMC,wBAAwB,GAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA;EAAAC,IAAA;EAAAC,MAAA;AAAA;EAAAD,IAAA;EAAAC,MAAA;EAAAC,GAAA;EAAAC,QAAA,EAAAC;AAAA,CAQpC;AAED,MAAMC,eAAe,GAAGV,SAAS,CAAE;EAClC,IAAI,EAAE;IACLW,OAAO,EAAE,CAAC;IACVC,SAAS,EAAG;EACb,CAAC;EACD,MAAM,EAAE;IAAED,OAAO,EAAE,CAAC;IAAEC,SAAS,EAAE;EAAO;AACzC,CAAE,CAAC;AAEH,MAAMC,cAAc,GAAGb,SAAS,CAAE;EACjC,IAAI,EAAE;IACLW,OAAO,EAAE,CAAC;IACVC,SAAS,EAAG;EACb,CAAC;EACD,MAAM,EAAE;IAAED,OAAO,EAAE,CAAC;IAAEC,SAAS,EAAE;EAAO;AACzC,CAAE,CAAC;AAQH,MAAME,wBAAwB,GAAGA,CAAE;EAClCC,SAAS;EACTC,MAAM;EACNC;AAC8B,CAAC,KAAM;EACrC,IAAKF,SAAS,IAAI,CAAEC,MAAM,EAAG;IAC5B;EACD;EAEA,MAAME,aAAa,GAChBD,KAAK,IAAID,MAAM,IAAQ,CAAEC,KAAK,IAAI,CAAED,MAAQ,GAC3CN,eAAe,GACfG,cAAc;EAElB,oBAAOd,GAAG,iHAIUmB,aAAa,kEAAAhB,OAAA,CAAAC,GAAA,CAAAC,QAAA,8DAAAF,OAAA,CAAAC,GAAA,CAAAC,QAAA;AAMlC,CAAC;AAED,OAAO,MAAMe,eAAe,GAAKC,KAAoC,iBAAMrB,GAAG,qCAM1Ee,wBAAwB,CAAEM,KAAM,CAAC,SAAAlB,OAAA,CAAAC,GAAA,CAAAC,QAAA,qDAAAF,OAAA,CAAAC,GAAA,CAAAC,QAAA,mnFACpC"}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":[],"sources":["@wordpress/components/src/navigator/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactNode } from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { ButtonAsButtonProps } from '../button/types';\n\nexport type MatchParams = Record< string, string | string[] >;\n\nexport type NavigateOptions = {\n\tfocusTargetSelector?: string;\n\tisBack?: boolean;\n\tskipFocus?: boolean;\n\treplace?: boolean;\n};\n\nexport type NavigateToParentOptions = Omit< NavigateOptions, 'isBack' >;\n\nexport type NavigatorLocation = NavigateOptions & {\n\tisInitial?: boolean;\n\tpath?: string;\n\thasRestoredFocus?: boolean;\n};\n\n// Returned by the `useNavigator` hook.\nexport type Navigator = {\n\tlocation: NavigatorLocation;\n\tparams: MatchParams;\n\tgoTo: ( path: string, options?: NavigateOptions ) => void;\n\tgoBack: () => void;\n\tgoToParent: ( options?: NavigateToParentOptions ) => void;\n};\n\nexport type NavigatorContext = Navigator & {\n\taddScreen: ( screen: Screen ) => void;\n\tremoveScreen: ( screen: Screen ) => void;\n\tmatch?: string;\n};\n\nexport type NavigatorProviderProps = {\n\t/**\n\t * The initial active path.\n\t */\n\tinitialPath: string;\n\t/**\n\t * The children elements.\n\t */\n\tchildren: ReactNode;\n};\n\nexport type NavigatorScreenProps = {\n\t/**\n\t * The screen's path, matched against the current path stored in the navigator.\n\t */\n\tpath: string;\n\t/**\n\t * The children elements.\n\t */\n\tchildren: ReactNode;\n};\n\nexport type NavigatorBackButtonProps = ButtonAsButtonProps;\n\nexport type NavigatorBackButtonHookProps = NavigatorBackButtonProps & {\n\t/**\n\t * Whether we should navigate to the parent screen.\n\t *\n\t * @default 'false'\n\t */\n\tgoToParent?: boolean;\n};\n\nexport type NavigatorToParentButtonProps = NavigatorBackButtonProps;\n\nexport type NavigatorButtonProps = NavigatorBackButtonProps & {\n\t/**\n\t * The path of the screen to navigate to. The value of this prop needs to be\n\t * a valid value for an HTML attribute.\n\t */\n\tpath: string;\n\t/**\n\t * The HTML attribute used to identify the `NavigatorButton`, which is used\n\t * by `Navigator` to restore focus.\n\t *\n\t * @default 'id'\n\t */\n\tattributeName?: string;\n};\n\nexport type Screen = {\n\tid: string;\n\tpath: string;\n};\n"],"mappings":""}

View File

@@ -0,0 +1,30 @@
/**
* WordPress dependencies
*/
import { useContext } from '@wordpress/element';
/**
* Internal dependencies
*/
import { NavigatorContext } from './context';
/**
* Retrieves a `navigator` instance.
*/
function useNavigator() {
const {
location,
params,
goTo,
goBack,
goToParent
} = useContext(NavigatorContext);
return {
location,
goTo,
goBack,
goToParent,
params
};
}
export default useNavigator;
//# sourceMappingURL=use-navigator.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["useContext","NavigatorContext","useNavigator","location","params","goTo","goBack","goToParent"],"sources":["@wordpress/components/src/navigator/use-navigator.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { NavigatorContext } from './context';\nimport type { Navigator } from './types';\n\n/**\n * Retrieves a `navigator` instance.\n */\nfunction useNavigator(): Navigator {\n\tconst { location, params, goTo, goBack, goToParent } =\n\t\tuseContext( NavigatorContext );\n\n\treturn {\n\t\tlocation,\n\t\tgoTo,\n\t\tgoBack,\n\t\tgoToParent,\n\t\tparams,\n\t};\n}\n\nexport default useNavigator;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,oBAAoB;;AAE/C;AACA;AACA;AACA,SAASC,gBAAgB,QAAQ,WAAW;AAG5C;AACA;AACA;AACA,SAASC,YAAYA,CAAA,EAAc;EAClC,MAAM;IAAEC,QAAQ;IAAEC,MAAM;IAAEC,IAAI;IAAEC,MAAM;IAAEC;EAAW,CAAC,GACnDP,UAAU,CAAEC,gBAAiB,CAAC;EAE/B,OAAO;IACNE,QAAQ;IACRE,IAAI;IACJC,MAAM;IACNC,UAAU;IACVH;EACD,CAAC;AACF;AAEA,eAAeF,YAAY"}

View File

@@ -0,0 +1,45 @@
/**
* External dependencies
*/
import { match } from 'path-to-regexp';
/**
* Internal dependencies
*/
function matchPath(path, pattern) {
const matchingFunction = match(pattern, {
decode: decodeURIComponent
});
return matchingFunction(path);
}
export function patternMatch(path, screens) {
for (const screen of screens) {
const matched = matchPath(path, screen.path);
if (matched) {
return {
params: matched.params,
id: screen.id
};
}
}
return undefined;
}
export function findParent(path, screens) {
if (!path.startsWith('/')) {
return undefined;
}
const pathParts = path.split('/');
let parentPath;
while (pathParts.length > 1 && parentPath === undefined) {
pathParts.pop();
const potentialParentPath = pathParts.join('/') === '' ? '/' : pathParts.join('/');
if (screens.find(screen => {
return matchPath(potentialParentPath, screen.path) !== false;
})) {
parentPath = potentialParentPath;
}
}
return parentPath;
}
//# sourceMappingURL=router.js.map

View File

@@ -0,0 +1 @@
{"version":3,"names":["match","matchPath","path","pattern","matchingFunction","decode","decodeURIComponent","patternMatch","screens","screen","matched","params","id","undefined","findParent","startsWith","pathParts","split","parentPath","length","pop","potentialParentPath","join","find"],"sources":["@wordpress/components/src/navigator/utils/router.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport { match } from 'path-to-regexp';\n\n/**\n * Internal dependencies\n */\nimport type { Screen, MatchParams } from '../types';\n\nfunction matchPath( path: string, pattern: string ) {\n\tconst matchingFunction = match< MatchParams >( pattern, {\n\t\tdecode: decodeURIComponent,\n\t} );\n\treturn matchingFunction( path );\n}\n\nexport function patternMatch( path: string, screens: Screen[] ) {\n\tfor ( const screen of screens ) {\n\t\tconst matched = matchPath( path, screen.path );\n\t\tif ( matched ) {\n\t\t\treturn { params: matched.params, id: screen.id };\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nexport function findParent( path: string, screens: Screen[] ) {\n\tif ( ! path.startsWith( '/' ) ) {\n\t\treturn undefined;\n\t}\n\tconst pathParts = path.split( '/' );\n\tlet parentPath;\n\twhile ( pathParts.length > 1 && parentPath === undefined ) {\n\t\tpathParts.pop();\n\t\tconst potentialParentPath =\n\t\t\tpathParts.join( '/' ) === '' ? '/' : pathParts.join( '/' );\n\t\tif (\n\t\t\tscreens.find( ( screen ) => {\n\t\t\t\treturn matchPath( potentialParentPath, screen.path ) !== false;\n\t\t\t} )\n\t\t) {\n\t\t\tparentPath = potentialParentPath;\n\t\t}\n\t}\n\n\treturn parentPath;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KA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