@wordpress/block-editor 15.6.2 → 15.6.4
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/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +2 -2
- package/build/components/border-radius-control/utils.js +7 -3
- package/build/components/border-radius-control/utils.js.map +2 -2
- package/build/components/global-styles/border-panel.js +11 -7
- package/build/components/global-styles/border-panel.js.map +2 -2
- package/build/components/rich-text/index.js +1 -0
- package/build/components/rich-text/index.js.map +2 -2
- package/build/hooks/block-bindings.js +6 -2
- package/build/hooks/block-bindings.js.map +2 -2
- package/build/hooks/fit-text.js +45 -8
- package/build/hooks/fit-text.js.map +2 -2
- package/build/utils/fit-text-frontend.js +28 -37
- package/build/utils/fit-text-frontend.js.map +2 -2
- package/build/utils/fit-text-utils.js +7 -14
- package/build/utils/fit-text-utils.js.map +2 -2
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +2 -2
- package/build-module/components/border-radius-control/utils.js +7 -3
- package/build-module/components/border-radius-control/utils.js.map +2 -2
- package/build-module/components/global-styles/border-panel.js +11 -7
- package/build-module/components/global-styles/border-panel.js.map +2 -2
- package/build-module/components/rich-text/index.js +1 -0
- package/build-module/components/rich-text/index.js.map +2 -2
- package/build-module/hooks/block-bindings.js +6 -2
- package/build-module/hooks/block-bindings.js.map +2 -2
- package/build-module/hooks/fit-text.js +45 -8
- package/build-module/hooks/fit-text.js.map +2 -2
- package/build-module/utils/fit-text-frontend.js +28 -37
- package/build-module/utils/fit-text-frontend.js.map +2 -2
- package/build-module/utils/fit-text-utils.js +7 -14
- package/build-module/utils/fit-text-utils.js.map +2 -2
- package/package.json +7 -6
- package/src/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/src/components/border-radius-control/test/utils.js +90 -0
- package/src/components/border-radius-control/utils.js +7 -3
- package/src/components/global-styles/border-panel.js +11 -7
- package/src/components/rich-text/index.js +1 -0
- package/src/hooks/block-bindings.js +6 -2
- package/src/hooks/fit-text.js +63 -12
- package/src/utils/fit-text-frontend.js +41 -73
- package/src/utils/fit-text-utils.js +12 -29
- package/tsconfig.json +1 -0
package/build/hooks/fit-text.js
CHANGED
|
@@ -44,6 +44,7 @@ var import_fit_text_utils = require("../utils/fit-text-utils");
|
|
|
44
44
|
var import_store = require("../store");
|
|
45
45
|
var import_use_block_refs = require("../components/block-list/use-block-props/use-block-refs");
|
|
46
46
|
var import_inspector_controls = __toESM(require("../components/inspector-controls"));
|
|
47
|
+
const EMPTY_OBJECT = {};
|
|
47
48
|
const FIT_TEXT_SUPPORT_KEY = "typography.fitText";
|
|
48
49
|
function addAttributes(settings) {
|
|
49
50
|
if (!(0, import_blocks.hasBlockSupport)(settings, FIT_TEXT_SUPPORT_KEY)) {
|
|
@@ -65,12 +66,15 @@ function addAttributes(settings) {
|
|
|
65
66
|
function useFitText({ fitText, name, clientId }) {
|
|
66
67
|
const hasFitTextSupport2 = (0, import_blocks.hasBlockSupport)(name, FIT_TEXT_SUPPORT_KEY);
|
|
67
68
|
const blockElement = (0, import_use_block_refs.useBlockElement)(clientId);
|
|
68
|
-
const blockAttributes = (0, import_data.useSelect)(
|
|
69
|
+
const { blockAttributes, parentId } = (0, import_data.useSelect)(
|
|
69
70
|
(select) => {
|
|
70
71
|
if (!clientId || !hasFitTextSupport2 || !fitText) {
|
|
71
|
-
return;
|
|
72
|
+
return EMPTY_OBJECT;
|
|
72
73
|
}
|
|
73
|
-
return
|
|
74
|
+
return {
|
|
75
|
+
blockAttributes: select(import_store.store).getBlockAttributes(clientId),
|
|
76
|
+
parentId: select(import_store.store).getBlockRootClientId(clientId)
|
|
77
|
+
};
|
|
74
78
|
},
|
|
75
79
|
[clientId, hasFitTextSupport2, fitText]
|
|
76
80
|
);
|
|
@@ -86,23 +90,49 @@ function useFitText({ fitText, name, clientId }) {
|
|
|
86
90
|
blockElement.ownerDocument.head.appendChild(styleElement);
|
|
87
91
|
}
|
|
88
92
|
const blockSelector = `#block-${clientId}`;
|
|
89
|
-
const
|
|
90
|
-
|
|
93
|
+
const applyFontSize = (fontSize) => {
|
|
94
|
+
if (fontSize === 0) {
|
|
95
|
+
styleElement.textContent = "";
|
|
96
|
+
} else {
|
|
97
|
+
styleElement.textContent = `${blockSelector} { font-size: ${fontSize}px !important; }`;
|
|
98
|
+
}
|
|
91
99
|
};
|
|
92
|
-
(0, import_fit_text_utils.optimizeFitText)(blockElement,
|
|
100
|
+
(0, import_fit_text_utils.optimizeFitText)(blockElement, applyFontSize);
|
|
93
101
|
}, [blockElement, clientId, hasFitTextSupport2, fitText]);
|
|
94
102
|
(0, import_element.useEffect)(() => {
|
|
95
103
|
if (!fitText || !blockElement || !clientId || !hasFitTextSupport2) {
|
|
96
104
|
return;
|
|
97
105
|
}
|
|
98
|
-
applyFitText();
|
|
99
106
|
const currentElement = blockElement;
|
|
107
|
+
const previousVisibility = currentElement.style.visibility;
|
|
108
|
+
let hideFrameId = null;
|
|
109
|
+
let calculateFrameId = null;
|
|
110
|
+
let showTimeoutId = null;
|
|
111
|
+
hideFrameId = window.requestAnimationFrame(() => {
|
|
112
|
+
currentElement.style.visibility = "hidden";
|
|
113
|
+
calculateFrameId = window.requestAnimationFrame(() => {
|
|
114
|
+
applyFitText();
|
|
115
|
+
showTimeoutId = setTimeout(() => {
|
|
116
|
+
currentElement.style.visibility = previousVisibility;
|
|
117
|
+
}, 10);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
100
120
|
let resizeObserver;
|
|
101
121
|
if (window.ResizeObserver && currentElement.parentElement) {
|
|
102
122
|
resizeObserver = new window.ResizeObserver(applyFitText);
|
|
103
123
|
resizeObserver.observe(currentElement.parentElement);
|
|
124
|
+
resizeObserver.observe(currentElement);
|
|
104
125
|
}
|
|
105
126
|
return () => {
|
|
127
|
+
if (hideFrameId !== null) {
|
|
128
|
+
window.cancelAnimationFrame(hideFrameId);
|
|
129
|
+
}
|
|
130
|
+
if (calculateFrameId !== null) {
|
|
131
|
+
window.cancelAnimationFrame(calculateFrameId);
|
|
132
|
+
}
|
|
133
|
+
if (showTimeoutId !== null) {
|
|
134
|
+
clearTimeout(showTimeoutId);
|
|
135
|
+
}
|
|
106
136
|
if (resizeObserver) {
|
|
107
137
|
resizeObserver.disconnect();
|
|
108
138
|
}
|
|
@@ -112,7 +142,14 @@ function useFitText({ fitText, name, clientId }) {
|
|
|
112
142
|
styleElement.remove();
|
|
113
143
|
}
|
|
114
144
|
};
|
|
115
|
-
}, [
|
|
145
|
+
}, [
|
|
146
|
+
fitText,
|
|
147
|
+
clientId,
|
|
148
|
+
parentId,
|
|
149
|
+
applyFitText,
|
|
150
|
+
blockElement,
|
|
151
|
+
hasFitTextSupport2
|
|
152
|
+
]);
|
|
116
153
|
(0, import_element.useEffect)(() => {
|
|
117
154
|
if (fitText && blockElement && hasFitTextSupport2) {
|
|
118
155
|
const frameId = window.requestAnimationFrame(() => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/fit-text.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport { useEffect, useCallback } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tToggleControl,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { optimizeFitText } from '../utils/fit-text-utils';\nimport { store as blockEditorStore } from '../store';\nimport { useBlockElement } from '../components/block-list/use-block-props/use-block-refs';\nimport InspectorControls from '../components/inspector-controls';\n\nexport const FIT_TEXT_SUPPORT_KEY = 'typography.fitText';\n\n/**\n * Filters registered block settings, extending attributes to include\n * the `fitText` attribute.\n *\n * @param {Object} settings Original block settings.\n * @return {Object} Filtered block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBlockSupport( settings, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify their own attribute definition.\n\tif ( settings.attributes?.fitText ) {\n\t\treturn settings;\n\t}\n\n\t// Add fitText attribute.\n\treturn {\n\t\t...settings,\n\t\tattributes: {\n\t\t\t...settings.attributes,\n\t\t\tfitText: {\n\t\t\t\ttype: 'boolean',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Custom hook to handle fit text functionality in the editor.\n *\n * @param {Object} props Component props.\n * @param {?boolean} props.fitText Fit text attribute.\n * @param {string} props.name Block name.\n * @param {string} props.clientId Block client ID.\n */\nfunction useFitText( { fitText, name, clientId } ) {\n\tconst hasFitTextSupport = hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY );\n\tconst blockElement = useBlockElement( clientId );\n\n\t// Monitor block attribute changes\n\t// Any attribute may change the available space.\n\tconst blockAttributes = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! clientId || ! hasFitTextSupport || ! fitText ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\treturn select( blockEditorStore ).getBlockAttributes( clientId );\n\t\t},\n\t\t[ clientId, hasFitTextSupport, fitText ]\n\t);\n\n\tconst applyFitText = useCallback( () => {\n\t\tif ( ! blockElement || ! hasFitTextSupport || ! fitText ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Get or create style element with unique ID\n\t\tconst styleId = `fit-text-${ clientId }`;\n\t\tlet styleElement = blockElement.ownerDocument.getElementById( styleId );\n\t\tif ( ! styleElement ) {\n\t\t\tstyleElement = blockElement.ownerDocument.createElement( 'style' );\n\t\t\tstyleElement.id = styleId;\n\t\t\tblockElement.ownerDocument.head.appendChild( styleElement );\n\t\t}\n\n\t\tconst blockSelector = `#block-${ clientId }`;\n\n\t\tconst applyStylesFn = ( css ) => {\n\t\t\tstyleElement.textContent = css;\n\t\t};\n\n\t\toptimizeFitText( blockElement, blockSelector, applyStylesFn );\n\t}, [ blockElement, clientId, hasFitTextSupport, fitText ] );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! fitText ||\n\t\t\t! blockElement ||\n\t\t\t! clientId ||\n\t\t\t! hasFitTextSupport\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Apply initially\n\t\tapplyFitText();\n\n\t\t// Store current element value for cleanup\n\t\tconst currentElement = blockElement;\n\n\t\t// Watch for size changes\n\t\tlet resizeObserver;\n\t\tif ( window.ResizeObserver && currentElement.parentElement ) {\n\t\t\tresizeObserver = new window.ResizeObserver( applyFitText );\n\t\t\tresizeObserver.observe( currentElement.parentElement );\n\t\t}\n\n\t\t// Cleanup function\n\t\treturn () => {\n\t\t\tif ( resizeObserver ) {\n\t\t\t\tresizeObserver.disconnect();\n\t\t\t}\n\n\t\t\tconst styleId = `fit-text-${ clientId }`;\n\t\t\tconst styleElement =\n\t\t\t\tcurrentElement.ownerDocument.getElementById( styleId );\n\t\t\tif ( styleElement ) {\n\t\t\t\tstyleElement.remove();\n\t\t\t}\n\t\t};\n\t}, [ fitText, clientId, applyFitText, blockElement, hasFitTextSupport ] );\n\n\t// Trigger fit text recalculation when content changes\n\tuseEffect( () => {\n\t\tif ( fitText && blockElement && hasFitTextSupport ) {\n\t\t\t// Wait for next frame to ensure DOM has updated after content changes\n\t\t\tconst frameId = window.requestAnimationFrame( () => {\n\t\t\t\tif ( blockElement ) {\n\t\t\t\t\tapplyFitText();\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\treturn () => window.cancelAnimationFrame( frameId );\n\t\t}\n\t}, [\n\t\tblockAttributes,\n\t\tfitText,\n\t\tapplyFitText,\n\t\tblockElement,\n\t\thasFitTextSupport,\n\t] );\n}\n\n/**\n * Fit text control component for the typography panel.\n *\n * @param {Object} props Component props.\n * @param {string} props.clientId Block client ID.\n * @param {Function} props.setAttributes Function to set block attributes.\n * @param {string} props.name Block name.\n * @param {boolean} props.fitText Whether fit text is enabled.\n * @param {string} props.fontSize Font size slug.\n * @param {Object} props.style Block style object.\n */\nexport function FitTextControl( {\n\tclientId,\n\tfitText = false,\n\tsetAttributes,\n\tname,\n\tfontSize,\n\tstyle,\n} ) {\n\tif ( ! hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<InspectorControls group=\"typography\">\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => fitText }\n\t\t\t\tlabel={ __( 'Fit text' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { fitText: undefined } ) }\n\t\t\t\tresetAllFilter={ () => ( { fitText: undefined } ) }\n\t\t\t\tpanelId={ clientId }\n\t\t\t>\n\t\t\t\t<ToggleControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Fit text' ) }\n\t\t\t\t\tchecked={ fitText }\n\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\tconst newFitText = ! fitText || undefined;\n\t\t\t\t\t\tconst updates = { fitText: newFitText };\n\n\t\t\t\t\t\t// When enabling fit text, clear font size if it has a value\n\t\t\t\t\t\tif ( newFitText ) {\n\t\t\t\t\t\t\tif ( fontSize ) {\n\t\t\t\t\t\t\t\tupdates.fontSize = undefined;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif ( style?.typography?.fontSize ) {\n\t\t\t\t\t\t\t\tupdates.style = {\n\t\t\t\t\t\t\t\t\t...style,\n\t\t\t\t\t\t\t\t\ttypography: {\n\t\t\t\t\t\t\t\t\t\t...style?.typography,\n\t\t\t\t\t\t\t\t\t\tfontSize: undefined,\n\t\t\t\t\t\t\t\t\t},\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\n\t\t\t\t\t\tsetAttributes( updates );\n\t\t\t\t\t} }\n\t\t\t\t\thelp={\n\t\t\t\t\t\tfitText\n\t\t\t\t\t\t\t? __( 'Text will resize to fit its container.' )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'The text will resize to fit its container, resetting other font size settings.'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\t\t</InspectorControls>\n\t);\n}\n\n/**\n * Override props applied to the block element on save.\n *\n * @param {Object} props Additional props applied to the block element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Block attributes.\n * @return {Object} Filtered props applied to the block element.\n */\nfunction addSaveProps( props, blockType, attributes ) {\n\tif ( ! hasBlockSupport( blockType, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn props;\n\t}\n\n\tconst { fitText } = attributes;\n\n\tif ( ! fitText ) {\n\t\treturn props;\n\t}\n\n\t// Add CSS class for frontend detection and styling\n\tconst className = props.className\n\t\t? `${ props.className } has-fit-text`\n\t\t: 'has-fit-text';\n\n\treturn {\n\t\t...props,\n\t\tclassName,\n\t};\n}\n/**\n * Override props applied to the block element in the editor.\n *\n * @param {Object} props Component props including block attributes.\n * @param {string} props.name Block name.\n * @param {boolean} props.fitText Whether fit text is enabled.\n * @param {string} props.clientId Block client ID.\n * @return {Object} Filtered props applied to the block element.\n */\nfunction useBlockProps( { name, fitText, clientId } ) {\n\tuseFitText( { fitText, name, clientId } );\n\tif ( ! fitText || ! hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn {};\n\t}\n\treturn {\n\t\tclassName: 'has-fit-text',\n\t};\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/fit-text/addAttribute',\n\taddAttributes\n);\n\nconst hasFitTextSupport = ( blockNameOrType ) => {\n\treturn hasBlockSupport( blockNameOrType, FIT_TEXT_SUPPORT_KEY );\n};\n\nexport default {\n\tuseBlockProps,\n\taddSaveProps,\n\tattributeKeys: [ 'fitText', 'fontSize', 'style' ],\n\thasSupport: hasFitTextSupport,\n\tedit: FitTextControl,\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport { useEffect, useCallback } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tToggleControl,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\n\nconst EMPTY_OBJECT = {};\n\n/**\n * Internal dependencies\n */\nimport { optimizeFitText } from '../utils/fit-text-utils';\nimport { store as blockEditorStore } from '../store';\nimport { useBlockElement } from '../components/block-list/use-block-props/use-block-refs';\nimport InspectorControls from '../components/inspector-controls';\n\nexport const FIT_TEXT_SUPPORT_KEY = 'typography.fitText';\n\n/**\n * Filters registered block settings, extending attributes to include\n * the `fitText` attribute.\n *\n * @param {Object} settings Original block settings.\n * @return {Object} Filtered block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBlockSupport( settings, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify their own attribute definition.\n\tif ( settings.attributes?.fitText ) {\n\t\treturn settings;\n\t}\n\n\t// Add fitText attribute.\n\treturn {\n\t\t...settings,\n\t\tattributes: {\n\t\t\t...settings.attributes,\n\t\t\tfitText: {\n\t\t\t\ttype: 'boolean',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Custom hook to handle fit text functionality in the editor.\n *\n * @param {Object} props Component props.\n * @param {?boolean} props.fitText Fit text attribute.\n * @param {string} props.name Block name.\n * @param {string} props.clientId Block client ID.\n */\nfunction useFitText( { fitText, name, clientId } ) {\n\tconst hasFitTextSupport = hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY );\n\tconst blockElement = useBlockElement( clientId );\n\n\t// Monitor block attribute changes, and parent changes.\n\t// Any attribute or parent change may change the available space.\n\tconst { blockAttributes, parentId } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! clientId || ! hasFitTextSupport || ! fitText ) {\n\t\t\t\treturn EMPTY_OBJECT;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tblockAttributes:\n\t\t\t\t\tselect( blockEditorStore ).getBlockAttributes( clientId ),\n\t\t\t\tparentId:\n\t\t\t\t\tselect( blockEditorStore ).getBlockRootClientId( clientId ),\n\t\t\t};\n\t\t},\n\t\t[ clientId, hasFitTextSupport, fitText ]\n\t);\n\n\tconst applyFitText = useCallback( () => {\n\t\tif ( ! blockElement || ! hasFitTextSupport || ! fitText ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Get or create style element with unique ID\n\t\tconst styleId = `fit-text-${ clientId }`;\n\t\tlet styleElement = blockElement.ownerDocument.getElementById( styleId );\n\t\tif ( ! styleElement ) {\n\t\t\tstyleElement = blockElement.ownerDocument.createElement( 'style' );\n\t\t\tstyleElement.id = styleId;\n\t\t\tblockElement.ownerDocument.head.appendChild( styleElement );\n\t\t}\n\n\t\tconst blockSelector = `#block-${ clientId }`;\n\n\t\tconst applyFontSize = ( fontSize ) => {\n\t\t\tif ( fontSize === 0 ) {\n\t\t\t\tstyleElement.textContent = '';\n\t\t\t} else {\n\t\t\t\tstyleElement.textContent = `${ blockSelector } { font-size: ${ fontSize }px !important; }`;\n\t\t\t}\n\t\t};\n\n\t\toptimizeFitText( blockElement, applyFontSize );\n\t}, [ blockElement, clientId, hasFitTextSupport, fitText ] );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! fitText ||\n\t\t\t! blockElement ||\n\t\t\t! clientId ||\n\t\t\t! hasFitTextSupport\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Store current element value for cleanup\n\t\tconst currentElement = blockElement;\n\t\tconst previousVisibility = currentElement.style.visibility;\n\n\t\t// Store IDs for cleanup\n\t\tlet hideFrameId = null;\n\t\tlet calculateFrameId = null;\n\t\tlet showTimeoutId = null;\n\n\t\t// We are hiding the element doing the calculation of fit text\n\t\t// and then showing it again to avoid the user noticing a flash of potentially\n\t\t// big fitText while the binary search is happening.\n\t\thideFrameId = window.requestAnimationFrame( () => {\n\t\t\tcurrentElement.style.visibility = 'hidden';\n\t\t\t// Wait for browser to render the hidden state\n\t\t\tcalculateFrameId = window.requestAnimationFrame( () => {\n\t\t\t\tapplyFitText();\n\n\t\t\t\t// Using a timeout instead of requestAnimationFrame, because\n\t\t\t\t// with requestAnimationFrame a flash of very high size\n\t\t\t\t// can still occur although rare.\n\t\t\t\tshowTimeoutId = setTimeout( () => {\n\t\t\t\t\tcurrentElement.style.visibility = previousVisibility;\n\t\t\t\t}, 10 );\n\t\t\t} );\n\t\t} );\n\n\t\t// Watch for size changes\n\t\tlet resizeObserver;\n\t\tif ( window.ResizeObserver && currentElement.parentElement ) {\n\t\t\tresizeObserver = new window.ResizeObserver( applyFitText );\n\t\t\tresizeObserver.observe( currentElement.parentElement );\n\t\t\tresizeObserver.observe( currentElement );\n\t\t}\n\n\t\t// Cleanup function\n\t\treturn () => {\n\t\t\t// Cancel pending async operations\n\t\t\tif ( hideFrameId !== null ) {\n\t\t\t\twindow.cancelAnimationFrame( hideFrameId );\n\t\t\t}\n\t\t\tif ( calculateFrameId !== null ) {\n\t\t\t\twindow.cancelAnimationFrame( calculateFrameId );\n\t\t\t}\n\t\t\tif ( showTimeoutId !== null ) {\n\t\t\t\tclearTimeout( showTimeoutId );\n\t\t\t}\n\n\t\t\tif ( resizeObserver ) {\n\t\t\t\tresizeObserver.disconnect();\n\t\t\t}\n\n\t\t\tconst styleId = `fit-text-${ clientId }`;\n\t\t\tconst styleElement =\n\t\t\t\tcurrentElement.ownerDocument.getElementById( styleId );\n\t\t\tif ( styleElement ) {\n\t\t\t\tstyleElement.remove();\n\t\t\t}\n\t\t};\n\t}, [\n\t\tfitText,\n\t\tclientId,\n\t\tparentId,\n\t\tapplyFitText,\n\t\tblockElement,\n\t\thasFitTextSupport,\n\t] );\n\n\t// Trigger fit text recalculation when content changes\n\tuseEffect( () => {\n\t\tif ( fitText && blockElement && hasFitTextSupport ) {\n\t\t\t// Wait for next frame to ensure DOM has updated after content changes\n\t\t\tconst frameId = window.requestAnimationFrame( () => {\n\t\t\t\tif ( blockElement ) {\n\t\t\t\t\tapplyFitText();\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\treturn () => window.cancelAnimationFrame( frameId );\n\t\t}\n\t}, [\n\t\tblockAttributes,\n\t\tfitText,\n\t\tapplyFitText,\n\t\tblockElement,\n\t\thasFitTextSupport,\n\t] );\n}\n\n/**\n * Fit text control component for the typography panel.\n *\n * @param {Object} props Component props.\n * @param {string} props.clientId Block client ID.\n * @param {Function} props.setAttributes Function to set block attributes.\n * @param {string} props.name Block name.\n * @param {boolean} props.fitText Whether fit text is enabled.\n * @param {string} props.fontSize Font size slug.\n * @param {Object} props.style Block style object.\n */\nexport function FitTextControl( {\n\tclientId,\n\tfitText = false,\n\tsetAttributes,\n\tname,\n\tfontSize,\n\tstyle,\n} ) {\n\tif ( ! hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<InspectorControls group=\"typography\">\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => fitText }\n\t\t\t\tlabel={ __( 'Fit text' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { fitText: undefined } ) }\n\t\t\t\tresetAllFilter={ () => ( { fitText: undefined } ) }\n\t\t\t\tpanelId={ clientId }\n\t\t\t>\n\t\t\t\t<ToggleControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Fit text' ) }\n\t\t\t\t\tchecked={ fitText }\n\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\tconst newFitText = ! fitText || undefined;\n\t\t\t\t\t\tconst updates = { fitText: newFitText };\n\n\t\t\t\t\t\t// When enabling fit text, clear font size if it has a value\n\t\t\t\t\t\tif ( newFitText ) {\n\t\t\t\t\t\t\tif ( fontSize ) {\n\t\t\t\t\t\t\t\tupdates.fontSize = undefined;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif ( style?.typography?.fontSize ) {\n\t\t\t\t\t\t\t\tupdates.style = {\n\t\t\t\t\t\t\t\t\t...style,\n\t\t\t\t\t\t\t\t\ttypography: {\n\t\t\t\t\t\t\t\t\t\t...style?.typography,\n\t\t\t\t\t\t\t\t\t\tfontSize: undefined,\n\t\t\t\t\t\t\t\t\t},\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\n\t\t\t\t\t\tsetAttributes( updates );\n\t\t\t\t\t} }\n\t\t\t\t\thelp={\n\t\t\t\t\t\tfitText\n\t\t\t\t\t\t\t? __( 'Text will resize to fit its container.' )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'The text will resize to fit its container, resetting other font size settings.'\n\t\t\t\t\t\t\t )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\t\t</InspectorControls>\n\t);\n}\n\n/**\n * Override props applied to the block element on save.\n *\n * @param {Object} props Additional props applied to the block element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Block attributes.\n * @return {Object} Filtered props applied to the block element.\n */\nfunction addSaveProps( props, blockType, attributes ) {\n\tif ( ! hasBlockSupport( blockType, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn props;\n\t}\n\n\tconst { fitText } = attributes;\n\n\tif ( ! fitText ) {\n\t\treturn props;\n\t}\n\n\t// Add CSS class for frontend detection and styling\n\tconst className = props.className\n\t\t? `${ props.className } has-fit-text`\n\t\t: 'has-fit-text';\n\n\treturn {\n\t\t...props,\n\t\tclassName,\n\t};\n}\n/**\n * Override props applied to the block element in the editor.\n *\n * @param {Object} props Component props including block attributes.\n * @param {string} props.name Block name.\n * @param {boolean} props.fitText Whether fit text is enabled.\n * @param {string} props.clientId Block client ID.\n * @return {Object} Filtered props applied to the block element.\n */\nfunction useBlockProps( { name, fitText, clientId } ) {\n\tuseFitText( { fitText, name, clientId } );\n\tif ( ! fitText || ! hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY ) ) {\n\t\treturn {};\n\t}\n\treturn {\n\t\tclassName: 'has-fit-text',\n\t};\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/fit-text/addAttribute',\n\taddAttributes\n);\n\nconst hasFitTextSupport = ( blockNameOrType ) => {\n\treturn hasBlockSupport( blockNameOrType, FIT_TEXT_SUPPORT_KEY );\n};\n\nexport default {\n\tuseBlockProps,\n\taddSaveProps,\n\tattributeKeys: [ 'fitText', 'fontSize', 'style' ],\n\thasSupport: hasFitTextSupport,\n\tedit: FitTextControl,\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgPI;AA7OJ,mBAA0B;AAC1B,oBAAgC;AAChC,qBAAuC;AACvC,kBAA0B;AAC1B,kBAAmB;AACnB,wBAGO;AAOP,4BAAgC;AAChC,mBAA0C;AAC1C,4BAAgC;AAChC,gCAA8B;AAR9B,MAAM,eAAe,CAAC;AAUf,MAAM,uBAAuB;AASpC,SAAS,cAAe,UAAW;AAClC,MAAK,KAAE,+BAAiB,UAAU,oBAAqB,GAAI;AAC1D,WAAO;AAAA,EACR;AAGA,MAAK,SAAS,YAAY,SAAU;AACnC,WAAO;AAAA,EACR;AAGA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,YAAY;AAAA,MACX,GAAG,SAAS;AAAA,MACZ,SAAS;AAAA,QACR,MAAM;AAAA,MACP;AAAA,IACD;AAAA,EACD;AACD;AAUA,SAAS,WAAY,EAAE,SAAS,MAAM,SAAS,GAAI;AAClD,QAAMA,yBAAoB,+BAAiB,MAAM,oBAAqB;AACtE,QAAM,mBAAe,uCAAiB,QAAS;AAI/C,QAAM,EAAE,iBAAiB,SAAS,QAAI;AAAA,IACrC,CAAE,WAAY;AACb,UAAK,CAAE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;AACnE,WAAO,CAAC;AAAA,EACT;AACA,SAAO;AAAA,IACN,WAAW;AAAA,EACZ;AACD;AAAA,IAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;AAEA,MAAM,oBAAoB,CAAE,oBAAqB;AAChD,aAAO,+BAAiB,iBAAiB,oBAAqB;AAC/D;AAEA,IAAO,mBAAQ;AAAA,EACd;AAAA,EACA;AAAA,EACA,eAAe,CAAE,WAAW,YAAY,OAAQ;AAAA,EAChD,YAAY;AAAA,EACZ,MAAM;AACP;",
|
|
6
6
|
"names": ["hasFitTextSupport", "blockEditorStore", "InspectorControls", "ToolsPanelItem"]
|
|
7
7
|
}
|
|
@@ -1,41 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var import_interactivity = require("@wordpress/interactivity");
|
|
2
3
|
var import_fit_text_utils = require("./fit-text-utils");
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
(0, import_interactivity.store)("core/fit-text", {
|
|
5
|
+
callbacks: {
|
|
6
|
+
init() {
|
|
7
|
+
const context = (0, import_interactivity.getContext)();
|
|
8
|
+
const { ref } = (0, import_interactivity.getElement)();
|
|
9
|
+
const applyFontSize = (fontSize) => {
|
|
10
|
+
if (fontSize === 0) {
|
|
11
|
+
ref.style.fontSize = "";
|
|
12
|
+
} else {
|
|
13
|
+
ref.style.fontSize = `${fontSize}px`;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
context.fontSize = (0, import_fit_text_utils.optimizeFitText)(ref, applyFontSize);
|
|
17
|
+
if (window.ResizeObserver && ref.parentElement) {
|
|
18
|
+
const resizeObserver = new window.ResizeObserver(() => {
|
|
19
|
+
context.fontSize = (0, import_fit_text_utils.optimizeFitText)(ref, applyFontSize);
|
|
20
|
+
});
|
|
21
|
+
resizeObserver.observe(ref.parentElement);
|
|
22
|
+
resizeObserver.observe(ref);
|
|
23
|
+
return () => {
|
|
24
|
+
if (resizeObserver) {
|
|
25
|
+
resizeObserver.disconnect();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
11
30
|
}
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
function getElementIdentifier(element) {
|
|
15
|
-
if (!element.dataset.fitTextId) {
|
|
16
|
-
element.dataset.fitTextId = `fit-text-${++idCounter}`;
|
|
17
|
-
}
|
|
18
|
-
return element.dataset.fitTextId;
|
|
19
|
-
}
|
|
20
|
-
function initializeFitText(element) {
|
|
21
|
-
const elementId = getElementIdentifier(element);
|
|
22
|
-
const applyFitText = () => {
|
|
23
|
-
const styleElement = getOrCreateStyleElement(elementId);
|
|
24
|
-
const elementSelector = `[data-fit-text-id="${elementId}"]`;
|
|
25
|
-
const applyStylesFn = (css) => {
|
|
26
|
-
styleElement.textContent = css;
|
|
27
|
-
};
|
|
28
|
-
(0, import_fit_text_utils.optimizeFitText)(element, elementSelector, applyStylesFn);
|
|
29
|
-
};
|
|
30
|
-
applyFitText();
|
|
31
|
-
if (window.ResizeObserver && element.parentElement) {
|
|
32
|
-
const resizeObserver = new window.ResizeObserver(applyFitText);
|
|
33
|
-
resizeObserver.observe(element.parentElement);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function initializeAllFitText() {
|
|
37
|
-
const elements = document.querySelectorAll(".has-fit-text");
|
|
38
|
-
elements.forEach(initializeFitText);
|
|
39
|
-
}
|
|
40
|
-
window.addEventListener("load", initializeAllFitText);
|
|
31
|
+
});
|
|
41
32
|
//# sourceMappingURL=fit-text-frontend.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/fit-text-frontend.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * Frontend fit text functionality.\n * Automatically detects and initializes fit text on blocks with the has-fit-text class.\n */\n\n/**\n *
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["/**\n * Frontend fit text functionality.\n * Automatically detects and initializes fit text on blocks with the has-fit-text class.\n * Supports both initial page load and Interactivity API client-side navigation.\n */\n\n/**\n * WordPress dependencies\n */\nimport { store, getElement, getContext } from '@wordpress/interactivity';\n\n/**\n * Internal dependencies\n */\nimport { optimizeFitText } from './fit-text-utils';\n\n// Initialize via Interactivity API for client-side navigation\nstore( 'core/fit-text', {\n\tcallbacks: {\n\t\tinit() {\n\t\t\tconst context = getContext();\n\t\t\tconst { ref } = getElement();\n\n\t\t\tconst applyFontSize = ( fontSize ) => {\n\t\t\t\tif ( fontSize === 0 ) {\n\t\t\t\t\tref.style.fontSize = '';\n\t\t\t\t} else {\n\t\t\t\t\tref.style.fontSize = `${ fontSize }px`;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// Initial fit text optimization.\n\t\t\tcontext.fontSize = optimizeFitText( ref, applyFontSize );\n\n\t\t\t// Starts ResizeObserver to handle dynamic resizing.\n\t\t\tif ( window.ResizeObserver && ref.parentElement ) {\n\t\t\t\tconst resizeObserver = new window.ResizeObserver( () => {\n\t\t\t\t\tcontext.fontSize = optimizeFitText( ref, applyFontSize );\n\t\t\t\t} );\n\t\t\t\tresizeObserver.observe( ref.parentElement );\n\t\t\t\tresizeObserver.observe( ref );\n\n\t\t\t\t// Return cleanup function to be called when element is removed.\n\t\t\t\treturn () => {\n\t\t\t\t\tif ( resizeObserver ) {\n\t\t\t\t\t\tresizeObserver.disconnect();\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t},\n} );\n"],
|
|
5
|
+
"mappings": ";AASA,2BAA8C;AAK9C,4BAAgC;AAAA,IAGhC,4BAAO,iBAAiB;AAAA,EACvB,WAAW;AAAA,IACV,OAAO;AACN,YAAM,cAAU,iCAAW;AAC3B,YAAM,EAAE,IAAI,QAAI,iCAAW;AAE3B,YAAM,gBAAgB,CAAE,aAAc;AACrC,YAAK,aAAa,GAAI;AACrB,cAAI,MAAM,WAAW;AAAA,QACtB,OAAO;AACN,cAAI,MAAM,WAAW,GAAI,QAAS;AAAA,QACnC;AAAA,MACD;AAGA,cAAQ,eAAW,uCAAiB,KAAK,aAAc;AAGvD,UAAK,OAAO,kBAAkB,IAAI,eAAgB;AACjD,cAAM,iBAAiB,IAAI,OAAO,eAAgB,MAAM;AACvD,kBAAQ,eAAW,uCAAiB,KAAK,aAAc;AAAA,QACxD,CAAE;AACF,uBAAe,QAAS,IAAI,aAAc;AAC1C,uBAAe,QAAS,GAAI;AAG5B,eAAO,MAAM;AACZ,cAAK,gBAAiB;AACrB,2BAAe,WAAW;AAAA,UAC3B;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD,CAAE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -21,17 +21,14 @@ __export(fit_text_utils_exports, {
|
|
|
21
21
|
optimizeFitText: () => optimizeFitText
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(fit_text_utils_exports);
|
|
24
|
-
function
|
|
25
|
-
return `${elementSelector} { font-size: ${fontSize}px !important; }`;
|
|
26
|
-
}
|
|
27
|
-
function findOptimalFontSize(textElement, elementSelector, applyStylesFn) {
|
|
24
|
+
function findOptimalFontSize(textElement, applyFontSize) {
|
|
28
25
|
const alreadyHasScrollableHeight = textElement.scrollHeight > textElement.clientHeight;
|
|
29
26
|
let minSize = 5;
|
|
30
27
|
let maxSize = 600;
|
|
31
28
|
let bestSize = minSize;
|
|
32
29
|
while (minSize <= maxSize) {
|
|
33
30
|
const midSize = Math.floor((minSize + maxSize) / 2);
|
|
34
|
-
|
|
31
|
+
applyFontSize(midSize);
|
|
35
32
|
const fitsWidth = textElement.scrollWidth <= textElement.clientWidth;
|
|
36
33
|
const fitsHeight = alreadyHasScrollableHeight || textElement.scrollHeight <= textElement.clientHeight;
|
|
37
34
|
if (fitsWidth && fitsHeight) {
|
|
@@ -43,18 +40,14 @@ function findOptimalFontSize(textElement, elementSelector, applyStylesFn) {
|
|
|
43
40
|
}
|
|
44
41
|
return bestSize;
|
|
45
42
|
}
|
|
46
|
-
function optimizeFitText(textElement,
|
|
43
|
+
function optimizeFitText(textElement, applyFontSize) {
|
|
47
44
|
if (!textElement) {
|
|
48
45
|
return;
|
|
49
46
|
}
|
|
50
|
-
|
|
51
|
-
const optimalSize = findOptimalFontSize(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
applyStylesFn
|
|
55
|
-
);
|
|
56
|
-
const cssRule = generateCSSRule(elementSelector, optimalSize);
|
|
57
|
-
applyStylesFn(cssRule);
|
|
47
|
+
applyFontSize(0);
|
|
48
|
+
const optimalSize = findOptimalFontSize(textElement, applyFontSize);
|
|
49
|
+
applyFontSize(optimalSize);
|
|
50
|
+
return optimalSize;
|
|
58
51
|
}
|
|
59
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
60
53
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/fit-text-utils.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * Shared utility functions for fit text functionality.\n * Uses callback-based approach for maximum code reuse between editor and frontend.\n */\n\n/**\n *
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * Shared utility functions for fit text functionality.\n * Uses callback-based approach for maximum code reuse between editor and frontend.\n */\n\n/**\n * Find optimal font size using simple binary search between 5-600px.\n *\n * @param {HTMLElement} textElement The text element\n * @param {Function} applyFontSize Function that receives font size in pixels\n * @return {number} Optimal font size\n */\nfunction findOptimalFontSize( textElement, applyFontSize ) {\n\tconst alreadyHasScrollableHeight =\n\t\ttextElement.scrollHeight > textElement.clientHeight;\n\tlet minSize = 5;\n\tlet maxSize = 600;\n\tlet bestSize = minSize;\n\n\twhile ( minSize <= maxSize ) {\n\t\tconst midSize = Math.floor( ( minSize + maxSize ) / 2 );\n\t\tapplyFontSize( midSize );\n\n\t\tconst fitsWidth = textElement.scrollWidth <= textElement.clientWidth;\n\t\tconst fitsHeight =\n\t\t\talreadyHasScrollableHeight ||\n\t\t\ttextElement.scrollHeight <= textElement.clientHeight;\n\n\t\tif ( fitsWidth && fitsHeight ) {\n\t\t\tbestSize = midSize;\n\t\t\tminSize = midSize + 1;\n\t\t} else {\n\t\t\tmaxSize = midSize - 1;\n\t\t}\n\t}\n\n\treturn bestSize;\n}\n\n/**\n * Complete fit text optimization for a single text element.\n * Handles the full flow using callbacks for font size application.\n *\n * @param {HTMLElement} textElement The text element (paragraph, heading, etc.)\n * @param {Function} applyFontSize Function that receives font size in pixels (0 to clear, >0 to apply)\n */\nexport function optimizeFitText( textElement, applyFontSize ) {\n\tif ( ! textElement ) {\n\t\treturn;\n\t}\n\n\tapplyFontSize( 0 );\n\n\tconst optimalSize = findOptimalFontSize( textElement, applyFontSize );\n\n\tapplyFontSize( optimalSize );\n\treturn optimalSize;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,SAAS,oBAAqB,aAAa,eAAgB;AAC1D,QAAM,6BACL,YAAY,eAAe,YAAY;AACxC,MAAI,UAAU;AACd,MAAI,UAAU;AACd,MAAI,WAAW;AAEf,SAAQ,WAAW,SAAU;AAC5B,UAAM,UAAU,KAAK,OAAS,UAAU,WAAY,CAAE;AACtD,kBAAe,OAAQ;AAEvB,UAAM,YAAY,YAAY,eAAe,YAAY;AACzD,UAAM,aACL,8BACA,YAAY,gBAAgB,YAAY;AAEzC,QAAK,aAAa,YAAa;AAC9B,iBAAW;AACX,gBAAU,UAAU;AAAA,IACrB,OAAO;AACN,gBAAU,UAAU;AAAA,IACrB;AAAA,EACD;AAEA,SAAO;AACR;AASO,SAAS,gBAAiB,aAAa,eAAgB;AAC7D,MAAK,CAAE,aAAc;AACpB;AAAA,EACD;AAEA,gBAAe,CAAE;AAEjB,QAAM,cAAc,oBAAqB,aAAa,aAAc;AAEpE,gBAAe,WAAY;AAC3B,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/block-settings-menu/block-settings-dropdown.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tgetBlockType,\n\tserialize,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\nimport { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { moreVertical } from '@wordpress/icons';\nimport { Children, cloneElement } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\nimport { pipe, useCopyToClipboard } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport BlockActions from '../block-actions';\nimport CommentIconSlotFill from '../../components/collab/block-comment-icon-slot';\nimport BlockHTMLConvertButton from './block-html-convert-button';\nimport __unstableBlockSettingsMenuFirstItem from './block-settings-menu-first-item';\nimport BlockSettingsMenuControls from '../block-settings-menu-controls';\nimport BlockParentSelectorMenuItem from './block-parent-selector-menu-item';\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\nimport { useNotifyCopy } from '../../utils/use-notify-copy';\n\nconst POPOVER_PROPS = {\n\tclassName: 'block-editor-block-settings-menu__popover',\n\tplacement: 'bottom-start',\n};\n\nfunction CopyMenuItem( {\n\tclientIds,\n\tonCopy,\n\tlabel,\n\tshortcut,\n\teventType = 'copy',\n\t__experimentalUpdateSelection: updateSelection = false,\n} ) {\n\tconst { getBlocksByClientId } = useSelect( blockEditorStore );\n\tconst { removeBlocks } = useDispatch( blockEditorStore );\n\tconst notifyCopy = useNotifyCopy();\n\tconst ref = useCopyToClipboard(\n\t\t() => serialize( getBlocksByClientId( clientIds ) ),\n\t\t() => {\n\t\t\tswitch ( eventType ) {\n\t\t\t\tcase 'copy':\n\t\t\t\tcase 'copyStyles':\n\t\t\t\t\tonCopy();\n\t\t\t\t\tnotifyCopy( eventType, clientIds );\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'cut':\n\t\t\t\t\tnotifyCopy( eventType, clientIds );\n\t\t\t\t\tremoveBlocks( clientIds, updateSelection );\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t);\n\tconst copyMenuItemLabel = label ? label : __( 'Copy' );\n\treturn (\n\t\t<MenuItem ref={ ref } shortcut={ shortcut }>\n\t\t\t{ copyMenuItemLabel }\n\t\t</MenuItem>\n\t);\n}\n\nexport function BlockSettingsDropdown( {\n\tblock,\n\tclientIds,\n\tchildren,\n\t__experimentalSelectBlock,\n\t...props\n} ) {\n\t// Get the client id of the current block for this menu, if one is set.\n\tconst currentClientId = block?.clientId;\n\tconst count = clientIds.length;\n\tconst firstBlockClientId = clientIds[ 0 ];\n\n\tconst {\n\t\tfirstParentClientId,\n\t\tparentBlockType,\n\t\tpreviousBlockClientId,\n\t\tselectedBlockClientIds,\n\t\topenedBlockSettingsMenu,\n\t\tisContentOnly,\n\t\tisZoomOut,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockName,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\tgetPreviousBlockClientId,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\tgetBlockAttributes,\n\t\t\t\tgetOpenedBlockSettingsMenu,\n\t\t\t\tgetBlockEditingMode,\n\t\t\t\tisZoomOut: _isZoomOut,\n\t\t\t} = unlock( select( blockEditorStore ) );\n\n\t\t\tconst { getActiveBlockVariation } = select( blocksStore );\n\n\t\t\tconst _firstParentClientId =\n\t\t\t\tgetBlockRootClientId( firstBlockClientId );\n\t\t\tconst parentBlockName =\n\t\t\t\t_firstParentClientId && getBlockName( _firstParentClientId );\n\n\t\t\treturn {\n\t\t\t\tfirstParentClientId: _firstParentClientId,\n\t\t\t\tparentBlockType:\n\t\t\t\t\t_firstParentClientId &&\n\t\t\t\t\t( getActiveBlockVariation(\n\t\t\t\t\t\tparentBlockName,\n\t\t\t\t\t\tgetBlockAttributes( _firstParentClientId )\n\t\t\t\t\t) ||\n\t\t\t\t\t\tgetBlockType( parentBlockName ) ),\n\t\t\t\tpreviousBlockClientId:\n\t\t\t\t\tgetPreviousBlockClientId( firstBlockClientId ),\n\t\t\t\tselectedBlockClientIds: getSelectedBlockClientIds(),\n\t\t\t\topenedBlockSettingsMenu: getOpenedBlockSettingsMenu(),\n\t\t\t\tisContentOnly:\n\t\t\t\t\tgetBlockEditingMode( firstBlockClientId ) === 'contentOnly',\n\t\t\t\tisZoomOut: _isZoomOut(),\n\t\t\t};\n\t\t},\n\t\t[ firstBlockClientId ]\n\t);\n\n\tconst { getBlockOrder, getSelectedBlockClientIds } =\n\t\tuseSelect( blockEditorStore );\n\n\tconst { setOpenedBlockSettingsMenu } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\n\tconst shortcuts = useSelect( ( select ) => {\n\t\tconst { getShortcutRepresentation } = select( keyboardShortcutsStore );\n\t\treturn {\n\t\t\tcopy: getShortcutRepresentation( 'core/block-editor/copy' ),\n\t\t\tcut: getShortcutRepresentation( 'core/block-editor/cut' ),\n\t\t\tduplicate: getShortcutRepresentation(\n\t\t\t\t'core/block-editor/duplicate'\n\t\t\t),\n\t\t\tremove: getShortcutRepresentation( 'core/block-editor/remove' ),\n\t\t\tinsertAfter: getShortcutRepresentation(\n\t\t\t\t'core/block-editor/insert-after'\n\t\t\t),\n\t\t\tinsertBefore: getShortcutRepresentation(\n\t\t\t\t'core/block-editor/insert-before'\n\t\t\t),\n\t\t};\n\t}, [] );\n\tconst hasSelectedBlocks = selectedBlockClientIds.length > 0;\n\n\tasync function updateSelectionAfterDuplicate( clientIdsPromise ) {\n\t\tif ( ! __experimentalSelectBlock ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst ids = await clientIdsPromise;\n\t\tif ( ids && ids[ 0 ] ) {\n\t\t\t__experimentalSelectBlock( ids[ 0 ], false );\n\t\t}\n\t}\n\n\tfunction updateSelectionAfterRemove() {\n\t\tif ( ! __experimentalSelectBlock ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet blockToFocus = previousBlockClientId || firstParentClientId;\n\n\t\t// Focus the first block if there's no previous block nor parent block.\n\t\tif ( ! blockToFocus ) {\n\t\t\tblockToFocus = getBlockOrder()[ 0 ];\n\t\t}\n\n\t\t// Only update the selection if the original selection is removed.\n\t\tconst shouldUpdateSelection =\n\t\t\thasSelectedBlocks && getSelectedBlockClientIds().length === 0;\n\n\t\t__experimentalSelectBlock( blockToFocus, shouldUpdateSelection );\n\t}\n\n\t// This can occur when the selected block (the parent)\n\t// displays child blocks within a List View.\n\tconst parentBlockIsSelected =\n\t\tselectedBlockClientIds?.includes( firstParentClientId );\n\n\t// When a currentClientId is in use, treat the menu as a controlled component.\n\t// This ensures that only one block settings menu is open at a time.\n\t// This is a temporary solution to work around an issue with `onFocusOutside`\n\t// where it does not allow a dropdown to be closed if focus was never within\n\t// the dropdown to begin with. Examples include a user either CMD+Clicking or\n\t// right clicking into an inactive window.\n\t// See: https://github.com/WordPress/gutenberg/pull/54083\n\tconst open = ! currentClientId\n\t\t? undefined\n\t\t: openedBlockSettingsMenu === currentClientId || false;\n\n\tfunction onToggle( localOpen ) {\n\t\tif ( localOpen && openedBlockSettingsMenu !== currentClientId ) {\n\t\t\tsetOpenedBlockSettingsMenu( currentClientId );\n\t\t} else if (\n\t\t\t! localOpen &&\n\t\t\topenedBlockSettingsMenu &&\n\t\t\topenedBlockSettingsMenu === currentClientId\n\t\t) {\n\t\t\tsetOpenedBlockSettingsMenu( undefined );\n\t\t}\n\t}\n\n\tconst shouldShowBlockParentMenuItem =\n\t\t! parentBlockIsSelected && !! firstParentClientId;\n\n\treturn (\n\t\t<BlockActions\n\t\t\tclientIds={ clientIds }\n\t\t\t__experimentalUpdateSelection={ ! __experimentalSelectBlock }\n\t\t>\n\t\t\t{ ( {\n\t\t\t\tcanCopyStyles,\n\t\t\t\tcanDuplicate,\n\t\t\t\tcanInsertBlock,\n\t\t\t\tcanRemove,\n\t\t\t\tonDuplicate,\n\t\t\t\tonInsertAfter,\n\t\t\t\tonInsertBefore,\n\t\t\t\tonRemove,\n\t\t\t\tonCopy,\n\t\t\t\tonPasteStyles,\n\t\t\t} ) => {\n\t\t\t\t// It is possible that some plugins register fills for this menu\n\t\t\t\t// even if Core doesn't render anything in the block settings menu.\n\t\t\t\t// in which case, we may want to render the menu anyway.\n\t\t\t\t// That said for now, we can start more conservative.\n\t\t\t\tconst isEmpty =\n\t\t\t\t\t! canRemove &&\n\t\t\t\t\t! canDuplicate &&\n\t\t\t\t\t! canInsertBlock &&\n\t\t\t\t\tisContentOnly;\n\n\t\t\t\tif ( isEmpty ) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn (\n\t\t\t\t\t<DropdownMenu\n\t\t\t\t\t\ticon={ moreVertical }\n\t\t\t\t\t\tlabel={ __( 'Options' ) }\n\t\t\t\t\t\tclassName=\"block-editor-block-settings-menu\"\n\t\t\t\t\t\tpopoverProps={ POPOVER_PROPS }\n\t\t\t\t\t\topen={ open }\n\t\t\t\t\t\tonToggle={ onToggle }\n\t\t\t\t\t\tnoIcons\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ ( { onClose } ) => (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t\t<__unstableBlockSettingsMenuFirstItem.Slot\n\t\t\t\t\t\t\t\t\t\tfillProps={ { onClose } }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t{ shouldShowBlockParentMenuItem && (\n\t\t\t\t\t\t\t\t\t\t<BlockParentSelectorMenuItem\n\t\t\t\t\t\t\t\t\t\t\tparentClientId={\n\t\t\t\t\t\t\t\t\t\t\t\tfirstParentClientId\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tparentBlockType={ parentBlockType }\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\t{ count === 1 && (\n\t\t\t\t\t\t\t\t\t\t<BlockHTMLConvertButton\n\t\t\t\t\t\t\t\t\t\t\tclientId={ firstBlockClientId }\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\t{ ! isContentOnly && (\n\t\t\t\t\t\t\t\t\t\t<CopyMenuItem\n\t\t\t\t\t\t\t\t\t\t\tclientIds={ clientIds }\n\t\t\t\t\t\t\t\t\t\t\tonCopy={ onCopy }\n\t\t\t\t\t\t\t\t\t\t\tshortcut={ shortcuts.copy }\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\t{ ! isContentOnly && (\n\t\t\t\t\t\t\t\t\t\t<CopyMenuItem\n\t\t\t\t\t\t\t\t\t\t\tclientIds={ clientIds }\n\t\t\t\t\t\t\t\t\t\t\tlabel={ __( 'Cut' ) }\n\t\t\t\t\t\t\t\t\t\t\teventType=\"cut\"\n\t\t\t\t\t\t\t\t\t\t\tshortcut={ shortcuts.cut }\n\t\t\t\t\t\t\t\t\t\t\t__experimentalUpdateSelection={\n\t\t\t\t\t\t\t\t\t\t\t\t! __experimentalSelectBlock\n\t\t\t\t\t\t\t\t\t\t\t}\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\t{ canDuplicate && (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\tonClick={ pipe(\n\t\t\t\t\t\t\t\t\t\t\t\tonClose,\n\t\t\t\t\t\t\t\t\t\t\t\tonDuplicate,\n\t\t\t\t\t\t\t\t\t\t\t\tupdateSelectionAfterDuplicate\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\tshortcut={ shortcuts.duplicate }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Duplicate' ) }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t{ canInsertBlock && ! isZoomOut && (\n\t\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={ pipe(\n\t\t\t\t\t\t\t\t\t\t\t\t\tonClose,\n\t\t\t\t\t\t\t\t\t\t\t\t\tonInsertBefore\n\t\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\t\tshortcut={\n\t\t\t\t\t\t\t\t\t\t\t\t\tshortcuts.insertBefore\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t{ __( 'Add before' ) }\n\t\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={ pipe(\n\t\t\t\t\t\t\t\t\t\t\t\t\tonClose,\n\t\t\t\t\t\t\t\t\t\t\t\t\tonInsertAfter\n\t\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\t\tshortcut={\n\t\t\t\t\t\t\t\t\t\t\t\t\tshortcuts.insertAfter\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t{ __( 'Add after' ) }\n\t\t\t\t\t\t\t\t\t\t\t</MenuItem>\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\t{ count === 1 && (\n\t\t\t\t\t\t\t\t\t\t<CommentIconSlotFill.Slot\n\t\t\t\t\t\t\t\t\t\t\tfillProps={ { onClose } }\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</MenuGroup>\n\t\t\t\t\t\t\t\t{ canCopyStyles && ! isContentOnly && (\n\t\t\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t\t\t<CopyMenuItem\n\t\t\t\t\t\t\t\t\t\t\tclientIds={ clientIds }\n\t\t\t\t\t\t\t\t\t\t\tonCopy={ onCopy }\n\t\t\t\t\t\t\t\t\t\t\tlabel={ __( 'Copy styles' ) }\n\t\t\t\t\t\t\t\t\t\t\teventType=\"copyStyles\"\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<MenuItem onClick={ onPasteStyles }>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Paste styles' ) }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t{ ! isContentOnly && (\n\t\t\t\t\t\t\t\t\t<BlockSettingsMenuControls.Slot\n\t\t\t\t\t\t\t\t\t\tfillProps={ {\n\t\t\t\t\t\t\t\t\t\t\tonClose,\n\t\t\t\t\t\t\t\t\t\t\tcount,\n\t\t\t\t\t\t\t\t\t\t\tfirstBlockClientId,\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\tclientIds={ clientIds }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t{ typeof children === 'function'\n\t\t\t\t\t\t\t\t\t? children( { onClose } )\n\t\t\t\t\t\t\t\t\t: Children.map( ( child ) =>\n\t\t\t\t\t\t\t\t\t\t\tcloneElement( child, { onClose } )\n\t\t\t\t\t\t\t\t\t ) }\n\t\t\t\t\t\t\t\t{ canRemove && (\n\t\t\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\tonClick={ pipe(\n\t\t\t\t\t\t\t\t\t\t\t\tonClose,\n\t\t\t\t\t\t\t\t\t\t\t\tonRemove,\n\t\t\t\t\t\t\t\t\t\t\t\tupdateSelectionAfterRemove\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\tshortcut={ shortcuts.remove }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Delete' ) }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t</MenuGroup>\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</DropdownMenu>\n\t\t\t\t);\n\t\t\t} }\n\t\t</BlockActions>\n\t);\n}\n\nexport default BlockSettingsDropdown;\n"],
|
|
5
|
-
"mappings": "AAiEE,SAsPQ,UAtPR,KAsPQ,YAtPR;AA9DF;AAAA,EACC;AAAA,EACA;AAAA,EACA,SAAS;AAAA,OACH;AACP,SAAS,cAAc,WAAW,gBAAgB;AAClD,SAAS,aAAa,iBAAiB;AACvC,SAAS,oBAAoB;AAC7B,SAAS,UAAU,oBAAoB;AACvC,SAAS,UAAU;AACnB,SAAS,SAAS,8BAA8B;AAChD,SAAS,MAAM,0BAA0B;AAKzC,OAAO,kBAAkB;AACzB,OAAO,yBAAyB;AAChC,OAAO,4BAA4B;AACnC,OAAO,0CAA0C;AACjD,OAAO,+BAA+B;AACtC,OAAO,iCAAiC;AACxC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,cAAc;AACvB,SAAS,qBAAqB;AAE9B,MAAM,gBAAgB;AAAA,EACrB,WAAW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AA;AAAA,oBACA;AAAA,oBACA;AAAA,oBACA,UAAW,UAAU;AAAA;AAAA,gBACtB;AAAA,gBAEC,CAAE,iBACH;AAAA,kBAAC;AAAA;AAAA,oBACA;AAAA,oBACA,OAAQ,GAAI,KAAM;AAAA,oBAClB,WAAU;AAAA,oBACV,UAAW,UAAU;AAAA,oBACrB,+BACC,CAAE;AAAA;AAAA,gBAEJ;AAAA,gBAEC,gBACD;AAAA,kBAAC;AAAA;AAAA,oBACA,SAAU;AAAA,sBACT;AAAA,sBACA;AAAA,sBACA;AAAA,oBACD;AAAA,oBACA,UAAW,UAAU;AAAA,oBAEnB,aAAI,WAAY;AAAA;AAAA,gBACnB;AAAA,gBAEC,kBAAkB,CAAE,aACrB,iCACC;AAAA;AAAA,oBAAC;AAAA;AAAA,sBACA,SAAU;AAAA,wBACT;AAAA,wBACA;AAAA,sBACD;AAAA,sBACA,UACC,UAAU;AAAA,sBAGT,aAAI,YAAa;AAAA;AAAA,kBACpB;AAAA,kBACA;AAAA,oBAAC;AAAA;AAAA,sBACA,SAAU;AAAA,wBACT;AAAA,wBACA;AAAA,sBACD;AAAA,sBACA,UACC,UAAU;AAAA,sBAGT,aAAI,WAAY;AAAA;AAAA,kBACnB;AAAA,mBACD;AAAA,gBAEC,UAAU,KACX;AAAA,kBAAC,oBAAoB;AAAA,kBAApB;AAAA,oBACA,WAAY,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tgetBlockType,\n\tserialize,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\nimport { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { moreVertical } from '@wordpress/icons';\nimport { Children, cloneElement } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\nimport { pipe, useCopyToClipboard } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport BlockActions from '../block-actions';\nimport CommentIconSlotFill from '../../components/collab/block-comment-icon-slot';\nimport BlockHTMLConvertButton from './block-html-convert-button';\nimport __unstableBlockSettingsMenuFirstItem from './block-settings-menu-first-item';\nimport BlockSettingsMenuControls from '../block-settings-menu-controls';\nimport BlockParentSelectorMenuItem from './block-parent-selector-menu-item';\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\nimport { useNotifyCopy } from '../../utils/use-notify-copy';\n\nconst POPOVER_PROPS = {\n\tclassName: 'block-editor-block-settings-menu__popover',\n\tplacement: 'bottom-start',\n};\n\nfunction CopyMenuItem( {\n\tclientIds,\n\tonCopy,\n\tlabel,\n\tshortcut,\n\teventType = 'copy',\n\t__experimentalUpdateSelection: updateSelection = false,\n} ) {\n\tconst { getBlocksByClientId } = useSelect( blockEditorStore );\n\tconst { removeBlocks } = useDispatch( blockEditorStore );\n\tconst notifyCopy = useNotifyCopy();\n\tconst ref = useCopyToClipboard(\n\t\t() => serialize( getBlocksByClientId( clientIds ) ),\n\t\t() => {\n\t\t\tswitch ( eventType ) {\n\t\t\t\tcase 'copy':\n\t\t\t\tcase 'copyStyles':\n\t\t\t\t\tonCopy();\n\t\t\t\t\tnotifyCopy( eventType, clientIds );\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'cut':\n\t\t\t\t\tnotifyCopy( eventType, clientIds );\n\t\t\t\t\tremoveBlocks( clientIds, updateSelection );\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t);\n\tconst copyMenuItemLabel = label ? label : __( 'Copy' );\n\treturn (\n\t\t<MenuItem ref={ ref } shortcut={ shortcut }>\n\t\t\t{ copyMenuItemLabel }\n\t\t</MenuItem>\n\t);\n}\n\nexport function BlockSettingsDropdown( {\n\tblock,\n\tclientIds,\n\tchildren,\n\t__experimentalSelectBlock,\n\t...props\n} ) {\n\t// Get the client id of the current block for this menu, if one is set.\n\tconst currentClientId = block?.clientId;\n\tconst count = clientIds.length;\n\tconst firstBlockClientId = clientIds[ 0 ];\n\n\tconst {\n\t\tfirstParentClientId,\n\t\tparentBlockType,\n\t\tpreviousBlockClientId,\n\t\tselectedBlockClientIds,\n\t\topenedBlockSettingsMenu,\n\t\tisContentOnly,\n\t\tisZoomOut,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockName,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\tgetPreviousBlockClientId,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\tgetBlockAttributes,\n\t\t\t\tgetOpenedBlockSettingsMenu,\n\t\t\t\tgetBlockEditingMode,\n\t\t\t\tisZoomOut: _isZoomOut,\n\t\t\t} = unlock( select( blockEditorStore ) );\n\n\t\t\tconst { getActiveBlockVariation } = select( blocksStore );\n\n\t\t\tconst _firstParentClientId =\n\t\t\t\tgetBlockRootClientId( firstBlockClientId );\n\t\t\tconst parentBlockName =\n\t\t\t\t_firstParentClientId && getBlockName( _firstParentClientId );\n\n\t\t\treturn {\n\t\t\t\tfirstParentClientId: _firstParentClientId,\n\t\t\t\tparentBlockType:\n\t\t\t\t\t_firstParentClientId &&\n\t\t\t\t\t( getActiveBlockVariation(\n\t\t\t\t\t\tparentBlockName,\n\t\t\t\t\t\tgetBlockAttributes( _firstParentClientId )\n\t\t\t\t\t) ||\n\t\t\t\t\t\tgetBlockType( parentBlockName ) ),\n\t\t\t\tpreviousBlockClientId:\n\t\t\t\t\tgetPreviousBlockClientId( firstBlockClientId ),\n\t\t\t\tselectedBlockClientIds: getSelectedBlockClientIds(),\n\t\t\t\topenedBlockSettingsMenu: getOpenedBlockSettingsMenu(),\n\t\t\t\tisContentOnly:\n\t\t\t\t\tgetBlockEditingMode( firstBlockClientId ) === 'contentOnly',\n\t\t\t\tisZoomOut: _isZoomOut(),\n\t\t\t};\n\t\t},\n\t\t[ firstBlockClientId ]\n\t);\n\n\tconst { getBlockOrder, getSelectedBlockClientIds } =\n\t\tuseSelect( blockEditorStore );\n\n\tconst { setOpenedBlockSettingsMenu } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\n\tconst shortcuts = useSelect( ( select ) => {\n\t\tconst { getShortcutRepresentation } = select( keyboardShortcutsStore );\n\t\treturn {\n\t\t\tcopy: getShortcutRepresentation( 'core/block-editor/copy' ),\n\t\t\tcut: getShortcutRepresentation( 'core/block-editor/cut' ),\n\t\t\tduplicate: getShortcutRepresentation(\n\t\t\t\t'core/block-editor/duplicate'\n\t\t\t),\n\t\t\tremove: getShortcutRepresentation( 'core/block-editor/remove' ),\n\t\t\tinsertAfter: getShortcutRepresentation(\n\t\t\t\t'core/block-editor/insert-after'\n\t\t\t),\n\t\t\tinsertBefore: getShortcutRepresentation(\n\t\t\t\t'core/block-editor/insert-before'\n\t\t\t),\n\t\t};\n\t}, [] );\n\tconst hasSelectedBlocks = selectedBlockClientIds.length > 0;\n\n\tasync function updateSelectionAfterDuplicate( clientIdsPromise ) {\n\t\tif ( ! __experimentalSelectBlock ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst ids = await clientIdsPromise;\n\t\tif ( ids && ids[ 0 ] ) {\n\t\t\t__experimentalSelectBlock( ids[ 0 ], false );\n\t\t}\n\t}\n\n\tfunction updateSelectionAfterRemove() {\n\t\tif ( ! __experimentalSelectBlock ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet blockToFocus = previousBlockClientId || firstParentClientId;\n\n\t\t// Focus the first block if there's no previous block nor parent block.\n\t\tif ( ! blockToFocus ) {\n\t\t\tblockToFocus = getBlockOrder()[ 0 ];\n\t\t}\n\n\t\t// Only update the selection if the original selection is removed.\n\t\tconst shouldUpdateSelection =\n\t\t\thasSelectedBlocks && getSelectedBlockClientIds().length === 0;\n\n\t\t__experimentalSelectBlock( blockToFocus, shouldUpdateSelection );\n\t}\n\n\t// This can occur when the selected block (the parent)\n\t// displays child blocks within a List View.\n\tconst parentBlockIsSelected =\n\t\tselectedBlockClientIds?.includes( firstParentClientId );\n\n\t// When a currentClientId is in use, treat the menu as a controlled component.\n\t// This ensures that only one block settings menu is open at a time.\n\t// This is a temporary solution to work around an issue with `onFocusOutside`\n\t// where it does not allow a dropdown to be closed if focus was never within\n\t// the dropdown to begin with. Examples include a user either CMD+Clicking or\n\t// right clicking into an inactive window.\n\t// See: https://github.com/WordPress/gutenberg/pull/54083\n\tconst open = ! currentClientId\n\t\t? undefined\n\t\t: openedBlockSettingsMenu === currentClientId || false;\n\n\tfunction onToggle( localOpen ) {\n\t\tif ( localOpen && openedBlockSettingsMenu !== currentClientId ) {\n\t\t\tsetOpenedBlockSettingsMenu( currentClientId );\n\t\t} else if (\n\t\t\t! localOpen &&\n\t\t\topenedBlockSettingsMenu &&\n\t\t\topenedBlockSettingsMenu === currentClientId\n\t\t) {\n\t\t\tsetOpenedBlockSettingsMenu( undefined );\n\t\t}\n\t}\n\n\tconst shouldShowBlockParentMenuItem =\n\t\t! parentBlockIsSelected && !! firstParentClientId;\n\n\treturn (\n\t\t<BlockActions\n\t\t\tclientIds={ clientIds }\n\t\t\t__experimentalUpdateSelection={ ! __experimentalSelectBlock }\n\t\t>\n\t\t\t{ ( {\n\t\t\t\tcanCopyStyles,\n\t\t\t\tcanDuplicate,\n\t\t\t\tcanInsertBlock,\n\t\t\t\tcanRemove,\n\t\t\t\tonDuplicate,\n\t\t\t\tonInsertAfter,\n\t\t\t\tonInsertBefore,\n\t\t\t\tonRemove,\n\t\t\t\tonCopy,\n\t\t\t\tonPasteStyles,\n\t\t\t} ) => {\n\t\t\t\t// It is possible that some plugins register fills for this menu\n\t\t\t\t// even if Core doesn't render anything in the block settings menu.\n\t\t\t\t// in which case, we may want to render the menu anyway.\n\t\t\t\t// That said for now, we can start more conservative.\n\t\t\t\tconst isEmpty =\n\t\t\t\t\t! canRemove &&\n\t\t\t\t\t! canDuplicate &&\n\t\t\t\t\t! canInsertBlock &&\n\t\t\t\t\tisContentOnly;\n\n\t\t\t\tif ( isEmpty ) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn (\n\t\t\t\t\t<DropdownMenu\n\t\t\t\t\t\ticon={ moreVertical }\n\t\t\t\t\t\tlabel={ __( 'Options' ) }\n\t\t\t\t\t\tclassName=\"block-editor-block-settings-menu\"\n\t\t\t\t\t\tpopoverProps={ POPOVER_PROPS }\n\t\t\t\t\t\topen={ open }\n\t\t\t\t\t\tonToggle={ onToggle }\n\t\t\t\t\t\tnoIcons\n\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ ( { onClose } ) => (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t\t<__unstableBlockSettingsMenuFirstItem.Slot\n\t\t\t\t\t\t\t\t\t\tfillProps={ { onClose } }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t{ shouldShowBlockParentMenuItem && (\n\t\t\t\t\t\t\t\t\t\t<BlockParentSelectorMenuItem\n\t\t\t\t\t\t\t\t\t\t\tparentClientId={\n\t\t\t\t\t\t\t\t\t\t\t\tfirstParentClientId\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tparentBlockType={ parentBlockType }\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\t{ count === 1 && (\n\t\t\t\t\t\t\t\t\t\t<BlockHTMLConvertButton\n\t\t\t\t\t\t\t\t\t\t\tclientId={ firstBlockClientId }\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\t{ ! isContentOnly && (\n\t\t\t\t\t\t\t\t\t\t<CopyMenuItem\n\t\t\t\t\t\t\t\t\t\t\tclientIds={ clientIds }\n\t\t\t\t\t\t\t\t\t\t\tonCopy={ onCopy }\n\t\t\t\t\t\t\t\t\t\t\tshortcut={ shortcuts.copy }\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\t{ ! isContentOnly && (\n\t\t\t\t\t\t\t\t\t\t<CopyMenuItem\n\t\t\t\t\t\t\t\t\t\t\tclientIds={ clientIds }\n\t\t\t\t\t\t\t\t\t\t\tlabel={ __( 'Cut' ) }\n\t\t\t\t\t\t\t\t\t\t\teventType=\"cut\"\n\t\t\t\t\t\t\t\t\t\t\tshortcut={ shortcuts.cut }\n\t\t\t\t\t\t\t\t\t\t\t__experimentalUpdateSelection={\n\t\t\t\t\t\t\t\t\t\t\t\t! __experimentalSelectBlock\n\t\t\t\t\t\t\t\t\t\t\t}\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\t{ canDuplicate && (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\tonClick={ pipe(\n\t\t\t\t\t\t\t\t\t\t\t\tonClose,\n\t\t\t\t\t\t\t\t\t\t\t\tonDuplicate,\n\t\t\t\t\t\t\t\t\t\t\t\tupdateSelectionAfterDuplicate\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\tshortcut={ shortcuts.duplicate }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Duplicate' ) }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t{ canInsertBlock && ! isZoomOut && (\n\t\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={ pipe(\n\t\t\t\t\t\t\t\t\t\t\t\t\tonClose,\n\t\t\t\t\t\t\t\t\t\t\t\t\tonInsertBefore\n\t\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\t\tshortcut={\n\t\t\t\t\t\t\t\t\t\t\t\t\tshortcuts.insertBefore\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t{ __( 'Add before' ) }\n\t\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={ pipe(\n\t\t\t\t\t\t\t\t\t\t\t\t\tonClose,\n\t\t\t\t\t\t\t\t\t\t\t\t\tonInsertAfter\n\t\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\t\tshortcut={\n\t\t\t\t\t\t\t\t\t\t\t\t\tshortcuts.insertAfter\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t{ __( 'Add after' ) }\n\t\t\t\t\t\t\t\t\t\t\t</MenuItem>\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\t{ count === 1 && (\n\t\t\t\t\t\t\t\t\t\t<CommentIconSlotFill.Slot\n\t\t\t\t\t\t\t\t\t\t\tfillProps={ {\n\t\t\t\t\t\t\t\t\t\t\t\tclientId: firstBlockClientId,\n\t\t\t\t\t\t\t\t\t\t\t\tonClose,\n\t\t\t\t\t\t\t\t\t\t\t} }\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</MenuGroup>\n\t\t\t\t\t\t\t\t{ canCopyStyles && ! isContentOnly && (\n\t\t\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t\t\t<CopyMenuItem\n\t\t\t\t\t\t\t\t\t\t\tclientIds={ clientIds }\n\t\t\t\t\t\t\t\t\t\t\tonCopy={ onCopy }\n\t\t\t\t\t\t\t\t\t\t\tlabel={ __( 'Copy styles' ) }\n\t\t\t\t\t\t\t\t\t\t\teventType=\"copyStyles\"\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<MenuItem onClick={ onPasteStyles }>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Paste styles' ) }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t{ ! isContentOnly && (\n\t\t\t\t\t\t\t\t\t<BlockSettingsMenuControls.Slot\n\t\t\t\t\t\t\t\t\t\tfillProps={ {\n\t\t\t\t\t\t\t\t\t\t\tonClose,\n\t\t\t\t\t\t\t\t\t\t\tcount,\n\t\t\t\t\t\t\t\t\t\t\tfirstBlockClientId,\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\tclientIds={ clientIds }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t{ typeof children === 'function'\n\t\t\t\t\t\t\t\t\t? children( { onClose } )\n\t\t\t\t\t\t\t\t\t: Children.map( ( child ) =>\n\t\t\t\t\t\t\t\t\t\t\tcloneElement( child, { onClose } )\n\t\t\t\t\t\t\t\t\t ) }\n\t\t\t\t\t\t\t\t{ canRemove && (\n\t\t\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\tonClick={ pipe(\n\t\t\t\t\t\t\t\t\t\t\t\tonClose,\n\t\t\t\t\t\t\t\t\t\t\t\tonRemove,\n\t\t\t\t\t\t\t\t\t\t\t\tupdateSelectionAfterRemove\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\tshortcut={ shortcuts.remove }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ __( 'Delete' ) }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>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electedBlockClientIds"]
|
|
7
7
|
}
|
|
@@ -13,9 +13,13 @@ function getAllValue(values = {}) {
|
|
|
13
13
|
if (typeof values === "string") {
|
|
14
14
|
return values;
|
|
15
15
|
}
|
|
16
|
-
const parsedQuantitiesAndUnits = Object.values(values).map(
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const parsedQuantitiesAndUnits = Object.values(values).map((value2) => {
|
|
17
|
+
const newValue = parseQuantityAndUnitFromRawValue(value2);
|
|
18
|
+
if (typeof value2 === "string" && newValue[0] === void 0) {
|
|
19
|
+
return [value2, ""];
|
|
20
|
+
}
|
|
21
|
+
return newValue;
|
|
22
|
+
});
|
|
19
23
|
const allValues = parsedQuantitiesAndUnits.map(
|
|
20
24
|
(value2) => value2[0] ?? ""
|
|
21
25
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/border-radius-control/utils.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue } from '@wordpress/components';\n\n/**\n * Gets the (non-undefined) item with the highest occurrence within an array\n * Based in part on: https://stackoverflow.com/a/20762713\n *\n * Undefined values are always sorted to the end by `sort`, so this function\n * returns the first element, to always prioritize real values over undefined\n * values.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description\n *\n * @param {Array<any>} inputArray Array of items to check.\n * @return {any} The item with the most occurrences.\n */\nexport function mode( inputArray ) {\n\tconst arr = [ ...inputArray ];\n\treturn arr\n\t\t.sort(\n\t\t\t( a, b ) =>\n\t\t\t\tinputArray.filter( ( v ) => v === b ).length -\n\t\t\t\tinputArray.filter( ( v ) => v === a ).length\n\t\t)\n\t\t.shift();\n}\n\n/**\n * Returns the most common CSS unit from the current CSS unit selections.\n *\n * - If a single flat border radius is set, its unit will be used\n * - If individual corner selections, the most common of those will be used\n * - Failing any unit selections a default of 'px' is returned.\n *\n * @param {Object} selectedUnits Unit selections for flat radius & each corner.\n * @return {string} Most common CSS unit from current selections. Default: `px`.\n */\nexport function getAllUnit( selectedUnits = {} ) {\n\tconst { flat, ...cornerUnits } = selectedUnits;\n\treturn (\n\t\tflat || mode( Object.values( cornerUnits ).filter( Boolean ) ) || 'px'\n\t);\n}\n\n/**\n * Gets the 'all' input value and unit from values data.\n *\n * @param {Object|string} values Radius values.\n * @return {string} A value + unit for the 'all' input.\n */\nexport function getAllValue( values = {} ) {\n\t/**\n\t * Border radius support was originally a single pixel value.\n\t *\n\t * To maintain backwards compatibility treat this case as the all value.\n\t */\n\tif ( typeof values === 'string' ) {\n\t\treturn values;\n\t}\n\n\tconst parsedQuantitiesAndUnits = Object.values( values ).map( ( value )
|
|
5
|
-
"mappings": "AAGA,SAAS,kDAAkD,wCAAwC;AAe5F,SAAS,KAAM,YAAa;AAClC,QAAM,MAAM,CAAE,GAAG,UAAW;AAC5B,SAAO,IACL;AAAA,IACA,CAAE,GAAG,MACJ,WAAW,OAAQ,CAAE,MAAO,MAAM,CAAE,EAAE,SACtC,WAAW,OAAQ,CAAE,MAAO,MAAM,CAAE,EAAE;AAAA,EACxC,EACC,MAAM;AACT;AAYO,SAAS,WAAY,gBAAgB,CAAC,GAAI;AAChD,QAAM,EAAE,MAAM,GAAG,YAAY,IAAI;AACjC,SACC,QAAQ,KAAM,OAAO,OAAQ,WAAY,EAAE,OAAQ,OAAQ,CAAE,KAAK;AAEpE;AAQO,SAAS,YAAa,SAAS,CAAC,GAAI;AAM1C,MAAK,OAAO,WAAW,UAAW;AACjC,WAAO;AAAA,EACR;AAEA,QAAM,2BAA2B,OAAO,OAAQ,MAAO,EAAE
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue } from '@wordpress/components';\n\n/**\n * Gets the (non-undefined) item with the highest occurrence within an array\n * Based in part on: https://stackoverflow.com/a/20762713\n *\n * Undefined values are always sorted to the end by `sort`, so this function\n * returns the first element, to always prioritize real values over undefined\n * values.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description\n *\n * @param {Array<any>} inputArray Array of items to check.\n * @return {any} The item with the most occurrences.\n */\nexport function mode( inputArray ) {\n\tconst arr = [ ...inputArray ];\n\treturn arr\n\t\t.sort(\n\t\t\t( a, b ) =>\n\t\t\t\tinputArray.filter( ( v ) => v === b ).length -\n\t\t\t\tinputArray.filter( ( v ) => v === a ).length\n\t\t)\n\t\t.shift();\n}\n\n/**\n * Returns the most common CSS unit from the current CSS unit selections.\n *\n * - If a single flat border radius is set, its unit will be used\n * - If individual corner selections, the most common of those will be used\n * - Failing any unit selections a default of 'px' is returned.\n *\n * @param {Object} selectedUnits Unit selections for flat radius & each corner.\n * @return {string} Most common CSS unit from current selections. Default: `px`.\n */\nexport function getAllUnit( selectedUnits = {} ) {\n\tconst { flat, ...cornerUnits } = selectedUnits;\n\treturn (\n\t\tflat || mode( Object.values( cornerUnits ).filter( Boolean ) ) || 'px'\n\t);\n}\n\n/**\n * Gets the 'all' input value and unit from values data.\n *\n * @param {Object|string} values Radius values.\n * @return {string} A value + unit for the 'all' input.\n */\nexport function getAllValue( values = {} ) {\n\t/**\n\t * Border radius support was originally a single pixel value.\n\t *\n\t * To maintain backwards compatibility treat this case as the all value.\n\t */\n\tif ( typeof values === 'string' ) {\n\t\treturn values;\n\t}\n\n\tconst parsedQuantitiesAndUnits = Object.values( values ).map( ( value ) => {\n\t\tconst newValue = parseQuantityAndUnitFromRawValue( value );\n\t\tif ( typeof value === 'string' && newValue[ 0 ] === undefined ) {\n\t\t\treturn [ value, '' ];\n\t\t}\n\t\treturn newValue;\n\t} );\n\n\tconst allValues = parsedQuantitiesAndUnits.map(\n\t\t( value ) => value[ 0 ] ?? ''\n\t);\n\tconst allUnits = parsedQuantitiesAndUnits.map( ( value ) => value[ 1 ] );\n\n\tconst value = allValues.every( ( v ) => v === allValues[ 0 ] )\n\t\t? allValues[ 0 ]\n\t\t: '';\n\tconst unit = mode( allUnits );\n\n\tconst allValue =\n\t\tvalue === 0 || value ? `${ value }${ unit || '' }` : undefined;\n\n\treturn allValue;\n}\n\n/**\n * Checks to determine if values are mixed.\n *\n * @param {Object} values Radius values.\n * @return {boolean} Whether values are mixed.\n */\nexport function hasMixedValues( values = {} ) {\n\tif ( typeof values === 'string' ) {\n\t\treturn false;\n\t}\n\n\tif ( ! values || typeof values !== 'object' ) {\n\t\treturn false;\n\t}\n\n\tconst cornerValues = Object.values( values );\n\n\tif ( cornerValues.length === 0 ) {\n\t\treturn false;\n\t}\n\n\tconst firstValue = cornerValues[ 0 ];\n\n\t// Check if all values are exactly the same (including undefined)\n\tconst allSame = cornerValues.every( ( value ) => value === firstValue );\n\n\treturn ! allSame;\n}\n\n/**\n * Checks to determine if values are defined.\n *\n * @param {Object} values Radius values.\n * @return {boolean} Whether values are mixed.\n */\nexport function hasDefinedValues( values ) {\n\tif ( ! values ) {\n\t\treturn false;\n\t}\n\n\t// A string value represents a shorthand value.\n\tif ( typeof values === 'string' ) {\n\t\treturn true;\n\t}\n\n\t// An object represents longhand border radius values, if any are set\n\t// flag values as being defined.\n\tconst filteredValues = Object.values( values ).filter( ( value ) => {\n\t\treturn !! value || value === 0;\n\t} );\n\n\treturn !! filteredValues.length;\n}\n\n/**\n * Checks is given value is a radius preset.\n *\n * @param {string} value Value to check\n *\n * @return {boolean} Return true if value is string in format var:preset|border-radius|.\n */\nexport function isValuePreset( value ) {\n\tif ( ! value?.includes ) {\n\t\treturn false;\n\t}\n\treturn value === '0' || value.includes( 'var:preset|border-radius|' );\n}\n\n/**\n * Returns the slug section of the given preset string.\n *\n * @param {string} value Value to extract slug from.\n *\n * @return {string|undefined} The int value of the slug from given preset.\n */\nexport function getPresetSlug( value ) {\n\tif ( ! value ) {\n\t\treturn;\n\t}\n\n\tif ( value === '0' || value === 'default' ) {\n\t\treturn value;\n\t}\n\n\tconst slug = value.match( /var:preset\\|border-radius\\|(.+)/ );\n\n\treturn slug ? slug[ 1 ] : undefined;\n}\n\n/**\n * Converts radius preset value into a Range component value .\n *\n * @param {string} presetValue Value to convert to Range value.\n * @param {Array} presets Array of current radius preset value objects.\n *\n * @return {number} The int value for use in Range control.\n */\nexport function getSliderValueFromPreset( presetValue, presets ) {\n\tif ( presetValue === undefined ) {\n\t\treturn 0;\n\t}\n\tconst slug =\n\t\tparseFloat( presetValue, 10 ) === 0\n\t\t\t? '0'\n\t\t\t: getPresetSlug( presetValue );\n\tconst sliderValue = presets.findIndex( ( size ) => {\n\t\treturn String( size.slug ) === slug;\n\t} );\n\n\t// Returning NaN rather than undefined as undefined makes range control thumb sit in center\n\treturn sliderValue !== -1 ? sliderValue : NaN;\n}\n\n/**\n * Converts a preset into a custom value.\n *\n * @param {string} value Value to convert\n * @param {Array} presets Array of the current radius preset objects\n *\n * @return {string} Mapping of the radius preset to its equivalent custom value.\n */\nexport function getCustomValueFromPreset( value, presets ) {\n\tif ( ! isValuePreset( value ) ) {\n\t\treturn value;\n\t}\n\n\tconst slug = parseFloat( value, 10 ) === 0 ? '0' : getPresetSlug( value );\n\tconst radiusSize = presets.find( ( size ) => String( size.slug ) === slug );\n\n\treturn radiusSize?.size;\n}\n\n/**\n * Converts a control value into a preset value.\n *\n * @param {number} controlValue to convert to preset value.\n * @param {string} controlType Type of control\n * @param {Array} presets Array of current radius preset value objects.\n *\n * @return {string} The custom value for use in Range control.\n */\nexport function getPresetValueFromControlValue(\n\tcontrolValue,\n\tcontrolType,\n\tpresets\n) {\n\tconst size = parseInt( controlValue, 10 );\n\tif ( controlType === 'selectList' ) {\n\t\tif ( size === 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\t} else if ( size === 0 ) {\n\t\treturn '0';\n\t}\n\n\treturn `var:preset|border-radius|${ presets[ controlValue ]?.slug }`;\n}\n\n/**\n * Converts a custom value to preset value if one can be found.\n *\n * Returns value as-is if no match is found.\n *\n * @param {string} value Value to convert\n * @param {Array} presets Array of the current border radius preset objects\n *\n * @return {string} The preset value if it can be found.\n */\nexport function getPresetValueFromCustomValue( value, presets ) {\n\t// Return value as-is if it is undefined or is already a preset, or '0';\n\tif ( ! value || isValuePreset( value ) || value === '0' ) {\n\t\treturn value;\n\t}\n\n\tconst spacingMatch = presets.find(\n\t\t( size ) => String( size.size ) === String( value )\n\t);\n\n\tif ( spacingMatch?.slug ) {\n\t\treturn `var:preset|border-radius|${ spacingMatch.slug }`;\n\t}\n\n\treturn value;\n}\n\n/**\n * Converts all preset values in a values object to their custom equivalents.\n *\n * @param {Object} values Values object to convert\n * @param {Array} presets Array of current border radius preset objects\n *\n * @return {Object} Values with presets converted to custom values\n */\nexport function convertPresetsToCustomValues( values, presets ) {\n\tif ( ! values || typeof values !== 'object' ) {\n\t\treturn values;\n\t}\n\n\tconst converted = {};\n\tObject.keys( values ).forEach( ( key ) => {\n\t\tconst value = values[ key ];\n\t\tif ( isValuePreset( value ) ) {\n\t\t\tconst customValue = getCustomValueFromPreset( value, presets );\n\t\t\tconverted[ key ] = customValue !== undefined ? customValue : value;\n\t\t} else {\n\t\t\tconverted[ key ] = value;\n\t\t}\n\t} );\n\n\treturn converted;\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,kDAAkD,wCAAwC;AAe5F,SAAS,KAAM,YAAa;AAClC,QAAM,MAAM,CAAE,GAAG,UAAW;AAC5B,SAAO,IACL;AAAA,IACA,CAAE,GAAG,MACJ,WAAW,OAAQ,CAAE,MAAO,MAAM,CAAE,EAAE,SACtC,WAAW,OAAQ,CAAE,MAAO,MAAM,CAAE,EAAE;AAAA,EACxC,EACC,MAAM;AACT;AAYO,SAAS,WAAY,gBAAgB,CAAC,GAAI;AAChD,QAAM,EAAE,MAAM,GAAG,YAAY,IAAI;AACjC,SACC,QAAQ,KAAM,OAAO,OAAQ,WAAY,EAAE,OAAQ,OAAQ,CAAE,KAAK;AAEpE;AAQ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AAO,SAAU;AAE/D,MAAK,CAAE,SAAS,cAAe,KAAM,KAAK,UAAU,KAAM;AACzD,WAAO;AAAA,EACR;AAEA,QAAM,eAAe,QAAQ;AAAA,IAC5B,CAAE,SAAU,OAAQ,KAAK,IAAK,MAAM,OAAQ,KAAM;AAAA,EACnD;AAEA,MAAK,cAAc,MAAO;AACzB,WAAO,4BAA6B,aAAa,IAAK;AAAA,EACvD;AAEA,SAAO;AACR;AAUO,SAAS,6BAA8B,QAAQ,SAAU;AAC/D,MAAK,CAAE,UAAU,OAAO,WAAW,UAAW;AAC7C,WAAO;AAAA,EACR;AAEA,QAAM,YAAY,CAAC;AACnB,SAAO,KAAM,MAAO,EAAE,QAAS,CAAE,QAAS;AACzC,UAAM,QAAQ,OAAQ,GAAI;AAC1B,QAAK,cAAe,KAAM,GAAI;AAC7B,YAAM,cAAc,yBAA0B,OAAO,OAAQ;AAC7D,gBAAW,GAAI,IAAI,gBAAgB,SAAY,cAAc;AAAA,IAC9D,OAAO;AACN,gBAAW,GAAI,IAAI;AAAA,IACpB;AAAA,EACD,CAAE;AAEF,SAAO;AACR;",
|
|
6
6
|
"names": ["value"]
|
|
7
7
|
}
|
|
@@ -121,16 +121,20 @@ function BorderPanel({
|
|
|
121
121
|
const showBorderWidth = useHasBorderWidthControl(settings);
|
|
122
122
|
const showBorderRadius = useHasBorderRadiusControl(settings);
|
|
123
123
|
const borderRadiusValues = useMemo(() => {
|
|
124
|
-
if (typeof border?.radius !== "object") {
|
|
125
|
-
return border?.radius;
|
|
124
|
+
if (typeof inheritedValue?.border?.radius !== "object") {
|
|
125
|
+
return decodeValue(inheritedValue?.border?.radius);
|
|
126
126
|
}
|
|
127
127
|
return {
|
|
128
|
-
topLeft: border?.radius?.topLeft,
|
|
129
|
-
topRight: border?.radius?.topRight,
|
|
130
|
-
bottomLeft:
|
|
131
|
-
|
|
128
|
+
topLeft: decodeValue(inheritedValue?.border?.radius?.topLeft),
|
|
129
|
+
topRight: decodeValue(inheritedValue?.border?.radius?.topRight),
|
|
130
|
+
bottomLeft: decodeValue(
|
|
131
|
+
inheritedValue?.border?.radius?.bottomLeft
|
|
132
|
+
),
|
|
133
|
+
bottomRight: decodeValue(
|
|
134
|
+
inheritedValue?.border?.radius?.bottomRight
|
|
135
|
+
)
|
|
132
136
|
};
|
|
133
|
-
}, [border?.radius]);
|
|
137
|
+
}, [inheritedValue?.border?.radius, decodeValue]);
|
|
134
138
|
const setBorderRadius = (newBorderRadius) => setBorder({ ...border, radius: newBorderRadius });
|
|
135
139
|
const hasBorderRadius = () => {
|
|
136
140
|
const borderValues = value?.border?.radius;
|