@wordpress/block-editor 11.4.0 → 11.5.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 +6 -0
- package/build/components/block-inspector/index.js +11 -10
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-inspector/useBlockInspectorAnimationSettings.js +46 -0
- package/build/components/block-inspector/useBlockInspectorAnimationSettings.js.map +1 -0
- package/build/components/block-lock/modal.js +1 -0
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +2 -2
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-styles/index.js +2 -1
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/child-layout-control/index.js +107 -0
- package/build/components/child-layout-control/index.js.map +1 -0
- package/build/components/date-format-picker/index.js +3 -3
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +594 -0
- package/build/components/global-styles/dimensions-panel.js.map +1 -0
- package/build/components/global-styles/hooks.js +72 -36
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +20 -6
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +25 -12
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +1 -1
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +2 -0
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/index.native.js +23 -0
- package/build/components/index.native.js.map +1 -1
- package/build/components/inserter/media-tab/hooks.js +10 -11
- package/build/components/inserter/media-tab/hooks.js.map +1 -1
- package/build/components/inserter/media-tab/media-list.js +5 -108
- package/build/components/inserter/media-tab/media-list.js.map +1 -1
- package/build/components/inserter/media-tab/media-preview.js +242 -0
- package/build/components/inserter/media-tab/media-preview.js.map +1 -0
- package/build/components/inspector-controls/block-support-tools-panel.js +1 -1
- package/build/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build/components/inspector-controls/fill.js +38 -9
- package/build/components/inspector-controls/fill.js.map +1 -1
- package/build/components/link-control/settings-drawer.js +1 -1
- package/build/components/link-control/settings-drawer.js.map +1 -1
- package/build/components/link-control/settings.js +1 -0
- package/build/components/link-control/settings.js.map +1 -1
- package/build/components/list-view/block.js +17 -3
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +2 -2
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/expander.js +2 -1
- package/build/components/list-view/expander.js.map +1 -1
- package/build/components/list-view/leaf.js +10 -6
- package/build/components/list-view/leaf.js.map +1 -1
- package/build/components/list-view/use-list-view-scroll-into-view.js +51 -0
- package/build/components/list-view/use-list-view-scroll-into-view.js.map +1 -0
- package/build/components/off-canvas-editor/appender.js +5 -10
- package/build/components/off-canvas-editor/appender.js.map +1 -1
- package/build/components/off-canvas-editor/branch.js +1 -0
- package/build/components/off-canvas-editor/branch.js.map +1 -1
- package/build/components/off-canvas-editor/index.js +7 -3
- package/build/components/off-canvas-editor/index.js.map +1 -1
- package/build/components/off-canvas-editor/leaf-more-menu.js +34 -4
- package/build/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
- package/build/components/off-canvas-editor/link-ui.js +1 -0
- package/build/components/off-canvas-editor/link-ui.js.map +1 -1
- package/build/components/responsive-block-control/index.js +1 -0
- package/build/components/responsive-block-control/index.js.map +1 -1
- package/build/components/rich-text/index.js +9 -43
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/use-delete.js +73 -0
- package/build/components/rich-text/use-delete.js.map +1 -0
- package/build/components/rich-text/use-input-rules.js +14 -6
- package/build/components/rich-text/use-input-rules.js.map +1 -1
- package/build/components/writing-flow/use-selection-observer.js +4 -1
- package/build/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build/hooks/align.js +3 -1
- package/build/hooks/align.js.map +1 -1
- package/build/hooks/dimensions.js +72 -190
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/duotone.js +94 -25
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/gap.js +0 -202
- package/build/hooks/gap.js.map +1 -1
- package/build/hooks/layout.js +14 -5
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/margin.js +7 -163
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +7 -163
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/typography.js +50 -65
- package/build/hooks/typography.js.map +1 -1
- package/build/hooks/utils.js +75 -0
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/flex.js +1 -0
- package/build/layouts/flex.js.map +1 -1
- package/build/store/actions.js +24 -12
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +28 -1
- package/build/store/defaults.js.map +1 -1
- package/build/store/reducer.js +53 -47
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +5 -1
- package/build/store/selectors.js.map +1 -1
- package/build/utils/parse-css-unit-to-px.js +36 -3
- package/build/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-module/components/block-inspector/index.js +9 -9
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-inspector/useBlockInspectorAnimationSettings.js +37 -0
- package/build-module/components/block-inspector/useBlockInspectorAnimationSettings.js.map +1 -0
- package/build-module/components/block-lock/modal.js +1 -0
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +2 -2
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-styles/index.js +2 -1
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/child-layout-control/index.js +98 -0
- package/build-module/components/child-layout-control/index.js.map +1 -0
- package/build-module/components/date-format-picker/index.js +4 -4
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +574 -0
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -0
- package/build-module/components/global-styles/hooks.js +71 -33
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/index.js +2 -1
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +26 -11
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +2 -0
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/index.native.js +2 -1
- package/build-module/components/index.native.js.map +1 -1
- package/build-module/components/inserter/media-tab/hooks.js +10 -11
- package/build-module/components/inserter/media-tab/hooks.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-list.js +6 -105
- package/build-module/components/inserter/media-tab/media-list.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-preview.js +222 -0
- package/build-module/components/inserter/media-tab/media-preview.js.map +1 -0
- package/build-module/components/inspector-controls/block-support-tools-panel.js +1 -1
- package/build-module/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build-module/components/inspector-controls/fill.js +39 -9
- package/build-module/components/inspector-controls/fill.js.map +1 -1
- package/build-module/components/link-control/settings-drawer.js +1 -1
- package/build-module/components/link-control/settings-drawer.js.map +1 -1
- package/build-module/components/link-control/settings.js +1 -0
- package/build-module/components/link-control/settings.js.map +1 -1
- package/build-module/components/list-view/block.js +16 -3
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +2 -2
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/expander.js +2 -1
- package/build-module/components/list-view/expander.js.map +1 -1
- package/build-module/components/list-view/leaf.js +8 -4
- package/build-module/components/list-view/leaf.js.map +1 -1
- package/build-module/components/list-view/use-list-view-scroll-into-view.js +42 -0
- package/build-module/components/list-view/use-list-view-scroll-into-view.js.map +1 -0
- package/build-module/components/off-canvas-editor/appender.js +5 -10
- package/build-module/components/off-canvas-editor/appender.js.map +1 -1
- package/build-module/components/off-canvas-editor/branch.js +1 -0
- package/build-module/components/off-canvas-editor/branch.js.map +1 -1
- package/build-module/components/off-canvas-editor/index.js +7 -3
- package/build-module/components/off-canvas-editor/index.js.map +1 -1
- package/build-module/components/off-canvas-editor/leaf-more-menu.js +36 -7
- package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +1 -1
- package/build-module/components/off-canvas-editor/link-ui.js +1 -0
- package/build-module/components/off-canvas-editor/link-ui.js.map +1 -1
- package/build-module/components/responsive-block-control/index.js +1 -0
- package/build-module/components/responsive-block-control/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +9 -43
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/use-delete.js +62 -0
- package/build-module/components/rich-text/use-delete.js.map +1 -0
- package/build-module/components/rich-text/use-input-rules.js +14 -6
- package/build-module/components/rich-text/use-input-rules.js.map +1 -1
- package/build-module/components/writing-flow/use-selection-observer.js +4 -1
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build-module/hooks/align.js +3 -1
- package/build-module/hooks/align.js.map +1 -1
- package/build-module/hooks/dimensions.js +75 -187
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/duotone.js +86 -24
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/gap.js +0 -183
- package/build-module/hooks/gap.js.map +1 -1
- package/build-module/hooks/layout.js +14 -5
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/margin.js +4 -143
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +4 -143
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/typography.js +52 -65
- package/build-module/hooks/typography.js.map +1 -1
- package/build-module/hooks/utils.js +70 -0
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/flex.js +1 -0
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/store/actions.js +24 -12
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +28 -1
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/reducer.js +53 -45
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +5 -1
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/parse-css-unit-to-px.js +36 -3
- package/build-module/utils/parse-css-unit-to-px.js.map +1 -1
- package/build-style/style-rtl.css +33 -21
- package/build-style/style.css +33 -21
- package/package.json +31 -31
- package/src/components/block-draggable/test/__snapshots__/index.native.js.snap +24 -24
- package/src/components/block-inspector/index.js +11 -14
- package/src/components/block-inspector/useBlockInspectorAnimationSettings.js +53 -0
- package/src/components/block-lock/modal.js +1 -0
- package/src/components/block-lock/style.scss +0 -9
- package/src/components/block-mobile-toolbar/test/__snapshots__/block-actions-menu.native.js.snap +20 -20
- package/src/components/block-mover/test/__snapshots__/index.native.js.snap +15 -15
- package/src/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/src/components/block-styles/index.js +5 -1
- package/src/components/child-layout-control/index.js +106 -0
- package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
- package/src/components/date-format-picker/index.js +6 -8
- package/src/components/date-format-picker/style.scss +0 -5
- package/src/components/global-styles/dimensions-panel.js +627 -0
- package/src/components/global-styles/hooks.js +88 -45
- package/src/components/global-styles/index.js +5 -1
- package/src/components/global-styles/typography-panel.js +33 -8
- package/src/components/global-styles/use-global-styles-output.js +4 -3
- package/src/components/global-styles/utils.js +2 -0
- package/src/components/index.native.js +5 -0
- package/src/components/inner-blocks/test/__snapshots__/index.js.snap +1 -1
- package/src/components/inserter/media-tab/hooks.js +9 -8
- package/src/components/inserter/media-tab/media-list.js +3 -122
- package/src/components/inserter/media-tab/media-preview.js +268 -0
- package/src/components/inserter/style.scss +22 -0
- package/src/components/inserter/test/__snapshots__/index.native.js.snap +15 -15
- package/src/components/inspector-controls/block-support-tools-panel.js +0 -1
- package/src/components/inspector-controls/fill.js +32 -8
- package/src/components/link-control/settings-drawer.js +2 -1
- package/src/components/link-control/settings.js +1 -0
- package/src/components/link-control/style.scss +18 -8
- package/src/components/link-control/test/index.js +3 -3
- package/src/components/list-view/block.js +19 -1
- package/src/components/list-view/branch.js +1 -2
- package/src/components/list-view/expander.js +1 -0
- package/src/components/list-view/leaf.js +43 -29
- package/src/components/list-view/use-list-view-scroll-into-view.js +48 -0
- package/src/components/media-replace-flow/style.scss +7 -9
- package/src/components/off-canvas-editor/appender.js +13 -16
- package/src/components/off-canvas-editor/branch.js +1 -0
- package/src/components/off-canvas-editor/index.js +8 -2
- package/src/components/off-canvas-editor/leaf-more-menu.js +57 -15
- package/src/components/off-canvas-editor/link-ui.js +1 -0
- package/src/components/responsive-block-control/index.js +1 -0
- package/src/components/rich-text/index.js +8 -44
- package/src/components/rich-text/use-delete.js +59 -0
- package/src/components/rich-text/use-input-rules.js +13 -5
- package/src/components/spacing-sizes-control/style.scss +1 -1
- package/src/components/url-popover/stories/index.js +1 -0
- package/src/components/writing-flow/use-selection-observer.js +5 -1
- package/src/hooks/align.js +1 -1
- package/src/hooks/dimensions.js +85 -269
- package/src/hooks/duotone.js +100 -30
- package/src/hooks/gap.js +0 -208
- package/src/hooks/layout.js +19 -6
- package/src/hooks/margin.js +1 -164
- package/src/hooks/padding.js +1 -163
- package/src/hooks/test/__snapshots__/align.native.js.snap +24 -24
- package/src/hooks/test/duotone.js +102 -0
- package/src/hooks/typography.js +66 -88
- package/src/hooks/utils.js +90 -0
- package/src/layouts/flex.js +1 -0
- package/src/store/actions.js +12 -4
- package/src/store/defaults.js +14 -1
- package/src/store/reducer.js +68 -43
- package/src/store/selectors.js +8 -1
- package/src/store/test/actions.js +4 -2
- package/src/utils/parse-css-unit-to-px.js +35 -5
- package/src/utils/test/parse-css-unit-to-px.js +12 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/hooks/child-layout.js +0 -213
- package/build/hooks/child-layout.js.map +0 -1
- package/build/hooks/min-height.js +0 -139
- package/build/hooks/min-height.js.map +0 -1
- package/build-module/hooks/child-layout.js +0 -193
- package/build-module/hooks/child-layout.js.map +0 -1
- package/build-module/hooks/min-height.js +0 -116
- package/build-module/hooks/min-height.js.map +0 -1
- package/src/hooks/child-layout.js +0 -195
- package/src/hooks/min-height.js +0 -104
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/margin.js"],"names":["__","Platform","useMemo","useRef","useState","useEffect","getBlockSupport","__experimentalUseCustomUnits","useCustomUnits","__experimentalBoxControl","BoxControl","isShallowEqual","useSetting","AXIAL_SIDES","SPACING_SUPPORT_KEY","useCustomSides","useIsDimensionsSupportValid","cleanEmptyObject","BlockPopover","SpacingSizesControl","getSpacingPresetCssVar","hasMarginSupport","blockType","support","margin","hasMarginValue","props","attributes","style","spacing","undefined","resetMargin","setAttributes","useIsMarginDisabled","name","blockName","isDisabled","isInvalid","MarginEdit","onMouseOver","onMouseOut","spacingSizes","units","availableUnits","sides","splitOnAxis","some","side","includes","onChange","next","newStyle","select","web","length","native","MarginVisualizer","clientId","forceShow","marginTop","top","marginRight","right","marginBottom","bottom","marginLeft","left","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","isActive","setIsActive","valueRef","timeoutRef","clearTimer","current","window","clearTimeout","setTimeout"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SACCC,QADD,EAECC,OAFD,EAGCC,MAHD,EAICC,QAJD,EAKCC,SALD,QAMO,oBANP;AAOA,SAASC,eAAT,QAAgC,mBAAhC;AACA,SACCC,4BAA4B,IAAIC,cADjC,EAECC,wBAAwB,IAAIC,UAF7B,QAGO,uBAHP;AAIA,OAAOC,cAAP,MAA2B,6BAA3B;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,2BAAvB;AACA,SACCC,WADD,EAECC,mBAFD,EAGCC,cAHD,EAICC,2BAJD,QAKO,cALP;AAMA,SAASC,gBAAT,QAAiC,SAAjC;AACA,OAAOC,YAAP,MAAyB,6BAAzB;AACA,OAAO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AAGI;AAA1D,IAPD,CADD;AAWA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tPlatform,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n\tuseEffect,\n} from '@wordpress/element';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalBoxControl as BoxControl,\n} from '@wordpress/components';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../components/use-setting';\nimport {\n\tAXIAL_SIDES,\n\tSPACING_SUPPORT_KEY,\n\tuseCustomSides,\n\tuseIsDimensionsSupportValid,\n} from './dimensions';\nimport { cleanEmptyObject } from './utils';\nimport BlockPopover from '../components/block-popover';\nimport SpacingSizesControl from '../components/spacing-sizes-control';\nimport { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils';\n\n/**\n * Determines if there is margin support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasMarginSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, SPACING_SUPPORT_KEY );\n\treturn !! ( true === support || support?.margin );\n}\n\n/**\n * Checks if there is a current value in the margin block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a margin value set.\n */\nexport function hasMarginValue( props ) {\n\treturn props.attributes.style?.spacing?.margin !== undefined;\n}\n\n/**\n * Resets the margin block support attributes. This can be used when disabling\n * the margin support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetMargin( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tmargin: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if margin settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether margin setting is disabled.\n */\nexport function useIsMarginDisabled( { name: blockName } = {} ) {\n\tconst isDisabled = ! useSetting( 'spacing.margin' );\n\tconst isInvalid = ! useIsDimensionsSupportValid( blockName, 'margin' );\n\n\treturn ! hasMarginSupport( blockName ) || isDisabled || isInvalid;\n}\n\n/**\n * Inspector control panel containing the margin related configuration\n *\n * @param {Object} props Block props.\n *\n * @return {WPElement} Margin edit element.\n */\nexport function MarginEdit( props ) {\n\tconst {\n\t\tname: blockName,\n\t\tattributes: { style },\n\t\tsetAttributes,\n\t\tonMouseOver,\n\t\tonMouseOut,\n\t} = props;\n\n\tconst spacingSizes = useSetting( 'spacing.spacingSizes' );\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [\n\t\t\t'%',\n\t\t\t'px',\n\t\t\t'em',\n\t\t\t'rem',\n\t\t\t'vw',\n\t\t],\n\t} );\n\tconst sides = useCustomSides( blockName, 'margin' );\n\tconst splitOnAxis =\n\t\tsides && sides.some( ( side ) => AXIAL_SIDES.includes( side ) );\n\n\tif ( useIsMarginDisabled( props ) ) {\n\t\treturn null;\n\t}\n\n\tconst onChange = ( next ) => {\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tmargin: next,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\treturn Platform.select( {\n\t\tweb: (\n\t\t\t<>\n\t\t\t\t{ ( ! spacingSizes || spacingSizes?.length === 0 ) && (\n\t\t\t\t\t<BoxControl\n\t\t\t\t\t\tvalues={ style?.spacing?.margin }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Margin' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ splitOnAxis }\n\t\t\t\t\t\tonMouseOver={ onMouseOver }\n\t\t\t\t\t\tonMouseOut={ onMouseOut }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ spacingSizes?.length > 0 && (\n\t\t\t\t\t<SpacingSizesControl\n\t\t\t\t\t\tvalues={ style?.spacing?.margin }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Margin' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ false }\n\t\t\t\t\t\tonMouseOver={ onMouseOver }\n\t\t\t\t\t\tonMouseOut={ onMouseOut }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</>\n\t\t),\n\t\tnative: null,\n\t} );\n}\n\nexport function MarginVisualizer( { clientId, attributes, forceShow } ) {\n\tconst margin = attributes?.style?.spacing?.margin;\n\n\tconst style = useMemo( () => {\n\t\tconst marginTop = margin?.top\n\t\t\t? getSpacingPresetCssVar( margin?.top )\n\t\t\t: 0;\n\t\tconst marginRight = margin?.right\n\t\t\t? getSpacingPresetCssVar( margin?.right )\n\t\t\t: 0;\n\t\tconst marginBottom = margin?.bottom\n\t\t\t? getSpacingPresetCssVar( margin?.bottom )\n\t\t\t: 0;\n\t\tconst marginLeft = margin?.left\n\t\t\t? getSpacingPresetCssVar( margin?.left )\n\t\t\t: 0;\n\n\t\treturn {\n\t\t\tborderTopWidth: marginTop,\n\t\t\tborderRightWidth: marginRight,\n\t\t\tborderBottomWidth: marginBottom,\n\t\t\tborderLeftWidth: marginLeft,\n\t\t\ttop: marginTop ? `calc(${ marginTop } * -1)` : 0,\n\t\t\tright: marginRight ? `calc(${ marginRight } * -1)` : 0,\n\t\t\tbottom: marginBottom ? `calc(${ marginBottom } * -1)` : 0,\n\t\t\tleft: marginLeft ? `calc(${ marginLeft } * -1)` : 0,\n\t\t};\n\t}, [ margin ] );\n\n\tconst [ isActive, setIsActive ] = useState( false );\n\tconst valueRef = useRef( margin );\n\tconst timeoutRef = useRef();\n\n\tconst clearTimer = () => {\n\t\tif ( timeoutRef.current ) {\n\t\t\twindow.clearTimeout( timeoutRef.current );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! isShallowEqual( margin, valueRef.current ) && ! forceShow ) {\n\t\t\tsetIsActive( true );\n\t\t\tvalueRef.current = margin;\n\n\t\t\ttimeoutRef.current = setTimeout( () => {\n\t\t\t\tsetIsActive( false );\n\t\t\t}, 400 );\n\t\t}\n\n\t\treturn () => {\n\t\t\tsetIsActive( false );\n\t\t\tclearTimer();\n\t\t};\n\t}, [ margin, forceShow ] );\n\n\tif ( ! isActive && ! forceShow ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockPopover\n\t\t\tclientId={ clientId }\n\t\t\t__unstableCoverTarget\n\t\t\t__unstableRefreshSize={ margin }\n\t\t\t__unstablePopoverSlot=\"block-toolbar\"\n\t\t\tshift={ false }\n\t\t>\n\t\t\t<div className=\"block-editor__padding-visualizer\" style={ style } />\n\t\t</BlockPopover>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/margin.js"],"names":["useMemo","useRef","useState","useEffect","isShallowEqual","BlockPopover","getSpacingPresetCssVar","MarginVisualizer","clientId","attributes","forceShow","margin","style","spacing","marginTop","top","marginRight","right","marginBottom","bottom","marginLeft","left","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth","isActive","setIsActive","valueRef","timeoutRef","clearTimer","current","window","clearTimeout","setTimeout"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,MAAlB,EAA0BC,QAA1B,EAAoCC,SAApC,QAAqD,oBAArD;AACA,OAAOC,cAAP,MAA2B,6BAA3B;AAEA;AACA;AACA;;AACA,OAAOC,YAAP,MAAyB,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,QAAQ,EAAGF,QADZ;AAEC,IAAA,qBAAqB,MAFtB;AAGC,IAAA,qBAAqB,EAAGG,MAHzB;AAIC,IAAA,qBAAqB,EAAC,eAJvB;AAKC,IAAA,KAAK,EAAG;AALT,KAOC;AAAK,IAAA,SAAS,EAAC,kCAAf;AAAkD,IAAA,KAAK,EAAGC;AAA1D,IAPD,CADD;AAWA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useRef, useState, useEffect } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport BlockPopover from '../components/block-popover';\nimport { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils';\n\nexport function MarginVisualizer( { clientId, attributes, forceShow } ) {\n\tconst margin = attributes?.style?.spacing?.margin;\n\n\tconst style = useMemo( () => {\n\t\tconst marginTop = margin?.top\n\t\t\t? getSpacingPresetCssVar( margin?.top )\n\t\t\t: 0;\n\t\tconst marginRight = margin?.right\n\t\t\t? getSpacingPresetCssVar( margin?.right )\n\t\t\t: 0;\n\t\tconst marginBottom = margin?.bottom\n\t\t\t? getSpacingPresetCssVar( margin?.bottom )\n\t\t\t: 0;\n\t\tconst marginLeft = margin?.left\n\t\t\t? getSpacingPresetCssVar( margin?.left )\n\t\t\t: 0;\n\n\t\treturn {\n\t\t\tborderTopWidth: marginTop,\n\t\t\tborderRightWidth: marginRight,\n\t\t\tborderBottomWidth: marginBottom,\n\t\t\tborderLeftWidth: marginLeft,\n\t\t\ttop: marginTop ? `calc(${ marginTop } * -1)` : 0,\n\t\t\tright: marginRight ? `calc(${ marginRight } * -1)` : 0,\n\t\t\tbottom: marginBottom ? `calc(${ marginBottom } * -1)` : 0,\n\t\t\tleft: marginLeft ? `calc(${ marginLeft } * -1)` : 0,\n\t\t};\n\t}, [ margin ] );\n\n\tconst [ isActive, setIsActive ] = useState( false );\n\tconst valueRef = useRef( margin );\n\tconst timeoutRef = useRef();\n\n\tconst clearTimer = () => {\n\t\tif ( timeoutRef.current ) {\n\t\t\twindow.clearTimeout( timeoutRef.current );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! isShallowEqual( margin, valueRef.current ) && ! forceShow ) {\n\t\t\tsetIsActive( true );\n\t\t\tvalueRef.current = margin;\n\n\t\t\ttimeoutRef.current = setTimeout( () => {\n\t\t\t\tsetIsActive( false );\n\t\t\t}, 400 );\n\t\t}\n\n\t\treturn () => {\n\t\t\tsetIsActive( false );\n\t\t\tclearTimer();\n\t\t};\n\t}, [ margin, forceShow ] );\n\n\tif ( ! isActive && ! forceShow ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockPopover\n\t\t\tclientId={ clientId }\n\t\t\t__unstableCoverTarget\n\t\t\t__unstableRefreshSize={ margin }\n\t\t\t__unstablePopoverSlot=\"block-toolbar\"\n\t\t\tshift={ false }\n\t\t>\n\t\t\t<div className=\"block-editor__padding-visualizer\" style={ style } />\n\t\t</BlockPopover>\n\t);\n}\n"]}
|
|
@@ -1,163 +1,24 @@
|
|
|
1
|
-
import { createElement
|
|
1
|
+
import { createElement } from "@wordpress/element";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* WordPress dependencies
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import { Platform, useState, useRef, useEffect, useMemo } from '@wordpress/element';
|
|
8
|
-
import { getBlockSupport } from '@wordpress/blocks';
|
|
9
|
-
import { __experimentalUseCustomUnits as useCustomUnits, __experimentalBoxControl as BoxControl } from '@wordpress/components';
|
|
6
|
+
import { useState, useRef, useEffect, useMemo } from '@wordpress/element';
|
|
10
7
|
import isShallowEqual from '@wordpress/is-shallow-equal';
|
|
11
8
|
/**
|
|
12
9
|
* Internal dependencies
|
|
13
10
|
*/
|
|
14
11
|
|
|
15
|
-
import useSetting from '../components/use-setting';
|
|
16
|
-
import { AXIAL_SIDES, SPACING_SUPPORT_KEY, useCustomSides, useIsDimensionsSupportValid } from './dimensions';
|
|
17
|
-
import { cleanEmptyObject } from './utils';
|
|
18
12
|
import BlockPopover from '../components/block-popover';
|
|
19
|
-
import SpacingSizesControl from '../components/spacing-sizes-control';
|
|
20
13
|
import { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils';
|
|
21
|
-
|
|
22
|
-
* Determines if there is padding support.
|
|
23
|
-
*
|
|
24
|
-
* @param {string|Object} blockType Block name or Block Type object.
|
|
25
|
-
*
|
|
26
|
-
* @return {boolean} Whether there is support.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
export function hasPaddingSupport(blockType) {
|
|
30
|
-
const support = getBlockSupport(blockType, SPACING_SUPPORT_KEY);
|
|
31
|
-
return !!(true === support || support !== null && support !== void 0 && support.padding);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Checks if there is a current value in the padding block support attributes.
|
|
35
|
-
*
|
|
36
|
-
* @param {Object} props Block props.
|
|
37
|
-
* @return {boolean} Whether or not the block has a padding value set.
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
export function hasPaddingValue(props) {
|
|
41
|
-
var _props$attributes$sty, _props$attributes$sty2;
|
|
42
|
-
|
|
43
|
-
return ((_props$attributes$sty = props.attributes.style) === null || _props$attributes$sty === void 0 ? void 0 : (_props$attributes$sty2 = _props$attributes$sty.spacing) === null || _props$attributes$sty2 === void 0 ? void 0 : _props$attributes$sty2.padding) !== undefined;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Resets the padding block support attributes. This can be used when disabling
|
|
47
|
-
* the padding support controls for a block via a `ToolsPanel`.
|
|
48
|
-
*
|
|
49
|
-
* @param {Object} props Block props.
|
|
50
|
-
* @param {Object} props.attributes Block's attributes.
|
|
51
|
-
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
export function resetPadding(_ref) {
|
|
55
|
-
let {
|
|
56
|
-
attributes = {},
|
|
57
|
-
setAttributes
|
|
58
|
-
} = _ref;
|
|
59
|
-
const {
|
|
60
|
-
style
|
|
61
|
-
} = attributes;
|
|
62
|
-
setAttributes({
|
|
63
|
-
style: cleanEmptyObject({ ...style,
|
|
64
|
-
spacing: { ...(style === null || style === void 0 ? void 0 : style.spacing),
|
|
65
|
-
padding: undefined
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Custom hook that checks if padding settings have been disabled.
|
|
72
|
-
*
|
|
73
|
-
* @param {string} name The name of the block.
|
|
74
|
-
*
|
|
75
|
-
* @return {boolean} Whether padding setting is disabled.
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
export function useIsPaddingDisabled() {
|
|
79
|
-
let {
|
|
80
|
-
name: blockName
|
|
81
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
82
|
-
const isDisabled = !useSetting('spacing.padding');
|
|
83
|
-
const isInvalid = !useIsDimensionsSupportValid(blockName, 'padding');
|
|
84
|
-
return !hasPaddingSupport(blockName) || isDisabled || isInvalid;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Inspector control panel containing the padding related configuration
|
|
88
|
-
*
|
|
89
|
-
* @param {Object} props
|
|
90
|
-
*
|
|
91
|
-
* @return {WPElement} Padding edit element.
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
export function PaddingEdit(props) {
|
|
95
|
-
var _style$spacing, _style$spacing2;
|
|
96
|
-
|
|
97
|
-
const {
|
|
98
|
-
name: blockName,
|
|
99
|
-
attributes: {
|
|
100
|
-
style
|
|
101
|
-
},
|
|
102
|
-
setAttributes,
|
|
103
|
-
onMouseOver,
|
|
104
|
-
onMouseOut
|
|
105
|
-
} = props;
|
|
106
|
-
const spacingSizes = useSetting('spacing.spacingSizes');
|
|
107
|
-
const units = useCustomUnits({
|
|
108
|
-
availableUnits: useSetting('spacing.units') || ['%', 'px', 'em', 'rem', 'vw']
|
|
109
|
-
});
|
|
110
|
-
const sides = useCustomSides(blockName, 'padding');
|
|
111
|
-
const splitOnAxis = sides && sides.some(side => AXIAL_SIDES.includes(side));
|
|
112
|
-
|
|
113
|
-
if (useIsPaddingDisabled(props)) {
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const onChange = next => {
|
|
118
|
-
const newStyle = { ...style,
|
|
119
|
-
spacing: { ...(style === null || style === void 0 ? void 0 : style.spacing),
|
|
120
|
-
padding: next
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
setAttributes({
|
|
124
|
-
style: cleanEmptyObject(newStyle)
|
|
125
|
-
});
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
return Platform.select({
|
|
129
|
-
web: createElement(Fragment, null, (!spacingSizes || (spacingSizes === null || spacingSizes === void 0 ? void 0 : spacingSizes.length) === 0) && createElement(BoxControl, {
|
|
130
|
-
values: style === null || style === void 0 ? void 0 : (_style$spacing = style.spacing) === null || _style$spacing === void 0 ? void 0 : _style$spacing.padding,
|
|
131
|
-
onChange: onChange,
|
|
132
|
-
label: __('Padding'),
|
|
133
|
-
sides: sides,
|
|
134
|
-
units: units,
|
|
135
|
-
allowReset: false,
|
|
136
|
-
splitOnAxis: splitOnAxis,
|
|
137
|
-
onMouseOver: onMouseOver,
|
|
138
|
-
onMouseOut: onMouseOut
|
|
139
|
-
}), (spacingSizes === null || spacingSizes === void 0 ? void 0 : spacingSizes.length) > 0 && createElement(SpacingSizesControl, {
|
|
140
|
-
values: style === null || style === void 0 ? void 0 : (_style$spacing2 = style.spacing) === null || _style$spacing2 === void 0 ? void 0 : _style$spacing2.padding,
|
|
141
|
-
onChange: onChange,
|
|
142
|
-
label: __('Padding'),
|
|
143
|
-
sides: sides,
|
|
144
|
-
units: units,
|
|
145
|
-
allowReset: false,
|
|
146
|
-
splitOnAxis: splitOnAxis,
|
|
147
|
-
onMouseOver: onMouseOver,
|
|
148
|
-
onMouseOut: onMouseOut
|
|
149
|
-
})),
|
|
150
|
-
native: null
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
export function PaddingVisualizer(_ref2) {
|
|
14
|
+
export function PaddingVisualizer(_ref) {
|
|
154
15
|
var _attributes$style, _attributes$style$spa;
|
|
155
16
|
|
|
156
17
|
let {
|
|
157
18
|
clientId,
|
|
158
19
|
attributes,
|
|
159
20
|
forceShow
|
|
160
|
-
} =
|
|
21
|
+
} = _ref;
|
|
161
22
|
const padding = attributes === null || attributes === void 0 ? void 0 : (_attributes$style = attributes.style) === null || _attributes$style === void 0 ? void 0 : (_attributes$style$spa = _attributes$style.spacing) === null || _attributes$style$spa === void 0 ? void 0 : _attributes$style$spa.padding;
|
|
162
23
|
const style = useMemo(() => {
|
|
163
24
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/padding.js"],"names":["__","Platform","useState","useRef","useEffect","useMemo","getBlockSupport","__experimentalUseCustomUnits","useCustomUnits","__experimentalBoxControl","BoxControl","isShallowEqual","useSetting","AXIAL_SIDES","SPACING_SUPPORT_KEY","useCustomSides","useIsDimensionsSupportValid","cleanEmptyObject","BlockPopover","SpacingSizesControl","getSpacingPresetCssVar","hasPaddingSupport","blockType","support","padding","hasPaddingValue","props","attributes","style","spacing","undefined","resetPadding","setAttributes","useIsPaddingDisabled","name","blockName","isDisabled","isInvalid","PaddingEdit","onMouseOver","onMouseOut","spacingSizes","units","availableUnits","sides","splitOnAxis","some","side","includes","onChange","next","newStyle","select","web","length","native","PaddingVisualizer","clientId","forceShow","borderTopWidth","top","borderRightWidth","right","borderBottomWidth","bottom","borderLeftWidth","left","isActive","setIsActive","valueRef","timeoutRef","clearTimer","current","window","clearTimeout","setTimeout"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SACCC,QADD,EAECC,QAFD,EAGCC,MAHD,EAICC,SAJD,EAKCC,OALD,QAMO,oBANP;AAOA,SAASC,eAAT,QAAgC,mBAAhC;AACA,SACCC,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KAAF,CAA1C;AACA,QAAMmE,QAAQ,GAAGlE,MAAM,CAAEqB,OAAF,CAAvB;AACA,QAAM8C,UAAU,GAAGnE,MAAM,EAAzB;;AAEA,QAAMoE,UAAU,GAAG,MAAM;AACxB,QAAKD,UAAU,CAACE,OAAhB,EAA0B;AACzBC,MAAAA,MAAM,CAACC,YAAP,CAAqBJ,UAAU,CAACE,OAAhC;AACA;AACD,GAJD;;AAMApE,EAAAA,SAAS,CAAE,MAAM;AAChB,QAAK,CAAEO,cAAc,CAAEa,OAAF,EAAW6C,QAAQ,CAACG,OAApB,CAAhB,IAAiD,CAAEd,SAAxD,EAAoE;AACnEU,MAAAA,WAAW,CAAE,IAAF,CAAX;AACAC,MAAAA,QAAQ,CAACG,OAAT,GAAmBhD,OAAnB;AAEA8C,MAAAA,UAAU,CAACE,OAAX,GAAqBG,UAAU,CAAE,MAAM;AACtCP,QAAAA,WAAW,CAAE,KAAF,CAAX;AACA,OAF8B,EAE5B,GAF4B,CAA/B;AAGA;;AAED,WAAO,MAAM;AACZA,MAAAA,WAAW,CAAE,KAAF,CAAX;AACAG,MAAAA,UAAU;AACV,KAHD;AAIA,GAdQ,EAcN,CAAE/C,OAAF,EAAWkC,SAAX,CAdM,CAAT;;AAgBA,MAAK,CAAES,QAAF,IAAc,CAAET,SAArB,EAAiC;AAChC,WAAO,IAAP;AACA;;AAED,SACC,cAAC,YAAD;AACC,IAAA,QAAQ,EAAGD,QADZ;AAEC,IAAA,qBAAqB,MAFtB;AAGC,IAAA,qBAAqB,EAAGjC,OAHzB;AAIC,IAAA,qBAAqB,EAAC,eAJvB;AAKC,IAAA,KAAK,EAAG;AALT,KAOC;AAAK,IAAA,SAAS,EAAC,kCAAf;AAAkD,IAAA,KAAK,EAAGI;AAA1D,IAPD,CADD;AAWA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tPlatform,\n\tuseState,\n\tuseRef,\n\tuseEffect,\n\tuseMemo,\n} from '@wordpress/element';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\t__experimentalUseCustomUnits as useCustomUnits,\n\t__experimentalBoxControl as BoxControl,\n} from '@wordpress/components';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useSetting from '../components/use-setting';\nimport {\n\tAXIAL_SIDES,\n\tSPACING_SUPPORT_KEY,\n\tuseCustomSides,\n\tuseIsDimensionsSupportValid,\n} from './dimensions';\nimport { cleanEmptyObject } from './utils';\nimport BlockPopover from '../components/block-popover';\nimport SpacingSizesControl from '../components/spacing-sizes-control';\nimport { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils';\n/**\n * Determines if there is padding support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasPaddingSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, SPACING_SUPPORT_KEY );\n\treturn !! ( true === support || support?.padding );\n}\n\n/**\n * Checks if there is a current value in the padding block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a padding value set.\n */\nexport function hasPaddingValue( props ) {\n\treturn props.attributes.style?.spacing?.padding !== undefined;\n}\n\n/**\n * Resets the padding block support attributes. This can be used when disabling\n * the padding support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetPadding( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tpadding: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if padding settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether padding setting is disabled.\n */\nexport function useIsPaddingDisabled( { name: blockName } = {} ) {\n\tconst isDisabled = ! useSetting( 'spacing.padding' );\n\tconst isInvalid = ! useIsDimensionsSupportValid( blockName, 'padding' );\n\n\treturn ! hasPaddingSupport( blockName ) || isDisabled || isInvalid;\n}\n\n/**\n * Inspector control panel containing the padding related configuration\n *\n * @param {Object} props\n *\n * @return {WPElement} Padding edit element.\n */\nexport function PaddingEdit( props ) {\n\tconst {\n\t\tname: blockName,\n\t\tattributes: { style },\n\t\tsetAttributes,\n\t\tonMouseOver,\n\t\tonMouseOut,\n\t} = props;\n\n\tconst spacingSizes = useSetting( 'spacing.spacingSizes' );\n\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: useSetting( 'spacing.units' ) || [\n\t\t\t'%',\n\t\t\t'px',\n\t\t\t'em',\n\t\t\t'rem',\n\t\t\t'vw',\n\t\t],\n\t} );\n\tconst sides = useCustomSides( blockName, 'padding' );\n\tconst splitOnAxis =\n\t\tsides && sides.some( ( side ) => AXIAL_SIDES.includes( side ) );\n\n\tif ( useIsPaddingDisabled( props ) ) {\n\t\treturn null;\n\t}\n\n\tconst onChange = ( next ) => {\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tspacing: {\n\t\t\t\t...style?.spacing,\n\t\t\t\tpadding: next,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\treturn Platform.select( {\n\t\tweb: (\n\t\t\t<>\n\t\t\t\t{ ( ! spacingSizes || spacingSizes?.length === 0 ) && (\n\t\t\t\t\t<BoxControl\n\t\t\t\t\t\tvalues={ style?.spacing?.padding }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Padding' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ splitOnAxis }\n\t\t\t\t\t\tonMouseOver={ onMouseOver }\n\t\t\t\t\t\tonMouseOut={ onMouseOut }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ spacingSizes?.length > 0 && (\n\t\t\t\t\t<SpacingSizesControl\n\t\t\t\t\t\tvalues={ style?.spacing?.padding }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\tlabel={ __( 'Padding' ) }\n\t\t\t\t\t\tsides={ sides }\n\t\t\t\t\t\tunits={ units }\n\t\t\t\t\t\tallowReset={ false }\n\t\t\t\t\t\tsplitOnAxis={ splitOnAxis }\n\t\t\t\t\t\tonMouseOver={ onMouseOver }\n\t\t\t\t\t\tonMouseOut={ onMouseOut }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</>\n\t\t),\n\t\tnative: null,\n\t} );\n}\n\nexport function PaddingVisualizer( { clientId, attributes, forceShow } ) {\n\tconst padding = attributes?.style?.spacing?.padding;\n\tconst style = useMemo( () => {\n\t\treturn {\n\t\t\tborderTopWidth: padding?.top\n\t\t\t\t? getSpacingPresetCssVar( padding?.top )\n\t\t\t\t: 0,\n\t\t\tborderRightWidth: padding?.right\n\t\t\t\t? getSpacingPresetCssVar( padding?.right )\n\t\t\t\t: 0,\n\t\t\tborderBottomWidth: padding?.bottom\n\t\t\t\t? getSpacingPresetCssVar( padding?.bottom )\n\t\t\t\t: 0,\n\t\t\tborderLeftWidth: padding?.left\n\t\t\t\t? getSpacingPresetCssVar( padding?.left )\n\t\t\t\t: 0,\n\t\t};\n\t}, [ padding ] );\n\n\tconst [ isActive, setIsActive ] = useState( false );\n\tconst valueRef = useRef( padding );\n\tconst timeoutRef = useRef();\n\n\tconst clearTimer = () => {\n\t\tif ( timeoutRef.current ) {\n\t\t\twindow.clearTimeout( timeoutRef.current );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! isShallowEqual( padding, valueRef.current ) && ! forceShow ) {\n\t\t\tsetIsActive( true );\n\t\t\tvalueRef.current = padding;\n\n\t\t\ttimeoutRef.current = setTimeout( () => {\n\t\t\t\tsetIsActive( false );\n\t\t\t}, 400 );\n\t\t}\n\n\t\treturn () => {\n\t\t\tsetIsActive( false );\n\t\t\tclearTimer();\n\t\t};\n\t}, [ padding, forceShow ] );\n\n\tif ( ! isActive && ! forceShow ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockPopover\n\t\t\tclientId={ clientId }\n\t\t\t__unstableCoverTarget\n\t\t\t__unstableRefreshSize={ padding }\n\t\t\t__unstablePopoverSlot=\"block-toolbar\"\n\t\t\tshift={ false }\n\t\t>\n\t\t\t<div className=\"block-editor__padding-visualizer\" style={ style } />\n\t\t</BlockPopover>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/padding.js"],"names":["useState","useRef","useEffect","useMemo","isShallowEqual","BlockPopover","getSpacingPresetCssVar","PaddingVisualizer","clientId","attributes","forceShow","padding","style","spacing","borderTopWidth","top","borderRightWidth","right","borderBottomWidth","bottom","borderLeftWidth","left","isActive","setIsActive","valueRef","timeoutRef","clearTimer","current","window","clearTimeout","setTimeout"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,MAAnB,EAA2BC,SAA3B,EAAsCC,OAAtC,QAAqD,oBAArD;AACA,OAAOC,cAAP,MAA2B,6BAA3B;AAEA;AACA;AACA;;AACA,OAAOC,YAAP,MAAyB,6BAAzB;AACA,SAASC,sBAAT,QAAuC,2CAAvC;AAEA,OAAO,SAASC,iBAAT,OAAkE;AAAA;;AAAA,MAAtC;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,UAAZ;AAAwBC,IAAAA;AAAxB,GAAsC;AACxE,QAAMC,OAAO,GAAGF,UAAH,aAAGA,UAAH,4CAAGA,UAAU,CAAEG,KAAf,+EAAG,kBAAmBC,OAAtB,0DAAG,sBAA4BF,OAA5C;AACA,QAAMC,KAAK,GAAGT,OAAO,CAAE,MAAM;AAC5B,WAAO;AACNW,MAAAA,cAAc,EAAEH,OAAO,SAAP,IAAAA,OAAO,WAAP,IAAAA,OAAO,CAAEI,GA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AAX,GAAqBG,UAAU,CAAE,MAAM;AACtCP,QAAAA,WAAW,CAAE,KAAF,CAAX;AACA,OAF8B,EAE5B,GAF4B,CAA/B;AAGA;;AAED,WAAO,MAAM;AACZA,MAAAA,WAAW,CAAE,KAAF,CAAX;AACAG,MAAAA,UAAU;AACV,KAHD;AAIA,GAdQ,EAcN,CAAEf,OAAF,EAAWD,SAAX,CAdM,CAAT;;AAgBA,MAAK,CAAEY,QAAF,IAAc,CAAEZ,SAArB,EAAiC;AAChC,WAAO,IAAP;AACA;;AAED,SACC,cAAC,YAAD;AACC,IAAA,QAAQ,EAAGF,QADZ;AAEC,IAAA,qBAAqB,MAFtB;AAGC,IAAA,qBAAqB,EAAGG,OAHzB;AAIC,IAAA,qBAAqB,EAAC,eAJvB;AAKC,IAAA,KAAK,EAAG;AALT,KAOC;AAAK,IAAA,SAAS,EAAC,kCAAf;AAAkD,IAAA,KAAK,EAAGC;AAA1D,IAPD,CADD;AAWA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useRef, useEffect, useMemo } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport BlockPopover from '../components/block-popover';\nimport { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils';\n\nexport function PaddingVisualizer( { clientId, attributes, forceShow } ) {\n\tconst padding = attributes?.style?.spacing?.padding;\n\tconst style = useMemo( () => {\n\t\treturn {\n\t\t\tborderTopWidth: padding?.top\n\t\t\t\t? getSpacingPresetCssVar( padding?.top )\n\t\t\t\t: 0,\n\t\t\tborderRightWidth: padding?.right\n\t\t\t\t? getSpacingPresetCssVar( padding?.right )\n\t\t\t\t: 0,\n\t\t\tborderBottomWidth: padding?.bottom\n\t\t\t\t? getSpacingPresetCssVar( padding?.bottom )\n\t\t\t\t: 0,\n\t\t\tborderLeftWidth: padding?.left\n\t\t\t\t? getSpacingPresetCssVar( padding?.left )\n\t\t\t\t: 0,\n\t\t};\n\t}, [ padding ] );\n\n\tconst [ isActive, setIsActive ] = useState( false );\n\tconst valueRef = useRef( padding );\n\tconst timeoutRef = useRef();\n\n\tconst clearTimer = () => {\n\t\tif ( timeoutRef.current ) {\n\t\t\twindow.clearTimeout( timeoutRef.current );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! isShallowEqual( padding, valueRef.current ) && ! forceShow ) {\n\t\t\tsetIsActive( true );\n\t\t\tvalueRef.current = padding;\n\n\t\t\ttimeoutRef.current = setTimeout( () => {\n\t\t\t\tsetIsActive( false );\n\t\t\t}, 400 );\n\t\t}\n\n\t\treturn () => {\n\t\t\tsetIsActive( false );\n\t\t\tclearTimer();\n\t\t};\n\t}, [ padding, forceShow ] );\n\n\tif ( ! isActive && ! forceShow ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockPopover\n\t\t\tclientId={ clientId }\n\t\t\t__unstableCoverTarget\n\t\t\t__unstableRefreshSize={ padding }\n\t\t\t__unstablePopoverSlot=\"block-toolbar\"\n\t\t\tshift={ false }\n\t\t>\n\t\t\t<div className=\"block-editor__padding-visualizer\" style={ style } />\n\t\t</BlockPopover>\n\t);\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import { createElement } from "@wordpress/element";
|
|
|
4
4
|
* WordPress dependencies
|
|
5
5
|
*/
|
|
6
6
|
import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
|
|
7
|
-
import { useMemo } from '@wordpress/element';
|
|
7
|
+
import { useMemo, useCallback } from '@wordpress/element';
|
|
8
8
|
/**
|
|
9
9
|
* Internal dependencies
|
|
10
10
|
*/
|
|
@@ -14,9 +14,7 @@ import { default as StylesTypographyPanel, useHasTypographyPanel } from '../comp
|
|
|
14
14
|
import { LINE_HEIGHT_SUPPORT_KEY } from './line-height';
|
|
15
15
|
import { FONT_FAMILY_SUPPORT_KEY } from './font-family';
|
|
16
16
|
import { FONT_SIZE_SUPPORT_KEY } from './font-size';
|
|
17
|
-
import {
|
|
18
|
-
import { cleanEmptyObject } from './utils';
|
|
19
|
-
import { overrideSettingsWithSupports, useSupportedStyles } from '../components/global-styles/hooks';
|
|
17
|
+
import { cleanEmptyObject, useBlockSettings } from './utils';
|
|
20
18
|
|
|
21
19
|
function omit(object, keys) {
|
|
22
20
|
return Object.fromEntries(Object.entries(object).filter(_ref => {
|
|
@@ -33,85 +31,74 @@ const FONT_WEIGHT_SUPPORT_KEY = 'typography.__experimentalFontWeight';
|
|
|
33
31
|
export const TYPOGRAPHY_SUPPORT_KEY = 'typography';
|
|
34
32
|
export const TYPOGRAPHY_SUPPORT_KEYS = [LINE_HEIGHT_SUPPORT_KEY, FONT_SIZE_SUPPORT_KEY, FONT_STYLE_SUPPORT_KEY, FONT_WEIGHT_SUPPORT_KEY, FONT_FAMILY_SUPPORT_KEY, TEXT_DECORATION_SUPPORT_KEY, TEXT_TRANSFORM_SUPPORT_KEY, LETTER_SPACING_SUPPORT_KEY];
|
|
35
33
|
|
|
34
|
+
function styleToAttributes(style) {
|
|
35
|
+
var _style$typography, _style$typography2;
|
|
36
|
+
|
|
37
|
+
const updatedStyle = { ...omit(style, ['fontFamily'])
|
|
38
|
+
};
|
|
39
|
+
const fontSizeValue = style === null || style === void 0 ? void 0 : (_style$typography = style.typography) === null || _style$typography === void 0 ? void 0 : _style$typography.fontSize;
|
|
40
|
+
const fontFamilyValue = style === null || style === void 0 ? void 0 : (_style$typography2 = style.typography) === null || _style$typography2 === void 0 ? void 0 : _style$typography2.fontFamily;
|
|
41
|
+
const fontSizeSlug = fontSizeValue !== null && fontSizeValue !== void 0 && fontSizeValue.startsWith('var:preset|font-size|') ? fontSizeValue.substring('var:preset|font-size|'.length) : undefined;
|
|
42
|
+
const fontFamilySlug = fontFamilyValue !== null && fontFamilyValue !== void 0 && fontFamilyValue.startsWith('var:preset|font-family|') ? fontFamilyValue.substring('var:preset|font-family|'.length) : undefined;
|
|
43
|
+
updatedStyle.typography = { ...omit(updatedStyle.typography, ['fontFamily']),
|
|
44
|
+
fontSize: fontSizeSlug ? undefined : fontSizeValue
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
style: cleanEmptyObject(updatedStyle),
|
|
48
|
+
fontFamily: fontFamilySlug,
|
|
49
|
+
fontSize: fontSizeSlug
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function attributesToStyle(attributes) {
|
|
54
|
+
var _attributes$style, _attributes$style2, _attributes$style2$ty;
|
|
55
|
+
|
|
56
|
+
return { ...attributes.style,
|
|
57
|
+
typography: { ...((_attributes$style = attributes.style) === null || _attributes$style === void 0 ? void 0 : _attributes$style.typography),
|
|
58
|
+
fontFamily: attributes.fontFamily ? 'var:preset|font-family|' + attributes.fontFamily : undefined,
|
|
59
|
+
fontSize: attributes.fontSize ? 'var:preset|font-size|' + attributes.fontSize : (_attributes$style2 = attributes.style) === null || _attributes$style2 === void 0 ? void 0 : (_attributes$style2$ty = _attributes$style2.typography) === null || _attributes$style2$ty === void 0 ? void 0 : _attributes$style2$ty.fontSize
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
36
64
|
function TypographyInspectorControl(_ref2) {
|
|
37
65
|
let {
|
|
38
|
-
children
|
|
66
|
+
children,
|
|
67
|
+
resetAllFilter
|
|
39
68
|
} = _ref2;
|
|
69
|
+
const attributesResetAllFilter = useCallback(attributes => {
|
|
70
|
+
const existingStyle = attributesToStyle(attributes);
|
|
71
|
+
const updatedStyle = resetAllFilter(existingStyle);
|
|
72
|
+
return { ...attributes,
|
|
73
|
+
...styleToAttributes(updatedStyle)
|
|
74
|
+
};
|
|
75
|
+
}, [resetAllFilter]);
|
|
40
76
|
return createElement(InspectorControls, {
|
|
41
|
-
group: "typography"
|
|
77
|
+
group: "typography",
|
|
78
|
+
resetAllFilter: attributesResetAllFilter
|
|
42
79
|
}, children);
|
|
43
80
|
}
|
|
44
81
|
|
|
45
|
-
function useBlockSettings(name) {
|
|
46
|
-
const fontFamilies = useSetting('typography.fontFamilies');
|
|
47
|
-
const fontSizes = useSetting('typography.fontSizes');
|
|
48
|
-
const customFontSize = useSetting('typography.customFontSize');
|
|
49
|
-
const fontStyle = useSetting('typography.fontStyle');
|
|
50
|
-
const fontWeight = useSetting('typography.fontWeight');
|
|
51
|
-
const lineHeight = useSetting('typography.lineHeight');
|
|
52
|
-
const textDecoration = useSetting('typography.textDecoration');
|
|
53
|
-
const textTransform = useSetting('typography.textTransform');
|
|
54
|
-
const letterSpacing = useSetting('typography.letterSpacing');
|
|
55
|
-
const supports = useSupportedStyles(name, null);
|
|
56
|
-
return useMemo(() => {
|
|
57
|
-
const rawSettings = {
|
|
58
|
-
typography: {
|
|
59
|
-
fontFamilies: {
|
|
60
|
-
custom: fontFamilies
|
|
61
|
-
},
|
|
62
|
-
fontSizes: {
|
|
63
|
-
custom: fontSizes
|
|
64
|
-
},
|
|
65
|
-
customFontSize,
|
|
66
|
-
fontStyle,
|
|
67
|
-
fontWeight,
|
|
68
|
-
lineHeight,
|
|
69
|
-
textDecoration,
|
|
70
|
-
textTransform,
|
|
71
|
-
letterSpacing
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
return overrideSettingsWithSupports(rawSettings, supports);
|
|
75
|
-
}, [fontFamilies, fontSizes, customFontSize, fontStyle, fontWeight, lineHeight, textDecoration, textTransform, letterSpacing, supports]);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
82
|
export function TypographyPanel(_ref3) {
|
|
79
83
|
let {
|
|
80
84
|
clientId,
|
|
81
85
|
name,
|
|
82
86
|
attributes,
|
|
83
|
-
setAttributes
|
|
87
|
+
setAttributes,
|
|
88
|
+
__unstableParentLayout
|
|
84
89
|
} = _ref3;
|
|
85
|
-
const settings = useBlockSettings(name);
|
|
90
|
+
const settings = useBlockSettings(name, __unstableParentLayout);
|
|
86
91
|
const isEnabled = useHasTypographyPanel(settings);
|
|
87
92
|
const value = useMemo(() => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
fontSize: attributes.fontSize ? 'var:preset|font-size|' + attributes.fontSize : (_attributes$style2 = attributes.style) === null || _attributes$style2 === void 0 ? void 0 : (_attributes$style2$ty = _attributes$style2.typography) === null || _attributes$style2$ty === void 0 ? void 0 : _attributes$style2$ty.fontSize
|
|
94
|
-
}
|
|
95
|
-
};
|
|
93
|
+
return attributesToStyle({
|
|
94
|
+
style: attributes.style,
|
|
95
|
+
fontFamily: attributes.fontFamily,
|
|
96
|
+
fontSize: attributes.fontSize
|
|
97
|
+
});
|
|
96
98
|
}, [attributes.style, attributes.fontSize, attributes.fontFamily]);
|
|
97
99
|
|
|
98
100
|
const onChange = newStyle => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const updatedStyle = { ...omit(newStyle, ['fontFamily'])
|
|
102
|
-
};
|
|
103
|
-
const fontSizeValue = newStyle === null || newStyle === void 0 ? void 0 : (_newStyle$typography = newStyle.typography) === null || _newStyle$typography === void 0 ? void 0 : _newStyle$typography.fontSize;
|
|
104
|
-
const fontFamilyValue = newStyle === null || newStyle === void 0 ? void 0 : (_newStyle$typography2 = newStyle.typography) === null || _newStyle$typography2 === void 0 ? void 0 : _newStyle$typography2.fontFamily;
|
|
105
|
-
const fontSizeSlug = fontSizeValue !== null && fontSizeValue !== void 0 && fontSizeValue.startsWith('var:preset|font-size|') ? fontSizeValue.substring('var:preset|font-size|'.length) : undefined;
|
|
106
|
-
const fontFamilySlug = fontFamilyValue !== null && fontFamilyValue !== void 0 && fontFamilyValue.startsWith('var:preset|font-family|') ? fontFamilyValue.substring('var:preset|font-family|'.length) : undefined;
|
|
107
|
-
updatedStyle.typography = { ...omit(updatedStyle.typography, ['fontFamily']),
|
|
108
|
-
fontSize: fontSizeSlug ? undefined : fontSizeValue
|
|
109
|
-
};
|
|
110
|
-
setAttributes({
|
|
111
|
-
style: cleanEmptyObject(updatedStyle),
|
|
112
|
-
fontFamily: fontFamilySlug,
|
|
113
|
-
fontSize: fontSizeSlug
|
|
114
|
-
});
|
|
101
|
+
setAttributes(styleToAttributes(newStyle));
|
|
115
102
|
};
|
|
116
103
|
|
|
117
104
|
if (!isEnabled) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/typography.js"],"names":["getBlockSupport","hasBlockSupport","useMemo","InspectorControls","default","StylesTypographyPanel","useHasTypographyPanel","LINE_HEIGHT_SUPPORT_KEY","FONT_FAMILY_SUPPORT_KEY","FONT_SIZE_SUPPORT_KEY","useSetting","cleanEmptyObject","overrideSettingsWithSupports","useSupportedStyles","omit","object","keys","Object","fromEntries","entries","filter","key","includes","LETTER_SPACING_SUPPORT_KEY","TEXT_TRANSFORM_SUPPORT_KEY","TEXT_DECORATION_SUPPORT_KEY","FONT_STYLE_SUPPORT_KEY","FONT_WEIGHT_SUPPORT_KEY","TYPOGRAPHY_SUPPORT_KEY","TYPOGRAPHY_SUPPORT_KEYS","TypographyInspectorControl","children","useBlockSettings","name","fontFamilies","fontSizes","customFontSize","fontStyle","fontWeight","lineHeight","textDecoration","textTransform","letterSpacing","supports","rawSettings","typography","custom","TypographyPanel","clientId","attributes","setAttributes","settings","isEnabled","value","style","fontFamily","undefined","fontSize","onChange","newStyle","updatedStyle","fontSizeValue","fontFamilyValue","fontSizeSlug","startsWith","substring","length","fontFamilySlug","defaultControls","hasTypographySupport","blockName","some"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,eAAT,EAA0BC,eAA1B,QAAiD,mBAAjD;AACA,SAASC,OAAT,QAAwB,oBAAxB;AAEA;AACA;AACA;;AACA,OAAOC,iBAAP,MAA8B,kCAA9B;AACA,SACCC,OAAO,IAAIC,qBADZ,EAECC,qBAFD,QAGO,8CAHP;AAKA,SAASC,uBAAT,QAAwC,eAAxC;AACA,SAASC,uBAAT,QAAwC,eAAxC;AACA,SAASC,qBAAT,QAAsC,aAAtC;AACA,SAASC,UAAT,QAA2B,eAA3B;AACA,SAASC,gBAAT,QAAiC,SAA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K;AAFZ,KAA1B;AAIAX,IAAAA,aAAa,CAAE;AACdI,MAAAA,KAAK,EAAE3C,gBAAgB,CAAEiD,YAAF,CADT;AAEdL,MAAAA,UAAU,EAAEY,cAFE;AAGdV,MAAAA,QAAQ,EAAEM;AAHI,KAAF,CAAb;AAKA,GAvBD;;AAyBA,MAAK,CAAEX,SAAP,EAAmB;AAClB,WAAO,IAAP;AACA;;AAED,QAAMgB,eAAe,GAAGpE,eAAe,CAAEiC,IAAF,EAAQ,CAC9CL,sBAD8C,EAE9C,+BAF8C,CAAR,CAAvC;AAKA,SACC,cAAC,qBAAD;AACC,IAAA,EAAE,EAAGE,0BADN;AAEC,IAAA,OAAO,EAAGkB,QAFX;AAGC,IAAA,IAAI,EAAGf,IAHR;AAIC,IAAA,QAAQ,EAAGkB,QAJZ;AAKC,IAAA,KAAK,EAAGE,KALT;AAMC,IAAA,QAAQ,EAAGK,QANZ;AAOC,IAAA,eAAe,EAAGU;AAPnB,IADD;AAWA;AAED,OAAO,MAAMC,oBAAoB,GAAKC,SAAF,IAAiB;AACpD,SAAOzC,uBAAuB,CAAC0C,IAAxB,CAAgClD,GAAF,IACpCpB,eAAe,CAAEqE,SAAF,EAAajD,GAAb,CADT,CAAP;AAGA,CAJM","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport InspectorControls from '../components/inspector-controls';\nimport {\n\tdefault as StylesTypographyPanel,\n\tuseHasTypographyPanel,\n} from '../components/global-styles/typography-panel';\n\nimport { LINE_HEIGHT_SUPPORT_KEY } from './line-height';\nimport { FONT_FAMILY_SUPPORT_KEY } from './font-family';\nimport { FONT_SIZE_SUPPORT_KEY } from './font-size';\nimport { useSetting } from '../components';\nimport { cleanEmptyObject } from './utils';\nimport {\n\toverrideSettingsWithSupports,\n\tuseSupportedStyles,\n} from '../components/global-styles/hooks';\n\nfunction omit( object, keys ) {\n\treturn Object.fromEntries(\n\t\tObject.entries( object ).filter( ( [ key ] ) => ! keys.includes( key ) )\n\t);\n}\n\nconst LETTER_SPACING_SUPPORT_KEY = 'typography.__experimentalLetterSpacing';\nconst TEXT_TRANSFORM_SUPPORT_KEY = 'typography.__experimentalTextTransform';\nconst TEXT_DECORATION_SUPPORT_KEY = 'typography.__experimentalTextDecoration';\nconst FONT_STYLE_SUPPORT_KEY = 'typography.__experimentalFontStyle';\nconst FONT_WEIGHT_SUPPORT_KEY = 'typography.__experimentalFontWeight';\nexport const TYPOGRAPHY_SUPPORT_KEY = 'typography';\nexport const TYPOGRAPHY_SUPPORT_KEYS = [\n\tLINE_HEIGHT_SUPPORT_KEY,\n\tFONT_SIZE_SUPPORT_KEY,\n\tFONT_STYLE_SUPPORT_KEY,\n\tFONT_WEIGHT_SUPPORT_KEY,\n\tFONT_FAMILY_SUPPORT_KEY,\n\tTEXT_DECORATION_SUPPORT_KEY,\n\tTEXT_TRANSFORM_SUPPORT_KEY,\n\tLETTER_SPACING_SUPPORT_KEY,\n];\n\nfunction TypographyInspectorControl( { children } ) {\n\treturn (\n\t\t<InspectorControls group=\"typography\">{ children }</InspectorControls>\n\t);\n}\n\nfunction useBlockSettings( name ) {\n\tconst fontFamilies = useSetting( 'typography.fontFamilies' );\n\tconst fontSizes = useSetting( 'typography.fontSizes' );\n\tconst customFontSize = useSetting( 'typography.customFontSize' );\n\tconst fontStyle = useSetting( 'typography.fontStyle' );\n\tconst fontWeight = useSetting( 'typography.fontWeight' );\n\tconst lineHeight = useSetting( 'typography.lineHeight' );\n\tconst textDecoration = useSetting( 'typography.textDecoration' );\n\tconst textTransform = useSetting( 'typography.textTransform' );\n\tconst letterSpacing = useSetting( 'typography.letterSpacing' );\n\tconst supports = useSupportedStyles( name, null );\n\n\treturn useMemo( () => {\n\t\tconst rawSettings = {\n\t\t\ttypography: {\n\t\t\t\tfontFamilies: {\n\t\t\t\t\tcustom: fontFamilies,\n\t\t\t\t},\n\t\t\t\tfontSizes: {\n\t\t\t\t\tcustom: fontSizes,\n\t\t\t\t},\n\t\t\t\tcustomFontSize,\n\t\t\t\tfontStyle,\n\t\t\t\tfontWeight,\n\t\t\t\tlineHeight,\n\t\t\t\ttextDecoration,\n\t\t\t\ttextTransform,\n\t\t\t\tletterSpacing,\n\t\t\t},\n\t\t};\n\t\treturn overrideSettingsWithSupports( rawSettings, supports );\n\t}, [\n\t\tfontFamilies,\n\t\tfontSizes,\n\t\tcustomFontSize,\n\t\tfontStyle,\n\t\tfontWeight,\n\t\tlineHeight,\n\t\ttextDecoration,\n\t\ttextTransform,\n\t\tletterSpacing,\n\t\tsupports,\n\t] );\n}\n\nexport function TypographyPanel( {\n\tclientId,\n\tname,\n\tattributes,\n\tsetAttributes,\n} ) {\n\tconst settings = useBlockSettings( name );\n\tconst isEnabled = useHasTypographyPanel( settings );\n\tconst value = useMemo( () => {\n\t\treturn {\n\t\t\t...attributes.style,\n\t\t\ttypography: {\n\t\t\t\t...attributes.style?.typography,\n\t\t\t\tfontFamily: attributes.fontFamily\n\t\t\t\t\t? 'var:preset|font-family|' + attributes.fontFamily\n\t\t\t\t\t: undefined,\n\t\t\t\tfontSize: attributes.fontSize\n\t\t\t\t\t? 'var:preset|font-size|' + attributes.fontSize\n\t\t\t\t\t: attributes.style?.typography?.fontSize,\n\t\t\t},\n\t\t};\n\t}, [ attributes.style, attributes.fontSize, attributes.fontFamily ] );\n\n\tconst onChange = ( newStyle ) => {\n\t\tconst updatedStyle = { ...omit( newStyle, [ 'fontFamily' ] ) };\n\t\tconst fontSizeValue = newStyle?.typography?.fontSize;\n\t\tconst fontFamilyValue = newStyle?.typography?.fontFamily;\n\t\tconst fontSizeSlug = fontSizeValue?.startsWith(\n\t\t\t'var:preset|font-size|'\n\t\t)\n\t\t\t? fontSizeValue.substring( 'var:preset|font-size|'.length )\n\t\t\t: undefined;\n\t\tconst fontFamilySlug = fontFamilyValue?.startsWith(\n\t\t\t'var:preset|font-family|'\n\t\t)\n\t\t\t? fontFamilyValue.substring( 'var:preset|font-family|'.length )\n\t\t\t: undefined;\n\t\tupdatedStyle.typography = {\n\t\t\t...omit( updatedStyle.typography, [ 'fontFamily' ] ),\n\t\t\tfontSize: fontSizeSlug ? undefined : fontSizeValue,\n\t\t};\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( updatedStyle ),\n\t\t\tfontFamily: fontFamilySlug,\n\t\t\tfontSize: fontSizeSlug,\n\t\t} );\n\t};\n\n\tif ( ! isEnabled ) {\n\t\treturn null;\n\t}\n\n\tconst defaultControls = getBlockSupport( name, [\n\t\tTYPOGRAPHY_SUPPORT_KEY,\n\t\t'__experimentalDefaultControls',\n\t] );\n\n\treturn (\n\t\t<StylesTypographyPanel\n\t\t\tas={ TypographyInspectorControl }\n\t\t\tpanelId={ clientId }\n\t\t\tname={ name }\n\t\t\tsettings={ settings }\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChange }\n\t\t\tdefaultControls={ defaultControls }\n\t\t/>\n\t);\n}\n\nexport const hasTypographySupport = ( blockName ) => {\n\treturn TYPOGRAPHY_SUPPORT_KEYS.some( ( key ) =>\n\t\thasBlockSupport( blockName, key )\n\t);\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/typography.js"],"names":["getBlockSupport","hasBlockSupport","useMemo","useCallback","InspectorControls","default","StylesTypographyPanel","useHasTypographyPanel","LINE_HEIGHT_SUPPORT_KEY","FONT_FAMILY_SUPPORT_KEY","FONT_SIZE_SUPPORT_KEY","cleanEmptyObject","useBlockSettings","omit","object","keys","Object","fromEntries","entries","filter","key","includes","LETTER_SPACING_SUPPORT_KEY","TEXT_TRANSFORM_SUPPORT_KEY","TEXT_DECORATION_SUPPORT_KEY","FONT_STYLE_SUPPORT_KEY","FONT_WEIGHT_SUPPORT_KEY","TYPOGRAPHY_SUPPORT_KEY","TYPOGRAPHY_SUPPORT_KEYS","styleToAttributes","style","updatedStyle","fontSizeValue","typography","fontSize","fontFamilyValue","fontFamily","fontSizeSlug","startsWith","substring","length","undefined","fontFamilySlug","attributesToStyle","attributes","TypographyInspectorControl","children","resetAllFilter","attributesResetAllFilter","existingStyle","TypographyPanel","clientId","name","setAttributes","__unstableParentLayout","settings","isEnabled","value","onChange","newStyle","defaultControls","hasTypographySupport","blockName","some"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,eAAT,EAA0BC,eAA1B,QAAiD,mBAAjD;AACA,SAASC,OAAT,EAAkBC,WAAlB,QAAqC,oBAArC;AAEA;AACA;AACA;;AACA,OAAOC,iBAAP,MAA8B,kCAA9B;AACA,SACCC,OAAO,IAAIC,qBADZ,EAECC,qBAFD,QAGO,8CAHP;AAKA,SAASC,uBAAT,QAAwC,eAAxC;AACA,SAASC,uBAAT,QAAwC,eAAxC;AACA,SAASC,qBAAT,QAAsC,aAAtC;AACA,SAASC,gBAAT,EAA2BC,gBAA3B,QAAmD,SAAnD;;AAEA,SAASC,IAAT,CAAeC,MAAf,EAAuBC,IAAvB,EAA8B;AAC7B,SAAOC,MAAM,CAACC,WAAP,CACND,MAAM,CAACE,OAAP,CAAgBJ,MAAhB,EAAyBK,MAAzB,CAAiC;AAAA,QAAE,CAAEC,GAAF,CAAF;AAAA,WAAe,CAAEL,IAAI,CAACM,QAAL,CAAeD,GAAf,CAAjB;AAAA,GAAjC,CADM,CAAP;AAGA;;AAED,MAAME,0BAA0B,GAAG,wCAAnC;AACA,MAAMC,0BAA0B,GAAG,wCAAnC;AACA,MAAMC,2BAA2B,GAAG,yCAApC;AACA,MAAMC,sBAAsB,GAAG,oCAA/B;AACA,MAAMC,uBAAuB,GAAG,qCAAhC;AACA,OAAO,MAAMC,sBAAsB,GAAG,YAA/B;AACP,OAAO,MAAMC,uBAAuB,GAAG,CACtCpB,uBADsC,EAEtCE,qBAFsC,EAGtCe,sBAHsC,EAItCC,uBAJsC,EAKtCjB,uBALsC,EAMtCe,2BANsC,EAOtCD,0BAPsC,EAQtCD,0BARsC,CAAhC;;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A,GANoB,EAMlB,CAAEU,UAAU,CAACd,KAAb,EAAoBc,UAAU,CAACV,QAA/B,EAAyCU,UAAU,CAACR,UAApD,CANkB,CAArB;;AAQA,QAAMsB,QAAQ,GAAKC,QAAF,IAAgB;AAChCN,IAAAA,aAAa,CAAExB,iBAAiB,CAAE8B,QAAF,CAAnB,CAAb;AACA,GAFD;;AAIA,MAAK,CAAEH,SAAP,EAAmB;AAClB,WAAO,IAAP;AACA;;AAED,QAAMI,eAAe,GAAG5D,eAAe,CAAEoD,IAAF,EAAQ,CAC9CzB,sBAD8C,EAE9C,+BAF8C,CAAR,CAAvC;AAKA,SACC,cAAC,qBAAD;AACC,IAAA,EAAE,EAAGkB,0BADN;AAEC,IAAA,OAAO,EAAGM,QAFX;AAGC,IAAA,IAAI,EAAGC,IAHR;AAIC,IAAA,QAAQ,EAAGG,QAJZ;AAKC,IAAA,KAAK,EAAGE,KALT;AAMC,IAAA,QAAQ,EAAGC,QANZ;AAOC,IAAA,eAAe,EAAGE;AAPnB,IADD;AAWA;AAED,OAAO,MAAMC,oBAAoB,GAAKC,SAAF,IAAiB;AACpD,SAAOlC,uBAAuB,CAACmC,IAAxB,CAAgC3C,GAAF,IACpCnB,eAAe,CAAE6D,SAAF,EAAa1C,GAAb,CADT,CAAP;AAGA,CAJM","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';\nimport { useMemo, useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport InspectorControls from '../components/inspector-controls';\nimport {\n\tdefault as StylesTypographyPanel,\n\tuseHasTypographyPanel,\n} from '../components/global-styles/typography-panel';\n\nimport { LINE_HEIGHT_SUPPORT_KEY } from './line-height';\nimport { FONT_FAMILY_SUPPORT_KEY } from './font-family';\nimport { FONT_SIZE_SUPPORT_KEY } from './font-size';\nimport { cleanEmptyObject, useBlockSettings } from './utils';\n\nfunction omit( object, keys ) {\n\treturn Object.fromEntries(\n\t\tObject.entries( object ).filter( ( [ key ] ) => ! keys.includes( key ) )\n\t);\n}\n\nconst LETTER_SPACING_SUPPORT_KEY = 'typography.__experimentalLetterSpacing';\nconst TEXT_TRANSFORM_SUPPORT_KEY = 'typography.__experimentalTextTransform';\nconst TEXT_DECORATION_SUPPORT_KEY = 'typography.__experimentalTextDecoration';\nconst FONT_STYLE_SUPPORT_KEY = 'typography.__experimentalFontStyle';\nconst FONT_WEIGHT_SUPPORT_KEY = 'typography.__experimentalFontWeight';\nexport const TYPOGRAPHY_SUPPORT_KEY = 'typography';\nexport const TYPOGRAPHY_SUPPORT_KEYS = [\n\tLINE_HEIGHT_SUPPORT_KEY,\n\tFONT_SIZE_SUPPORT_KEY,\n\tFONT_STYLE_SUPPORT_KEY,\n\tFONT_WEIGHT_SUPPORT_KEY,\n\tFONT_FAMILY_SUPPORT_KEY,\n\tTEXT_DECORATION_SUPPORT_KEY,\n\tTEXT_TRANSFORM_SUPPORT_KEY,\n\tLETTER_SPACING_SUPPORT_KEY,\n];\n\nfunction styleToAttributes( style ) {\n\tconst updatedStyle = { ...omit( style, [ 'fontFamily' ] ) };\n\tconst fontSizeValue = style?.typography?.fontSize;\n\tconst fontFamilyValue = style?.typography?.fontFamily;\n\tconst fontSizeSlug = fontSizeValue?.startsWith( 'var:preset|font-size|' )\n\t\t? fontSizeValue.substring( 'var:preset|font-size|'.length )\n\t\t: undefined;\n\tconst fontFamilySlug = fontFamilyValue?.startsWith(\n\t\t'var:preset|font-family|'\n\t)\n\t\t? fontFamilyValue.substring( 'var:preset|font-family|'.length )\n\t\t: undefined;\n\tupdatedStyle.typography = {\n\t\t...omit( updatedStyle.typography, [ 'fontFamily' ] ),\n\t\tfontSize: fontSizeSlug ? undefined : fontSizeValue,\n\t};\n\treturn {\n\t\tstyle: cleanEmptyObject( updatedStyle ),\n\t\tfontFamily: fontFamilySlug,\n\t\tfontSize: fontSizeSlug,\n\t};\n}\n\nfunction attributesToStyle( attributes ) {\n\treturn {\n\t\t...attributes.style,\n\t\ttypography: {\n\t\t\t...attributes.style?.typography,\n\t\t\tfontFamily: attributes.fontFamily\n\t\t\t\t? 'var:preset|font-family|' + attributes.fontFamily\n\t\t\t\t: undefined,\n\t\t\tfontSize: attributes.fontSize\n\t\t\t\t? 'var:preset|font-size|' + attributes.fontSize\n\t\t\t\t: attributes.style?.typography?.fontSize,\n\t\t},\n\t};\n}\n\nfunction TypographyInspectorControl( { children, resetAllFilter } ) {\n\tconst attributesResetAllFilter = useCallback(\n\t\t( attributes ) => {\n\t\t\tconst existingStyle = attributesToStyle( attributes );\n\t\t\tconst updatedStyle = resetAllFilter( existingStyle );\n\t\t\treturn {\n\t\t\t\t...attributes,\n\t\t\t\t...styleToAttributes( updatedStyle ),\n\t\t\t};\n\t\t},\n\t\t[ resetAllFilter ]\n\t);\n\n\treturn (\n\t\t<InspectorControls\n\t\t\tgroup=\"typography\"\n\t\t\tresetAllFilter={ attributesResetAllFilter }\n\t\t>\n\t\t\t{ children }\n\t\t</InspectorControls>\n\t);\n}\n\nexport function TypographyPanel( {\n\tclientId,\n\tname,\n\tattributes,\n\tsetAttributes,\n\t__unstableParentLayout,\n} ) {\n\tconst settings = useBlockSettings( name, __unstableParentLayout );\n\tconst isEnabled = useHasTypographyPanel( settings );\n\tconst value = useMemo( () => {\n\t\treturn attributesToStyle( {\n\t\t\tstyle: attributes.style,\n\t\t\tfontFamily: attributes.fontFamily,\n\t\t\tfontSize: attributes.fontSize,\n\t\t} );\n\t}, [ attributes.style, attributes.fontSize, attributes.fontFamily ] );\n\n\tconst onChange = ( newStyle ) => {\n\t\tsetAttributes( styleToAttributes( newStyle ) );\n\t};\n\n\tif ( ! isEnabled ) {\n\t\treturn null;\n\t}\n\n\tconst defaultControls = getBlockSupport( name, [\n\t\tTYPOGRAPHY_SUPPORT_KEY,\n\t\t'__experimentalDefaultControls',\n\t] );\n\n\treturn (\n\t\t<StylesTypographyPanel\n\t\t\tas={ TypographyInspectorControl }\n\t\t\tpanelId={ clientId }\n\t\t\tname={ name }\n\t\t\tsettings={ settings }\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChange }\n\t\t\tdefaultControls={ defaultControls }\n\t\t/>\n\t);\n}\n\nexport const hasTypographySupport = ( blockName ) => {\n\treturn TYPOGRAPHY_SUPPORT_KEYS.some( ( key ) =>\n\t\thasBlockSupport( blockName, key )\n\t);\n};\n"]}
|
|
@@ -7,6 +7,13 @@ import { isEmpty, mapValues, get } from 'lodash';
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { getBlockSupport } from '@wordpress/blocks';
|
|
10
|
+
import { useMemo } from '@wordpress/element';
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { useSetting } from '../components';
|
|
16
|
+
import { useSettingsForBlockElement } from '../components/global-styles/hooks';
|
|
10
17
|
/**
|
|
11
18
|
* Removed falsy values from nested object.
|
|
12
19
|
*
|
|
@@ -165,4 +172,67 @@ export function shouldSkipSerialization(blockType, featureSet, feature) {
|
|
|
165
172
|
|
|
166
173
|
return skipSerialization;
|
|
167
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Based on the block and its context, returns an object of all the block settings.
|
|
177
|
+
* This object can be passed as a prop to all the Styles UI components
|
|
178
|
+
* (TypographyPanel, DimensionsPanel...).
|
|
179
|
+
*
|
|
180
|
+
* @param {string} name Block name.
|
|
181
|
+
* @param {*} parentLayout Parent layout.
|
|
182
|
+
*
|
|
183
|
+
* @return {Object} Settings object.
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
export function useBlockSettings(name, parentLayout) {
|
|
187
|
+
const fontFamilies = useSetting('typography.fontFamilies');
|
|
188
|
+
const fontSizes = useSetting('typography.fontSizes');
|
|
189
|
+
const customFontSize = useSetting('typography.customFontSize');
|
|
190
|
+
const fontStyle = useSetting('typography.fontStyle');
|
|
191
|
+
const fontWeight = useSetting('typography.fontWeight');
|
|
192
|
+
const lineHeight = useSetting('typography.lineHeight');
|
|
193
|
+
const textDecoration = useSetting('typography.textDecoration');
|
|
194
|
+
const textTransform = useSetting('typography.textTransform');
|
|
195
|
+
const letterSpacing = useSetting('typography.letterSpacing');
|
|
196
|
+
const padding = useSetting('spacing.padding');
|
|
197
|
+
const margin = useSetting('spacing.margin');
|
|
198
|
+
const blockGap = useSetting('spacing.blockGap');
|
|
199
|
+
const spacingSizes = useSetting('spacing.spacingSizes');
|
|
200
|
+
const units = useSetting('spacing.units');
|
|
201
|
+
const minHeight = useSetting('dimensions.minHeight');
|
|
202
|
+
const layout = useSetting('layout');
|
|
203
|
+
const rawSettings = useMemo(() => {
|
|
204
|
+
return {
|
|
205
|
+
typography: {
|
|
206
|
+
fontFamilies: {
|
|
207
|
+
custom: fontFamilies
|
|
208
|
+
},
|
|
209
|
+
fontSizes: {
|
|
210
|
+
custom: fontSizes
|
|
211
|
+
},
|
|
212
|
+
customFontSize,
|
|
213
|
+
fontStyle,
|
|
214
|
+
fontWeight,
|
|
215
|
+
lineHeight,
|
|
216
|
+
textDecoration,
|
|
217
|
+
textTransform,
|
|
218
|
+
letterSpacing
|
|
219
|
+
},
|
|
220
|
+
spacing: {
|
|
221
|
+
spacingSizes: {
|
|
222
|
+
custom: spacingSizes
|
|
223
|
+
},
|
|
224
|
+
padding,
|
|
225
|
+
margin,
|
|
226
|
+
blockGap,
|
|
227
|
+
units
|
|
228
|
+
},
|
|
229
|
+
dimensions: {
|
|
230
|
+
minHeight
|
|
231
|
+
},
|
|
232
|
+
layout,
|
|
233
|
+
parentLayout
|
|
234
|
+
};
|
|
235
|
+
}, [fontFamilies, fontSizes, customFontSize, fontStyle, fontWeight, lineHeight, textDecoration, textTransform, letterSpacing, padding, margin, blockGap, spacingSizes, units, minHeight, layout, parentLayout]);
|
|
236
|
+
return useSettingsForBlockElement(rawSettings, name);
|
|
237
|
+
}
|
|
168
238
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/hooks/utils.js"],"names":["isEmpty","mapValues","get","getBlockSupport","cleanEmptyObject","object","Array","isArray","cleanedNestedObjects","Object","fromEntries","entries","filter","value","Boolean","undefined","normalizePath","path","toString","cloneObject","map","key","immutableSet","normalizedPath","newObject","reduce","acc","i","length","transformStyles","activeSupports","migrationPaths","result","source","index","results","values","every","isActive","innerBlocks","referenceBlockAttributes","attributes","returnBlock","forEach","support","styleValue","shouldSkipSerialization","blockType","featureSet","feature","skipSerialization","__experimentalSkipSerialization","includes"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,SAAlB,EAA6BC,GAA7B,QAAwC,QAAxC;AAEA;AACA;AACA;;AACA,SAASC,eAAT,QAAgC,mBAAhC;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,gBAAgB,GAAKC,MAAF,IAAc;AAC7C,MACCA,MAAM,KAAK,IAAX,IACA,OAAOA,MAAP,KAAkB,QADlB,IAEAC,KAAK,CAACC,OAAN,CAAeF,MAAf,CAHD,EAIE;AACD,WAAOA,MAAP;AACA;;AACD,QAAMG,oBAAoB,GAAGC,MAAM,CAACC,WAAP,CAC5BD,MAAM,CAACE,OAAP,CAAgBV,SAAS,CAAEI,MAAF,EAAUD,gBAAV,CAAzB,EAAwDQ,MAAxD,CACC;AAAA,QAAE,GAAIC,KAAJ,CAAF;AAAA,WAAmBC,OAAO,CAAED,KAAF,CAA1B;AAAA,GADD,CAD4B,CAA7B;AAKA,SAAOb,OAAO,CAAEQ,oBAAF,CAAP,GAAkCO,SAAlC,GAA8CP,oBAArD;AACA,CAdM;AAgBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASQ,aAAT,CAAwBC,IAAxB,EAA+B;AAC9B,MAAKX,KAAK,CAACC,OAAN,CAAeU,IAAf,CAAL,EAA6B;AAC5B,WAAOA,IAAP;AACA,GAFD,MAEO,IAAK,OAAOA,IAAP,KAAgB,QAArB,EAAgC;AAC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AAW,CAACD,UADW,EAEvBxB,IAFuB,EAGvB4B,UAHuB;AAFX,WAAd;AAQA;AACD,OAZD;AAaA;AACD,GAhBD;AAiBA,SAAOH,WAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,uBAAT,CAAkCC,SAAlC,EAA6CC,UAA7C,EAAyDC,OAAzD,EAAmE;AACzE,QAAML,OAAO,GAAGzC,eAAe,CAAE4C,SAAF,EAAaC,UAAb,CAA/B;AACA,QAAME,iBAAiB,GAAGN,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEO,+BAAnC;;AAEA,MAAK7C,KAAK,CAACC,OAAN,CAAe2C,iBAAf,CAAL,EAA0C;AACzC,WAAOA,iBAAiB,CAACE,QAAlB,CAA4BH,OAA5B,CAAP;AACA;;AAED,SAAOC,iBAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { isEmpty, mapValues, get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { getBlockSupport } from '@wordpress/blocks';\n\n/**\n * Removed falsy values from nested object.\n *\n * @param {*} object\n * @return {*} Object cleaned from falsy values\n */\nexport const cleanEmptyObject = ( object ) => {\n\tif (\n\t\tobject === null ||\n\t\ttypeof object !== 'object' ||\n\t\tArray.isArray( object )\n\t) {\n\t\treturn object;\n\t}\n\tconst cleanedNestedObjects = Object.fromEntries(\n\t\tObject.entries( mapValues( object, cleanEmptyObject ) ).filter(\n\t\t\t( [ , value ] ) => Boolean( value )\n\t\t)\n\t);\n\treturn isEmpty( cleanedNestedObjects ) ? undefined : cleanedNestedObjects;\n};\n\n/**\n * Converts a path to an array of its fragments.\n * Supports strings, numbers and arrays:\n *\n * 'foo' => [ 'foo' ]\n * 2 => [ '2' ]\n * [ 'foo', 'bar' ] => [ 'foo', 'bar' ]\n *\n * @param {string|number|Array} path Path\n * @return {Array} Normalized path.\n */\nfunction normalizePath( path ) {\n\tif ( Array.isArray( path ) ) {\n\t\treturn path;\n\t} else if ( typeof path === 'number' ) {\n\t\treturn [ path.toString() ];\n\t}\n\n\treturn [ path ];\n}\n\n/**\n * Clones an object.\n * Non-object values are returned unchanged.\n *\n * @param {*} object Object to clone.\n * @return {*} Cloned object, or original literal non-object value.\n */\nfunction cloneObject( object ) {\n\tif ( typeof object === 'object' ) {\n\t\treturn {\n\t\t\t...Object.fromEntries(\n\t\t\t\tObject.entries( object ).map( ( [ key, value ] ) => [\n\t\t\t\t\tkey,\n\t\t\t\t\tcloneObject( value ),\n\t\t\t\t] )\n\t\t\t),\n\t\t};\n\t}\n\n\treturn object;\n}\n\n/**\n * Perform an immutable set.\n * Handles nullish initial values.\n * Clones all nested objects in the specified object.\n *\n * @param {Object} object Object to set a value in.\n * @param {number|string|Array} path Path in the object to modify.\n * @param {*} value New value to set.\n * @return {Object} Cloned object with the new value set.\n */\nexport function immutableSet( object, path, value ) {\n\tconst normalizedPath = normalizePath( path );\n\tconst newObject = object ? cloneObject( object ) : {};\n\n\tnormalizedPath.reduce( ( acc, key, i ) => {\n\t\tif ( acc[ key ] === undefined ) {\n\t\t\tacc[ key ] = {};\n\t\t}\n\t\tif ( i === normalizedPath.length - 1 ) {\n\t\t\tacc[ key ] = value;\n\t\t}\n\t\treturn acc[ key ];\n\t}, newObject );\n\n\treturn newObject;\n}\n\nexport function transformStyles(\n\tactiveSupports,\n\tmigrationPaths,\n\tresult,\n\tsource,\n\tindex,\n\tresults\n) {\n\t// If there are no active supports return early.\n\tif (\n\t\tObject.values( activeSupports ?? {} ).every(\n\t\t\t( isActive ) => ! isActive\n\t\t)\n\t) {\n\t\treturn result;\n\t}\n\t// If the condition verifies we are probably in the presence of a wrapping transform\n\t// e.g: nesting paragraphs in a group or columns and in that case the styles should not be transformed.\n\tif ( results.length === 1 && result.innerBlocks.length === source.length ) {\n\t\treturn result;\n\t}\n\t// For cases where we have a transform from one block to multiple blocks\n\t// or multiple blocks to one block we apply the styles of the first source block\n\t// to the result(s).\n\tlet referenceBlockAttributes = source[ 0 ]?.attributes;\n\t// If we are in presence of transform between more than one block in the source\n\t// that has more than one block in the result\n\t// we apply the styles on source N to the result N,\n\t// if source N does not exists we do nothing.\n\tif ( results.length > 1 && source.length > 1 ) {\n\t\tif ( source[ index ] ) {\n\t\t\treferenceBlockAttributes = source[ index ]?.attributes;\n\t\t} else {\n\t\t\treturn result;\n\t\t}\n\t}\n\tlet returnBlock = result;\n\tObject.entries( activeSupports ).forEach( ( [ support, isActive ] ) => {\n\t\tif ( isActive ) {\n\t\t\tmigrationPaths[ support ].forEach( ( path ) => {\n\t\t\t\tconst styleValue = get( referenceBlockAttributes, path );\n\t\t\t\tif ( styleValue ) {\n\t\t\t\t\treturnBlock = {\n\t\t\t\t\t\t...returnBlock,\n\t\t\t\t\t\tattributes: immutableSet(\n\t\t\t\t\t\t\treturnBlock.attributes,\n\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\tstyleValue\n\t\t\t\t\t\t),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\t} );\n\treturn returnBlock;\n}\n\n/**\n * Check whether serialization of specific block support feature or set should\n * be skipped.\n *\n * @param {string|Object} blockType Block name or block type object.\n * @param {string} featureSet Name of block support feature set.\n * @param {string} feature Name of the individual feature to check.\n *\n * @return {boolean} Whether serialization should occur.\n */\nexport function shouldSkipSerialization( blockType, featureSet, feature ) {\n\tconst support = getBlockSupport( blockType, featureSet );\n\tconst skipSerialization = support?.__experimentalSkipSerialization;\n\n\tif ( Array.isArray( skipSerialization ) ) {\n\t\treturn skipSerialization.includes( feature );\n\t}\n\n\treturn skipSerialization;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/utils.js"],"names":["isEmpty","mapValues","get","getBlockSupport","useMemo","useSetting","useSettingsForBlockElement","cleanEmptyObject","object","Array","isArray","cleanedNestedObjects","Object","fromEntries","entries","filter","value","Boolean","undefined","normalizePath","path","toString","cloneObject","map","key","immutableSet","normalizedPath","newObject","reduce","acc","i","length","transformStyles","activeSupports","migrationPaths","result","source","index","results","values","every","isActive","innerBlocks","referenceBlockAttributes","attributes","returnBlock","forEach","support","styleValue","shouldSkipSerialization","blockType","featureSet","feature","skipSerialization","__experimentalSkipSerialization","includes","useBlockSettings","name","parentLayout","fontFamilies","fontSizes","customFontSize","fontStyle","fontWeight","lineHeight","textDecoration","textTransform","letterSpacing","padding","margin","blockGap","spacingSizes","units","minHeight","layout","rawSettings","typography","custom","spacing","dimensions"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,SAAlB,EAA6BC,GAA7B,QAAwC,QAAxC;AAEA;AACA;AACA;;AACA,SAASC,eAAT,QAAgC,mBAAhC;AACA,SAASC,OAAT,QAAwB,oBAAxB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,eAA3B;AACA,SAASC,0BAAT,QAA2C,mCAA3C;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,gBAAgB,GAAKC,MAAF,IAAc;AAC7C,MACCA,MAAM,KAAK,IAAX,IACA,OAAOA,MAAP,KAAkB,QADlB,IAEAC,KAAK,CAACC,OAAN,CAAeF,MAAf,CAHD,EAIE;AACD,WAAOA,MAAP;AACA;;AACD,QAAMG,oBAAoB,GAAGC,MAAM,CAACC,WAAP,CAC5BD,MAAM,CAACE,OAAP,CAAgBb,SAAS,CAAEO,MAAF,EAAUD,gBAAV,CAAzB,EAAwDQ,MAAxD,CACC;AAAA,QAAE,GAAIC,KAAJ,CAAF;AAAA,WAAmBC,OAAO,CAAED,KAAF,CAA1B;AAAA,GADD,CAD4B,CAA7B;AAKA,SAAOhB,OAAO,CAAEW,oBAAF,CAAP,GAAkCO,SAAlC,GAA8CP,oBAArD;AACA,CAdM;AAgBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASQ,aAAT,CAAwBC,IAAxB,EAA+B;AAC9B,MAAKX,KAAK,CAACC,OAAN,CAAeU,IAAf,CA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E,EAgBFC,MAhBE,EAiBFhB,YAjBE,CAhCwB,CAA3B;AAoDA,SAAOpD,0BAA0B,CAAEqE,WAAF,EAAelB,IAAf,CAAjC;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { isEmpty, mapValues, get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { getBlockSupport } from '@wordpress/blocks';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { useSetting } from '../components';\nimport { useSettingsForBlockElement } from '../components/global-styles/hooks';\n\n/**\n * Removed falsy values from nested object.\n *\n * @param {*} object\n * @return {*} Object cleaned from falsy values\n */\nexport const cleanEmptyObject = ( object ) => {\n\tif (\n\t\tobject === null ||\n\t\ttypeof object !== 'object' ||\n\t\tArray.isArray( object )\n\t) {\n\t\treturn object;\n\t}\n\tconst cleanedNestedObjects = Object.fromEntries(\n\t\tObject.entries( mapValues( object, cleanEmptyObject ) ).filter(\n\t\t\t( [ , value ] ) => Boolean( value )\n\t\t)\n\t);\n\treturn isEmpty( cleanedNestedObjects ) ? undefined : cleanedNestedObjects;\n};\n\n/**\n * Converts a path to an array of its fragments.\n * Supports strings, numbers and arrays:\n *\n * 'foo' => [ 'foo' ]\n * 2 => [ '2' ]\n * [ 'foo', 'bar' ] => [ 'foo', 'bar' ]\n *\n * @param {string|number|Array} path Path\n * @return {Array} Normalized path.\n */\nfunction normalizePath( path ) {\n\tif ( Array.isArray( path ) ) {\n\t\treturn path;\n\t} else if ( typeof path === 'number' ) {\n\t\treturn [ path.toString() ];\n\t}\n\n\treturn [ path ];\n}\n\n/**\n * Clones an object.\n * Non-object values are returned unchanged.\n *\n * @param {*} object Object to clone.\n * @return {*} Cloned object, or original literal non-object value.\n */\nfunction cloneObject( object ) {\n\tif ( typeof object === 'object' ) {\n\t\treturn {\n\t\t\t...Object.fromEntries(\n\t\t\t\tObject.entries( object ).map( ( [ key, value ] ) => [\n\t\t\t\t\tkey,\n\t\t\t\t\tcloneObject( value ),\n\t\t\t\t] )\n\t\t\t),\n\t\t};\n\t}\n\n\treturn object;\n}\n\n/**\n * Perform an immutable set.\n * Handles nullish initial values.\n * Clones all nested objects in the specified object.\n *\n * @param {Object} object Object to set a value in.\n * @param {number|string|Array} path Path in the object to modify.\n * @param {*} value New value to set.\n * @return {Object} Cloned object with the new value set.\n */\nexport function immutableSet( object, path, value ) {\n\tconst normalizedPath = normalizePath( path );\n\tconst newObject = object ? cloneObject( object ) : {};\n\n\tnormalizedPath.reduce( ( acc, key, i ) => {\n\t\tif ( acc[ key ] === undefined ) {\n\t\t\tacc[ key ] = {};\n\t\t}\n\t\tif ( i === normalizedPath.length - 1 ) {\n\t\t\tacc[ key ] = value;\n\t\t}\n\t\treturn acc[ key ];\n\t}, newObject );\n\n\treturn newObject;\n}\n\nexport function transformStyles(\n\tactiveSupports,\n\tmigrationPaths,\n\tresult,\n\tsource,\n\tindex,\n\tresults\n) {\n\t// If there are no active supports return early.\n\tif (\n\t\tObject.values( activeSupports ?? {} ).every(\n\t\t\t( isActive ) => ! isActive\n\t\t)\n\t) {\n\t\treturn result;\n\t}\n\t// If the condition verifies we are probably in the presence of a wrapping transform\n\t// e.g: nesting paragraphs in a group or columns and in that case the styles should not be transformed.\n\tif ( results.length === 1 && result.innerBlocks.length === source.length ) {\n\t\treturn result;\n\t}\n\t// For cases where we have a transform from one block to multiple blocks\n\t// or multiple blocks to one block we apply the styles of the first source block\n\t// to the result(s).\n\tlet referenceBlockAttributes = source[ 0 ]?.attributes;\n\t// If we are in presence of transform between more than one block in the source\n\t// that has more than one block in the result\n\t// we apply the styles on source N to the result N,\n\t// if source N does not exists we do nothing.\n\tif ( results.length > 1 && source.length > 1 ) {\n\t\tif ( source[ index ] ) {\n\t\t\treferenceBlockAttributes = source[ index ]?.attributes;\n\t\t} else {\n\t\t\treturn result;\n\t\t}\n\t}\n\tlet returnBlock = result;\n\tObject.entries( activeSupports ).forEach( ( [ support, isActive ] ) => {\n\t\tif ( isActive ) {\n\t\t\tmigrationPaths[ support ].forEach( ( path ) => {\n\t\t\t\tconst styleValue = get( referenceBlockAttributes, path );\n\t\t\t\tif ( styleValue ) {\n\t\t\t\t\treturnBlock = {\n\t\t\t\t\t\t...returnBlock,\n\t\t\t\t\t\tattributes: immutableSet(\n\t\t\t\t\t\t\treturnBlock.attributes,\n\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\tstyleValue\n\t\t\t\t\t\t),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\t} );\n\treturn returnBlock;\n}\n\n/**\n * Check whether serialization of specific block support feature or set should\n * be skipped.\n *\n * @param {string|Object} blockType Block name or block type object.\n * @param {string} featureSet Name of block support feature set.\n * @param {string} feature Name of the individual feature to check.\n *\n * @return {boolean} Whether serialization should occur.\n */\nexport function shouldSkipSerialization( blockType, featureSet, feature ) {\n\tconst support = getBlockSupport( blockType, featureSet );\n\tconst skipSerialization = support?.__experimentalSkipSerialization;\n\n\tif ( Array.isArray( skipSerialization ) ) {\n\t\treturn skipSerialization.includes( feature );\n\t}\n\n\treturn skipSerialization;\n}\n\n/**\n * Based on the block and its context, returns an object of all the block settings.\n * This object can be passed as a prop to all the Styles UI components\n * (TypographyPanel, DimensionsPanel...).\n *\n * @param {string} name Block name.\n * @param {*} parentLayout Parent layout.\n *\n * @return {Object} Settings object.\n */\nexport function useBlockSettings( name, parentLayout ) {\n\tconst fontFamilies = useSetting( 'typography.fontFamilies' );\n\tconst fontSizes = useSetting( 'typography.fontSizes' );\n\tconst customFontSize = useSetting( 'typography.customFontSize' );\n\tconst fontStyle = useSetting( 'typography.fontStyle' );\n\tconst fontWeight = useSetting( 'typography.fontWeight' );\n\tconst lineHeight = useSetting( 'typography.lineHeight' );\n\tconst textDecoration = useSetting( 'typography.textDecoration' );\n\tconst textTransform = useSetting( 'typography.textTransform' );\n\tconst letterSpacing = useSetting( 'typography.letterSpacing' );\n\tconst padding = useSetting( 'spacing.padding' );\n\tconst margin = useSetting( 'spacing.margin' );\n\tconst blockGap = useSetting( 'spacing.blockGap' );\n\tconst spacingSizes = useSetting( 'spacing.spacingSizes' );\n\tconst units = useSetting( 'spacing.units' );\n\tconst minHeight = useSetting( 'dimensions.minHeight' );\n\tconst layout = useSetting( 'layout' );\n\n\tconst rawSettings = useMemo( () => {\n\t\treturn {\n\t\t\ttypography: {\n\t\t\t\tfontFamilies: {\n\t\t\t\t\tcustom: fontFamilies,\n\t\t\t\t},\n\t\t\t\tfontSizes: {\n\t\t\t\t\tcustom: fontSizes,\n\t\t\t\t},\n\t\t\t\tcustomFontSize,\n\t\t\t\tfontStyle,\n\t\t\t\tfontWeight,\n\t\t\t\tlineHeight,\n\t\t\t\ttextDecoration,\n\t\t\t\ttextTransform,\n\t\t\t\tletterSpacing,\n\t\t\t},\n\t\t\tspacing: {\n\t\t\t\tspacingSizes: {\n\t\t\t\t\tcustom: spacingSizes,\n\t\t\t\t},\n\t\t\t\tpadding,\n\t\t\t\tmargin,\n\t\t\t\tblockGap,\n\t\t\t\tunits,\n\t\t\t},\n\t\t\tdimensions: {\n\t\t\t\tminHeight,\n\t\t\t},\n\t\t\tlayout,\n\t\t\tparentLayout,\n\t\t};\n\t}, [\n\t\tfontFamilies,\n\t\tfontSizes,\n\t\tcustomFontSize,\n\t\tfontStyle,\n\t\tfontWeight,\n\t\tlineHeight,\n\t\ttextDecoration,\n\t\ttextTransform,\n\t\tletterSpacing,\n\t\tpadding,\n\t\tmargin,\n\t\tblockGap,\n\t\tspacingSizes,\n\t\tunits,\n\t\tminHeight,\n\t\tlayout,\n\t\tparentLayout,\n\t] );\n\n\treturn useSettingsForBlockElement( rawSettings, name );\n}\n"]}
|