@wordpress/block-editor
Version:
8 lines (7 loc) • 2.38 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/hooks/gap.js"],
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { getSpacingPresetCssVar } from '../components/spacing-sizes-control/utils';\n\n/**\n * Returns a BoxControl object value from a given blockGap style value.\n * The string check is for backwards compatibility before Gutenberg supported\n * split gap values (row and column) and the value was a string n + unit.\n *\n * @param {?string | ?Object} blockGapValue A block gap string or axial object value, e.g., '10px' or { top: '10px', left: '10px'}.\n * @return {Object|null} A value to pass to the BoxControl component.\n */\nexport function getGapBoxControlValueFromStyle( blockGapValue ) {\n\tif ( ! blockGapValue ) {\n\t\treturn null;\n\t}\n\n\tconst isValueString = typeof blockGapValue === 'string';\n\treturn {\n\t\ttop: isValueString ? blockGapValue : blockGapValue?.top,\n\t\tleft: isValueString ? blockGapValue : blockGapValue?.left,\n\t};\n}\n\n/**\n * Returns a CSS value for the `gap` property from a given blockGap style.\n *\n * @param {?string | ?Object} blockGapValue A block gap string or axial object value, e.g., '10px' or { top: '10px', left: '10px'}.\n * @param {?string} defaultValue A default gap value.\n * @return {string|null} The concatenated gap value (row and column).\n */\nexport function getGapCSSValue( blockGapValue, defaultValue = '0' ) {\n\tconst blockGapBoxControlValue =\n\t\tgetGapBoxControlValueFromStyle( blockGapValue );\n\tif ( ! blockGapBoxControlValue ) {\n\t\treturn null;\n\t}\n\n\tconst row =\n\t\tgetSpacingPresetCssVar( blockGapBoxControlValue?.top ) || defaultValue;\n\tconst column =\n\t\tgetSpacingPresetCssVar( blockGapBoxControlValue?.left ) || defaultValue;\n\n\treturn row === column ? row : `${ row } ${ column }`;\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAuC;AAUhC,SAAS,+BAAgC,eAAgB;AAC/D,MAAK,CAAE,eAAgB;AACtB,WAAO;AAAA,EACR;AAEA,QAAM,gBAAgB,OAAO,kBAAkB;AAC/C,SAAO;AAAA,IACN,KAAK,gBAAgB,gBAAgB,eAAe;AAAA,IACpD,MAAM,gBAAgB,gBAAgB,eAAe;AAAA,EACtD;AACD;AASO,SAAS,eAAgB,eAAe,eAAe,KAAM;AACnE,QAAM,0BACL,+BAAgC,aAAc;AAC/C,MAAK,CAAE,yBAA0B;AAChC,WAAO;AAAA,EACR;AAEA,QAAM,UACL,qCAAwB,yBAAyB,GAAI,KAAK;AAC3D,QAAM,aACL,qCAAwB,yBAAyB,IAAK,KAAK;AAE5D,SAAO,QAAQ,SAAS,MAAM,GAAI,GAAI,IAAK,MAAO;AACnD;",
"names": []
}