UNPKG

@wordpress/block-library

Version:
105 lines (104 loc) • 3.63 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_i18n = require("@wordpress/i18n"); let _wordpress_components = require("@wordpress/components"); let _wordpress_block_editor = require("@wordpress/block-editor"); let ___utils_style_state_js = require("../utils/style-state.cjs"); let ___lock_unlock_ts = require("../lock-unlock.cjs"); let react_jsx_runtime = require("react/jsx-runtime"); // packages/block-library/src/post-featured-image/dimension-controls.jsx const { DimensionsTool } = (0, ___lock_unlock_ts.unlock)(_wordpress_block_editor.privateApis); const DEFAULT_SCALE = "cover"; const DIMENSION_KEYS = [ "aspectRatio", "width", "height", "scale" ]; const scaleOptions = [ { value: "cover", label: (0, _wordpress_i18n._x)("Cover", "Scale option for Image dimension control"), help: (0, _wordpress_i18n.__)("Image is scaled and cropped to fill the entire space without being distorted.") }, { value: "contain", label: (0, _wordpress_i18n._x)("Contain", "Scale option for Image dimension control"), help: (0, _wordpress_i18n.__)("Image is scaled to fill the space without clipping nor distorting.") }, { value: "fill", label: (0, _wordpress_i18n._x)("Fill", "Scale option for Image dimension control"), help: (0, _wordpress_i18n.__)("Image will be stretched and distorted to completely fill the space.") } ]; const DimensionControls = ({ clientId, attributes, setAttributes, selectedStyleState, hasSelectedStyleState = false }) => { const { style } = attributes; const selectedStyleStateKey = (0, ___utils_style_state_js.getStyleStateKey)(selectedStyleState); const activeAspectRatio = (0, ___utils_style_state_js.getActiveDimensionValue)({ attributes, selectedState: selectedStyleState, hasSelectedStyleState, attributeKey: "aspectRatio" }); const activeWidth = (0, ___utils_style_state_js.getActiveDimensionValue)({ attributes, selectedState: selectedStyleState, hasSelectedStyleState, attributeKey: "width" }); const activeHeight = (0, ___utils_style_state_js.getActiveDimensionValue)({ attributes, selectedState: selectedStyleState, hasSelectedStyleState, attributeKey: "height" }); const activeScale = (0, ___utils_style_state_js.getActiveDimensionValue)({ attributes, selectedState: selectedStyleState, hasSelectedStyleState, attributeKey: "scale", styleKey: "objectFit" }); const [availableUnits] = (0, _wordpress_block_editor.useSettings)("spacing.units"); const units = (0, _wordpress_components.__experimentalUseCustomUnits)({ availableUnits: availableUnits || [ "px", "%", "vw", "em", "rem" ] }); const setDimensionAttributes = (nextDimensions) => { const nextImageDimensions = { ...nextDimensions, width: !nextDimensions.width && nextDimensions.height ? "auto" : nextDimensions.width }; setAttributes((0, ___utils_style_state_js.getDimensionUpdateAttributes)({ style, selectedState: selectedStyleState, hasSelectedStyleState, nextDimensions: nextImageDimensions, dimensionKeyMap: { scale: "objectFit" }, dimensionKeys: DIMENSION_KEYS })); }; return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DimensionsTool, { panelId: clientId, value: { aspectRatio: activeAspectRatio, width: activeWidth, height: activeHeight, scale: activeScale }, onChange: setDimensionAttributes, defaultScale: DEFAULT_SCALE, defaultAspectRatio: "auto", scaleOptions, unitsOptions: units }, selectedStyleStateKey); }; exports.default = DimensionControls; //# sourceMappingURL=dimension-controls.cjs.map