@wordpress/edit-site 5.28.9 → 5.28.10
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/build/components/global-styles/font-library-modal/context.js +50 -22
- package/build/components/global-styles/font-library-modal/context.js.map +1 -1
- package/build/components/global-styles/font-library-modal/font-collection.js +1 -0
- package/build/components/global-styles/font-library-modal/font-collection.js.map +1 -1
- package/build/components/global-styles/font-library-modal/index.js +1 -1
- package/build/components/global-styles/font-library-modal/index.js.map +1 -1
- package/build/components/global-styles/font-library-modal/installed-fonts.js +5 -2
- package/build/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
- package/build/hooks/push-changes-to-global-styles/index.js +4 -40
- package/build/hooks/push-changes-to-global-styles/index.js.map +1 -1
- package/build/utils/set-nested-value.js +44 -0
- package/build/utils/set-nested-value.js.map +1 -0
- package/build-module/components/global-styles/font-library-modal/context.js +49 -22
- package/build-module/components/global-styles/font-library-modal/context.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/font-collection.js +1 -0
- package/build-module/components/global-styles/font-library-modal/font-collection.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/index.js +2 -2
- package/build-module/components/global-styles/font-library-modal/index.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/installed-fonts.js +5 -2
- package/build-module/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
- package/build-module/hooks/push-changes-to-global-styles/index.js +1 -38
- package/build-module/hooks/push-changes-to-global-styles/index.js.map +1 -1
- package/build-module/utils/set-nested-value.js +38 -0
- package/build-module/utils/set-nested-value.js.map +1 -0
- package/package.json +16 -16
- package/src/components/global-styles/font-library-modal/context.js +66 -41
- package/src/components/global-styles/font-library-modal/font-collection.js +1 -0
- package/src/components/global-styles/font-library-modal/index.js +2 -2
- package/src/components/global-styles/font-library-modal/installed-fonts.js +4 -1
- package/src/hooks/push-changes-to-global-styles/index.js +1 -40
- package/src/utils/set-nested-value.js +39 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["addFilter","createHigherOrderComponent","InspectorAdvancedControls","store","blockEditorStore","privateApis","blockEditorPrivateApis","useBlockEditingMode","BaseControl","Button","__","sprintf","__EXPERIMENTAL_STYLE_PROPERTY","getBlockType","hasBlockSupport","useContext","useMemo","useCallback","useDispatch","useSelect","noticesStore","coreStore","useSupportedStyles","unlock","cleanEmptyObject","GlobalStylesContext","STYLE_PROPERTY","blockGap","value","STYLE_PATH_TO_CSS_VAR_INFIX","STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE","SUPPORTED_STYLES","getValueFromObjectPath","object","path","forEach","fieldName","flatBorderProperties","sides","getBorderStyleChanges","border","presetColor","userStyle","changes","getFallbackBorderStyleChange","color","customColor","style","width","hasColorOrWidth","side","push","globalBorderStyle","useChangesToPush","name","attributes","userConfig","supports","blockUserConfig","styles","blocks","flatMap","key","presetAttributeKey","join","presetAttributeValue","linkChanges","hoverPath","hoverValue","includes","borderChanges","currentPath","splice","borderColor","change","setNestedValue","reduce","acc","idx","undefined","Number","isInteger","length","cloneDeep","JSON","parse","stringify","PushChangesToGlobalStylesControl","setAttributes","user","setUserConfig","__unstableMarkNextChangeAsNotPersistent","createSuccessNotice","pushChanges","blockStyles","newBlockStyles","newUserConfig","newBlockAttributes","backgroundColor","textColor","gradient","fontSize","fontFamily","undoIgnore","title","type","actions","label","onClick","createElement","className","help","VisualLabel","variant","disabled","PushChangesToGlobalStyles","props","blockEditingMode","isBlockBasedTheme","select","getCurrentTheme","is_block_theme","supportsStyles","some","feature","isDisplayed","withPushChangesToGlobalStyles","BlockEdit","Fragment","isSelected"],"sources":["@wordpress/edit-site/src/hooks/push-changes-to-global-styles/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport {\n\tInspectorAdvancedControls,\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\nimport { BaseControl, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\t__EXPERIMENTAL_STYLE_PROPERTY,\n\tgetBlockType,\n\thasBlockSupport,\n} from '@wordpress/blocks';\nimport { useContext, useMemo, useCallback } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { useSupportedStyles } from '../../components/global-styles/hooks';\nimport { unlock } from '../../lock-unlock';\n\nconst { cleanEmptyObject, GlobalStylesContext } = unlock(\n\tblockEditorPrivateApis\n);\n\n// Block Gap is a special case and isn't defined within the blocks\n// style properties config. We'll add it here to allow it to be pushed\n// to global styles as well.\nconst STYLE_PROPERTY = {\n\t...__EXPERIMENTAL_STYLE_PROPERTY,\n\tblockGap: { value: [ 'spacing', 'blockGap' ] },\n};\n\n// TODO: Temporary duplication of constant in @wordpress/block-editor. Can be\n// removed by moving PushChangesToGlobalStylesControl to\n// @wordpress/block-editor.\nconst STYLE_PATH_TO_CSS_VAR_INFIX = {\n\t'border.color': 'color',\n\t'color.background': 'color',\n\t'color.text': 'color',\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.button.typography.fontFamily': 'font-family',\n\t'elements.button.typography.fontSize': 'font-size',\n\t'elements.caption.color.text': 'color',\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\tblockGap: 'spacing',\n\t'typography.fontSize': 'font-size',\n\t'typography.fontFamily': 'font-family',\n};\n\n// TODO: Temporary duplication of constant in @wordpress/block-editor. Can be\n// removed by moving PushChangesToGlobalStylesControl to\n// @wordpress/block-editor.\nconst STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE = {\n\t'border.color': 'borderColor',\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\nconst SUPPORTED_STYLES = [ 'border', 'color', 'spacing', 'typography' ];\n\nconst getValueFromObjectPath = ( object, path ) => {\n\tlet value = object;\n\tpath.forEach( ( fieldName ) => {\n\t\tvalue = value?.[ fieldName ];\n\t} );\n\treturn value;\n};\n\nconst flatBorderProperties = [ 'borderColor', 'borderWidth', 'borderStyle' ];\nconst sides = [ 'top', 'right', 'bottom', 'left' ];\n\nfunction getBorderStyleChanges( border, presetColor, userStyle ) {\n\tif ( ! border && ! presetColor ) {\n\t\treturn [];\n\t}\n\n\tconst changes = [\n\t\t...getFallbackBorderStyleChange( 'top', border, userStyle ),\n\t\t...getFallbackBorderStyleChange( 'right', border, userStyle ),\n\t\t...getFallbackBorderStyleChange( 'bottom', border, userStyle ),\n\t\t...getFallbackBorderStyleChange( 'left', border, userStyle ),\n\t];\n\n\t// Handle a flat border i.e. all sides the same, CSS shorthand.\n\tconst { color: customColor, style, width } = border || {};\n\tconst hasColorOrWidth = presetColor || customColor || width;\n\n\tif ( hasColorOrWidth && ! style ) {\n\t\t// Global Styles need individual side configurations to overcome\n\t\t// theme.json configurations which are per side as well.\n\t\tsides.forEach( ( side ) => {\n\t\t\t// Only add fallback border-style if global styles don't already\n\t\t\t// have something set.\n\t\t\tif ( ! userStyle?.[ side ]?.style ) {\n\t\t\t\tchanges.push( {\n\t\t\t\t\tpath: [ 'border', side, 'style' ],\n\t\t\t\t\tvalue: 'solid',\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t}\n\n\treturn changes;\n}\n\nfunction getFallbackBorderStyleChange( side, border, globalBorderStyle ) {\n\tif ( ! border?.[ side ] || globalBorderStyle?.[ side ]?.style ) {\n\t\treturn [];\n\t}\n\n\tconst { color, style, width } = border[ side ];\n\tconst hasColorOrWidth = color || width;\n\n\tif ( ! hasColorOrWidth || style ) {\n\t\treturn [];\n\t}\n\n\treturn [ { path: [ 'border', side, 'style' ], value: 'solid' } ];\n}\n\nfunction useChangesToPush( name, attributes, userConfig ) {\n\tconst supports = useSupportedStyles( name );\n\tconst blockUserConfig = userConfig?.styles?.blocks?.[ name ];\n\n\treturn useMemo( () => {\n\t\tconst changes = supports.flatMap( ( key ) => {\n\t\t\tif ( ! STYLE_PROPERTY[ key ] ) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\tconst { value: path } = STYLE_PROPERTY[ key ];\n\t\t\tconst presetAttributeKey = path.join( '.' );\n\t\t\tconst presetAttributeValue =\n\t\t\t\tattributes[\n\t\t\t\t\tSTYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE[ presetAttributeKey ]\n\t\t\t\t];\n\t\t\tconst value = presetAttributeValue\n\t\t\t\t? `var:preset|${ STYLE_PATH_TO_CSS_VAR_INFIX[ presetAttributeKey ] }|${ presetAttributeValue }`\n\t\t\t\t: getValueFromObjectPath( attributes.style, path );\n\n\t\t\t// Links only have a single support entry but have two element\n\t\t\t// style properties, color and hover color. The following check\n\t\t\t// will add the hover color to the changes if required.\n\t\t\tif ( key === 'linkColor' ) {\n\t\t\t\tconst linkChanges = value ? [ { path, value } ] : [];\n\t\t\t\tconst hoverPath = [\n\t\t\t\t\t'elements',\n\t\t\t\t\t'link',\n\t\t\t\t\t':hover',\n\t\t\t\t\t'color',\n\t\t\t\t\t'text',\n\t\t\t\t];\n\t\t\t\tconst hoverValue = getValueFromObjectPath(\n\t\t\t\t\tattributes.style,\n\t\t\t\t\thoverPath\n\t\t\t\t);\n\n\t\t\t\tif ( hoverValue ) {\n\t\t\t\t\tlinkChanges.push( { path: hoverPath, value: hoverValue } );\n\t\t\t\t}\n\n\t\t\t\treturn linkChanges;\n\t\t\t}\n\n\t\t\t// The shorthand border styles can't be mapped directly as global\n\t\t\t// styles requires longhand config.\n\t\t\tif ( flatBorderProperties.includes( key ) && value ) {\n\t\t\t\t// The shorthand config path is included to clear the block attribute.\n\t\t\t\tconst borderChanges = [ { path, value } ];\n\t\t\t\tsides.forEach( ( side ) => {\n\t\t\t\t\tconst currentPath = [ ...path ];\n\t\t\t\t\tcurrentPath.splice( -1, 0, side );\n\t\t\t\t\tborderChanges.push( { path: currentPath, value } );\n\t\t\t\t} );\n\t\t\t\treturn borderChanges;\n\t\t\t}\n\n\t\t\treturn value ? [ { path, value } ] : [];\n\t\t} );\n\n\t\t// To ensure display of a visible border, global styles require a\n\t\t// default border style if a border color or width is present.\n\t\tgetBorderStyleChanges(\n\t\t\tattributes.style?.border,\n\t\t\tattributes.borderColor,\n\t\t\tblockUserConfig?.border\n\t\t).forEach( ( change ) => changes.push( change ) );\n\n\t\treturn changes;\n\t}, [ supports, attributes, blockUserConfig ] );\n}\n\n/**\n * Sets the value at path of object.\n * If a portion of path doesn’t exist, it’s created.\n * Arrays are created for missing index properties while objects are created\n * for all other missing properties.\n *\n * This function intentionally mutates the input object.\n *\n * Inspired by _.set().\n *\n * @see https://lodash.com/docs/4.17.15#set\n *\n * @todo Needs to be deduplicated with its copy in `@wordpress/core-data`.\n *\n * @param {Object} object Object to modify\n * @param {Array} path Path of the property to set.\n * @param {*} value Value to set.\n */\nfunction setNestedValue( object, path, value ) {\n\tif ( ! object || typeof object !== 'object' ) {\n\t\treturn object;\n\t}\n\n\tpath.reduce( ( acc, key, idx ) => {\n\t\tif ( acc[ key ] === undefined ) {\n\t\t\tif ( Number.isInteger( path[ idx + 1 ] ) ) {\n\t\t\t\tacc[ key ] = [];\n\t\t\t} else {\n\t\t\t\tacc[ key ] = {};\n\t\t\t}\n\t\t}\n\t\tif ( idx === path.length - 1 ) {\n\t\t\tacc[ key ] = value;\n\t\t}\n\t\treturn acc[ key ];\n\t}, object );\n\n\treturn object;\n}\n\nfunction cloneDeep( object ) {\n\treturn ! object ? {} : JSON.parse( JSON.stringify( object ) );\n}\n\nfunction PushChangesToGlobalStylesControl( {\n\tname,\n\tattributes,\n\tsetAttributes,\n} ) {\n\tconst { user: userConfig, setUserConfig } =\n\t\tuseContext( GlobalStylesContext );\n\n\tconst changes = useChangesToPush( name, attributes, userConfig );\n\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tconst pushChanges = useCallback( () => {\n\t\tif ( changes.length === 0 ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( changes.length > 0 ) {\n\t\t\tconst { style: blockStyles } = attributes;\n\n\t\t\tconst newBlockStyles = cloneDeep( blockStyles );\n\t\t\tconst newUserConfig = cloneDeep( userConfig );\n\n\t\t\tfor ( const { path, value } of changes ) {\n\t\t\t\tsetNestedValue( newBlockStyles, path, undefined );\n\t\t\t\tsetNestedValue(\n\t\t\t\t\tnewUserConfig,\n\t\t\t\t\t[ 'styles', 'blocks', name, ...path ],\n\t\t\t\t\tvalue\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst newBlockAttributes = {\n\t\t\t\tborderColor: undefined,\n\t\t\t\tbackgroundColor: undefined,\n\t\t\t\ttextColor: undefined,\n\t\t\t\tgradient: undefined,\n\t\t\t\tfontSize: undefined,\n\t\t\t\tfontFamily: undefined,\n\t\t\t\tstyle: cleanEmptyObject( newBlockStyles ),\n\t\t\t};\n\n\t\t\t// @wordpress/core-data doesn't support editing multiple entity types in\n\t\t\t// a single undo level. So for now, we disable @wordpress/core-data undo\n\t\t\t// tracking and implement our own Undo button in the snackbar\n\t\t\t// notification.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( newBlockAttributes );\n\t\t\tsetUserConfig( () => newUserConfig, { undoIgnore: true } );\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the block e.g. 'Heading'.\n\t\t\t\t\t__( '%s styles applied.' ),\n\t\t\t\t\tgetBlockType( name ).title\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tactions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\tonClick() {\n\t\t\t\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\t\t\t\tsetAttributes( attributes );\n\t\t\t\t\t\t\t\tsetUserConfig( () => userConfig, {\n\t\t\t\t\t\t\t\t\tundoIgnore: true,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t}, [\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\tattributes,\n\t\tchanges,\n\t\tcreateSuccessNotice,\n\t\tname,\n\t\tsetAttributes,\n\t\tsetUserConfig,\n\t\tuserConfig,\n\t] );\n\n\treturn (\n\t\t<BaseControl\n\t\t\tclassName=\"edit-site-push-changes-to-global-styles-control\"\n\t\t\thelp={ sprintf(\n\t\t\t\t// translators: %s: Title of the block e.g. 'Heading'.\n\t\t\t\t__(\n\t\t\t\t\t'Apply this block’s typography, spacing, dimensions, and color styles to all %s blocks.'\n\t\t\t\t),\n\t\t\t\tgetBlockType( name ).title\n\t\t\t) }\n\t\t>\n\t\t\t<BaseControl.VisualLabel>\n\t\t\t\t{ __( 'Styles' ) }\n\t\t\t</BaseControl.VisualLabel>\n\t\t\t<Button\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tdisabled={ changes.length === 0 }\n\t\t\t\tonClick={ pushChanges }\n\t\t\t>\n\t\t\t\t{ __( 'Apply globally' ) }\n\t\t\t</Button>\n\t\t</BaseControl>\n\t);\n}\n\nfunction PushChangesToGlobalStyles( props ) {\n\tconst blockEditingMode = useBlockEditingMode();\n\tconst isBlockBasedTheme = useSelect(\n\t\t( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,\n\t\t[]\n\t);\n\tconst supportsStyles = SUPPORTED_STYLES.some( ( feature ) =>\n\t\thasBlockSupport( props.name, feature )\n\t);\n\tconst isDisplayed =\n\t\tblockEditingMode === 'default' && supportsStyles && isBlockBasedTheme;\n\n\tif ( ! isDisplayed ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<InspectorAdvancedControls>\n\t\t\t<PushChangesToGlobalStylesControl { ...props } />\n\t\t</InspectorAdvancedControls>\n\t);\n}\n\nconst withPushChangesToGlobalStyles = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => (\n\t\t<>\n\t\t\t<BlockEdit { ...props } />\n\t\t\t{ props.isSelected && <PushChangesToGlobalStyles { ...props } /> }\n\t\t</>\n\t)\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/edit-site/push-changes-to-global-styles',\n\twithPushChangesToGlobalStyles\n);\n"],"mappings":";AAAA;AACA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,KAAK,EAAG;EAC3C,MAAMC,gBAAgB,GAAG9G,mBAAmB,CAAC,CAAC;EAC9C,MAAM+G,iBAAiB,GAAGnG,SAAS,CAChCoG,MAAM,IAAMA,MAAM,CAAElG,SAAU,CAAC,CAACmG,eAAe,CAAC,CAAC,EAAEC,cAAc,EACnE,EACD,CAAC;EACD,MAAMC,cAAc,GAAG3F,gBAAgB,CAAC4F,IAAI,CAAIC,OAAO,IACtD9G,eAAe,CAAEsG,KAAK,CAAC9D,IAAI,EAAEsE,OAAQ,CACtC,CAAC;EACD,MAAMC,WAAW,GAChBR,gBAAgB,KAAK,SAAS,IAAIK,cAAc,IAAIJ,iBAAiB;EAEtE,IAAK,CAAEO,WAAW,EAAG;IACpB,OAAO,IAAI;EACZ;EAEA,OACChB,aAAA,CAAC3G,yBAAyB,QACzB2G,aAAA,CAACtB,gCAAgC;IAAA,GAAM6B;EAAK,CAAI,CACtB,CAAC;AAE9B;AAEA,MAAMU,6BAA6B,GAAG7H,0BAA0B,CAC7D8H,SAAS,IAAQX,KAAK,IACvBP,aAAA,CAAAmB,QAAA,QACCnB,aAAA,CAACkB,SAAS;EAAA,GAAMX;AAAK,CAAI,CAAC,EACxBA,KAAK,CAACa,UAAU,IAAIpB,aAAA,CAACM,yBAAyB;EAAA,GAAMC;AAAK,CAAI,CAC9D,CAEJ,CAAC;AAEDpH,SAAS,CACR,kBAAkB,EAClB,8CAA8C,EAC9C8H,6BACD,CAAC"}
|
|
1
|
+
{"version":3,"names":["addFilter","createHigherOrderComponent","InspectorAdvancedControls","store","blockEditorStore","privateApis","blockEditorPrivateApis","useBlockEditingMode","BaseControl","Button","__","sprintf","__EXPERIMENTAL_STYLE_PROPERTY","getBlockType","hasBlockSupport","useContext","useMemo","useCallback","useDispatch","useSelect","noticesStore","coreStore","useSupportedStyles","unlock","setNestedValue","cleanEmptyObject","GlobalStylesContext","STYLE_PROPERTY","blockGap","value","STYLE_PATH_TO_CSS_VAR_INFIX","STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE","SUPPORTED_STYLES","getValueFromObjectPath","object","path","forEach","fieldName","flatBorderProperties","sides","getBorderStyleChanges","border","presetColor","userStyle","changes","getFallbackBorderStyleChange","color","customColor","style","width","hasColorOrWidth","side","push","globalBorderStyle","useChangesToPush","name","attributes","userConfig","supports","blockUserConfig","styles","blocks","flatMap","key","presetAttributeKey","join","presetAttributeValue","linkChanges","hoverPath","hoverValue","includes","borderChanges","currentPath","splice","borderColor","change","cloneDeep","JSON","parse","stringify","PushChangesToGlobalStylesControl","setAttributes","user","setUserConfig","__unstableMarkNextChangeAsNotPersistent","createSuccessNotice","pushChanges","length","blockStyles","newBlockStyles","newUserConfig","undefined","newBlockAttributes","backgroundColor","textColor","gradient","fontSize","fontFamily","undoIgnore","title","type","actions","label","onClick","createElement","className","help","VisualLabel","variant","disabled","PushChangesToGlobalStyles","props","blockEditingMode","isBlockBasedTheme","select","getCurrentTheme","is_block_theme","supportsStyles","some","feature","isDisplayed","withPushChangesToGlobalStyles","BlockEdit","Fragment","isSelected"],"sources":["@wordpress/edit-site/src/hooks/push-changes-to-global-styles/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport {\n\tInspectorAdvancedControls,\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\nimport { BaseControl, Button } from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\t__EXPERIMENTAL_STYLE_PROPERTY,\n\tgetBlockType,\n\thasBlockSupport,\n} from '@wordpress/blocks';\nimport { useContext, useMemo, useCallback } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { useSupportedStyles } from '../../components/global-styles/hooks';\nimport { unlock } from '../../lock-unlock';\nimport setNestedValue from '../../utils/set-nested-value';\n\nconst { cleanEmptyObject, GlobalStylesContext } = unlock(\n\tblockEditorPrivateApis\n);\n\n// Block Gap is a special case and isn't defined within the blocks\n// style properties config. We'll add it here to allow it to be pushed\n// to global styles as well.\nconst STYLE_PROPERTY = {\n\t...__EXPERIMENTAL_STYLE_PROPERTY,\n\tblockGap: { value: [ 'spacing', 'blockGap' ] },\n};\n\n// TODO: Temporary duplication of constant in @wordpress/block-editor. Can be\n// removed by moving PushChangesToGlobalStylesControl to\n// @wordpress/block-editor.\nconst STYLE_PATH_TO_CSS_VAR_INFIX = {\n\t'border.color': 'color',\n\t'color.background': 'color',\n\t'color.text': 'color',\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.button.typography.fontFamily': 'font-family',\n\t'elements.button.typography.fontSize': 'font-size',\n\t'elements.caption.color.text': 'color',\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\tblockGap: 'spacing',\n\t'typography.fontSize': 'font-size',\n\t'typography.fontFamily': 'font-family',\n};\n\n// TODO: Temporary duplication of constant in @wordpress/block-editor. Can be\n// removed by moving PushChangesToGlobalStylesControl to\n// @wordpress/block-editor.\nconst STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE = {\n\t'border.color': 'borderColor',\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\nconst SUPPORTED_STYLES = [ 'border', 'color', 'spacing', 'typography' ];\n\nconst getValueFromObjectPath = ( object, path ) => {\n\tlet value = object;\n\tpath.forEach( ( fieldName ) => {\n\t\tvalue = value?.[ fieldName ];\n\t} );\n\treturn value;\n};\n\nconst flatBorderProperties = [ 'borderColor', 'borderWidth', 'borderStyle' ];\nconst sides = [ 'top', 'right', 'bottom', 'left' ];\n\nfunction getBorderStyleChanges( border, presetColor, userStyle ) {\n\tif ( ! border && ! presetColor ) {\n\t\treturn [];\n\t}\n\n\tconst changes = [\n\t\t...getFallbackBorderStyleChange( 'top', border, userStyle ),\n\t\t...getFallbackBorderStyleChange( 'right', border, userStyle ),\n\t\t...getFallbackBorderStyleChange( 'bottom', border, userStyle ),\n\t\t...getFallbackBorderStyleChange( 'left', border, userStyle ),\n\t];\n\n\t// Handle a flat border i.e. all sides the same, CSS shorthand.\n\tconst { color: customColor, style, width } = border || {};\n\tconst hasColorOrWidth = presetColor || customColor || width;\n\n\tif ( hasColorOrWidth && ! style ) {\n\t\t// Global Styles need individual side configurations to overcome\n\t\t// theme.json configurations which are per side as well.\n\t\tsides.forEach( ( side ) => {\n\t\t\t// Only add fallback border-style if global styles don't already\n\t\t\t// have something set.\n\t\t\tif ( ! userStyle?.[ side ]?.style ) {\n\t\t\t\tchanges.push( {\n\t\t\t\t\tpath: [ 'border', side, 'style' ],\n\t\t\t\t\tvalue: 'solid',\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t}\n\n\treturn changes;\n}\n\nfunction getFallbackBorderStyleChange( side, border, globalBorderStyle ) {\n\tif ( ! border?.[ side ] || globalBorderStyle?.[ side ]?.style ) {\n\t\treturn [];\n\t}\n\n\tconst { color, style, width } = border[ side ];\n\tconst hasColorOrWidth = color || width;\n\n\tif ( ! hasColorOrWidth || style ) {\n\t\treturn [];\n\t}\n\n\treturn [ { path: [ 'border', side, 'style' ], value: 'solid' } ];\n}\n\nfunction useChangesToPush( name, attributes, userConfig ) {\n\tconst supports = useSupportedStyles( name );\n\tconst blockUserConfig = userConfig?.styles?.blocks?.[ name ];\n\n\treturn useMemo( () => {\n\t\tconst changes = supports.flatMap( ( key ) => {\n\t\t\tif ( ! STYLE_PROPERTY[ key ] ) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\tconst { value: path } = STYLE_PROPERTY[ key ];\n\t\t\tconst presetAttributeKey = path.join( '.' );\n\t\t\tconst presetAttributeValue =\n\t\t\t\tattributes[\n\t\t\t\t\tSTYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE[ presetAttributeKey ]\n\t\t\t\t];\n\t\t\tconst value = presetAttributeValue\n\t\t\t\t? `var:preset|${ STYLE_PATH_TO_CSS_VAR_INFIX[ presetAttributeKey ] }|${ presetAttributeValue }`\n\t\t\t\t: getValueFromObjectPath( attributes.style, path );\n\n\t\t\t// Links only have a single support entry but have two element\n\t\t\t// style properties, color and hover color. The following check\n\t\t\t// will add the hover color to the changes if required.\n\t\t\tif ( key === 'linkColor' ) {\n\t\t\t\tconst linkChanges = value ? [ { path, value } ] : [];\n\t\t\t\tconst hoverPath = [\n\t\t\t\t\t'elements',\n\t\t\t\t\t'link',\n\t\t\t\t\t':hover',\n\t\t\t\t\t'color',\n\t\t\t\t\t'text',\n\t\t\t\t];\n\t\t\t\tconst hoverValue = getValueFromObjectPath(\n\t\t\t\t\tattributes.style,\n\t\t\t\t\thoverPath\n\t\t\t\t);\n\n\t\t\t\tif ( hoverValue ) {\n\t\t\t\t\tlinkChanges.push( { path: hoverPath, value: hoverValue } );\n\t\t\t\t}\n\n\t\t\t\treturn linkChanges;\n\t\t\t}\n\n\t\t\t// The shorthand border styles can't be mapped directly as global\n\t\t\t// styles requires longhand config.\n\t\t\tif ( flatBorderProperties.includes( key ) && value ) {\n\t\t\t\t// The shorthand config path is included to clear the block attribute.\n\t\t\t\tconst borderChanges = [ { path, value } ];\n\t\t\t\tsides.forEach( ( side ) => {\n\t\t\t\t\tconst currentPath = [ ...path ];\n\t\t\t\t\tcurrentPath.splice( -1, 0, side );\n\t\t\t\t\tborderChanges.push( { path: currentPath, value } );\n\t\t\t\t} );\n\t\t\t\treturn borderChanges;\n\t\t\t}\n\n\t\t\treturn value ? [ { path, value } ] : [];\n\t\t} );\n\n\t\t// To ensure display of a visible border, global styles require a\n\t\t// default border style if a border color or width is present.\n\t\tgetBorderStyleChanges(\n\t\t\tattributes.style?.border,\n\t\t\tattributes.borderColor,\n\t\t\tblockUserConfig?.border\n\t\t).forEach( ( change ) => changes.push( change ) );\n\n\t\treturn changes;\n\t}, [ supports, attributes, blockUserConfig ] );\n}\n\nfunction cloneDeep( object ) {\n\treturn ! object ? {} : JSON.parse( JSON.stringify( object ) );\n}\n\nfunction PushChangesToGlobalStylesControl( {\n\tname,\n\tattributes,\n\tsetAttributes,\n} ) {\n\tconst { user: userConfig, setUserConfig } =\n\t\tuseContext( GlobalStylesContext );\n\n\tconst changes = useChangesToPush( name, attributes, userConfig );\n\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\n\tconst pushChanges = useCallback( () => {\n\t\tif ( changes.length === 0 ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( changes.length > 0 ) {\n\t\t\tconst { style: blockStyles } = attributes;\n\n\t\t\tconst newBlockStyles = cloneDeep( blockStyles );\n\t\t\tconst newUserConfig = cloneDeep( userConfig );\n\n\t\t\tfor ( const { path, value } of changes ) {\n\t\t\t\tsetNestedValue( newBlockStyles, path, undefined );\n\t\t\t\tsetNestedValue(\n\t\t\t\t\tnewUserConfig,\n\t\t\t\t\t[ 'styles', 'blocks', name, ...path ],\n\t\t\t\t\tvalue\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst newBlockAttributes = {\n\t\t\t\tborderColor: undefined,\n\t\t\t\tbackgroundColor: undefined,\n\t\t\t\ttextColor: undefined,\n\t\t\t\tgradient: undefined,\n\t\t\t\tfontSize: undefined,\n\t\t\t\tfontFamily: undefined,\n\t\t\t\tstyle: cleanEmptyObject( newBlockStyles ),\n\t\t\t};\n\n\t\t\t// @wordpress/core-data doesn't support editing multiple entity types in\n\t\t\t// a single undo level. So for now, we disable @wordpress/core-data undo\n\t\t\t// tracking and implement our own Undo button in the snackbar\n\t\t\t// notification.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( newBlockAttributes );\n\t\t\tsetUserConfig( () => newUserConfig, { undoIgnore: true } );\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the block e.g. 'Heading'.\n\t\t\t\t\t__( '%s styles applied.' ),\n\t\t\t\t\tgetBlockType( name ).title\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tactions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: __( 'Undo' ),\n\t\t\t\t\t\t\tonClick() {\n\t\t\t\t\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\t\t\t\t\tsetAttributes( attributes );\n\t\t\t\t\t\t\t\tsetUserConfig( () => userConfig, {\n\t\t\t\t\t\t\t\t\tundoIgnore: true,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t}, [\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\tattributes,\n\t\tchanges,\n\t\tcreateSuccessNotice,\n\t\tname,\n\t\tsetAttributes,\n\t\tsetUserConfig,\n\t\tuserConfig,\n\t] );\n\n\treturn (\n\t\t<BaseControl\n\t\t\tclassName=\"edit-site-push-changes-to-global-styles-control\"\n\t\t\thelp={ sprintf(\n\t\t\t\t// translators: %s: Title of the block e.g. 'Heading'.\n\t\t\t\t__(\n\t\t\t\t\t'Apply this block’s typography, spacing, dimensions, and color styles to all %s blocks.'\n\t\t\t\t),\n\t\t\t\tgetBlockType( name ).title\n\t\t\t) }\n\t\t>\n\t\t\t<BaseControl.VisualLabel>\n\t\t\t\t{ __( 'Styles' ) }\n\t\t\t</BaseControl.VisualLabel>\n\t\t\t<Button\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tdisabled={ changes.length === 0 }\n\t\t\t\tonClick={ pushChanges }\n\t\t\t>\n\t\t\t\t{ __( 'Apply globally' ) }\n\t\t\t</Button>\n\t\t</BaseControl>\n\t);\n}\n\nfunction PushChangesToGlobalStyles( props ) {\n\tconst blockEditingMode = useBlockEditingMode();\n\tconst isBlockBasedTheme = useSelect(\n\t\t( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,\n\t\t[]\n\t);\n\tconst supportsStyles = SUPPORTED_STYLES.some( ( feature ) =>\n\t\thasBlockSupport( props.name, feature )\n\t);\n\tconst isDisplayed =\n\t\tblockEditingMode === 'default' && supportsStyles && isBlockBasedTheme;\n\n\tif ( ! isDisplayed ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<InspectorAdvancedControls>\n\t\t\t<PushChangesToGlobalStylesControl { ...props } />\n\t\t</InspectorAdvancedControls>\n\t);\n}\n\nconst withPushChangesToGlobalStyles = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => (\n\t\t<>\n\t\t\t<BlockEdit { ...props } />\n\t\t\t{ props.isSelected && <PushChangesToGlobalStyles { ...props } /> }\n\t\t</>\n\t)\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/edit-site/push-changes-to-global-styles',\n\twithPushChangesToGlobalStyles\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,SACCC,yBAAyB,EACzBC,KAAK,IAAIC,gBAAgB,EACzBC,WAAW,IAAIC,sBAAsB,EACrCC,mBAAmB,QACb,yBAAyB;AAChC,SAASC,WAAW,EAAEC,MAAM,QAAQ,uBAAuB;AAC3D,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SACCC,6BAA6B,EAC7BC,YAAY,EACZC,eAAe,QACT,mBAAmB;AAC1B,SAASC,UAAU,EAAEC,OAAO,EAAEC,WAAW,QAAQ,oBAAoB;AACrE,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAAShB,KAAK,IAAIiB,YAAY,QAAQ,oBAAoB;AAC1D,SAASjB,KAAK,IAAIkB,SAAS,QAAQ,sBAAsB;;AAEzD;AACA;AACA;AACA,SAASC,kBAAkB,QAAQ,sCAAsC;AACzE,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,cAAc,MAAM,8BAA8B;AAEzD,MAAM;EAAEC,gBAAgB;EAAEC;AAAoB,CAAC,GAAGH,MAAM,CACvDjB,sBACD,CAAC;;AAED;AACA;AACA;AACA,MAAMqB,cAAc,GAAG;EACtB,GAAGf,6BAA6B;EAChCgB,QAAQ,EAAE;IAAEC,KAAK,EAAE,CAAE,SAAS,EAAE,UAAU;EAAG;AAC9C,CAAC;;AAED;AACA;AACA;AACA,MAAMC,2BAA2B,GAAG;EACnC,c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CAACtG,yBAAyB,QACzBsG,aAAA,CAACxB,gCAAgC;IAAA,GAAM+B;EAAK,CAAI,CACtB,CAAC;AAE9B;AAEA,MAAMU,6BAA6B,GAAGxH,0BAA0B,CAC7DyH,SAAS,IAAQX,KAAK,IACvBP,aAAA,CAAAmB,QAAA,QACCnB,aAAA,CAACkB,SAAS;EAAA,GAAMX;AAAK,CAAI,CAAC,EACxBA,KAAK,CAACa,UAAU,IAAIpB,aAAA,CAACM,yBAAyB;EAAA,GAAMC;AAAK,CAAI,CAC9D,CAEJ,CAAC;AAED/G,SAAS,CACR,kBAAkB,EAClB,8CAA8C,EAC9CyH,6BACD,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets the value at path of object.
|
|
3
|
+
* If a portion of path doesn’t exist, it’s created.
|
|
4
|
+
* Arrays are created for missing index properties while objects are created
|
|
5
|
+
* for all other missing properties.
|
|
6
|
+
*
|
|
7
|
+
* This function intentionally mutates the input object.
|
|
8
|
+
*
|
|
9
|
+
* Inspired by _.set().
|
|
10
|
+
*
|
|
11
|
+
* @see https://lodash.com/docs/4.17.15#set
|
|
12
|
+
*
|
|
13
|
+
* @todo Needs to be deduplicated with its copy in `@wordpress/core-data`.
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} object Object to modify
|
|
16
|
+
* @param {Array} path Path of the property to set.
|
|
17
|
+
* @param {*} value Value to set.
|
|
18
|
+
*/
|
|
19
|
+
export default function setNestedValue(object, path, value) {
|
|
20
|
+
if (!object || typeof object !== 'object') {
|
|
21
|
+
return object;
|
|
22
|
+
}
|
|
23
|
+
path.reduce((acc, key, idx) => {
|
|
24
|
+
if (acc[key] === undefined) {
|
|
25
|
+
if (Number.isInteger(path[idx + 1])) {
|
|
26
|
+
acc[key] = [];
|
|
27
|
+
} else {
|
|
28
|
+
acc[key] = {};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (idx === path.length - 1) {
|
|
32
|
+
acc[key] = value;
|
|
33
|
+
}
|
|
34
|
+
return acc[key];
|
|
35
|
+
}, object);
|
|
36
|
+
return object;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=set-nested-value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["setNestedValue","object","path","value","reduce","acc","key","idx","undefined","Number","isInteger","length"],"sources":["@wordpress/edit-site/src/utils/set-nested-value.js"],"sourcesContent":["/**\n * Sets the value at path of object.\n * If a portion of path doesn’t exist, it’s created.\n * Arrays are created for missing index properties while objects are created\n * for all other missing properties.\n *\n * This function intentionally mutates the input object.\n *\n * Inspired by _.set().\n *\n * @see https://lodash.com/docs/4.17.15#set\n *\n * @todo Needs to be deduplicated with its copy in `@wordpress/core-data`.\n *\n * @param {Object} object Object to modify\n * @param {Array} path Path of the property to set.\n * @param {*} value Value to set.\n */\nexport default function setNestedValue( object, path, value ) {\n\tif ( ! object || typeof object !== 'object' ) {\n\t\treturn object;\n\t}\n\n\tpath.reduce( ( acc, key, idx ) => {\n\t\tif ( acc[ key ] === undefined ) {\n\t\t\tif ( Number.isInteger( path[ idx + 1 ] ) ) {\n\t\t\t\tacc[ key ] = [];\n\t\t\t} else {\n\t\t\t\tacc[ key ] = {};\n\t\t\t}\n\t\t}\n\t\tif ( idx === path.length - 1 ) {\n\t\t\tacc[ key ] = value;\n\t\t}\n\t\treturn acc[ key ];\n\t}, object );\n\n\treturn object;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,cAAcA,CAAEC,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAG;EAC7D,IAAK,CAAEF,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAG;IAC7C,OAAOA,MAAM;EACd;EAEAC,IAAI,CAACE,MAAM,CAAE,CAAEC,GAAG,EAAEC,GAAG,EAAEC,GAAG,KAAM;IACjC,IAAKF,GAAG,CAAEC,GAAG,CAAE,KAAKE,SAAS,EAAG;MAC/B,IAAKC,MAAM,CAACC,SAAS,CAAER,IAAI,CAAEK,GAAG,GAAG,CAAC,CAAG,CAAC,EAAG;QAC1CF,GAAG,CAAEC,GAAG,CAAE,GAAG,EAAE;MAChB,CAAC,MAAM;QACND,GAAG,CAAEC,GAAG,CAAE,GAAG,CAAC,CAAC;MAChB;IACD;IACA,IAAKC,GAAG,KAAKL,IAAI,CAACS,MAAM,GAAG,CAAC,EAAG;MAC9BN,GAAG,CAAEC,GAAG,CAAE,GAAGH,KAAK;IACnB;IACA,OAAOE,GAAG,CAAEC,GAAG,CAAE;EAClB,CAAC,EAAEL,MAAO,CAAC;EAEX,OAAOA,MAAM;AACd"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/edit-site",
|
|
3
|
-
"version": "5.28.
|
|
3
|
+
"version": "5.28.10",
|
|
4
4
|
"description": "Edit Site Page module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -30,42 +30,42 @@
|
|
|
30
30
|
"@wordpress/a11y": "^3.51.1",
|
|
31
31
|
"@wordpress/api-fetch": "^6.48.1",
|
|
32
32
|
"@wordpress/blob": "^3.51.1",
|
|
33
|
-
"@wordpress/block-editor": "^12.19.
|
|
34
|
-
"@wordpress/block-library": "^8.28.
|
|
33
|
+
"@wordpress/block-editor": "^12.19.8",
|
|
34
|
+
"@wordpress/block-library": "^8.28.10",
|
|
35
35
|
"@wordpress/blocks": "^12.28.6",
|
|
36
|
-
"@wordpress/commands": "^0.22.
|
|
37
|
-
"@wordpress/components": "^26.0.
|
|
36
|
+
"@wordpress/commands": "^0.22.6",
|
|
37
|
+
"@wordpress/components": "^26.0.6",
|
|
38
38
|
"@wordpress/compose": "^6.28.1",
|
|
39
|
-
"@wordpress/core-commands": "^0.20.
|
|
40
|
-
"@wordpress/core-data": "^6.28.
|
|
39
|
+
"@wordpress/core-commands": "^0.20.8",
|
|
40
|
+
"@wordpress/core-data": "^6.28.8",
|
|
41
41
|
"@wordpress/data": "^9.21.1",
|
|
42
|
-
"@wordpress/dataviews": "^0.5.
|
|
42
|
+
"@wordpress/dataviews": "^0.5.7",
|
|
43
43
|
"@wordpress/date": "^4.51.1",
|
|
44
44
|
"@wordpress/deprecated": "^3.51.1",
|
|
45
45
|
"@wordpress/dom": "^3.51.1",
|
|
46
|
-
"@wordpress/editor": "^13.28.
|
|
46
|
+
"@wordpress/editor": "^13.28.8",
|
|
47
47
|
"@wordpress/element": "^5.28.1",
|
|
48
48
|
"@wordpress/escape-html": "^2.51.1",
|
|
49
49
|
"@wordpress/hooks": "^3.51.1",
|
|
50
50
|
"@wordpress/html-entities": "^3.51.1",
|
|
51
51
|
"@wordpress/i18n": "^4.51.1",
|
|
52
52
|
"@wordpress/icons": "^9.42.4",
|
|
53
|
-
"@wordpress/interface": "^5.28.
|
|
53
|
+
"@wordpress/interface": "^5.28.6",
|
|
54
54
|
"@wordpress/keyboard-shortcuts": "^4.28.1",
|
|
55
55
|
"@wordpress/keycodes": "^3.51.1",
|
|
56
56
|
"@wordpress/media-utils": "^4.42.2",
|
|
57
57
|
"@wordpress/notices": "^4.19.1",
|
|
58
|
-
"@wordpress/patterns": "^1.12.
|
|
59
|
-
"@wordpress/plugins": "^6.19.
|
|
60
|
-
"@wordpress/preferences": "^3.28.
|
|
58
|
+
"@wordpress/patterns": "^1.12.8",
|
|
59
|
+
"@wordpress/plugins": "^6.19.6",
|
|
60
|
+
"@wordpress/preferences": "^3.28.6",
|
|
61
61
|
"@wordpress/primitives": "^3.49.1",
|
|
62
62
|
"@wordpress/private-apis": "^0.33.1",
|
|
63
|
-
"@wordpress/reusable-blocks": "^4.28.
|
|
63
|
+
"@wordpress/reusable-blocks": "^4.28.8",
|
|
64
64
|
"@wordpress/router": "^0.20.1",
|
|
65
65
|
"@wordpress/style-engine": "^1.34.1",
|
|
66
66
|
"@wordpress/url": "^3.52.1",
|
|
67
67
|
"@wordpress/viewport": "^5.28.1",
|
|
68
|
-
"@wordpress/widgets": "^3.28.
|
|
68
|
+
"@wordpress/widgets": "^3.28.8",
|
|
69
69
|
"@wordpress/wordcount": "^3.51.1",
|
|
70
70
|
"change-case": "^4.1.2",
|
|
71
71
|
"classnames": "^2.3.1",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"publishConfig": {
|
|
86
86
|
"access": "public"
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "be077ee679b7b319a1d9eed46a74ffcbc5ad0b93"
|
|
89
89
|
}
|
|
@@ -35,12 +35,12 @@ import {
|
|
|
35
35
|
checkFontFaceInstalled,
|
|
36
36
|
} from './utils';
|
|
37
37
|
import { toggleFont } from './utils/toggleFont';
|
|
38
|
+
import setNestedValue from '../../../utils/set-nested-value';
|
|
38
39
|
|
|
39
40
|
export const FontLibraryContext = createContext( {} );
|
|
40
41
|
|
|
41
42
|
function FontLibraryProvider( { children } ) {
|
|
42
|
-
const {
|
|
43
|
-
useDispatch( coreStore );
|
|
43
|
+
const { saveEntityRecord } = useDispatch( coreStore );
|
|
44
44
|
const { globalStylesId } = useSelect( ( select ) => {
|
|
45
45
|
const { __experimentalGetCurrentGlobalStylesId } = select( coreStore );
|
|
46
46
|
return { globalStylesId: __experimentalGetCurrentGlobalStylesId() };
|
|
@@ -94,11 +94,30 @@ function FontLibraryProvider( { children } ) {
|
|
|
94
94
|
'base'
|
|
95
95
|
);
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
/*
|
|
98
|
+
* Save the font families to the database.
|
|
99
|
+
|
|
100
|
+
* This function is called when the user activates or deactivates a font family.
|
|
101
|
+
* It only updates the global styles post content in the database for new font families.
|
|
102
|
+
* This avoids saving other styles/settings changed by the user using other parts of the editor.
|
|
103
|
+
*
|
|
104
|
+
* It uses the font families from the param to avoid using the font families from an outdated state.
|
|
105
|
+
*
|
|
106
|
+
* @param {Array} fonts - The font families that will be saved to the database.
|
|
107
|
+
*/
|
|
108
|
+
const saveFontFamilies = async ( fonts ) => {
|
|
109
|
+
// Gets the global styles database post content.
|
|
110
|
+
const updatedGlobalStyles = globalStyles.record;
|
|
111
|
+
|
|
112
|
+
// Updates the database version of global styles with the edited font families in the client.
|
|
113
|
+
setNestedValue(
|
|
114
|
+
updatedGlobalStyles,
|
|
115
|
+
[ 'settings', 'typography', 'fontFamilies' ],
|
|
116
|
+
fonts
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
// Saves a new version of the global styles in the database.
|
|
120
|
+
await saveEntityRecord( 'root', 'globalStyles', updatedGlobalStyles );
|
|
102
121
|
};
|
|
103
122
|
|
|
104
123
|
// Library Fonts
|
|
@@ -322,15 +341,11 @@ function FontLibraryProvider( { children } ) {
|
|
|
322
341
|
|
|
323
342
|
if ( fontFamiliesToActivate.length > 0 ) {
|
|
324
343
|
// Activate the font family (add the font family to the global styles).
|
|
325
|
-
activateCustomFontFamilies(
|
|
326
|
-
|
|
327
|
-
// Save the global styles to the database.
|
|
328
|
-
await saveSpecifiedEntityEdits(
|
|
329
|
-
'root',
|
|
330
|
-
'globalStyles',
|
|
331
|
-
globalStylesId,
|
|
332
|
-
[ 'settings.typography.fontFamilies' ]
|
|
344
|
+
const activeFonts = activateCustomFontFamilies(
|
|
345
|
+
fontFamiliesToActivate
|
|
333
346
|
);
|
|
347
|
+
// Save the global styles to the database.
|
|
348
|
+
await saveFontFamilies( activeFonts );
|
|
334
349
|
|
|
335
350
|
refreshLibrary();
|
|
336
351
|
}
|
|
@@ -360,14 +375,11 @@ function FontLibraryProvider( { children } ) {
|
|
|
360
375
|
// Deactivate the font family if delete request is successful
|
|
361
376
|
// (Removes the font family from the global styles).
|
|
362
377
|
if ( uninstalledFontFamily.deleted ) {
|
|
363
|
-
deactivateFontFamily(
|
|
364
|
-
|
|
365
|
-
await saveSpecifiedEntityEdits(
|
|
366
|
-
'root',
|
|
367
|
-
'globalStyles',
|
|
368
|
-
globalStylesId,
|
|
369
|
-
[ 'settings.typography.fontFamilies' ]
|
|
378
|
+
const activeFonts = deactivateFontFamily(
|
|
379
|
+
fontFamilyToUninstall
|
|
370
380
|
);
|
|
381
|
+
// Save the global styles to the database.
|
|
382
|
+
await saveFontFamilies( activeFonts );
|
|
371
383
|
}
|
|
372
384
|
|
|
373
385
|
// Refresh the library (the library font families from database).
|
|
@@ -391,42 +403,54 @@ function FontLibraryProvider( { children } ) {
|
|
|
391
403
|
const newCustomFonts = initialCustomFonts.filter(
|
|
392
404
|
( f ) => f.slug !== font.slug
|
|
393
405
|
);
|
|
394
|
-
|
|
406
|
+
const activeFonts = {
|
|
395
407
|
...fontFamilies,
|
|
396
408
|
[ font.source ]: newCustomFonts,
|
|
397
|
-
}
|
|
409
|
+
};
|
|
410
|
+
setFontFamilies( activeFonts );
|
|
398
411
|
|
|
399
412
|
if ( font.fontFace ) {
|
|
400
413
|
font.fontFace.forEach( ( face ) => {
|
|
401
414
|
unloadFontFaceInBrowser( face, 'all' );
|
|
402
415
|
} );
|
|
403
416
|
}
|
|
417
|
+
return activeFonts;
|
|
404
418
|
};
|
|
405
419
|
|
|
406
420
|
const activateCustomFontFamilies = ( fontsToAdd ) => {
|
|
407
|
-
|
|
408
|
-
const fontsToActivate = fontsToAdd.map(
|
|
409
|
-
( { id: _familyDbId, fontFace, ...font } ) => ( {
|
|
410
|
-
...font,
|
|
411
|
-
...( fontFace && fontFace.length > 0
|
|
412
|
-
? {
|
|
413
|
-
fontFace: fontFace.map(
|
|
414
|
-
( { id: _faceDbId, ...face } ) => face
|
|
415
|
-
),
|
|
416
|
-
}
|
|
417
|
-
: {} ),
|
|
418
|
-
} )
|
|
419
|
-
);
|
|
421
|
+
const fontsToActivate = cleanFontsForSave( fontsToAdd );
|
|
420
422
|
|
|
421
|
-
|
|
422
|
-
setFontFamilies( {
|
|
423
|
+
const activeFonts = {
|
|
423
424
|
...fontFamilies,
|
|
424
425
|
// Merge the existing custom fonts with the new fonts.
|
|
425
426
|
custom: mergeFontFamilies( fontFamilies?.custom, fontsToActivate ),
|
|
426
|
-
}
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
// Activate the fonts by set the new custom fonts array.
|
|
430
|
+
setFontFamilies( activeFonts );
|
|
431
|
+
|
|
432
|
+
loadFontsInBrowser( fontsToActivate );
|
|
433
|
+
|
|
434
|
+
return activeFonts;
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
// Removes the id from the families and faces to avoid saving that to global styles post content.
|
|
438
|
+
const cleanFontsForSave = ( fonts ) => {
|
|
439
|
+
return fonts.map( ( { id: _familyDbId, fontFace, ...font } ) => ( {
|
|
440
|
+
...font,
|
|
441
|
+
...( fontFace && fontFace.length > 0
|
|
442
|
+
? {
|
|
443
|
+
fontFace: fontFace.map(
|
|
444
|
+
( { id: _faceDbId, ...face } ) => face
|
|
445
|
+
),
|
|
446
|
+
}
|
|
447
|
+
: {} ),
|
|
448
|
+
} ) );
|
|
449
|
+
};
|
|
427
450
|
|
|
451
|
+
const loadFontsInBrowser = ( fonts ) => {
|
|
428
452
|
// Add custom fonts to the browser.
|
|
429
|
-
|
|
453
|
+
fonts.forEach( ( font ) => {
|
|
430
454
|
if ( font.fontFace ) {
|
|
431
455
|
font.fontFace.forEach( ( face ) => {
|
|
432
456
|
// Load font faces just in the iframe because they already are in the document.
|
|
@@ -518,6 +542,7 @@ function FontLibraryProvider( { children } ) {
|
|
|
518
542
|
value={ {
|
|
519
543
|
libraryFontSelected,
|
|
520
544
|
handleSetLibraryFontSelected,
|
|
545
|
+
fontFamilies,
|
|
521
546
|
themeFonts,
|
|
522
547
|
baseThemeFonts,
|
|
523
548
|
customFonts,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { __ } from '@wordpress/i18n';
|
|
4
|
+
import { __, _x } from '@wordpress/i18n';
|
|
5
5
|
import {
|
|
6
6
|
Modal,
|
|
7
7
|
privateApis as componentsPrivateApis,
|
|
@@ -23,7 +23,7 @@ const { Tabs } = unlock( componentsPrivateApis );
|
|
|
23
23
|
|
|
24
24
|
const DEFAULT_TAB = {
|
|
25
25
|
id: 'installed-fonts',
|
|
26
|
-
title:
|
|
26
|
+
title: _x( 'Library', 'Font library' ),
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
const UPLOAD_TAB = {
|
|
@@ -49,6 +49,7 @@ function InstalledFonts() {
|
|
|
49
49
|
fontFamiliesHasChanges,
|
|
50
50
|
notice,
|
|
51
51
|
setNotice,
|
|
52
|
+
fontFamilies,
|
|
52
53
|
} = useContext( FontLibraryContext );
|
|
53
54
|
const [ isConfirmDeleteOpen, setIsConfirmDeleteOpen ] = useState( false );
|
|
54
55
|
const customFontFamilyId =
|
|
@@ -262,7 +263,9 @@ function InstalledFonts() {
|
|
|
262
263
|
) }
|
|
263
264
|
<Button
|
|
264
265
|
variant="primary"
|
|
265
|
-
onClick={
|
|
266
|
+
onClick={ () => {
|
|
267
|
+
saveFontFamilies( fontFamilies );
|
|
268
|
+
} }
|
|
266
269
|
disabled={ ! fontFamiliesHasChanges }
|
|
267
270
|
__experimentalIsFocusable
|
|
268
271
|
>
|
|
@@ -26,6 +26,7 @@ import { store as coreStore } from '@wordpress/core-data';
|
|
|
26
26
|
*/
|
|
27
27
|
import { useSupportedStyles } from '../../components/global-styles/hooks';
|
|
28
28
|
import { unlock } from '../../lock-unlock';
|
|
29
|
+
import setNestedValue from '../../utils/set-nested-value';
|
|
29
30
|
|
|
30
31
|
const { cleanEmptyObject, GlobalStylesContext } = unlock(
|
|
31
32
|
blockEditorPrivateApis
|
|
@@ -235,46 +236,6 @@ function useChangesToPush( name, attributes, userConfig ) {
|
|
|
235
236
|
}, [ supports, attributes, blockUserConfig ] );
|
|
236
237
|
}
|
|
237
238
|
|
|
238
|
-
/**
|
|
239
|
-
* Sets the value at path of object.
|
|
240
|
-
* If a portion of path doesn’t exist, it’s created.
|
|
241
|
-
* Arrays are created for missing index properties while objects are created
|
|
242
|
-
* for all other missing properties.
|
|
243
|
-
*
|
|
244
|
-
* This function intentionally mutates the input object.
|
|
245
|
-
*
|
|
246
|
-
* Inspired by _.set().
|
|
247
|
-
*
|
|
248
|
-
* @see https://lodash.com/docs/4.17.15#set
|
|
249
|
-
*
|
|
250
|
-
* @todo Needs to be deduplicated with its copy in `@wordpress/core-data`.
|
|
251
|
-
*
|
|
252
|
-
* @param {Object} object Object to modify
|
|
253
|
-
* @param {Array} path Path of the property to set.
|
|
254
|
-
* @param {*} value Value to set.
|
|
255
|
-
*/
|
|
256
|
-
function setNestedValue( object, path, value ) {
|
|
257
|
-
if ( ! object || typeof object !== 'object' ) {
|
|
258
|
-
return object;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
path.reduce( ( acc, key, idx ) => {
|
|
262
|
-
if ( acc[ key ] === undefined ) {
|
|
263
|
-
if ( Number.isInteger( path[ idx + 1 ] ) ) {
|
|
264
|
-
acc[ key ] = [];
|
|
265
|
-
} else {
|
|
266
|
-
acc[ key ] = {};
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
if ( idx === path.length - 1 ) {
|
|
270
|
-
acc[ key ] = value;
|
|
271
|
-
}
|
|
272
|
-
return acc[ key ];
|
|
273
|
-
}, object );
|
|
274
|
-
|
|
275
|
-
return object;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
239
|
function cloneDeep( object ) {
|
|
279
240
|
return ! object ? {} : JSON.parse( JSON.stringify( object ) );
|
|
280
241
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets the value at path of object.
|
|
3
|
+
* If a portion of path doesn’t exist, it’s created.
|
|
4
|
+
* Arrays are created for missing index properties while objects are created
|
|
5
|
+
* for all other missing properties.
|
|
6
|
+
*
|
|
7
|
+
* This function intentionally mutates the input object.
|
|
8
|
+
*
|
|
9
|
+
* Inspired by _.set().
|
|
10
|
+
*
|
|
11
|
+
* @see https://lodash.com/docs/4.17.15#set
|
|
12
|
+
*
|
|
13
|
+
* @todo Needs to be deduplicated with its copy in `@wordpress/core-data`.
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} object Object to modify
|
|
16
|
+
* @param {Array} path Path of the property to set.
|
|
17
|
+
* @param {*} value Value to set.
|
|
18
|
+
*/
|
|
19
|
+
export default function setNestedValue( object, path, value ) {
|
|
20
|
+
if ( ! object || typeof object !== 'object' ) {
|
|
21
|
+
return object;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
path.reduce( ( acc, key, idx ) => {
|
|
25
|
+
if ( acc[ key ] === undefined ) {
|
|
26
|
+
if ( Number.isInteger( path[ idx + 1 ] ) ) {
|
|
27
|
+
acc[ key ] = [];
|
|
28
|
+
} else {
|
|
29
|
+
acc[ key ] = {};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if ( idx === path.length - 1 ) {
|
|
33
|
+
acc[ key ] = value;
|
|
34
|
+
}
|
|
35
|
+
return acc[ key ];
|
|
36
|
+
}, object );
|
|
37
|
+
|
|
38
|
+
return object;
|
|
39
|
+
}
|