UNPKG

@wordpress/editor

Version:
64 lines (63 loc) 1.72 kB
// packages/editor/src/hooks/push-changes-to-global-styles/use-review-rows.js import { useMemo } from "@wordpress/element"; import { getStyle, getValueFromVariable } from "@wordpress/global-styles-engine"; import { getStyleLabel } from "./style-labels.mjs"; import { formatStyleValue, formatBorderShorthand, formatBorderRadius, formatSpacingShorthand, formatBlockGap } from "./format-style-value.mjs"; function formatReviewValue(format, value, resolve) { if (format === "border") { return formatBorderShorthand(value); } if (format === "borderRadius") { return formatBorderRadius(value); } if (format === "spacing") { return formatSpacingShorthand(value, resolve); } if (format === "blockGap") { return formatBlockGap(value, resolve); } return formatStyleValue(value); } function useReviewRows(rows, merged, name) { return useMemo(() => { const resolve = (value) => getValueFromVariable(merged, name, value); return rows.map((row) => { const currentValue = getStyle( merged, row.primaryPath.join("."), name, // Keep preset values encoded (e.g. `var:preset|color|vivid-red`) // so they show by name, matching the new value. false ); return { ...row, label: getStyleLabel(row.primaryPath), currentValue, formattedCurrentValue: formatReviewValue( row.format, currentValue, resolve ), formattedNewValue: formatReviewValue( row.format, row.newValue, resolve ) }; }); }, [rows, merged, name]); } export { useReviewRows }; //# sourceMappingURL=use-review-rows.mjs.map