@wordpress/boot 0.26.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build-module/components/app/index.mjs.map +1 -1
- package/build-module/components/app/router.mjs +24 -24
- package/build-module/components/app/router.mjs.map +1 -1
- package/build-module/components/app/use-route-focus.mjs +162 -0
- package/build-module/components/app/use-route-focus.mjs.map +1 -0
- package/build-module/components/app/use-route-title.mjs +6 -1
- package/build-module/components/app/use-route-title.mjs.map +1 -1
- package/build-module/components/canvas/index.mjs +1 -1
- package/build-module/components/canvas/index.mjs.map +1 -1
- package/build-module/components/canvas/use-navigate-to-entity-record.mjs +20 -12
- package/build-module/components/canvas/use-navigate-to-entity-record.mjs.map +1 -1
- package/build-module/components/error-boundary/index.mjs +2 -2
- package/build-module/components/error-boundary/index.mjs.map +1 -1
- package/build-module/components/navigation/drilldown-item/index.mjs +3 -3
- package/build-module/components/navigation/drilldown-item/index.mjs.map +1 -1
- package/build-module/components/navigation/dropdown-item/index.mjs +3 -3
- package/build-module/components/navigation/dropdown-item/index.mjs.map +1 -1
- package/build-module/components/navigation/navigation-item/index.mjs +3 -3
- package/build-module/components/navigation/navigation-item/index.mjs.map +1 -1
- package/build-module/components/navigation/navigation-screen/index.mjs +7 -7
- package/build-module/components/navigation/navigation-screen/index.mjs.map +1 -1
- package/build-module/components/navigation/router-link-item.mjs.map +1 -1
- package/build-module/components/plugin-area/index.mjs +5 -1
- package/build-module/components/plugin-area/index.mjs.map +1 -1
- package/build-module/components/root/index.mjs +31 -28
- package/build-module/components/root/index.mjs.map +1 -1
- package/build-module/components/root/single-page.mjs +28 -25
- package/build-module/components/root/single-page.mjs.map +1 -1
- package/build-module/components/save-button/index.mjs +8 -3
- package/build-module/components/save-button/index.mjs.map +1 -1
- package/build-module/components/save-panel/index.mjs +3 -1
- package/build-module/components/save-panel/index.mjs.map +1 -1
- package/build-module/components/sidebar/index.mjs +11 -11
- package/build-module/components/sidebar/index.mjs.map +1 -1
- package/build-types/components/app/use-route-focus.d.ts +14 -0
- package/build-types/components/app/use-route-focus.d.ts.map +1 -0
- package/build-types/components/canvas/use-navigate-to-entity-record.d.ts +3 -1
- package/build-types/components/canvas/use-navigate-to-entity-record.d.ts.map +1 -1
- package/build-types/components/root/index.d.ts.map +1 -1
- package/build-types/components/root/single-page.d.ts.map +1 -1
- package/build-types/components/save-button/index.d.ts.map +1 -1
- package/build-types/components/save-panel/index.d.ts.map +1 -1
- package/build-types/components/sidebar/index.d.ts.map +1 -1
- package/package.json +35 -28
- package/src/components/app/test/fixtures/own-focus.tsx +22 -0
- package/src/components/app/test/fixtures/settings-general.tsx +21 -0
- package/src/components/app/test/fixtures/settings.tsx +10 -0
- package/src/components/app/test/navigation-focus.browser.test.tsx +108 -0
- package/src/components/app/use-route-focus.ts +53 -0
- package/src/components/canvas/index.tsx +1 -1
- package/src/components/canvas/use-navigate-to-entity-record.ts +33 -16
- package/src/components/error-boundary/index.tsx +2 -2
- package/src/components/navigation/drilldown-item/index.tsx +3 -3
- package/src/components/navigation/dropdown-item/index.tsx +3 -3
- package/src/components/navigation/navigation-item/index.tsx +3 -3
- package/src/components/navigation/navigation-item/style.module.scss +13 -7
- package/src/components/navigation/navigation-screen/index.tsx +2 -2
- package/src/components/navigation/navigation-screen/style.module.scss +1 -1
- package/src/components/navigation/router-link-item.tsx +3 -3
- package/src/components/root/_layout.module.scss +8 -1
- package/src/components/root/index.tsx +11 -4
- package/src/components/root/single-page.tsx +4 -1
- package/src/components/root/test/admin-scheme-sidebar.browser.test.tsx +120 -0
- package/src/components/save-button/index.tsx +7 -2
- package/src/components/save-panel/index.tsx +4 -1
- package/src/components/sidebar/index.tsx +10 -6
- package/src/components/sidebar/style.module.scss +1 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useEffect, useState } from "@wordpress/element";
|
|
2
2
|
import { useSelect } from "@wordpress/data";
|
|
3
3
|
import { __, _n, sprintf } from "@wordpress/i18n";
|
|
4
|
-
import { store } from "@wordpress/core-data";
|
|
4
|
+
import { privateApis, store } from "@wordpress/core-data";
|
|
5
5
|
import { ariaKeyShortcut, displayShortcut, shortcutAriaLabel } from "@wordpress/keycodes";
|
|
6
6
|
import { check } from "@wordpress/icons";
|
|
7
|
-
import { EntitiesSavedStates } from "@wordpress/editor";
|
|
8
7
|
import { Button, Modal } from "@wordpress/components";
|
|
9
8
|
import { KeyboardShortcutDescription, KeyboardShortcutDisplay, Tooltip, useKeyboardShortcutProps } from "@wordpress/ui";
|
|
10
9
|
import useSaveShortcut from "../save-panel/use-save-shortcut.mjs";
|
|
10
|
+
import { unlock } from "../../lock-unlock.mjs";
|
|
11
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
12
|
// packages/style-runtime/src/index.ts
|
|
13
13
|
const STYLE_HASH_ATTRIBUTE = "data-wp-hash";
|
|
@@ -118,6 +118,7 @@ var style_module_default = {
|
|
|
118
118
|
"shortcut": "_0e6f3a8336688e3f__shortcut"
|
|
119
119
|
};
|
|
120
120
|
// packages/boot/src/components/save-button/index.tsx
|
|
121
|
+
const { EntitiesSavedStates } = unlock(privateApis);
|
|
121
122
|
function SaveButton() {
|
|
122
123
|
const [isSaveViewOpen, setIsSaveViewOpened] = useState(false);
|
|
123
124
|
const { isSaving, dirtyEntityRecordsCount } = useSelect((select) => {
|
|
@@ -152,7 +153,11 @@ function SaveButton() {
|
|
|
152
153
|
const disabled = isSaving || isInSavedState;
|
|
153
154
|
const getLabel = () => {
|
|
154
155
|
if (isInSavedState) return __("Saved");
|
|
155
|
-
return sprintf(
|
|
156
|
+
return sprintf(
|
|
157
|
+
/** translators: %d: number of unsaved changes (number). */
|
|
158
|
+
_n("Review %d change…", "Review %d changes…", dirtyEntityRecordsCount),
|
|
159
|
+
dirtyEntityRecordsCount
|
|
160
|
+
);
|
|
156
161
|
};
|
|
157
162
|
const label = getLabel();
|
|
158
163
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(Tooltip.Root, { children: [/* @__PURE__ */ jsxs(Tooltip.Trigger, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["coreStore","styles"],"sources":["../../../../style-runtime/src/index.ts","../../../src/components/save-button/style.module.scss","../../../src/components/save-button/index.tsx"],"sourcesContent":["type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n","import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"da0f7c3ff6\", \"._4e8b2ecc322dfc1f__save-button{width:100%}._0e6f3a8336688e3f__shortcut:not(:first-child){margin-inline-start:8px}\");\n}\nexport default {\"save-button\":\"_4e8b2ecc322dfc1f__save-button\",\"shortcut\":\"_0e6f3a8336688e3f__shortcut\"};\n","import { useEffect, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { _n, __, sprintf } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tariaKeyShortcut,\n\tdisplayShortcut,\n\tshortcutAriaLabel,\n} from '@wordpress/keycodes';\nimport { check } from '@wordpress/icons';\nimport { EntitiesSavedStates } from '@wordpress/editor';\nimport { Button, Modal } from '@wordpress/components';\nimport {\n\tKeyboardShortcutDescription,\n\tKeyboardShortcutDisplay,\n\tTooltip,\n\tuseKeyboardShortcutProps,\n} from '@wordpress/ui';\nimport styles from './style.module.scss';\nimport useSaveShortcut from '../save-panel/use-save-shortcut';\n\nexport default function SaveButton() {\n\tconst [ isSaveViewOpen, setIsSaveViewOpened ] = useState( false );\n\tconst { isSaving, dirtyEntityRecordsCount } = useSelect( ( select ) => {\n\t\tconst { isSavingEntityRecord, __experimentalGetDirtyEntityRecords } =\n\t\t\tselect( coreStore );\n\t\tconst dirtyEntityRecords = __experimentalGetDirtyEntityRecords();\n\t\treturn {\n\t\t\tisSaving: dirtyEntityRecords.some( ( record ) =>\n\t\t\t\tisSavingEntityRecord( record.kind, record.name, record.key )\n\t\t\t),\n\t\t\tdirtyEntityRecordsCount: dirtyEntityRecords.length,\n\t\t};\n\t}, [] );\n\tconst [ showSavedState, setShowSavedState ] = useState( false );\n\n\tuseEffect( () => {\n\t\tif ( isSaving ) {\n\t\t\t// Proactively expect to show saved state. This is done once save\n\t\t\t// starts to avoid race condition where setting it after would cause\n\t\t\t// the button to be unmounted before state is updated.\n\t\t\tsetShowSavedState( true );\n\t\t}\n\t}, [ isSaving ] );\n\n\tconst hasChanges = dirtyEntityRecordsCount > 0;\n\n\t// Handle save failure case: If we were showing saved state but saving\n\t// failed, reset to show changes again.\n\tuseEffect( () => {\n\t\tif ( ! isSaving && hasChanges ) {\n\t\t\tsetShowSavedState( false );\n\t\t}\n\t}, [ isSaving, hasChanges ] );\n\n\tfunction hideSavedState() {\n\t\tif ( showSavedState ) {\n\t\t\tsetShowSavedState( false );\n\t\t}\n\t}\n\n\tconst shouldShowButton = hasChanges || showSavedState;\n\n\tuseSaveShortcut( { openSavePanel: () => setIsSaveViewOpened( true ) } );\n\tconst shortcut = {\n\t\tdisplayShortcut: displayShortcut.primary( 's' ),\n\t\tariaKeyShortcut: ariaKeyShortcut.primary( 's' ),\n\t\tlabel: shortcutAriaLabel.primary( 's' ),\n\t};\n\tconst { descriptionId, targetProps } = useKeyboardShortcutProps( {\n\t\tshortcut,\n\t} );\n\n\tif ( ! shouldShowButton ) {\n\t\treturn null;\n\t}\n\n\tconst isInSavedState = showSavedState && ! hasChanges;\n\tconst disabled = isSaving || isInSavedState;\n\n\tconst getLabel = () => {\n\t\tif ( isInSavedState ) {\n\t\t\treturn __( 'Saved' );\n\t\t}\n\t\treturn sprintf(\n\t\t\t// translators: %d: number of unsaved changes (number).\n\t\t\t_n(\n\t\t\t\t'Review %d change…',\n\t\t\t\t'Review %d changes…',\n\t\t\t\tdirtyEntityRecordsCount\n\t\t\t),\n\t\t\tdirtyEntityRecordsCount\n\t\t);\n\t};\n\tconst label = getLabel();\n\n\treturn (\n\t\t<>\n\t\t\t<Tooltip.Root>\n\t\t\t\t<Tooltip.Trigger\n\t\t\t\t\t{ ...targetProps }\n\t\t\t\t\trender={\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\tonClick={ () => setIsSaveViewOpened( true ) }\n\t\t\t\t\t\t\tonBlur={ hideSavedState }\n\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t\tclassName={ styles[ 'save-button' ] }\n\t\t\t\t\t\t\ticon={ isInSavedState ? check : undefined }\n\t\t\t\t\t\t/>\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ label }\n\t\t\t\t\t{ descriptionId && (\n\t\t\t\t\t\t<KeyboardShortcutDescription\n\t\t\t\t\t\t\tdescriptionId={ descriptionId }\n\t\t\t\t\t\t\tshortcut={ shortcut }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</Tooltip.Trigger>\n\t\t\t\t<Tooltip.Popup>\n\t\t\t\t\t{ hasChanges && <span>{ label }</span> }\n\t\t\t\t\t<KeyboardShortcutDisplay\n\t\t\t\t\t\tclassName={ styles.shortcut }\n\t\t\t\t\t\tshortcut={ shortcut }\n\t\t\t\t\t/>\n\t\t\t\t</Tooltip.Popup>\n\t\t\t</Tooltip.Root>\n\t\t\t{ isSaveViewOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Review changes' ) }\n\t\t\t\t\tonRequestClose={ () => setIsSaveViewOpened( false ) }\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t>\n\t\t\t\t\t<EntitiesSaved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AQ,GAAI,gBAAiB;EAC7B,sBAAuB,oBAAqB,KAAM;EAClD,MAAK;EAEL,UAAA,oBAAC,qBAAD;GACC,aAAc,oBAAqB,KAAM;GACzC,SAAQ;EACR,CAAA;CACK,CAAA,CAEP,EAAA,CAAA;AAEJ"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["coreDataPrivateApis","coreStore","styles"],"sources":["../../../../style-runtime/src/index.ts","../../../src/components/save-button/style.module.scss","../../../src/components/save-button/index.tsx"],"sourcesContent":["type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n","import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"da0f7c3ff6\", \"._4e8b2ecc322dfc1f__save-button{width:100%}._0e6f3a8336688e3f__shortcut:not(:first-child){margin-inline-start:8px}\");\n}\nexport default {\"save-button\":\"_4e8b2ecc322dfc1f__save-button\",\"shortcut\":\"_0e6f3a8336688e3f__shortcut\"};\n","import { useEffect, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { _n, __, sprintf } from '@wordpress/i18n';\nimport {\n\tprivateApis as coreDataPrivateApis,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport {\n\tariaKeyShortcut,\n\tdisplayShortcut,\n\tshortcutAriaLabel,\n} from '@wordpress/keycodes';\nimport { check } from '@wordpress/icons';\nimport { Button, Modal } from '@wordpress/components';\nimport {\n\tKeyboardShortcutDescription,\n\tKeyboardShortcutDisplay,\n\tTooltip,\n\tuseKeyboardShortcutProps,\n} from '@wordpress/ui';\nimport styles from './style.module.scss';\nimport useSaveShortcut from '../save-panel/use-save-shortcut';\nimport { unlock } from '../../lock-unlock';\n\nconst { EntitiesSavedStates } = unlock( coreDataPrivateApis );\n\nexport default function SaveButton() {\n\tconst [ isSaveViewOpen, setIsSaveViewOpened ] = useState( false );\n\tconst { isSaving, dirtyEntityRecordsCount } = useSelect( ( select ) => {\n\t\tconst { isSavingEntityRecord, __experimentalGetDirtyEntityRecords } =\n\t\t\tselect( coreStore );\n\t\tconst dirtyEntityRecords = __experimentalGetDirtyEntityRecords();\n\t\treturn {\n\t\t\tisSaving: dirtyEntityRecords.some( ( record ) =>\n\t\t\t\tisSavingEntityRecord( record.kind, record.name, record.key )\n\t\t\t),\n\t\t\tdirtyEntityRecordsCount: dirtyEntityRecords.length,\n\t\t};\n\t}, [] );\n\tconst [ showSavedState, setShowSavedState ] = useState( false );\n\n\tuseEffect( () => {\n\t\tif ( isSaving ) {\n\t\t\t// Proactively expect to show saved state. This is done once save\n\t\t\t// starts to avoid race condition where setting it after would cause\n\t\t\t// the button to be unmounted before state is updated.\n\t\t\tsetShowSavedState( true );\n\t\t}\n\t}, [ isSaving ] );\n\n\tconst hasChanges = dirtyEntityRecordsCount > 0;\n\n\t// Handle save failure case: If we were showing saved state but saving\n\t// failed, reset to show changes again.\n\tuseEffect( () => {\n\t\tif ( ! isSaving && hasChanges ) {\n\t\t\tsetShowSavedState( false );\n\t\t}\n\t}, [ isSaving, hasChanges ] );\n\n\tfunction hideSavedState() {\n\t\tif ( showSavedState ) {\n\t\t\tsetShowSavedState( false );\n\t\t}\n\t}\n\n\tconst shouldShowButton = hasChanges || showSavedState;\n\n\tuseSaveShortcut( { openSavePanel: () => setIsSaveViewOpened( true ) } );\n\tconst shortcut = {\n\t\tdisplayShortcut: displayShortcut.primary( 's' ),\n\t\tariaKeyShortcut: ariaKeyShortcut.primary( 's' ),\n\t\tlabel: shortcutAriaLabel.primary( 's' ),\n\t};\n\tconst { descriptionId, targetProps } = useKeyboardShortcutProps( {\n\t\tshortcut,\n\t} );\n\n\tif ( ! shouldShowButton ) {\n\t\treturn null;\n\t}\n\n\tconst isInSavedState = showSavedState && ! hasChanges;\n\tconst disabled = isSaving || isInSavedState;\n\n\tconst getLabel = () => {\n\t\tif ( isInSavedState ) {\n\t\t\treturn __( 'Saved' );\n\t\t}\n\t\treturn sprintf(\n\t\t\t// translators: %d: number of unsaved changes (number).\n\t\t\t_n(\n\t\t\t\t'Review %d change…',\n\t\t\t\t'Review %d changes…',\n\t\t\t\tdirtyEntityRecordsCount\n\t\t\t),\n\t\t\tdirtyEntityRecordsCount\n\t\t);\n\t};\n\tconst label = getLabel();\n\n\treturn (\n\t\t<>\n\t\t\t<Tooltip.Root>\n\t\t\t\t<Tooltip.Trigger\n\t\t\t\t\t{ ...targetProps }\n\t\t\t\t\trender={\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\tonClick={ () => setIsSaveViewOpened( true ) }\n\t\t\t\t\t\t\tonBlur={ hideSavedState }\n\t\t\t\t\t\t\tdisabled={ disabled }\n\t\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t\tclassName={ styles[ 'save-button' ] }\n\t\t\t\t\t\t\ticon={ isInSavedState ? check : undefined }\n\t\t\t\t\t\t/>\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{ label }\n\t\t\t\t\t{ descriptionId && (\n\t\t\t\t\t\t<KeyboardShortcutDescription\n\t\t\t\t\t\t\tdescriptionId={ descriptionId }\n\t\t\t\t\t\t\tshortcut={ shortcut }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</Tooltip.Trigger>\n\t\t\t\t<Tooltip.Popup>\n\t\t\t\t\t{ hasChanges && <span>{ label }</span> }\n\t\t\t\t\t<KeyboardShortcutDisplay\n\t\t\t\t\t\tclassName={ styles.shortcut }\n\t\t\t\t\t\tshortcut={ shortcut }\n\t\t\t\t\t/>\n\t\t\t\t</Tooltip.Popup>\n\t\t\t</Tooltip.Root>\n\t\t\t{ isSaveViewOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Review changes' ) }\n\t\t\t\t\tonRequestClose={ () => setIsSaveViewOpened( false ) }\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t>\n\t\t\t\t\t<EntitiesSavedStates\n\t\t\t\t\t\tclose={ () => setIsSaveViewOpened( false ) }\n\t\t\t\t\t\tvariant=\"inline\"\n\t\t\t\t\t/>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;AAUA,MAAM,uBAAuB;;;;;;;;;AAU7B,SAAS,aAAa;CACrB,MAAM,cAAc;CAEpB,IAAK,YAAY,kBAChB,OAAO,YAAY;CAGpB,YAAY,mBAAmB;EAC9B,2BAAW,IAAI,IAAI;EACnB,wBAAQ,IAAI,IAAI;EAChB,gCAAgB,IAAI,QAAQ;CAC7B;CAEA,IAAK,OAAO,aAAa,aACxB,iBAAkB,QAAS;CAG5B,OAAO,YAAY;AACpB;;;;;;;;;AAUA,SAAS,0BACR,gBACA,MACU;CACV,IAAK,CAAE,eAAe,MACrB,OAAO;CAGR,KAAM,MAAM,SAAS,eAAe,KAAK,iBACxC,SAAU,qBAAsB,EACjC,GACC,IAAK,MAAM,aAAc,oBAAqB,MAAM,MACnD,OAAO;CAIT,OAAO;AACR;;;;;;;;;AAUA,SAAS,YAAa,gBAA0B,MAAc,KAAc;CAC3E,IAAK,CAAE,eAAe,MACrB;CAGD,MAAM,UAAU,WAAW;CAC3B,IAAI,iBAAiB,QAAQ,eAAe,IAAK,cAAe;CAEhE,IAAK,CAAE,gBAAiB;EACvB,iCAAiB,IAAI,IAAI;EACzB,QAAQ,eAAe,IAAK,gBAAgB,cAAe;CAC5D;CAEA,IAAK,eAAe,IAAK,IAAK,GAC7B;CAMD,IAAK,0BAA2B,gBAAgB,IAAK,GAAI;EACxD,eAAe,IAAK,IAAK;EACzB;CACD;CAEA,MAAM,QAAQ,eAAe,cAAe,OAAQ;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,CAAA,GAAA,qBAAC,QAAQ,OAAT,EAAA,UAAA,CACG,cAAc,oBAAC,QAAD,EAAA,UAAQ,MAAa,CAAA,GACrC,oBAAC,yBAAD;EACC,WAAYA,qBAAO;EACR;CACX,CAAA,CACa,EAAA,CAAA,CACF,EAAA,CAAA,GACZ,kBACD,oBAAC,OAAD;EACC,OAAQ,GAAI,gBAAiB;EAC7B,sBAAuB,oBAAqB,KAAM;EAClD,MAAK;EAEL,UAAA,oBAAC,qBAAD;GACC,aAAc,oBAAqB,KAAM;GACzC,SAAQ;EACR,CAAA;CACK,CAAA,CAEP,EAAA,CAAA;AAEJ"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useState } from "@wordpress/element";
|
|
2
2
|
import { Modal } from "@wordpress/components";
|
|
3
|
-
import {
|
|
3
|
+
import { privateApis } from "@wordpress/core-data";
|
|
4
4
|
import { __ } from "@wordpress/i18n";
|
|
5
5
|
import useSaveShortcut from "./use-save-shortcut.mjs";
|
|
6
|
+
import { unlock } from "../../lock-unlock.mjs";
|
|
6
7
|
import { jsx } from "react/jsx-runtime";
|
|
7
8
|
// packages/style-runtime/src/index.ts
|
|
8
9
|
const STYLE_HASH_ATTRIBUTE = "data-wp-hash";
|
|
@@ -110,6 +111,7 @@ function registerStyle(hash, css) {
|
|
|
110
111
|
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("e8f942db13", "@media (min-width:600px){._1bb5b45e7ea3b538__modal{width:600px}}");
|
|
111
112
|
var style_module_default = { "modal": "_1bb5b45e7ea3b538__modal" };
|
|
112
113
|
// packages/boot/src/components/save-panel/index.tsx
|
|
114
|
+
const { EntitiesSavedStates } = unlock(privateApis);
|
|
113
115
|
function SavePanel() {
|
|
114
116
|
const [isOpen, setIsOpen] = useState(false);
|
|
115
117
|
useSaveShortcut({ openSavePanel: () => setIsOpen(true) });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["styles"],"sources":["../../../../style-runtime/src/index.ts","../../../src/components/save-panel/style.module.scss","../../../src/components/save-panel/index.tsx"],"sourcesContent":["type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n","import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"e8f942db13\", \"@media (min-width:600px){._1bb5b45e7ea3b538__modal{width:600px}}\");\n}\nexport default {\"modal\":\"_1bb5b45e7ea3b538__modal\"};\n","import { useState } from '@wordpress/element';\nimport { Modal } from '@wordpress/components';\nimport {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["coreDataPrivateApis","styles"],"sources":["../../../../style-runtime/src/index.ts","../../../src/components/save-panel/style.module.scss","../../../src/components/save-panel/index.tsx"],"sourcesContent":["type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n","import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"e8f942db13\", \"@media (min-width:600px){._1bb5b45e7ea3b538__modal{width:600px}}\");\n}\nexport default {\"modal\":\"_1bb5b45e7ea3b538__modal\"};\n","import { useState } from '@wordpress/element';\nimport { Modal } from '@wordpress/components';\nimport { privateApis as coreDataPrivateApis } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport useSaveShortcut from './use-save-shortcut';\nimport { unlock } from '../../lock-unlock';\nimport styles from './style.module.scss';\n\nconst { EntitiesSavedStates } = unlock( coreDataPrivateApis );\n\nexport default function SavePanel() {\n\tconst [ isOpen, setIsOpen ] = useState< boolean >( false );\n\tuseSaveShortcut( {\n\t\topenSavePanel: () => setIsOpen( true ),\n\t} );\n\tif ( ! isOpen ) {\n\t\treturn false;\n\t}\n\treturn (\n\t\t<Modal\n\t\t\tclassName={ styles.modal }\n\t\t\tonRequestClose={ () => setIsOpen( false ) }\n\t\t\ttitle={ __( 'Review changes' ) }\n\t\t\tsize=\"small\"\n\t\t>\n\t\t\t<EntitiesSavedStates\n\t\t\t\tclose={ () => setIsOpen( false ) }\n\t\t\t\tvariant=\"inline\"\n\t\t\t/>\n\t\t</Modal>\n\t);\n}\n"],"mappings":";;;;;;;;AAUA,MAAM,uBAAuB;;;;;;;;;AAU7B,SAAS,aAAa;CACrB,MAAM,cAAc;CAEpB,IAAK,YAAY,kBAChB,OAAO,YAAY;CAGpB,YAAY,mBAAmB;EAC9B,2BAAW,IAAI,IAAI;EACnB,wBAAQ,IAAI,IAAI;EAChB,gCAAgB,IAAI,QAAQ;CAC7B;CAEA,IAAK,OAAO,aAAa,aACxB,iBAAkB,QAAS;CAG5B,OAAO,YAAY;AACpB;;;;;;;;;AAUA,SAAS,0BACR,gBACA,MACU;CACV,IAAK,CAAE,eAAe,MACrB,OAAO;CAGR,KAAM,MAAM,SAAS,eAAe,KAAK,iBACxC,SAAU,qBAAsB,EACjC,GACC,IAAK,MAAM,aAAc,oBAAqB,MAAM,MACnD,OAAO;CAIT,OAAO;AACR;;;;;;;;;AAUA,SAAS,YAAa,gBAA0B,MAAc,KAAc;CAC3E,IAAK,CAAE,eAAe,MACrB;CAGD,MAAM,UAAU,WAAW;CAC3B,IAAI,iBAAiB,QAAQ,eAAe,IAAK,cAAe;CAEhE,IAAK,CAAE,gBAAiB;EACvB,iCAAiB,IAAI,IAAI;EACzB,QAAQ,eAAe,IAAK,gBAAgB,cAAe;CAC5D;CAEA,IAAK,eAAe,IAAK,IAAK,GAC7B;CAMD,IAAK,0BAA2B,gBAAgB,IAAK,GAAI;EACxD,eAAe,IAAK,IAAK;EACzB;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EL,UAAA,oBAAC,qBAAD;GACC,aAAc,UAAW,KAAM;GAC/B,SAAQ;EACR,CAAA;CACK,CAAA;AAET"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Button } from "@wordpress/components";
|
|
2
1
|
import { useSelect } from "@wordpress/data";
|
|
3
2
|
import { __, isRTL } from "@wordpress/i18n";
|
|
4
3
|
import { chevronLeft, chevronRight } from "@wordpress/icons";
|
|
4
|
+
import { ButtonLink } from "@wordpress/ui";
|
|
5
5
|
import Navigation from "../navigation/index.mjs";
|
|
6
6
|
import SaveButton from "../save-button/index.mjs";
|
|
7
7
|
import { store } from "../../store/index.mjs";
|
|
@@ -109,23 +109,23 @@ function registerStyle(hash, css) {
|
|
|
109
109
|
for (const targetDocument of runtime.documents.keys()) injectStyle(targetDocument, hash, css);
|
|
110
110
|
}
|
|
111
111
|
// packages/boot/src/components/sidebar/style.module.scss
|
|
112
|
-
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("
|
|
112
|
+
if (typeof process === "undefined" || process.env.NODE_ENV !== "test") registerStyle("af10b27344", "._102c48b38f288206__scrollable{display:flex;flex-direction:column;height:100%;overflow:auto;position:relative}._3597f06eb43ce6f6__content{contain:content;flex-grow:1;position:relative}.a5292b69e9e562b6__footer{padding-block-end:8px;padding-block-start:16px;padding-inline-end:8px;padding-inline-start:16px}.ac9ccd553de41d59__back-button{justify-content:flex-start;margin-block-end:8px;margin-block-start:16px;margin-inline-end:12px;margin-inline-start:12px}");
|
|
113
113
|
var style_module_default = {
|
|
114
|
-
"scrollable": "
|
|
115
|
-
"content": "
|
|
116
|
-
"footer": "
|
|
117
|
-
"back-button": "
|
|
114
|
+
"scrollable": "_102c48b38f288206__scrollable",
|
|
115
|
+
"content": "_3597f06eb43ce6f6__content",
|
|
116
|
+
"footer": "a5292b69e9e562b6__footer",
|
|
117
|
+
"back-button": "ac9ccd553de41d59__back-button"
|
|
118
118
|
};
|
|
119
119
|
// packages/boot/src/components/sidebar/index.tsx
|
|
120
120
|
function DashboardBackButton() {
|
|
121
121
|
const dashboardLink = useSelect((select) => select(store).getDashboardLink(), []);
|
|
122
|
-
return /* @__PURE__ */
|
|
123
|
-
|
|
122
|
+
return /* @__PURE__ */ jsxs(ButtonLink, {
|
|
123
|
+
variant: "minimal",
|
|
124
|
+
tone: "neutral",
|
|
124
125
|
className: style_module_default["back-button"],
|
|
125
126
|
href: dashboardLink || "/",
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
children: __("Dashboard")
|
|
127
|
+
"aria-label": __("Go to the Dashboard"),
|
|
128
|
+
children: [/* @__PURE__ */ jsx(ButtonLink.Icon, { icon: isRTL() ? chevronRight : chevronLeft }), __("Dashboard")]
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
131
|
function Sidebar() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["bootStore","styles"],"sources":["../../../../style-runtime/src/index.ts","../../../src/components/sidebar/style.module.scss","../../../src/components/sidebar/index.tsx"],"sourcesContent":["type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n","import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["bootStore","styles"],"sources":["../../../../style-runtime/src/index.ts","../../../src/components/sidebar/style.module.scss","../../../src/components/sidebar/index.tsx"],"sourcesContent":["type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n","import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"af10b27344\", \"._102c48b38f288206__scrollable{display:flex;flex-direction:column;height:100%;overflow:auto;position:relative}._3597f06eb43ce6f6__content{contain:content;flex-grow:1;position:relative}.a5292b69e9e562b6__footer{padding-block-end:8px;padding-block-start:16px;padding-inline-end:8px;padding-inline-start:16px}.ac9ccd553de41d59__back-button{justify-content:flex-start;margin-block-end:8px;margin-block-start:16px;margin-inline-end:12px;margin-inline-start:12px}\");\n}\nexport default {\"scrollable\":\"_102c48b38f288206__scrollable\",\"content\":\"_3597f06eb43ce6f6__content\",\"footer\":\"a5292b69e9e562b6__footer\",\"back-button\":\"ac9ccd553de41d59__back-button\"};\n","import { useSelect } from '@wordpress/data';\nimport { __, isRTL } from '@wordpress/i18n';\nimport { chevronLeft, chevronRight } from '@wordpress/icons';\nimport {\n\t// eslint-disable-next-line @wordpress/use-recommended-components\n\tButtonLink,\n} from '@wordpress/ui';\nimport Navigation from '../navigation';\nimport SaveButton from '../save-button';\nimport { store as bootStore } from '../../store';\nimport styles from './style.module.scss';\n\nfunction DashboardBackButton() {\n\tconst dashboardLink = useSelect(\n\t\t( select ) => select( bootStore ).getDashboardLink(),\n\t\t[]\n\t);\n\treturn (\n\t\t<ButtonLink\n\t\t\tvariant=\"minimal\"\n\t\t\ttone=\"neutral\"\n\t\t\tclassName={ styles[ 'back-button' ] }\n\t\t\thref={ dashboardLink || '/' }\n\t\t\taria-label={ __( 'Go to the Dashboard' ) }\n\t\t>\n\t\t\t<ButtonLink.Icon icon={ isRTL() ? chevronRight : chevronLeft } />\n\t\t\t{ __( 'Dashboard' ) }\n\t\t</ButtonLink>\n\t);\n}\n\nexport default function Sidebar() {\n\treturn (\n\t\t<div className={ styles.scrollable }>\n\t\t\t<DashboardBackButton />\n\t\t\t<div className={ styles.content }>\n\t\t\t\t<Navigation />\n\t\t\t</div>\n\t\t\t<div className={ styles.footer }>\n\t\t\t\t<SaveButton />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,CAAa,CAAA;GACT,CAAA;EACD;;AAEP"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RefObject } from '@wordpress/element';
|
|
2
|
+
/**
|
|
3
|
+
* Hook that moves focus to the new page when a navigation removes the focused
|
|
4
|
+
* element, such as a breadcrumb link that becomes the new page's heading.
|
|
5
|
+
* Otherwise focus falls back to the document body, and keyboard and screen
|
|
6
|
+
* reader users lose their place.
|
|
7
|
+
*
|
|
8
|
+
* It runs in an effect after the route resolves. Effects of the page content
|
|
9
|
+
* run before it, so the page can move focus itself first.
|
|
10
|
+
*
|
|
11
|
+
* @param layoutRef Ref to the layout element that contains the stage.
|
|
12
|
+
*/
|
|
13
|
+
export default function useRouteFocus(layoutRef: RefObject<HTMLElement | null>): void;
|
|
14
|
+
//# sourceMappingURL=use-route-focus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-route-focus.d.ts","sourceRoot":"","sources":["../../../src/components/app/use-route-focus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAOvE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACpC,SAAS,EAAE,SAAS,CAAE,WAAW,GAAG,IAAI,CAAE,QAiC1C"}
|
|
@@ -12,9 +12,11 @@ interface NavigateParams {
|
|
|
12
12
|
* gates the inspector's edit affordance and `onNavigateToPreviousEntityRecord`
|
|
13
13
|
* gates the document bar's back button.
|
|
14
14
|
*
|
|
15
|
+
* @param postType Post type rendered in the canvas, if the route names one.
|
|
16
|
+
* @param postId Post ID rendered in the canvas, if the route names one.
|
|
15
17
|
* @return The two callbacks, for spreading into the editor settings.
|
|
16
18
|
*/
|
|
17
|
-
export default function useNavigateToEntityRecord(): {
|
|
19
|
+
export default function useNavigateToEntityRecord(postType?: string, postId?: string): {
|
|
18
20
|
onNavigateToEntityRecord: (params: NavigateParams) => void;
|
|
19
21
|
onNavigateToPreviousEntityRecord: (() => any) | undefined;
|
|
20
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-navigate-to-entity-record.d.ts","sourceRoot":"","sources":["../../../src/components/canvas/use-navigate-to-entity-record.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-navigate-to-entity-record.d.ts","sourceRoot":"","sources":["../../../src/components/canvas/use-navigate-to-entity-record.ts"],"names":[],"mappings":"AA8BA,UAAU,cAAc;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAChD,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM;uCAaJ,cAAc;;EA4FzB;AAED,UAAU,UAAU;IACnB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACvC;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAE,QAAQ,CAAC,EAAE,MAAM,cASvC,MAAM,SAAS,UAAU,EAAE,UAsDxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/root/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/root/index.tsx"],"names":[],"mappings":"AAgCA,MAAM,CAAC,OAAO,UAAU,IAAI,gCAiM3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"single-page.d.ts","sourceRoot":"","sources":["../../../src/components/root/single-page.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"single-page.d.ts","sourceRoot":"","sources":["../../../src/components/root/single-page.tsx"],"names":[],"mappings":"AAqBA;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,gCAoErC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/save-button/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/save-button/index.tsx"],"names":[],"mappings":"AA0BA,MAAM,CAAC,OAAO,UAAU,UAAU,uCA4HjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/save-panel/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/save-panel/index.tsx"],"names":[],"mappings":"AAUA,MAAM,CAAC,OAAO,UAAU,SAAS,wCAqBhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/sidebar/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/sidebar/index.tsx"],"names":[],"mappings":"AA+BA,MAAM,CAAC,OAAO,UAAU,OAAO,gCAY9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/boot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "Minimal boot package for WordPress admin pages.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -38,34 +38,41 @@
|
|
|
38
38
|
"wpScriptModuleExports": "./build-module/index.mjs",
|
|
39
39
|
"types": "build-types",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@wordpress/a11y": "^5.
|
|
42
|
-
"@wordpress/admin-ui": "^3.
|
|
43
|
-
"@wordpress/base-styles": "^15.
|
|
44
|
-
"@wordpress/components": "^
|
|
45
|
-
"@wordpress/compose": "^9.
|
|
46
|
-
"@wordpress/core-data": "^9.
|
|
47
|
-
"@wordpress/data": "^11.
|
|
48
|
-
"@wordpress/dom": "^5.
|
|
49
|
-
"@wordpress/editor": "^16.
|
|
50
|
-
"@wordpress/element": "^10.
|
|
51
|
-
"@wordpress/html-entities": "^5.
|
|
52
|
-
"@wordpress/i18n": "^7.
|
|
53
|
-
"@wordpress/icons": "^
|
|
54
|
-
"@wordpress/keyboard-shortcuts": "^6.
|
|
55
|
-
"@wordpress/keycodes": "^5.
|
|
56
|
-
"@wordpress/lazy-editor": "^2.
|
|
57
|
-
"@wordpress/notices": "^6.
|
|
58
|
-
"@wordpress/plugins": "^8.
|
|
59
|
-
"@wordpress/primitives": "^5.
|
|
60
|
-
"@wordpress/private-apis": "^3.
|
|
61
|
-
"@wordpress/react-inert-value": "^2.
|
|
62
|
-
"@wordpress/route": "^0.
|
|
63
|
-
"@wordpress/style-runtime": "^0.
|
|
64
|
-
"@wordpress/theme": "^
|
|
65
|
-
"@wordpress/ui": "^0.
|
|
66
|
-
"@wordpress/url": "^5.
|
|
41
|
+
"@wordpress/a11y": "^5.3.0",
|
|
42
|
+
"@wordpress/admin-ui": "^3.3.0",
|
|
43
|
+
"@wordpress/base-styles": "^15.2.0",
|
|
44
|
+
"@wordpress/components": "^45.1.0",
|
|
45
|
+
"@wordpress/compose": "^9.3.0",
|
|
46
|
+
"@wordpress/core-data": "^9.3.0",
|
|
47
|
+
"@wordpress/data": "^11.3.0",
|
|
48
|
+
"@wordpress/dom": "^5.3.0",
|
|
49
|
+
"@wordpress/editor": "^16.3.0",
|
|
50
|
+
"@wordpress/element": "^10.3.0",
|
|
51
|
+
"@wordpress/html-entities": "^5.3.0",
|
|
52
|
+
"@wordpress/i18n": "^7.3.0",
|
|
53
|
+
"@wordpress/icons": "^21.1.0",
|
|
54
|
+
"@wordpress/keyboard-shortcuts": "^6.3.0",
|
|
55
|
+
"@wordpress/keycodes": "^5.3.0",
|
|
56
|
+
"@wordpress/lazy-editor": "^2.3.0",
|
|
57
|
+
"@wordpress/notices": "^6.3.0",
|
|
58
|
+
"@wordpress/plugins": "^8.3.0",
|
|
59
|
+
"@wordpress/primitives": "^5.3.0",
|
|
60
|
+
"@wordpress/private-apis": "^3.3.0",
|
|
61
|
+
"@wordpress/react-inert-value": "^2.3.0",
|
|
62
|
+
"@wordpress/route": "^0.27.0",
|
|
63
|
+
"@wordpress/style-runtime": "^0.17.0",
|
|
64
|
+
"@wordpress/theme": "^5.1.0",
|
|
65
|
+
"@wordpress/ui": "^0.28.0",
|
|
66
|
+
"@wordpress/url": "^5.3.0",
|
|
67
67
|
"clsx": "^2.1.1"
|
|
68
68
|
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@testing-library/dom": "^10.4.2",
|
|
71
|
+
"@testing-library/jest-dom": "^7.0.1",
|
|
72
|
+
"@testing-library/react": "^16.3.3",
|
|
73
|
+
"vitest": "^5.1.1",
|
|
74
|
+
"vitest-browser-react": "^2.3.0"
|
|
75
|
+
},
|
|
69
76
|
"peerDependencies": {
|
|
70
77
|
"@types/react": "^18 || ^19",
|
|
71
78
|
"react": "^18 || ^19",
|
|
@@ -79,5 +86,5 @@
|
|
|
79
86
|
"publishConfig": {
|
|
80
87
|
"access": "public"
|
|
81
88
|
},
|
|
82
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "7f19202f61aeba8f4bdce892a1a0df485ad76e2b"
|
|
83
90
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Page } from '@wordpress/admin-ui';
|
|
2
|
+
import { useEffect, useRef } from '@wordpress/element';
|
|
3
|
+
|
|
4
|
+
// Moves focus to its own button when it mounts after focus was lost.
|
|
5
|
+
function Stage() {
|
|
6
|
+
const ref = useRef< HTMLButtonElement >( null );
|
|
7
|
+
|
|
8
|
+
useEffect( () => {
|
|
9
|
+
const ownerDocument = ref.current?.ownerDocument;
|
|
10
|
+
if ( ownerDocument?.activeElement === ownerDocument?.body ) {
|
|
11
|
+
ref.current?.focus();
|
|
12
|
+
}
|
|
13
|
+
}, [] );
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<Page ariaLabel="Own focus">
|
|
17
|
+
<button ref={ ref }>Own focus</button>
|
|
18
|
+
</Page>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const stage = Stage;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Breadcrumbs, Page } from '@wordpress/admin-ui';
|
|
2
|
+
import { Link } from '@wordpress/route';
|
|
3
|
+
|
|
4
|
+
export const stage = () => (
|
|
5
|
+
<Page
|
|
6
|
+
ariaLabel="General"
|
|
7
|
+
breadcrumbs={
|
|
8
|
+
<Breadcrumbs
|
|
9
|
+
items={ [
|
|
10
|
+
{ label: 'Settings', to: '/settings' },
|
|
11
|
+
{ label: 'General' },
|
|
12
|
+
] }
|
|
13
|
+
/>
|
|
14
|
+
}
|
|
15
|
+
>
|
|
16
|
+
<Link to="/settings/general" search={ { tab: 'advanced' } }>
|
|
17
|
+
Advanced
|
|
18
|
+
</Link>
|
|
19
|
+
<Link to="/own-focus">Own focus</Link>
|
|
20
|
+
</Page>
|
|
21
|
+
);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { screen, waitFor } from '@testing-library/react';
|
|
3
|
+
import { userEvent } from 'vitest/browser';
|
|
4
|
+
import { render } from 'vitest-browser-react';
|
|
5
|
+
import Router from '../router';
|
|
6
|
+
import RootSinglePage from '../../root/single-page';
|
|
7
|
+
|
|
8
|
+
const ROUTES = [
|
|
9
|
+
{
|
|
10
|
+
path: '/settings',
|
|
11
|
+
content_module: new URL( './fixtures/settings.tsx', import.meta.url )
|
|
12
|
+
.href,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
path: '/settings/general',
|
|
16
|
+
content_module: new URL(
|
|
17
|
+
'./fixtures/settings-general.tsx',
|
|
18
|
+
import.meta.url
|
|
19
|
+
).href,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
path: '/own-focus',
|
|
23
|
+
content_module: new URL( './fixtures/own-focus.tsx', import.meta.url )
|
|
24
|
+
.href,
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
// Wait long enough for the router to finish a navigation that leaves no
|
|
29
|
+
// visible change to wait for.
|
|
30
|
+
const settle = () => new Promise( ( resolve ) => setTimeout( resolve, 100 ) );
|
|
31
|
+
|
|
32
|
+
async function renderAt( path: string ) {
|
|
33
|
+
window.history.replaceState( null, '', `?p=${ path }` );
|
|
34
|
+
await render(
|
|
35
|
+
<Router routes={ ROUTES } rootComponent={ RootSinglePage } />
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe( 'navigation focus', () => {
|
|
40
|
+
beforeEach( () => {
|
|
41
|
+
// Each route load requests the site's base entity from the REST API.
|
|
42
|
+
vi.stubGlobal(
|
|
43
|
+
'fetch',
|
|
44
|
+
vi.fn(
|
|
45
|
+
async () =>
|
|
46
|
+
new Response( JSON.stringify( { name: 'Test site' } ), {
|
|
47
|
+
headers: { 'Content-Type': 'application/json' },
|
|
48
|
+
} )
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
} );
|
|
52
|
+
|
|
53
|
+
afterEach( () => {
|
|
54
|
+
vi.unstubAllGlobals();
|
|
55
|
+
} );
|
|
56
|
+
|
|
57
|
+
it( 'does not move focus on the initial load', async () => {
|
|
58
|
+
await renderAt( '/settings/general' );
|
|
59
|
+
|
|
60
|
+
const page = await screen.findByRole( 'region', { name: 'General' } );
|
|
61
|
+
await settle();
|
|
62
|
+
|
|
63
|
+
expect( page.matches( ':focus-within' ) ).toBe( false );
|
|
64
|
+
} );
|
|
65
|
+
|
|
66
|
+
it( 'moves focus to the new page when the focused link is removed', async () => {
|
|
67
|
+
await renderAt( '/settings/general' );
|
|
68
|
+
|
|
69
|
+
const link = await screen.findByRole( 'link', { name: 'Settings' } );
|
|
70
|
+
link.focus();
|
|
71
|
+
await userEvent.keyboard( '{Enter}' );
|
|
72
|
+
|
|
73
|
+
const page = await screen.findByRole( 'region', { name: 'Settings' } );
|
|
74
|
+
await waitFor( () =>
|
|
75
|
+
expect( page.matches( ':focus-within' ) ).toBe( true )
|
|
76
|
+
);
|
|
77
|
+
} );
|
|
78
|
+
|
|
79
|
+
it( 'keeps focus on a link that the navigation does not remove', async () => {
|
|
80
|
+
await renderAt( '/settings/general' );
|
|
81
|
+
|
|
82
|
+
const link = await screen.findByRole( 'link', { name: 'Advanced' } );
|
|
83
|
+
link.focus();
|
|
84
|
+
await userEvent.keyboard( '{Enter}' );
|
|
85
|
+
|
|
86
|
+
await waitFor( () =>
|
|
87
|
+
expect( window.location.search ).toContain( 'advanced' )
|
|
88
|
+
);
|
|
89
|
+
await settle();
|
|
90
|
+
|
|
91
|
+
expect( link ).toHaveFocus();
|
|
92
|
+
} );
|
|
93
|
+
|
|
94
|
+
it( 'does not override focus that the new page recovers itself', async () => {
|
|
95
|
+
await renderAt( '/settings/general' );
|
|
96
|
+
|
|
97
|
+
const link = await screen.findByRole( 'link', { name: 'Own focus' } );
|
|
98
|
+
link.focus();
|
|
99
|
+
await userEvent.keyboard( '{Enter}' );
|
|
100
|
+
|
|
101
|
+
const button = await screen.findByRole( 'button', {
|
|
102
|
+
name: 'Own focus',
|
|
103
|
+
} );
|
|
104
|
+
await settle();
|
|
105
|
+
|
|
106
|
+
expect( button ).toHaveFocus();
|
|
107
|
+
} );
|
|
108
|
+
} );
|