@wordpress/components 28.8.2 → 28.8.3
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/CHANGELOG.md +9 -0
- package/build/guide/index.js +1 -0
- package/build/guide/index.js.map +1 -1
- package/build/navigator/navigator-provider/component.js +3 -4
- package/build/navigator/navigator-provider/component.js.map +1 -1
- package/build/tools-panel/tools-panel/hook.js +183 -109
- package/build/tools-panel/tools-panel/hook.js.map +1 -1
- package/build-module/guide/index.js +1 -0
- package/build-module/guide/index.js.map +1 -1
- package/build-module/navigator/navigator-provider/component.js +3 -4
- package/build-module/navigator/navigator-provider/component.js.map +1 -1
- package/build-module/tools-panel/tools-panel/hook.js +184 -110
- package/build-module/tools-panel/tools-panel/hook.js.map +1 -1
- package/build-types/guide/index.d.ts.map +1 -1
- package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
- package/build-types/tools-panel/tools-panel/hook.d.ts +2 -2
- package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/guide/index.tsx +1 -0
- package/src/navigator/navigator-provider/component.tsx +3 -2
- package/src/tools-panel/tools-panel/hook.ts +221 -163
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
### Enhancements
|
|
6
|
+
|
|
7
|
+
- `Guide`: Update finish button to use the new default size ([#65680](https://github.com/WordPress/gutenberg/pull/65680)).
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
- `ToolsPanel`: atomic one-step state update when (un)registering panels ([#65564](https://github.com/WordPress/gutenberg/pull/65564)).
|
|
12
|
+
- `Navigator`: fix `isInitial` logic ([#65527](https://github.com/WordPress/gutenberg/pull/65527)).
|
|
13
|
+
|
|
5
14
|
## 28.8.0 (2024-09-19)
|
|
6
15
|
|
|
7
16
|
### Bug Fixes
|
package/build/guide/index.js
CHANGED
package/build/guide/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_clsx","_interopRequireDefault","require","_element","_deprecated","_i18n","_modal","_button","_pageControl","_jsxRuntime","Guide","children","className","contentLabel","finishButtonText","__","onFinish","pages","ref","useRef","currentPage","setCurrentPage","useState","useEffect","frame","current","querySelector","HTMLElement","focus","Children","count","deprecated","since","alternative","_Children$map","map","child","content","canGoBack","canGoForward","length","goBack","goForward","jsx","default","clsx","isDismissible","onRequestClose","onKeyDown","event","code","preventDefault","jsxs","image","numberOfPages","variant","onClick","__next40pxDefaultSize","_default","exports"],"sources":["@wordpress/components/src/guide/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useEffect, Children, useRef } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport Modal from '../modal';\nimport Button from '../button';\nimport PageControl from './page-control';\nimport type { GuideProps } from './types';\n\n/**\n * `Guide` is a React component that renders a _user guide_ in a modal. The guide consists of several pages which the user can step through one by one. The guide is finished when the modal is closed or when the user clicks _Finish_ on the last page of the guide.\n *\n * ```jsx\n * function MyTutorial() {\n * \tconst [ isOpen, setIsOpen ] = useState( true );\n *\n * \tif ( ! isOpen ) {\n * \t\treturn null;\n * \t}\n *\n * \treturn (\n * \t\t<Guide\n * \t\t\tonFinish={ () => setIsOpen( false ) }\n * \t\t\tpages={ [\n * \t\t\t\t{\n * \t\t\t\t\tcontent: <p>Welcome to the ACME Store!</p>,\n * \t\t\t\t},\n * \t\t\t\t{\n * \t\t\t\t\timage: <img src=\"https://acmestore.com/add-to-cart.png\" />,\n * \t\t\t\t\tcontent: (\n * \t\t\t\t\t\t<p>\n * \t\t\t\t\t\t\tClick <i>Add to Cart</i> to buy a product.\n * \t\t\t\t\t\t</p>\n * \t\t\t\t\t),\n * \t\t\t\t},\n * \t\t\t] }\n * \t\t/>\n * \t);\n * }\n * ```\n */\nfunction Guide( {\n\tchildren,\n\tclassName,\n\tcontentLabel,\n\tfinishButtonText = __( 'Finish' ),\n\tonFinish,\n\tpages = [],\n}: GuideProps ) {\n\tconst ref = useRef< HTMLDivElement >( null );\n\tconst [ currentPage, setCurrentPage ] = useState( 0 );\n\n\tuseEffect( () => {\n\t\t// Place focus at the top of the guide on mount and when the page changes.\n\t\tconst frame = ref.current?.querySelector( '.components-guide' );\n\t\tif ( frame instanceof HTMLElement ) {\n\t\t\tframe.focus();\n\t\t}\n\t}, [ currentPage ] );\n\n\tuseEffect( () => {\n\t\tif ( Children.count( children ) ) {\n\t\t\tdeprecated( 'Passing children to <Guide>', {\n\t\t\t\tsince: '5.5',\n\t\t\t\talternative: 'the `pages` prop',\n\t\t\t} );\n\t\t}\n\t}, [ children ] );\n\n\tif ( Children.count( children ) ) {\n\t\tpages =\n\t\t\tChildren.map( children, ( child ) => ( {\n\t\t\t\tcontent: child,\n\t\t\t} ) ) ?? [];\n\t}\n\n\tconst canGoBack = currentPage > 0;\n\tconst canGoForward = currentPage < pages.length - 1;\n\n\tconst goBack = () => {\n\t\tif ( canGoBack ) {\n\t\t\tsetCurrentPage( currentPage - 1 );\n\t\t}\n\t};\n\n\tconst goForward = () => {\n\t\tif ( canGoForward ) {\n\t\t\tsetCurrentPage( currentPage + 1 );\n\t\t}\n\t};\n\n\tif ( pages.length === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName={ clsx( 'components-guide', className ) }\n\t\t\tcontentLabel={ contentLabel }\n\t\t\tisDismissible={ pages.length > 1 }\n\t\t\tonRequestClose={ onFinish }\n\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\tif ( event.code === 'ArrowLeft' ) {\n\t\t\t\t\tgoBack();\n\t\t\t\t\t// Do not scroll the modal's contents.\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t} else if ( event.code === 'ArrowRight' ) {\n\t\t\t\t\tgoForward();\n\t\t\t\t\t// Do not scroll the modal's contents.\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} }\n\t\t\tref={ ref }\n\t\t>\n\t\t\t<div className=\"components-guide__container\">\n\t\t\t\t<div className=\"components-guide__page\">\n\t\t\t\t\t{ pages[ currentPage ].image }\n\n\t\t\t\t\t{ pages.length > 1 && (\n\t\t\t\t\t\t<PageControl\n\t\t\t\t\t\t\tcurrentPage={ currentPage }\n\t\t\t\t\t\t\tnumberOfPages={ pages.length }\n\t\t\t\t\t\t\tsetCurrentPage={ setCurrentPage }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ pages[ currentPage ].content }\n\t\t\t\t</div>\n\n\t\t\t\t<div className=\"components-guide__footer\">\n\t\t\t\t\t{ canGoBack && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"components-guide__back-button\"\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ goBack }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Previous' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t\t{ canGoForward && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"components-guide__forward-button\"\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tonClick={ goForward }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Next' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ! canGoForward && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"components-guide__finish-button\"\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tonClick={ onFinish }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ finishButtonText }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</Modal>\n\t);\n}\n\nexport default Guide;\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,MAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,OAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,YAAA,GAAAP,sBAAA,CAAAC,OAAA;AAAyC,IAAAO,WAAA,GAAAP,OAAA;AAjBzC;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;;AAMA;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,SAASQ,KAAKA,CAAE;EACfC,QAAQ;EACRC,SAAS;EACTC,YAAY;EACZC,gBAAgB,GAAG,IAAAC,QAAE,EAAE,QAAS,CAAC;EACjCC,QAAQ;EACRC,KAAK,GAAG;AACG,CAAC,EAAG;EACf,MAAMC,GAAG,GAAG,IAAAC,eAAM,EAAoB,IAAK,CAAC;EAC5C,MAAM,CAAEC,WAAW,EAAEC,cAAc,CAAE,GAAG,IAAAC,iBAAQ,EAAE,CAAE,CAAC;EAErD,IAAAC,kBAAS,EAAE,MAAM;IAChB;IACA,MAAMC,KAAK,GAAGN,GAAG,CAACO,OAAO,EAAEC,aAAa,CAAE,mBAAoB,CAAC;IAC/D,IAAKF,KAAK,YAAYG,WAAW,EAAG;MACnCH,KAAK,CAACI,KAAK,CAAC,CAAC;IACd;EACD,CAAC,EAAE,CAAER,WAAW,CAAG,CAAC;EA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C,OAAO,EAAGd,SAAW;UACrBe,qBAAqB;UAAA9C,QAAA,EAEnB,IAAAI,QAAE,EAAE,MAAO;QAAC,CACP,CACR,EACC,CAAEwB,YAAY,iBACf,IAAA9B,WAAA,CAAAkC,GAAA,EAACpC,OAAA,CAAAqC,OAAM;UACNhC,SAAS,EAAC,iCAAiC;UAC3C2C,OAAO,EAAC,SAAS;UACjBC,OAAO,EAAGxC,QAAU;
|
|
1
|
+
{"version":3,"names":["_clsx","_interopRequireDefault","require","_element","_deprecated","_i18n","_modal","_button","_pageControl","_jsxRuntime","Guide","children","className","contentLabel","finishButtonText","__","onFinish","pages","ref","useRef","currentPage","setCurrentPage","useState","useEffect","frame","current","querySelector","HTMLElement","focus","Children","count","deprecated","since","alternative","_Children$map","map","child","content","canGoBack","canGoForward","length","goBack","goForward","jsx","default","clsx","isDismissible","onRequestClose","onKeyDown","event","code","preventDefault","jsxs","image","numberOfPages","variant","onClick","__next40pxDefaultSize","_default","exports"],"sources":["@wordpress/components/src/guide/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useEffect, Children, useRef } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport Modal from '../modal';\nimport Button from '../button';\nimport PageControl from './page-control';\nimport type { GuideProps } from './types';\n\n/**\n * `Guide` is a React component that renders a _user guide_ in a modal. The guide consists of several pages which the user can step through one by one. The guide is finished when the modal is closed or when the user clicks _Finish_ on the last page of the guide.\n *\n * ```jsx\n * function MyTutorial() {\n * \tconst [ isOpen, setIsOpen ] = useState( true );\n *\n * \tif ( ! isOpen ) {\n * \t\treturn null;\n * \t}\n *\n * \treturn (\n * \t\t<Guide\n * \t\t\tonFinish={ () => setIsOpen( false ) }\n * \t\t\tpages={ [\n * \t\t\t\t{\n * \t\t\t\t\tcontent: <p>Welcome to the ACME Store!</p>,\n * \t\t\t\t},\n * \t\t\t\t{\n * \t\t\t\t\timage: <img src=\"https://acmestore.com/add-to-cart.png\" />,\n * \t\t\t\t\tcontent: (\n * \t\t\t\t\t\t<p>\n * \t\t\t\t\t\t\tClick <i>Add to Cart</i> to buy a product.\n * \t\t\t\t\t\t</p>\n * \t\t\t\t\t),\n * \t\t\t\t},\n * \t\t\t] }\n * \t\t/>\n * \t);\n * }\n * ```\n */\nfunction Guide( {\n\tchildren,\n\tclassName,\n\tcontentLabel,\n\tfinishButtonText = __( 'Finish' ),\n\tonFinish,\n\tpages = [],\n}: GuideProps ) {\n\tconst ref = useRef< HTMLDivElement >( null );\n\tconst [ currentPage, setCurrentPage ] = useState( 0 );\n\n\tuseEffect( () => {\n\t\t// Place focus at the top of the guide on mount and when the page changes.\n\t\tconst frame = ref.current?.querySelector( '.components-guide' );\n\t\tif ( frame instanceof HTMLElement ) {\n\t\t\tframe.focus();\n\t\t}\n\t}, [ currentPage ] );\n\n\tuseEffect( () => {\n\t\tif ( Children.count( children ) ) {\n\t\t\tdeprecated( 'Passing children to <Guide>', {\n\t\t\t\tsince: '5.5',\n\t\t\t\talternative: 'the `pages` prop',\n\t\t\t} );\n\t\t}\n\t}, [ children ] );\n\n\tif ( Children.count( children ) ) {\n\t\tpages =\n\t\t\tChildren.map( children, ( child ) => ( {\n\t\t\t\tcontent: child,\n\t\t\t} ) ) ?? [];\n\t}\n\n\tconst canGoBack = currentPage > 0;\n\tconst canGoForward = currentPage < pages.length - 1;\n\n\tconst goBack = () => {\n\t\tif ( canGoBack ) {\n\t\t\tsetCurrentPage( currentPage - 1 );\n\t\t}\n\t};\n\n\tconst goForward = () => {\n\t\tif ( canGoForward ) {\n\t\t\tsetCurrentPage( currentPage + 1 );\n\t\t}\n\t};\n\n\tif ( pages.length === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName={ clsx( 'components-guide', className ) }\n\t\t\tcontentLabel={ contentLabel }\n\t\t\tisDismissible={ pages.length > 1 }\n\t\t\tonRequestClose={ onFinish }\n\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\tif ( event.code === 'ArrowLeft' ) {\n\t\t\t\t\tgoBack();\n\t\t\t\t\t// Do not scroll the modal's contents.\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t} else if ( event.code === 'ArrowRight' ) {\n\t\t\t\t\tgoForward();\n\t\t\t\t\t// Do not scroll the modal's contents.\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} }\n\t\t\tref={ ref }\n\t\t>\n\t\t\t<div className=\"components-guide__container\">\n\t\t\t\t<div className=\"components-guide__page\">\n\t\t\t\t\t{ pages[ currentPage ].image }\n\n\t\t\t\t\t{ pages.length > 1 && (\n\t\t\t\t\t\t<PageControl\n\t\t\t\t\t\t\tcurrentPage={ currentPage }\n\t\t\t\t\t\t\tnumberOfPages={ pages.length }\n\t\t\t\t\t\t\tsetCurrentPage={ setCurrentPage }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ pages[ currentPage ].content }\n\t\t\t\t</div>\n\n\t\t\t\t<div className=\"components-guide__footer\">\n\t\t\t\t\t{ canGoBack && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"components-guide__back-button\"\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ goBack }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Previous' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t\t{ canGoForward && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"components-guide__forward-button\"\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tonClick={ goForward }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Next' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ! canGoForward && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"components-guide__finish-button\"\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tonClick={ onFinish }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ finishButtonText }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</Modal>\n\t);\n}\n\nexport default Guide;\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,MAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,OAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,YAAA,GAAAP,sBAAA,CAAAC,OAAA;AAAyC,IAAAO,WAAA,GAAAP,OAAA;AAjBzC;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;;AAMA;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,SAASQ,KAAKA,CAAE;EACfC,QAAQ;EACRC,SAAS;EACTC,YAAY;EACZC,gBAAgB,GAAG,IAAAC,QAAE,EAAE,QAAS,CAAC;EACjCC,QAAQ;EACRC,KAAK,GAAG;AACG,CAAC,EAAG;EACf,MAAMC,GAAG,GAAG,IAAAC,eAAM,EAAoB,IAAK,CAAC;EAC5C,MAAM,CAAEC,WAAW,EAAEC,cAAc,CAAE,GAAG,IAAAC,iBAAQ,EAAE,CAAE,CAAC;EAErD,IAAAC,kBAA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MAAQ;UAClBgB,qBAAqB;UAAA9C,QAAA,EAEnB,IAAAI,QAAE,EAAE,UAAW;QAAC,CACX,CACR,EACCwB,YAAY,iBACb,IAAA9B,WAAA,CAAAkC,GAAA,EAACpC,OAAA,CAAAqC,OAAM;UACNhC,SAAS,EAAC,kCAAkC;UAC5C2C,OAAO,EAAC,SAAS;UACjBC,OAAO,EAAGd,SAAW;UACrBe,qBAAqB;UAAA9C,QAAA,EAEnB,IAAAI,QAAE,EAAE,MAAO;QAAC,CACP,CACR,EACC,CAAEwB,YAAY,iBACf,IAAA9B,WAAA,CAAAkC,GAAA,EAACpC,OAAA,CAAAqC,OAAM;UACNhC,SAAS,EAAC,iCAAiC;UAC3C2C,OAAO,EAAC,SAAS;UACjBC,OAAO,EAAGxC,QAAU;UACpByC,qBAAqB;UAAA9C,QAAA,EAEnBG;QAAgB,CACX,CACR;MAAA,CACG,CAAC;IAAA,CACF;EAAC,CACA,CAAC;AAEV;AAAC,IAAA4C,QAAA,GAAAC,OAAA,CAAAf,OAAA,GAEclC,KAAK","ignoreList":[]}
|
|
@@ -51,8 +51,7 @@ function goTo(state, path, options = {}) {
|
|
|
51
51
|
focusSelectors
|
|
52
52
|
} = state;
|
|
53
53
|
const currentLocation = {
|
|
54
|
-
...state.currentLocation
|
|
55
|
-
isInitial: false
|
|
54
|
+
...state.currentLocation
|
|
56
55
|
};
|
|
57
56
|
const {
|
|
58
57
|
// Default assignments
|
|
@@ -97,6 +96,7 @@ function goTo(state, path, options = {}) {
|
|
|
97
96
|
return {
|
|
98
97
|
currentLocation: {
|
|
99
98
|
...restOptions,
|
|
99
|
+
isInitial: false,
|
|
100
100
|
path,
|
|
101
101
|
isBack,
|
|
102
102
|
hasRestoredFocus: false,
|
|
@@ -112,8 +112,7 @@ function goToParent(state, options = {}) {
|
|
|
112
112
|
focusSelectors
|
|
113
113
|
} = state;
|
|
114
114
|
const currentLocation = {
|
|
115
|
-
...state.currentLocation
|
|
116
|
-
isInitial: false
|
|
115
|
+
...state.currentLocation
|
|
117
116
|
};
|
|
118
117
|
const currentPath = currentLocation.path;
|
|
119
118
|
if (currentPath === undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_isShallowEqual","_interopRequireDefault","_warning","_context","_useCx","_router","_view","_context2","styles","_interopRequireWildcard","_deprecated","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","addScreen","screens","screen","some","s","path","globalThis","SCRIPT_DEBUG","warning","id","removeScreen","filter","goTo","state","options","_focusSelectorsCopy2","focusSelectors","currentLocation","isInitial","isBack","skipFocus","replace","focusTargetSelector","restOptions","focusSelectorsCopy","getFocusSelectorsCopy","_focusSelectorsCopy","Map","currentFocusSelector","delete","hasRestoredFocus","goToParent","currentPath","undefined","parentPath","findParent","routerReducer","action","matchedPath","restState","type","patternMatch","isShallowEqual","params","UnconnectedNavigatorProvider","props","forwardedRef","initialPath","initialPathProp","children","className","otherProps","useContextSystem","routerState","dispatch","useReducer","methods","useMemo","goBack","deprecated","since","alternative","navigatorContextValue","_matchedPath$params","location","match","cx","useCx","classes","navigatorProviderWrapper","jsx","View","ref","NavigatorContext","Provider","value","NavigatorProvider","exports","contextConnect","_default"],"sources":["@wordpress/components/src/navigator/navigator-provider/component.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, useReducer } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../../context';\nimport { contextConnect, useContextSystem } from '../../context';\nimport { useCx } from '../../utils/hooks/use-cx';\nimport { patternMatch, findParent } from '../utils/router';\nimport { View } from '../../view';\nimport { NavigatorContext } from '../context';\nimport * as styles from '../styles';\nimport type {\n\tNavigatorProviderProps,\n\tNavigatorLocation,\n\tNavigatorContext as NavigatorContextType,\n\tNavigateOptions,\n\tScreen,\n\tNavigateToParentOptions,\n} from '../types';\nimport deprecated from '@wordpress/deprecated';\n\ntype MatchedPath = ReturnType< typeof patternMatch >;\n\ntype RouterAction =\n\t| { type: 'add' | 'remove'; screen: Screen }\n\t| { type: 'goto'; path: string; options?: NavigateOptions }\n\t| { type: 'gotoparent'; options?: NavigateToParentOptions };\n\ntype RouterState = {\n\tinitialPath: string;\n\tscreens: Screen[];\n\tcurrentLocation: NavigatorLocation;\n\tmatchedPath: MatchedPath;\n\tfocusSelectors: Map< string, string >;\n};\n\nfunction addScreen( { screens }: RouterState, screen: Screen ) {\n\tif ( screens.some( ( s ) => s.path === screen.path ) ) {\n\t\twarning(\n\t\t\t`Navigator: a screen with path ${ screen.path } already exists.\nThe screen with id ${ screen.id } will not be added.`\n\t\t);\n\t\treturn screens;\n\t}\n\treturn [ ...screens, screen ];\n}\n\nfunction removeScreen( { screens }: RouterState, screen: Screen ) {\n\treturn screens.filter( ( s ) => s.id !== screen.id );\n}\n\nfunction goTo(\n\tstate: RouterState,\n\tpath: string,\n\toptions: NavigateOptions = {}\n) {\n\tconst { focusSelectors } = state;\n\tconst currentLocation = { ...state.currentLocation, isInitial: false };\n\n\tconst {\n\t\t// Default assignments\n\t\tisBack = false,\n\t\tskipFocus = false,\n\t\t// Extract to avoid forwarding\n\t\treplace,\n\t\tfocusTargetSelector,\n\t\t// Rest\n\t\t...restOptions\n\t} = options;\n\n\tif ( currentLocation.path === path ) {\n\t\treturn { currentLocation, focusSelectors };\n\t}\n\n\tlet focusSelectorsCopy: typeof focusSelectors | undefined;\n\tfunction getFocusSelectorsCopy() {\n\t\tfocusSelectorsCopy =\n\t\t\tfocusSelectorsCopy ?? new Map( state.focusSelectors );\n\t\treturn focusSelectorsCopy;\n\t}\n\n\t// Set a focus selector that will be used when navigating\n\t// back to the current location.\n\tif ( focusTargetSelector && currentLocation.path ) {\n\t\tgetFocusSelectorsCopy().set(\n\t\t\tcurrentLocation.path,\n\t\t\tfocusTargetSelector\n\t\t);\n\t}\n\n\t// Get the focus selector for the new location.\n\tlet currentFocusSelector;\n\tif ( focusSelectors.get( path ) ) {\n\t\tif ( isBack ) {\n\t\t\t// Use the found focus selector only when navigating back.\n\t\t\tcurrentFocusSelector = focusSelectors.get( path );\n\t\t}\n\t\t// Make a copy of the focusSelectors map to remove the focus selector\n\t\t// only if necessary (ie. a focus selector was found).\n\t\tgetFocusSelectorsCopy().delete( path );\n\t}\n\n\treturn {\n\t\tcurrentLocation: {\n\t\t\t...restOptions,\n\t\t\tpath,\n\t\t\tisBack,\n\t\t\thasRestoredFocus: false,\n\t\t\tfocusTargetSelector: currentFocusSelector,\n\t\t\tskipFocus,\n\t\t},\n\t\tfocusSelectors: focusSelectorsCopy ?? focusSelectors,\n\t};\n}\n\nfunction goToParent(\n\tstate: RouterState,\n\toptions: NavigateToParentOptions = {}\n) {\n\tconst { screens, focusSelectors } = state;\n\tconst currentLocation = { ...state.currentLocation, isInitial: false };\n\tconst currentPath = currentLocation.path;\n\tif ( currentPath === undefined ) {\n\t\treturn { currentLocation, focusSelectors };\n\t}\n\tconst parentPath = findParent( currentPath, screens );\n\tif ( parentPath === undefined ) {\n\t\treturn { currentLocation, focusSelectors };\n\t}\n\treturn goTo( state, parentPath, {\n\t\t...options,\n\t\tisBack: true,\n\t} );\n}\n\nfunction routerReducer(\n\tstate: RouterState,\n\taction: RouterAction\n): RouterState {\n\tlet {\n\t\tscreens,\n\t\tcurrentLocation,\n\t\tmatchedPath,\n\t\tfocusSelectors,\n\t\t...restState\n\t} = state;\n\tswitch ( action.type ) {\n\t\tcase 'add':\n\t\t\tscreens = addScreen( state, action.screen );\n\t\t\tbreak;\n\t\tcase 'remove':\n\t\t\tscreens = removeScreen( state, action.screen );\n\t\t\tbreak;\n\t\tcase 'goto':\n\t\t\t( { currentLocation, focusSelectors } = goTo(\n\t\t\t\tstate,\n\t\t\t\taction.path,\n\t\t\t\taction.options\n\t\t\t) );\n\t\t\tbreak;\n\t\tcase 'gotoparent':\n\t\t\t( { currentLocation, focusSelectors } = goToParent(\n\t\t\t\tstate,\n\t\t\t\taction.options\n\t\t\t) );\n\t\t\tbreak;\n\t}\n\n\t// Return early in case there is no change\n\tif (\n\t\tscreens === state.screens &&\n\t\tcurrentLocation === state.currentLocation\n\t) {\n\t\treturn state;\n\t}\n\n\t// Compute the matchedPath\n\tconst currentPath = currentLocation.path;\n\tmatchedPath =\n\t\tcurrentPath !== undefined\n\t\t\t? patternMatch( currentPath, screens )\n\t\t\t: undefined;\n\n\t// If the new match is the same as the previous match,\n\t// return the previous one to keep immutability.\n\tif (\n\t\tmatchedPath &&\n\t\tstate.matchedPath &&\n\t\tmatchedPath.id === state.matchedPath.id &&\n\t\tisShallowEqual( matchedPath.params, state.matchedPath.params )\n\t) {\n\t\tmatchedPath = state.matchedPath;\n\t}\n\n\treturn {\n\t\t...restState,\n\t\tscreens,\n\t\tcurrentLocation,\n\t\tmatchedPath,\n\t\tfocusSelectors,\n\t};\n}\n\nfunction UnconnectedNavigatorProvider(\n\tprops: WordPressComponentProps< NavigatorProviderProps, 'div' >,\n\tforwardedRef: ForwardedRef< any >\n) {\n\tconst {\n\t\tinitialPath: initialPathProp,\n\t\tchildren,\n\t\tclassName,\n\t\t...otherProps\n\t} = useContextSystem( props, 'NavigatorProvider' );\n\n\tconst [ routerState, dispatch ] = useReducer(\n\t\trouterReducer,\n\t\tinitialPathProp,\n\t\t( path ) => ( {\n\t\t\tscreens: [],\n\t\t\tcurrentLocation: { path, isInitial: true },\n\t\t\tmatchedPath: undefined,\n\t\t\tfocusSelectors: new Map(),\n\t\t\tinitialPath: initialPathProp,\n\t\t} )\n\t);\n\n\t// The methods are constant forever, create stable references to them.\n\tconst methods = useMemo(\n\t\t() => ( {\n\t\t\t// Note: calling goBack calls `goToParent` internally, as it was established\n\t\t\t// that `goBack` should behave like `goToParent`, and `goToParent` should\n\t\t\t// be marked as deprecated.\n\t\t\tgoBack: ( options: NavigateToParentOptions | undefined ) =>\n\t\t\t\tdispatch( { type: 'gotoparent', options } ),\n\t\t\tgoTo: ( path: string, options?: NavigateOptions ) =>\n\t\t\t\tdispatch( { type: 'goto', path, options } ),\n\t\t\tgoToParent: ( options: NavigateToParentOptions | undefined ) => {\n\t\t\t\tdeprecated( `wp.components.useNavigator().goToParent`, {\n\t\t\t\t\tsince: '6.7',\n\t\t\t\t\talternative: 'wp.components.useNavigator().goBack',\n\t\t\t\t} );\n\t\t\t\tdispatch( { type: 'gotoparent', options } );\n\t\t\t},\n\t\t\taddScreen: ( screen: Screen ) =>\n\t\t\t\tdispatch( { type: 'add', screen } ),\n\t\t\tremoveScreen: ( screen: Screen ) =>\n\t\t\t\tdispatch( { type: 'remove', screen } ),\n\t\t} ),\n\t\t[]\n\t);\n\n\tconst { currentLocation, matchedPath } = routerState;\n\n\tconst navigatorContextValue: NavigatorContextType = useMemo(\n\t\t() => ( {\n\t\t\tlocation: currentLocation,\n\t\t\tparams: matchedPath?.params ?? {},\n\t\t\tmatch: matchedPath?.id,\n\t\t\t...methods,\n\t\t} ),\n\t\t[ currentLocation, matchedPath, methods ]\n\t);\n\n\tconst cx = useCx();\n\tconst classes = useMemo(\n\t\t() => cx( styles.navigatorProviderWrapper, className ),\n\t\t[ className, cx ]\n\t);\n\n\treturn (\n\t\t<View ref={ forwardedRef } className={ classes } { ...otherProps }>\n\t\t\t<NavigatorContext.Provider value={ navigatorContextValue }>\n\t\t\t\t{ children }\n\t\t\t</NavigatorContext.Provider>\n\t\t</View>\n\t);\n}\n\n/**\n * The `NavigatorProvider` component allows rendering nested views/panels/menus\n * (via the `NavigatorScreen` component and navigate between these different\n * view (via the `NavigatorButton` and `NavigatorBackButton` components or the\n * `useNavigator` hook).\n *\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 NavigatorProvider = contextConnect(\n\tUnconnectedNavigatorProvider,\n\t'NavigatorProvider'\n);\n\nexport default NavigatorProvider;\n"],"mappings":";;;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAD,sBAAA,CAAAF,OAAA;AAMA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AACA,IAAAQ,SAAA,GAAAR,OAAA;AACA,IAAAS,MAAA,GAAAC,uBAAA,CAAAV,OAAA;AASA,IAAAW,WAAA,GAAAT,sBAAA,CAAAF,OAAA;AAA+C,IAAAY,WAAA,GAAAZ,OAAA;AAAA,SAAAa,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA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,cAAAA,mBAAA,GAAI,CAAC,CAAC;MACjCE,KAAK,EAAE3B,WAAW,EAAE7B,EAAE;MACtB,GAAG+C;IACJ,CAAC;EAAA,CAAE,EACH,CAAEvC,eAAe,EAAEqB,WAAW,EAAEkB,OAAO,CACxC,CAAC;EAED,MAAMU,EAAE,GAAG,IAAAC,YAAK,EAAC,CAAC;EAClB,MAAMC,OAAO,GAAG,IAAAX,gBAAO,EACtB,MAAMS,EAAE,CAAE1F,MAAM,CAAC6F,wBAAwB,EAAEnB,SAAU,CAAC,EACtD,CAAEA,SAAS,EAAEgB,EAAE,CAChB,CAAC;EAED,oBACC,IAAAvF,WAAA,CAAA2F,GAAA,EAAChG,KAAA,CAAAiG,IAAI;IAACC,GAAG,EAAG1B,YAAc;IAACI,SAAS,EAAGkB,OAAS;IAAA,GAAMjB,UAAU;IAAAF,QAAA,eAC/D,IAAAtE,WAAA,CAAA2F,GAAA,EAAC/F,SAAA,CAAAkG,gBAAgB,CAACC,QAAQ;MAACC,KAAK,EAAGb,qBAAuB;MAAAb,QAAA,EACvDA;IAAQ,CACgB;EAAC,CACvB,CAAC;AAET;;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;AACO,MAAM2B,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG,IAAAE,uBAAc,EAC9ClC,4BAA4B,EAC5B,mBACD,CAAC;AAAC,IAAAmC,QAAA,GAAAF,OAAA,CAAA3F,OAAA,GAEa0F,iBAAiB","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_element","require","_isShallowEqual","_interopRequireDefault","_warning","_context","_useCx","_router","_view","_context2","styles","_interopRequireWildcard","_deprecated","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","addScreen","screens","screen","some","s","path","globalThis","SCRIPT_DEBUG","warning","id","removeScreen","filter","goTo","state","options","_focusSelectorsCopy2","focusSelectors","currentLocation","isBack","skipFocus","replace","focusTargetSelector","restOptions","focusSelectorsCopy","getFocusSelectorsCopy","_focusSelectorsCopy","Map","currentFocusSelector","delete","isInitial","hasRestoredFocus","goToParent","currentPath","undefined","parentPath","findParent","routerReducer","action","matchedPath","restState","type","patternMatch","isShallowEqual","params","UnconnectedNavigatorProvider","props","forwardedRef","initialPath","initialPathProp","children","className","otherProps","useContextSystem","routerState","dispatch","useReducer","methods","useMemo","goBack","deprecated","since","alternative","navigatorContextValue","_matchedPath$params","location","match","cx","useCx","classes","navigatorProviderWrapper","jsx","View","ref","NavigatorContext","Provider","value","NavigatorProvider","exports","contextConnect","_default"],"sources":["@wordpress/components/src/navigator/navigator-provider/component.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, useReducer } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport warning from '@wordpress/warning';\n\n/**\n * Internal dependencies\n */\nimport type { WordPressComponentProps } from '../../context';\nimport { contextConnect, useContextSystem } from '../../context';\nimport { useCx } from '../../utils/hooks/use-cx';\nimport { patternMatch, findParent } from '../utils/router';\nimport { View } from '../../view';\nimport { NavigatorContext } from '../context';\nimport * as styles from '../styles';\nimport type {\n\tNavigatorProviderProps,\n\tNavigatorLocation,\n\tNavigatorContext as NavigatorContextType,\n\tNavigateOptions,\n\tScreen,\n\tNavigateToParentOptions,\n} from '../types';\nimport deprecated from '@wordpress/deprecated';\n\ntype MatchedPath = ReturnType< typeof patternMatch >;\n\ntype RouterAction =\n\t| { type: 'add' | 'remove'; screen: Screen }\n\t| { type: 'goto'; path: string; options?: NavigateOptions }\n\t| { type: 'gotoparent'; options?: NavigateToParentOptions };\n\ntype RouterState = {\n\tinitialPath: string;\n\tscreens: Screen[];\n\tcurrentLocation: NavigatorLocation;\n\tmatchedPath: MatchedPath;\n\tfocusSelectors: Map< string, string >;\n};\n\nfunction addScreen( { screens }: RouterState, screen: Screen ) {\n\tif ( screens.some( ( s ) => s.path === screen.path ) ) {\n\t\twarning(\n\t\t\t`Navigator: a screen with path ${ screen.path } already exists.\nThe screen with id ${ screen.id } will not be added.`\n\t\t);\n\t\treturn screens;\n\t}\n\treturn [ ...screens, screen ];\n}\n\nfunction removeScreen( { screens }: RouterState, screen: Screen ) {\n\treturn screens.filter( ( s ) => s.id !== screen.id );\n}\n\nfunction goTo(\n\tstate: RouterState,\n\tpath: string,\n\toptions: NavigateOptions = {}\n) {\n\tconst { focusSelectors } = state;\n\tconst currentLocation = { ...state.currentLocation };\n\n\tconst {\n\t\t// Default assignments\n\t\tisBack = false,\n\t\tskipFocus = false,\n\t\t// Extract to avoid forwarding\n\t\treplace,\n\t\tfocusTargetSelector,\n\t\t// Rest\n\t\t...restOptions\n\t} = options;\n\n\tif ( currentLocation.path === path ) {\n\t\treturn { currentLocation, focusSelectors };\n\t}\n\n\tlet focusSelectorsCopy: typeof focusSelectors | undefined;\n\tfunction getFocusSelectorsCopy() {\n\t\tfocusSelectorsCopy =\n\t\t\tfocusSelectorsCopy ?? new Map( state.focusSelectors );\n\t\treturn focusSelectorsCopy;\n\t}\n\n\t// Set a focus selector that will be used when navigating\n\t// back to the current location.\n\tif ( focusTargetSelector && currentLocation.path ) {\n\t\tgetFocusSelectorsCopy().set(\n\t\t\tcurrentLocation.path,\n\t\t\tfocusTargetSelector\n\t\t);\n\t}\n\n\t// Get the focus selector for the new location.\n\tlet currentFocusSelector;\n\tif ( focusSelectors.get( path ) ) {\n\t\tif ( isBack ) {\n\t\t\t// Use the found focus selector only when navigating back.\n\t\t\tcurrentFocusSelector = focusSelectors.get( path );\n\t\t}\n\t\t// Make a copy of the focusSelectors map to remove the focus selector\n\t\t// only if necessary (ie. a focus selector was found).\n\t\tgetFocusSelectorsCopy().delete( path );\n\t}\n\n\treturn {\n\t\tcurrentLocation: {\n\t\t\t...restOptions,\n\t\t\tisInitial: false,\n\t\t\tpath,\n\t\t\tisBack,\n\t\t\thasRestoredFocus: false,\n\t\t\tfocusTargetSelector: currentFocusSelector,\n\t\t\tskipFocus,\n\t\t},\n\t\tfocusSelectors: focusSelectorsCopy ?? focusSelectors,\n\t};\n}\n\nfunction goToParent(\n\tstate: RouterState,\n\toptions: NavigateToParentOptions = {}\n) {\n\tconst { screens, focusSelectors } = state;\n\tconst currentLocation = { ...state.currentLocation };\n\tconst currentPath = currentLocation.path;\n\tif ( currentPath === undefined ) {\n\t\treturn { currentLocation, focusSelectors };\n\t}\n\tconst parentPath = findParent( currentPath, screens );\n\tif ( parentPath === undefined ) {\n\t\treturn { currentLocation, focusSelectors };\n\t}\n\treturn goTo( state, parentPath, {\n\t\t...options,\n\t\tisBack: true,\n\t} );\n}\n\nfunction routerReducer(\n\tstate: RouterState,\n\taction: RouterAction\n): RouterState {\n\tlet {\n\t\tscreens,\n\t\tcurrentLocation,\n\t\tmatchedPath,\n\t\tfocusSelectors,\n\t\t...restState\n\t} = state;\n\tswitch ( action.type ) {\n\t\tcase 'add':\n\t\t\tscreens = addScreen( state, action.screen );\n\t\t\tbreak;\n\t\tcase 'remove':\n\t\t\tscreens = removeScreen( state, action.screen );\n\t\t\tbreak;\n\t\tcase 'goto':\n\t\t\t( { currentLocation, focusSelectors } = goTo(\n\t\t\t\tstate,\n\t\t\t\taction.path,\n\t\t\t\taction.options\n\t\t\t) );\n\t\t\tbreak;\n\t\tcase 'gotoparent':\n\t\t\t( { currentLocation, focusSelectors } = goToParent(\n\t\t\t\tstate,\n\t\t\t\taction.options\n\t\t\t) );\n\t\t\tbreak;\n\t}\n\n\t// Return early in case there is no change\n\tif (\n\t\tscreens === state.screens &&\n\t\tcurrentLocation === state.currentLocation\n\t) {\n\t\treturn state;\n\t}\n\n\t// Compute the matchedPath\n\tconst currentPath = currentLocation.path;\n\tmatchedPath =\n\t\tcurrentPath !== undefined\n\t\t\t? patternMatch( currentPath, screens )\n\t\t\t: undefined;\n\n\t// If the new match is the same as the previous match,\n\t// return the previous one to keep immutability.\n\tif (\n\t\tmatchedPath &&\n\t\tstate.matchedPath &&\n\t\tmatchedPath.id === state.matchedPath.id &&\n\t\tisShallowEqual( matchedPath.params, state.matchedPath.params )\n\t) {\n\t\tmatchedPath = state.matchedPath;\n\t}\n\n\treturn {\n\t\t...restState,\n\t\tscreens,\n\t\tcurrentLocation,\n\t\tmatchedPath,\n\t\tfocusSelectors,\n\t};\n}\n\nfunction UnconnectedNavigatorProvider(\n\tprops: WordPressComponentProps< NavigatorProviderProps, 'div' >,\n\tforwardedRef: ForwardedRef< any >\n) {\n\tconst {\n\t\tinitialPath: initialPathProp,\n\t\tchildren,\n\t\tclassName,\n\t\t...otherProps\n\t} = useContextSystem( props, 'NavigatorProvider' );\n\n\tconst [ routerState, dispatch ] = useReducer(\n\t\trouterReducer,\n\t\tinitialPathProp,\n\t\t( path ) => ( {\n\t\t\tscreens: [],\n\t\t\tcurrentLocation: { path, isInitial: true },\n\t\t\tmatchedPath: undefined,\n\t\t\tfocusSelectors: new Map(),\n\t\t\tinitialPath: initialPathProp,\n\t\t} )\n\t);\n\n\t// The methods are constant forever, create stable references to them.\n\tconst methods = useMemo(\n\t\t() => ( {\n\t\t\t// Note: calling goBack calls `goToParent` internally, as it was established\n\t\t\t// that `goBack` should behave like `goToParent`, and `goToParent` should\n\t\t\t// be marked as deprecated.\n\t\t\tgoBack: ( options: NavigateToParentOptions | undefined ) =>\n\t\t\t\tdispatch( { type: 'gotoparent', options } ),\n\t\t\tgoTo: ( path: string, options?: NavigateOptions ) =>\n\t\t\t\tdispatch( { type: 'goto', path, options } ),\n\t\t\tgoToParent: ( options: NavigateToParentOptions | undefined ) => {\n\t\t\t\tdeprecated( `wp.components.useNavigator().goToParent`, {\n\t\t\t\t\tsince: '6.7',\n\t\t\t\t\talternative: 'wp.components.useNavigator().goBack',\n\t\t\t\t} );\n\t\t\t\tdispatch( { type: 'gotoparent', options } );\n\t\t\t},\n\t\t\taddScreen: ( screen: Screen ) =>\n\t\t\t\tdispatch( { type: 'add', screen } ),\n\t\t\tremoveScreen: ( screen: Screen ) =>\n\t\t\t\tdispatch( { type: 'remove', screen } ),\n\t\t} ),\n\t\t[]\n\t);\n\n\tconst { currentLocation, matchedPath } = routerState;\n\n\tconst navigatorContextValue: NavigatorContextType = useMemo(\n\t\t() => ( {\n\t\t\tlocation: currentLocation,\n\t\t\tparams: matchedPath?.params ?? {},\n\t\t\tmatch: matchedPath?.id,\n\t\t\t...methods,\n\t\t} ),\n\t\t[ currentLocation, matchedPath, methods ]\n\t);\n\n\tconst cx = useCx();\n\tconst classes = useMemo(\n\t\t() => cx( styles.navigatorProviderWrapper, className ),\n\t\t[ className, cx ]\n\t);\n\n\treturn (\n\t\t<View ref={ forwardedRef } className={ classes } { ...otherProps }>\n\t\t\t<NavigatorContext.Provider value={ navigatorContextValue }>\n\t\t\t\t{ children }\n\t\t\t</NavigatorContext.Provider>\n\t\t</View>\n\t);\n}\n\n/**\n * The `NavigatorProvider` component allows rendering nested views/panels/menus\n * (via the `NavigatorScreen` component and navigate between these different\n * view (via the `NavigatorButton` and `NavigatorBackButton` components or the\n * `useNavigator` hook).\n *\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 NavigatorProvider = contextConnect(\n\tUnconnectedNavigatorProvider,\n\t'NavigatorProvider'\n);\n\nexport default NavigatorProvider;\n"],"mappings":";;;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAD,sBAAA,CAAAF,OAAA;AAMA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,KAAA,GAAAP,OAAA;AACA,IAAAQ,SAAA,GAAAR,OAAA;AACA,IAAAS,MAAA,GAAAC,uBAAA,CAAAV,OAAA;AASA,IAAAW,WAAA,GAAAT,sBAAA,CAAAF,OAAA;AAA+C,IAAAY,WAAA,GAAAZ,OAAA;AAAA,SAAAa,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA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,SAAU,CAAC,EACtD,CAAEA,SAAS,EAAEgB,EAAE,CAChB,CAAC;EAED,oBACC,IAAAvF,WAAA,CAAA2F,GAAA,EAAChG,KAAA,CAAAiG,IAAI;IAACC,GAAG,EAAG1B,YAAc;IAACI,SAAS,EAAGkB,OAAS;IAAA,GAAMjB,UAAU;IAAAF,QAAA,eAC/D,IAAAtE,WAAA,CAAA2F,GAAA,EAAC/F,SAAA,CAAAkG,gBAAgB,CAACC,QAAQ;MAACC,KAAK,EAAGb,qBAAuB;MAAAb,QAAA,EACvDA;IAAQ,CACgB;EAAC,CACvB,CAAC;AAET;;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;AACO,MAAM2B,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG,IAAAE,uBAAc,EAC9ClC,4BAA4B,EAC5B,mBACD,CAAC;AAAC,IAAAmC,QAAA,GAAAF,OAAA,CAAA3F,OAAA,GAEa0F,iBAAiB","ignoreList":[]}
|
|
@@ -19,20 +19,27 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
const DEFAULT_COLUMNS = 2;
|
|
22
|
+
function emptyMenuItems() {
|
|
23
|
+
return {
|
|
24
|
+
default: {},
|
|
25
|
+
optional: {}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function emptyState() {
|
|
29
|
+
return {
|
|
30
|
+
panelItems: [],
|
|
31
|
+
menuItemOrder: [],
|
|
32
|
+
menuItems: emptyMenuItems()
|
|
33
|
+
};
|
|
34
|
+
}
|
|
22
35
|
const generateMenuItems = ({
|
|
23
36
|
panelItems,
|
|
24
37
|
shouldReset,
|
|
25
38
|
currentMenuItems,
|
|
26
39
|
menuItemOrder
|
|
27
40
|
}) => {
|
|
28
|
-
const newMenuItems =
|
|
29
|
-
|
|
30
|
-
optional: {}
|
|
31
|
-
};
|
|
32
|
-
const menuItems = {
|
|
33
|
-
default: {},
|
|
34
|
-
optional: {}
|
|
35
|
-
};
|
|
41
|
+
const newMenuItems = emptyMenuItems();
|
|
42
|
+
const menuItems = emptyMenuItems();
|
|
36
43
|
panelItems.forEach(({
|
|
37
44
|
hasValue,
|
|
38
45
|
isShownByDefault,
|
|
@@ -71,7 +78,128 @@ const generateMenuItems = ({
|
|
|
71
78
|
});
|
|
72
79
|
return menuItems;
|
|
73
80
|
};
|
|
74
|
-
|
|
81
|
+
function panelItemsReducer(panelItems, action) {
|
|
82
|
+
switch (action.type) {
|
|
83
|
+
case 'REGISTER_PANEL':
|
|
84
|
+
{
|
|
85
|
+
const newItems = [...panelItems];
|
|
86
|
+
// If an item with this label has already been registered, remove it
|
|
87
|
+
// first. This can happen when an item is moved between the default
|
|
88
|
+
// and optional groups.
|
|
89
|
+
const existingIndex = newItems.findIndex(oldItem => oldItem.label === action.item.label);
|
|
90
|
+
if (existingIndex !== -1) {
|
|
91
|
+
newItems.splice(existingIndex, 1);
|
|
92
|
+
}
|
|
93
|
+
newItems.push(action.item);
|
|
94
|
+
return newItems;
|
|
95
|
+
}
|
|
96
|
+
case 'UNREGISTER_PANEL':
|
|
97
|
+
{
|
|
98
|
+
const index = panelItems.findIndex(item => item.label === action.label);
|
|
99
|
+
if (index !== -1) {
|
|
100
|
+
const newItems = [...panelItems];
|
|
101
|
+
newItems.splice(index, 1);
|
|
102
|
+
return newItems;
|
|
103
|
+
}
|
|
104
|
+
return panelItems;
|
|
105
|
+
}
|
|
106
|
+
default:
|
|
107
|
+
return panelItems;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function menuItemOrderReducer(menuItemOrder, action) {
|
|
111
|
+
switch (action.type) {
|
|
112
|
+
case 'REGISTER_PANEL':
|
|
113
|
+
{
|
|
114
|
+
// Track the initial order of item registration. This is used for
|
|
115
|
+
// maintaining menu item order later.
|
|
116
|
+
if (menuItemOrder.includes(action.item.label)) {
|
|
117
|
+
return menuItemOrder;
|
|
118
|
+
}
|
|
119
|
+
return [...menuItemOrder, action.item.label];
|
|
120
|
+
}
|
|
121
|
+
default:
|
|
122
|
+
return menuItemOrder;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function menuItemsReducer(state, action) {
|
|
126
|
+
switch (action.type) {
|
|
127
|
+
case 'REGISTER_PANEL':
|
|
128
|
+
case 'UNREGISTER_PANEL':
|
|
129
|
+
// generate new menu items from original `menuItems` and updated `panelItems` and `menuItemOrder`
|
|
130
|
+
return generateMenuItems({
|
|
131
|
+
currentMenuItems: state.menuItems,
|
|
132
|
+
panelItems: state.panelItems,
|
|
133
|
+
menuItemOrder: state.menuItemOrder,
|
|
134
|
+
shouldReset: false
|
|
135
|
+
});
|
|
136
|
+
case 'RESET_ALL':
|
|
137
|
+
return generateMenuItems({
|
|
138
|
+
panelItems: state.panelItems,
|
|
139
|
+
menuItemOrder: state.menuItemOrder,
|
|
140
|
+
shouldReset: true
|
|
141
|
+
});
|
|
142
|
+
case 'UPDATE_VALUE':
|
|
143
|
+
{
|
|
144
|
+
const oldValue = state.menuItems[action.group][action.label];
|
|
145
|
+
if (action.value === oldValue) {
|
|
146
|
+
return state.menuItems;
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
...state.menuItems,
|
|
150
|
+
[action.group]: {
|
|
151
|
+
...state.menuItems[action.group],
|
|
152
|
+
[action.label]: action.value
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
case 'TOGGLE_VALUE':
|
|
157
|
+
{
|
|
158
|
+
const currentItem = state.panelItems.find(item => item.label === action.label);
|
|
159
|
+
if (!currentItem) {
|
|
160
|
+
return state.menuItems;
|
|
161
|
+
}
|
|
162
|
+
const menuGroup = currentItem.isShownByDefault ? 'default' : 'optional';
|
|
163
|
+
const newMenuItems = {
|
|
164
|
+
...state.menuItems,
|
|
165
|
+
[menuGroup]: {
|
|
166
|
+
...state.menuItems[menuGroup],
|
|
167
|
+
[action.label]: !state.menuItems[menuGroup][action.label]
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
return newMenuItems;
|
|
171
|
+
}
|
|
172
|
+
default:
|
|
173
|
+
return state.menuItems;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function panelReducer(state, action) {
|
|
177
|
+
const panelItems = panelItemsReducer(state.panelItems, action);
|
|
178
|
+
const menuItemOrder = menuItemOrderReducer(state.menuItemOrder, action);
|
|
179
|
+
// `menuItemsReducer` is a bit unusual because it generates new state from original `menuItems`
|
|
180
|
+
// and the updated `panelItems` and `menuItemOrder`.
|
|
181
|
+
const menuItems = menuItemsReducer({
|
|
182
|
+
panelItems,
|
|
183
|
+
menuItemOrder,
|
|
184
|
+
menuItems: state.menuItems
|
|
185
|
+
}, action);
|
|
186
|
+
return {
|
|
187
|
+
panelItems,
|
|
188
|
+
menuItemOrder,
|
|
189
|
+
menuItems
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function resetAllFiltersReducer(filters, action) {
|
|
193
|
+
switch (action.type) {
|
|
194
|
+
case 'REGISTER':
|
|
195
|
+
return [...filters, action.filter];
|
|
196
|
+
case 'UNREGISTER':
|
|
197
|
+
return filters.filter(f => f !== action.filter);
|
|
198
|
+
default:
|
|
199
|
+
return filters;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const isMenuItemTypeEmpty = obj => Object.keys(obj).length === 0;
|
|
75
203
|
function useToolsPanel(props) {
|
|
76
204
|
const {
|
|
77
205
|
className,
|
|
@@ -98,32 +226,18 @@ function useToolsPanel(props) {
|
|
|
98
226
|
}, [wasResetting]);
|
|
99
227
|
|
|
100
228
|
// Allow panel items to register themselves.
|
|
101
|
-
const [
|
|
102
|
-
|
|
103
|
-
|
|
229
|
+
const [{
|
|
230
|
+
panelItems,
|
|
231
|
+
menuItems
|
|
232
|
+
}, panelDispatch] = (0, _element.useReducer)(panelReducer, undefined, emptyState);
|
|
233
|
+
const [resetAllFilters, dispatchResetAllFilters] = (0, _element.useReducer)(resetAllFiltersReducer, []);
|
|
104
234
|
const registerPanelItem = (0, _element.useCallback)(item => {
|
|
105
235
|
// Add item to panel items.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// first. This can happen when an item is moved between the default
|
|
110
|
-
// and optional groups.
|
|
111
|
-
const existingIndex = newItems.findIndex(oldItem => oldItem.label === item.label);
|
|
112
|
-
if (existingIndex !== -1) {
|
|
113
|
-
newItems.splice(existingIndex, 1);
|
|
114
|
-
}
|
|
115
|
-
return [...newItems, item];
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
// Track the initial order of item registration. This is used for
|
|
119
|
-
// maintaining menu item order later.
|
|
120
|
-
setMenuItemOrder(items => {
|
|
121
|
-
if (items.includes(item.label)) {
|
|
122
|
-
return items;
|
|
123
|
-
}
|
|
124
|
-
return [...items, item.label];
|
|
236
|
+
panelDispatch({
|
|
237
|
+
type: 'REGISTER_PANEL',
|
|
238
|
+
item
|
|
125
239
|
});
|
|
126
|
-
}, [
|
|
240
|
+
}, []);
|
|
127
241
|
|
|
128
242
|
// Panels need to deregister on unmount to avoid orphans in menu state.
|
|
129
243
|
// This is an issue when panel items are being injected via SlotFills.
|
|
@@ -132,96 +246,58 @@ function useToolsPanel(props) {
|
|
|
132
246
|
// controls, e.g. both panels have a "padding" control, the
|
|
133
247
|
// deregistration of the first panel doesn't occur until after the
|
|
134
248
|
// registration of the next.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (index !== -1) {
|
|
139
|
-
newItems.splice(index, 1);
|
|
140
|
-
}
|
|
141
|
-
return newItems;
|
|
142
|
-
});
|
|
143
|
-
}, [setPanelItems]);
|
|
144
|
-
const registerResetAllFilter = (0, _element.useCallback)(newFilter => {
|
|
145
|
-
setResetAllFilters(filters => {
|
|
146
|
-
return [...filters, newFilter];
|
|
249
|
+
panelDispatch({
|
|
250
|
+
type: 'UNREGISTER_PANEL',
|
|
251
|
+
label
|
|
147
252
|
});
|
|
148
|
-
}, [
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
253
|
+
}, []);
|
|
254
|
+
const registerResetAllFilter = (0, _element.useCallback)(filter => {
|
|
255
|
+
dispatchResetAllFilters({
|
|
256
|
+
type: 'REGISTER',
|
|
257
|
+
filter
|
|
152
258
|
});
|
|
153
|
-
}, [
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
optional: {}
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
// Setup menuItems state as panel items register themselves.
|
|
162
|
-
(0, _element.useEffect)(() => {
|
|
163
|
-
setMenuItems(prevState => {
|
|
164
|
-
const items = generateMenuItems({
|
|
165
|
-
panelItems,
|
|
166
|
-
shouldReset: false,
|
|
167
|
-
currentMenuItems: prevState,
|
|
168
|
-
menuItemOrder
|
|
169
|
-
});
|
|
170
|
-
return items;
|
|
259
|
+
}, []);
|
|
260
|
+
const deregisterResetAllFilter = (0, _element.useCallback)(filter => {
|
|
261
|
+
dispatchResetAllFilters({
|
|
262
|
+
type: 'UNREGISTER',
|
|
263
|
+
filter
|
|
171
264
|
});
|
|
172
|
-
}, [
|
|
265
|
+
}, []);
|
|
173
266
|
|
|
174
267
|
// Updates the status of the panel’s menu items. For default items the
|
|
175
268
|
// value represents whether it differs from the default and for optional
|
|
176
269
|
// items whether the item is shown.
|
|
177
270
|
const flagItemCustomization = (0, _element.useCallback)((value, label, group = 'default') => {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
[label]: value
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
return newState;
|
|
271
|
+
panelDispatch({
|
|
272
|
+
type: 'UPDATE_VALUE',
|
|
273
|
+
group,
|
|
274
|
+
label,
|
|
275
|
+
value
|
|
187
276
|
});
|
|
188
|
-
}, [
|
|
277
|
+
}, []);
|
|
189
278
|
|
|
190
279
|
// Whether all optional menu items are hidden or not must be tracked
|
|
191
280
|
// in order to later determine if the panel display is empty and handle
|
|
192
281
|
// conditional display of a plus icon to indicate the presence of further
|
|
193
282
|
// menu items.
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const allControlsHidden = !Object.entries(menuItems.optional).some(([, isSelected]) => isSelected);
|
|
198
|
-
setAreAllOptionalControlsHidden(allControlsHidden);
|
|
199
|
-
}
|
|
200
|
-
}, [menuItems, setAreAllOptionalControlsHidden]);
|
|
283
|
+
const areAllOptionalControlsHidden = (0, _element.useMemo)(() => {
|
|
284
|
+
return isMenuItemTypeEmpty(menuItems.default) && !isMenuItemTypeEmpty(menuItems.optional) && Object.values(menuItems.optional).every(isSelected => !isSelected);
|
|
285
|
+
}, [menuItems]);
|
|
201
286
|
const cx = (0, _useCx.useCx)();
|
|
202
287
|
const classes = (0, _element.useMemo)(() => {
|
|
203
288
|
const wrapperStyle = hasInnerWrapper && styles.ToolsPanelWithInnerWrapper(DEFAULT_COLUMNS);
|
|
204
|
-
const emptyStyle =
|
|
289
|
+
const emptyStyle = areAllOptionalControlsHidden && styles.ToolsPanelHiddenInnerWrapper;
|
|
205
290
|
return cx(styles.ToolsPanel(DEFAULT_COLUMNS), wrapperStyle, emptyStyle, className);
|
|
206
|
-
}, [areAllOptionalControlsHidden, className, cx, hasInnerWrapper
|
|
291
|
+
}, [areAllOptionalControlsHidden, className, cx, hasInnerWrapper]);
|
|
207
292
|
|
|
208
293
|
// Toggle the checked state of a menu item which is then used to determine
|
|
209
294
|
// display of the item within the panel.
|
|
210
295
|
const toggleItem = (0, _element.useCallback)(label => {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const newMenuItems = {
|
|
217
|
-
...menuItems,
|
|
218
|
-
[menuGroup]: {
|
|
219
|
-
...menuItems[menuGroup],
|
|
220
|
-
[label]: !menuItems[menuGroup][label]
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
setMenuItems(newMenuItems);
|
|
224
|
-
}, [menuItems, panelItems, setMenuItems]);
|
|
296
|
+
panelDispatch({
|
|
297
|
+
type: 'TOGGLE_VALUE',
|
|
298
|
+
label
|
|
299
|
+
});
|
|
300
|
+
}, []);
|
|
225
301
|
|
|
226
302
|
// Resets display of children and executes resetAll callback if available.
|
|
227
303
|
const resetAllItems = (0, _element.useCallback)(() => {
|
|
@@ -231,30 +307,28 @@ function useToolsPanel(props) {
|
|
|
231
307
|
}
|
|
232
308
|
|
|
233
309
|
// Turn off display of all non-default items.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
menuItemOrder,
|
|
237
|
-
shouldReset: true
|
|
310
|
+
panelDispatch({
|
|
311
|
+
type: 'RESET_ALL'
|
|
238
312
|
});
|
|
239
|
-
|
|
240
|
-
}, [panelItems, resetAllFilters, resetAll, setMenuItems, menuItemOrder]);
|
|
313
|
+
}, [resetAllFilters, resetAll]);
|
|
241
314
|
|
|
242
315
|
// Assist ItemGroup styling when there are potentially hidden placeholder
|
|
243
316
|
// items by identifying first & last items that are toggled on for display.
|
|
244
317
|
const getFirstVisibleItemLabel = items => {
|
|
245
318
|
const optionalItems = menuItems.optional || {};
|
|
246
|
-
const firstItem = items.find(item => item.isShownByDefault ||
|
|
319
|
+
const firstItem = items.find(item => item.isShownByDefault || optionalItems[item.label]);
|
|
247
320
|
return firstItem?.label;
|
|
248
321
|
};
|
|
249
322
|
const firstDisplayedItem = getFirstVisibleItemLabel(panelItems);
|
|
250
323
|
const lastDisplayedItem = getFirstVisibleItemLabel([...panelItems].reverse());
|
|
324
|
+
const hasMenuItems = panelItems.length > 0;
|
|
251
325
|
const panelContext = (0, _element.useMemo)(() => ({
|
|
252
326
|
areAllOptionalControlsHidden,
|
|
253
327
|
deregisterPanelItem,
|
|
254
328
|
deregisterResetAllFilter,
|
|
255
329
|
firstDisplayedItem,
|
|
256
330
|
flagItemCustomization,
|
|
257
|
-
hasMenuItems
|
|
331
|
+
hasMenuItems,
|
|
258
332
|
isResetting: isResettingRef.current,
|
|
259
333
|
lastDisplayedItem,
|
|
260
334
|
menuItems,
|
|
@@ -264,7 +338,7 @@ function useToolsPanel(props) {
|
|
|
264
338
|
shouldRenderPlaceholderItems,
|
|
265
339
|
__experimentalFirstVisibleItemClass,
|
|
266
340
|
__experimentalLastVisibleItemClass
|
|
267
|
-
}), [areAllOptionalControlsHidden, deregisterPanelItem, deregisterResetAllFilter, firstDisplayedItem, flagItemCustomization, lastDisplayedItem, menuItems, panelId,
|
|
341
|
+
}), [areAllOptionalControlsHidden, deregisterPanelItem, deregisterResetAllFilter, firstDisplayedItem, flagItemCustomization, lastDisplayedItem, menuItems, panelId, hasMenuItems, registerResetAllFilter, registerPanelItem, shouldRenderPlaceholderItems, __experimentalFirstVisibleItemClass, __experimentalLastVisibleItemClass]);
|
|
268
342
|
return {
|
|
269
343
|
...otherProps,
|
|
270
344
|
headingLevel,
|