@wordpress/block-editor 15.6.1 → 15.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/background-image-control/index.js +2 -2
- package/build/components/background-image-control/index.js.map +2 -2
- package/build/components/block-quick-navigation/index.js +1 -0
- package/build/components/block-quick-navigation/index.js.map +2 -2
- package/build/components/block-toolbar/switch-section-style.js +2 -5
- package/build/components/block-toolbar/switch-section-style.js.map +2 -2
- package/build/components/global-styles/border-panel.js +2 -1
- package/build/components/global-styles/border-panel.js.map +2 -2
- package/build/components/global-styles/color-panel.js +2 -1
- package/build/components/global-styles/color-panel.js.map +2 -2
- package/build/components/global-styles/dimensions-panel.js +3 -2
- package/build/components/global-styles/dimensions-panel.js.map +2 -2
- package/build/components/global-styles/filters-panel.js +2 -1
- package/build/components/global-styles/filters-panel.js.map +2 -2
- package/build/components/global-styles/hooks.js +0 -179
- package/build/components/global-styles/hooks.js.map +3 -3
- package/build/components/global-styles/index.js +0 -29
- package/build/components/global-styles/index.js.map +2 -2
- package/build/components/global-styles/typography-panel.js +2 -1
- package/build/components/global-styles/typography-panel.js.map +2 -2
- package/build/components/global-styles/typography-utils.js +2 -49
- package/build/components/global-styles/typography-utils.js.map +2 -2
- package/build/components/global-styles/utils.js +0 -396
- package/build/components/global-styles/utils.js.map +3 -3
- package/build/components/inserter/media-tab/media-tab.js +33 -1
- package/build/components/inserter/media-tab/media-tab.js.map +3 -3
- package/build/components/inserter/tips.js +0 -2
- package/build/components/inserter/tips.js.map +2 -2
- package/build/components/media-placeholder/index.js +31 -1
- package/build/components/media-placeholder/index.js.map +3 -3
- package/build/components/media-replace-flow/index.js +29 -1
- package/build/components/media-replace-flow/index.js.map +3 -3
- package/build/components/{global-styles/context.js → media-upload-modal/index.js} +8 -23
- package/build/components/media-upload-modal/index.js.map +7 -0
- package/build/hooks/allowed-blocks.js +3 -8
- package/build/hooks/allowed-blocks.js.map +3 -3
- package/build/hooks/block-style-variation.js +10 -23
- package/build/hooks/block-style-variation.js.map +2 -2
- package/build/hooks/duotone.js +3 -3
- package/build/hooks/duotone.js.map +2 -2
- package/build/hooks/fit-text.js +2 -2
- package/build/hooks/fit-text.js.map +2 -2
- package/build/hooks/font-size.js +2 -2
- package/build/hooks/font-size.js.map +2 -2
- package/build/hooks/use-typography-props.js +2 -2
- package/build/hooks/use-typography-props.js.map +2 -2
- package/build/private-apis.js +3 -1
- package/build/private-apis.js.map +3 -3
- package/build-module/components/background-image-control/index.js +1 -1
- package/build-module/components/background-image-control/index.js.map +2 -2
- package/build-module/components/block-quick-navigation/index.js +1 -0
- package/build-module/components/block-quick-navigation/index.js.map +2 -2
- package/build-module/components/block-toolbar/switch-section-style.js +2 -5
- package/build-module/components/block-toolbar/switch-section-style.js.map +2 -2
- package/build-module/components/global-styles/border-panel.js +2 -1
- package/build-module/components/global-styles/border-panel.js.map +2 -2
- package/build-module/components/global-styles/color-panel.js +2 -1
- package/build-module/components/global-styles/color-panel.js.map +2 -2
- package/build-module/components/global-styles/dimensions-panel.js +2 -1
- package/build-module/components/global-styles/dimensions-panel.js.map +2 -2
- package/build-module/components/global-styles/filters-panel.js +2 -1
- package/build-module/components/global-styles/filters-panel.js.map +2 -2
- package/build-module/components/global-styles/hooks.js +1 -167
- package/build-module/components/global-styles/hooks.js.map +2 -2
- package/build-module/components/global-styles/index.js +1 -29
- package/build-module/components/global-styles/index.js.map +2 -2
- package/build-module/components/global-styles/typography-panel.js +2 -1
- package/build-module/components/global-styles/typography-panel.js.map +2 -2
- package/build-module/components/global-styles/typography-utils.js +1 -49
- package/build-module/components/global-styles/typography-utils.js.map +2 -2
- package/build-module/components/global-styles/utils.js +0 -372
- package/build-module/components/global-styles/utils.js.map +2 -2
- package/build-module/components/inserter/media-tab/media-tab.js +34 -2
- package/build-module/components/inserter/media-tab/media-tab.js.map +2 -2
- package/build-module/components/inserter/tips.js +0 -2
- package/build-module/components/inserter/tips.js.map +2 -2
- package/build-module/components/media-placeholder/index.js +31 -1
- package/build-module/components/media-placeholder/index.js.map +2 -2
- package/build-module/components/media-replace-flow/index.js +29 -1
- package/build-module/components/media-replace-flow/index.js.map +2 -2
- package/build-module/components/media-upload-modal/index.js +7 -0
- package/build-module/components/media-upload-modal/index.js.map +7 -0
- package/build-module/hooks/allowed-blocks.js +3 -8
- package/build-module/hooks/allowed-blocks.js.map +2 -2
- package/build-module/hooks/block-style-variation.js +8 -25
- package/build-module/hooks/block-style-variation.js.map +2 -2
- package/build-module/hooks/duotone.js +3 -3
- package/build-module/hooks/duotone.js.map +2 -2
- package/build-module/hooks/fit-text.js +2 -2
- package/build-module/hooks/fit-text.js.map +2 -2
- package/build-module/hooks/font-size.js +1 -1
- package/build-module/hooks/font-size.js.map +2 -2
- package/build-module/hooks/use-typography-props.js +1 -1
- package/build-module/hooks/use-typography-props.js.map +2 -2
- package/build-module/private-apis.js +3 -1
- package/build-module/private-apis.js.map +2 -2
- package/build-style/style-rtl.css +10 -6
- package/build-style/style.css +10 -6
- package/package.json +36 -35
- package/src/components/background-image-control/index.js +1 -1
- package/src/components/block-card/style.scss +1 -1
- package/src/components/block-navigation/style.scss +1 -1
- package/src/components/block-quick-navigation/index.js +1 -0
- package/src/components/block-quick-navigation/style.scss +5 -0
- package/src/components/block-switcher/style.scss +1 -1
- package/src/components/block-toolbar/switch-section-style.js +2 -5
- package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
- package/src/components/global-styles/border-panel.js +2 -1
- package/src/components/global-styles/color-panel.js +2 -1
- package/src/components/global-styles/color-panel.native.js +1 -1
- package/src/components/global-styles/dimensions-panel.js +2 -1
- package/src/components/global-styles/filters-panel.js +2 -1
- package/src/components/global-styles/hooks.js +1 -200
- package/src/components/global-styles/index.js +1 -17
- package/src/components/global-styles/test/typography-utils.js +0 -806
- package/src/components/global-styles/typography-panel.js +2 -1
- package/src/components/global-styles/typography-utils.js +0 -133
- package/src/components/global-styles/utils.js +0 -568
- package/src/components/inserter/media-tab/media-tab.js +44 -2
- package/src/components/inserter/style.scss +2 -2
- package/src/components/inserter/tips.js +0 -2
- package/src/components/media-placeholder/index.js +41 -1
- package/src/components/media-replace-flow/index.js +39 -1
- package/src/components/media-upload-modal/index.js +18 -0
- package/src/components/multi-selection-inspector/style.scss +1 -1
- package/src/hooks/allowed-blocks.js +3 -11
- package/src/hooks/block-style-variation.js +8 -28
- package/src/hooks/duotone.js +3 -3
- package/src/hooks/fit-text.js +2 -2
- package/src/hooks/font-size.js +1 -1
- package/src/hooks/use-typography-props.js +1 -1
- package/src/private-apis.js +2 -0
- package/src/style.scss +1 -0
- package/tsconfig.json +2 -0
- package/build/components/global-styles/context.js.map +0 -7
- package/build/components/global-styles/get-block-css-selector.js +0 -78
- package/build/components/global-styles/get-block-css-selector.js.map +0 -7
- package/build/components/global-styles/get-global-styles-changes.js +0 -216
- package/build/components/global-styles/get-global-styles-changes.js.map +0 -7
- package/build/components/global-styles/use-global-styles-output.js +0 -998
- package/build/components/global-styles/use-global-styles-output.js.map +0 -7
- package/build-module/components/global-styles/context.js +0 -17
- package/build-module/components/global-styles/context.js.map +0 -7
- package/build-module/components/global-styles/get-block-css-selector.js +0 -54
- package/build-module/components/global-styles/get-block-css-selector.js.map +0 -7
- package/build-module/components/global-styles/get-global-styles-changes.js +0 -182
- package/build-module/components/global-styles/get-global-styles-changes.js.map +0 -7
- package/build-module/components/global-styles/use-global-styles-output.js +0 -979
- package/build-module/components/global-styles/use-global-styles-output.js.map +0 -7
- package/src/components/global-styles/README.md +0 -190
- package/src/components/global-styles/context.js +0 -16
- package/src/components/global-styles/get-block-css-selector.js +0 -114
- package/src/components/global-styles/get-global-styles-changes.js +0 -252
- package/src/components/global-styles/test/get-global-styles-changes.js +0 -290
- package/src/components/global-styles/test/use-global-styles-output.js +0 -1131
- package/src/components/global-styles/test/utils.js +0 -499
- package/src/components/global-styles/use-global-styles-output.js +0 -1487
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/global-styles/typography-utils.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * The fluid utilities must match the backend equivalent.\n * See: gutenberg_get_typography_font_size_value() in lib/block-supports/typography.php\n * ---------------------------------------------------------------\n */\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetComputedFluidTypographyValue,\n\tgetTypographyValueAndUnit,\n} from '../font-sizes/fluid-utils';\nimport { getFontStylesAndWeights } from '../../utils/get-font-styles-and-weights';\n\n/**\n * @typedef {Object} FluidPreset\n * @property {string|undefined} max A maximum font size value.\n * @property {?string|undefined} min A minimum font size value.\n */\n\n/**\n * @typedef {Object} Preset\n * @property {?string|?number} size A default font size.\n * @property {string} name A font size name, displayed in the UI.\n * @property {string} slug A font size slug\n * @property {boolean|FluidPreset|undefined} fluid Specifies the minimum and maximum font size value of a fluid font size.\n */\n\n/**\n * @typedef {Object} TypographySettings\n * @property {?string} minViewportWidth Minimum viewport size from which type will have fluidity. Optional if size is specified.\n * @property {?string} maxViewportWidth Maximum size up to which type will have fluidity. Optional if size is specified.\n * @property {?number} scaleFactor A scale factor to determine how fast a font scales within boundaries. Optional.\n * @property {?number} minFontSizeFactor How much to scale defaultFontSize by to derive minimumFontSize. Optional.\n * @property {?string} minFontSize The smallest a calculated font size may be. Optional.\n */\n\n/**\n * Returns a font-size value based on a given font-size preset.\n * Takes into account fluid typography parameters and attempts to return a css formula depending on available, valid values.\n *\n * The Core PHP equivalent is wp_get_typography_font_size_value().\n *\n * @param {Preset} preset\n * @param {Object} settings\n * @param {boolean|TypographySettings} settings.typography.fluid Whether fluid typography is enabled, and, optionally, fluid font size options.\n * @param {?Object} settings.typography.layout Layout options.\n *\n * @return {string|*} A font-size value or the value of preset.size.\n */\nexport function getTypographyFontSizeValue( preset, settings ) {\n\tconst { size: defaultSize } = preset;\n\n\t/*\n\t * Catch falsy values and 0/'0'. Fluid calculations cannot be performed on `0`.\n\t * Also return early when a preset font size explicitly disables fluid typography with `false`.\n\t */\n\tif ( ! defaultSize || '0' === defaultSize || false === preset?.fluid ) {\n\t\treturn defaultSize;\n\t}\n\n\t/*\n\t * Return early when fluid typography is disabled in the settings, and there\n\t * are no local settings to enable it for the individual preset.\n\t *\n\t * If this condition isn't met, either the settings or individual preset settings\n\t * have enabled fluid typography.\n\t */\n\tif (\n\t\t! isFluidTypographyEnabled( settings?.typography ) &&\n\t\t! isFluidTypographyEnabled( preset )\n\t) {\n\t\treturn defaultSize;\n\t}\n\n\tlet fluidTypographySettings =\n\t\tgetFluidTypographyOptionsFromSettings( settings );\n\tfluidTypographySettings =\n\t\ttypeof fluidTypographySettings?.fluid === 'object'\n\t\t\t? fluidTypographySettings?.fluid\n\t\t\t: {};\n\n\tconst fluidFontSizeValue = getComputedFluidTypographyValue( {\n\t\tminimumFontSize: preset?.fluid?.min,\n\t\tmaximumFontSize: preset?.fluid?.max,\n\t\tfontSize: defaultSize,\n\t\tminimumFontSizeLimit: fluidTypographySettings?.minFontSize,\n\t\tmaximumViewportWidth: fluidTypographySettings?.maxViewportWidth,\n\t\tminimumViewportWidth: fluidTypographySettings?.minViewportWidth,\n\t} );\n\n\tif ( !! fluidFontSizeValue ) {\n\t\treturn fluidFontSizeValue;\n\t}\n\n\treturn defaultSize;\n}\n\nfunction isFluidTypographyEnabled( typographySettings ) {\n\tconst fluidSettings = typographySettings?.fluid;\n\treturn (\n\t\ttrue === fluidSettings ||\n\t\t( fluidSettings &&\n\t\t\ttypeof fluidSettings === 'object' &&\n\t\t\tObject.keys( fluidSettings ).length > 0 )\n\t);\n}\n\n/**\n * Returns fluid typography settings from theme.json setting object.\n *\n * @param {Object} settings Theme.json settings\n * @param {Object} settings.typography Theme.json typography settings\n * @param {Object} settings.layout Theme.json layout settings\n * @return {TypographySettings} Fluid typography settings\n */\nexport function getFluidTypographyOptionsFromSettings( settings ) {\n\tconst typographySettings = settings?.typography;\n\tconst layoutSettings = settings?.layout;\n\tconst defaultMaxViewportWidth = getTypographyValueAndUnit(\n\t\tlayoutSettings?.wideSize\n\t)\n\t\t? layoutSettings?.wideSize\n\t\t: null;\n\treturn isFluidTypographyEnabled( typographySettings ) &&\n\t\tdefaultMaxViewportWidth\n\t\t? {\n\t\t\t\tfluid: {\n\t\t\t\t\tmaxViewportWidth: defaultMaxViewportWidth,\n\t\t\t\t\t...typographySettings.fluid,\n\t\t\t\t},\n\t\t }\n\t\t: {\n\t\t\t\tfluid: typographySettings?.fluid,\n\t\t };\n}\n\n/**\n * Returns an object of merged font families and the font faces from the selected font family\n * based on the theme.json settings object and the currently selected font family.\n *\n * @param {Object} settings Theme.json settings.\n * @param {string} selectedFontFamily Decoded font family string.\n * @return {Object} Merged font families and font faces from the selected font family.\n */\nexport function getMergedFontFamiliesAndFontFamilyFaces(\n\tsettings,\n\tselectedFontFamily\n) {\n\tconst fontFamiliesFromSettings = settings?.typography?.fontFamilies;\n\n\tconst fontFamilies = [ 'default', 'theme', 'custom' ].flatMap(\n\t\t( key ) => fontFamiliesFromSettings?.[ key ] ?? []\n\t);\n\n\tconst fontFamilyFaces =\n\t\tfontFamilies.find(\n\t\t\t( family ) => family.fontFamily === selectedFontFamily\n\t\t)?.fontFace ?? [];\n\n\treturn { fontFamilies, fontFamilyFaces };\n}\n\n/**\n * Returns the nearest font weight value from the available font weight list based on the new font weight.\n * The nearest font weight is the one with the smallest difference from the new font weight.\n *\n * @param {Array} availableFontWeights Array of available font weights.\n * @param {string} newFontWeightValue New font weight value.\n * @return {string} Nearest font weight.\n */\nexport function findNearestFontWeight(\n\tavailableFontWeights,\n\tnewFontWeightValue\n) {\n\tnewFontWeightValue =\n\t\t'number' === typeof newFontWeightValue\n\t\t\t? newFontWeightValue.toString()\n\t\t\t: newFontWeightValue;\n\tif ( ! newFontWeightValue || typeof newFontWeightValue !== 'string' ) {\n\t\treturn '';\n\t}\n\n\tif ( ! availableFontWeights || availableFontWeights.length === 0 ) {\n\t\treturn newFontWeightValue;\n\t}\n\n\tconst nearestFontWeight = availableFontWeights?.reduce(\n\t\t( nearest, { value: fw } ) => {\n\t\t\tconst currentDiff = Math.abs(\n\t\t\t\tparseInt( fw ) - parseInt( newFontWeightValue )\n\t\t\t);\n\t\t\tconst nearestDiff = Math.abs(\n\t\t\t\tparseInt( nearest ) - parseInt( newFontWeightValue )\n\t\t\t);\n\t\t\treturn currentDiff < nearestDiff ? fw : nearest;\n\t\t},\n\t\tavailableFontWeights[ 0 ]?.value\n\t);\n\n\treturn nearestFontWeight;\n}\n\n/**\n * Returns the nearest font style based on the new font style.\n * Defaults to an empty string if the new font style is not valid or available.\n *\n * @param {Array} availableFontStyles Array of available font weights.\n * @param {string} newFontStyleValue New font style value.\n * @return {string} Nearest font style or an empty string.\n */\nexport function findNearestFontStyle( availableFontStyles, newFontStyleValue ) {\n\tif ( typeof newFontStyleValue !== 'string' || ! newFontStyleValue ) {\n\t\treturn '';\n\t}\n\n\tconst validStyles = [ 'normal', 'italic', 'oblique' ];\n\tif ( ! validStyles.includes( newFontStyleValue ) ) {\n\t\treturn '';\n\t}\n\n\tif (\n\t\t! availableFontStyles ||\n\t\tavailableFontStyles.length === 0 ||\n\t\tavailableFontStyles.find(\n\t\t\t( style ) => style.value === newFontStyleValue\n\t\t)\n\t) {\n\t\treturn newFontStyleValue;\n\t}\n\n\tif (\n\t\tnewFontStyleValue === 'oblique' &&\n\t\t! availableFontStyles.find( ( style ) => style.value === 'oblique' )\n\t) {\n\t\treturn 'italic';\n\t}\n\n\treturn '';\n}\n\n/**\n * Returns the nearest font style and weight based on the available font family faces and the new font style and weight.\n *\n * @param {Array} fontFamilyFaces Array of available font family faces.\n * @param {string} fontStyle New font style. Defaults to previous value.\n * @param {string} fontWeight New font weight. Defaults to previous value.\n * @return {Object} Nearest font style and font weight.\n */\nexport function findNearestStyleAndWeight(\n\tfontFamilyFaces,\n\tfontStyle,\n\tfontWeight\n) {\n\tlet nearestFontStyle = fontStyle;\n\tlet nearestFontWeight = fontWeight;\n\n\tconst { fontStyles, fontWeights, combinedStyleAndWeightOptions } =\n\t\tgetFontStylesAndWeights( fontFamilyFaces );\n\n\t// Check if the new font style and weight are available in the font family faces.\n\tconst hasFontStyle = fontStyles?.some(\n\t\t( { value: fs } ) => fs === fontStyle\n\t);\n\tconst hasFontWeight = fontWeights?.some(\n\t\t( { value: fw } ) => fw?.toString() === fontWeight?.toString()\n\t);\n\n\tif ( ! hasFontStyle ) {\n\t\t/*\n\t\t * Default to italic if oblique is not available.\n\t\t * Or find the nearest font style based on the nearest font weight.\n\t\t */\n\t\tnearestFontStyle = fontStyle\n\t\t\t? findNearestFontStyle( fontStyles, fontStyle )\n\t\t\t: combinedStyleAndWeightOptions?.find(\n\t\t\t\t\t( option ) =>\n\t\t\t\t\t\toption.style.fontWeight ===\n\t\t\t\t\t\tfindNearestFontWeight( fontWeights, fontWeight )\n\t\t\t )?.style?.fontStyle;\n\t}\n\n\tif ( ! hasFontWeight ) {\n\t\t/*\n\t\t * Find the nearest font weight based on available weights.\n\t\t * Or find the nearest font weight based on the nearest font style.\n\t\t */\n\t\tnearestFontWeight = fontWeight\n\t\t\t? findNearestFontWeight( fontWeights, fontWeight )\n\t\t\t: combinedStyleAndWeightOptions?.find(\n\t\t\t\t\t( option ) =>\n\t\t\t\t\t\toption.style.fontStyle ===\n\t\t\t\t\t\t( nearestFontStyle || fontStyle )\n\t\t\t )?.style?.fontWeight;\n\t}\n\n\treturn { nearestFontStyle, nearestFontWeight };\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { getFontStylesAndWeights } from '../../utils/get-font-styles-and-weights';\n\n/**\n * Returns an object of merged font families and the font faces from the selected font family\n * based on the theme.json settings object and the currently selected font family.\n *\n * @param {Object} settings Theme.json settings.\n * @param {string} selectedFontFamily Decoded font family string.\n * @return {Object} Merged font families and font faces from the selected font family.\n */\nexport function getMergedFontFamiliesAndFontFamilyFaces(\n\tsettings,\n\tselectedFontFamily\n) {\n\tconst fontFamiliesFromSettings = settings?.typography?.fontFamilies;\n\n\tconst fontFamilies = [ 'default', 'theme', 'custom' ].flatMap(\n\t\t( key ) => fontFamiliesFromSettings?.[ key ] ?? []\n\t);\n\n\tconst fontFamilyFaces =\n\t\tfontFamilies.find(\n\t\t\t( family ) => family.fontFamily === selectedFontFamily\n\t\t)?.fontFace ?? [];\n\n\treturn { fontFamilies, fontFamilyFaces };\n}\n\n/**\n * Returns the nearest font weight value from the available font weight list based on the new font weight.\n * The nearest font weight is the one with the smallest difference from the new font weight.\n *\n * @param {Array} availableFontWeights Array of available font weights.\n * @param {string} newFontWeightValue New font weight value.\n * @return {string} Nearest font weight.\n */\nexport function findNearestFontWeight(\n\tavailableFontWeights,\n\tnewFontWeightValue\n) {\n\tnewFontWeightValue =\n\t\t'number' === typeof newFontWeightValue\n\t\t\t? newFontWeightValue.toString()\n\t\t\t: newFontWeightValue;\n\tif ( ! newFontWeightValue || typeof newFontWeightValue !== 'string' ) {\n\t\treturn '';\n\t}\n\n\tif ( ! availableFontWeights || availableFontWeights.length === 0 ) {\n\t\treturn newFontWeightValue;\n\t}\n\n\tconst nearestFontWeight = availableFontWeights?.reduce(\n\t\t( nearest, { value: fw } ) => {\n\t\t\tconst currentDiff = Math.abs(\n\t\t\t\tparseInt( fw ) - parseInt( newFontWeightValue )\n\t\t\t);\n\t\t\tconst nearestDiff = Math.abs(\n\t\t\t\tparseInt( nearest ) - parseInt( newFontWeightValue )\n\t\t\t);\n\t\t\treturn currentDiff < nearestDiff ? fw : nearest;\n\t\t},\n\t\tavailableFontWeights[ 0 ]?.value\n\t);\n\n\treturn nearestFontWeight;\n}\n\n/**\n * Returns the nearest font style based on the new font style.\n * Defaults to an empty string if the new font style is not valid or available.\n *\n * @param {Array} availableFontStyles Array of available font weights.\n * @param {string} newFontStyleValue New font style value.\n * @return {string} Nearest font style or an empty string.\n */\nexport function findNearestFontStyle( availableFontStyles, newFontStyleValue ) {\n\tif ( typeof newFontStyleValue !== 'string' || ! newFontStyleValue ) {\n\t\treturn '';\n\t}\n\n\tconst validStyles = [ 'normal', 'italic', 'oblique' ];\n\tif ( ! validStyles.includes( newFontStyleValue ) ) {\n\t\treturn '';\n\t}\n\n\tif (\n\t\t! availableFontStyles ||\n\t\tavailableFontStyles.length === 0 ||\n\t\tavailableFontStyles.find(\n\t\t\t( style ) => style.value === newFontStyleValue\n\t\t)\n\t) {\n\t\treturn newFontStyleValue;\n\t}\n\n\tif (\n\t\tnewFontStyleValue === 'oblique' &&\n\t\t! availableFontStyles.find( ( style ) => style.value === 'oblique' )\n\t) {\n\t\treturn 'italic';\n\t}\n\n\treturn '';\n}\n\n/**\n * Returns the nearest font style and weight based on the available font family faces and the new font style and weight.\n *\n * @param {Array} fontFamilyFaces Array of available font family faces.\n * @param {string} fontStyle New font style. Defaults to previous value.\n * @param {string} fontWeight New font weight. Defaults to previous value.\n * @return {Object} Nearest font style and font weight.\n */\nexport function findNearestStyleAndWeight(\n\tfontFamilyFaces,\n\tfontStyle,\n\tfontWeight\n) {\n\tlet nearestFontStyle = fontStyle;\n\tlet nearestFontWeight = fontWeight;\n\n\tconst { fontStyles, fontWeights, combinedStyleAndWeightOptions } =\n\t\tgetFontStylesAndWeights( fontFamilyFaces );\n\n\t// Check if the new font style and weight are available in the font family faces.\n\tconst hasFontStyle = fontStyles?.some(\n\t\t( { value: fs } ) => fs === fontStyle\n\t);\n\tconst hasFontWeight = fontWeights?.some(\n\t\t( { value: fw } ) => fw?.toString() === fontWeight?.toString()\n\t);\n\n\tif ( ! hasFontStyle ) {\n\t\t/*\n\t\t * Default to italic if oblique is not available.\n\t\t * Or find the nearest font style based on the nearest font weight.\n\t\t */\n\t\tnearestFontStyle = fontStyle\n\t\t\t? findNearestFontStyle( fontStyles, fontStyle )\n\t\t\t: combinedStyleAndWeightOptions?.find(\n\t\t\t\t\t( option ) =>\n\t\t\t\t\t\toption.style.fontWeight ===\n\t\t\t\t\t\tfindNearestFontWeight( fontWeights, fontWeight )\n\t\t\t )?.style?.fontStyle;\n\t}\n\n\tif ( ! hasFontWeight ) {\n\t\t/*\n\t\t * Find the nearest font weight based on available weights.\n\t\t * Or find the nearest font weight based on the nearest font style.\n\t\t */\n\t\tnearestFontWeight = fontWeight\n\t\t\t? findNearestFontWeight( fontWeights, fontWeight )\n\t\t\t: combinedStyleAndWeightOptions?.find(\n\t\t\t\t\t( option ) =>\n\t\t\t\t\t\toption.style.fontStyle ===\n\t\t\t\t\t\t( nearestFontStyle || fontStyle )\n\t\t\t )?.style?.fontWeight;\n\t}\n\n\treturn { nearestFontStyle, nearestFontWeight };\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,+BAA+B;AAUjC,SAAS,wCACf,UACA,oBACC;AACD,QAAM,2BAA2B,UAAU,YAAY;AAEvD,QAAM,eAAe,CAAE,WAAW,SAAS,QAAS,EAAE;AAAA,IACrD,CAAE,QAAS,2BAA4B,GAAI,KAAK,CAAC;AAAA,EAClD;AAEA,QAAM,kBACL,aAAa;AAAA,IACZ,CAAE,WAAY,OAAO,eAAe;AAAA,EACrC,GAAG,YAAY,CAAC;AAEjB,SAAO,EAAE,cAAc,gBAAgB;AACxC;AAUO,SAAS,sBACf,sBACA,oBACC;AACD,uBACC,aAAa,OAAO,qBACjB,mBAAmB,SAAS,IAC5B;AACJ,MAAK,CAAE,sBAAsB,OAAO,uBAAuB,UAAW;AACrE,WAAO;AAAA,EACR;AAEA,MAAK,CAAE,wBAAwB,qBAAqB,WAAW,GAAI;AAClE,WAAO;AAAA,EACR;AAEA,QAAM,oBAAoB,sBAAsB;AAAA,IAC/C,CAAE,SAAS,EAAE,OAAO,GAAG,MAAO;AAC7B,YAAM,cAAc,KAAK;AAAA,QACxB,SAAU,EAAG,IAAI,SAAU,kBAAmB;AAAA,MAC/C;AACA,YAAM,cAAc,KAAK;AAAA,QACxB,SAAU,OAAQ,IAAI,SAAU,kBAAmB;AAAA,MACpD;AACA,aAAO,cAAc,cAAc,KAAK;AAAA,IACzC;AAAA,IACA,qBAAsB,CAAE,GAAG;AAAA,EAC5B;AAEA,SAAO;AACR;AAUO,SAAS,qBAAsB,qBAAqB,mBAAoB;AAC9E,MAAK,OAAO,sBAAsB,YAAY,CAAE,mBAAoB;AACnE,WAAO;AAAA,EACR;AAEA,QAAM,cAAc,CAAE,UAAU,UAAU,SAAU;AACpD,MAAK,CAAE,YAAY,SAAU,iBAAkB,GAAI;AAClD,WAAO;AAAA,EACR;AAEA,MACC,CAAE,uBACF,oBAAoB,WAAW,KAC/B,oBAAoB;AAAA,IACnB,CAAE,UAAW,MAAM,UAAU;AAAA,EAC9B,GACC;AACD,WAAO;AAAA,EACR;AAEA,MACC,sBAAsB,aACtB,CAAE,oBAAoB,KAAM,CAAE,UAAW,MAAM,UAAU,SAAU,GAClE;AACD,WAAO;AAAA,EACR;AAEA,SAAO;AACR;AAUO,SAAS,0BACf,iBACA,WACA,YACC;AACD,MAAI,mBAAmB;AACvB,MAAI,oBAAoB;AAExB,QAAM,EAAE,YAAY,aAAa,8BAA8B,IAC9D,wBAAyB,eAAgB;AAG1C,QAAM,eAAe,YAAY;AAAA,IAChC,CAAE,EAAE,OAAO,GAAG,MAAO,OAAO;AAAA,EAC7B;AACA,QAAM,gBAAgB,aAAa;AAAA,IAClC,CAAE,EAAE,OAAO,GAAG,MAAO,IAAI,SAAS,MAAM,YAAY,SAAS;AAAA,EAC9D;AAEA,MAAK,CAAE,cAAe;AAKrB,uBAAmB,YAChB,qBAAsB,YAAY,SAAU,IAC5C,+BAA+B;AAAA,MAC/B,CAAE,WACD,OAAO,MAAM,eACb,sBAAuB,aAAa,UAAW;AAAA,IAChD,GAAG,OAAO;AAAA,EACd;AAEA,MAAK,CAAE,eAAgB;AAKtB,wBAAoB,aACjB,sBAAuB,aAAa,UAAW,IAC/C,+BAA+B;AAAA,MAC/B,CAAE,WACD,OAAO,MAAM,eACX,oBAAoB;AAAA,IACvB,GAAG,OAAO;AAAA,EACd;AAEA,SAAO,EAAE,kBAAkB,kBAAkB;AAC9C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,133 +1,4 @@
|
|
|
1
|
-
import fastDeepEqual from "fast-deep-equal/es6";
|
|
2
1
|
import { useViewportMatch } from "@wordpress/compose";
|
|
3
|
-
import { getCSSValueFromRawStyle } from "@wordpress/style-engine";
|
|
4
|
-
import { getTypographyFontSizeValue } from "./typography-utils";
|
|
5
|
-
import { getValueFromObjectPath } from "../../utils/object";
|
|
6
|
-
const ROOT_BLOCK_SELECTOR = "body";
|
|
7
|
-
const ROOT_CSS_PROPERTIES_SELECTOR = ":root";
|
|
8
|
-
const PRESET_METADATA = [
|
|
9
|
-
{
|
|
10
|
-
path: ["color", "palette"],
|
|
11
|
-
valueKey: "color",
|
|
12
|
-
cssVarInfix: "color",
|
|
13
|
-
classes: [
|
|
14
|
-
{ classSuffix: "color", propertyName: "color" },
|
|
15
|
-
{
|
|
16
|
-
classSuffix: "background-color",
|
|
17
|
-
propertyName: "background-color"
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
classSuffix: "border-color",
|
|
21
|
-
propertyName: "border-color"
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
path: ["color", "gradients"],
|
|
27
|
-
valueKey: "gradient",
|
|
28
|
-
cssVarInfix: "gradient",
|
|
29
|
-
classes: [
|
|
30
|
-
{
|
|
31
|
-
classSuffix: "gradient-background",
|
|
32
|
-
propertyName: "background"
|
|
33
|
-
}
|
|
34
|
-
]
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
path: ["color", "duotone"],
|
|
38
|
-
valueKey: "colors",
|
|
39
|
-
cssVarInfix: "duotone",
|
|
40
|
-
valueFunc: ({ slug }) => `url( '#wp-duotone-${slug}' )`,
|
|
41
|
-
classes: []
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
path: ["shadow", "presets"],
|
|
45
|
-
valueKey: "shadow",
|
|
46
|
-
cssVarInfix: "shadow",
|
|
47
|
-
classes: []
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
path: ["typography", "fontSizes"],
|
|
51
|
-
valueFunc: (preset, settings) => getTypographyFontSizeValue(preset, settings),
|
|
52
|
-
valueKey: "size",
|
|
53
|
-
cssVarInfix: "font-size",
|
|
54
|
-
classes: [{ classSuffix: "font-size", propertyName: "font-size" }]
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
path: ["typography", "fontFamilies"],
|
|
58
|
-
valueKey: "fontFamily",
|
|
59
|
-
cssVarInfix: "font-family",
|
|
60
|
-
classes: [
|
|
61
|
-
{ classSuffix: "font-family", propertyName: "font-family" }
|
|
62
|
-
]
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
path: ["spacing", "spacingSizes"],
|
|
66
|
-
valueKey: "size",
|
|
67
|
-
cssVarInfix: "spacing",
|
|
68
|
-
classes: []
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
path: ["border", "radiusSizes"],
|
|
72
|
-
valueKey: "size",
|
|
73
|
-
cssVarInfix: "border-radius",
|
|
74
|
-
classes: []
|
|
75
|
-
}
|
|
76
|
-
];
|
|
77
|
-
const STYLE_PATH_TO_CSS_VAR_INFIX = {
|
|
78
|
-
"color.background": "color",
|
|
79
|
-
"color.text": "color",
|
|
80
|
-
"filter.duotone": "duotone",
|
|
81
|
-
"elements.link.color.text": "color",
|
|
82
|
-
"elements.link.:hover.color.text": "color",
|
|
83
|
-
"elements.link.typography.fontFamily": "font-family",
|
|
84
|
-
"elements.link.typography.fontSize": "font-size",
|
|
85
|
-
"elements.button.color.text": "color",
|
|
86
|
-
"elements.button.color.background": "color",
|
|
87
|
-
"elements.caption.color.text": "color",
|
|
88
|
-
"elements.button.typography.fontFamily": "font-family",
|
|
89
|
-
"elements.button.typography.fontSize": "font-size",
|
|
90
|
-
"elements.heading.color": "color",
|
|
91
|
-
"elements.heading.color.background": "color",
|
|
92
|
-
"elements.heading.typography.fontFamily": "font-family",
|
|
93
|
-
"elements.heading.gradient": "gradient",
|
|
94
|
-
"elements.heading.color.gradient": "gradient",
|
|
95
|
-
"elements.h1.color": "color",
|
|
96
|
-
"elements.h1.color.background": "color",
|
|
97
|
-
"elements.h1.typography.fontFamily": "font-family",
|
|
98
|
-
"elements.h1.color.gradient": "gradient",
|
|
99
|
-
"elements.h2.color": "color",
|
|
100
|
-
"elements.h2.color.background": "color",
|
|
101
|
-
"elements.h2.typography.fontFamily": "font-family",
|
|
102
|
-
"elements.h2.color.gradient": "gradient",
|
|
103
|
-
"elements.h3.color": "color",
|
|
104
|
-
"elements.h3.color.background": "color",
|
|
105
|
-
"elements.h3.typography.fontFamily": "font-family",
|
|
106
|
-
"elements.h3.color.gradient": "gradient",
|
|
107
|
-
"elements.h4.color": "color",
|
|
108
|
-
"elements.h4.color.background": "color",
|
|
109
|
-
"elements.h4.typography.fontFamily": "font-family",
|
|
110
|
-
"elements.h4.color.gradient": "gradient",
|
|
111
|
-
"elements.h5.color": "color",
|
|
112
|
-
"elements.h5.color.background": "color",
|
|
113
|
-
"elements.h5.typography.fontFamily": "font-family",
|
|
114
|
-
"elements.h5.color.gradient": "gradient",
|
|
115
|
-
"elements.h6.color": "color",
|
|
116
|
-
"elements.h6.color.background": "color",
|
|
117
|
-
"elements.h6.typography.fontFamily": "font-family",
|
|
118
|
-
"elements.h6.color.gradient": "gradient",
|
|
119
|
-
"color.gradient": "gradient",
|
|
120
|
-
shadow: "shadow",
|
|
121
|
-
"typography.fontSize": "font-size",
|
|
122
|
-
"typography.fontFamily": "font-family"
|
|
123
|
-
};
|
|
124
|
-
const STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE = {
|
|
125
|
-
"color.background": "backgroundColor",
|
|
126
|
-
"color.text": "textColor",
|
|
127
|
-
"color.gradient": "gradient",
|
|
128
|
-
"typography.fontSize": "fontSize",
|
|
129
|
-
"typography.fontFamily": "fontFamily"
|
|
130
|
-
};
|
|
131
2
|
function useToolsPanelDropdownMenuProps() {
|
|
132
3
|
const isMobile = useViewportMatch("medium", "<");
|
|
133
4
|
return !isMobile ? {
|
|
@@ -138,143 +9,6 @@ function useToolsPanelDropdownMenuProps() {
|
|
|
138
9
|
}
|
|
139
10
|
} : {};
|
|
140
11
|
}
|
|
141
|
-
function findInPresetsBy(features, blockName, presetPath, presetProperty, presetValueValue) {
|
|
142
|
-
const orderedPresetsByOrigin = [
|
|
143
|
-
getValueFromObjectPath(features, [
|
|
144
|
-
"blocks",
|
|
145
|
-
blockName,
|
|
146
|
-
...presetPath
|
|
147
|
-
]),
|
|
148
|
-
getValueFromObjectPath(features, presetPath)
|
|
149
|
-
];
|
|
150
|
-
for (const presetByOrigin of orderedPresetsByOrigin) {
|
|
151
|
-
if (presetByOrigin) {
|
|
152
|
-
const origins = ["custom", "theme", "default"];
|
|
153
|
-
for (const origin of origins) {
|
|
154
|
-
const presets = presetByOrigin[origin];
|
|
155
|
-
if (presets) {
|
|
156
|
-
const presetObject = presets.find(
|
|
157
|
-
(preset) => preset[presetProperty] === presetValueValue
|
|
158
|
-
);
|
|
159
|
-
if (presetObject) {
|
|
160
|
-
if (presetProperty === "slug") {
|
|
161
|
-
return presetObject;
|
|
162
|
-
}
|
|
163
|
-
const highestPresetObjectWithSameSlug = findInPresetsBy(
|
|
164
|
-
features,
|
|
165
|
-
blockName,
|
|
166
|
-
presetPath,
|
|
167
|
-
"slug",
|
|
168
|
-
presetObject.slug
|
|
169
|
-
);
|
|
170
|
-
if (highestPresetObjectWithSameSlug[presetProperty] === presetObject[presetProperty]) {
|
|
171
|
-
return presetObject;
|
|
172
|
-
}
|
|
173
|
-
return void 0;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
function getPresetVariableFromValue(features, blockName, variableStylePath, presetPropertyValue) {
|
|
181
|
-
if (!presetPropertyValue) {
|
|
182
|
-
return presetPropertyValue;
|
|
183
|
-
}
|
|
184
|
-
const cssVarInfix = STYLE_PATH_TO_CSS_VAR_INFIX[variableStylePath];
|
|
185
|
-
const metadata = PRESET_METADATA.find(
|
|
186
|
-
(data) => data.cssVarInfix === cssVarInfix
|
|
187
|
-
);
|
|
188
|
-
if (!metadata) {
|
|
189
|
-
return presetPropertyValue;
|
|
190
|
-
}
|
|
191
|
-
const { valueKey, path } = metadata;
|
|
192
|
-
const presetObject = findInPresetsBy(
|
|
193
|
-
features,
|
|
194
|
-
blockName,
|
|
195
|
-
path,
|
|
196
|
-
valueKey,
|
|
197
|
-
presetPropertyValue
|
|
198
|
-
);
|
|
199
|
-
if (!presetObject) {
|
|
200
|
-
return presetPropertyValue;
|
|
201
|
-
}
|
|
202
|
-
return `var:preset|${cssVarInfix}|${presetObject.slug}`;
|
|
203
|
-
}
|
|
204
|
-
function getValueFromPresetVariable(features, blockName, variable, [presetType, slug]) {
|
|
205
|
-
const metadata = PRESET_METADATA.find(
|
|
206
|
-
(data) => data.cssVarInfix === presetType
|
|
207
|
-
);
|
|
208
|
-
if (!metadata) {
|
|
209
|
-
return variable;
|
|
210
|
-
}
|
|
211
|
-
const presetObject = findInPresetsBy(
|
|
212
|
-
features.settings,
|
|
213
|
-
blockName,
|
|
214
|
-
metadata.path,
|
|
215
|
-
"slug",
|
|
216
|
-
slug
|
|
217
|
-
);
|
|
218
|
-
if (presetObject) {
|
|
219
|
-
const { valueKey } = metadata;
|
|
220
|
-
const result = presetObject[valueKey];
|
|
221
|
-
return getValueFromVariable(features, blockName, result);
|
|
222
|
-
}
|
|
223
|
-
return variable;
|
|
224
|
-
}
|
|
225
|
-
function getValueFromCustomVariable(features, blockName, variable, path) {
|
|
226
|
-
const result = getValueFromObjectPath(features.settings, [
|
|
227
|
-
"blocks",
|
|
228
|
-
blockName,
|
|
229
|
-
"custom",
|
|
230
|
-
...path
|
|
231
|
-
]) ?? getValueFromObjectPath(features.settings, ["custom", ...path]);
|
|
232
|
-
if (!result) {
|
|
233
|
-
return variable;
|
|
234
|
-
}
|
|
235
|
-
return getValueFromVariable(features, blockName, result);
|
|
236
|
-
}
|
|
237
|
-
function getValueFromVariable(features, blockName, variable) {
|
|
238
|
-
if (!variable || typeof variable !== "string") {
|
|
239
|
-
if (typeof variable?.ref === "string") {
|
|
240
|
-
variable = getValueFromObjectPath(features, variable.ref);
|
|
241
|
-
if (!variable || !!variable?.ref) {
|
|
242
|
-
return variable;
|
|
243
|
-
}
|
|
244
|
-
} else {
|
|
245
|
-
return variable;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
const USER_VALUE_PREFIX = "var:";
|
|
249
|
-
const THEME_VALUE_PREFIX = "var(--wp--";
|
|
250
|
-
const THEME_VALUE_SUFFIX = ")";
|
|
251
|
-
let parsedVar;
|
|
252
|
-
if (variable.startsWith(USER_VALUE_PREFIX)) {
|
|
253
|
-
parsedVar = variable.slice(USER_VALUE_PREFIX.length).split("|");
|
|
254
|
-
} else if (variable.startsWith(THEME_VALUE_PREFIX) && variable.endsWith(THEME_VALUE_SUFFIX)) {
|
|
255
|
-
parsedVar = variable.slice(THEME_VALUE_PREFIX.length, -THEME_VALUE_SUFFIX.length).split("--");
|
|
256
|
-
} else {
|
|
257
|
-
return variable;
|
|
258
|
-
}
|
|
259
|
-
const [type, ...path] = parsedVar;
|
|
260
|
-
if (type === "preset") {
|
|
261
|
-
return getValueFromPresetVariable(
|
|
262
|
-
features,
|
|
263
|
-
blockName,
|
|
264
|
-
variable,
|
|
265
|
-
path
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
if (type === "custom") {
|
|
269
|
-
return getValueFromCustomVariable(
|
|
270
|
-
features,
|
|
271
|
-
blockName,
|
|
272
|
-
variable,
|
|
273
|
-
path
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
return variable;
|
|
277
|
-
}
|
|
278
12
|
function scopeSelector(scope, selector) {
|
|
279
13
|
if (!scope || !selector) {
|
|
280
14
|
return selector;
|
|
@@ -289,113 +23,7 @@ function scopeSelector(scope, selector) {
|
|
|
289
23
|
});
|
|
290
24
|
return selectorsScoped.join(", ");
|
|
291
25
|
}
|
|
292
|
-
function scopeFeatureSelectors(scope, selectors) {
|
|
293
|
-
if (!scope || !selectors) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const featureSelectors = {};
|
|
297
|
-
Object.entries(selectors).forEach(([feature, selector]) => {
|
|
298
|
-
if (typeof selector === "string") {
|
|
299
|
-
featureSelectors[feature] = scopeSelector(scope, selector);
|
|
300
|
-
}
|
|
301
|
-
if (typeof selector === "object") {
|
|
302
|
-
featureSelectors[feature] = {};
|
|
303
|
-
Object.entries(selector).forEach(
|
|
304
|
-
([subfeature, subfeatureSelector]) => {
|
|
305
|
-
featureSelectors[feature][subfeature] = scopeSelector(
|
|
306
|
-
scope,
|
|
307
|
-
subfeatureSelector
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
return featureSelectors;
|
|
314
|
-
}
|
|
315
|
-
function appendToSelector(selector, toAppend) {
|
|
316
|
-
if (!selector.includes(",")) {
|
|
317
|
-
return selector + toAppend;
|
|
318
|
-
}
|
|
319
|
-
const selectors = selector.split(",");
|
|
320
|
-
const newSelectors = selectors.map((sel) => sel + toAppend);
|
|
321
|
-
return newSelectors.join(",");
|
|
322
|
-
}
|
|
323
|
-
function areGlobalStyleConfigsEqual(original, variation) {
|
|
324
|
-
if (typeof original !== "object" || typeof variation !== "object") {
|
|
325
|
-
return original === variation;
|
|
326
|
-
}
|
|
327
|
-
return fastDeepEqual(original?.styles, variation?.styles) && fastDeepEqual(original?.settings, variation?.settings);
|
|
328
|
-
}
|
|
329
|
-
function getBlockStyleVariationSelector(variation, blockSelector) {
|
|
330
|
-
const variationClass = `.is-style-${variation}`;
|
|
331
|
-
if (!blockSelector) {
|
|
332
|
-
return variationClass;
|
|
333
|
-
}
|
|
334
|
-
const ancestorRegex = /((?::\([^)]+\))?\s*)([^\s:]+)/;
|
|
335
|
-
const addVariationClass = (_match, group1, group2) => {
|
|
336
|
-
return group1 + group2 + variationClass;
|
|
337
|
-
};
|
|
338
|
-
const result = blockSelector.split(",").map((part) => part.replace(ancestorRegex, addVariationClass));
|
|
339
|
-
return result.join(",");
|
|
340
|
-
}
|
|
341
|
-
function getResolvedThemeFilePath(file, themeFileURIs) {
|
|
342
|
-
if (!file || !themeFileURIs || !Array.isArray(themeFileURIs)) {
|
|
343
|
-
return file;
|
|
344
|
-
}
|
|
345
|
-
const uri = themeFileURIs.find(
|
|
346
|
-
(themeFileUri) => themeFileUri?.name === file
|
|
347
|
-
);
|
|
348
|
-
if (!uri?.href) {
|
|
349
|
-
return file;
|
|
350
|
-
}
|
|
351
|
-
return uri?.href;
|
|
352
|
-
}
|
|
353
|
-
function getResolvedRefValue(ruleValue, tree) {
|
|
354
|
-
if (!ruleValue || !tree) {
|
|
355
|
-
return ruleValue;
|
|
356
|
-
}
|
|
357
|
-
if (typeof ruleValue !== "string" && ruleValue?.ref) {
|
|
358
|
-
const resolvedRuleValue = getCSSValueFromRawStyle(
|
|
359
|
-
getValueFromObjectPath(tree, ruleValue.ref)
|
|
360
|
-
);
|
|
361
|
-
if (resolvedRuleValue?.ref) {
|
|
362
|
-
return void 0;
|
|
363
|
-
}
|
|
364
|
-
if (resolvedRuleValue === void 0) {
|
|
365
|
-
return ruleValue;
|
|
366
|
-
}
|
|
367
|
-
return resolvedRuleValue;
|
|
368
|
-
}
|
|
369
|
-
return ruleValue;
|
|
370
|
-
}
|
|
371
|
-
function getResolvedValue(ruleValue, tree) {
|
|
372
|
-
if (!ruleValue || !tree) {
|
|
373
|
-
return ruleValue;
|
|
374
|
-
}
|
|
375
|
-
const resolvedValue = getResolvedRefValue(ruleValue, tree);
|
|
376
|
-
if (resolvedValue?.url) {
|
|
377
|
-
resolvedValue.url = getResolvedThemeFilePath(
|
|
378
|
-
resolvedValue.url,
|
|
379
|
-
tree?._links?.["wp:theme-file"]
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
return resolvedValue;
|
|
383
|
-
}
|
|
384
26
|
export {
|
|
385
|
-
PRESET_METADATA,
|
|
386
|
-
ROOT_BLOCK_SELECTOR,
|
|
387
|
-
ROOT_CSS_PROPERTIES_SELECTOR,
|
|
388
|
-
STYLE_PATH_TO_CSS_VAR_INFIX,
|
|
389
|
-
STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE,
|
|
390
|
-
appendToSelector,
|
|
391
|
-
areGlobalStyleConfigsEqual,
|
|
392
|
-
getBlockStyleVariationSelector,
|
|
393
|
-
getPresetVariableFromValue,
|
|
394
|
-
getResolvedRefValue,
|
|
395
|
-
getResolvedThemeFilePath,
|
|
396
|
-
getResolvedValue,
|
|
397
|
-
getValueFromVariable,
|
|
398
|
-
scopeFeatureSelectors,
|
|
399
27
|
scopeSelector,
|
|
400
28
|
useToolsPanelDropdownMenuProps
|
|
401
29
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/global-styles/utils.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { useViewportMatch } from '@wordpress/compose';\nimport { getCSSValueFromRawStyle } from '@wordpress/style-engine';\n\n/**\n * Internal dependencies\n */\nimport { getTypographyFontSizeValue } from './typography-utils';\nimport { getValueFromObjectPath } from '../../utils/object';\n\n/* Supporting data. */\nexport const ROOT_BLOCK_SELECTOR = 'body';\nexport const ROOT_CSS_PROPERTIES_SELECTOR = ':root';\n\nexport const PRESET_METADATA = [\n\t{\n\t\tpath: [ 'color', 'palette' ],\n\t\tvalueKey: 'color',\n\t\tcssVarInfix: 'color',\n\t\tclasses: [\n\t\t\t{ classSuffix: 'color', propertyName: 'color' },\n\t\t\t{\n\t\t\t\tclassSuffix: 'background-color',\n\t\t\t\tpropertyName: 'background-color',\n\t\t\t},\n\t\t\t{\n\t\t\t\tclassSuffix: 'border-color',\n\t\t\t\tpropertyName: 'border-color',\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tpath: [ 'color', 'gradients' ],\n\t\tvalueKey: 'gradient',\n\t\tcssVarInfix: 'gradient',\n\t\tclasses: [\n\t\t\t{\n\t\t\t\tclassSuffix: 'gradient-background',\n\t\t\t\tpropertyName: 'background',\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tpath: [ 'color', 'duotone' ],\n\t\tvalueKey: 'colors',\n\t\tcssVarInfix: 'duotone',\n\t\tvalueFunc: ( { slug } ) => `url( '#wp-duotone-${ slug }' )`,\n\t\tclasses: [],\n\t},\n\t{\n\t\tpath: [ 'shadow', 'presets' ],\n\t\tvalueKey: 'shadow',\n\t\tcssVarInfix: 'shadow',\n\t\tclasses: [],\n\t},\n\t{\n\t\tpath: [ 'typography', 'fontSizes' ],\n\t\tvalueFunc: ( preset, settings ) =>\n\t\t\tgetTypographyFontSizeValue( preset, settings ),\n\t\tvalueKey: 'size',\n\t\tcssVarInfix: 'font-size',\n\t\tclasses: [ { classSuffix: 'font-size', propertyName: 'font-size' } ],\n\t},\n\t{\n\t\tpath: [ 'typography', 'fontFamilies' ],\n\t\tvalueKey: 'fontFamily',\n\t\tcssVarInfix: 'font-family',\n\t\tclasses: [\n\t\t\t{ classSuffix: 'font-family', propertyName: 'font-family' },\n\t\t],\n\t},\n\t{\n\t\tpath: [ 'spacing', 'spacingSizes' ],\n\t\tvalueKey: 'size',\n\t\tcssVarInfix: 'spacing',\n\t\tclasses: [],\n\t},\n\t{\n\t\tpath: [ 'border', 'radiusSizes' ],\n\t\tvalueKey: 'size',\n\t\tcssVarInfix: 'border-radius',\n\t\tclasses: [],\n\t},\n];\n\nexport const STYLE_PATH_TO_CSS_VAR_INFIX = {\n\t'color.background': 'color',\n\t'color.text': 'color',\n\t'filter.duotone': 'duotone',\n\t'elements.link.color.text': 'color',\n\t'elements.link.:hover.color.text': 'color',\n\t'elements.link.typography.fontFamily': 'font-family',\n\t'elements.link.typography.fontSize': 'font-size',\n\t'elements.button.color.text': 'color',\n\t'elements.button.color.background': 'color',\n\t'elements.caption.color.text': 'color',\n\t'elements.button.typography.fontFamily': 'font-family',\n\t'elements.button.typography.fontSize': 'font-size',\n\t'elements.heading.color': 'color',\n\t'elements.heading.color.background': 'color',\n\t'elements.heading.typography.fontFamily': 'font-family',\n\t'elements.heading.gradient': 'gradient',\n\t'elements.heading.color.gradient': 'gradient',\n\t'elements.h1.color': 'color',\n\t'elements.h1.color.background': 'color',\n\t'elements.h1.typography.fontFamily': 'font-family',\n\t'elements.h1.color.gradient': 'gradient',\n\t'elements.h2.color': 'color',\n\t'elements.h2.color.background': 'color',\n\t'elements.h2.typography.fontFamily': 'font-family',\n\t'elements.h2.color.gradient': 'gradient',\n\t'elements.h3.color': 'color',\n\t'elements.h3.color.background': 'color',\n\t'elements.h3.typography.fontFamily': 'font-family',\n\t'elements.h3.color.gradient': 'gradient',\n\t'elements.h4.color': 'color',\n\t'elements.h4.color.background': 'color',\n\t'elements.h4.typography.fontFamily': 'font-family',\n\t'elements.h4.color.gradient': 'gradient',\n\t'elements.h5.color': 'color',\n\t'elements.h5.color.background': 'color',\n\t'elements.h5.typography.fontFamily': 'font-family',\n\t'elements.h5.color.gradient': 'gradient',\n\t'elements.h6.color': 'color',\n\t'elements.h6.color.background': 'color',\n\t'elements.h6.typography.fontFamily': 'font-family',\n\t'elements.h6.color.gradient': 'gradient',\n\t'color.gradient': 'gradient',\n\tshadow: 'shadow',\n\t'typography.fontSize': 'font-size',\n\t'typography.fontFamily': 'font-family',\n};\n\n// A static list of block attributes that store global style preset slugs.\nexport const STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE = {\n\t'color.background': 'backgroundColor',\n\t'color.text': 'textColor',\n\t'color.gradient': 'gradient',\n\t'typography.fontSize': 'fontSize',\n\t'typography.fontFamily': 'fontFamily',\n};\n\nexport function useToolsPanelDropdownMenuProps() {\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\treturn ! isMobile\n\t\t? {\n\t\t\t\tpopoverProps: {\n\t\t\t\t\tplacement: 'left-start',\n\t\t\t\t\t// For non-mobile, inner sidebar width (248px) - button width (24px) - border (1px) + padding (16px) + spacing (20px)\n\t\t\t\t\toffset: 259,\n\t\t\t\t},\n\t\t }\n\t\t: {};\n}\n\nfunction findInPresetsBy(\n\tfeatures,\n\tblockName,\n\tpresetPath,\n\tpresetProperty,\n\tpresetValueValue\n) {\n\t// Block presets take priority above root level presets.\n\tconst orderedPresetsByOrigin = [\n\t\tgetValueFromObjectPath( features, [\n\t\t\t'blocks',\n\t\t\tblockName,\n\t\t\t...presetPath,\n\t\t] ),\n\t\tgetValueFromObjectPath( features, presetPath ),\n\t];\n\n\tfor ( const presetByOrigin of orderedPresetsByOrigin ) {\n\t\tif ( presetByOrigin ) {\n\t\t\t// Preset origins ordered by priority.\n\t\t\tconst origins = [ 'custom', 'theme', 'default' ];\n\t\t\tfor ( const origin of origins ) {\n\t\t\t\tconst presets = presetByOrigin[ origin ];\n\t\t\t\tif ( presets ) {\n\t\t\t\t\tconst presetObject = presets.find(\n\t\t\t\t\t\t( preset ) =>\n\t\t\t\t\t\t\tpreset[ presetProperty ] === presetValueValue\n\t\t\t\t\t);\n\t\t\t\t\tif ( presetObject ) {\n\t\t\t\t\t\tif ( presetProperty === 'slug' ) {\n\t\t\t\t\t\t\treturn presetObject;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// If there is a highest priority preset with the same slug but different value the preset we found was overwritten and should be ignored.\n\t\t\t\t\t\tconst highestPresetObjectWithSameSlug = findInPresetsBy(\n\t\t\t\t\t\t\tfeatures,\n\t\t\t\t\t\t\tblockName,\n\t\t\t\t\t\t\tpresetPath,\n\t\t\t\t\t\t\t'slug',\n\t\t\t\t\t\t\tpresetObject.slug\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\thighestPresetObjectWithSameSlug[\n\t\t\t\t\t\t\t\tpresetProperty\n\t\t\t\t\t\t\t] === presetObject[ presetProperty ]\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn presetObject;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function getPresetVariableFromValue(\n\tfeatures,\n\tblockName,\n\tvariableStylePath,\n\tpresetPropertyValue\n) {\n\tif ( ! presetPropertyValue ) {\n\t\treturn presetPropertyValue;\n\t}\n\n\tconst cssVarInfix = STYLE_PATH_TO_CSS_VAR_INFIX[ variableStylePath ];\n\n\tconst metadata = PRESET_METADATA.find(\n\t\t( data ) => data.cssVarInfix === cssVarInfix\n\t);\n\n\tif ( ! metadata ) {\n\t\t// The property doesn't have preset data\n\t\t// so the value should be returned as it is.\n\t\treturn presetPropertyValue;\n\t}\n\tconst { valueKey, path } = metadata;\n\n\tconst presetObject = findInPresetsBy(\n\t\tfeatures,\n\t\tblockName,\n\t\tpath,\n\t\tvalueKey,\n\t\tpresetPropertyValue\n\t);\n\n\tif ( ! presetObject ) {\n\t\t// Value wasn't found in the presets,\n\t\t// so it must be a custom value.\n\t\treturn presetPropertyValue;\n\t}\n\n\treturn `var:preset|${ cssVarInfix }|${ presetObject.slug }`;\n}\n\nfunction getValueFromPresetVariable(\n\tfeatures,\n\tblockName,\n\tvariable,\n\t[ presetType, slug ]\n) {\n\tconst metadata = PRESET_METADATA.find(\n\t\t( data ) => data.cssVarInfix === presetType\n\t);\n\tif ( ! metadata ) {\n\t\treturn variable;\n\t}\n\n\tconst presetObject = findInPresetsBy(\n\t\tfeatures.settings,\n\t\tblockName,\n\t\tmetadata.path,\n\t\t'slug',\n\t\tslug\n\t);\n\n\tif ( presetObject ) {\n\t\tconst { valueKey } = metadata;\n\t\tconst result = presetObject[ valueKey ];\n\t\treturn getValueFromVariable( features, blockName, result );\n\t}\n\n\treturn variable;\n}\n\nfunction getValueFromCustomVariable( features, blockName, variable, path ) {\n\tconst result =\n\t\tgetValueFromObjectPath( features.settings, [\n\t\t\t'blocks',\n\t\t\tblockName,\n\t\t\t'custom',\n\t\t\t...path,\n\t\t] ) ??\n\t\tgetValueFromObjectPath( features.settings, [ 'custom', ...path ] );\n\tif ( ! result ) {\n\t\treturn variable;\n\t}\n\t// A variable may reference another variable so we need recursion until we find the value.\n\treturn getValueFromVariable( features, blockName, result );\n}\n\n/**\n * Attempts to fetch the value of a theme.json CSS variable.\n *\n * @param {Object} features GlobalStylesContext config, e.g., user, base or merged. Represents the theme.json tree.\n * @param {string} blockName The name of a block as represented in the styles property. E.g., 'root' for root-level, and 'core/${blockName}' for blocks.\n * @param {string|*} variable An incoming style value. A CSS var value is expected, but it could be any value.\n * @return {string|*|{ref}} The value of the CSS var, if found. If not found, the passed variable argument.\n */\nexport function getValueFromVariable( features, blockName, variable ) {\n\tif ( ! variable || typeof variable !== 'string' ) {\n\t\tif ( typeof variable?.ref === 'string' ) {\n\t\t\tvariable = getValueFromObjectPath( features, variable.ref );\n\t\t\t// Presence of another ref indicates a reference to another dynamic value.\n\t\t\t// Pointing to another dynamic value is not supported.\n\t\t\tif ( ! variable || !! variable?.ref ) {\n\t\t\t\treturn variable;\n\t\t\t}\n\t\t} else {\n\t\t\treturn variable;\n\t\t}\n\t}\n\tconst USER_VALUE_PREFIX = 'var:';\n\tconst THEME_VALUE_PREFIX = 'var(--wp--';\n\tconst THEME_VALUE_SUFFIX = ')';\n\n\tlet parsedVar;\n\n\tif ( variable.startsWith( USER_VALUE_PREFIX ) ) {\n\t\tparsedVar = variable.slice( USER_VALUE_PREFIX.length ).split( '|' );\n\t} else if (\n\t\tvariable.startsWith( THEME_VALUE_PREFIX ) &&\n\t\tvariable.endsWith( THEME_VALUE_SUFFIX )\n\t) {\n\t\tparsedVar = variable\n\t\t\t.slice( THEME_VALUE_PREFIX.length, -THEME_VALUE_SUFFIX.length )\n\t\t\t.split( '--' );\n\t} else {\n\t\t// We don't know how to parse the value: either is raw of uses complex CSS such as `calc(1px * var(--wp--variable) )`\n\t\treturn variable;\n\t}\n\n\tconst [ type, ...path ] = parsedVar;\n\tif ( type === 'preset' ) {\n\t\treturn getValueFromPresetVariable(\n\t\t\tfeatures,\n\t\t\tblockName,\n\t\t\tvariable,\n\t\t\tpath\n\t\t);\n\t}\n\tif ( type === 'custom' ) {\n\t\treturn getValueFromCustomVariable(\n\t\t\tfeatures,\n\t\t\tblockName,\n\t\t\tvariable,\n\t\t\tpath\n\t\t);\n\t}\n\treturn variable;\n}\n\n/**\n * Function that scopes a selector with another one. This works a bit like\n * SCSS nesting except the `&` operator isn't supported.\n *\n * @example\n * ```js\n * const scope = '.a, .b .c';\n * const selector = '> .x, .y';\n * const merged = scopeSelector( scope, selector );\n * // merged is '.a > .x, .a .y, .b .c > .x, .b .c .y'\n * ```\n *\n * @param {string} scope Selector to scope to.\n * @param {string} selector Original selector.\n *\n * @return {string} Scoped selector.\n */\nexport function scopeSelector( scope, selector ) {\n\tif ( ! scope || ! selector ) {\n\t\treturn selector;\n\t}\n\n\tconst scopes = scope.split( ',' );\n\tconst selectors = selector.split( ',' );\n\n\tconst selectorsScoped = [];\n\tscopes.forEach( ( outer ) => {\n\t\tselectors.forEach( ( inner ) => {\n\t\t\tselectorsScoped.push( `${ outer.trim() } ${ inner.trim() }` );\n\t\t} );\n\t} );\n\n\treturn selectorsScoped.join( ', ' );\n}\n\n/**\n * Scopes a collection of selectors for features and subfeatures.\n *\n * @example\n * ```js\n * const scope = '.custom-scope';\n * const selectors = {\n * color: '.wp-my-block p',\n * typography: { fontSize: '.wp-my-block caption' },\n * };\n * const result = scopeFeatureSelector( scope, selectors );\n * // result is {\n * // color: '.custom-scope .wp-my-block p',\n * // typography: { fonSize: '.custom-scope .wp-my-block caption' },\n * // }\n * ```\n *\n * @param {string} scope Selector to scope collection of selectors with.\n * @param {Object} selectors Collection of feature selectors e.g.\n *\n * @return {Object|undefined} Scoped collection of feature selectors.\n */\nexport function scopeFeatureSelectors( scope, selectors ) {\n\tif ( ! scope || ! selectors ) {\n\t\treturn;\n\t}\n\n\tconst featureSelectors = {};\n\n\tObject.entries( selectors ).forEach( ( [ feature, selector ] ) => {\n\t\tif ( typeof selector === 'string' ) {\n\t\t\tfeatureSelectors[ feature ] = scopeSelector( scope, selector );\n\t\t}\n\n\t\tif ( typeof selector === 'object' ) {\n\t\t\tfeatureSelectors[ feature ] = {};\n\n\t\t\tObject.entries( selector ).forEach(\n\t\t\t\t( [ subfeature, subfeatureSelector ] ) => {\n\t\t\t\t\tfeatureSelectors[ feature ][ subfeature ] = scopeSelector(\n\t\t\t\t\t\tscope,\n\t\t\t\t\t\tsubfeatureSelector\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t} );\n\n\treturn featureSelectors;\n}\n\n/**\n * Appends a sub-selector to an existing one.\n *\n * Given the compounded `selector` \"h1, h2, h3\"\n * and the `toAppend` selector \".some-class\" the result will be\n * \"h1.some-class, h2.some-class, h3.some-class\".\n *\n * @param {string} selector Original selector.\n * @param {string} toAppend Selector to append.\n *\n * @return {string} The new selector.\n */\nexport function appendToSelector( selector, toAppend ) {\n\tif ( ! selector.includes( ',' ) ) {\n\t\treturn selector + toAppend;\n\t}\n\tconst selectors = selector.split( ',' );\n\tconst newSelectors = selectors.map( ( sel ) => sel + toAppend );\n\treturn newSelectors.join( ',' );\n}\n\n/**\n * Compares global style variations according to their styles and settings properties.\n *\n * @example\n * ```js\n * const globalStyles = { styles: { typography: { fontSize: '10px' } }, settings: {} };\n * const variation = { styles: { typography: { fontSize: '10000px' } }, settings: {} };\n * const isEqual = areGlobalStyleConfigsEqual( globalStyles, variation );\n * // false\n * ```\n *\n * @param {Object} original A global styles object.\n * @param {Object} variation A global styles object.\n *\n * @return {boolean} Whether `original` and `variation` match.\n */\nexport function areGlobalStyleConfigsEqual( original, variation ) {\n\tif ( typeof original !== 'object' || typeof variation !== 'object' ) {\n\t\treturn original === variation;\n\t}\n\treturn (\n\t\tfastDeepEqual( original?.styles, variation?.styles ) &&\n\t\tfastDeepEqual( original?.settings, variation?.settings )\n\t);\n}\n\n/**\n * Generates the selector for a block style variation by creating the\n * appropriate CSS class and adding it to the ancestor portion of the block's\n * selector.\n *\n * For example, take the Button block which has a compound selector:\n * `.wp-block-button .wp-block-button__link`. With a variation named 'custom',\n * the class `.is-style-custom` should be added to the `.wp-block-button`\n * ancestor only.\n *\n * This function will take into account comma separated and complex selectors.\n *\n * @param {string} variation Name for the variation.\n * @param {string} blockSelector CSS selector for the block.\n *\n * @return {string} CSS selector for the block style variation.\n */\nexport function getBlockStyleVariationSelector( variation, blockSelector ) {\n\tconst variationClass = `.is-style-${ variation }`;\n\n\tif ( ! blockSelector ) {\n\t\treturn variationClass;\n\t}\n\n\tconst ancestorRegex = /((?::\\([^)]+\\))?\\s*)([^\\s:]+)/;\n\tconst addVariationClass = ( _match, group1, group2 ) => {\n\t\treturn group1 + group2 + variationClass;\n\t};\n\n\tconst result = blockSelector\n\t\t.split( ',' )\n\t\t.map( ( part ) => part.replace( ancestorRegex, addVariationClass ) );\n\n\treturn result.join( ',' );\n}\n\n/**\n * Looks up a theme file URI based on a relative path.\n *\n * @param {string} file A relative path.\n * @param {Array<Object>} themeFileURIs A collection of absolute theme file URIs and their corresponding file paths.\n * @return {string} A resolved theme file URI, if one is found in the themeFileURIs collection.\n */\nexport function getResolvedThemeFilePath( file, themeFileURIs ) {\n\tif ( ! file || ! themeFileURIs || ! Array.isArray( themeFileURIs ) ) {\n\t\treturn file;\n\t}\n\n\tconst uri = themeFileURIs.find(\n\t\t( themeFileUri ) => themeFileUri?.name === file\n\t);\n\n\tif ( ! uri?.href ) {\n\t\treturn file;\n\t}\n\n\treturn uri?.href;\n}\n\n/**\n * Resolves ref values in theme JSON.\n *\n * @param {Object|string} ruleValue A block style value that may contain a reference to a theme.json value.\n * @param {Object} tree A theme.json object.\n * @return {*} The resolved value or incoming ruleValue.\n */\nexport function getResolvedRefValue( ruleValue, tree ) {\n\tif ( ! ruleValue || ! tree ) {\n\t\treturn ruleValue;\n\t}\n\n\t/*\n\t * Where the rule value is an object with a 'ref' property pointing\n\t * to a path, this converts that path into the value at that path.\n\t * For example: { \"ref\": \"style.color.background\" } => \"#fff\".\n\t */\n\tif ( typeof ruleValue !== 'string' && ruleValue?.ref ) {\n\t\tconst resolvedRuleValue = getCSSValueFromRawStyle(\n\t\t\tgetValueFromObjectPath( tree, ruleValue.ref )\n\t\t);\n\n\t\t/*\n\t\t * Presence of another ref indicates a reference to another dynamic value.\n\t\t * Pointing to another dynamic value is not supported.\n\t\t */\n\t\tif ( resolvedRuleValue?.ref ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif ( resolvedRuleValue === undefined ) {\n\t\t\treturn ruleValue;\n\t\t}\n\n\t\treturn resolvedRuleValue;\n\t}\n\treturn ruleValue;\n}\n\n/**\n * Resolves ref and relative path values in theme JSON.\n *\n * @param {Object|string} ruleValue A block style value that may contain a reference to a theme.json value.\n * @param {Object} tree A theme.json object.\n * @return {*} The resolved value or incoming ruleValue.\n */\nexport function getResolvedValue( ruleValue, tree ) {\n\tif ( ! ruleValue || ! tree ) {\n\t\treturn ruleValue;\n\t}\n\n\t// Resolve ref values.\n\tconst resolvedValue = getResolvedRefValue( ruleValue, tree );\n\n\t// Resolve relative paths.\n\tif ( resolvedValue?.url ) {\n\t\tresolvedValue.url = getResolvedThemeFilePath(\n\t\t\tresolvedValue.url,\n\t\t\ttree?._links?.[ 'wp:theme-file' ]\n\t\t);\n\t}\n\n\treturn resolvedValue;\n}\n"],
|
|
5
|
-
"mappings": "AAGA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useViewportMatch } from '@wordpress/compose';\n\nexport function useToolsPanelDropdownMenuProps() {\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\treturn ! isMobile\n\t\t? {\n\t\t\t\tpopoverProps: {\n\t\t\t\t\tplacement: 'left-start',\n\t\t\t\t\t// For non-mobile, inner sidebar width (248px) - button width (24px) - border (1px) + padding (16px) + spacing (20px)\n\t\t\t\t\toffset: 259,\n\t\t\t\t},\n\t\t }\n\t\t: {};\n}\n\n/**\n * Function that scopes a selector with another one. This works a bit like\n * SCSS nesting except the `&` operator isn't supported.\n *\n * @example\n * ```js\n * const scope = '.a, .b .c';\n * const selector = '> .x, .y';\n * const merged = scopeSelector( scope, selector );\n * // merged is '.a > .x, .a .y, .b .c > .x, .b .c .y'\n * ```\n *\n * @param {string} scope Selector to scope to.\n * @param {string} selector Original selector.\n *\n * @return {string} Scoped selector.\n */\nexport function scopeSelector( scope, selector ) {\n\tif ( ! scope || ! selector ) {\n\t\treturn selector;\n\t}\n\n\tconst scopes = scope.split( ',' );\n\tconst selectors = selector.split( ',' );\n\n\tconst selectorsScoped = [];\n\tscopes.forEach( ( outer ) => {\n\t\tselectors.forEach( ( inner ) => {\n\t\t\tselectorsScoped.push( `${ outer.trim() } ${ inner.trim() }` );\n\t\t} );\n\t} );\n\n\treturn selectorsScoped.join( ', ' );\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,wBAAwB;AAE1B,SAAS,iCAAiC;AAChD,QAAM,WAAW,iBAAkB,UAAU,GAAI;AACjD,SAAO,CAAE,WACN;AAAA,IACA,cAAc;AAAA,MACb,WAAW;AAAA;AAAA,MAEX,QAAQ;AAAA,IACT;AAAA,EACA,IACA,CAAC;AACL;AAmBO,SAAS,cAAe,OAAO,UAAW;AAChD,MAAK,CAAE,SAAS,CAAE,UAAW;AAC5B,WAAO;AAAA,EACR;AAEA,QAAM,SAAS,MAAM,MAAO,GAAI;AAChC,QAAM,YAAY,SAAS,MAAO,GAAI;AAEtC,QAAM,kBAAkB,CAAC;AACzB,SAAO,QAAS,CAAE,UAAW;AAC5B,cAAU,QAAS,CAAE,UAAW;AAC/B,sBAAgB,KAAM,GAAI,MAAM,KAAK,CAAE,IAAK,MAAM,KAAK,CAAE,EAAG;AAAA,IAC7D,CAAE;AAAA,EACH,CAAE;AAEF,SAAO,gBAAgB,KAAM,IAAK;AACnC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,16 +2,48 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { __ } from "@wordpress/i18n";
|
|
3
3
|
import { useViewportMatch } from "@wordpress/compose";
|
|
4
4
|
import { Button } from "@wordpress/components";
|
|
5
|
-
import { useCallback, useMemo } from "@wordpress/element";
|
|
5
|
+
import { useCallback, useMemo, useState } from "@wordpress/element";
|
|
6
|
+
import { useSelect } from "@wordpress/data";
|
|
6
7
|
import { MediaCategoryPanel } from "./media-panel";
|
|
7
8
|
import MediaUploadCheck from "../../media-upload/check";
|
|
8
9
|
import MediaUpload from "../../media-upload";
|
|
10
|
+
import MediaUploadModal from "../../media-upload-modal";
|
|
9
11
|
import { useMediaCategories } from "./hooks";
|
|
10
12
|
import { getBlockAndPreviewFromMedia } from "./utils";
|
|
11
13
|
import MobileTabNavigation from "../mobile-tab-navigation";
|
|
12
14
|
import CategoryTabs from "../category-tabs";
|
|
13
15
|
import InserterNoResults from "../no-results";
|
|
16
|
+
import { store as blockEditorStore } from "../../../store";
|
|
14
17
|
const ALLOWED_MEDIA_TYPES = ["image", "video", "audio"];
|
|
18
|
+
function ConditionalMediaUpload({ render, ...props }) {
|
|
19
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
20
|
+
const mediaUpload = useSelect((select) => {
|
|
21
|
+
const { getSettings } = select(blockEditorStore);
|
|
22
|
+
return getSettings().mediaUpload;
|
|
23
|
+
}, []);
|
|
24
|
+
if (window.__experimentalDataViewsMediaModal) {
|
|
25
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
26
|
+
render && render({ open: () => setIsModalOpen(true) }),
|
|
27
|
+
/* @__PURE__ */ jsx(
|
|
28
|
+
MediaUploadModal,
|
|
29
|
+
{
|
|
30
|
+
...props,
|
|
31
|
+
isOpen: isModalOpen,
|
|
32
|
+
onClose: () => {
|
|
33
|
+
setIsModalOpen(false);
|
|
34
|
+
props.onClose?.();
|
|
35
|
+
},
|
|
36
|
+
onSelect: (media) => {
|
|
37
|
+
setIsModalOpen(false);
|
|
38
|
+
props.onSelect?.(media);
|
|
39
|
+
},
|
|
40
|
+
onUpload: mediaUpload
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
] });
|
|
44
|
+
}
|
|
45
|
+
return /* @__PURE__ */ jsx(MediaUpload, { ...props, render });
|
|
46
|
+
}
|
|
15
47
|
function MediaTab({
|
|
16
48
|
rootClientId,
|
|
17
49
|
selectedCategory,
|
|
@@ -54,7 +86,7 @@ function MediaTab({
|
|
|
54
86
|
}
|
|
55
87
|
),
|
|
56
88
|
/* @__PURE__ */ jsx(MediaUploadCheck, { children: /* @__PURE__ */ jsx(
|
|
57
|
-
|
|
89
|
+
ConditionalMediaUpload,
|
|
58
90
|
{
|
|
59
91
|
multiple: false,
|
|
60
92
|
onSelect: onSelectMedia,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/inserter/media-tab/media-tab.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { Button } from '@wordpress/components';\nimport { useCallback, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { MediaCategoryPanel } from './media-panel';\nimport MediaUploadCheck from '../../media-upload/check';\nimport MediaUpload from '../../media-upload';\nimport { useMediaCategories } from './hooks';\nimport { getBlockAndPreviewFromMedia } from './utils';\nimport MobileTabNavigation from '../mobile-tab-navigation';\nimport CategoryTabs from '../category-tabs';\nimport InserterNoResults from '../no-results';\n\nconst ALLOWED_MEDIA_TYPES = [ 'image', 'video', 'audio' ];\n\nfunction MediaTab( {\n\trootClientId,\n\tselectedCategory,\n\tonSelectCategory,\n\tonInsert,\n\tchildren,\n} ) {\n\tconst mediaCategories = useMediaCategories( rootClientId );\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\tconst baseCssClass = 'block-editor-inserter__media-tabs';\n\tconst onSelectMedia = useCallback(\n\t\t( media ) => {\n\t\t\tif ( ! media?.url ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst [ block ] = getBlockAndPreviewFromMedia( media, media.type );\n\t\t\tonInsert( block );\n\t\t},\n\t\t[ onInsert ]\n\t);\n\tconst categories = useMemo(\n\t\t() =>\n\t\t\tmediaCategories.map( ( mediaCategory ) => ( {\n\t\t\t\t...mediaCategory,\n\t\t\t\tlabel: mediaCategory.labels.name,\n\t\t\t} ) ),\n\t\t[ mediaCategories ]\n\t);\n\n\tif ( ! categories.length ) {\n\t\treturn <InserterNoResults />;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ ! isMobile && (\n\t\t\t\t<div className={ `${ baseCssClass }-container` }>\n\t\t\t\t\t<CategoryTabs\n\t\t\t\t\t\tcategories={ categories }\n\t\t\t\t\t\tselectedCategory={ selectedCategory }\n\t\t\t\t\t\tonSelectCategory={ onSelectCategory }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t</CategoryTabs>\n\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t<
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { Button } from '@wordpress/components';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { MediaCategoryPanel } from './media-panel';\nimport MediaUploadCheck from '../../media-upload/check';\nimport MediaUpload from '../../media-upload';\nimport MediaUploadModal from '../../media-upload-modal';\nimport { useMediaCategories } from './hooks';\nimport { getBlockAndPreviewFromMedia } from './utils';\nimport MobileTabNavigation from '../mobile-tab-navigation';\nimport CategoryTabs from '../category-tabs';\nimport InserterNoResults from '../no-results';\nimport { store as blockEditorStore } from '../../../store';\n\nconst ALLOWED_MEDIA_TYPES = [ 'image', 'video', 'audio' ];\n\n/**\n * Conditional Media component that uses MediaUploadModal when experiment is enabled,\n * otherwise falls back to MediaUpload.\n *\n * @param {Object} root0 Component props.\n * @param {Function} root0.render Render prop function that receives { open } object.\n * @return {JSX.Element} The component.\n */\nfunction ConditionalMediaUpload( { render, ...props } ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst mediaUpload = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn getSettings().mediaUpload;\n\t}, [] );\n\n\tif ( window.__experimentalDataViewsMediaModal ) {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ render && render( { open: () => setIsModalOpen( true ) } ) }\n\t\t\t\t<MediaUploadModal\n\t\t\t\t\t{ ...props }\n\t\t\t\t\tisOpen={ isModalOpen }\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\tprops.onClose?.();\n\t\t\t\t\t} }\n\t\t\t\t\tonSelect={ ( media ) => {\n\t\t\t\t\t\tsetIsModalOpen( false );\n\t\t\t\t\t\tprops.onSelect?.( media );\n\t\t\t\t\t} }\n\t\t\t\t\tonUpload={ mediaUpload }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t}\n\n\treturn <MediaUpload { ...props } render={ render } />;\n}\n\nfunction MediaTab( {\n\trootClientId,\n\tselectedCategory,\n\tonSelectCategory,\n\tonInsert,\n\tchildren,\n} ) {\n\tconst mediaCategories = useMediaCategories( rootClientId );\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\tconst baseCssClass = 'block-editor-inserter__media-tabs';\n\tconst onSelectMedia = useCallback(\n\t\t( media ) => {\n\t\t\tif ( ! media?.url ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst [ block ] = getBlockAndPreviewFromMedia( media, media.type );\n\t\t\tonInsert( block );\n\t\t},\n\t\t[ onInsert ]\n\t);\n\tconst categories = useMemo(\n\t\t() =>\n\t\t\tmediaCategories.map( ( mediaCategory ) => ( {\n\t\t\t\t...mediaCategory,\n\t\t\t\tlabel: mediaCategory.labels.name,\n\t\t\t} ) ),\n\t\t[ mediaCategories ]\n\t);\n\n\tif ( ! categories.length ) {\n\t\treturn <InserterNoResults />;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ ! isMobile && (\n\t\t\t\t<div className={ `${ baseCssClass }-container` }>\n\t\t\t\t\t<CategoryTabs\n\t\t\t\t\t\tcategories={ categories }\n\t\t\t\t\t\tselectedCategory={ selectedCategory }\n\t\t\t\t\t\tonSelectCategory={ onSelectCategory }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t</CategoryTabs>\n\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t<ConditionalMediaUpload\n\t\t\t\t\t\t\tmultiple={ false }\n\t\t\t\t\t\t\tonSelect={ onSelectMedia }\n\t\t\t\t\t\t\tallowedTypes={ ALLOWED_MEDIA_TYPES }\n\t\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\t\t\t\t\t\t// Safari doesn't emit a focus event on button elements when\n\t\t\t\t\t\t\t\t\t\t// clicked and we need to manually focus the button here.\n\t\t\t\t\t\t\t\t\t\t// The reason is that core's Media Library modal explicitly triggers a\n\t\t\t\t\t\t\t\t\t\t// focus event and therefore a `blur` event is triggered on a different\n\t\t\t\t\t\t\t\t\t\t// element, which doesn't contain the `data-unstable-ignore-focus-outside-for-relatedtarget`\n\t\t\t\t\t\t\t\t\t\t// attribute making the Inserter dialog to close.\n\t\t\t\t\t\t\t\t\t\tevent.target.focus();\n\t\t\t\t\t\t\t\t\t\topen();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tclassName=\"block-editor-inserter__media-library-button\"\n\t\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\t\tdata-unstable-ignore-focus-outside-for-relatedtarget=\".media-modal\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Open Media Library' ) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</MediaUploadCheck>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ isMobile && (\n\t\t\t\t<MobileTabNavigation categories={ categories }>\n\t\t\t\t\t{ ( category ) => (\n\t\t\t\t\t\t<MediaCategoryPanel\n\t\t\t\t\t\t\tonInsert={ onInsert }\n\t\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\t\tcategory={ category }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</MobileTabNavigation>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default MediaTab;\n"],
|
|
5
|
+
"mappings": "AA0CG,mBAEC,KAFD;AAvCH,SAAS,UAAU;AACnB,SAAS,wBAAwB;AACjC,SAAS,cAAc;AACvB,SAAS,aAAa,SAAS,gBAAgB;AAC/C,SAAS,iBAAiB;AAK1B,SAAS,0BAA0B;AACnC,OAAO,sBAAsB;AAC7B,OAAO,iBAAiB;AACxB,OAAO,sBAAsB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,mCAAmC;AAC5C,OAAO,yBAAyB;AAChC,OAAO,kBAAkB;AACzB,OAAO,uBAAuB;AAC9B,SAAS,SAAS,wBAAwB;AAE1C,MAAM,sBAAsB,CAAE,SAAS,SAAS,OAAQ;AAUxD,SAAS,uBAAwB,EAAE,QAAQ,GAAG,MAAM,GAAI;AACvD,QAAM,CAAE,aAAa,cAAe,IAAI,SAAU,KAAM;AACxD,QAAM,cAAc,UAAW,CAAE,WAAY;AAC5C,UAAM,EAAE,YAAY,IAAI,OAAQ,gBAAiB;AACjD,WAAO,YAAY,EAAE;AAAA,EACtB,GAAG,CAAC,CAAE;AAEN,MAAK,OAAO,mCAAoC;AAC/C,WACC,iCACG;AAAA,gBAAU,OAAQ,EAAE,MAAM,MAAM,eAAgB,IAAK,EAAE,CAAE;AAAA,MAC3D;AAAA,QAAC;AAAA;AAAA,UACE,GAAG;AAAA,UACL,QAAS;AAAA,UACT,SAAU,MAAM;AACf,2BAAgB,KAAM;AACtB,kBAAM,UAAU;AAAA,UACjB;AAAA,UACA,UAAW,CAAE,UAAW;AACvB,2BAAgB,KAAM;AACtB,kBAAM,WAAY,KAAM;AAAA,UACzB;AAAA,UACA,UAAW;AAAA;AAAA,MACZ;AAAA,OACD;AAAA,EAEF;AAEA,SAAO,oBAAC,eAAc,GAAG,OAAQ,QAAkB;AACpD;AAEA,SAAS,SAAU;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,kBAAkB,mBAAoB,YAAa;AACzD,QAAM,WAAW,iBAAkB,UAAU,GAAI;AACjD,QAAM,eAAe;AACrB,QAAM,gBAAgB;AAAA,IACrB,CAAE,UAAW;AACZ,UAAK,CAAE,OAAO,KAAM;AACnB;AAAA,MACD;AACA,YAAM,CAAE,KAAM,IAAI,4BAA6B,OAAO,MAAM,IAAK;AACjE,eAAU,KAAM;AAAA,IACjB;AAAA,IACA,CAAE,QAAS;AAAA,EACZ;AACA,QAAM,aAAa;AAAA,IAClB,MACC,gBAAgB,IAAK,CAAE,mBAAqB;AAAA,MAC3C,GAAG;AAAA,MACH,OAAO,cAAc,OAAO;AAAA,IAC7B,EAAI;AAAA,IACL,CAAE,eAAgB;AAAA,EACnB;AAEA,MAAK,CAAE,WAAW,QAAS;AAC1B,WAAO,oBAAC,qBAAkB;AAAA,EAC3B;AAEA,SACC,iCACG;AAAA,KAAE,YACH,qBAAC,SAAI,WAAY,GAAI,YAAa,cACjC;AAAA;AAAA,QAAC;AAAA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UAEE;AAAA;AAAA,MACH;AAAA,MACA,oBAAC,oBACA;AAAA,QAAC;AAAA;AAAA,UACA,UAAW;AAAA,UACX,UAAW;AAAA,UACX,cAAe;AAAA,UACf,QAAS,CAAE,EAAE,KAAK,MACjB;AAAA,YAAC;AAAA;AAAA,cACA,uBAAqB;AAAA,cACrB,SAAU,CAAE,UAAW;AAOtB,sBAAM,OAAO,MAAM;AACnB,qBAAK;AAAA,cACN;AAAA,cACA,WAAU;AAAA,cACV,SAAQ;AAAA,cACR,wDAAqD;AAAA,cAEnD,aAAI,oBAAqB;AAAA;AAAA,UAC5B;AAAA;AAAA,MAEF,GACD;AAAA,OACD;AAAA,IAEC,YACD,oBAAC,uBAAoB,YAClB,WAAE,aACH;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD,GAEF;AAAA,KAEF;AAEF;AAEA,IAAO,oBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,8 +26,6 @@ const globalTips = [
|
|
|
26
26
|
];
|
|
27
27
|
function Tips() {
|
|
28
28
|
const [randomIndex] = useState(
|
|
29
|
-
// Disable Reason: I'm not generating an HTML id.
|
|
30
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
31
29
|
Math.floor(Math.random() * globalTips.length)
|
|
32
30
|
);
|
|
33
31
|
return /* @__PURE__ */ jsx(Tip, { children: globalTips[randomIndex] });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/inserter/tips.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { createInterpolateElement, useState } from '@wordpress/element';\nimport { Tip } from '@wordpress/components';\n\nconst globalTips = [\n\tcreateInterpolateElement(\n\t\t__(\n\t\t\t'While writing, you can press <kbd>/</kbd> to quickly insert new blocks.'\n\t\t),\n\t\t{ kbd: <kbd /> }\n\t),\n\tcreateInterpolateElement(\n\t\t__(\n\t\t\t'Indent a list by pressing <kbd>space</kbd> at the beginning of a line.'\n\t\t),\n\t\t{ kbd: <kbd /> }\n\t),\n\tcreateInterpolateElement(\n\t\t__(\n\t\t\t'Outdent a list by pressing <kbd>backspace</kbd> at the beginning of a line.'\n\t\t),\n\t\t{ kbd: <kbd /> }\n\t),\n\t__( 'Drag files into the editor to automatically insert media blocks.' ),\n\t__( \"Change a block's type by pressing the block icon on the toolbar.\" ),\n];\n\nfunction Tips() {\n\tconst [ randomIndex ] = useState(\n\t\
|
|
5
|
-
"mappings": "AAYS;AATT,SAAS,UAAU;AACnB,SAAS,0BAA0B,gBAAgB;AACnD,SAAS,WAAW;AAEpB,MAAM,aAAa;AAAA,EAClB;AAAA,IACC;AAAA,MACC;AAAA,IACD;AAAA,IACA,EAAE,KAAK,oBAAC,SAAI,EAAG;AAAA,EAChB;AAAA,EACA;AAAA,IACC;AAAA,MACC;AAAA,IACD;AAAA,IACA,EAAE,KAAK,oBAAC,SAAI,EAAG;AAAA,EAChB;AAAA,EACA;AAAA,IACC;AAAA,MACC;AAAA,IACD;AAAA,IACA,EAAE,KAAK,oBAAC,SAAI,EAAG;AAAA,EAChB;AAAA,EACA,GAAI,kEAAmE;AAAA,EACvE,GAAI,kEAAmE;AACxE;AAEA,SAAS,OAAO;AACf,QAAM,CAAE,WAAY,IAAI;AAAA
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { createInterpolateElement, useState } from '@wordpress/element';\nimport { Tip } from '@wordpress/components';\n\nconst globalTips = [\n\tcreateInterpolateElement(\n\t\t__(\n\t\t\t'While writing, you can press <kbd>/</kbd> to quickly insert new blocks.'\n\t\t),\n\t\t{ kbd: <kbd /> }\n\t),\n\tcreateInterpolateElement(\n\t\t__(\n\t\t\t'Indent a list by pressing <kbd>space</kbd> at the beginning of a line.'\n\t\t),\n\t\t{ kbd: <kbd /> }\n\t),\n\tcreateInterpolateElement(\n\t\t__(\n\t\t\t'Outdent a list by pressing <kbd>backspace</kbd> at the beginning of a line.'\n\t\t),\n\t\t{ kbd: <kbd /> }\n\t),\n\t__( 'Drag files into the editor to automatically insert media blocks.' ),\n\t__( \"Change a block's type by pressing the block icon on the toolbar.\" ),\n];\n\nfunction Tips() {\n\tconst [ randomIndex ] = useState(\n\t\tMath.floor( Math.random() * globalTips.length )\n\t);\n\n\treturn <Tip>{ globalTips[ randomIndex ] }</Tip>;\n}\n\nexport default Tips;\n"],
|
|
5
|
+
"mappings": "AAYS;AATT,SAAS,UAAU;AACnB,SAAS,0BAA0B,gBAAgB;AACnD,SAAS,WAAW;AAEpB,MAAM,aAAa;AAAA,EAClB;AAAA,IACC;AAAA,MACC;AAAA,IACD;AAAA,IACA,EAAE,KAAK,oBAAC,SAAI,EAAG;AAAA,EAChB;AAAA,EACA;AAAA,IACC;AAAA,MACC;AAAA,IACD;AAAA,IACA,EAAE,KAAK,oBAAC,SAAI,EAAG;AAAA,EAChB;AAAA,EACA;AAAA,IACC;AAAA,MACC;AAAA,IACD;AAAA,IACA,EAAE,KAAK,oBAAC,SAAI,EAAG;AAAA,EAChB;AAAA,EACA,GAAI,kEAAmE;AAAA,EACvE,GAAI,kEAAmE;AACxE;AAEA,SAAS,OAAO;AACf,QAAM,CAAE,WAAY,IAAI;AAAA,IACvB,KAAK,MAAO,KAAK,OAAO,IAAI,WAAW,MAAO;AAAA,EAC/C;AAEA,SAAO,oBAAC,OAAM,qBAAY,WAAY,GAAG;AAC1C;AAEA,IAAO,eAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|