Skip to content

Commit

Permalink
Mobile: fix getPxFromCssUnit circular dependency (#57045)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Dec 14, 2023
1 parent 829e69c commit 30b5e03
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 14 deletions.
9 changes: 3 additions & 6 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,16 +539,13 @@ _Returns_

### getPxFromCssUnit

Returns the px value of a cssUnit. The memoized version of getPxFromCssUnit;

_Parameters_
> **Deprecated**
- _cssUnit_ `string`:
- _options_ `Object`:
This function was accidentially exposed for mobile/native usage.

_Returns_

- `string`: returns the cssUnit value in a simple px format.
- `string`: Empty string.

### getSpacingPresetCssVar

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { TextInput, Platform, Dimensions } from 'react-native';
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { RichText, getPxFromCssUnit } from '@wordpress/block-editor';
import { getPxFromCssUnit } from '@wordpress/components';

/**
* Internal dependencies
*/
import RichText from '../rich-text';

/**
* Internal dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
showUserSuggestions,
showXpostSuggestions,
} from '@wordpress/react-native-bridge';
import { BlockFormatControls, getPxFromCssUnit } from '@wordpress/block-editor';
import { BlockFormatControls } from '@wordpress/block-editor';
import { getPxFromCssUnit } from '@wordpress/components';
import { Component } from '@wordpress/element';
import {
compose,
Expand Down
8 changes: 8 additions & 0 deletions packages/block-editor/src/utils/get-px-from-css-unit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* This function was accidentially exposed for mobile/native usage.
*
* @deprecated
*
* @return {string} Empty string.
*/
export default () => '';
2 changes: 1 addition & 1 deletion packages/block-editor/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { default as transformStyles } from './transform-styles';
export * from './block-variation-transforms';
export { default as getPxFromCssUnit } from './parse-css-unit-to-px';
export { default as getPxFromCssUnit } from './get-px-from-css-unit';
6 changes: 4 additions & 2 deletions packages/block-library/src/spacer/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import { View, useWindowDimensions } from 'react-native';
/**
* WordPress dependencies
*/
import { useConvertUnitToMobile } from '@wordpress/components';
import {
useConvertUnitToMobile,
getPxFromCssUnit,
} from '@wordpress/components';
import { withPreferredColorScheme } from '@wordpress/compose';
import {
InspectorControls,
isValueSpacingPreset,
useSettings,
getCustomValueFromPreset,
getPxFromCssUnit,
} from '@wordpress/block-editor';
import { useEffect } from '@wordpress/element';

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/font-size-picker/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { useState } from '@wordpress/element';
import { Icon, chevronRight, check } from '@wordpress/icons';
import { __, sprintf } from '@wordpress/i18n';
import { BottomSheet } from '@wordpress/components';
import { getPxFromCssUnit } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import { default as getPxFromCssUnit } from '../mobile/utils/get-px-from-css-unit';
import { default as UnitControl, useCustomUnits } from '../unit-control';
import styles from './style.scss';

Expand Down
1 change: 1 addition & 0 deletions packages/components/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export {
ALIGNMENT_BREAKPOINTS,
alignmentHelpers,
} from './mobile/utils/alignments';
export { default as getPxFromCssUnit } from './mobile/utils/get-px-from-css-unit';

// Hooks.
export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { colord } from 'colord';
* WordPress dependencies
*/
import {
getPxFromCssUnit,
useSettings,
useMultipleOriginColorsAndGradients,
SETTINGS_DEFAULTS,
Expand All @@ -19,6 +18,7 @@ import { usePreferredColorSchemeStyle } from '@wordpress/compose';
/**
* Internal dependencies
*/
import { default as getPxFromCssUnit } from '../utils/get-px-from-css-unit';
import { useGlobalStyles } from './index.native';

export const BLOCK_STYLE_ATTRIBUTES = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {
default as memoizedGetPxFromCssUnit,
getPxFromCssUnit,
} from '../parse-css-unit-to-px';
} from '../get-px-from-css-unit';

describe( 'getPxFromCssUnit', () => {
// Absolute units.
Expand Down

0 comments on commit 30b5e03

Please sign in to comment.