@wordpress/interface 9.38.0 → 10.0.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/CHANGELOG.md +7 -0
- package/build/components/action-item/index.cjs +17 -41
- package/build/components/action-item/index.cjs.map +2 -2
- package/build/components/complementary-area/index.cjs +4 -3
- package/build/components/complementary-area/index.cjs.map +3 -3
- package/build/components/complementary-area-more-menu-item/index.cjs +52 -24
- package/build/components/complementary-area-more-menu-item/index.cjs.map +2 -2
- package/build-module/components/action-item/index.mjs +18 -42
- package/build-module/components/action-item/index.mjs.map +2 -2
- package/build-module/components/complementary-area/index.mjs +7 -3
- package/build-module/components/complementary-area/index.mjs.map +2 -2
- package/build-module/components/complementary-area-more-menu-item/index.mjs +47 -24
- package/build-module/components/complementary-area-more-menu-item/index.mjs.map +2 -2
- package/package.json +15 -15
- package/src/components/action-item/README.md +17 -10
- package/src/components/action-item/index.js +27 -45
- package/src/components/complementary-area/index.js +8 -4
- package/src/components/complementary-area-more-menu-item/index.js +51 -24
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 10.0.0 (2026-08-26)
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
- `ActionItem`: `as` now defaults to `MenuItem` instead of `Button` ([#81507](https://github.com/WordPress/gutenberg/pull/81507)).
|
|
10
|
+
- `ActionItem.Slot`: Remove the `bubblesVirtually` prop ([#81507](https://github.com/WordPress/gutenberg/pull/81507)).
|
|
11
|
+
|
|
5
12
|
## 9.38.0 (2026-08-12)
|
|
6
13
|
|
|
7
14
|
### Enhancements
|
|
@@ -25,58 +25,34 @@ module.exports = __toCommonJS(action_item_exports);
|
|
|
25
25
|
var import_components = require("@wordpress/components");
|
|
26
26
|
var import_element = require("@wordpress/element");
|
|
27
27
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
|
-
var noop = () => {
|
|
29
|
-
};
|
|
30
28
|
function ActionItemSlot({
|
|
31
29
|
name,
|
|
32
30
|
as: Component = import_components.MenuGroup,
|
|
33
31
|
fillProps = {},
|
|
34
|
-
|
|
32
|
+
children,
|
|
35
33
|
...props
|
|
36
34
|
}) {
|
|
37
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
38
|
-
|
|
39
|
-
{
|
|
40
|
-
|
|
41
|
-
bubblesVirtually,
|
|
42
|
-
fillProps,
|
|
43
|
-
children: (fills) => {
|
|
44
|
-
if (!import_element.Children.toArray(fills).length) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
const initializedByPlugins = [];
|
|
48
|
-
import_element.Children.forEach(
|
|
49
|
-
fills,
|
|
50
|
-
({
|
|
51
|
-
props: { __unstableExplicitMenuItem, __unstableTarget }
|
|
52
|
-
}) => {
|
|
53
|
-
if (__unstableTarget && __unstableExplicitMenuItem) {
|
|
54
|
-
initializedByPlugins.push(__unstableTarget);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
);
|
|
58
|
-
const children = import_element.Children.map(fills, (child) => {
|
|
59
|
-
if (!child.props.__unstableExplicitMenuItem && initializedByPlugins.includes(
|
|
60
|
-
child.props.__unstableTarget
|
|
61
|
-
)) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
return child;
|
|
65
|
-
});
|
|
66
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...props, children });
|
|
67
|
-
}
|
|
35
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Slot, { name, fillProps, children: (fills) => {
|
|
36
|
+
const items = import_element.Children.toArray(fills);
|
|
37
|
+
if (!items.length) {
|
|
38
|
+
return null;
|
|
68
39
|
}
|
|
69
|
-
|
|
40
|
+
if (typeof children === "function") {
|
|
41
|
+
return children(items);
|
|
42
|
+
}
|
|
43
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...props, children: items });
|
|
44
|
+
} });
|
|
70
45
|
}
|
|
71
|
-
function ActionItem({ name, as
|
|
72
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Fill, { name, children: ({ onClick:
|
|
46
|
+
function ActionItem({ name, as, onClick, ...props }) {
|
|
47
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Fill, { name, children: ({ as: slotAs = import_components.MenuItem, onClick: slotOnClick }) => {
|
|
48
|
+
const Component = as ?? slotAs;
|
|
49
|
+
const handlers = [onClick, slotOnClick].filter(Boolean);
|
|
73
50
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
74
51
|
Component,
|
|
75
52
|
{
|
|
76
|
-
onClick:
|
|
77
|
-
(
|
|
78
|
-
|
|
79
|
-
} : void 0,
|
|
53
|
+
onClick: handlers.length ? (...args) => handlers.forEach(
|
|
54
|
+
(handler) => handler(...args)
|
|
55
|
+
) : void 0,
|
|
80
56
|
...props
|
|
81
57
|
}
|
|
82
58
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/action-item/index.js"],
|
|
4
|
-
"sourcesContent": ["import { MenuGroup,
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { MenuGroup, MenuItem, Slot, Fill } from '@wordpress/components';\nimport { Children } from '@wordpress/element';\n\nfunction ActionItemSlot( {\n\tname,\n\tas: Component = MenuGroup,\n\tfillProps = {},\n\tchildren,\n\t...props\n} ) {\n\treturn (\n\t\t<Slot name={ name } fillProps={ fillProps }>\n\t\t\t{ ( fills ) => {\n\t\t\t\t// Each fill renders an array of its own, so flatten them into a\n\t\t\t\t// single list before handing them over.\n\t\t\t\tconst items = Children.toArray( fills );\n\n\t\t\t\tif ( ! items.length ) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tif ( typeof children === 'function' ) {\n\t\t\t\t\treturn children( items );\n\t\t\t\t}\n\n\t\t\t\treturn <Component { ...props }>{ items }</Component>;\n\t\t\t} }\n\t\t</Slot>\n\t);\n}\n\nfunction ActionItem( { name, as, onClick, ...props } ) {\n\treturn (\n\t\t<Fill name={ name }>\n\t\t\t{ ( { as: slotAs = MenuItem, onClick: slotOnClick } ) => {\n\t\t\t\t// The slot provides the component to render the item with, so\n\t\t\t\t// that it fits the menu it ends up in, and an onClick handler,\n\t\t\t\t// for example one that closes that menu. The `as` prop\n\t\t\t\t// replaces the component. The `onClick` prop does not replace\n\t\t\t\t// the handler: both run.\n\t\t\t\tconst Component = as ?? slotAs;\n\t\t\t\tconst handlers = [ onClick, slotOnClick ].filter( Boolean );\n\n\t\t\t\treturn (\n\t\t\t\t\t<Component\n\t\t\t\t\t\tonClick={\n\t\t\t\t\t\t\thandlers.length\n\t\t\t\t\t\t\t\t? ( ...args ) =>\n\t\t\t\t\t\t\t\t\t\thandlers.forEach( ( handler ) =>\n\t\t\t\t\t\t\t\t\t\t\thandler( ...args )\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} }\n\t\t</Fill>\n\t);\n}\n\nActionItem.Slot = ActionItemSlot;\n\nexport default ActionItem;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAgD;AAChD,qBAAyB;AAwBd;AAtBX,SAAS,eAAgB;AAAA,EACxB;AAAA,EACA,IAAI,YAAY;AAAA,EAChB,YAAY,CAAC;AAAA,EACb;AAAA,EACA,GAAG;AACJ,GAAI;AACH,SACC,4CAAC,0BAAK,MAAc,WACjB,WAAE,UAAW;AAGd,UAAM,QAAQ,wBAAS,QAAS,KAAM;AAEtC,QAAK,CAAE,MAAM,QAAS;AACrB,aAAO;AAAA,IACR;AAEA,QAAK,OAAO,aAAa,YAAa;AACrC,aAAO,SAAU,KAAM;AAAA,IACxB;AAEA,WAAO,4CAAC,aAAY,GAAG,OAAU,iBAAO;AAAA,EACzC,GACD;AAEF;AAEA,SAAS,WAAY,EAAE,MAAM,IAAI,SAAS,GAAG,MAAM,GAAI;AACtD,SACC,4CAAC,0BAAK,MACH,WAAE,EAAE,IAAI,SAAS,4BAAU,SAAS,YAAY,MAAO;AAMxD,UAAM,YAAY,MAAM;AACxB,UAAM,WAAW,CAAE,SAAS,WAAY,EAAE,OAAQ,OAAQ;AAE1D,WACC;AAAA,MAAC;AAAA;AAAA,QACA,SACC,SAAS,SACN,IAAK,SACL,SAAS;AAAA,UAAS,CAAE,YACnB,QAAS,GAAG,IAAK;AAAA,QAClB,IACA;AAAA,QAEF,GAAG;AAAA;AAAA,IACN;AAAA,EAEF,GACD;AAEF;AAEA,WAAW,OAAO;AAElB,IAAO,sBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -43,7 +43,7 @@ var import_preferences = require("@wordpress/preferences");
|
|
|
43
43
|
var import_compose = require("@wordpress/compose");
|
|
44
44
|
var import_plugins = require("@wordpress/plugins");
|
|
45
45
|
var import_complementary_area_header = __toESM(require("../complementary-area-header/index.cjs"));
|
|
46
|
-
var import_complementary_area_more_menu_item =
|
|
46
|
+
var import_complementary_area_more_menu_item = require("../complementary-area-more-menu-item/index.cjs");
|
|
47
47
|
var import_complementary_area_toggle = __toESM(require("../complementary-area-toggle/index.cjs"));
|
|
48
48
|
var import_pinned_items = __toESM(require("../pinned-items/index.cjs"));
|
|
49
49
|
var import_store = require("../../store/index.cjs");
|
|
@@ -193,6 +193,7 @@ function ComplementaryArea({
|
|
|
193
193
|
},
|
|
194
194
|
[identifier, scope]
|
|
195
195
|
);
|
|
196
|
+
const hasMenuItem = (0, import_complementary_area_more_menu_item.useHasComplementaryAreaMenuItem)(scope, name);
|
|
196
197
|
const isMobileViewport = (0, import_compose.useViewportMatch)("medium", "<");
|
|
197
198
|
useAdjustComplementaryListener(
|
|
198
199
|
scope,
|
|
@@ -243,8 +244,8 @@ function ComplementaryArea({
|
|
|
243
244
|
shortcut: toggleShortcut
|
|
244
245
|
}
|
|
245
246
|
) }),
|
|
246
|
-
name && isPinnable && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
247
|
-
import_complementary_area_more_menu_item.
|
|
247
|
+
name && isPinnable && !hasMenuItem && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
248
|
+
import_complementary_area_more_menu_item.DefaultComplementaryAreaMoreMenuItem,
|
|
248
249
|
{
|
|
249
250
|
target: name,
|
|
250
251
|
scope,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/complementary-area/index.js"],
|
|
4
|
-
"sourcesContent": ["import clsx from 'clsx';\nimport {\n\tButton,\n\tPanel,\n\tSlot,\n\tFill,\n\t__unstableMotion as motion,\n\t__unstableAnimatePresence as AnimatePresence,\n} from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { check, starEmpty, starFilled } from '@wordpress/icons';\nimport {\n\tcloneElement,\n\tisValidElement,\n\tuseEffect,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { store as viewportStore } from '@wordpress/viewport';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport {\n\tuseReducedMotion,\n\tuseViewportMatch,\n\tusePrevious,\n} from '@wordpress/compose';\nimport { usePluginContext } from '@wordpress/plugins';\nimport ComplementaryAreaHeader from '../complementary-area-header';\nimport ComplementaryAreaMoreMenuItem from '../complementary-area-more-menu-item';\nimport ComplementaryAreaToggle from '../complementary-area-toggle';\nimport PinnedItems from '../pinned-items';\nimport { store as interfaceStore } from '../../store';\n\nconst ANIMATION_DURATION = 0.3;\n\nfunction ComplementaryAreaSlot( { scope, ...props } ) {\n\treturn <Slot name={ `ComplementaryArea/${ scope }` } { ...props } />;\n}\n\nconst variants = {\n\t// `auto` leaves the width to the area's own stylesheet, so it stays in one\n\t// place. framer-motion measures the element to animate, then restores\n\t// `auto`.\n\topen: { width: 'auto' },\n\t// Resolved with the `custom` value passed to `AnimatePresence`, which is\n\t// the only way an already removed element can be given a fresh transition.\n\tclosed: ( transition ) => ( { width: 0, transition } ),\n};\n\n/**\n * Renders the complementary area container, replacing the default `div` with\n * the element given via the `render` prop.\n *\n * `className` and `style` are composed rather than overwritten, since the\n * container is also the scroll container for the sidebar.\n *\n * @param {Object} [render] Replacement element.\n * @param {Object} props Props for the container.\n */\nfunction renderContainer( render, props ) {\n\tif ( isValidElement( render ) ) {\n\t\treturn cloneElement( render, {\n\t\t\t...props,\n\t\t\tclassName: clsx( render.props.className, props.className ),\n\t\t\tstyle: { ...render.props.style, ...props.style },\n\t\t} );\n\t}\n\n\treturn <div { ...props } />;\n}\n\nfunction ComplementaryAreaFill( {\n\tactiveArea,\n\tisActive,\n\tscope,\n\tchildren,\n\tclassName,\n\tid,\n\trender,\n} ) {\n\tconst disableMotion = useReducedMotion();\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\t// Swapping one open area straight for another should not animate.\n\tconst previousActiveArea = usePrevious( activeArea );\n\tconst isSwitchingAreas =\n\t\t!! previousActiveArea &&\n\t\t!! activeArea &&\n\t\tactiveArea !== previousActiveArea;\n\tconst transition = {\n\t\ttype: 'tween',\n\t\tduration:\n\t\t\tdisableMotion || isMobileViewport || isSwitchingAreas\n\t\t\t\t? 0\n\t\t\t\t: ANIMATION_DURATION,\n\t\tease: [ 0.6, 0, 0.4, 1 ],\n\t};\n\n\treturn (\n\t\t<Fill name={ `ComplementaryArea/${ scope }` }>\n\t\t\t<AnimatePresence initial={ false } custom={ transition }>\n\t\t\t\t{ isActive && (\n\t\t\t\t\t<motion.div\n\t\t\t\t\t\tvariants={ variants }\n\t\t\t\t\t\tinitial=\"closed\"\n\t\t\t\t\t\tanimate=\"open\"\n\t\t\t\t\t\texit=\"closed\"\n\t\t\t\t\t\ttransition={ transition }\n\t\t\t\t\t\tclassName=\"interface-complementary-area__fill\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ renderContainer( render, {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tclassName,\n\t\t\t\t\t\t\tchildren,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</motion.div>\n\t\t\t\t) }\n\t\t\t</AnimatePresence>\n\t\t</Fill>\n\t);\n}\n\nfunction useAdjustComplementaryListener(\n\tscope,\n\tidentifier,\n\tactiveArea,\n\tisActive,\n\tisSmall\n) {\n\tconst previousIsSmallRef = useRef( false );\n\tconst shouldOpenWhenNotSmallRef = useRef( false );\n\tconst { enableComplementaryArea, disableComplementaryArea } =\n\t\tuseDispatch( interfaceStore );\n\tuseEffect( () => {\n\t\t// If the complementary area is active and the editor is switching from\n\t\t// a big to a small window size.\n\t\tif ( isActive && isSmall && ! previousIsSmallRef.current ) {\n\t\t\tdisableComplementaryArea( scope );\n\t\t\t// Flag the complementary area to be reopened when the window size\n\t\t\t// goes from small to big.\n\t\t\tshouldOpenWhenNotSmallRef.current = true;\n\t\t} else if (\n\t\t\t// If there is a flag indicating the complementary area should be\n\t\t\t// enabled when we go from small to big window size and we are going\n\t\t\t// from a small to big window size.\n\t\t\tshouldOpenWhenNotSmallRef.current &&\n\t\t\t! isSmall &&\n\t\t\tpreviousIsSmallRef.current\n\t\t) {\n\t\t\t// Remove the flag indicating the complementary area should be\n\t\t\t// enabled.\n\t\t\tshouldOpenWhenNotSmallRef.current = false;\n\t\t\tenableComplementaryArea( scope, identifier );\n\t\t} else if (\n\t\t\t// If the flag is indicating the current complementary should be\n\t\t\t// reopened but another complementary area becomes active, remove\n\t\t\t// the flag.\n\t\t\tshouldOpenWhenNotSmallRef.current &&\n\t\t\tactiveArea &&\n\t\t\tactiveArea !== identifier\n\t\t) {\n\t\t\tshouldOpenWhenNotSmallRef.current = false;\n\t\t}\n\t\tif ( isSmall !== previousIsSmallRef.current ) {\n\t\t\tpreviousIsSmallRef.current = isSmall;\n\t\t}\n\t}, [\n\t\tisActive,\n\t\tisSmall,\n\t\tscope,\n\t\tidentifier,\n\t\tactiveArea,\n\t\tdisableComplementaryArea,\n\t\tenableComplementaryArea,\n\t] );\n}\n\nfunction ComplementaryArea( {\n\tchildren,\n\tclassName,\n\tcloseLabel = __( 'Close plugin' ),\n\tidentifier: identifierProp,\n\theader,\n\theaderClassName,\n\ticon: iconProp,\n\tisPinnable = true,\n\tpanelClassName,\n\trender,\n\tscope,\n\tname,\n\ttitle,\n\ttoggleShortcut,\n\tisActiveByDefault,\n} ) {\n\tconst context = usePluginContext();\n\tconst icon = iconProp || context.icon;\n\tconst identifier = identifierProp || `${ context.name }/${ name }`;\n\n\t// This state is used to delay the rendering of the Fill\n\t// until the initial effect runs.\n\t// This prevents the animation from running on mount if\n\t// the complementary area is active by default.\n\tconst [ isReady, setIsReady ] = useState( false );\n\tconst {\n\t\tisLoading,\n\t\tisActive,\n\t\tisPinned,\n\t\tactiveArea,\n\t\tisSmall,\n\t\tisLarge,\n\t\tshowIconLabels,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetActiveComplementaryArea,\n\t\t\t\tisComplementaryAreaLoading,\n\t\t\t\tisItemPinned,\n\t\t\t} = select( interfaceStore );\n\t\t\tconst { get } = select( preferencesStore );\n\n\t\t\tconst _activeArea = getActiveComplementaryArea( scope );\n\n\t\t\treturn {\n\t\t\t\tisLoading: isComplementaryAreaLoading( scope ),\n\t\t\t\tisActive: _activeArea === identifier,\n\t\t\t\tisPinned: isItemPinned( scope, identifier ),\n\t\t\t\tactiveArea: _activeArea,\n\t\t\t\tisSmall: select( viewportStore ).isViewportMatch( '< medium' ),\n\t\t\t\tisLarge: select( viewportStore ).isViewportMatch( 'large' ),\n\t\t\t\tshowIconLabels: get( 'core', 'showIconLabels' ),\n\t\t\t};\n\t\t},\n\t\t[ identifier, scope ]\n\t);\n\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\n\tuseAdjustComplementaryListener(\n\t\tscope,\n\t\tidentifier,\n\t\tactiveArea,\n\t\tisActive,\n\t\tisSmall\n\t);\n\tconst {\n\t\tenableComplementaryArea,\n\t\tdisableComplementaryArea,\n\t\tpinItem,\n\t\tunpinItem,\n\t} = useDispatch( interfaceStore );\n\n\tuseEffect( () => {\n\t\t// Set initial visibility: For large screens, enable if it's active by\n\t\t// default. For small screens, always initially disable.\n\t\tif ( isActiveByDefault && activeArea === undefined && ! isSmall ) {\n\t\t\tenableComplementaryArea( scope, identifier );\n\t\t} else if ( activeArea === undefined && isSmall ) {\n\t\t\tdisableComplementaryArea( scope, identifier );\n\t\t}\n\t\tsetIsReady( true );\n\t}, [\n\t\tactiveArea,\n\t\tisActiveByDefault,\n\t\tscope,\n\t\tidentifier,\n\t\tisSmall,\n\t\tenableComplementaryArea,\n\t\tdisableComplementaryArea,\n\t] );\n\n\tif ( ! isReady ) {\n\t\treturn;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ isPinnable && (\n\t\t\t\t<PinnedItems scope={ scope }>\n\t\t\t\t\t{ isPinned && (\n\t\t\t\t\t\t<ComplementaryAreaToggle\n\t\t\t\t\t\t\tscope={ scope }\n\t\t\t\t\t\t\tidentifier={ identifier }\n\t\t\t\t\t\t\tisPressed={\n\t\t\t\t\t\t\t\tisActive && ( ! showIconLabels || isLarge )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\taria-expanded={ isActive }\n\t\t\t\t\t\t\taria-disabled={ isLoading }\n\t\t\t\t\t\t\tlabel={ title }\n\t\t\t\t\t\t\ticon={ showIconLabels ? check : icon }\n\t\t\t\t\t\t\tshowTooltip={ ! showIconLabels }\n\t\t\t\t\t\t\tvariant={ showIconLabels ? 'tertiary' : undefined }\n\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\tshortcut={ toggleShortcut }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</PinnedItems>\n\t\t\t) }\n\t\t\t{ name && isPinnable && (\n\t\t\t\t<ComplementaryAreaMoreMenuItem\n\t\t\t\t\ttarget={ name }\n\t\t\t\t\tscope={ scope }\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tidentifier={ identifier }\n\t\t\t\t>\n\t\t\t\t\t{ title }\n\t\t\t\t</ComplementaryAreaMoreMenuItem>\n\t\t\t) }\n\t\t\t<ComplementaryAreaFill\n\t\t\t\tactiveArea={ activeArea }\n\t\t\t\tisActive={ isActive }\n\t\t\t\tclassName={ clsx( 'interface-complementary-area', className ) }\n\t\t\t\tscope={ scope }\n\t\t\t\tid={ identifier.replace( '/', ':' ) }\n\t\t\t\trender={ render }\n\t\t\t>\n\t\t\t\t<ComplementaryAreaHeader\n\t\t\t\t\tclassName={ headerClassName }\n\t\t\t\t\tcloseLabel={ closeLabel }\n\t\t\t\t\tonClose={ () => disableComplementaryArea( scope ) }\n\t\t\t\t\ttoggleButtonProps={ {\n\t\t\t\t\t\tlabel: closeLabel,\n\t\t\t\t\t\tsize: 'compact',\n\t\t\t\t\t\tshortcut: toggleShortcut,\n\t\t\t\t\t\tscope,\n\t\t\t\t\t\tidentifier,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ header || (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<h2 className=\"interface-complementary-area-header__title\">\n\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t</h2>\n\t\t\t\t\t\t\t{ isPinnable && ! isMobileViewport && (\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tclassName=\"interface-complementary-area__pin-unpin-item\"\n\t\t\t\t\t\t\t\t\ticon={ isPinned ? starFilled : starEmpty }\n\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\tisPinned\n\t\t\t\t\t\t\t\t\t\t\t? __( 'Unpin from toolbar' )\n\t\t\t\t\t\t\t\t\t\t\t: __( 'Pin to toolbar' )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t( isPinned ? unpinItem : pinItem )(\n\t\t\t\t\t\t\t\t\t\t\tscope,\n\t\t\t\t\t\t\t\t\t\t\tidentifier\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tisPressed={ isPinned }\n\t\t\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</ComplementaryAreaHeader>\n\t\t\t\t<Panel className={ panelClassName }>{ children }</Panel>\n\t\t\t</ComplementaryAreaFill>\n\t\t</>\n\t);\n}\n\nComplementaryArea.Slot = ComplementaryAreaSlot;\n\nexport default ComplementaryArea;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AACjB,wBAOO;AACP,kBAAuC;AACvC,kBAAmB;AACnB,mBAA6C;AAC7C,qBAMO;AACP,sBAAuC;AACvC,yBAA0C;AAC1C,qBAIO;AACP,qBAAiC;AACjC,uCAAoC;AACpC,+
|
|
6
|
-
"names": ["clsx", "AnimatePresence", "motion", "interfaceStore", "preferencesStore", "viewportStore", "PinnedItems", "ComplementaryAreaToggle", "
|
|
4
|
+
"sourcesContent": ["import clsx from 'clsx';\nimport {\n\tButton,\n\tPanel,\n\tSlot,\n\tFill,\n\t__unstableMotion as motion,\n\t__unstableAnimatePresence as AnimatePresence,\n} from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { check, starEmpty, starFilled } from '@wordpress/icons';\nimport {\n\tcloneElement,\n\tisValidElement,\n\tuseEffect,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { store as viewportStore } from '@wordpress/viewport';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport {\n\tuseReducedMotion,\n\tuseViewportMatch,\n\tusePrevious,\n} from '@wordpress/compose';\nimport { usePluginContext } from '@wordpress/plugins';\nimport ComplementaryAreaHeader from '../complementary-area-header';\nimport {\n\tDefaultComplementaryAreaMoreMenuItem,\n\tuseHasComplementaryAreaMenuItem,\n} from '../complementary-area-more-menu-item';\nimport ComplementaryAreaToggle from '../complementary-area-toggle';\nimport PinnedItems from '../pinned-items';\nimport { store as interfaceStore } from '../../store';\n\nconst ANIMATION_DURATION = 0.3;\n\nfunction ComplementaryAreaSlot( { scope, ...props } ) {\n\treturn <Slot name={ `ComplementaryArea/${ scope }` } { ...props } />;\n}\n\nconst variants = {\n\t// `auto` leaves the width to the area's own stylesheet, so it stays in one\n\t// place. framer-motion measures the element to animate, then restores\n\t// `auto`.\n\topen: { width: 'auto' },\n\t// Resolved with the `custom` value passed to `AnimatePresence`, which is\n\t// the only way an already removed element can be given a fresh transition.\n\tclosed: ( transition ) => ( { width: 0, transition } ),\n};\n\n/**\n * Renders the complementary area container, replacing the default `div` with\n * the element given via the `render` prop.\n *\n * `className` and `style` are composed rather than overwritten, since the\n * container is also the scroll container for the sidebar.\n *\n * @param {Object} [render] Replacement element.\n * @param {Object} props Props for the container.\n */\nfunction renderContainer( render, props ) {\n\tif ( isValidElement( render ) ) {\n\t\treturn cloneElement( render, {\n\t\t\t...props,\n\t\t\tclassName: clsx( render.props.className, props.className ),\n\t\t\tstyle: { ...render.props.style, ...props.style },\n\t\t} );\n\t}\n\n\treturn <div { ...props } />;\n}\n\nfunction ComplementaryAreaFill( {\n\tactiveArea,\n\tisActive,\n\tscope,\n\tchildren,\n\tclassName,\n\tid,\n\trender,\n} ) {\n\tconst disableMotion = useReducedMotion();\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\t// Swapping one open area straight for another should not animate.\n\tconst previousActiveArea = usePrevious( activeArea );\n\tconst isSwitchingAreas =\n\t\t!! previousActiveArea &&\n\t\t!! activeArea &&\n\t\tactiveArea !== previousActiveArea;\n\tconst transition = {\n\t\ttype: 'tween',\n\t\tduration:\n\t\t\tdisableMotion || isMobileViewport || isSwitchingAreas\n\t\t\t\t? 0\n\t\t\t\t: ANIMATION_DURATION,\n\t\tease: [ 0.6, 0, 0.4, 1 ],\n\t};\n\n\treturn (\n\t\t<Fill name={ `ComplementaryArea/${ scope }` }>\n\t\t\t<AnimatePresence initial={ false } custom={ transition }>\n\t\t\t\t{ isActive && (\n\t\t\t\t\t<motion.div\n\t\t\t\t\t\tvariants={ variants }\n\t\t\t\t\t\tinitial=\"closed\"\n\t\t\t\t\t\tanimate=\"open\"\n\t\t\t\t\t\texit=\"closed\"\n\t\t\t\t\t\ttransition={ transition }\n\t\t\t\t\t\tclassName=\"interface-complementary-area__fill\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ renderContainer( render, {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tclassName,\n\t\t\t\t\t\t\tchildren,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</motion.div>\n\t\t\t\t) }\n\t\t\t</AnimatePresence>\n\t\t</Fill>\n\t);\n}\n\nfunction useAdjustComplementaryListener(\n\tscope,\n\tidentifier,\n\tactiveArea,\n\tisActive,\n\tisSmall\n) {\n\tconst previousIsSmallRef = useRef( false );\n\tconst shouldOpenWhenNotSmallRef = useRef( false );\n\tconst { enableComplementaryArea, disableComplementaryArea } =\n\t\tuseDispatch( interfaceStore );\n\tuseEffect( () => {\n\t\t// If the complementary area is active and the editor is switching from\n\t\t// a big to a small window size.\n\t\tif ( isActive && isSmall && ! previousIsSmallRef.current ) {\n\t\t\tdisableComplementaryArea( scope );\n\t\t\t// Flag the complementary area to be reopened when the window size\n\t\t\t// goes from small to big.\n\t\t\tshouldOpenWhenNotSmallRef.current = true;\n\t\t} else if (\n\t\t\t// If there is a flag indicating the complementary area should be\n\t\t\t// enabled when we go from small to big window size and we are going\n\t\t\t// from a small to big window size.\n\t\t\tshouldOpenWhenNotSmallRef.current &&\n\t\t\t! isSmall &&\n\t\t\tpreviousIsSmallRef.current\n\t\t) {\n\t\t\t// Remove the flag indicating the complementary area should be\n\t\t\t// enabled.\n\t\t\tshouldOpenWhenNotSmallRef.current = false;\n\t\t\tenableComplementaryArea( scope, identifier );\n\t\t} else if (\n\t\t\t// If the flag is indicating the current complementary should be\n\t\t\t// reopened but another complementary area becomes active, remove\n\t\t\t// the flag.\n\t\t\tshouldOpenWhenNotSmallRef.current &&\n\t\t\tactiveArea &&\n\t\t\tactiveArea !== identifier\n\t\t) {\n\t\t\tshouldOpenWhenNotSmallRef.current = false;\n\t\t}\n\t\tif ( isSmall !== previousIsSmallRef.current ) {\n\t\t\tpreviousIsSmallRef.current = isSmall;\n\t\t}\n\t}, [\n\t\tisActive,\n\t\tisSmall,\n\t\tscope,\n\t\tidentifier,\n\t\tactiveArea,\n\t\tdisableComplementaryArea,\n\t\tenableComplementaryArea,\n\t] );\n}\n\nfunction ComplementaryArea( {\n\tchildren,\n\tclassName,\n\tcloseLabel = __( 'Close plugin' ),\n\tidentifier: identifierProp,\n\theader,\n\theaderClassName,\n\ticon: iconProp,\n\tisPinnable = true,\n\tpanelClassName,\n\trender,\n\tscope,\n\tname,\n\ttitle,\n\ttoggleShortcut,\n\tisActiveByDefault,\n} ) {\n\tconst context = usePluginContext();\n\tconst icon = iconProp || context.icon;\n\tconst identifier = identifierProp || `${ context.name }/${ name }`;\n\n\t// This state is used to delay the rendering of the Fill\n\t// until the initial effect runs.\n\t// This prevents the animation from running on mount if\n\t// the complementary area is active by default.\n\tconst [ isReady, setIsReady ] = useState( false );\n\tconst {\n\t\tisLoading,\n\t\tisActive,\n\t\tisPinned,\n\t\tactiveArea,\n\t\tisSmall,\n\t\tisLarge,\n\t\tshowIconLabels,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetActiveComplementaryArea,\n\t\t\t\tisComplementaryAreaLoading,\n\t\t\t\tisItemPinned,\n\t\t\t} = select( interfaceStore );\n\t\t\tconst { get } = select( preferencesStore );\n\n\t\t\tconst _activeArea = getActiveComplementaryArea( scope );\n\n\t\t\treturn {\n\t\t\t\tisLoading: isComplementaryAreaLoading( scope ),\n\t\t\t\tisActive: _activeArea === identifier,\n\t\t\t\tisPinned: isItemPinned( scope, identifier ),\n\t\t\t\tactiveArea: _activeArea,\n\t\t\t\tisSmall: select( viewportStore ).isViewportMatch( '< medium' ),\n\t\t\t\tisLarge: select( viewportStore ).isViewportMatch( 'large' ),\n\t\t\t\tshowIconLabels: get( 'core', 'showIconLabels' ),\n\t\t\t};\n\t\t},\n\t\t[ identifier, scope ]\n\t);\n\n\tconst hasMenuItem = useHasComplementaryAreaMenuItem( scope, name );\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\n\tuseAdjustComplementaryListener(\n\t\tscope,\n\t\tidentifier,\n\t\tactiveArea,\n\t\tisActive,\n\t\tisSmall\n\t);\n\tconst {\n\t\tenableComplementaryArea,\n\t\tdisableComplementaryArea,\n\t\tpinItem,\n\t\tunpinItem,\n\t} = useDispatch( interfaceStore );\n\n\tuseEffect( () => {\n\t\t// Set initial visibility: For large screens, enable if it's active by\n\t\t// default. For small screens, always initially disable.\n\t\tif ( isActiveByDefault && activeArea === undefined && ! isSmall ) {\n\t\t\tenableComplementaryArea( scope, identifier );\n\t\t} else if ( activeArea === undefined && isSmall ) {\n\t\t\tdisableComplementaryArea( scope, identifier );\n\t\t}\n\t\tsetIsReady( true );\n\t}, [\n\t\tactiveArea,\n\t\tisActiveByDefault,\n\t\tscope,\n\t\tidentifier,\n\t\tisSmall,\n\t\tenableComplementaryArea,\n\t\tdisableComplementaryArea,\n\t] );\n\n\tif ( ! isReady ) {\n\t\treturn;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ isPinnable && (\n\t\t\t\t<PinnedItems scope={ scope }>\n\t\t\t\t\t{ isPinned && (\n\t\t\t\t\t\t<ComplementaryAreaToggle\n\t\t\t\t\t\t\tscope={ scope }\n\t\t\t\t\t\t\tidentifier={ identifier }\n\t\t\t\t\t\t\tisPressed={\n\t\t\t\t\t\t\t\tisActive && ( ! showIconLabels || isLarge )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\taria-expanded={ isActive }\n\t\t\t\t\t\t\taria-disabled={ isLoading }\n\t\t\t\t\t\t\tlabel={ title }\n\t\t\t\t\t\t\ticon={ showIconLabels ? check : icon }\n\t\t\t\t\t\t\tshowTooltip={ ! showIconLabels }\n\t\t\t\t\t\t\tvariant={ showIconLabels ? 'tertiary' : undefined }\n\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\tshortcut={ toggleShortcut }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</PinnedItems>\n\t\t\t) }\n\t\t\t{ name && isPinnable && ! hasMenuItem && (\n\t\t\t\t<DefaultComplementaryAreaMoreMenuItem\n\t\t\t\t\ttarget={ name }\n\t\t\t\t\tscope={ scope }\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tidentifier={ identifier }\n\t\t\t\t>\n\t\t\t\t\t{ title }\n\t\t\t\t</DefaultComplementaryAreaMoreMenuItem>\n\t\t\t) }\n\t\t\t<ComplementaryAreaFill\n\t\t\t\tactiveArea={ activeArea }\n\t\t\t\tisActive={ isActive }\n\t\t\t\tclassName={ clsx( 'interface-complementary-area', className ) }\n\t\t\t\tscope={ scope }\n\t\t\t\tid={ identifier.replace( '/', ':' ) }\n\t\t\t\trender={ render }\n\t\t\t>\n\t\t\t\t<ComplementaryAreaHeader\n\t\t\t\t\tclassName={ headerClassName }\n\t\t\t\t\tcloseLabel={ closeLabel }\n\t\t\t\t\tonClose={ () => disableComplementaryArea( scope ) }\n\t\t\t\t\ttoggleButtonProps={ {\n\t\t\t\t\t\tlabel: closeLabel,\n\t\t\t\t\t\tsize: 'compact',\n\t\t\t\t\t\tshortcut: toggleShortcut,\n\t\t\t\t\t\tscope,\n\t\t\t\t\t\tidentifier,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ header || (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<h2 className=\"interface-complementary-area-header__title\">\n\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t</h2>\n\t\t\t\t\t\t\t{ isPinnable && ! isMobileViewport && (\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tclassName=\"interface-complementary-area__pin-unpin-item\"\n\t\t\t\t\t\t\t\t\ticon={ isPinned ? starFilled : starEmpty }\n\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\tisPinned\n\t\t\t\t\t\t\t\t\t\t\t? __( 'Unpin from toolbar' )\n\t\t\t\t\t\t\t\t\t\t\t: __( 'Pin to toolbar' )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t( isPinned ? unpinItem : pinItem )(\n\t\t\t\t\t\t\t\t\t\t\tscope,\n\t\t\t\t\t\t\t\t\t\t\tidentifier\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tisPressed={ isPinned }\n\t\t\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</ComplementaryAreaHeader>\n\t\t\t\t<Panel className={ panelClassName }>{ children }</Panel>\n\t\t\t</ComplementaryAreaFill>\n\t\t</>\n\t);\n}\n\nComplementaryArea.Slot = ComplementaryAreaSlot;\n\nexport default ComplementaryArea;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AACjB,wBAOO;AACP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,WAAU;AAAA,oBACV,MAAO,WAAW,0BAAa;AAAA,oBAC/B,OACC,eACG,gBAAI,oBAAqB,QACzB,gBAAI,gBAAiB;AAAA,oBAEzB,SAAU,OACP,WAAW,YAAY;AAAA,sBACxB;AAAA,sBACA;AAAA,oBACD;AAAA,oBAED,WAAY;AAAA,oBACZ,MAAK;AAAA;AAAA,gBACN;AAAA,iBAEF;AAAA;AAAA,UAEF;AAAA,UACA,4CAAC,2BAAM,WAAY,gBAAmB,UAAU;AAAA;AAAA;AAAA,IACjD;AAAA,KACD;AAEF;AAEA,kBAAkB,OAAO;AAEzB,IAAO,6BAAQ;",
|
|
6
|
+
"names": ["clsx", "AnimatePresence", "motion", "interfaceStore", "preferencesStore", "viewportStore", "PinnedItems", "ComplementaryAreaToggle", "ComplementaryAreaHeader"]
|
|
7
7
|
}
|
|
@@ -29,43 +29,36 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// packages/interface/src/components/complementary-area-more-menu-item/index.js
|
|
30
30
|
var complementary_area_more_menu_item_exports = {};
|
|
31
31
|
__export(complementary_area_more_menu_item_exports, {
|
|
32
|
-
|
|
32
|
+
DefaultComplementaryAreaMoreMenuItem: () => DefaultComplementaryAreaMoreMenuItem,
|
|
33
|
+
default: () => ComplementaryAreaMoreMenuItem,
|
|
34
|
+
useHasComplementaryAreaMenuItem: () => useHasComplementaryAreaMenuItem
|
|
33
35
|
});
|
|
34
36
|
module.exports = __toCommonJS(complementary_area_more_menu_item_exports);
|
|
37
|
+
var import_compose = require("@wordpress/compose");
|
|
38
|
+
var import_element = require("@wordpress/element");
|
|
35
39
|
var import_icons = require("@wordpress/icons");
|
|
36
|
-
var import_components = require("@wordpress/components");
|
|
37
40
|
var import_complementary_area_toggle = __toESM(require("../complementary-area-toggle/index.cjs"));
|
|
38
41
|
var import_action_item = __toESM(require("../action-item/index.cjs"));
|
|
39
42
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
__unstableTarget,
|
|
46
|
-
...restProps
|
|
47
|
-
}) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.MenuItem, { ...restProps });
|
|
48
|
-
function ComplementaryAreaMoreMenuItem({
|
|
43
|
+
var menuItems = (0, import_compose.observableMap)();
|
|
44
|
+
function useHasComplementaryAreaMenuItem(scope, target) {
|
|
45
|
+
return !!(0, import_compose.useObservableValue)(menuItems, `${scope}/${target}`);
|
|
46
|
+
}
|
|
47
|
+
function DefaultComplementaryAreaMoreMenuItem({
|
|
49
48
|
scope,
|
|
50
49
|
target,
|
|
51
|
-
__unstableExplicitMenuItem,
|
|
52
50
|
...props
|
|
53
51
|
}) {
|
|
54
52
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
55
53
|
import_complementary_area_toggle.default,
|
|
56
54
|
{
|
|
57
|
-
as: (toggleProps) =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
name: `${scope}/plugin-more-menu`,
|
|
65
|
-
...toggleProps
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
},
|
|
55
|
+
as: (toggleProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
56
|
+
import_action_item.default,
|
|
57
|
+
{
|
|
58
|
+
name: `${scope}/plugin-more-menu`,
|
|
59
|
+
...toggleProps
|
|
60
|
+
}
|
|
61
|
+
),
|
|
69
62
|
role: "menuitemcheckbox",
|
|
70
63
|
selectedIcon: import_icons.check,
|
|
71
64
|
name: target,
|
|
@@ -74,4 +67,39 @@ function ComplementaryAreaMoreMenuItem({
|
|
|
74
67
|
}
|
|
75
68
|
);
|
|
76
69
|
}
|
|
70
|
+
function ComplementaryAreaMoreMenuItem({
|
|
71
|
+
scope,
|
|
72
|
+
target,
|
|
73
|
+
// Accepted so they don't leak to DOM elements. Registering the menu item is
|
|
74
|
+
// what keeps `ComplementaryArea` from injecting a second one.
|
|
75
|
+
__unstableExplicitMenuItem,
|
|
76
|
+
__unstableTarget,
|
|
77
|
+
...props
|
|
78
|
+
}) {
|
|
79
|
+
(0, import_element.useLayoutEffect)(() => {
|
|
80
|
+
const key = `${scope}/${target}`;
|
|
81
|
+
menuItems.set(key, (menuItems.get(key) ?? 0) + 1);
|
|
82
|
+
return () => {
|
|
83
|
+
const count = menuItems.get(key) - 1;
|
|
84
|
+
if (count) {
|
|
85
|
+
menuItems.set(key, count);
|
|
86
|
+
} else {
|
|
87
|
+
menuItems.delete(key);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}, [scope, target]);
|
|
91
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
92
|
+
DefaultComplementaryAreaMoreMenuItem,
|
|
93
|
+
{
|
|
94
|
+
scope,
|
|
95
|
+
target,
|
|
96
|
+
...props
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
101
|
+
0 && (module.exports = {
|
|
102
|
+
DefaultComplementaryAreaMoreMenuItem,
|
|
103
|
+
useHasComplementaryAreaMenuItem
|
|
104
|
+
});
|
|
77
105
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/complementary-area-more-menu-item/index.js"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AACtB,
|
|
4
|
+
"sourcesContent": ["import { observableMap, useObservableValue } from '@wordpress/compose';\nimport { useLayoutEffect } from '@wordpress/element';\nimport { check } from '@wordpress/icons';\nimport ComplementaryAreaToggle from '../complementary-area-toggle';\nimport ActionItem from '../action-item';\n\n// How many more menu items are rendered for a complementary area, by\n// `scope/target`.\nconst menuItems = observableMap();\n\nexport function useHasComplementaryAreaMenuItem( scope, target ) {\n\treturn !! useObservableValue( menuItems, `${ scope }/${ target }` );\n}\n\n// The more menu item `ComplementaryArea` injects for every pinnable area. It is\n// left out while a plugin renders one of its own for the same area.\n// @see https://github.com/WordPress/gutenberg/issues/14457\nexport function DefaultComplementaryAreaMoreMenuItem( {\n\tscope,\n\ttarget,\n\t...props\n} ) {\n\treturn (\n\t\t<ComplementaryAreaToggle\n\t\t\tas={ ( toggleProps ) => (\n\t\t\t\t<ActionItem\n\t\t\t\t\tname={ `${ scope }/plugin-more-menu` }\n\t\t\t\t\t{ ...toggleProps }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\trole=\"menuitemcheckbox\"\n\t\t\tselectedIcon={ check }\n\t\t\tname={ target }\n\t\t\tscope={ scope }\n\t\t\t{ ...props }\n\t\t/>\n\t);\n}\n\nexport default function ComplementaryAreaMoreMenuItem( {\n\tscope,\n\ttarget,\n\t// Accepted so they don't leak to DOM elements. Registering the menu item is\n\t// what keeps `ComplementaryArea` from injecting a second one.\n\t__unstableExplicitMenuItem,\n\t__unstableTarget,\n\t...props\n} ) {\n\tuseLayoutEffect( () => {\n\t\tconst key = `${ scope }/${ target }`;\n\t\tmenuItems.set( key, ( menuItems.get( key ) ?? 0 ) + 1 );\n\n\t\treturn () => {\n\t\t\tconst count = menuItems.get( key ) - 1;\n\t\t\tif ( count ) {\n\t\t\t\tmenuItems.set( key, count );\n\t\t\t} else {\n\t\t\t\tmenuItems.delete( key );\n\t\t\t}\n\t\t};\n\t}, [ scope, target ] );\n\n\treturn (\n\t\t<DefaultComplementaryAreaMoreMenuItem\n\t\t\tscope={ scope }\n\t\t\ttarget={ target }\n\t\t\t{ ...props }\n\t\t/>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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
import { MenuGroup,
|
|
2
|
+
import { MenuGroup, MenuItem, Slot, Fill } from "@wordpress/components";
|
|
3
3
|
import { Children } from "@wordpress/element";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
var noop = () => {
|
|
6
|
-
};
|
|
7
5
|
function ActionItemSlot({
|
|
8
6
|
name,
|
|
9
7
|
as: Component = MenuGroup,
|
|
10
8
|
fillProps = {},
|
|
11
|
-
|
|
9
|
+
children,
|
|
12
10
|
...props
|
|
13
11
|
}) {
|
|
14
|
-
return /* @__PURE__ */ jsx(
|
|
15
|
-
|
|
16
|
-
{
|
|
17
|
-
|
|
18
|
-
bubblesVirtually,
|
|
19
|
-
fillProps,
|
|
20
|
-
children: (fills) => {
|
|
21
|
-
if (!Children.toArray(fills).length) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
const initializedByPlugins = [];
|
|
25
|
-
Children.forEach(
|
|
26
|
-
fills,
|
|
27
|
-
({
|
|
28
|
-
props: { __unstableExplicitMenuItem, __unstableTarget }
|
|
29
|
-
}) => {
|
|
30
|
-
if (__unstableTarget && __unstableExplicitMenuItem) {
|
|
31
|
-
initializedByPlugins.push(__unstableTarget);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
const children = Children.map(fills, (child) => {
|
|
36
|
-
if (!child.props.__unstableExplicitMenuItem && initializedByPlugins.includes(
|
|
37
|
-
child.props.__unstableTarget
|
|
38
|
-
)) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
return child;
|
|
42
|
-
});
|
|
43
|
-
return /* @__PURE__ */ jsx(Component, { ...props, children });
|
|
44
|
-
}
|
|
12
|
+
return /* @__PURE__ */ jsx(Slot, { name, fillProps, children: (fills) => {
|
|
13
|
+
const items = Children.toArray(fills);
|
|
14
|
+
if (!items.length) {
|
|
15
|
+
return null;
|
|
45
16
|
}
|
|
46
|
-
|
|
17
|
+
if (typeof children === "function") {
|
|
18
|
+
return children(items);
|
|
19
|
+
}
|
|
20
|
+
return /* @__PURE__ */ jsx(Component, { ...props, children: items });
|
|
21
|
+
} });
|
|
47
22
|
}
|
|
48
|
-
function ActionItem({ name, as
|
|
49
|
-
return /* @__PURE__ */ jsx(Fill, { name, children: ({ onClick:
|
|
23
|
+
function ActionItem({ name, as, onClick, ...props }) {
|
|
24
|
+
return /* @__PURE__ */ jsx(Fill, { name, children: ({ as: slotAs = MenuItem, onClick: slotOnClick }) => {
|
|
25
|
+
const Component = as ?? slotAs;
|
|
26
|
+
const handlers = [onClick, slotOnClick].filter(Boolean);
|
|
50
27
|
return /* @__PURE__ */ jsx(
|
|
51
28
|
Component,
|
|
52
29
|
{
|
|
53
|
-
onClick:
|
|
54
|
-
(
|
|
55
|
-
|
|
56
|
-
} : void 0,
|
|
30
|
+
onClick: handlers.length ? (...args) => handlers.forEach(
|
|
31
|
+
(handler) => handler(...args)
|
|
32
|
+
) : void 0,
|
|
57
33
|
...props
|
|
58
34
|
}
|
|
59
35
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/action-item/index.js"],
|
|
4
|
-
"sourcesContent": ["import { MenuGroup,
|
|
5
|
-
"mappings": ";AAAA,SAAS,WAAW,
|
|
4
|
+
"sourcesContent": ["import { MenuGroup, MenuItem, Slot, Fill } from '@wordpress/components';\nimport { Children } from '@wordpress/element';\n\nfunction ActionItemSlot( {\n\tname,\n\tas: Component = MenuGroup,\n\tfillProps = {},\n\tchildren,\n\t...props\n} ) {\n\treturn (\n\t\t<Slot name={ name } fillProps={ fillProps }>\n\t\t\t{ ( fills ) => {\n\t\t\t\t// Each fill renders an array of its own, so flatten them into a\n\t\t\t\t// single list before handing them over.\n\t\t\t\tconst items = Children.toArray( fills );\n\n\t\t\t\tif ( ! items.length ) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\tif ( typeof children === 'function' ) {\n\t\t\t\t\treturn children( items );\n\t\t\t\t}\n\n\t\t\t\treturn <Component { ...props }>{ items }</Component>;\n\t\t\t} }\n\t\t</Slot>\n\t);\n}\n\nfunction ActionItem( { name, as, onClick, ...props } ) {\n\treturn (\n\t\t<Fill name={ name }>\n\t\t\t{ ( { as: slotAs = MenuItem, onClick: slotOnClick } ) => {\n\t\t\t\t// The slot provides the component to render the item with, so\n\t\t\t\t// that it fits the menu it ends up in, and an onClick handler,\n\t\t\t\t// for example one that closes that menu. The `as` prop\n\t\t\t\t// replaces the component. The `onClick` prop does not replace\n\t\t\t\t// the handler: both run.\n\t\t\t\tconst Component = as ?? slotAs;\n\t\t\t\tconst handlers = [ onClick, slotOnClick ].filter( Boolean );\n\n\t\t\t\treturn (\n\t\t\t\t\t<Component\n\t\t\t\t\t\tonClick={\n\t\t\t\t\t\t\thandlers.length\n\t\t\t\t\t\t\t\t? ( ...args ) =>\n\t\t\t\t\t\t\t\t\t\thandlers.forEach( ( handler ) =>\n\t\t\t\t\t\t\t\t\t\t\thandler( ...args )\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} }\n\t\t</Fill>\n\t);\n}\n\nActionItem.Slot = ActionItemSlot;\n\nexport default ActionItem;\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,WAAW,UAAU,MAAM,YAAY;AAChD,SAAS,gBAAgB;AAwBd;AAtBX,SAAS,eAAgB;AAAA,EACxB;AAAA,EACA,IAAI,YAAY;AAAA,EAChB,YAAY,CAAC;AAAA,EACb;AAAA,EACA,GAAG;AACJ,GAAI;AACH,SACC,oBAAC,QAAK,MAAc,WACjB,WAAE,UAAW;AAGd,UAAM,QAAQ,SAAS,QAAS,KAAM;AAEtC,QAAK,CAAE,MAAM,QAAS;AACrB,aAAO;AAAA,IACR;AAEA,QAAK,OAAO,aAAa,YAAa;AACrC,aAAO,SAAU,KAAM;AAAA,IACxB;AAEA,WAAO,oBAAC,aAAY,GAAG,OAAU,iBAAO;AAAA,EACzC,GACD;AAEF;AAEA,SAAS,WAAY,EAAE,MAAM,IAAI,SAAS,GAAG,MAAM,GAAI;AACtD,SACC,oBAAC,QAAK,MACH,WAAE,EAAE,IAAI,SAAS,UAAU,SAAS,YAAY,MAAO;AAMxD,UAAM,YAAY,MAAM;AACxB,UAAM,WAAW,CAAE,SAAS,WAAY,EAAE,OAAQ,OAAQ;AAE1D,WACC;AAAA,MAAC;AAAA;AAAA,QACA,SACC,SAAS,SACN,IAAK,SACL,SAAS;AAAA,UAAS,CAAE,YACnB,QAAS,GAAG,IAAK;AAAA,QAClB,IACA;AAAA,QAEF,GAAG;AAAA;AAAA,IACN;AAAA,EAEF,GACD;AAEF;AAEA,WAAW,OAAO;AAElB,IAAO,sBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -27,7 +27,10 @@ import {
|
|
|
27
27
|
} from "@wordpress/compose";
|
|
28
28
|
import { usePluginContext } from "@wordpress/plugins";
|
|
29
29
|
import ComplementaryAreaHeader from "../complementary-area-header/index.mjs";
|
|
30
|
-
import
|
|
30
|
+
import {
|
|
31
|
+
DefaultComplementaryAreaMoreMenuItem,
|
|
32
|
+
useHasComplementaryAreaMenuItem
|
|
33
|
+
} from "../complementary-area-more-menu-item/index.mjs";
|
|
31
34
|
import ComplementaryAreaToggle from "../complementary-area-toggle/index.mjs";
|
|
32
35
|
import PinnedItems from "../pinned-items/index.mjs";
|
|
33
36
|
import { store as interfaceStore } from "../../store/index.mjs";
|
|
@@ -177,6 +180,7 @@ function ComplementaryArea({
|
|
|
177
180
|
},
|
|
178
181
|
[identifier, scope]
|
|
179
182
|
);
|
|
183
|
+
const hasMenuItem = useHasComplementaryAreaMenuItem(scope, name);
|
|
180
184
|
const isMobileViewport = useViewportMatch("medium", "<");
|
|
181
185
|
useAdjustComplementaryListener(
|
|
182
186
|
scope,
|
|
@@ -227,8 +231,8 @@ function ComplementaryArea({
|
|
|
227
231
|
shortcut: toggleShortcut
|
|
228
232
|
}
|
|
229
233
|
) }),
|
|
230
|
-
name && isPinnable && /* @__PURE__ */ jsx(
|
|
231
|
-
|
|
234
|
+
name && isPinnable && !hasMenuItem && /* @__PURE__ */ jsx(
|
|
235
|
+
DefaultComplementaryAreaMoreMenuItem,
|
|
232
236
|
{
|
|
233
237
|
target: name,
|
|
234
238
|
scope,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/complementary-area/index.js"],
|
|
4
|
-
"sourcesContent": ["import clsx from 'clsx';\nimport {\n\tButton,\n\tPanel,\n\tSlot,\n\tFill,\n\t__unstableMotion as motion,\n\t__unstableAnimatePresence as AnimatePresence,\n} from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { check, starEmpty, starFilled } from '@wordpress/icons';\nimport {\n\tcloneElement,\n\tisValidElement,\n\tuseEffect,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { store as viewportStore } from '@wordpress/viewport';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport {\n\tuseReducedMotion,\n\tuseViewportMatch,\n\tusePrevious,\n} from '@wordpress/compose';\nimport { usePluginContext } from '@wordpress/plugins';\nimport ComplementaryAreaHeader from '../complementary-area-header';\nimport ComplementaryAreaMoreMenuItem from '../complementary-area-more-menu-item';\nimport ComplementaryAreaToggle from '../complementary-area-toggle';\nimport PinnedItems from '../pinned-items';\nimport { store as interfaceStore } from '../../store';\n\nconst ANIMATION_DURATION = 0.3;\n\nfunction ComplementaryAreaSlot( { scope, ...props } ) {\n\treturn <Slot name={ `ComplementaryArea/${ scope }` } { ...props } />;\n}\n\nconst variants = {\n\t// `auto` leaves the width to the area's own stylesheet, so it stays in one\n\t// place. framer-motion measures the element to animate, then restores\n\t// `auto`.\n\topen: { width: 'auto' },\n\t// Resolved with the `custom` value passed to `AnimatePresence`, which is\n\t// the only way an already removed element can be given a fresh transition.\n\tclosed: ( transition ) => ( { width: 0, transition } ),\n};\n\n/**\n * Renders the complementary area container, replacing the default `div` with\n * the element given via the `render` prop.\n *\n * `className` and `style` are composed rather than overwritten, since the\n * container is also the scroll container for the sidebar.\n *\n * @param {Object} [render] Replacement element.\n * @param {Object} props Props for the container.\n */\nfunction renderContainer( render, props ) {\n\tif ( isValidElement( render ) ) {\n\t\treturn cloneElement( render, {\n\t\t\t...props,\n\t\t\tclassName: clsx( render.props.className, props.className ),\n\t\t\tstyle: { ...render.props.style, ...props.style },\n\t\t} );\n\t}\n\n\treturn <div { ...props } />;\n}\n\nfunction ComplementaryAreaFill( {\n\tactiveArea,\n\tisActive,\n\tscope,\n\tchildren,\n\tclassName,\n\tid,\n\trender,\n} ) {\n\tconst disableMotion = useReducedMotion();\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\t// Swapping one open area straight for another should not animate.\n\tconst previousActiveArea = usePrevious( activeArea );\n\tconst isSwitchingAreas =\n\t\t!! previousActiveArea &&\n\t\t!! activeArea &&\n\t\tactiveArea !== previousActiveArea;\n\tconst transition = {\n\t\ttype: 'tween',\n\t\tduration:\n\t\t\tdisableMotion || isMobileViewport || isSwitchingAreas\n\t\t\t\t? 0\n\t\t\t\t: ANIMATION_DURATION,\n\t\tease: [ 0.6, 0, 0.4, 1 ],\n\t};\n\n\treturn (\n\t\t<Fill name={ `ComplementaryArea/${ scope }` }>\n\t\t\t<AnimatePresence initial={ false } custom={ transition }>\n\t\t\t\t{ isActive && (\n\t\t\t\t\t<motion.div\n\t\t\t\t\t\tvariants={ variants }\n\t\t\t\t\t\tinitial=\"closed\"\n\t\t\t\t\t\tanimate=\"open\"\n\t\t\t\t\t\texit=\"closed\"\n\t\t\t\t\t\ttransition={ transition }\n\t\t\t\t\t\tclassName=\"interface-complementary-area__fill\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ renderContainer( render, {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tclassName,\n\t\t\t\t\t\t\tchildren,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</motion.div>\n\t\t\t\t) }\n\t\t\t</AnimatePresence>\n\t\t</Fill>\n\t);\n}\n\nfunction useAdjustComplementaryListener(\n\tscope,\n\tidentifier,\n\tactiveArea,\n\tisActive,\n\tisSmall\n) {\n\tconst previousIsSmallRef = useRef( false );\n\tconst shouldOpenWhenNotSmallRef = useRef( false );\n\tconst { enableComplementaryArea, disableComplementaryArea } =\n\t\tuseDispatch( interfaceStore );\n\tuseEffect( () => {\n\t\t// If the complementary area is active and the editor is switching from\n\t\t// a big to a small window size.\n\t\tif ( isActive && isSmall && ! previousIsSmallRef.current ) {\n\t\t\tdisableComplementaryArea( scope );\n\t\t\t// Flag the complementary area to be reopened when the window size\n\t\t\t// goes from small to big.\n\t\t\tshouldOpenWhenNotSmallRef.current = true;\n\t\t} else if (\n\t\t\t// If there is a flag indicating the complementary area should be\n\t\t\t// enabled when we go from small to big window size and we are going\n\t\t\t// from a small to big window size.\n\t\t\tshouldOpenWhenNotSmallRef.current &&\n\t\t\t! isSmall &&\n\t\t\tpreviousIsSmallRef.current\n\t\t) {\n\t\t\t// Remove the flag indicating the complementary area should be\n\t\t\t// enabled.\n\t\t\tshouldOpenWhenNotSmallRef.current = false;\n\t\t\tenableComplementaryArea( scope, identifier );\n\t\t} else if (\n\t\t\t// If the flag is indicating the current complementary should be\n\t\t\t// reopened but another complementary area becomes active, remove\n\t\t\t// the flag.\n\t\t\tshouldOpenWhenNotSmallRef.current &&\n\t\t\tactiveArea &&\n\t\t\tactiveArea !== identifier\n\t\t) {\n\t\t\tshouldOpenWhenNotSmallRef.current = false;\n\t\t}\n\t\tif ( isSmall !== previousIsSmallRef.current ) {\n\t\t\tpreviousIsSmallRef.current = isSmall;\n\t\t}\n\t}, [\n\t\tisActive,\n\t\tisSmall,\n\t\tscope,\n\t\tidentifier,\n\t\tactiveArea,\n\t\tdisableComplementaryArea,\n\t\tenableComplementaryArea,\n\t] );\n}\n\nfunction ComplementaryArea( {\n\tchildren,\n\tclassName,\n\tcloseLabel = __( 'Close plugin' ),\n\tidentifier: identifierProp,\n\theader,\n\theaderClassName,\n\ticon: iconProp,\n\tisPinnable = true,\n\tpanelClassName,\n\trender,\n\tscope,\n\tname,\n\ttitle,\n\ttoggleShortcut,\n\tisActiveByDefault,\n} ) {\n\tconst context = usePluginContext();\n\tconst icon = iconProp || context.icon;\n\tconst identifier = identifierProp || `${ context.name }/${ name }`;\n\n\t// This state is used to delay the rendering of the Fill\n\t// until the initial effect runs.\n\t// This prevents the animation from running on mount if\n\t// the complementary area is active by default.\n\tconst [ isReady, setIsReady ] = useState( false );\n\tconst {\n\t\tisLoading,\n\t\tisActive,\n\t\tisPinned,\n\t\tactiveArea,\n\t\tisSmall,\n\t\tisLarge,\n\t\tshowIconLabels,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetActiveComplementaryArea,\n\t\t\t\tisComplementaryAreaLoading,\n\t\t\t\tisItemPinned,\n\t\t\t} = select( interfaceStore );\n\t\t\tconst { get } = select( preferencesStore );\n\n\t\t\tconst _activeArea = getActiveComplementaryArea( scope );\n\n\t\t\treturn {\n\t\t\t\tisLoading: isComplementaryAreaLoading( scope ),\n\t\t\t\tisActive: _activeArea === identifier,\n\t\t\t\tisPinned: isItemPinned( scope, identifier ),\n\t\t\t\tactiveArea: _activeArea,\n\t\t\t\tisSmall: select( viewportStore ).isViewportMatch( '< medium' ),\n\t\t\t\tisLarge: select( viewportStore ).isViewportMatch( 'large' ),\n\t\t\t\tshowIconLabels: get( 'core', 'showIconLabels' ),\n\t\t\t};\n\t\t},\n\t\t[ identifier, scope ]\n\t);\n\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\n\tuseAdjustComplementaryListener(\n\t\tscope,\n\t\tidentifier,\n\t\tactiveArea,\n\t\tisActive,\n\t\tisSmall\n\t);\n\tconst {\n\t\tenableComplementaryArea,\n\t\tdisableComplementaryArea,\n\t\tpinItem,\n\t\tunpinItem,\n\t} = useDispatch( interfaceStore );\n\n\tuseEffect( () => {\n\t\t// Set initial visibility: For large screens, enable if it's active by\n\t\t// default. For small screens, always initially disable.\n\t\tif ( isActiveByDefault && activeArea === undefined && ! isSmall ) {\n\t\t\tenableComplementaryArea( scope, identifier );\n\t\t} else if ( activeArea === undefined && isSmall ) {\n\t\t\tdisableComplementaryArea( scope, identifier );\n\t\t}\n\t\tsetIsReady( true );\n\t}, [\n\t\tactiveArea,\n\t\tisActiveByDefault,\n\t\tscope,\n\t\tidentifier,\n\t\tisSmall,\n\t\tenableComplementaryArea,\n\t\tdisableComplementaryArea,\n\t] );\n\n\tif ( ! isReady ) {\n\t\treturn;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ isPinnable && (\n\t\t\t\t<PinnedItems scope={ scope }>\n\t\t\t\t\t{ isPinned && (\n\t\t\t\t\t\t<ComplementaryAreaToggle\n\t\t\t\t\t\t\tscope={ scope }\n\t\t\t\t\t\t\tidentifier={ identifier }\n\t\t\t\t\t\t\tisPressed={\n\t\t\t\t\t\t\t\tisActive && ( ! showIconLabels || isLarge )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\taria-expanded={ isActive }\n\t\t\t\t\t\t\taria-disabled={ isLoading }\n\t\t\t\t\t\t\tlabel={ title }\n\t\t\t\t\t\t\ticon={ showIconLabels ? check : icon }\n\t\t\t\t\t\t\tshowTooltip={ ! showIconLabels }\n\t\t\t\t\t\t\tvariant={ showIconLabels ? 'tertiary' : undefined }\n\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\tshortcut={ toggleShortcut }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</PinnedItems>\n\t\t\t) }\n\t\t\t{ name && isPinnable && (\n\t\t\t\t<ComplementaryAreaMoreMenuItem\n\t\t\t\t\ttarget={ name }\n\t\t\t\t\tscope={ scope }\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tidentifier={ identifier }\n\t\t\t\t>\n\t\t\t\t\t{ title }\n\t\t\t\t</ComplementaryAreaMoreMenuItem>\n\t\t\t) }\n\t\t\t<ComplementaryAreaFill\n\t\t\t\tactiveArea={ activeArea }\n\t\t\t\tisActive={ isActive }\n\t\t\t\tclassName={ clsx( 'interface-complementary-area', className ) }\n\t\t\t\tscope={ scope }\n\t\t\t\tid={ identifier.replace( '/', ':' ) }\n\t\t\t\trender={ render }\n\t\t\t>\n\t\t\t\t<ComplementaryAreaHeader\n\t\t\t\t\tclassName={ headerClassName }\n\t\t\t\t\tcloseLabel={ closeLabel }\n\t\t\t\t\tonClose={ () => disableComplementaryArea( scope ) }\n\t\t\t\t\ttoggleButtonProps={ {\n\t\t\t\t\t\tlabel: closeLabel,\n\t\t\t\t\t\tsize: 'compact',\n\t\t\t\t\t\tshortcut: toggleShortcut,\n\t\t\t\t\t\tscope,\n\t\t\t\t\t\tidentifier,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ header || (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<h2 className=\"interface-complementary-area-header__title\">\n\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t</h2>\n\t\t\t\t\t\t\t{ isPinnable && ! isMobileViewport && (\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tclassName=\"interface-complementary-area__pin-unpin-item\"\n\t\t\t\t\t\t\t\t\ticon={ isPinned ? starFilled : starEmpty }\n\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\tisPinned\n\t\t\t\t\t\t\t\t\t\t\t? __( 'Unpin from toolbar' )\n\t\t\t\t\t\t\t\t\t\t\t: __( 'Pin to toolbar' )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t( isPinned ? unpinItem : pinItem )(\n\t\t\t\t\t\t\t\t\t\t\tscope,\n\t\t\t\t\t\t\t\t\t\t\tidentifier\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tisPressed={ isPinned }\n\t\t\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</ComplementaryAreaHeader>\n\t\t\t\t<Panel className={ panelClassName }>{ children }</Panel>\n\t\t\t</ComplementaryAreaFill>\n\t\t</>\n\t);\n}\n\nComplementaryArea.Slot = ComplementaryAreaSlot;\n\nexport default ComplementaryArea;\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAO,UAAU;AACjB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,oBAAoB;AAAA,EACpB,6BAA6B;AAAA,OACvB;AACP,SAAS,aAAa,iBAAiB;AACvC,SAAS,UAAU;AACnB,SAAS,OAAO,WAAW,kBAAkB;AAC7C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,SAAS,qBAAqB;AACvC,SAAS,SAAS,wBAAwB;AAC1C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,wBAAwB;AACjC,OAAO,6BAA6B;AACpC,
|
|
4
|
+
"sourcesContent": ["import clsx from 'clsx';\nimport {\n\tButton,\n\tPanel,\n\tSlot,\n\tFill,\n\t__unstableMotion as motion,\n\t__unstableAnimatePresence as AnimatePresence,\n} from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport { check, starEmpty, starFilled } from '@wordpress/icons';\nimport {\n\tcloneElement,\n\tisValidElement,\n\tuseEffect,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { store as viewportStore } from '@wordpress/viewport';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport {\n\tuseReducedMotion,\n\tuseViewportMatch,\n\tusePrevious,\n} from '@wordpress/compose';\nimport { usePluginContext } from '@wordpress/plugins';\nimport ComplementaryAreaHeader from '../complementary-area-header';\nimport {\n\tDefaultComplementaryAreaMoreMenuItem,\n\tuseHasComplementaryAreaMenuItem,\n} from '../complementary-area-more-menu-item';\nimport ComplementaryAreaToggle from '../complementary-area-toggle';\nimport PinnedItems from '../pinned-items';\nimport { store as interfaceStore } from '../../store';\n\nconst ANIMATION_DURATION = 0.3;\n\nfunction ComplementaryAreaSlot( { scope, ...props } ) {\n\treturn <Slot name={ `ComplementaryArea/${ scope }` } { ...props } />;\n}\n\nconst variants = {\n\t// `auto` leaves the width to the area's own stylesheet, so it stays in one\n\t// place. framer-motion measures the element to animate, then restores\n\t// `auto`.\n\topen: { width: 'auto' },\n\t// Resolved with the `custom` value passed to `AnimatePresence`, which is\n\t// the only way an already removed element can be given a fresh transition.\n\tclosed: ( transition ) => ( { width: 0, transition } ),\n};\n\n/**\n * Renders the complementary area container, replacing the default `div` with\n * the element given via the `render` prop.\n *\n * `className` and `style` are composed rather than overwritten, since the\n * container is also the scroll container for the sidebar.\n *\n * @param {Object} [render] Replacement element.\n * @param {Object} props Props for the container.\n */\nfunction renderContainer( render, props ) {\n\tif ( isValidElement( render ) ) {\n\t\treturn cloneElement( render, {\n\t\t\t...props,\n\t\t\tclassName: clsx( render.props.className, props.className ),\n\t\t\tstyle: { ...render.props.style, ...props.style },\n\t\t} );\n\t}\n\n\treturn <div { ...props } />;\n}\n\nfunction ComplementaryAreaFill( {\n\tactiveArea,\n\tisActive,\n\tscope,\n\tchildren,\n\tclassName,\n\tid,\n\trender,\n} ) {\n\tconst disableMotion = useReducedMotion();\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\t// Swapping one open area straight for another should not animate.\n\tconst previousActiveArea = usePrevious( activeArea );\n\tconst isSwitchingAreas =\n\t\t!! previousActiveArea &&\n\t\t!! activeArea &&\n\t\tactiveArea !== previousActiveArea;\n\tconst transition = {\n\t\ttype: 'tween',\n\t\tduration:\n\t\t\tdisableMotion || isMobileViewport || isSwitchingAreas\n\t\t\t\t? 0\n\t\t\t\t: ANIMATION_DURATION,\n\t\tease: [ 0.6, 0, 0.4, 1 ],\n\t};\n\n\treturn (\n\t\t<Fill name={ `ComplementaryArea/${ scope }` }>\n\t\t\t<AnimatePresence initial={ false } custom={ transition }>\n\t\t\t\t{ isActive && (\n\t\t\t\t\t<motion.div\n\t\t\t\t\t\tvariants={ variants }\n\t\t\t\t\t\tinitial=\"closed\"\n\t\t\t\t\t\tanimate=\"open\"\n\t\t\t\t\t\texit=\"closed\"\n\t\t\t\t\t\ttransition={ transition }\n\t\t\t\t\t\tclassName=\"interface-complementary-area__fill\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ renderContainer( render, {\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tclassName,\n\t\t\t\t\t\t\tchildren,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t</motion.div>\n\t\t\t\t) }\n\t\t\t</AnimatePresence>\n\t\t</Fill>\n\t);\n}\n\nfunction useAdjustComplementaryListener(\n\tscope,\n\tidentifier,\n\tactiveArea,\n\tisActive,\n\tisSmall\n) {\n\tconst previousIsSmallRef = useRef( false );\n\tconst shouldOpenWhenNotSmallRef = useRef( false );\n\tconst { enableComplementaryArea, disableComplementaryArea } =\n\t\tuseDispatch( interfaceStore );\n\tuseEffect( () => {\n\t\t// If the complementary area is active and the editor is switching from\n\t\t// a big to a small window size.\n\t\tif ( isActive && isSmall && ! previousIsSmallRef.current ) {\n\t\t\tdisableComplementaryArea( scope );\n\t\t\t// Flag the complementary area to be reopened when the window size\n\t\t\t// goes from small to big.\n\t\t\tshouldOpenWhenNotSmallRef.current = true;\n\t\t} else if (\n\t\t\t// If there is a flag indicating the complementary area should be\n\t\t\t// enabled when we go from small to big window size and we are going\n\t\t\t// from a small to big window size.\n\t\t\tshouldOpenWhenNotSmallRef.current &&\n\t\t\t! isSmall &&\n\t\t\tpreviousIsSmallRef.current\n\t\t) {\n\t\t\t// Remove the flag indicating the complementary area should be\n\t\t\t// enabled.\n\t\t\tshouldOpenWhenNotSmallRef.current = false;\n\t\t\tenableComplementaryArea( scope, identifier );\n\t\t} else if (\n\t\t\t// If the flag is indicating the current complementary should be\n\t\t\t// reopened but another complementary area becomes active, remove\n\t\t\t// the flag.\n\t\t\tshouldOpenWhenNotSmallRef.current &&\n\t\t\tactiveArea &&\n\t\t\tactiveArea !== identifier\n\t\t) {\n\t\t\tshouldOpenWhenNotSmallRef.current = false;\n\t\t}\n\t\tif ( isSmall !== previousIsSmallRef.current ) {\n\t\t\tpreviousIsSmallRef.current = isSmall;\n\t\t}\n\t}, [\n\t\tisActive,\n\t\tisSmall,\n\t\tscope,\n\t\tidentifier,\n\t\tactiveArea,\n\t\tdisableComplementaryArea,\n\t\tenableComplementaryArea,\n\t] );\n}\n\nfunction ComplementaryArea( {\n\tchildren,\n\tclassName,\n\tcloseLabel = __( 'Close plugin' ),\n\tidentifier: identifierProp,\n\theader,\n\theaderClassName,\n\ticon: iconProp,\n\tisPinnable = true,\n\tpanelClassName,\n\trender,\n\tscope,\n\tname,\n\ttitle,\n\ttoggleShortcut,\n\tisActiveByDefault,\n} ) {\n\tconst context = usePluginContext();\n\tconst icon = iconProp || context.icon;\n\tconst identifier = identifierProp || `${ context.name }/${ name }`;\n\n\t// This state is used to delay the rendering of the Fill\n\t// until the initial effect runs.\n\t// This prevents the animation from running on mount if\n\t// the complementary area is active by default.\n\tconst [ isReady, setIsReady ] = useState( false );\n\tconst {\n\t\tisLoading,\n\t\tisActive,\n\t\tisPinned,\n\t\tactiveArea,\n\t\tisSmall,\n\t\tisLarge,\n\t\tshowIconLabels,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetActiveComplementaryArea,\n\t\t\t\tisComplementaryAreaLoading,\n\t\t\t\tisItemPinned,\n\t\t\t} = select( interfaceStore );\n\t\t\tconst { get } = select( preferencesStore );\n\n\t\t\tconst _activeArea = getActiveComplementaryArea( scope );\n\n\t\t\treturn {\n\t\t\t\tisLoading: isComplementaryAreaLoading( scope ),\n\t\t\t\tisActive: _activeArea === identifier,\n\t\t\t\tisPinned: isItemPinned( scope, identifier ),\n\t\t\t\tactiveArea: _activeArea,\n\t\t\t\tisSmall: select( viewportStore ).isViewportMatch( '< medium' ),\n\t\t\t\tisLarge: select( viewportStore ).isViewportMatch( 'large' ),\n\t\t\t\tshowIconLabels: get( 'core', 'showIconLabels' ),\n\t\t\t};\n\t\t},\n\t\t[ identifier, scope ]\n\t);\n\n\tconst hasMenuItem = useHasComplementaryAreaMenuItem( scope, name );\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\n\tuseAdjustComplementaryListener(\n\t\tscope,\n\t\tidentifier,\n\t\tactiveArea,\n\t\tisActive,\n\t\tisSmall\n\t);\n\tconst {\n\t\tenableComplementaryArea,\n\t\tdisableComplementaryArea,\n\t\tpinItem,\n\t\tunpinItem,\n\t} = useDispatch( interfaceStore );\n\n\tuseEffect( () => {\n\t\t// Set initial visibility: For large screens, enable if it's active by\n\t\t// default. For small screens, always initially disable.\n\t\tif ( isActiveByDefault && activeArea === undefined && ! isSmall ) {\n\t\t\tenableComplementaryArea( scope, identifier );\n\t\t} else if ( activeArea === undefined && isSmall ) {\n\t\t\tdisableComplementaryArea( scope, identifier );\n\t\t}\n\t\tsetIsReady( true );\n\t}, [\n\t\tactiveArea,\n\t\tisActiveByDefault,\n\t\tscope,\n\t\tidentifier,\n\t\tisSmall,\n\t\tenableComplementaryArea,\n\t\tdisableComplementaryArea,\n\t] );\n\n\tif ( ! isReady ) {\n\t\treturn;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ isPinnable && (\n\t\t\t\t<PinnedItems scope={ scope }>\n\t\t\t\t\t{ isPinned && (\n\t\t\t\t\t\t<ComplementaryAreaToggle\n\t\t\t\t\t\t\tscope={ scope }\n\t\t\t\t\t\t\tidentifier={ identifier }\n\t\t\t\t\t\t\tisPressed={\n\t\t\t\t\t\t\t\tisActive && ( ! showIconLabels || isLarge )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\taria-expanded={ isActive }\n\t\t\t\t\t\t\taria-disabled={ isLoading }\n\t\t\t\t\t\t\tlabel={ title }\n\t\t\t\t\t\t\ticon={ showIconLabels ? check : icon }\n\t\t\t\t\t\t\tshowTooltip={ ! showIconLabels }\n\t\t\t\t\t\t\tvariant={ showIconLabels ? 'tertiary' : undefined }\n\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\tshortcut={ toggleShortcut }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</PinnedItems>\n\t\t\t) }\n\t\t\t{ name && isPinnable && ! hasMenuItem && (\n\t\t\t\t<DefaultComplementaryAreaMoreMenuItem\n\t\t\t\t\ttarget={ name }\n\t\t\t\t\tscope={ scope }\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tidentifier={ identifier }\n\t\t\t\t>\n\t\t\t\t\t{ title }\n\t\t\t\t</DefaultComplementaryAreaMoreMenuItem>\n\t\t\t) }\n\t\t\t<ComplementaryAreaFill\n\t\t\t\tactiveArea={ activeArea }\n\t\t\t\tisActive={ isActive }\n\t\t\t\tclassName={ clsx( 'interface-complementary-area', className ) }\n\t\t\t\tscope={ scope }\n\t\t\t\tid={ identifier.replace( '/', ':' ) }\n\t\t\t\trender={ render }\n\t\t\t>\n\t\t\t\t<ComplementaryAreaHeader\n\t\t\t\t\tclassName={ headerClassName }\n\t\t\t\t\tcloseLabel={ closeLabel }\n\t\t\t\t\tonClose={ () => disableComplementaryArea( scope ) }\n\t\t\t\t\ttoggleButtonProps={ {\n\t\t\t\t\t\tlabel: closeLabel,\n\t\t\t\t\t\tsize: 'compact',\n\t\t\t\t\t\tshortcut: toggleShortcut,\n\t\t\t\t\t\tscope,\n\t\t\t\t\t\tidentifier,\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ header || (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<h2 className=\"interface-complementary-area-header__title\">\n\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t</h2>\n\t\t\t\t\t\t\t{ isPinnable && ! isMobileViewport && (\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tclassName=\"interface-complementary-area__pin-unpin-item\"\n\t\t\t\t\t\t\t\t\ticon={ isPinned ? starFilled : starEmpty }\n\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\tisPinned\n\t\t\t\t\t\t\t\t\t\t\t? __( 'Unpin from toolbar' )\n\t\t\t\t\t\t\t\t\t\t\t: __( 'Pin to toolbar' )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t( isPinned ? unpinItem : pinItem )(\n\t\t\t\t\t\t\t\t\t\t\tscope,\n\t\t\t\t\t\t\t\t\t\t\tidentifier\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tisPressed={ isPinned }\n\t\t\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</ComplementaryAreaHeader>\n\t\t\t\t<Panel className={ panelClassName }>{ children }</Panel>\n\t\t\t</ComplementaryAreaFill>\n\t\t</>\n\t);\n}\n\nComplementaryArea.Slot = ComplementaryAreaSlot;\n\nexport default ComplementaryArea;\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,UAAU;AACjB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,oBAAoB;AAAA,EACpB,6BAA6B;AAAA,OACvB;AACP,SAAS,aAAa,iBAAiB;AACvC,SAAS,UAAU;AACnB,SAAS,OAAO,WAAW,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AA,kBAAC;AAAA;AAAA,oBACA,WAAU;AAAA,oBACV,MAAO,WAAW,aAAa;AAAA,oBAC/B,OACC,WACG,GAAI,oBAAqB,IACzB,GAAI,gBAAiB;AAAA,oBAEzB,SAAU,OACP,WAAW,YAAY;AAAA,sBACxB;AAAA,sBACA;AAAA,oBACD;AAAA,oBAED,WAAY;AAAA,oBACZ,MAAK;AAAA;AAAA,gBACN;AAAA,iBAEF;AAAA;AAAA,UAEF;AAAA,UACA,oBAAC,SAAM,WAAY,gBAAmB,UAAU;AAAA;AAAA;AAAA,IACjD;AAAA,KACD;AAEF;AAEA,kBAAkB,OAAO;AAEzB,IAAO,6BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,38 +1,29 @@
|
|
|
1
1
|
// packages/interface/src/components/complementary-area-more-menu-item/index.js
|
|
2
|
+
import { observableMap, useObservableValue } from "@wordpress/compose";
|
|
3
|
+
import { useLayoutEffect } from "@wordpress/element";
|
|
2
4
|
import { check } from "@wordpress/icons";
|
|
3
|
-
import { MenuItem } from "@wordpress/components";
|
|
4
5
|
import ComplementaryAreaToggle from "../complementary-area-toggle/index.mjs";
|
|
5
6
|
import ActionItem from "../action-item/index.mjs";
|
|
6
7
|
import { jsx } from "react/jsx-runtime";
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
__unstableTarget,
|
|
13
|
-
...restProps
|
|
14
|
-
}) => /* @__PURE__ */ jsx(MenuItem, { ...restProps });
|
|
15
|
-
function ComplementaryAreaMoreMenuItem({
|
|
8
|
+
var menuItems = observableMap();
|
|
9
|
+
function useHasComplementaryAreaMenuItem(scope, target) {
|
|
10
|
+
return !!useObservableValue(menuItems, `${scope}/${target}`);
|
|
11
|
+
}
|
|
12
|
+
function DefaultComplementaryAreaMoreMenuItem({
|
|
16
13
|
scope,
|
|
17
14
|
target,
|
|
18
|
-
__unstableExplicitMenuItem,
|
|
19
15
|
...props
|
|
20
16
|
}) {
|
|
21
17
|
return /* @__PURE__ */ jsx(
|
|
22
18
|
ComplementaryAreaToggle,
|
|
23
19
|
{
|
|
24
|
-
as: (toggleProps) =>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
name: `${scope}/plugin-more-menu`,
|
|
32
|
-
...toggleProps
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
},
|
|
20
|
+
as: (toggleProps) => /* @__PURE__ */ jsx(
|
|
21
|
+
ActionItem,
|
|
22
|
+
{
|
|
23
|
+
name: `${scope}/plugin-more-menu`,
|
|
24
|
+
...toggleProps
|
|
25
|
+
}
|
|
26
|
+
),
|
|
36
27
|
role: "menuitemcheckbox",
|
|
37
28
|
selectedIcon: check,
|
|
38
29
|
name: target,
|
|
@@ -41,7 +32,39 @@ function ComplementaryAreaMoreMenuItem({
|
|
|
41
32
|
}
|
|
42
33
|
);
|
|
43
34
|
}
|
|
35
|
+
function ComplementaryAreaMoreMenuItem({
|
|
36
|
+
scope,
|
|
37
|
+
target,
|
|
38
|
+
// Accepted so they don't leak to DOM elements. Registering the menu item is
|
|
39
|
+
// what keeps `ComplementaryArea` from injecting a second one.
|
|
40
|
+
__unstableExplicitMenuItem,
|
|
41
|
+
__unstableTarget,
|
|
42
|
+
...props
|
|
43
|
+
}) {
|
|
44
|
+
useLayoutEffect(() => {
|
|
45
|
+
const key = `${scope}/${target}`;
|
|
46
|
+
menuItems.set(key, (menuItems.get(key) ?? 0) + 1);
|
|
47
|
+
return () => {
|
|
48
|
+
const count = menuItems.get(key) - 1;
|
|
49
|
+
if (count) {
|
|
50
|
+
menuItems.set(key, count);
|
|
51
|
+
} else {
|
|
52
|
+
menuItems.delete(key);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}, [scope, target]);
|
|
56
|
+
return /* @__PURE__ */ jsx(
|
|
57
|
+
DefaultComplementaryAreaMoreMenuItem,
|
|
58
|
+
{
|
|
59
|
+
scope,
|
|
60
|
+
target,
|
|
61
|
+
...props
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
}
|
|
44
65
|
export {
|
|
45
|
-
|
|
66
|
+
DefaultComplementaryAreaMoreMenuItem,
|
|
67
|
+
ComplementaryAreaMoreMenuItem as default,
|
|
68
|
+
useHasComplementaryAreaMenuItem
|
|
46
69
|
};
|
|
47
70
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/complementary-area-more-menu-item/index.js"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";AAAA,SAAS,
|
|
4
|
+
"sourcesContent": ["import { observableMap, useObservableValue } from '@wordpress/compose';\nimport { useLayoutEffect } from '@wordpress/element';\nimport { check } from '@wordpress/icons';\nimport ComplementaryAreaToggle from '../complementary-area-toggle';\nimport ActionItem from '../action-item';\n\n// How many more menu items are rendered for a complementary area, by\n// `scope/target`.\nconst menuItems = observableMap();\n\nexport function useHasComplementaryAreaMenuItem( scope, target ) {\n\treturn !! useObservableValue( menuItems, `${ scope }/${ target }` );\n}\n\n// The more menu item `ComplementaryArea` injects for every pinnable area. It is\n// left out while a plugin renders one of its own for the same area.\n// @see https://github.com/WordPress/gutenberg/issues/14457\nexport function DefaultComplementaryAreaMoreMenuItem( {\n\tscope,\n\ttarget,\n\t...props\n} ) {\n\treturn (\n\t\t<ComplementaryAreaToggle\n\t\t\tas={ ( toggleProps ) => (\n\t\t\t\t<ActionItem\n\t\t\t\t\tname={ `${ scope }/plugin-more-menu` }\n\t\t\t\t\t{ ...toggleProps }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\trole=\"menuitemcheckbox\"\n\t\t\tselectedIcon={ check }\n\t\t\tname={ target }\n\t\t\tscope={ scope }\n\t\t\t{ ...props }\n\t\t/>\n\t);\n}\n\nexport default function ComplementaryAreaMoreMenuItem( {\n\tscope,\n\ttarget,\n\t// Accepted so they don't leak to DOM elements. Registering the menu item is\n\t// what keeps `ComplementaryArea` from injecting a second one.\n\t__unstableExplicitMenuItem,\n\t__unstableTarget,\n\t...props\n} ) {\n\tuseLayoutEffect( () => {\n\t\tconst key = `${ scope }/${ target }`;\n\t\tmenuItems.set( key, ( menuItems.get( key ) ?? 0 ) + 1 );\n\n\t\treturn () => {\n\t\t\tconst count = menuItems.get( key ) - 1;\n\t\t\tif ( count ) {\n\t\t\t\tmenuItems.set( key, count );\n\t\t\t} else {\n\t\t\t\tmenuItems.delete( key );\n\t\t\t}\n\t\t};\n\t}, [ scope, target ] );\n\n\treturn (\n\t\t<DefaultComplementaryAreaMoreMenuItem\n\t\t\tscope={ scope }\n\t\t\ttarget={ target }\n\t\t\t{ ...props }\n\t\t/>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,eAAe,0BAA0B;AAClD,SAAS,uBAAuB;AAChC,SAAS,aAAa;AACtB,OAAO,6BAA6B;AACpC,OAAO,gBAAgB;AAqBnB;AAjBJ,IAAM,YAAY,cAAc;AAEzB,SAAS,gCAAiC,OAAO,QAAS;AAChE,SAAO,CAAC,CAAE,mBAAoB,WAAW,GAAI,KAAM,IAAK,MAAO,EAAG;AACnE;AAKO,SAAS,qCAAsC;AAAA,EACrD;AAAA,EACA;AAAA,EACA,GAAG;AACJ,GAAI;AACH,SACC;AAAA,IAAC;AAAA;AAAA,MACA,IAAK,CAAE,gBACN;AAAA,QAAC;AAAA;AAAA,UACA,MAAO,GAAI,KAAM;AAAA,UACf,GAAG;AAAA;AAAA,MACN;AAAA,MAED,MAAK;AAAA,MACL,cAAe;AAAA,MACf,MAAO;AAAA,MACP;AAAA,MACE,GAAG;AAAA;AAAA,EACN;AAEF;AAEe,SAAR,8BAAgD;AAAA,EACtD;AAAA,EACA;AAAA;AAAA;AAAA,EAGA;AAAA,EACA;AAAA,EACA,GAAG;AACJ,GAAI;AACH,kBAAiB,MAAM;AACtB,UAAM,MAAM,GAAI,KAAM,IAAK,MAAO;AAClC,cAAU,IAAK,MAAO,UAAU,IAAK,GAAI,KAAK,KAAM,CAAE;AAEtD,WAAO,MAAM;AACZ,YAAM,QAAQ,UAAU,IAAK,GAAI,IAAI;AACrC,UAAK,OAAQ;AACZ,kBAAU,IAAK,KAAK,KAAM;AAAA,MAC3B,OAAO;AACN,kBAAU,OAAQ,GAAI;AAAA,MACvB;AAAA,IACD;AAAA,EACD,GAAG,CAAE,OAAO,MAAO,CAAE;AAErB,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACE,GAAG;AAAA;AAAA,EACN;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/interface",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "Interface module for WordPress. The package contains shared functionality across the modern JavaScript-based WordPress screens.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -52,19 +52,19 @@
|
|
|
52
52
|
"build-module/store/index.mjs"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@wordpress/a11y": "^4.
|
|
56
|
-
"@wordpress/admin-ui": "^2.
|
|
57
|
-
"@wordpress/base-styles": "^
|
|
58
|
-
"@wordpress/components": "^
|
|
59
|
-
"@wordpress/compose": "^8.
|
|
60
|
-
"@wordpress/data": "^10.
|
|
61
|
-
"@wordpress/deprecated": "^4.
|
|
62
|
-
"@wordpress/element": "^8.
|
|
63
|
-
"@wordpress/i18n": "^6.
|
|
64
|
-
"@wordpress/icons": "^15.
|
|
65
|
-
"@wordpress/plugins": "^7.
|
|
66
|
-
"@wordpress/preferences": "^4.
|
|
67
|
-
"@wordpress/viewport": "^6.
|
|
55
|
+
"@wordpress/a11y": "^4.54.0",
|
|
56
|
+
"@wordpress/admin-ui": "^2.9.0",
|
|
57
|
+
"@wordpress/base-styles": "^13.0.0",
|
|
58
|
+
"@wordpress/components": "^40.0.0",
|
|
59
|
+
"@wordpress/compose": "^8.7.0",
|
|
60
|
+
"@wordpress/data": "^10.54.0",
|
|
61
|
+
"@wordpress/deprecated": "^4.54.0",
|
|
62
|
+
"@wordpress/element": "^8.6.0",
|
|
63
|
+
"@wordpress/i18n": "^6.27.0",
|
|
64
|
+
"@wordpress/icons": "^15.5.0",
|
|
65
|
+
"@wordpress/plugins": "^7.54.0",
|
|
66
|
+
"@wordpress/preferences": "^4.54.0",
|
|
67
|
+
"@wordpress/viewport": "^6.54.0",
|
|
68
68
|
"clsx": "^2.1.1"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"publishConfig": {
|
|
79
79
|
"access": "public"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "5ef24f60261976bb198ad035db24bf81c1fb92b4"
|
|
82
82
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## ActionItem.Slot
|
|
6
6
|
|
|
7
|
-
The props not referred below are passed to the container component.
|
|
7
|
+
Renders nothing when no fill is present. The props not referred below are passed to the container component.
|
|
8
8
|
|
|
9
9
|
## Props
|
|
10
10
|
|
|
@@ -15,13 +15,6 @@ The name of the slot and fill pair passed to the `Slot` component.
|
|
|
15
15
|
- Type: `String`
|
|
16
16
|
- Required: Yes
|
|
17
17
|
|
|
18
|
-
### bubblesVirtually
|
|
19
|
-
|
|
20
|
-
Property used to change the event bubbling behavior, passed to the `Slot` component.
|
|
21
|
-
|
|
22
|
-
- Type: `boolean`
|
|
23
|
-
- Required: no
|
|
24
|
-
|
|
25
18
|
### as
|
|
26
19
|
|
|
27
20
|
The component used as the container of the fills. Defaults to the `MenuGroup` component.
|
|
@@ -30,6 +23,20 @@ The component used as the container of the fills. Defaults to the `MenuGroup` co
|
|
|
30
23
|
- Required: no
|
|
31
24
|
- Default: `MenuGroup`
|
|
32
25
|
|
|
26
|
+
### fillProps
|
|
27
|
+
|
|
28
|
+
Props passed to every fill. An `as` among them provides the component the items render as, unless the item asks for one of its own.
|
|
29
|
+
|
|
30
|
+
- Type: `Object`
|
|
31
|
+
- Required: no
|
|
32
|
+
|
|
33
|
+
### children
|
|
34
|
+
|
|
35
|
+
A function receiving the rendered fills as a flat array. Use it when the container has to wrap each fill rather than just group them. Takes precedence over `as`.
|
|
36
|
+
|
|
37
|
+
- Type: `Function`
|
|
38
|
+
- Required: no
|
|
39
|
+
|
|
33
40
|
## ActionItem
|
|
34
41
|
|
|
35
42
|
The props not referred below are passed to the item component.
|
|
@@ -50,8 +57,8 @@ Callback function executed when a click on the item happens.
|
|
|
50
57
|
|
|
51
58
|
### as
|
|
52
59
|
|
|
53
|
-
The component that is going to be used to render an action item. Defaults to the `
|
|
60
|
+
The component that is going to be used to render an action item. Defaults to the `as` the slot provides through `fillProps`, or to the `MenuItem` component, so that it nests in the `MenuGroup` the slot renders by default.
|
|
54
61
|
|
|
55
62
|
- Type: `Component`
|
|
56
63
|
- Required: no
|
|
57
|
-
- Default: `
|
|
64
|
+
- Default: `MenuItem`
|
|
@@ -1,72 +1,54 @@
|
|
|
1
|
-
import { MenuGroup,
|
|
1
|
+
import { MenuGroup, MenuItem, Slot, Fill } from '@wordpress/components';
|
|
2
2
|
import { Children } from '@wordpress/element';
|
|
3
3
|
|
|
4
|
-
const noop = () => {};
|
|
5
|
-
|
|
6
4
|
function ActionItemSlot( {
|
|
7
5
|
name,
|
|
8
6
|
as: Component = MenuGroup,
|
|
9
7
|
fillProps = {},
|
|
10
|
-
|
|
8
|
+
children,
|
|
11
9
|
...props
|
|
12
10
|
} ) {
|
|
13
11
|
return (
|
|
14
|
-
<Slot
|
|
15
|
-
name={ name }
|
|
16
|
-
bubblesVirtually={ bubblesVirtually }
|
|
17
|
-
fillProps={ fillProps }
|
|
18
|
-
>
|
|
12
|
+
<Slot name={ name } fillProps={ fillProps }>
|
|
19
13
|
{ ( fills ) => {
|
|
20
|
-
|
|
14
|
+
// Each fill renders an array of its own, so flatten them into a
|
|
15
|
+
// single list before handing them over.
|
|
16
|
+
const items = Children.toArray( fills );
|
|
17
|
+
|
|
18
|
+
if ( ! items.length ) {
|
|
21
19
|
return null;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// from pinnable plugin sidebars.
|
|
28
|
-
// @see https://github.com/WordPress/gutenberg/issues/14457
|
|
29
|
-
const initializedByPlugins = [];
|
|
30
|
-
Children.forEach(
|
|
31
|
-
fills,
|
|
32
|
-
( {
|
|
33
|
-
props: { __unstableExplicitMenuItem, __unstableTarget },
|
|
34
|
-
} ) => {
|
|
35
|
-
if ( __unstableTarget && __unstableExplicitMenuItem ) {
|
|
36
|
-
initializedByPlugins.push( __unstableTarget );
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
const children = Children.map( fills, ( child ) => {
|
|
41
|
-
if (
|
|
42
|
-
! child.props.__unstableExplicitMenuItem &&
|
|
43
|
-
initializedByPlugins.includes(
|
|
44
|
-
child.props.__unstableTarget
|
|
45
|
-
)
|
|
46
|
-
) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
return child;
|
|
50
|
-
} );
|
|
22
|
+
if ( typeof children === 'function' ) {
|
|
23
|
+
return children( items );
|
|
24
|
+
}
|
|
51
25
|
|
|
52
|
-
return <Component { ...props }>{
|
|
26
|
+
return <Component { ...props }>{ items }</Component>;
|
|
53
27
|
} }
|
|
54
28
|
</Slot>
|
|
55
29
|
);
|
|
56
30
|
}
|
|
57
31
|
|
|
58
|
-
function ActionItem( { name, as
|
|
32
|
+
function ActionItem( { name, as, onClick, ...props } ) {
|
|
59
33
|
return (
|
|
60
34
|
<Fill name={ name }>
|
|
61
|
-
{ ( { onClick:
|
|
35
|
+
{ ( { as: slotAs = MenuItem, onClick: slotOnClick } ) => {
|
|
36
|
+
// The slot provides the component to render the item with, so
|
|
37
|
+
// that it fits the menu it ends up in, and an onClick handler,
|
|
38
|
+
// for example one that closes that menu. The `as` prop
|
|
39
|
+
// replaces the component. The `onClick` prop does not replace
|
|
40
|
+
// the handler: both run.
|
|
41
|
+
const Component = as ?? slotAs;
|
|
42
|
+
const handlers = [ onClick, slotOnClick ].filter( Boolean );
|
|
43
|
+
|
|
62
44
|
return (
|
|
63
45
|
<Component
|
|
64
46
|
onClick={
|
|
65
|
-
|
|
66
|
-
? ( ...args ) =>
|
|
67
|
-
(
|
|
68
|
-
|
|
69
|
-
|
|
47
|
+
handlers.length
|
|
48
|
+
? ( ...args ) =>
|
|
49
|
+
handlers.forEach( ( handler ) =>
|
|
50
|
+
handler( ...args )
|
|
51
|
+
)
|
|
70
52
|
: undefined
|
|
71
53
|
}
|
|
72
54
|
{ ...props }
|
|
@@ -26,7 +26,10 @@ import {
|
|
|
26
26
|
} from '@wordpress/compose';
|
|
27
27
|
import { usePluginContext } from '@wordpress/plugins';
|
|
28
28
|
import ComplementaryAreaHeader from '../complementary-area-header';
|
|
29
|
-
import
|
|
29
|
+
import {
|
|
30
|
+
DefaultComplementaryAreaMoreMenuItem,
|
|
31
|
+
useHasComplementaryAreaMenuItem,
|
|
32
|
+
} from '../complementary-area-more-menu-item';
|
|
30
33
|
import ComplementaryAreaToggle from '../complementary-area-toggle';
|
|
31
34
|
import PinnedItems from '../pinned-items';
|
|
32
35
|
import { store as interfaceStore } from '../../store';
|
|
@@ -232,6 +235,7 @@ function ComplementaryArea( {
|
|
|
232
235
|
[ identifier, scope ]
|
|
233
236
|
);
|
|
234
237
|
|
|
238
|
+
const hasMenuItem = useHasComplementaryAreaMenuItem( scope, name );
|
|
235
239
|
const isMobileViewport = useViewportMatch( 'medium', '<' );
|
|
236
240
|
|
|
237
241
|
useAdjustComplementaryListener(
|
|
@@ -294,15 +298,15 @@ function ComplementaryArea( {
|
|
|
294
298
|
) }
|
|
295
299
|
</PinnedItems>
|
|
296
300
|
) }
|
|
297
|
-
{ name && isPinnable && (
|
|
298
|
-
<
|
|
301
|
+
{ name && isPinnable && ! hasMenuItem && (
|
|
302
|
+
<DefaultComplementaryAreaMoreMenuItem
|
|
299
303
|
target={ name }
|
|
300
304
|
scope={ scope }
|
|
301
305
|
icon={ icon }
|
|
302
306
|
identifier={ identifier }
|
|
303
307
|
>
|
|
304
308
|
{ title }
|
|
305
|
-
</
|
|
309
|
+
</DefaultComplementaryAreaMoreMenuItem>
|
|
306
310
|
) }
|
|
307
311
|
<ComplementaryAreaFill
|
|
308
312
|
activeArea={ activeArea }
|
|
@@ -1,38 +1,33 @@
|
|
|
1
|
+
import { observableMap, useObservableValue } from '@wordpress/compose';
|
|
2
|
+
import { useLayoutEffect } from '@wordpress/element';
|
|
1
3
|
import { check } from '@wordpress/icons';
|
|
2
|
-
import { MenuItem } from '@wordpress/components';
|
|
3
4
|
import ComplementaryAreaToggle from '../complementary-area-toggle';
|
|
4
5
|
import ActionItem from '../action-item';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// @see https://github.com/WordPress/gutenberg/issues/14457
|
|
10
|
-
__unstableExplicitMenuItem,
|
|
11
|
-
__unstableTarget,
|
|
12
|
-
...restProps
|
|
13
|
-
} ) => <MenuItem { ...restProps } />;
|
|
7
|
+
// How many more menu items are rendered for a complementary area, by
|
|
8
|
+
// `scope/target`.
|
|
9
|
+
const menuItems = observableMap();
|
|
14
10
|
|
|
15
|
-
export
|
|
11
|
+
export function useHasComplementaryAreaMenuItem( scope, target ) {
|
|
12
|
+
return !! useObservableValue( menuItems, `${ scope }/${ target }` );
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// The more menu item `ComplementaryArea` injects for every pinnable area. It is
|
|
16
|
+
// left out while a plugin renders one of its own for the same area.
|
|
17
|
+
// @see https://github.com/WordPress/gutenberg/issues/14457
|
|
18
|
+
export function DefaultComplementaryAreaMoreMenuItem( {
|
|
16
19
|
scope,
|
|
17
20
|
target,
|
|
18
|
-
__unstableExplicitMenuItem,
|
|
19
21
|
...props
|
|
20
22
|
} ) {
|
|
21
23
|
return (
|
|
22
24
|
<ComplementaryAreaToggle
|
|
23
|
-
as={ ( toggleProps ) =>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
__unstableTarget={ `${ scope }/${ target }` }
|
|
30
|
-
as={ PluginsMenuItem }
|
|
31
|
-
name={ `${ scope }/plugin-more-menu` }
|
|
32
|
-
{ ...toggleProps }
|
|
33
|
-
/>
|
|
34
|
-
);
|
|
35
|
-
} }
|
|
25
|
+
as={ ( toggleProps ) => (
|
|
26
|
+
<ActionItem
|
|
27
|
+
name={ `${ scope }/plugin-more-menu` }
|
|
28
|
+
{ ...toggleProps }
|
|
29
|
+
/>
|
|
30
|
+
) }
|
|
36
31
|
role="menuitemcheckbox"
|
|
37
32
|
selectedIcon={ check }
|
|
38
33
|
name={ target }
|
|
@@ -41,3 +36,35 @@ export default function ComplementaryAreaMoreMenuItem( {
|
|
|
41
36
|
/>
|
|
42
37
|
);
|
|
43
38
|
}
|
|
39
|
+
|
|
40
|
+
export default function ComplementaryAreaMoreMenuItem( {
|
|
41
|
+
scope,
|
|
42
|
+
target,
|
|
43
|
+
// Accepted so they don't leak to DOM elements. Registering the menu item is
|
|
44
|
+
// what keeps `ComplementaryArea` from injecting a second one.
|
|
45
|
+
__unstableExplicitMenuItem,
|
|
46
|
+
__unstableTarget,
|
|
47
|
+
...props
|
|
48
|
+
} ) {
|
|
49
|
+
useLayoutEffect( () => {
|
|
50
|
+
const key = `${ scope }/${ target }`;
|
|
51
|
+
menuItems.set( key, ( menuItems.get( key ) ?? 0 ) + 1 );
|
|
52
|
+
|
|
53
|
+
return () => {
|
|
54
|
+
const count = menuItems.get( key ) - 1;
|
|
55
|
+
if ( count ) {
|
|
56
|
+
menuItems.set( key, count );
|
|
57
|
+
} else {
|
|
58
|
+
menuItems.delete( key );
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}, [ scope, target ] );
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<DefaultComplementaryAreaMoreMenuItem
|
|
65
|
+
scope={ scope }
|
|
66
|
+
target={ target }
|
|
67
|
+
{ ...props }
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
}
|