@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 4.83 kB
Source Map (JSON)
{"version":3,"file":"dimension-controls.mjs","names":["blockEditorPrivateApis","useCustomUnits"],"sources":["../../src/post-featured-image/dimension-controls.jsx"],"sourcesContent":["import { __, _x } from '@wordpress/i18n';\nimport { __experimentalUseCustomUnits as useCustomUnits } from '@wordpress/components';\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tuseSettings,\n} from '@wordpress/block-editor';\nimport {\n\tgetActiveDimensionValue,\n\tgetDimensionUpdateAttributes,\n\tgetStyleStateKey,\n} from '../utils/style-state';\nimport { unlock } from '../lock-unlock';\n\nconst { DimensionsTool } = unlock( blockEditorPrivateApis );\n\nconst DEFAULT_SCALE = 'cover';\nconst DIMENSION_KEYS = [ 'aspectRatio', 'width', 'height', 'scale' ];\n\nconst scaleOptions = [\n\t{\n\t\tvalue: 'cover',\n\t\tlabel: _x( 'Cover', 'Scale option for Image dimension control' ),\n\t\thelp: __(\n\t\t\t'Image is scaled and cropped to fill the entire space without being distorted.'\n\t\t),\n\t},\n\t{\n\t\tvalue: 'contain',\n\t\tlabel: _x( 'Contain', 'Scale option for Image dimension control' ),\n\t\thelp: __(\n\t\t\t'Image is scaled to fill the space without clipping nor distorting.'\n\t\t),\n\t},\n\t{\n\t\tvalue: 'fill',\n\t\tlabel: _x( 'Fill', 'Scale option for Image dimension control' ),\n\t\thelp: __(\n\t\t\t'Image will be stretched and distorted to completely fill the space.'\n\t\t),\n\t},\n];\n\nconst DimensionControls = ( {\n\tclientId,\n\tattributes,\n\tsetAttributes,\n\tselectedStyleState,\n\thasSelectedStyleState = false,\n} ) => {\n\tconst { style } = attributes;\n\tconst selectedStyleStateKey = getStyleStateKey( selectedStyleState );\n\tconst activeAspectRatio = getActiveDimensionValue( {\n\t\tattributes,\n\t\tselectedState: selectedStyleState,\n\t\thasSelectedStyleState,\n\t\tattributeKey: 'aspectRatio',\n\t} );\n\tconst activeWidth = getActiveDimensionValue( {\n\t\tattributes,\n\t\tselectedState: selectedStyleState,\n\t\thasSelectedStyleState,\n\t\tattributeKey: 'width',\n\t} );\n\tconst activeHeight = getActiveDimensionValue( {\n\t\tattributes,\n\t\tselectedState: selectedStyleState,\n\t\thasSelectedStyleState,\n\t\tattributeKey: 'height',\n\t} );\n\tconst activeScale = getActiveDimensionValue( {\n\t\tattributes,\n\t\tselectedState: selectedStyleState,\n\t\thasSelectedStyleState,\n\t\tattributeKey: 'scale',\n\t\tstyleKey: 'objectFit',\n\t} );\n\n\tconst [ availableUnits ] = useSettings( 'spacing.units' );\n\tconst units = useCustomUnits( {\n\t\tavailableUnits: availableUnits || [ 'px', '%', 'vw', 'em', 'rem' ],\n\t} );\n\n\tconst setDimensionAttributes = ( nextDimensions ) => {\n\t\tconst nextImageDimensions = {\n\t\t\t...nextDimensions,\n\t\t\twidth:\n\t\t\t\t! nextDimensions.width && nextDimensions.height\n\t\t\t\t\t? 'auto'\n\t\t\t\t\t: nextDimensions.width,\n\t\t};\n\n\t\tsetAttributes(\n\t\t\tgetDimensionUpdateAttributes( {\n\t\t\t\tstyle,\n\t\t\t\tselectedState: selectedStyleState,\n\t\t\t\thasSelectedStyleState,\n\t\t\t\tnextDimensions: nextImageDimensions,\n\t\t\t\tdimensionKeyMap: { scale: 'objectFit' },\n\t\t\t\tdimensionKeys: DIMENSION_KEYS,\n\t\t\t} )\n\t\t);\n\t};\n\n\treturn (\n\t\t<DimensionsTool\n\t\t\tkey={ selectedStyleStateKey }\n\t\t\tpanelId={ clientId }\n\t\t\tvalue={ {\n\t\t\t\taspectRatio: activeAspectRatio,\n\t\t\t\twidth: activeWidth,\n\t\t\t\theight: activeHeight,\n\t\t\t\tscale: activeScale,\n\t\t\t} }\n\t\t\tonChange={ setDimensionAttributes }\n\t\t\tdefaultScale={ DEFAULT_SCALE }\n\t\t\tdefaultAspectRatio=\"auto\"\n\t\t\tscaleOptions={ scaleOptions }\n\t\t\tunitsOptions={ units }\n\t\t/>\n\t);\n};\n\nexport default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