@wordpress/block-editor 10.0.2 → 10.1.1-next.4d3b314fd5.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 +2 -0
- package/build/components/block-draggable/index.js +1 -1
- package/build/components/block-draggable/index.js.map +1 -1
- package/build/components/block-list/index.js +19 -5
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +7 -1
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +14 -5
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-popover/inbetween.js +24 -9
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +29 -3
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/block-preview/auto.js +23 -11
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-styles/index.js +1 -3
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-tools/index.js +18 -13
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-tools/insertion-point.js +5 -3
- package/build/components/block-tools/insertion-point.js.map +1 -1
- package/build/components/block-tools/use-block-toolbar-popover-props.js +6 -3
- package/build/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
- package/build/components/block-variation-picker/index.native.js +2 -1
- package/build/components/block-variation-picker/index.native.js.map +1 -1
- package/build/components/button-block-appender/index.native.js +1 -0
- package/build/components/button-block-appender/index.native.js.map +1 -1
- package/build/components/index.js +9 -0
- package/build/components/index.js.map +1 -1
- package/build/components/list-view/index.js +2 -1
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/rich-text/format-toolbar-container.js +8 -1
- package/build/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build/components/rich-text/index.js +12 -0
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/url-input/index.js +1 -3
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/url-popover/image-url-input-ui.js +1 -1
- package/build/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build/components/use-block-drop-zone/index.js +19 -1
- package/build/components/use-block-drop-zone/index.js.map +1 -1
- package/build/components/use-on-block-drop/index.js +62 -20
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/use-setting/index.js +16 -12
- package/build/components/use-setting/index.js.map +1 -1
- package/build/components/writing-flow/use-arrow-nav.js +21 -8
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/hooks/index.js +13 -1
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/layout.js +76 -23
- package/build/hooks/layout.js.map +1 -1
- package/build/index.js +14 -0
- package/build/index.js.map +1 -1
- package/build/store/reducer.js +33 -19
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +5 -5
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-draggable/index.js +1 -1
- package/build-module/components/block-draggable/index.js.map +1 -1
- package/build-module/components/block-list/index.js +22 -8
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +8 -2
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +15 -6
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +24 -9
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +29 -4
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +22 -10
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-styles/index.js +1 -2
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-tools/index.js +18 -12
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-tools/insertion-point.js +5 -3
- package/build-module/components/block-tools/insertion-point.js.map +1 -1
- package/build-module/components/block-tools/use-block-toolbar-popover-props.js +6 -3
- package/build-module/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
- package/build-module/components/block-variation-picker/index.native.js +2 -1
- package/build-module/components/block-variation-picker/index.native.js.map +1 -1
- package/build-module/components/button-block-appender/index.native.js +1 -0
- package/build-module/components/button-block-appender/index.native.js.map +1 -1
- package/build-module/components/index.js +1 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/list-view/index.js +2 -1
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/rich-text/format-toolbar-container.js +6 -1
- package/build-module/components/rich-text/format-toolbar-container.js.map +1 -1
- package/build-module/components/rich-text/index.js +12 -0
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/url-input/index.js +1 -2
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/url-popover/image-url-input-ui.js +1 -1
- package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
- package/build-module/components/use-block-drop-zone/index.js +19 -1
- package/build-module/components/use-block-drop-zone/index.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js +62 -21
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/use-setting/index.js +16 -12
- package/build-module/components/use-setting/index.js.map +1 -1
- package/build-module/components/writing-flow/use-arrow-nav.js +22 -9
- package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/layout.js +73 -23
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/store/reducer.js +29 -18
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +5 -5
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +24 -6
- package/build-style/style.css +24 -6
- package/package.json +29 -29
- package/src/components/block-controls/test/index.js +84 -8
- package/src/components/block-draggable/index.js +1 -1
- package/src/components/block-draggable/test/index.native.js +0 -9
- package/src/components/block-list/index.js +42 -6
- package/src/components/block-list/use-block-props/index.js +6 -1
- package/src/components/block-list/use-in-between-inserter.js +14 -8
- package/src/components/block-mover/style.scss +2 -7
- package/src/components/block-popover/inbetween.js +34 -10
- package/src/components/block-popover/index.js +47 -3
- package/src/components/block-preview/auto.js +77 -65
- package/src/components/block-preview/style.scss +13 -0
- package/src/components/block-styles/index.js +1 -2
- package/src/components/block-tools/index.js +16 -10
- package/src/components/block-tools/insertion-point.js +3 -3
- package/src/components/block-tools/use-block-toolbar-popover-props.js +6 -0
- package/src/components/block-variation-picker/index.native.js +1 -0
- package/src/components/button-block-appender/index.native.js +1 -0
- package/src/components/index.js +1 -0
- package/src/components/link-control/test/index.js +1 -2
- package/src/components/list-view/index.js +1 -0
- package/src/components/rich-text/format-toolbar-container.js +8 -2
- package/src/components/rich-text/index.js +14 -0
- package/src/components/url-input/index.js +6 -2
- package/src/components/url-popover/image-url-input-ui.js +1 -1
- package/src/components/use-block-drop-zone/index.js +26 -1
- package/src/components/use-on-block-drop/index.js +110 -35
- package/src/components/use-on-block-drop/test/index.js +33 -43
- package/src/components/use-setting/index.js +18 -16
- package/src/components/warning/style.scss +1 -0
- package/src/components/writing-flow/use-arrow-nav.js +23 -9
- package/src/hooks/index.js +1 -0
- package/src/hooks/layout.js +64 -21
- package/src/index.js +2 -0
- package/src/store/reducer.js +22 -14
- package/src/store/selectors.js +5 -4
- package/src/store/test/reducer.js +0 -17
- package/src/components/block-controls/test/__snapshots__/index.js.snap +0 -64
|
@@ -16,11 +16,11 @@ import { useBlockEditContext } from '../block-edit';
|
|
|
16
16
|
import { store as blockEditorStore } from '../../store';
|
|
17
17
|
const blockedPaths = ['color', 'border', 'typography', 'spacing'];
|
|
18
18
|
const deprecatedFlags = {
|
|
19
|
-
'color.palette': settings => settings.colors
|
|
20
|
-
'color.gradients': settings => settings.gradients
|
|
19
|
+
'color.palette': settings => settings.colors,
|
|
20
|
+
'color.gradients': settings => settings.gradients,
|
|
21
21
|
'color.custom': settings => settings.disableCustomColors === undefined ? undefined : !settings.disableCustomColors,
|
|
22
22
|
'color.customGradient': settings => settings.disableCustomGradients === undefined ? undefined : !settings.disableCustomGradients,
|
|
23
|
-
'typography.fontSizes': settings => settings.fontSizes
|
|
23
|
+
'typography.fontSizes': settings => settings.fontSizes,
|
|
24
24
|
'typography.customFontSize': settings => settings.disableCustomFontSizes === undefined ? undefined : !settings.disableCustomFontSizes,
|
|
25
25
|
'typography.lineHeight': settings => settings.enableCustomLineHeight,
|
|
26
26
|
'spacing.units': settings => {
|
|
@@ -95,7 +95,7 @@ export default function useSetting(path) {
|
|
|
95
95
|
name: blockName,
|
|
96
96
|
clientId
|
|
97
97
|
} = useBlockEditContext();
|
|
98
|
-
|
|
98
|
+
return useSelect(select => {
|
|
99
99
|
if (blockedPaths.includes(path)) {
|
|
100
100
|
// eslint-disable-next-line no-console
|
|
101
101
|
console.warn('Top level useSetting paths are disabled. Please use a subpath to query the information needed.');
|
|
@@ -104,23 +104,28 @@ export default function useSetting(path) {
|
|
|
104
104
|
|
|
105
105
|
let result;
|
|
106
106
|
const normalizedPath = removeCustomPrefixes(path); // 1. Take settings from the block instance or its ancestors.
|
|
107
|
+
// Start from the current block and work our way up the ancestors.
|
|
107
108
|
|
|
108
|
-
const candidates = [...select(blockEditorStore).getBlockParents(clientId
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
const candidates = [clientId, ...select(blockEditorStore).getBlockParents(clientId,
|
|
110
|
+
/* ascending */
|
|
111
|
+
true)];
|
|
112
|
+
|
|
113
|
+
for (const candidateClientId of candidates) {
|
|
111
114
|
const candidateBlockName = select(blockEditorStore).getBlockName(candidateClientId);
|
|
112
115
|
|
|
113
116
|
if (hasBlockSupport(candidateBlockName, '__experimentalSettings', false)) {
|
|
114
117
|
var _get;
|
|
115
118
|
|
|
116
119
|
const candidateAtts = select(blockEditorStore).getBlockAttributes(candidateClientId);
|
|
117
|
-
|
|
120
|
+
result = (_get = get(candidateAtts, `settings.blocks.${blockName}.${normalizedPath}`)) !== null && _get !== void 0 ? _get : get(candidateAtts, `settings.${normalizedPath}`);
|
|
118
121
|
|
|
119
|
-
if (
|
|
120
|
-
|
|
122
|
+
if (result !== undefined) {
|
|
123
|
+
// Stop the search for more distant ancestors and move on.
|
|
124
|
+
break;
|
|
121
125
|
}
|
|
122
126
|
}
|
|
123
|
-
}
|
|
127
|
+
} // 2. Fall back to the settings from the block editor store (__experimentalFeatures).
|
|
128
|
+
|
|
124
129
|
|
|
125
130
|
const settings = select(blockEditorStore).getSettings();
|
|
126
131
|
|
|
@@ -156,6 +161,5 @@ export default function useSetting(path) {
|
|
|
156
161
|
|
|
157
162
|
return normalizedPath === 'typography.dropCap' ? true : undefined;
|
|
158
163
|
}, [blockName, clientId, path]);
|
|
159
|
-
return setting;
|
|
160
164
|
}
|
|
161
165
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/use-setting/index.js"],"names":["get","useSelect","__EXPERIMENTAL_PATHS_WITH_MERGE","PATHS_WITH_MERGE","hasBlockSupport","useBlockEditContext","store","blockEditorStore","blockedPaths","deprecatedFlags","settings","colors","undefined","gradients","disableCustomColors","disableCustomGradients","fontSizes","disableCustomFontSizes","enableCustomLineHeight","enableCustomUnits","enableCustomSpacing","prefixedFlags","removeCustomPrefixes","path","useSetting","name","blockName","clientId","setting","select","includes","console","warn","result","normalizedPath","candidates","getBlockParents","forEach","candidateClientId","candidateBlockName","getBlockName","candidateAtts","getBlockAttributes","candidateResult","getSettings","defaultsPath","blockPath","custom","theme","default","deprecatedSettingsValue"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SACCC,+BAA+B,IAAIC,gBADpC,EAECC,eAFD,QAGO,mBAHP;AAKA;AACA;AACA;;AACA,SAASC,mBAAT,QAAoC,eAApC;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA,MAAMC,YAAY,GAAG,CAAE,OAA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AP;AACA,KApEY,CAsEb;AACA;AACA;AACA;;;AACA,WAAOhB,cAAc,KAAK,oBAAnB,GAA0C,IAA1C,GAAiDtB,SAAxD;AACA,GA5EuB,EA6ExB,CAAEc,SAAF,EAAaC,QAAb,EAAuBJ,IAAvB,CA7EwB,CAAzB;AAgFA,SAAOK,OAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport {\n\t__EXPERIMENTAL_PATHS_WITH_MERGE as PATHS_WITH_MERGE,\n\thasBlockSupport,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { useBlockEditContext } from '../block-edit';\nimport { store as blockEditorStore } from '../../store';\n\nconst blockedPaths = [ 'color', 'border', 'typography', 'spacing' ];\n\nconst deprecatedFlags = {\n\t'color.palette': ( settings ) =>\n\t\tsettings.colors === undefined ? undefined : settings.colors,\n\t'color.gradients': ( settings ) =>\n\t\tsettings.gradients === undefined ? undefined : settings.gradients,\n\t'color.custom': ( settings ) =>\n\t\tsettings.disableCustomColors === undefined\n\t\t\t? undefined\n\t\t\t: ! settings.disableCustomColors,\n\t'color.customGradient': ( settings ) =>\n\t\tsettings.disableCustomGradients === undefined\n\t\t\t? undefined\n\t\t\t: ! settings.disableCustomGradients,\n\t'typography.fontSizes': ( settings ) =>\n\t\tsettings.fontSizes === undefined ? undefined : settings.fontSizes,\n\t'typography.customFontSize': ( settings ) =>\n\t\tsettings.disableCustomFontSizes === undefined\n\t\t\t? undefined\n\t\t\t: ! settings.disableCustomFontSizes,\n\t'typography.lineHeight': ( settings ) => settings.enableCustomLineHeight,\n\t'spacing.units': ( settings ) => {\n\t\tif ( settings.enableCustomUnits === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( settings.enableCustomUnits === true ) {\n\t\t\treturn [ 'px', 'em', 'rem', 'vh', 'vw', '%' ];\n\t\t}\n\n\t\treturn settings.enableCustomUnits;\n\t},\n\t'spacing.padding': ( settings ) => settings.enableCustomSpacing,\n};\n\nconst prefixedFlags = {\n\t/*\n\t * These were only available in the plugin\n\t * and can be removed when the minimum WordPress version\n\t * for the plugin is 5.9.\n\t */\n\t'border.customColor': 'border.color',\n\t'border.customStyle': 'border.style',\n\t'border.customWidth': 'border.width',\n\t'typography.customFontStyle': 'typography.fontStyle',\n\t'typography.customFontWeight': 'typography.fontWeight',\n\t'typography.customLetterSpacing': 'typography.letterSpacing',\n\t'typography.customTextDecorations': 'typography.textDecoration',\n\t'typography.customTextTransforms': 'typography.textTransform',\n\t/*\n\t * These were part of WordPress 5.8 and we need to keep them.\n\t */\n\t'border.customRadius': 'border.radius',\n\t'spacing.customMargin': 'spacing.margin',\n\t'spacing.customPadding': 'spacing.padding',\n\t'typography.customLineHeight': 'typography.lineHeight',\n};\n\n/**\n * Remove `custom` prefixes for flags that did not land in 5.8.\n *\n * This provides continued support for `custom` prefixed properties. It will\n * be removed once third party devs have had sufficient time to update themes,\n * plugins, etc.\n *\n * @see https://github.com/WordPress/gutenberg/pull/34485\n *\n * @param {string} path Path to desired value in settings.\n * @return {string} The value for defined setting.\n */\nconst removeCustomPrefixes = ( path ) => {\n\treturn prefixedFlags[ path ] || path;\n};\n\n/**\n * Hook that retrieves the given setting for the block instance in use.\n *\n * It looks up the settings first in the block instance hierarchy.\n * If none is found, it'll look it up in the block editor store.\n *\n * @param {string} path The path to the setting.\n * @return {any} Returns the value defined for the setting.\n * @example\n * ```js\n * const isEnabled = useSetting( 'typography.dropCap' );\n * ```\n */\nexport default function useSetting( path ) {\n\tconst { name: blockName, clientId } = useBlockEditContext();\n\n\tconst setting = useSelect(\n\t\t( select ) => {\n\t\t\tif ( blockedPaths.includes( path ) ) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'Top level useSetting paths are disabled. Please use a subpath to query the information needed.'\n\t\t\t\t);\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tlet result;\n\t\t\tconst normalizedPath = removeCustomPrefixes( path );\n\n\t\t\t// 1. Take settings from the block instance or its ancestors.\n\t\t\tconst candidates = [\n\t\t\t\t...select( blockEditorStore ).getBlockParents( clientId ),\n\t\t\t\tclientId, // The current block is added last, so it overwrites any ancestor.\n\t\t\t];\n\t\t\tcandidates.forEach( ( candidateClientId ) => {\n\t\t\t\tconst candidateBlockName =\n\t\t\t\t\tselect( blockEditorStore ).getBlockName(\n\t\t\t\t\t\tcandidateClientId\n\t\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\thasBlockSupport(\n\t\t\t\t\t\tcandidateBlockName,\n\t\t\t\t\t\t'__experimentalSettings',\n\t\t\t\t\t\tfalse\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tconst candidateAtts =\n\t\t\t\t\t\tselect( blockEditorStore ).getBlockAttributes(\n\t\t\t\t\t\t\tcandidateClientId\n\t\t\t\t\t\t);\n\t\t\t\t\tconst candidateResult =\n\t\t\t\t\t\tget(\n\t\t\t\t\t\t\tcandidateAtts,\n\t\t\t\t\t\t\t`settings.blocks.${ blockName }.${ normalizedPath }`\n\t\t\t\t\t\t) ??\n\t\t\t\t\t\tget( candidateAtts, `settings.${ normalizedPath }` );\n\t\t\t\t\tif ( candidateResult !== undefined ) {\n\t\t\t\t\t\tresult = candidateResult;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\t// 2. Fall back to the settings from the block editor store (__experimentalFeatures).\n\t\t\tconst settings = select( blockEditorStore ).getSettings();\n\t\t\tif ( result === undefined ) {\n\t\t\t\tconst defaultsPath = `__experimentalFeatures.${ normalizedPath }`;\n\t\t\t\tconst blockPath = `__experimentalFeatures.blocks.${ blockName }.${ normalizedPath }`;\n\t\t\t\tresult =\n\t\t\t\t\tget( settings, blockPath ) ?? get( settings, defaultsPath );\n\t\t\t}\n\n\t\t\t// Return if the setting was found in either the block instance or the store.\n\t\t\tif ( result !== undefined ) {\n\t\t\t\tif ( PATHS_WITH_MERGE[ normalizedPath ] ) {\n\t\t\t\t\treturn result.custom ?? result.theme ?? result.default;\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\t// 3. Otherwise, use deprecated settings.\n\t\t\tconst deprecatedSettingsValue = deprecatedFlags[ normalizedPath ]\n\t\t\t\t? deprecatedFlags[ normalizedPath ]( settings )\n\t\t\t\t: undefined;\n\t\t\tif ( deprecatedSettingsValue !== undefined ) {\n\t\t\t\treturn deprecatedSettingsValue;\n\t\t\t}\n\n\t\t\t// 4. Fallback for typography.dropCap:\n\t\t\t// This is only necessary to support typography.dropCap.\n\t\t\t// when __experimentalFeatures are not present (core without plugin).\n\t\t\t// To remove when __experimentalFeatures are ported to core.\n\t\t\treturn normalizedPath === 'typography.dropCap' ? true : undefined;\n\t\t},\n\t\t[ blockName, clientId, path ]\n\t);\n\n\treturn setting;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/use-setting/index.js"],"names":["get","useSelect","__EXPERIMENTAL_PATHS_WITH_MERGE","PATHS_WITH_MERGE","hasBlockSupport","useBlockEditContext","store","blockEditorStore","blockedPaths","deprecatedFlags","settings","colors","gradients","disableCustomColors","undefined","disableCustomGradients","fontSizes","disableCustomFontSizes","enableCustomLineHeight","enableCustomUnits","enableCustomSpacing","prefixedFlags","removeCustomPrefixes","path","useSetting","name","blockName","clientId","select","includes","console","warn","result","normalizedPath","candidates","getBlockParents","candidateClientId","candidateBlockName","getBlockName","candidateAtts","getBlockAttributes","getSettings","defaultsPath","blockPath","custom","theme","default","deprecatedSettingsValue"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SACCC,+BAA+B,IAAIC,gBADpC,EAECC,eAFD,QAGO,mBAHP;AAKA;AACA;AACA;;AACA,SAASC,mBAAT,QAAoC,eAApC;AACA,SAASC,KAAK,IAAIC,gBAAl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AAhB;AAsFA","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport {\n\t__EXPERIMENTAL_PATHS_WITH_MERGE as PATHS_WITH_MERGE,\n\thasBlockSupport,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { useBlockEditContext } from '../block-edit';\nimport { store as blockEditorStore } from '../../store';\n\nconst blockedPaths = [ 'color', 'border', 'typography', 'spacing' ];\n\nconst deprecatedFlags = {\n\t'color.palette': ( settings ) => settings.colors,\n\t'color.gradients': ( settings ) => settings.gradients,\n\t'color.custom': ( settings ) =>\n\t\tsettings.disableCustomColors === undefined\n\t\t\t? undefined\n\t\t\t: ! settings.disableCustomColors,\n\t'color.customGradient': ( settings ) =>\n\t\tsettings.disableCustomGradients === undefined\n\t\t\t? undefined\n\t\t\t: ! settings.disableCustomGradients,\n\t'typography.fontSizes': ( settings ) => settings.fontSizes,\n\t'typography.customFontSize': ( settings ) =>\n\t\tsettings.disableCustomFontSizes === undefined\n\t\t\t? undefined\n\t\t\t: ! settings.disableCustomFontSizes,\n\t'typography.lineHeight': ( settings ) => settings.enableCustomLineHeight,\n\t'spacing.units': ( settings ) => {\n\t\tif ( settings.enableCustomUnits === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( settings.enableCustomUnits === true ) {\n\t\t\treturn [ 'px', 'em', 'rem', 'vh', 'vw', '%' ];\n\t\t}\n\n\t\treturn settings.enableCustomUnits;\n\t},\n\t'spacing.padding': ( settings ) => settings.enableCustomSpacing,\n};\n\nconst prefixedFlags = {\n\t/*\n\t * These were only available in the plugin\n\t * and can be removed when the minimum WordPress version\n\t * for the plugin is 5.9.\n\t */\n\t'border.customColor': 'border.color',\n\t'border.customStyle': 'border.style',\n\t'border.customWidth': 'border.width',\n\t'typography.customFontStyle': 'typography.fontStyle',\n\t'typography.customFontWeight': 'typography.fontWeight',\n\t'typography.customLetterSpacing': 'typography.letterSpacing',\n\t'typography.customTextDecorations': 'typography.textDecoration',\n\t'typography.customTextTransforms': 'typography.textTransform',\n\t/*\n\t * These were part of WordPress 5.8 and we need to keep them.\n\t */\n\t'border.customRadius': 'border.radius',\n\t'spacing.customMargin': 'spacing.margin',\n\t'spacing.customPadding': 'spacing.padding',\n\t'typography.customLineHeight': 'typography.lineHeight',\n};\n\n/**\n * Remove `custom` prefixes for flags that did not land in 5.8.\n *\n * This provides continued support for `custom` prefixed properties. It will\n * be removed once third party devs have had sufficient time to update themes,\n * plugins, etc.\n *\n * @see https://github.com/WordPress/gutenberg/pull/34485\n *\n * @param {string} path Path to desired value in settings.\n * @return {string} The value for defined setting.\n */\nconst removeCustomPrefixes = ( path ) => {\n\treturn prefixedFlags[ path ] || path;\n};\n\n/**\n * Hook that retrieves the given setting for the block instance in use.\n *\n * It looks up the settings first in the block instance hierarchy.\n * If none is found, it'll look it up in the block editor store.\n *\n * @param {string} path The path to the setting.\n * @return {any} Returns the value defined for the setting.\n * @example\n * ```js\n * const isEnabled = useSetting( 'typography.dropCap' );\n * ```\n */\nexport default function useSetting( path ) {\n\tconst { name: blockName, clientId } = useBlockEditContext();\n\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tif ( blockedPaths.includes( path ) ) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'Top level useSetting paths are disabled. Please use a subpath to query the information needed.'\n\t\t\t\t);\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tlet result;\n\n\t\t\tconst normalizedPath = removeCustomPrefixes( path );\n\n\t\t\t// 1. Take settings from the block instance or its ancestors.\n\t\t\t// Start from the current block and work our way up the ancestors.\n\t\t\tconst candidates = [\n\t\t\t\tclientId,\n\t\t\t\t...select( blockEditorStore ).getBlockParents(\n\t\t\t\t\tclientId,\n\t\t\t\t\t/* ascending */ true\n\t\t\t\t),\n\t\t\t];\n\n\t\t\tfor ( const candidateClientId of candidates ) {\n\t\t\t\tconst candidateBlockName =\n\t\t\t\t\tselect( blockEditorStore ).getBlockName(\n\t\t\t\t\t\tcandidateClientId\n\t\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\thasBlockSupport(\n\t\t\t\t\t\tcandidateBlockName,\n\t\t\t\t\t\t'__experimentalSettings',\n\t\t\t\t\t\tfalse\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tconst candidateAtts =\n\t\t\t\t\t\tselect( blockEditorStore ).getBlockAttributes(\n\t\t\t\t\t\t\tcandidateClientId\n\t\t\t\t\t\t);\n\t\t\t\t\tresult =\n\t\t\t\t\t\tget(\n\t\t\t\t\t\t\tcandidateAtts,\n\t\t\t\t\t\t\t`settings.blocks.${ blockName }.${ normalizedPath }`\n\t\t\t\t\t\t) ??\n\t\t\t\t\t\tget( candidateAtts, `settings.${ normalizedPath }` );\n\t\t\t\t\tif ( result !== undefined ) {\n\t\t\t\t\t\t// Stop the search for more distant ancestors and move on.\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// 2. Fall back to the settings from the block editor store (__experimentalFeatures).\n\t\t\tconst settings = select( blockEditorStore ).getSettings();\n\t\t\tif ( result === undefined ) {\n\t\t\t\tconst defaultsPath = `__experimentalFeatures.${ normalizedPath }`;\n\t\t\t\tconst blockPath = `__experimentalFeatures.blocks.${ blockName }.${ normalizedPath }`;\n\t\t\t\tresult =\n\t\t\t\t\tget( settings, blockPath ) ?? get( settings, defaultsPath );\n\t\t\t}\n\n\t\t\t// Return if the setting was found in either the block instance or the store.\n\t\t\tif ( result !== undefined ) {\n\t\t\t\tif ( PATHS_WITH_MERGE[ normalizedPath ] ) {\n\t\t\t\t\treturn result.custom ?? result.theme ?? result.default;\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\t// 3. Otherwise, use deprecated settings.\n\t\t\tconst deprecatedSettingsValue = deprecatedFlags[ normalizedPath ]\n\t\t\t\t? deprecatedFlags[ normalizedPath ]( settings )\n\t\t\t\t: undefined;\n\t\t\tif ( deprecatedSettingsValue !== undefined ) {\n\t\t\t\treturn deprecatedSettingsValue;\n\t\t\t}\n\n\t\t\t// 4. Fallback for typography.dropCap:\n\t\t\t// This is only necessary to support typography.dropCap.\n\t\t\t// when __experimentalFeatures are not present (core without plugin).\n\t\t\t// To remove when __experimentalFeatures are ported to core.\n\t\t\treturn normalizedPath === 'typography.dropCap' ? true : undefined;\n\t\t},\n\t\t[ blockName, clientId, path ]\n\t);\n}\n"]}
|
|
@@ -9,7 +9,7 @@ import { useRefEffect } from '@wordpress/compose';
|
|
|
9
9
|
* Internal dependencies
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { getBlockClientId } from '../../utils/dom';
|
|
12
|
+
import { getBlockClientId, isInSameBlock } from '../../utils/dom';
|
|
13
13
|
import { store as blockEditorStore } from '../../store';
|
|
14
14
|
/**
|
|
15
15
|
* Returns true if the element should consider edge navigation upon a keyboard
|
|
@@ -76,7 +76,13 @@ export function getClosestTabbable(target, isReverse, containerElement, onlyVert
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
function isTabCandidate(node) {
|
|
79
|
-
//
|
|
79
|
+
// Skip if there's only one child that is content editable (and thus a
|
|
80
|
+
// better candidate).
|
|
81
|
+
if (node.children.length === 1 && isInSameBlock(node, node.firstElementChild) && node.firstElementChild.getAttribute('contenteditable') === 'true') {
|
|
82
|
+
return;
|
|
83
|
+
} // Not a candidate if the node is not tabbable.
|
|
84
|
+
|
|
85
|
+
|
|
80
86
|
if (!focus.tabbable.isTabbableIndex(node)) {
|
|
81
87
|
return false;
|
|
82
88
|
} // Skip focusable elements such as links within content editable nodes.
|
|
@@ -128,7 +134,11 @@ export default function useArrowNav() {
|
|
|
128
134
|
function onKeyDown(event) {
|
|
129
135
|
const {
|
|
130
136
|
keyCode,
|
|
131
|
-
target
|
|
137
|
+
target,
|
|
138
|
+
shiftKey,
|
|
139
|
+
ctrlKey,
|
|
140
|
+
altKey,
|
|
141
|
+
metaKey
|
|
132
142
|
} = event;
|
|
133
143
|
const isUp = keyCode === UP;
|
|
134
144
|
const isDown = keyCode === DOWN;
|
|
@@ -138,8 +148,7 @@ export default function useArrowNav() {
|
|
|
138
148
|
const isHorizontal = isLeft || isRight;
|
|
139
149
|
const isVertical = isUp || isDown;
|
|
140
150
|
const isNav = isHorizontal || isVertical;
|
|
141
|
-
const
|
|
142
|
-
const hasModifier = isShift || event.ctrlKey || event.altKey || event.metaKey;
|
|
151
|
+
const hasModifier = shiftKey || ctrlKey || altKey || metaKey;
|
|
143
152
|
const isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;
|
|
144
153
|
const {
|
|
145
154
|
ownerDocument
|
|
@@ -164,7 +173,7 @@ export default function useArrowNav() {
|
|
|
164
173
|
return;
|
|
165
174
|
}
|
|
166
175
|
|
|
167
|
-
if (
|
|
176
|
+
if (shiftKey) {
|
|
168
177
|
return;
|
|
169
178
|
}
|
|
170
179
|
|
|
@@ -215,17 +224,21 @@ export default function useArrowNav() {
|
|
|
215
224
|
keepCaretInsideBlock
|
|
216
225
|
} = getSettings();
|
|
217
226
|
|
|
218
|
-
if (
|
|
227
|
+
if (shiftKey) {
|
|
219
228
|
if (isClosestTabbableABlock(target, isReverse) && isNavEdge(target, isReverse)) {
|
|
220
229
|
node.contentEditable = true; // Firefox doesn't automatically move focus.
|
|
221
230
|
|
|
222
231
|
node.focus();
|
|
223
232
|
}
|
|
224
|
-
} else if (isVertical && isVerticalEdge(target, isReverse) &&
|
|
233
|
+
} else if (isVertical && isVerticalEdge(target, isReverse) && ( // When Alt is pressed, only intercept if the caret is also at
|
|
234
|
+
// the horizontal edge.
|
|
235
|
+
altKey ? isHorizontalEdge(target, isReverseDir) : true) && !keepCaretInsideBlock) {
|
|
225
236
|
const closestTabbable = getClosestTabbable(target, isReverse, node, true);
|
|
226
237
|
|
|
227
238
|
if (closestTabbable) {
|
|
228
|
-
placeCaretAtVerticalEdge(closestTabbable,
|
|
239
|
+
placeCaretAtVerticalEdge(closestTabbable, // When Alt is pressed, place the caret at the furthest
|
|
240
|
+
// horizontal edge and the furthest vertical edge.
|
|
241
|
+
altKey ? !isReverse : isReverse, altKey ? undefined : verticalRect);
|
|
229
242
|
event.preventDefault();
|
|
230
243
|
}
|
|
231
244
|
} else if (isHorizontal && defaultView.getSelection().isCollapsed && isHorizontalEdge(target, isReverseDir) && !keepCaretInsideBlock) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-arrow-nav.js"],"names":["computeCaretRect","focus","isHorizontalEdge","isVerticalEdge","placeCaretAtHorizontalEdge","placeCaretAtVerticalEdge","isRTL","UP","DOWN","LEFT","RIGHT","useDispatch","useSelect","useRefEffect","getBlockClientId","store","blockEditorStore","isNavigationCandidate","element","keyCode","hasModifier","isVertical","tagName","simpleInputTypes","includes","getAttribute","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focusable","find","reverse","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getMultiSelectedBlocksStartClientId","getMultiSelectedBlocksEndClientId","getSettings","hasMultiSelection","__unstableIsFullySelected","selectBlock","verticalRect","onMouseDown","isClosestTabbableABlock","closestTabbable","onKeyDown","event","isUp","isDown","isLeft","isRight","isHorizontal","isNav","isShift","shiftKey","ctrlKey","altKey","metaKey","isNavEdge","ownerDocument","defaultView","defaultPrevented","preventDefault","isReverseDir","keepCaretInsideBlock","getSelection","isCollapsed","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,gBADD,EAECC,KAFD,EAGCC,gBAHD,EAICC,cAJD,EAKCC,0BALD,EAMCC,wBAND,EAOCC,KAPD,QAQO,gBARP;AASA,SAASC,EAAT,EAAaC,IAAb,EAAmBC,IAAnB,EAAyBC,KAAzB,QAAsC,qBAAtC;AACA,S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AL,EAAuB;AACtBrD,UAAAA,wBAAwB,CACvBqD,eADuB,EAEvB9B,SAFuB,EAGvB2B,YAHuB,CAAxB;AAKAK,UAAAA,KAAK,CAACgB,cAAN;AACA;AACD,OApBM,MAoBA,IACNX,YAAY,IACZS,WAAW,CAACK,YAAZ,GAA2BC,WAD3B,IAEA9E,gBAAgB,CAAEyB,MAAF,EAAUkD,YAAV,CAFhB,IAGA,CAAEC,oBAJI,EAKL;AACD,cAAMpB,eAAe,GAAGhC,kBAAkB,CACzCC,MADyC,EAEzCkD,YAFyC,EAGzCrC,IAHyC,CAA1C;AAKApC,QAAAA,0BAA0B,CAAEsD,eAAF,EAAmB9B,SAAnB,CAA1B;AACAgC,QAAAA,KAAK,CAACgB,cAAN;AACA;AACD;;AAEDpC,IAAAA,IAAI,CAACyC,gBAAL,CAAuB,WAAvB,EAAoCzB,WAApC;AACAhB,IAAAA,IAAI,CAACyC,gBAAL,CAAuB,SAAvB,EAAkCtB,SAAlC;AACA,WAAO,MAAM;AACZnB,MAAAA,IAAI,CAAC0C,mBAAL,CAA0B,WAA1B,EAAuC1B,WAAvC;AACAhB,MAAAA,IAAI,CAAC0C,mBAAL,CAA0B,SAA1B,EAAqCvB,SAArC;AACA,KAHD;AAIA,GAzJkB,EAyJhB,EAzJgB,CAAnB;AA0JA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getBlockClientId } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Returns true if the element should consider edge navigation upon a keyboard\n * event of the given directional key code, or false otherwise.\n *\n * @param {Element} element HTML element to test.\n * @param {number} keyCode KeyboardEvent keyCode to test.\n * @param {boolean} hasModifier Whether a modifier is pressed.\n *\n * @return {boolean} Whether element should consider edge navigation.\n */\nexport function isNavigationCandidate( element, keyCode, hasModifier ) {\n\tconst isVertical = keyCode === UP || keyCode === DOWN;\n\n\t// Currently, all elements support unmodified vertical navigation.\n\tif ( isVertical && ! hasModifier ) {\n\t\treturn true;\n\t}\n\n\tconst { tagName } = element;\n\n\t// Native inputs should not navigate horizontally, unless they are simple types that don't need left/right arrow keys.\n\tif ( tagName === 'INPUT' ) {\n\t\tconst simpleInputTypes = [\n\t\t\t'button',\n\t\t\t'checkbox',\n\t\t\t'color',\n\t\t\t'file',\n\t\t\t'image',\n\t\t\t'radio',\n\t\t\t'reset',\n\t\t\t'submit',\n\t\t];\n\t\treturn simpleInputTypes.includes( element.getAttribute( 'type' ) );\n\t}\n\n\t// Native textareas should not navigate horizontally.\n\treturn tagName !== 'TEXTAREA';\n}\n\n/**\n * Returns the optimal tab target from the given focused element in the desired\n * direction. A preference is made toward text fields, falling back to the block\n * focus stop if no other candidates exist for the block.\n *\n * @param {Element} target Currently focused text field.\n * @param {boolean} isReverse True if considering as the first field.\n * @param {Element} containerElement Element containing all blocks.\n * @param {boolean} onlyVertical Whether to only consider tabbable elements\n * that are visually above or under the\n * target.\n *\n * @return {?Element} Optimal tab target, if one exists.\n */\nexport function getClosestTabbable(\n\ttarget,\n\tisReverse,\n\tcontainerElement,\n\tonlyVertical\n) {\n\t// Since the current focus target is not guaranteed to be a text field, find\n\t// all focusables. Tabbability is considered later.\n\tlet focusableNodes = focus.focusable.find( containerElement );\n\n\tif ( isReverse ) {\n\t\tfocusableNodes.reverse();\n\t}\n\n\t// Consider as candidates those focusables after the current target. It's\n\t// assumed this can only be reached if the target is focusable (on its\n\t// keydown event), so no need to verify it exists in the set.\n\tfocusableNodes = focusableNodes.slice(\n\t\tfocusableNodes.indexOf( target ) + 1\n\t);\n\n\tlet targetRect;\n\n\tif ( onlyVertical ) {\n\t\ttargetRect = target.getBoundingClientRect();\n\t}\n\n\tfunction isTabCandidate( node ) {\n\t\t// Not a candidate if the node is not tabbable.\n\t\tif ( ! focus.tabbable.isTabbableIndex( node ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Skip focusable elements such as links within content editable nodes.\n\t\tif ( node.isContentEditable && node.contentEditable !== 'true' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( onlyVertical ) {\n\t\t\tconst nodeRect = node.getBoundingClientRect();\n\n\t\t\tif (\n\t\t\t\tnodeRect.left >= targetRect.right ||\n\t\t\t\tnodeRect.right <= targetRect.left\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn focusableNodes.find( isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetMultiSelectedBlocksStartClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t\t__unstableIsFullySelected,\n\t} = useSelect( blockEditorStore );\n\tconst { selectBlock } = useDispatch( blockEditorStore );\n\treturn useRefEffect( ( node ) => {\n\t\t// Here a DOMRect is stored while moving the caret vertically so\n\t\t// vertical position of the start position can be restored. This is to\n\t\t// recreate browser behaviour across blocks.\n\t\tlet verticalRect;\n\n\t\tfunction onMouseDown() {\n\t\t\tverticalRect = null;\n\t\t}\n\n\t\tfunction isClosestTabbableABlock( target, isReverse ) {\n\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\ttarget,\n\t\t\t\tisReverse,\n\t\t\t\tnode\n\t\t\t);\n\t\t\treturn closestTabbable && getBlockClientId( closestTabbable );\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\tconst { keyCode, target } = event;\n\t\t\tconst isUp = keyCode === UP;\n\t\t\tconst isDown = keyCode === DOWN;\n\t\t\tconst isLeft = keyCode === LEFT;\n\t\t\tconst isRight = keyCode === RIGHT;\n\t\t\tconst isReverse = isUp || isLeft;\n\t\t\tconst isHorizontal = isLeft || isRight;\n\t\t\tconst isVertical = isUp || isDown;\n\t\t\tconst isNav = isHorizontal || isVertical;\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst hasModifier =\n\t\t\t\tisShift || event.ctrlKey || event.altKey || event.metaKey;\n\t\t\tconst isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\t// If there is a multi-selection, the arrow keys should collapse the\n\t\t\t// selection to the start or end of the selection.\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\t// Only handle if we have a full selection (not a native partial\n\t\t\t\t// selection).\n\t\t\t\tif ( ! __unstableIsFullySelected() ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( ! isNav ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( isShift ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\tif ( isReverse ) {\n\t\t\t\t\tselectBlock( getMultiSelectedBlocksStartClientId() );\n\t\t\t\t} else {\n\t\t\t\t\tselectBlock( getMultiSelectedBlocksEndClientId(), -1 );\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// When presing any key other than up or down, the initial vertical\n\t\t\t// position must ALWAYS be reset. The vertical position is saved so\n\t\t\t// it can be restored as well as possible on sebsequent vertical\n\t\t\t// arrow key presses. It may not always be possible to restore the\n\t\t\t// exact same position (such as at an empty line), so it wouldn't be\n\t\t\t// good to compute the position right before any vertical arrow key\n\t\t\t// press.\n\t\t\tif ( ! isVertical ) {\n\t\t\t\tverticalRect = null;\n\t\t\t} else if ( ! verticalRect ) {\n\t\t\t\tverticalRect = computeCaretRect( defaultView );\n\t\t\t}\n\n\t\t\t// Abort if navigation has already been handled (e.g. RichText\n\t\t\t// inline boundaries).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Abort if our current target is not a candidate for navigation\n\t\t\t// (e.g. preserve native input behaviors).\n\t\t\tif ( ! isNavigationCandidate( target, keyCode, hasModifier ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In the case of RTL scripts, right means previous and left means\n\t\t\t// next, which is the exact reverse of LTR.\n\t\t\tconst isReverseDir = isRTL( target ) ? ! isReverse : isReverse;\n\t\t\tconst { keepCaretInsideBlock } = getSettings();\n\n\t\t\tif ( isShift ) {\n\t\t\t\tif (\n\t\t\t\t\tisClosestTabbableABlock( target, isReverse ) &&\n\t\t\t\t\tisNavEdge( target, isReverse )\n\t\t\t\t) {\n\t\t\t\t\tnode.contentEditable = true;\n\t\t\t\t\t// Firefox doesn't automatically move focus.\n\t\t\t\t\tnode.focus();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisVertical &&\n\t\t\t\tisVerticalEdge( target, isReverse ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverse,\n\t\t\t\t\tnode,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\tif ( closestTabbable ) {\n\t\t\t\t\tplaceCaretAtVerticalEdge(\n\t\t\t\t\t\tclosestTabbable,\n\t\t\t\t\t\tisReverse,\n\t\t\t\t\t\tverticalRect\n\t\t\t\t\t);\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisHorizontal &&\n\t\t\t\tdefaultView.getSelection().isCollapsed &&\n\t\t\t\tisHorizontalEdge( target, isReverseDir ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverseDir,\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tplaceCaretAtHorizontalEdge( closestTabbable, isReverse );\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-arrow-nav.js"],"names":["computeCaretRect","focus","isHorizontalEdge","isVerticalEdge","placeCaretAtHorizontalEdge","placeCaretAtVerticalEdge","isRTL","UP","DOWN","LEFT","RIGHT","useDispatch","useSelect","useRefEffect","getBlockClientId","isInSameBlock","store","blockEditorStore","isNavigationCandidate","element","keyCode","hasModifier","isVertical","tagName","simpleInputTypes","includes","getAttribute","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focusable","find","reverse","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","children","length","firstElementChild","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getMultiSelectedBlocksStartClientId","getMultiSelectedBlocksEndClientId","getSettings","hasMultiSelection","__unstableIsFullySelected","selectBlock","verticalRect","onMouseDown","isClosestTabbableABlock","closestTabbable","onKeyDown","event","shiftKey","ctrlKey","altKey","metaKey","isUp","isDown","isLeft","isRight","isHorizontal","isNav","isNavEdge","ownerDocument","defaultView","defaultPrevented","preventDefault","isReverseDir","keepCaretInsideBlock","undefined","getSelection","isCollapsed","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,gBADD,EAECC,KAFD,EAGCC,gBAHD,EAICC,cAJD,EAKCC,0BALD,EAMCC,wBAND,EAOCC,KAP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,CAAC6C,mBAAL,CAA0B,SAA1B,EAAqCvB,SAArC;AACA,KAHD;AAIA,GA7JkB,EA6JhB,EA7JgB,CAAnB;AA8JA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getBlockClientId, isInSameBlock } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Returns true if the element should consider edge navigation upon a keyboard\n * event of the given directional key code, or false otherwise.\n *\n * @param {Element} element HTML element to test.\n * @param {number} keyCode KeyboardEvent keyCode to test.\n * @param {boolean} hasModifier Whether a modifier is pressed.\n *\n * @return {boolean} Whether element should consider edge navigation.\n */\nexport function isNavigationCandidate( element, keyCode, hasModifier ) {\n\tconst isVertical = keyCode === UP || keyCode === DOWN;\n\n\t// Currently, all elements support unmodified vertical navigation.\n\tif ( isVertical && ! hasModifier ) {\n\t\treturn true;\n\t}\n\n\tconst { tagName } = element;\n\n\t// Native inputs should not navigate horizontally, unless they are simple types that don't need left/right arrow keys.\n\tif ( tagName === 'INPUT' ) {\n\t\tconst simpleInputTypes = [\n\t\t\t'button',\n\t\t\t'checkbox',\n\t\t\t'color',\n\t\t\t'file',\n\t\t\t'image',\n\t\t\t'radio',\n\t\t\t'reset',\n\t\t\t'submit',\n\t\t];\n\t\treturn simpleInputTypes.includes( element.getAttribute( 'type' ) );\n\t}\n\n\t// Native textareas should not navigate horizontally.\n\treturn tagName !== 'TEXTAREA';\n}\n\n/**\n * Returns the optimal tab target from the given focused element in the desired\n * direction. A preference is made toward text fields, falling back to the block\n * focus stop if no other candidates exist for the block.\n *\n * @param {Element} target Currently focused text field.\n * @param {boolean} isReverse True if considering as the first field.\n * @param {Element} containerElement Element containing all blocks.\n * @param {boolean} onlyVertical Whether to only consider tabbable elements\n * that are visually above or under the\n * target.\n *\n * @return {?Element} Optimal tab target, if one exists.\n */\nexport function getClosestTabbable(\n\ttarget,\n\tisReverse,\n\tcontainerElement,\n\tonlyVertical\n) {\n\t// Since the current focus target is not guaranteed to be a text field, find\n\t// all focusables. Tabbability is considered later.\n\tlet focusableNodes = focus.focusable.find( containerElement );\n\n\tif ( isReverse ) {\n\t\tfocusableNodes.reverse();\n\t}\n\n\t// Consider as candidates those focusables after the current target. It's\n\t// assumed this can only be reached if the target is focusable (on its\n\t// keydown event), so no need to verify it exists in the set.\n\tfocusableNodes = focusableNodes.slice(\n\t\tfocusableNodes.indexOf( target ) + 1\n\t);\n\n\tlet targetRect;\n\n\tif ( onlyVertical ) {\n\t\ttargetRect = target.getBoundingClientRect();\n\t}\n\n\tfunction isTabCandidate( node ) {\n\t\t// Skip if there's only one child that is content editable (and thus a\n\t\t// better candidate).\n\t\tif (\n\t\t\tnode.children.length === 1 &&\n\t\t\tisInSameBlock( node, node.firstElementChild ) &&\n\t\t\tnode.firstElementChild.getAttribute( 'contenteditable' ) === 'true'\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Not a candidate if the node is not tabbable.\n\t\tif ( ! focus.tabbable.isTabbableIndex( node ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Skip focusable elements such as links within content editable nodes.\n\t\tif ( node.isContentEditable && node.contentEditable !== 'true' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( onlyVertical ) {\n\t\t\tconst nodeRect = node.getBoundingClientRect();\n\n\t\t\tif (\n\t\t\t\tnodeRect.left >= targetRect.right ||\n\t\t\t\tnodeRect.right <= targetRect.left\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn focusableNodes.find( isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetMultiSelectedBlocksStartClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t\t__unstableIsFullySelected,\n\t} = useSelect( blockEditorStore );\n\tconst { selectBlock } = useDispatch( blockEditorStore );\n\treturn useRefEffect( ( node ) => {\n\t\t// Here a DOMRect is stored while moving the caret vertically so\n\t\t// vertical position of the start position can be restored. This is to\n\t\t// recreate browser behaviour across blocks.\n\t\tlet verticalRect;\n\n\t\tfunction onMouseDown() {\n\t\t\tverticalRect = null;\n\t\t}\n\n\t\tfunction isClosestTabbableABlock( target, isReverse ) {\n\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\ttarget,\n\t\t\t\tisReverse,\n\t\t\t\tnode\n\t\t\t);\n\t\t\treturn closestTabbable && getBlockClientId( closestTabbable );\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\tconst { keyCode, target, shiftKey, ctrlKey, altKey, metaKey } =\n\t\t\t\tevent;\n\t\t\tconst isUp = keyCode === UP;\n\t\t\tconst isDown = keyCode === DOWN;\n\t\t\tconst isLeft = keyCode === LEFT;\n\t\t\tconst isRight = keyCode === RIGHT;\n\t\t\tconst isReverse = isUp || isLeft;\n\t\t\tconst isHorizontal = isLeft || isRight;\n\t\t\tconst isVertical = isUp || isDown;\n\t\t\tconst isNav = isHorizontal || isVertical;\n\t\t\tconst hasModifier = shiftKey || ctrlKey || altKey || metaKey;\n\t\t\tconst isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\t// If there is a multi-selection, the arrow keys should collapse the\n\t\t\t// selection to the start or end of the selection.\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\t// Only handle if we have a full selection (not a native partial\n\t\t\t\t// selection).\n\t\t\t\tif ( ! __unstableIsFullySelected() ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( ! isNav ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( shiftKey ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\tif ( isReverse ) {\n\t\t\t\t\tselectBlock( getMultiSelectedBlocksStartClientId() );\n\t\t\t\t} else {\n\t\t\t\t\tselectBlock( getMultiSelectedBlocksEndClientId(), -1 );\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// When presing any key other than up or down, the initial vertical\n\t\t\t// position must ALWAYS be reset. The vertical position is saved so\n\t\t\t// it can be restored as well as possible on sebsequent vertical\n\t\t\t// arrow key presses. It may not always be possible to restore the\n\t\t\t// exact same position (such as at an empty line), so it wouldn't be\n\t\t\t// good to compute the position right before any vertical arrow key\n\t\t\t// press.\n\t\t\tif ( ! isVertical ) {\n\t\t\t\tverticalRect = null;\n\t\t\t} else if ( ! verticalRect ) {\n\t\t\t\tverticalRect = computeCaretRect( defaultView );\n\t\t\t}\n\n\t\t\t// Abort if navigation has already been handled (e.g. RichText\n\t\t\t// inline boundaries).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Abort if our current target is not a candidate for navigation\n\t\t\t// (e.g. preserve native input behaviors).\n\t\t\tif ( ! isNavigationCandidate( target, keyCode, hasModifier ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In the case of RTL scripts, right means previous and left means\n\t\t\t// next, which is the exact reverse of LTR.\n\t\t\tconst isReverseDir = isRTL( target ) ? ! isReverse : isReverse;\n\t\t\tconst { keepCaretInsideBlock } = getSettings();\n\n\t\t\tif ( shiftKey ) {\n\t\t\t\tif (\n\t\t\t\t\tisClosestTabbableABlock( target, isReverse ) &&\n\t\t\t\t\tisNavEdge( target, isReverse )\n\t\t\t\t) {\n\t\t\t\t\tnode.contentEditable = true;\n\t\t\t\t\t// Firefox doesn't automatically move focus.\n\t\t\t\t\tnode.focus();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisVertical &&\n\t\t\t\tisVerticalEdge( target, isReverse ) &&\n\t\t\t\t// When Alt is pressed, only intercept if the caret is also at\n\t\t\t\t// the horizontal edge.\n\t\t\t\t( altKey ? isHorizontalEdge( target, isReverseDir ) : true ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverse,\n\t\t\t\t\tnode,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\tif ( closestTabbable ) {\n\t\t\t\t\tplaceCaretAtVerticalEdge(\n\t\t\t\t\t\tclosestTabbable,\n\t\t\t\t\t\t// When Alt is pressed, place the caret at the furthest\n\t\t\t\t\t\t// horizontal edge and the furthest vertical edge.\n\t\t\t\t\t\taltKey ? ! isReverse : isReverse,\n\t\t\t\t\t\taltKey ? undefined : verticalRect\n\t\t\t\t\t);\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisHorizontal &&\n\t\t\t\tdefaultView.getSelection().isCollapsed &&\n\t\t\t\tisHorizontalEdge( target, isReverseDir ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverseDir,\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tplaceCaretAtHorizontalEdge( closestTabbable, isReverse );\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"]}
|
|
@@ -19,6 +19,7 @@ import './content-lock-ui';
|
|
|
19
19
|
import './metadata';
|
|
20
20
|
import './metadata-name';
|
|
21
21
|
export { useCustomSides } from './dimensions';
|
|
22
|
+
export { useLayoutClasses, useLayoutStyles } from './layout';
|
|
22
23
|
export { getBorderClassesAndStyles, useBorderProps } from './use-border-props';
|
|
23
24
|
export { getColorClassesAndStyles, useColorProps } from './use-color-props';
|
|
24
25
|
export { getSpacingClassesAndStyles } from './use-spacing-props';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/index.js"],"names":["useCustomSides","getBorderClassesAndStyles","useBorderProps","getColorClassesAndStyles","useColorProps","getSpacingClassesAndStyles","getTypographyClassesAndStyles","getGapCSSValue","useCachedTruthy"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,UAAP;AACA,OAAO,SAAP;AACA,OAAO,QAAP;AACA,OAAO,UAAP;AACA,OAAO,cAAP;AACA,OAAO,qBAAP;AACA,OAAO,wBAAP;AACA,OAAO,SAAP;AACA,OAAO,YAAP;AACA,OAAO,SAAP;AACA,OAAO,WAAP;AACA,OAAO,aAAP;AACA,OAAO,UAAP;AACA,OAAO,UAAP;AACA,OAAO,mBAAP;AACA,OAAO,YAAP;AACA,OAAO,iBAAP;AAEA,SAASA,cAAT,QAA+B,cAA/B;AACA,SAASC,yBAAT,EAAoCC,cAApC,QAA0D,oBAA1D;AACA,SAASC,wBAAT,EAAmCC,aAAnC,QAAwD,mBAAxD;AACA,SAASC,0BAAT,QAA2C,qBAA3C;AACA,SAASC,6BAAT,QAA8C,wBAA9C;AACA,SAASC,cAAT,QAA+B,OAA/B;AACA,SAASC,eAAT,QAAgC,qBAAhC","sourcesContent":["/**\n * Internal dependencies\n */\nimport './compat';\nimport './align';\nimport './lock';\nimport './anchor';\nimport './aria-label';\nimport './custom-class-name';\nimport './generated-class-name';\nimport './style';\nimport './settings';\nimport './color';\nimport './duotone';\nimport './font-size';\nimport './border';\nimport './layout';\nimport './content-lock-ui';\nimport './metadata';\nimport './metadata-name';\n\nexport { useCustomSides } from './dimensions';\nexport { getBorderClassesAndStyles, useBorderProps } from './use-border-props';\nexport { getColorClassesAndStyles, useColorProps } from './use-color-props';\nexport { getSpacingClassesAndStyles } from './use-spacing-props';\nexport { getTypographyClassesAndStyles } from './use-typography-props';\nexport { getGapCSSValue } from './gap';\nexport { useCachedTruthy } from './use-cached-truthy';\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/index.js"],"names":["useCustomSides","useLayoutClasses","useLayoutStyles","getBorderClassesAndStyles","useBorderProps","getColorClassesAndStyles","useColorProps","getSpacingClassesAndStyles","getTypographyClassesAndStyles","getGapCSSValue","useCachedTruthy"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,UAAP;AACA,OAAO,SAAP;AACA,OAAO,QAAP;AACA,OAAO,UAAP;AACA,OAAO,cAAP;AACA,OAAO,qBAAP;AACA,OAAO,wBAAP;AACA,OAAO,SAAP;AACA,OAAO,YAAP;AACA,OAAO,SAAP;AACA,OAAO,WAAP;AACA,OAAO,aAAP;AACA,OAAO,UAAP;AACA,OAAO,UAAP;AACA,OAAO,mBAAP;AACA,OAAO,YAAP;AACA,OAAO,iBAAP;AAEA,SAASA,cAAT,QAA+B,cAA/B;AACA,SAASC,gBAAT,EAA2BC,eAA3B,QAAkD,UAAlD;AACA,SAASC,yBAAT,EAAoCC,cAApC,QAA0D,oBAA1D;AACA,SAASC,wBAAT,EAAmCC,aAAnC,QAAwD,mBAAxD;AACA,SAASC,0BAAT,QAA2C,qBAA3C;AACA,SAASC,6BAAT,QAA8C,wBAA9C;AACA,SAASC,cAAT,QAA+B,OAA/B;AACA,SAASC,eAAT,QAAgC,qBAAhC","sourcesContent":["/**\n * Internal dependencies\n */\nimport './compat';\nimport './align';\nimport './lock';\nimport './anchor';\nimport './aria-label';\nimport './custom-class-name';\nimport './generated-class-name';\nimport './style';\nimport './settings';\nimport './color';\nimport './duotone';\nimport './font-size';\nimport './border';\nimport './layout';\nimport './content-lock-ui';\nimport './metadata';\nimport './metadata-name';\n\nexport { useCustomSides } from './dimensions';\nexport { useLayoutClasses, useLayoutStyles } from './layout';\nexport { getBorderClassesAndStyles, useBorderProps } from './use-border-props';\nexport { getColorClassesAndStyles, useColorProps } from './use-color-props';\nexport { getSpacingClassesAndStyles } from './use-spacing-props';\nexport { getTypographyClassesAndStyles } from './use-typography-props';\nexport { getGapCSSValue } from './gap';\nexport { useCachedTruthy } from './use-cached-truthy';\n"]}
|
|
@@ -29,22 +29,17 @@ import BlockList from '../components/block-list';
|
|
|
29
29
|
import { getLayoutType, getLayoutTypes } from '../layouts';
|
|
30
30
|
const layoutBlockSupportKey = '__experimentalLayout';
|
|
31
31
|
/**
|
|
32
|
-
* Generates the utility classnames for the given
|
|
33
|
-
* This method was primarily added to reintroduce classnames that were removed
|
|
34
|
-
* in the 5.9 release (https://github.com/WordPress/gutenberg/issues/38719), rather
|
|
35
|
-
* than providing an extensive list of all possible layout classes. The plan is to
|
|
36
|
-
* have the style engine generate a more extensive list of utility classnames which
|
|
37
|
-
* will then replace this method.
|
|
32
|
+
* Generates the utility classnames for the given block's layout attributes.
|
|
38
33
|
*
|
|
39
|
-
* @param { Object }
|
|
40
|
-
* @param { Object } layoutDefinitions An object containing layout definitions, stored in theme.json.
|
|
34
|
+
* @param { Object } block Block object.
|
|
41
35
|
*
|
|
42
36
|
* @return { Array } Array of CSS classname strings.
|
|
43
37
|
*/
|
|
44
38
|
|
|
45
|
-
function useLayoutClasses(
|
|
46
|
-
var
|
|
39
|
+
export function useLayoutClasses() {
|
|
40
|
+
var _globalLayoutSettings, _globalLayoutSettings2;
|
|
47
41
|
|
|
42
|
+
let block = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
48
43
|
const rootPaddingAlignment = useSelect(select => {
|
|
49
44
|
var _getSettings$__experi;
|
|
50
45
|
|
|
@@ -53,32 +48,86 @@ function useLayoutClasses(layout, layoutDefinitions) {
|
|
|
53
48
|
} = select(blockEditorStore);
|
|
54
49
|
return (_getSettings$__experi = getSettings().__experimentalFeatures) === null || _getSettings$__experi === void 0 ? void 0 : _getSettings$__experi.useRootPaddingAwareAlignments;
|
|
55
50
|
}, []);
|
|
51
|
+
const globalLayoutSettings = useSetting('layout') || {};
|
|
52
|
+
const {
|
|
53
|
+
attributes = {},
|
|
54
|
+
name
|
|
55
|
+
} = block;
|
|
56
|
+
const {
|
|
57
|
+
layout
|
|
58
|
+
} = attributes;
|
|
59
|
+
const {
|
|
60
|
+
default: defaultBlockLayout
|
|
61
|
+
} = getBlockSupport(name, layoutBlockSupportKey) || {};
|
|
62
|
+
const usedLayout = layout !== null && layout !== void 0 && layout.inherit || layout !== null && layout !== void 0 && layout.contentSize || layout !== null && layout !== void 0 && layout.wideSize ? { ...layout,
|
|
63
|
+
type: 'constrained'
|
|
64
|
+
} : layout || defaultBlockLayout || {};
|
|
56
65
|
const layoutClassnames = [];
|
|
57
66
|
|
|
58
|
-
if (
|
|
59
|
-
var
|
|
67
|
+
if (globalLayoutSettings !== null && globalLayoutSettings !== void 0 && (_globalLayoutSettings = globalLayoutSettings.definitions) !== null && _globalLayoutSettings !== void 0 && (_globalLayoutSettings2 = _globalLayoutSettings[(usedLayout === null || usedLayout === void 0 ? void 0 : usedLayout.type) || 'default']) !== null && _globalLayoutSettings2 !== void 0 && _globalLayoutSettings2.className) {
|
|
68
|
+
var _globalLayoutSettings3, _globalLayoutSettings4;
|
|
60
69
|
|
|
61
|
-
layoutClassnames.push(
|
|
70
|
+
layoutClassnames.push(globalLayoutSettings === null || globalLayoutSettings === void 0 ? void 0 : (_globalLayoutSettings3 = globalLayoutSettings.definitions) === null || _globalLayoutSettings3 === void 0 ? void 0 : (_globalLayoutSettings4 = _globalLayoutSettings3[(usedLayout === null || usedLayout === void 0 ? void 0 : usedLayout.type) || 'default']) === null || _globalLayoutSettings4 === void 0 ? void 0 : _globalLayoutSettings4.className);
|
|
62
71
|
}
|
|
63
72
|
|
|
64
|
-
if ((
|
|
73
|
+
if ((usedLayout !== null && usedLayout !== void 0 && usedLayout.inherit || usedLayout !== null && usedLayout !== void 0 && usedLayout.contentSize || (usedLayout === null || usedLayout === void 0 ? void 0 : usedLayout.type) === 'constrained') && rootPaddingAlignment) {
|
|
65
74
|
layoutClassnames.push('has-global-padding');
|
|
66
75
|
}
|
|
67
76
|
|
|
68
|
-
if (
|
|
69
|
-
layoutClassnames.push(`is-${kebabCase(
|
|
77
|
+
if (usedLayout !== null && usedLayout !== void 0 && usedLayout.orientation) {
|
|
78
|
+
layoutClassnames.push(`is-${kebabCase(usedLayout.orientation)}`);
|
|
70
79
|
}
|
|
71
80
|
|
|
72
|
-
if (
|
|
73
|
-
layoutClassnames.push(`is-content-justification-${kebabCase(
|
|
81
|
+
if (usedLayout !== null && usedLayout !== void 0 && usedLayout.justifyContent) {
|
|
82
|
+
layoutClassnames.push(`is-content-justification-${kebabCase(usedLayout.justifyContent)}`);
|
|
74
83
|
}
|
|
75
84
|
|
|
76
|
-
if (
|
|
85
|
+
if (usedLayout !== null && usedLayout !== void 0 && usedLayout.flexWrap && usedLayout.flexWrap === 'nowrap') {
|
|
77
86
|
layoutClassnames.push('is-nowrap');
|
|
78
87
|
}
|
|
79
88
|
|
|
80
89
|
return layoutClassnames;
|
|
81
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Generates a CSS rule with the given block's layout styles.
|
|
93
|
+
*
|
|
94
|
+
* @param { Object } block Block object.
|
|
95
|
+
* @param { string } selector A selector to use in generating the CSS rule.
|
|
96
|
+
*
|
|
97
|
+
* @return { string } CSS rule.
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
export function useLayoutStyles() {
|
|
101
|
+
var _fullLayoutType$getLa;
|
|
102
|
+
|
|
103
|
+
let block = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
104
|
+
let selector = arguments.length > 1 ? arguments[1] : undefined;
|
|
105
|
+
const {
|
|
106
|
+
attributes = {},
|
|
107
|
+
name
|
|
108
|
+
} = block;
|
|
109
|
+
const {
|
|
110
|
+
layout = {},
|
|
111
|
+
style = {}
|
|
112
|
+
} = attributes; // Update type for blocks using legacy layouts.
|
|
113
|
+
|
|
114
|
+
const usedLayout = layout !== null && layout !== void 0 && layout.inherit || layout !== null && layout !== void 0 && layout.contentSize || layout !== null && layout !== void 0 && layout.wideSize ? { ...layout,
|
|
115
|
+
type: 'constrained'
|
|
116
|
+
} : layout || {};
|
|
117
|
+
const fullLayoutType = getLayoutType((usedLayout === null || usedLayout === void 0 ? void 0 : usedLayout.type) || 'default');
|
|
118
|
+
const globalLayoutSettings = useSetting('layout') || {};
|
|
119
|
+
const blockGapSupport = useSetting('spacing.blockGap');
|
|
120
|
+
const hasBlockGapSupport = blockGapSupport !== null;
|
|
121
|
+
const css = fullLayoutType === null || fullLayoutType === void 0 ? void 0 : (_fullLayoutType$getLa = fullLayoutType.getLayoutStyle) === null || _fullLayoutType$getLa === void 0 ? void 0 : _fullLayoutType$getLa.call(fullLayoutType, {
|
|
122
|
+
blockName: name,
|
|
123
|
+
selector,
|
|
124
|
+
layout,
|
|
125
|
+
layoutDefinitions: globalLayoutSettings === null || globalLayoutSettings === void 0 ? void 0 : globalLayoutSettings.definitions,
|
|
126
|
+
style,
|
|
127
|
+
hasBlockGapSupport
|
|
128
|
+
});
|
|
129
|
+
return css;
|
|
130
|
+
}
|
|
82
131
|
|
|
83
132
|
function LayoutPanel(_ref) {
|
|
84
133
|
let {
|
|
@@ -246,7 +295,8 @@ export const withInspectorControls = createHigherOrderComponent(BlockEdit => pro
|
|
|
246
295
|
export const withLayoutStyles = createHigherOrderComponent(BlockListBlock => props => {
|
|
247
296
|
const {
|
|
248
297
|
name,
|
|
249
|
-
attributes
|
|
298
|
+
attributes,
|
|
299
|
+
block
|
|
250
300
|
} = props;
|
|
251
301
|
const hasLayoutBlockSupport = hasBlockSupport(name, layoutBlockSupportKey);
|
|
252
302
|
const disableLayoutStyles = useSelect(select => {
|
|
@@ -268,7 +318,7 @@ export const withLayoutStyles = createHigherOrderComponent(BlockListBlock => pro
|
|
|
268
318
|
const usedLayout = layout !== null && layout !== void 0 && layout.inherit || layout !== null && layout !== void 0 && layout.contentSize || layout !== null && layout !== void 0 && layout.wideSize ? { ...layout,
|
|
269
319
|
type: 'constrained'
|
|
270
320
|
} : layout || defaultBlockLayout || {};
|
|
271
|
-
const layoutClasses = hasLayoutBlockSupport ? useLayoutClasses(
|
|
321
|
+
const layoutClasses = hasLayoutBlockSupport ? useLayoutClasses(block) : null;
|
|
272
322
|
const selector = `.${getBlockDefaultClassName(name)}.wp-container-${id}`;
|
|
273
323
|
const blockGapSupport = useSetting('spacing.blockGap');
|
|
274
324
|
const hasBlockGapSupport = blockGapSupport !== null; // Get CSS string for the current layout type.
|
|
@@ -277,10 +327,10 @@ export const withLayoutStyles = createHigherOrderComponent(BlockListBlock => pro
|
|
|
277
327
|
let css;
|
|
278
328
|
|
|
279
329
|
if (shouldRenderLayoutStyles) {
|
|
280
|
-
var _fullLayoutType$
|
|
330
|
+
var _fullLayoutType$getLa2;
|
|
281
331
|
|
|
282
332
|
const fullLayoutType = getLayoutType((usedLayout === null || usedLayout === void 0 ? void 0 : usedLayout.type) || 'default');
|
|
283
|
-
css = fullLayoutType === null || fullLayoutType === void 0 ? void 0 : (_fullLayoutType$
|
|
333
|
+
css = fullLayoutType === null || fullLayoutType === void 0 ? void 0 : (_fullLayoutType$getLa2 = fullLayoutType.getLayoutStyle) === null || _fullLayoutType$getLa2 === void 0 ? void 0 : _fullLayoutType$getLa2.call(fullLayoutType, {
|
|
284
334
|
blockName: name,
|
|
285
335
|
selector,
|
|
286
336
|
layout: usedLayout,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/layout.js"],"names":["classnames","kebabCase","createHigherOrderComponent","useInstanceId","addFilter","getBlockDefaultClassName","getBlockSupport","hasBlockSupport","useSelect","Button","ButtonGroup","ToggleControl","PanelBody","__","useContext","createPortal","store","blockEditorStore","InspectorControls","useSetting","LayoutStyle","BlockList","getLayoutType","getLayoutTypes","layoutBlockSupportKey","useLayoutClasses","layout","layoutDefinitions","rootPaddingAlignment","select","getSettings","__experimentalFeatures","useRootPaddingAwareAlignments","layoutClassnames","type","className","push","inherit","contentSize","orientation","justifyContent","flexWrap","LayoutPanel","setAttributes","attributes","name","blockName","defaultThemeLayout","themeSupportsLayout","supportsLayout","layoutBlockSupport","allowSwitching","allowEditing","allowInheriting","default","defaultBlockLayout","showInheritToggle","usedLayout","layoutType","constrainedType","displayControlsForLegacyLayouts","hasContentSizeOrLegacySettings","onChangeType","newType","onChangeLayout","newLayout","LayoutTypeSwitcher","onChange","map","label","addAttribute","settings","withInspectorControls","BlockEdit","props","supportLayout","withLayoutStyles","BlockListBlock","hasLayoutBlockSupport","disableLayoutStyles","shouldRenderLayoutStyles","id","element","__unstableElementContext","wideSize","layoutClasses","definitions","selector","blockGapSupport","hasBlockGapSupport","css","fullLayoutType","getLayoutStyle","style"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AACA,SAASC,SAAT,QAA0B,QAA1B;AAEA;AACA;AACA;;AACA,SAASC,0BAAT,EAAqCC,aAArC,QAA0D,oBAA1D;AACA,SAASC,SAAT,QAA0B,kBAA1B;AACA,SACCC,wBADD,EAECC,eAFD,EAGCC,eAHD,QAIO,mBAJP;AAKA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SACCC,MADD,EAECC,WAFD,EAGCC,aAHD,EAICC,SAJD,QAKO,uBALP;AAMA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,UAAT,EAAqBC,YAArB,QAAyC,oBAAzC;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,UAA1C;AACA,S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QA,GA9CiC,CAgDlC;;;AACA,QAAMtD,SAAS,GAAGnC,UAAU,CAC3B0E,KAD2B,aAC3BA,KAD2B,uBAC3BA,KAAK,CAAEvC,SADoB,EAE3B;AACC,KAAG,gBAAgB8C,EAAI,EAAvB,GAA4BD,wBAAwB,IAAI,CAAC,CAAEU,GAD5D,CACiE;;AADjE,GAF2B,EAK3BL,aAL2B,CAA5B;AAQA,SACC,8BACGL,wBAAwB,IACzBE,OADC,IAED,CAAC,CAAEQ,GAFF,IAGD3E,YAAY,CACX,cAAC,WAAD;AACC,IAAA,SAAS,EAAG8B,IADb;AAEC,IAAA,QAAQ,EAAG0C,QAFZ;AAGC,IAAA,GAAG,EAAGG,GAHP;AAIC,IAAA,MAAM,EAAGjC,UAJV;AAKC,IAAA,KAAK,EAAGb,UAAH,aAAGA,UAAH,uBAAGA,UAAU,CAAEiD;AALrB,IADW,EAQXX,OARW,CAJd,EAcC,cAAC,cAAD,eAAqBR,KAArB;AAA6B,IAAA,SAAS,EAAGvC;AAAzC,KAdD,CADD;AAkBA,CA5EwD,CAAnD;AA+EP/B,SAAS,CACR,0BADQ,EAER,0BAFQ,EAGRkE,YAHQ,CAAT;AAKAlE,SAAS,CACR,uBADQ,EAER,uCAFQ,EAGRwE,gBAHQ,CAAT;AAKAxE,SAAS,CACR,kBADQ,EAER,4CAFQ,EAGRoE,qBAHQ,CAAT","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\nimport { kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';\nimport { addFilter } from '@wordpress/hooks';\nimport {\n\tgetBlockDefaultClassName,\n\tgetBlockSupport,\n\thasBlockSupport,\n} from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tButton,\n\tButtonGroup,\n\tToggleControl,\n\tPanelBody,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useContext, createPortal } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { InspectorControls } from '../components';\nimport useSetting from '../components/use-setting';\nimport { LayoutStyle } from '../components/block-list/layout';\nimport BlockList from '../components/block-list';\nimport { getLayoutType, getLayoutTypes } from '../layouts';\n\nconst layoutBlockSupportKey = '__experimentalLayout';\n\n/**\n * Generates the utility classnames for the given blocks layout attributes.\n * This method was primarily added to reintroduce classnames that were removed\n * in the 5.9 release (https://github.com/WordPress/gutenberg/issues/38719), rather\n * than providing an extensive list of all possible layout classes. The plan is to\n * have the style engine generate a more extensive list of utility classnames which\n * will then replace this method.\n *\n * @param { Object } layout Layout object.\n * @param { Object } layoutDefinitions An object containing layout definitions, stored in theme.json.\n *\n * @return { Array } Array of CSS classname strings.\n */\nfunction useLayoutClasses( layout, layoutDefinitions ) {\n\tconst rootPaddingAlignment = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn getSettings().__experimentalFeatures\n\t\t\t?.useRootPaddingAwareAlignments;\n\t}, [] );\n\tconst layoutClassnames = [];\n\n\tif ( layoutDefinitions?.[ layout?.type || 'default' ]?.className ) {\n\t\tlayoutClassnames.push(\n\t\t\tlayoutDefinitions?.[ layout?.type || 'default' ]?.className\n\t\t);\n\t}\n\n\tif (\n\t\t( layout?.inherit ||\n\t\t\tlayout?.contentSize ||\n\t\t\tlayout?.type === 'constrained' ) &&\n\t\trootPaddingAlignment\n\t) {\n\t\tlayoutClassnames.push( 'has-global-padding' );\n\t}\n\n\tif ( layout?.orientation ) {\n\t\tlayoutClassnames.push( `is-${ kebabCase( layout.orientation ) }` );\n\t}\n\n\tif ( layout?.justifyContent ) {\n\t\tlayoutClassnames.push(\n\t\t\t`is-content-justification-${ kebabCase( layout.justifyContent ) }`\n\t\t);\n\t}\n\n\tif ( layout?.flexWrap && layout.flexWrap === 'nowrap' ) {\n\t\tlayoutClassnames.push( 'is-nowrap' );\n\t}\n\n\treturn layoutClassnames;\n}\n\nfunction LayoutPanel( { setAttributes, attributes, name: blockName } ) {\n\tconst { layout } = attributes;\n\tconst defaultThemeLayout = useSetting( 'layout' );\n\tconst themeSupportsLayout = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn getSettings().supportsLayout;\n\t}, [] );\n\n\tconst layoutBlockSupport = getBlockSupport(\n\t\tblockName,\n\t\tlayoutBlockSupportKey,\n\t\t{}\n\t);\n\tconst {\n\t\tallowSwitching,\n\t\tallowEditing = true,\n\t\tallowInheriting = true,\n\t\tdefault: defaultBlockLayout,\n\t} = layoutBlockSupport;\n\n\tif ( ! allowEditing ) {\n\t\treturn null;\n\t}\n\n\t// Only show the inherit toggle if it's supported,\n\t// a default theme layout is set (e.g. one that provides `contentSize` and/or `wideSize` values),\n\t// and either the default / flow or the constrained layout type is in use, as the toggle switches from one to the other.\n\tconst showInheritToggle = !! (\n\t\tallowInheriting &&\n\t\t!! defaultThemeLayout &&\n\t\t( ! layout?.type ||\n\t\t\tlayout?.type === 'default' ||\n\t\t\tlayout?.type === 'constrained' ||\n\t\t\tlayout?.inherit )\n\t);\n\n\tconst usedLayout = layout || defaultBlockLayout || {};\n\tconst {\n\t\tinherit = false,\n\t\ttype = 'default',\n\t\tcontentSize = null,\n\t} = usedLayout;\n\t/**\n\t * `themeSupportsLayout` is only relevant to the `default/flow` or\n\t * `constrained` layouts and it should not be taken into account when other\n\t * `layout` types are used.\n\t */\n\tif (\n\t\t( type === 'default' || type === 'constrained' ) &&\n\t\t! themeSupportsLayout\n\t) {\n\t\treturn null;\n\t}\n\tconst layoutType = getLayoutType( type );\n\tconst constrainedType = getLayoutType( 'constrained' );\n\tconst displayControlsForLegacyLayouts =\n\t\t! usedLayout.type && ( contentSize || inherit );\n\tconst hasContentSizeOrLegacySettings = !! inherit || !! contentSize;\n\n\tconst onChangeType = ( newType ) =>\n\t\tsetAttributes( { layout: { type: newType } } );\n\tconst onChangeLayout = ( newLayout ) =>\n\t\tsetAttributes( { layout: newLayout } );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Layout' ) }>\n\t\t\t\t\t{ showInheritToggle && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tclassName=\"block-editor-hooks__toggle-control\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Inner blocks use content width' ) }\n\t\t\t\t\t\t\t\tchecked={\n\t\t\t\t\t\t\t\t\tlayoutType?.name === 'constrained' ||\n\t\t\t\t\t\t\t\t\thasContentSizeOrLegacySettings\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tlayout: {\n\t\t\t\t\t\t\t\t\t\t\ttype:\n\t\t\t\t\t\t\t\t\t\t\t\tlayoutType?.name ===\n\t\t\t\t\t\t\t\t\t\t\t\t\t'constrained' ||\n\t\t\t\t\t\t\t\t\t\t\t\thasContentSizeOrLegacySettings\n\t\t\t\t\t\t\t\t\t\t\t\t\t? 'default'\n\t\t\t\t\t\t\t\t\t\t\t\t\t: 'constrained',\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}\n\t\t\t\t\t\t\t\thelp={\n\t\t\t\t\t\t\t\t\tlayoutType?.name === 'constrained' ||\n\t\t\t\t\t\t\t\t\thasContentSizeOrLegacySettings\n\t\t\t\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t\t\t\t'Nested blocks use content width with options for full and wide widths.'\n\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\t\t\t'Nested blocks will fill the width of this container. Toggle to constrain.'\n\t\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\t\t\t\t\t) }\n\n\t\t\t\t\t{ ! inherit && allowSwitching && (\n\t\t\t\t\t\t<LayoutTypeSwitcher\n\t\t\t\t\t\t\ttype={ type }\n\t\t\t\t\t\t\tonChange={ onChangeType }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ layoutType && layoutType.name !== 'default' && (\n\t\t\t\t\t\t<layoutType.inspectorControls\n\t\t\t\t\t\t\tlayout={ usedLayout }\n\t\t\t\t\t\t\tonChange={ onChangeLayout }\n\t\t\t\t\t\t\tlayoutBlockSupport={ layoutBlockSupport }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ constrainedType && displayControlsForLegacyLayouts && (\n\t\t\t\t\t\t<constrainedType.inspectorControls\n\t\t\t\t\t\t\tlayout={ usedLayout }\n\t\t\t\t\t\t\tonChange={ onChangeLayout }\n\t\t\t\t\t\t\tlayoutBlockSupport={ layoutBlockSupport }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t{ ! inherit && layoutType && (\n\t\t\t\t<layoutType.toolBarControls\n\t\t\t\t\tlayout={ usedLayout }\n\t\t\t\t\tonChange={ onChangeLayout }\n\t\t\t\t\tlayoutBlockSupport={ layoutBlockSupport }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction LayoutTypeSwitcher( { type, onChange } ) {\n\treturn (\n\t\t<ButtonGroup>\n\t\t\t{ getLayoutTypes().map( ( { name, label } ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tkey={ name }\n\t\t\t\t\t\tisPressed={ type === name }\n\t\t\t\t\t\tonClick={ () => onChange( name ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ label }\n\t\t\t\t\t</Button>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</ButtonGroup>\n\t);\n}\n\n/**\n * Filters registered block settings, extending attributes to include `layout`.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nexport function addAttribute( settings ) {\n\tif ( 'type' in ( settings.attributes?.layout ?? {} ) ) {\n\t\treturn settings;\n\t}\n\tif ( hasBlockSupport( settings, layoutBlockSupportKey ) ) {\n\t\tsettings.attributes = {\n\t\t\t...settings.attributes,\n\t\t\tlayout: {\n\t\t\t\ttype: 'object',\n\t\t\t},\n\t\t};\n\t}\n\n\treturn settings;\n}\n\n/**\n * Override the default edit UI to include layout controls\n *\n * @param {Function} BlockEdit Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withInspectorControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { name: blockName } = props;\n\t\tconst supportLayout = hasBlockSupport(\n\t\t\tblockName,\n\t\t\tlayoutBlockSupportKey\n\t\t);\n\n\t\treturn [\n\t\t\tsupportLayout && <LayoutPanel key=\"layout\" { ...props } />,\n\t\t\t<BlockEdit key=\"edit\" { ...props } />,\n\t\t];\n\t},\n\t'withInspectorControls'\n);\n\n/**\n * Override the default block element to add the layout styles.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withLayoutStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst { name, attributes } = props;\n\t\tconst hasLayoutBlockSupport = hasBlockSupport(\n\t\t\tname,\n\t\t\tlayoutBlockSupportKey\n\t\t);\n\t\tconst disableLayoutStyles = useSelect( ( select ) => {\n\t\t\tconst { getSettings } = select( blockEditorStore );\n\t\t\treturn !! getSettings().disableLayoutStyles;\n\t\t} );\n\t\tconst shouldRenderLayoutStyles =\n\t\t\thasLayoutBlockSupport && ! disableLayoutStyles;\n\t\tconst id = useInstanceId( BlockListBlock );\n\t\tconst defaultThemeLayout = useSetting( 'layout' ) || {};\n\t\tconst element = useContext( BlockList.__unstableElementContext );\n\t\tconst { layout } = attributes;\n\t\tconst { default: defaultBlockLayout } =\n\t\t\tgetBlockSupport( name, layoutBlockSupportKey ) || {};\n\t\tconst usedLayout =\n\t\t\tlayout?.inherit || layout?.contentSize || layout?.wideSize\n\t\t\t\t? { ...layout, type: 'constrained' }\n\t\t\t\t: layout || defaultBlockLayout || {};\n\t\tconst layoutClasses = hasLayoutBlockSupport\n\t\t\t? useLayoutClasses( usedLayout, defaultThemeLayout?.definitions )\n\t\t\t: null;\n\t\tconst selector = `.${ getBlockDefaultClassName(\n\t\t\tname\n\t\t) }.wp-container-${ id }`;\n\t\tconst blockGapSupport = useSetting( 'spacing.blockGap' );\n\t\tconst hasBlockGapSupport = blockGapSupport !== null;\n\n\t\t// Get CSS string for the current layout type.\n\t\t// The CSS and `style` element is only output if it is not empty.\n\t\tlet css;\n\t\tif ( shouldRenderLayoutStyles ) {\n\t\t\tconst fullLayoutType = getLayoutType(\n\t\t\t\tusedLayout?.type || 'default'\n\t\t\t);\n\t\t\tcss = fullLayoutType?.getLayoutStyle?.( {\n\t\t\t\tblockName: name,\n\t\t\t\tselector,\n\t\t\t\tlayout: usedLayout,\n\t\t\t\tlayoutDefinitions: defaultThemeLayout?.definitions,\n\t\t\t\tstyle: attributes?.style,\n\t\t\t\thasBlockGapSupport,\n\t\t\t} );\n\t\t}\n\n\t\t// Attach a `wp-container-` id-based class name as well as a layout class name such as `is-layout-flex`.\n\t\tconst className = classnames(\n\t\t\tprops?.className,\n\t\t\t{\n\t\t\t\t[ `wp-container-${ id }` ]: shouldRenderLayoutStyles && !! css, // Only attach a container class if there is generated CSS to be attached.\n\t\t\t},\n\t\t\tlayoutClasses\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ shouldRenderLayoutStyles &&\n\t\t\t\t\telement &&\n\t\t\t\t\t!! css &&\n\t\t\t\t\tcreatePortal(\n\t\t\t\t\t\t<LayoutStyle\n\t\t\t\t\t\t\tblockName={ name }\n\t\t\t\t\t\t\tselector={ selector }\n\t\t\t\t\t\t\tcss={ css }\n\t\t\t\t\t\t\tlayout={ usedLayout }\n\t\t\t\t\t\t\tstyle={ attributes?.style }\n\t\t\t\t\t\t/>,\n\t\t\t\t\t\telement\n\t\t\t\t\t) }\n\t\t\t\t<BlockListBlock { ...props } className={ className } />\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/layout/addAttribute',\n\taddAttribute\n);\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/editor/layout/with-layout-styles',\n\twithLayoutStyles\n);\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/layout/with-inspector-controls',\n\twithInspectorControls\n);\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/layout.js"],"names":["classnames","kebabCase","createHigherOrderComponent","useInstanceId","addFilter","getBlockDefaultClassName","getBlockSupport","hasBlockSupport","useSelect","Button","ButtonGroup","ToggleControl","PanelBody","__","useContext","createPortal","store","blockEditorStore","InspectorControls","useSetting","LayoutStyle","BlockList","getLayoutType","getLayoutTypes","layoutBlockSupportKey","useLayoutClasses","block","rootPaddingAlignment","select","getSettings","__experimentalFeatures","useRootPaddingAwareAlignments","globalLayoutSettings","attributes","name","layout","default","defaultBlockLayout","usedLayout","inherit","contentSize","wideSize","type","layoutClassnames","definitions","className","push","orientation","justifyContent","flexWrap","useLayoutStyles","selector","style","fullLayoutType","blockGapSupport","hasBlockGapSupport","css","getLayoutStyle","blockName","layoutDefinitions","LayoutPanel","setAttributes","defaultThemeLayout","themeSupportsLayout","supportsLayout","layoutBlockSupport","allowSwitching","allowEditing","allowInheriting","showInheritToggle","layoutType","constrainedType","displayControlsForLegacyLayouts","hasContentSizeOrLegacySettings","onChangeType","newType","onChangeLayout","newLayout","LayoutTypeSwitcher","onChange","map","label","addAttribute","settings","withInspectorControls","BlockEdit","props","supportLayout","withLayoutStyles","BlockListBlock","hasLayoutBlockSupport","disableLayoutStyles","shouldRenderLayoutStyles","id","element","__unstableElementContext","layoutClasses"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,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C,CAAEpC,GAD5D,CACiE;;AADjE,GAF2B,EAK3BwC,aAL2B,CAA5B;AAQA,SACC,8BACGJ,wBAAwB,IACzBE,OADC,IAED,CAAC,CAAEtC,GAFF,IAGDzC,YAAY,CACX,cAAC,WAAD;AACC,IAAA,SAAS,EAAGmB,IADb;AAEC,IAAA,QAAQ,EAAGiB,QAFZ;AAGC,IAAA,GAAG,EAAGK,GAHP;AAIC,IAAA,MAAM,EAAGlB,UAJV;AAKC,IAAA,KAAK,EAAGL,UAAH,aAAGA,UAAH,uBAAGA,UAAU,CAAEmB;AALrB,IADW,EAQX0C,OARW,CAJd,EAcC,cAAC,cAAD,eAAqBR,KAArB;AAA6B,IAAA,SAAS,EAAGzC;AAAzC,KAdD,CADD;AAkBA,CA5EwD,CAAnD;AA+EPzC,SAAS,CACR,0BADQ,EAER,0BAFQ,EAGR8E,YAHQ,CAAT;AAKA9E,SAAS,CACR,uBADQ,EAER,uCAFQ,EAGRoF,gBAHQ,CAAT;AAKApF,SAAS,CACR,kBADQ,EAER,4CAFQ,EAGRgF,qBAHQ,CAAT","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\nimport { kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';\nimport { addFilter } from '@wordpress/hooks';\nimport {\n\tgetBlockDefaultClassName,\n\tgetBlockSupport,\n\thasBlockSupport,\n} from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tButton,\n\tButtonGroup,\n\tToggleControl,\n\tPanelBody,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useContext, createPortal } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { InspectorControls } from '../components';\nimport useSetting from '../components/use-setting';\nimport { LayoutStyle } from '../components/block-list/layout';\nimport BlockList from '../components/block-list';\nimport { getLayoutType, getLayoutTypes } from '../layouts';\n\nconst layoutBlockSupportKey = '__experimentalLayout';\n\n/**\n * Generates the utility classnames for the given block's layout attributes.\n *\n * @param { Object } block Block object.\n *\n * @return { Array } Array of CSS classname strings.\n */\nexport function useLayoutClasses( block = {} ) {\n\tconst rootPaddingAlignment = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn getSettings().__experimentalFeatures\n\t\t\t?.useRootPaddingAwareAlignments;\n\t}, [] );\n\tconst globalLayoutSettings = useSetting( 'layout' ) || {};\n\n\tconst { attributes = {}, name } = block;\n\tconst { layout } = attributes;\n\n\tconst { default: defaultBlockLayout } =\n\t\tgetBlockSupport( name, layoutBlockSupportKey ) || {};\n\tconst usedLayout =\n\t\tlayout?.inherit || layout?.contentSize || layout?.wideSize\n\t\t\t? { ...layout, type: 'constrained' }\n\t\t\t: layout || defaultBlockLayout || {};\n\n\tconst layoutClassnames = [];\n\n\tif (\n\t\tglobalLayoutSettings?.definitions?.[ usedLayout?.type || 'default' ]\n\t\t\t?.className\n\t) {\n\t\tlayoutClassnames.push(\n\t\t\tglobalLayoutSettings?.definitions?.[ usedLayout?.type || 'default' ]\n\t\t\t\t?.className\n\t\t);\n\t}\n\n\tif (\n\t\t( usedLayout?.inherit ||\n\t\t\tusedLayout?.contentSize ||\n\t\t\tusedLayout?.type === 'constrained' ) &&\n\t\trootPaddingAlignment\n\t) {\n\t\tlayoutClassnames.push( 'has-global-padding' );\n\t}\n\n\tif ( usedLayout?.orientation ) {\n\t\tlayoutClassnames.push( `is-${ kebabCase( usedLayout.orientation ) }` );\n\t}\n\n\tif ( usedLayout?.justifyContent ) {\n\t\tlayoutClassnames.push(\n\t\t\t`is-content-justification-${ kebabCase(\n\t\t\t\tusedLayout.justifyContent\n\t\t\t) }`\n\t\t);\n\t}\n\n\tif ( usedLayout?.flexWrap && usedLayout.flexWrap === 'nowrap' ) {\n\t\tlayoutClassnames.push( 'is-nowrap' );\n\t}\n\n\treturn layoutClassnames;\n}\n\n/**\n * Generates a CSS rule with the given block's layout styles.\n *\n * @param { Object } block Block object.\n * @param { string } selector A selector to use in generating the CSS rule.\n *\n * @return { string } CSS rule.\n */\nexport function useLayoutStyles( block = {}, selector ) {\n\tconst { attributes = {}, name } = block;\n\tconst { layout = {}, style = {} } = attributes;\n\t// Update type for blocks using legacy layouts.\n\tconst usedLayout =\n\t\tlayout?.inherit || layout?.contentSize || layout?.wideSize\n\t\t\t? { ...layout, type: 'constrained' }\n\t\t\t: layout || {};\n\tconst fullLayoutType = getLayoutType( usedLayout?.type || 'default' );\n\tconst globalLayoutSettings = useSetting( 'layout' ) || {};\n\tconst blockGapSupport = useSetting( 'spacing.blockGap' );\n\tconst hasBlockGapSupport = blockGapSupport !== null;\n\tconst css = fullLayoutType?.getLayoutStyle?.( {\n\t\tblockName: name,\n\t\tselector,\n\t\tlayout,\n\t\tlayoutDefinitions: globalLayoutSettings?.definitions,\n\t\tstyle,\n\t\thasBlockGapSupport,\n\t} );\n\treturn css;\n}\n\nfunction LayoutPanel( { setAttributes, attributes, name: blockName } ) {\n\tconst { layout } = attributes;\n\tconst defaultThemeLayout = useSetting( 'layout' );\n\tconst themeSupportsLayout = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn getSettings().supportsLayout;\n\t}, [] );\n\n\tconst layoutBlockSupport = getBlockSupport(\n\t\tblockName,\n\t\tlayoutBlockSupportKey,\n\t\t{}\n\t);\n\tconst {\n\t\tallowSwitching,\n\t\tallowEditing = true,\n\t\tallowInheriting = true,\n\t\tdefault: defaultBlockLayout,\n\t} = layoutBlockSupport;\n\n\tif ( ! allowEditing ) {\n\t\treturn null;\n\t}\n\n\t// Only show the inherit toggle if it's supported,\n\t// a default theme layout is set (e.g. one that provides `contentSize` and/or `wideSize` values),\n\t// and either the default / flow or the constrained layout type is in use, as the toggle switches from one to the other.\n\tconst showInheritToggle = !! (\n\t\tallowInheriting &&\n\t\t!! defaultThemeLayout &&\n\t\t( ! layout?.type ||\n\t\t\tlayout?.type === 'default' ||\n\t\t\tlayout?.type === 'constrained' ||\n\t\t\tlayout?.inherit )\n\t);\n\n\tconst usedLayout = layout || defaultBlockLayout || {};\n\tconst {\n\t\tinherit = false,\n\t\ttype = 'default',\n\t\tcontentSize = null,\n\t} = usedLayout;\n\t/**\n\t * `themeSupportsLayout` is only relevant to the `default/flow` or\n\t * `constrained` layouts and it should not be taken into account when other\n\t * `layout` types are used.\n\t */\n\tif (\n\t\t( type === 'default' || type === 'constrained' ) &&\n\t\t! themeSupportsLayout\n\t) {\n\t\treturn null;\n\t}\n\tconst layoutType = getLayoutType( type );\n\tconst constrainedType = getLayoutType( 'constrained' );\n\tconst displayControlsForLegacyLayouts =\n\t\t! usedLayout.type && ( contentSize || inherit );\n\tconst hasContentSizeOrLegacySettings = !! inherit || !! contentSize;\n\n\tconst onChangeType = ( newType ) =>\n\t\tsetAttributes( { layout: { type: newType } } );\n\tconst onChangeLayout = ( newLayout ) =>\n\t\tsetAttributes( { layout: newLayout } );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Layout' ) }>\n\t\t\t\t\t{ showInheritToggle && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tclassName=\"block-editor-hooks__toggle-control\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Inner blocks use content width' ) }\n\t\t\t\t\t\t\t\tchecked={\n\t\t\t\t\t\t\t\t\tlayoutType?.name === 'constrained' ||\n\t\t\t\t\t\t\t\t\thasContentSizeOrLegacySettings\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tlayout: {\n\t\t\t\t\t\t\t\t\t\t\ttype:\n\t\t\t\t\t\t\t\t\t\t\t\tlayoutType?.name ===\n\t\t\t\t\t\t\t\t\t\t\t\t\t'constrained' ||\n\t\t\t\t\t\t\t\t\t\t\t\thasContentSizeOrLegacySettings\n\t\t\t\t\t\t\t\t\t\t\t\t\t? 'default'\n\t\t\t\t\t\t\t\t\t\t\t\t\t: 'constrained',\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}\n\t\t\t\t\t\t\t\thelp={\n\t\t\t\t\t\t\t\t\tlayoutType?.name === 'constrained' ||\n\t\t\t\t\t\t\t\t\thasContentSizeOrLegacySettings\n\t\t\t\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t\t\t\t'Nested blocks use content width with options for full and wide widths.'\n\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\t\t\t'Nested blocks will fill the width of this container. Toggle to constrain.'\n\t\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\t\t\t\t\t) }\n\n\t\t\t\t\t{ ! inherit && allowSwitching && (\n\t\t\t\t\t\t<LayoutTypeSwitcher\n\t\t\t\t\t\t\ttype={ type }\n\t\t\t\t\t\t\tonChange={ onChangeType }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ layoutType && layoutType.name !== 'default' && (\n\t\t\t\t\t\t<layoutType.inspectorControls\n\t\t\t\t\t\t\tlayout={ usedLayout }\n\t\t\t\t\t\t\tonChange={ onChangeLayout }\n\t\t\t\t\t\t\tlayoutBlockSupport={ layoutBlockSupport }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ constrainedType && displayControlsForLegacyLayouts && (\n\t\t\t\t\t\t<constrainedType.inspectorControls\n\t\t\t\t\t\t\tlayout={ usedLayout }\n\t\t\t\t\t\t\tonChange={ onChangeLayout }\n\t\t\t\t\t\t\tlayoutBlockSupport={ layoutBlockSupport }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t{ ! inherit && layoutType && (\n\t\t\t\t<layoutType.toolBarControls\n\t\t\t\t\tlayout={ usedLayout }\n\t\t\t\t\tonChange={ onChangeLayout }\n\t\t\t\t\tlayoutBlockSupport={ layoutBlockSupport }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction LayoutTypeSwitcher( { type, onChange } ) {\n\treturn (\n\t\t<ButtonGroup>\n\t\t\t{ getLayoutTypes().map( ( { name, label } ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tkey={ name }\n\t\t\t\t\t\tisPressed={ type === name }\n\t\t\t\t\t\tonClick={ () => onChange( name ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ label }\n\t\t\t\t\t</Button>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</ButtonGroup>\n\t);\n}\n\n/**\n * Filters registered block settings, extending attributes to include `layout`.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nexport function addAttribute( settings ) {\n\tif ( 'type' in ( settings.attributes?.layout ?? {} ) ) {\n\t\treturn settings;\n\t}\n\tif ( hasBlockSupport( settings, layoutBlockSupportKey ) ) {\n\t\tsettings.attributes = {\n\t\t\t...settings.attributes,\n\t\t\tlayout: {\n\t\t\t\ttype: 'object',\n\t\t\t},\n\t\t};\n\t}\n\n\treturn settings;\n}\n\n/**\n * Override the default edit UI to include layout controls\n *\n * @param {Function} BlockEdit Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withInspectorControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { name: blockName } = props;\n\t\tconst supportLayout = hasBlockSupport(\n\t\t\tblockName,\n\t\t\tlayoutBlockSupportKey\n\t\t);\n\n\t\treturn [\n\t\t\tsupportLayout && <LayoutPanel key=\"layout\" { ...props } />,\n\t\t\t<BlockEdit key=\"edit\" { ...props } />,\n\t\t];\n\t},\n\t'withInspectorControls'\n);\n\n/**\n * Override the default block element to add the layout styles.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withLayoutStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst { name, attributes, block } = props;\n\t\tconst hasLayoutBlockSupport = hasBlockSupport(\n\t\t\tname,\n\t\t\tlayoutBlockSupportKey\n\t\t);\n\t\tconst disableLayoutStyles = useSelect( ( select ) => {\n\t\t\tconst { getSettings } = select( blockEditorStore );\n\t\t\treturn !! getSettings().disableLayoutStyles;\n\t\t} );\n\t\tconst shouldRenderLayoutStyles =\n\t\t\thasLayoutBlockSupport && ! disableLayoutStyles;\n\t\tconst id = useInstanceId( BlockListBlock );\n\t\tconst defaultThemeLayout = useSetting( 'layout' ) || {};\n\t\tconst element = useContext( BlockList.__unstableElementContext );\n\t\tconst { layout } = attributes;\n\t\tconst { default: defaultBlockLayout } =\n\t\t\tgetBlockSupport( name, layoutBlockSupportKey ) || {};\n\t\tconst usedLayout =\n\t\t\tlayout?.inherit || layout?.contentSize || layout?.wideSize\n\t\t\t\t? { ...layout, type: 'constrained' }\n\t\t\t\t: layout || defaultBlockLayout || {};\n\t\tconst layoutClasses = hasLayoutBlockSupport\n\t\t\t? useLayoutClasses( block )\n\t\t\t: null;\n\t\tconst selector = `.${ getBlockDefaultClassName(\n\t\t\tname\n\t\t) }.wp-container-${ id }`;\n\t\tconst blockGapSupport = useSetting( 'spacing.blockGap' );\n\t\tconst hasBlockGapSupport = blockGapSupport !== null;\n\n\t\t// Get CSS string for the current layout type.\n\t\t// The CSS and `style` element is only output if it is not empty.\n\t\tlet css;\n\t\tif ( shouldRenderLayoutStyles ) {\n\t\t\tconst fullLayoutType = getLayoutType(\n\t\t\t\tusedLayout?.type || 'default'\n\t\t\t);\n\t\t\tcss = fullLayoutType?.getLayoutStyle?.( {\n\t\t\t\tblockName: name,\n\t\t\t\tselector,\n\t\t\t\tlayout: usedLayout,\n\t\t\t\tlayoutDefinitions: defaultThemeLayout?.definitions,\n\t\t\t\tstyle: attributes?.style,\n\t\t\t\thasBlockGapSupport,\n\t\t\t} );\n\t\t}\n\n\t\t// Attach a `wp-container-` id-based class name as well as a layout class name such as `is-layout-flex`.\n\t\tconst className = classnames(\n\t\t\tprops?.className,\n\t\t\t{\n\t\t\t\t[ `wp-container-${ id }` ]: shouldRenderLayoutStyles && !! css, // Only attach a container class if there is generated CSS to be attached.\n\t\t\t},\n\t\t\tlayoutClasses\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ shouldRenderLayoutStyles &&\n\t\t\t\t\telement &&\n\t\t\t\t\t!! css &&\n\t\t\t\t\tcreatePortal(\n\t\t\t\t\t\t<LayoutStyle\n\t\t\t\t\t\t\tblockName={ name }\n\t\t\t\t\t\t\tselector={ selector }\n\t\t\t\t\t\t\tcss={ css }\n\t\t\t\t\t\t\tlayout={ usedLayout }\n\t\t\t\t\t\t\tstyle={ attributes?.style }\n\t\t\t\t\t\t/>,\n\t\t\t\t\t\telement\n\t\t\t\t\t) }\n\t\t\t\t<BlockListBlock { ...props } className={ className } />\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/layout/addAttribute',\n\taddAttribute\n);\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/editor/layout/with-layout-styles',\n\twithLayoutStyles\n);\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/layout/with-inspector-controls',\n\twithInspectorControls\n);\n"]}
|
package/build-module/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
4
|
import './hooks';
|
|
5
|
-
export { getBorderClassesAndStyles as __experimentalGetBorderClassesAndStyles, useBorderProps as __experimentalUseBorderProps, getColorClassesAndStyles as __experimentalGetColorClassesAndStyles, getTypographyClassesAndStyles, useColorProps as __experimentalUseColorProps, useCustomSides as __experimentalUseCustomSides, getSpacingClassesAndStyles as __experimentalGetSpacingClassesAndStyles, getGapCSSValue as __experimentalGetGapCSSValue, useCachedTruthy } from './hooks';
|
|
5
|
+
export { getBorderClassesAndStyles as __experimentalGetBorderClassesAndStyles, useBorderProps as __experimentalUseBorderProps, getColorClassesAndStyles as __experimentalGetColorClassesAndStyles, getTypographyClassesAndStyles, useColorProps as __experimentalUseColorProps, useCustomSides as __experimentalUseCustomSides, getSpacingClassesAndStyles as __experimentalGetSpacingClassesAndStyles, getGapCSSValue as __experimentalGetGapCSSValue, useCachedTruthy, useLayoutClasses as __experimentaluseLayoutClasses, useLayoutStyles as __experimentaluseLayoutStyles } from './hooks';
|
|
6
6
|
export * from './components';
|
|
7
7
|
export * from './elements';
|
|
8
8
|
export * from './utils';
|