@wordpress/block-editor 14.3.3 → 14.3.4
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/README.md +42 -0
- package/build/components/media-placeholder/index.js +17 -19
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/rich-text/index.js +4 -8
- package/build/components/rich-text/index.js.map +1 -1
- package/build/hooks/block-bindings.js +6 -13
- package/build/hooks/block-bindings.js.map +1 -1
- package/build/hooks/use-bindings-attributes.js +5 -4
- package/build/hooks/use-bindings-attributes.js.map +1 -1
- package/build/private-apis.js +0 -2
- package/build/private-apis.js.map +1 -1
- package/build/utils/block-bindings.js +48 -0
- package/build/utils/block-bindings.js.map +1 -1
- package/build/utils/index.js +7 -0
- package/build/utils/index.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +18 -20
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/rich-text/index.js +4 -8
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/hooks/block-bindings.js +6 -13
- package/build-module/hooks/block-bindings.js.map +1 -1
- package/build-module/hooks/use-bindings-attributes.js +5 -4
- package/build-module/hooks/use-bindings-attributes.js.map +1 -1
- package/build-module/private-apis.js +0 -2
- package/build-module/private-apis.js.map +1 -1
- package/build-module/utils/block-bindings.js +48 -0
- package/build-module/utils/block-bindings.js.map +1 -1
- package/build-module/utils/index.js +1 -0
- package/build-module/utils/index.js.map +1 -1
- package/build-style/content-rtl.css +2 -14
- package/build-style/content.css +2 -14
- package/package.json +6 -6
- package/src/components/media-placeholder/content.scss +3 -19
- package/src/components/media-placeholder/index.js +17 -17
- package/src/components/rich-text/index.js +4 -13
- package/src/hooks/block-bindings.js +9 -10
- package/src/hooks/use-bindings-attributes.js +66 -63
- package/src/private-apis.js +0 -2
- package/src/utils/block-bindings.js +47 -0
- package/src/utils/index.js +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["store","blocksStore","createHigherOrderComponent","useRegistry","useSelect","useCallback","useMemo","useContext","addFilter","isURLLike","unlock","BlockContext","jsx","_jsx","Fragment","_Fragment","BLOCK_BINDINGS_ALLOWED_BLOCKS","DEFAULT_ATTRIBUTE","replacePatternOverrideDefaultBindings","blockName","bindings","source","supportedAttributes","bindingsWithDefaults","attributeName","bindingSource","canBindBlock","canBindAttribute","includes","getBindableAttributes","withBlockBindingSupport","BlockEdit","props","registry","blockContext","sources","select","getAllBlockBindingsSources","name","clientId","context","setAttributes","blockBindings","attributes","metadata","updatedContext","boundAttributes","blockBindingsBySource","Map","binding","Object","entries","sourceName","args","sourceArgs","key","usesContext","set","get","size","values","getValues","keys","forEach","attr","label","value","hasParentPattern","hasPatternOverridesDefaultBinding","_setAttributes","nextAttributes","batch","keptAttributes","newValue","setValues","length","caption","href","children","shimAttributeSource","settings","edit"],"sources":["@wordpress/block-editor/src/hooks/use-bindings-attributes.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { useCallback, useMemo, useContext } from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport isURLLike from '../components/link-control/is-url-like';\nimport { unlock } from '../lock-unlock';\nimport BlockContext from '../components/block-context';\n\n/** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */\n/** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */\n\n/**\n * Given a binding of block attributes, returns a higher order component that\n * overrides its `attributes` and `setAttributes` props to sync any changes needed.\n *\n * @return {WPHigherOrderComponent} Higher-order component.\n */\n\nconst BLOCK_BINDINGS_ALLOWED_BLOCKS = {\n\t'core/paragraph': [ 'content' ],\n\t'core/heading': [ 'content' ],\n\t'core/image': [ 'id', 'url', 'title', 'alt' ],\n\t'core/button': [ 'url', 'text', 'linkTarget', 'rel' ],\n};\n\nconst DEFAULT_ATTRIBUTE = '__default';\n\n/**\n * Returns the bindings with the `__default` binding for pattern overrides\n * replaced with the full-set of supported attributes. e.g.:\n *\n * bindings passed in: `{ __default: { source: 'core/pattern-overrides' } }`\n * bindings returned: `{ content: { source: 'core/pattern-overrides' } }`\n *\n * @param {string} blockName The block name (e.g. 'core/paragraph').\n * @param {Object} bindings A block's bindings from the metadata attribute.\n *\n * @return {Object} The bindings with default replaced for pattern overrides.\n */\nfunction replacePatternOverrideDefaultBindings( blockName, bindings ) {\n\t// The `__default` binding currently only works for pattern overrides.\n\tif (\n\t\tbindings?.[ DEFAULT_ATTRIBUTE ]?.source === 'core/pattern-overrides'\n\t) {\n\t\tconst supportedAttributes = BLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ];\n\t\tconst bindingsWithDefaults = {};\n\t\tfor ( const attributeName of supportedAttributes ) {\n\t\t\t// If the block has mixed binding sources, retain any non pattern override bindings.\n\t\t\tconst bindingSource = bindings[ attributeName ]\n\t\t\t\t? bindings[ attributeName ]\n\t\t\t\t: { source: 'core/pattern-overrides' };\n\t\t\tbindingsWithDefaults[ attributeName ] = bindingSource;\n\t\t}\n\n\t\treturn bindingsWithDefaults;\n\t}\n\n\treturn bindings;\n}\n\n/**\n * Based on the given block name,\n * check if it is possible to bind the block.\n *\n * @param {string} blockName - The block name.\n * @return {boolean} Whether it is possible to bind the block to sources.\n */\nexport function canBindBlock( blockName ) {\n\treturn blockName in BLOCK_BINDINGS_ALLOWED_BLOCKS;\n}\n\n/**\n * Based on the given block name and attribute name,\n * check if it is possible to bind the block attribute.\n *\n * @param {string} blockName - The block name.\n * @param {string} attributeName - The attribute name.\n * @return {boolean} Whether it is possible to bind the block attribute.\n */\nexport function canBindAttribute( blockName, attributeName ) {\n\treturn (\n\t\tcanBindBlock( blockName ) &&\n\t\tBLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ].includes( attributeName )\n\t);\n}\n\nexport function getBindableAttributes( blockName ) {\n\treturn BLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ];\n}\n\nexport const withBlockBindingSupport = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst registry = useRegistry();\n\t\tconst blockContext = useContext( BlockContext );\n\t\tconst sources = useSelect( ( select ) =>\n\t\t\tunlock( select( blocksStore ) ).getAllBlockBindingsSources()\n\t\t);\n\t\tconst { name, clientId, context, setAttributes } = props;\n\t\tconst blockBindings = useMemo(\n\t\t\t() =>\n\t\t\t\treplacePatternOverrideDefaultBindings(\n\t\t\t\t\tname,\n\t\t\t\t\tprops.attributes.metadata?.bindings\n\t\t\t\t),\n\t\t\t[ props.attributes.metadata?.bindings, name ]\n\t\t);\n\n\t\t// While this hook doesn't directly call any selectors, `useSelect` is\n\t\t// used purposely here to ensure `boundAttributes` is updated whenever\n\t\t// there are attribute updates.\n\t\t// `source.getValues` may also call a selector via `registry.select`.\n\t\tconst updatedContext = {};\n\t\tconst boundAttributes = useSelect( () => {\n\t\t\tif ( ! blockBindings ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst attributes = {};\n\n\t\t\tconst blockBindingsBySource = new Map();\n\n\t\t\tfor ( const [ attributeName, binding ] of Object.entries(\n\t\t\t\tblockBindings\n\t\t\t) ) {\n\t\t\t\tconst { source: sourceName, args: sourceArgs } = binding;\n\t\t\t\tconst source = sources[ sourceName ];\n\t\t\t\tif ( ! source || ! canBindAttribute( name, attributeName ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// Populate context.\n\t\t\t\tfor ( const key of source.usesContext || [] ) {\n\t\t\t\t\tupdatedContext[ key ] = blockContext[ key ];\n\t\t\t\t}\n\n\t\t\t\tblockBindingsBySource.set( source, {\n\t\t\t\t\t...blockBindingsBySource.get( source ),\n\t\t\t\t\t[ attributeName ]: {\n\t\t\t\t\t\targs: sourceArgs,\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tif ( blockBindingsBySource.size ) {\n\t\t\t\tfor ( const [ source, bindings ] of blockBindingsBySource ) {\n\t\t\t\t\t// Get values in batch if the source supports it.\n\t\t\t\t\tlet values = {};\n\t\t\t\t\tif ( ! source.getValues ) {\n\t\t\t\t\t\tObject.keys( bindings ).forEach( ( attr ) => {\n\t\t\t\t\t\t\t// Default to the the source label when `getValues` doesn't exist.\n\t\t\t\t\t\t\tvalues[ attr ] = source.label;\n\t\t\t\t\t\t} );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvalues = source.getValues( {\n\t\t\t\t\t\t\tregistry,\n\t\t\t\t\t\t\tcontext: updatedContext,\n\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\tbindings,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t\tfor ( const [ attributeName, value ] of Object.entries(\n\t\t\t\t\t\tvalues\n\t\t\t\t\t) ) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tattributeName === 'url' &&\n\t\t\t\t\t\t\t( ! value || ! isURLLike( value ) )\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// Return null if value is not a valid URL.\n\t\t\t\t\t\t\tattributes[ attributeName ] = null;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tattributes[ attributeName ] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn attributes;\n\t\t}, [\n\t\t\tblockBindings,\n\t\t\tname,\n\t\t\tclientId,\n\t\t\tupdatedContext,\n\t\t\tregistry,\n\t\t\tsources,\n\t\t] );\n\n\t\tconst hasParentPattern = !! updatedContext[ 'pattern/overrides' ];\n\t\tconst hasPatternOverridesDefaultBinding =\n\t\t\tprops.attributes.metadata?.bindings?.[ DEFAULT_ATTRIBUTE ]\n\t\t\t\t?.source === 'core/pattern-overrides';\n\n\t\tconst _setAttributes = useCallback(\n\t\t\t( nextAttributes ) => {\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\tif ( ! blockBindings ) {\n\t\t\t\t\t\tsetAttributes( nextAttributes );\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst keptAttributes = { ...nextAttributes };\n\t\t\t\t\tconst blockBindingsBySource = new Map();\n\n\t\t\t\t\t// Loop only over the updated attributes to avoid modifying the bound ones that haven't changed.\n\t\t\t\t\tfor ( const [ attributeName, newValue ] of Object.entries(\n\t\t\t\t\t\tkeptAttributes\n\t\t\t\t\t) ) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t! blockBindings[ attributeName ] ||\n\t\t\t\t\t\t\t! canBindAttribute( name, attributeName )\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst binding = blockBindings[ attributeName ];\n\t\t\t\t\t\tconst source = sources[ binding?.source ];\n\t\t\t\t\t\tif ( ! source?.setValues ) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tblockBindingsBySource.set( source, {\n\t\t\t\t\t\t\t...blockBindingsBySource.get( source ),\n\t\t\t\t\t\t\t[ attributeName ]: {\n\t\t\t\t\t\t\t\targs: binding.args,\n\t\t\t\t\t\t\t\tnewValue,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} );\n\t\t\t\t\t\tdelete keptAttributes[ attributeName ];\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( blockBindingsBySource.size ) {\n\t\t\t\t\t\tfor ( const [\n\t\t\t\t\t\t\tsource,\n\t\t\t\t\t\t\tbindings,\n\t\t\t\t\t\t] of blockBindingsBySource ) {\n\t\t\t\t\t\t\tsource.setValues( {\n\t\t\t\t\t\t\t\tregistry,\n\t\t\t\t\t\t\t\tcontext: updatedContext,\n\t\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\t\tbindings,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\t// Don't update non-connected attributes if the block is using pattern overrides\n\t\t\t\t\t\t// and the editing is happening while overriding the pattern (not editing the original).\n\t\t\t\t\t\t! (\n\t\t\t\t\t\t\thasPatternOverridesDefaultBinding &&\n\t\t\t\t\t\t\thasParentPattern\n\t\t\t\t\t\t) &&\n\t\t\t\t\t\tObject.keys( keptAttributes ).length\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Don't update caption and href until they are supported.\n\t\t\t\t\t\tif ( hasPatternOverridesDefaultBinding ) {\n\t\t\t\t\t\t\tdelete keptAttributes?.caption;\n\t\t\t\t\t\t\tdelete keptAttributes?.href;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsetAttributes( keptAttributes );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t},\n\t\t\t[\n\t\t\t\tregistry,\n\t\t\t\tblockBindings,\n\t\t\t\tname,\n\t\t\t\tclientId,\n\t\t\t\tupdatedContext,\n\t\t\t\tsetAttributes,\n\t\t\t\tsources,\n\t\t\t\thasPatternOverridesDefaultBinding,\n\t\t\t\thasParentPattern,\n\t\t\t]\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit\n\t\t\t\t\t{ ...props }\n\t\t\t\t\tattributes={ { ...props.attributes, ...boundAttributes } }\n\t\t\t\t\tsetAttributes={ _setAttributes }\n\t\t\t\t\tcontext={ { ...context, ...updatedContext } }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n\t'withBlockBindingSupport'\n);\n\n/**\n * Filters a registered block's settings to enhance a block's `edit` component\n * to upgrade bound attributes.\n *\n * @param {WPBlockSettings} settings - Registered block settings.\n * @param {string} name - Block name.\n * @return {WPBlockSettings} Filtered block settings.\n */\nfunction shimAttributeSource( settings, name ) {\n\tif ( ! canBindBlock( name ) ) {\n\t\treturn settings;\n\t}\n\n\treturn {\n\t\t...settings,\n\t\tedit: withBlockBindingSupport( settings.edit ),\n\t};\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/editor/custom-sources-backwards-comp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,eACCjE,IAAA,CAACkB,SAAS;MAAA,GACJC,KAAK;MACVW,UAAU,EAAG;QAAE,GAAGX,KAAK,CAACW,UAAU;QAAE,GAAGG;MAAgB,CAAG;MAC1DL,aAAa,EAAG4B,cAAgB;MAChC7B,OAAO,EAAG;QAAE,GAAGA,OAAO;QAAE,GAAGK;MAAe;IAAG,CAC7C;EAAC,CACD,CAAC;AAEL,CAAC,EACD,yBACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASkC,mBAAmBA,CAAEC,QAAQ,EAAE1C,IAAI,EAAG;EAC9C,IAAK,CAAEZ,YAAY,CAAEY,IAAK,CAAC,EAAG;IAC7B,OAAO0C,QAAQ;EAChB;EAEA,OAAO;IACN,GAAGA,QAAQ;IACXC,IAAI,EAAEnD,uBAAuB,CAAEkD,QAAQ,CAACC,IAAK;EAC9C,CAAC;AACF;AAEAzE,SAAS,CACR,0BAA0B,EAC1B,0EAA0E,EAC1EuE,mBACD,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["store","blocksStore","createHigherOrderComponent","useRegistry","useSelect","useCallback","useMemo","useContext","addFilter","isURLLike","unlock","BlockContext","jsx","_jsx","Fragment","_Fragment","BLOCK_BINDINGS_ALLOWED_BLOCKS","DEFAULT_ATTRIBUTE","replacePatternOverrideDefaultBindings","blockName","bindings","source","supportedAttributes","bindingsWithDefaults","attributeName","bindingSource","canBindBlock","canBindAttribute","includes","getBindableAttributes","withBlockBindingSupport","BlockEdit","props","registry","blockContext","sources","select","getAllBlockBindingsSources","name","clientId","context","setAttributes","blockBindings","attributes","metadata","updatedContext","boundAttributes","blockBindingsBySource","Map","binding","Object","entries","sourceName","args","sourceArgs","key","usesContext","set","get","size","values","getValues","keys","forEach","attr","label","value","hasParentPattern","hasPatternOverridesDefaultBinding","_setAttributes","nextAttributes","batch","keptAttributes","newValue","setValues","dispatch","length","caption","href","children","shimAttributeSource","settings","edit"],"sources":["@wordpress/block-editor/src/hooks/use-bindings-attributes.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { useCallback, useMemo, useContext } from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport isURLLike from '../components/link-control/is-url-like';\nimport { unlock } from '../lock-unlock';\nimport BlockContext from '../components/block-context';\n\n/** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */\n/** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */\n\n/**\n * Given a binding of block attributes, returns a higher order component that\n * overrides its `attributes` and `setAttributes` props to sync any changes needed.\n *\n * @return {WPHigherOrderComponent} Higher-order component.\n */\n\nconst BLOCK_BINDINGS_ALLOWED_BLOCKS = {\n\t'core/paragraph': [ 'content' ],\n\t'core/heading': [ 'content' ],\n\t'core/image': [ 'id', 'url', 'title', 'alt' ],\n\t'core/button': [ 'url', 'text', 'linkTarget', 'rel' ],\n};\n\nconst DEFAULT_ATTRIBUTE = '__default';\n\n/**\n * Returns the bindings with the `__default` binding for pattern overrides\n * replaced with the full-set of supported attributes. e.g.:\n *\n * bindings passed in: `{ __default: { source: 'core/pattern-overrides' } }`\n * bindings returned: `{ content: { source: 'core/pattern-overrides' } }`\n *\n * @param {string} blockName The block name (e.g. 'core/paragraph').\n * @param {Object} bindings A block's bindings from the metadata attribute.\n *\n * @return {Object} The bindings with default replaced for pattern overrides.\n */\nfunction replacePatternOverrideDefaultBindings( blockName, bindings ) {\n\t// The `__default` binding currently only works for pattern overrides.\n\tif (\n\t\tbindings?.[ DEFAULT_ATTRIBUTE ]?.source === 'core/pattern-overrides'\n\t) {\n\t\tconst supportedAttributes = BLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ];\n\t\tconst bindingsWithDefaults = {};\n\t\tfor ( const attributeName of supportedAttributes ) {\n\t\t\t// If the block has mixed binding sources, retain any non pattern override bindings.\n\t\t\tconst bindingSource = bindings[ attributeName ]\n\t\t\t\t? bindings[ attributeName ]\n\t\t\t\t: { source: 'core/pattern-overrides' };\n\t\t\tbindingsWithDefaults[ attributeName ] = bindingSource;\n\t\t}\n\n\t\treturn bindingsWithDefaults;\n\t}\n\n\treturn bindings;\n}\n\n/**\n * Based on the given block name,\n * check if it is possible to bind the block.\n *\n * @param {string} blockName - The block name.\n * @return {boolean} Whether it is possible to bind the block to sources.\n */\nexport function canBindBlock( blockName ) {\n\treturn blockName in BLOCK_BINDINGS_ALLOWED_BLOCKS;\n}\n\n/**\n * Based on the given block name and attribute name,\n * check if it is possible to bind the block attribute.\n *\n * @param {string} blockName - The block name.\n * @param {string} attributeName - The attribute name.\n * @return {boolean} Whether it is possible to bind the block attribute.\n */\nexport function canBindAttribute( blockName, attributeName ) {\n\treturn (\n\t\tcanBindBlock( blockName ) &&\n\t\tBLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ].includes( attributeName )\n\t);\n}\n\nexport function getBindableAttributes( blockName ) {\n\treturn BLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ];\n}\n\nexport const withBlockBindingSupport = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst registry = useRegistry();\n\t\tconst blockContext = useContext( BlockContext );\n\t\tconst sources = useSelect( ( select ) =>\n\t\t\tunlock( select( blocksStore ) ).getAllBlockBindingsSources()\n\t\t);\n\t\tconst { name, clientId, context, setAttributes } = props;\n\t\tconst blockBindings = useMemo(\n\t\t\t() =>\n\t\t\t\treplacePatternOverrideDefaultBindings(\n\t\t\t\t\tname,\n\t\t\t\t\tprops.attributes.metadata?.bindings\n\t\t\t\t),\n\t\t\t[ props.attributes.metadata?.bindings, name ]\n\t\t);\n\n\t\t// While this hook doesn't directly call any selectors, `useSelect` is\n\t\t// used purposely here to ensure `boundAttributes` is updated whenever\n\t\t// there are attribute updates.\n\t\t// `source.getValues` may also call a selector via `registry.select`.\n\t\tconst updatedContext = {};\n\t\tconst boundAttributes = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tif ( ! blockBindings ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst attributes = {};\n\n\t\t\t\tconst blockBindingsBySource = new Map();\n\n\t\t\t\tfor ( const [ attributeName, binding ] of Object.entries(\n\t\t\t\t\tblockBindings\n\t\t\t\t) ) {\n\t\t\t\t\tconst { source: sourceName, args: sourceArgs } = binding;\n\t\t\t\t\tconst source = sources[ sourceName ];\n\t\t\t\t\tif (\n\t\t\t\t\t\t! source ||\n\t\t\t\t\t\t! canBindAttribute( name, attributeName )\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Populate context.\n\t\t\t\t\tfor ( const key of source.usesContext || [] ) {\n\t\t\t\t\t\tupdatedContext[ key ] = blockContext[ key ];\n\t\t\t\t\t}\n\n\t\t\t\t\tblockBindingsBySource.set( source, {\n\t\t\t\t\t\t...blockBindingsBySource.get( source ),\n\t\t\t\t\t\t[ attributeName ]: {\n\t\t\t\t\t\t\targs: sourceArgs,\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\tif ( blockBindingsBySource.size ) {\n\t\t\t\t\tfor ( const [\n\t\t\t\t\t\tsource,\n\t\t\t\t\t\tbindings,\n\t\t\t\t\t] of blockBindingsBySource ) {\n\t\t\t\t\t\t// Get values in batch if the source supports it.\n\t\t\t\t\t\tlet values = {};\n\t\t\t\t\t\tif ( ! source.getValues ) {\n\t\t\t\t\t\t\tObject.keys( bindings ).forEach( ( attr ) => {\n\t\t\t\t\t\t\t\t// Default to the the source label when `getValues` doesn't exist.\n\t\t\t\t\t\t\t\tvalues[ attr ] = source.label;\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tvalues = source.getValues( {\n\t\t\t\t\t\t\t\tselect,\n\t\t\t\t\t\t\t\tcontext: updatedContext,\n\t\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\t\tbindings,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t}\n\t\t\t\t\t\tfor ( const [ attributeName, value ] of Object.entries(\n\t\t\t\t\t\t\tvalues\n\t\t\t\t\t\t) ) {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tattributeName === 'url' &&\n\t\t\t\t\t\t\t\t( ! value || ! isURLLike( value ) )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t// Return null if value is not a valid URL.\n\t\t\t\t\t\t\t\tattributes[ attributeName ] = null;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tattributes[ attributeName ] = value;\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\n\t\t\t\treturn attributes;\n\t\t\t},\n\t\t\t[ blockBindings, name, clientId, updatedContext, sources ]\n\t\t);\n\n\t\tconst hasParentPattern = !! updatedContext[ 'pattern/overrides' ];\n\t\tconst hasPatternOverridesDefaultBinding =\n\t\t\tprops.attributes.metadata?.bindings?.[ DEFAULT_ATTRIBUTE ]\n\t\t\t\t?.source === 'core/pattern-overrides';\n\n\t\tconst _setAttributes = useCallback(\n\t\t\t( nextAttributes ) => {\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\tif ( ! blockBindings ) {\n\t\t\t\t\t\tsetAttributes( nextAttributes );\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst keptAttributes = { ...nextAttributes };\n\t\t\t\t\tconst blockBindingsBySource = new Map();\n\n\t\t\t\t\t// Loop only over the updated attributes to avoid modifying the bound ones that haven't changed.\n\t\t\t\t\tfor ( const [ attributeName, newValue ] of Object.entries(\n\t\t\t\t\t\tkeptAttributes\n\t\t\t\t\t) ) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t! blockBindings[ attributeName ] ||\n\t\t\t\t\t\t\t! canBindAttribute( name, attributeName )\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst binding = blockBindings[ attributeName ];\n\t\t\t\t\t\tconst source = sources[ binding?.source ];\n\t\t\t\t\t\tif ( ! source?.setValues ) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tblockBindingsBySource.set( source, {\n\t\t\t\t\t\t\t...blockBindingsBySource.get( source ),\n\t\t\t\t\t\t\t[ attributeName ]: {\n\t\t\t\t\t\t\t\targs: binding.args,\n\t\t\t\t\t\t\t\tnewValue,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} );\n\t\t\t\t\t\tdelete keptAttributes[ attributeName ];\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( blockBindingsBySource.size ) {\n\t\t\t\t\t\tfor ( const [\n\t\t\t\t\t\t\tsource,\n\t\t\t\t\t\t\tbindings,\n\t\t\t\t\t\t] of blockBindingsBySource ) {\n\t\t\t\t\t\t\tsource.setValues( {\n\t\t\t\t\t\t\t\tselect: registry.select,\n\t\t\t\t\t\t\t\tdispatch: registry.dispatch,\n\t\t\t\t\t\t\t\tcontext: updatedContext,\n\t\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\t\tbindings,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\t// Don't update non-connected attributes if the block is using pattern overrides\n\t\t\t\t\t\t// and the editing is happening while overriding the pattern (not editing the original).\n\t\t\t\t\t\t! (\n\t\t\t\t\t\t\thasPatternOverridesDefaultBinding &&\n\t\t\t\t\t\t\thasParentPattern\n\t\t\t\t\t\t) &&\n\t\t\t\t\t\tObject.keys( keptAttributes ).length\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Don't update caption and href until they are supported.\n\t\t\t\t\t\tif ( hasPatternOverridesDefaultBinding ) {\n\t\t\t\t\t\t\tdelete keptAttributes?.caption;\n\t\t\t\t\t\t\tdelete keptAttributes?.href;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsetAttributes( keptAttributes );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t},\n\t\t\t[\n\t\t\t\tregistry,\n\t\t\t\tblockBindings,\n\t\t\t\tname,\n\t\t\t\tclientId,\n\t\t\t\tupdatedContext,\n\t\t\t\tsetAttributes,\n\t\t\t\tsources,\n\t\t\t\thasPatternOverridesDefaultBinding,\n\t\t\t\thasParentPattern,\n\t\t\t]\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit\n\t\t\t\t\t{ ...props }\n\t\t\t\t\tattributes={ { ...props.attributes, ...boundAttributes } }\n\t\t\t\t\tsetAttributes={ _setAttributes }\n\t\t\t\t\tcontext={ { ...context, ...updatedContext } }\n\t\t\t\t/>\n\t\t\t</>\n\t\t);\n\t},\n\t'withBlockBindingSupport'\n);\n\n/**\n * Filters a registered block's settings to enhance a block's `edit` component\n * to upgrade bound attributes.\n *\n * @param {WPBlockSettings} settings - Registered block settings.\n * @param {string} name - Block name.\n * @return {WPBlockSettings} Filtered block settings.\n */\nfunction shimAttributeSource( settings, name ) {\n\tif ( ! canBindBlock( name ) ) {\n\t\treturn settings;\n\t}\n\n\treturn {\n\t\t...settings,\n\t\tedit: withBlockBindingSupport( settings.edit ),\n\t};\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/editor/custom-sources-backwards-compatibility/shim-attribute-source',\n\tshimAttributeSource\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACxD,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,WAAW,EAAEC,OAAO,EAAEC,UAAU,QAAQ,oBAAoB;AACrE,SAASC,SAAS,QAAQ,kBAAkB;;AAE5C;AACA;AACA;AACA,OAAOC,SA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yBACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASmC,mBAAmBA,CAAEC,QAAQ,EAAE3C,IAAI,EAAG;EAC9C,IAAK,CAAEZ,YAAY,CAAEY,IAAK,CAAC,EAAG;IAC7B,OAAO2C,QAAQ;EAChB;EAEA,OAAO;IACN,GAAGA,QAAQ;IACXC,IAAI,EAAEpD,uBAAuB,CAAEmD,QAAQ,CAACC,IAAK;EAC9C,CAAC;AACF;AAEA1E,SAAS,CACR,0BAA0B,EAC1B,0EAA0E,EAC1EwE,mBACD,CAAC","ignoreList":[]}
|
|
@@ -32,7 +32,6 @@ import { PrivatePublishDateTimePicker } from './components/publish-date-time-pic
|
|
|
32
32
|
import useSpacingSizes from './components/spacing-sizes-control/hooks/use-spacing-sizes';
|
|
33
33
|
import useBlockDisplayTitle from './components/block-title/use-block-display-title';
|
|
34
34
|
import TabbedSidebar from './components/tabbed-sidebar';
|
|
35
|
-
import { useBlockBindingsUtils } from './utils/block-bindings';
|
|
36
35
|
|
|
37
36
|
/**
|
|
38
37
|
* Private @wordpress/block-editor APIs.
|
|
@@ -77,7 +76,6 @@ lock(privateApis, {
|
|
|
77
76
|
useBlockDisplayTitle,
|
|
78
77
|
__unstableBlockStyleVariationOverridesWithConfig,
|
|
79
78
|
setBackgroundStyleDefaults,
|
|
80
|
-
useBlockBindingsUtils,
|
|
81
79
|
sectionRootClientIdKey
|
|
82
80
|
});
|
|
83
81
|
//# sourceMappingURL=private-apis.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["globalStyles","ExperimentalBlockEditorProvider","lock","getRichTextValues","ResizableBoxPopover","default","PrivateQuickInserter","extractWords","getNormalizedSearchTerms","normalizeString","PrivateListView","BlockInfo","useHasBlockToolbar","cleanEmptyObject","BlockQuickNavigation","LayoutStyle","BlockRemovalWarningModal","setBackgroundStyleDefaults","useLayoutClasses","useLayoutStyles","__unstableBlockStyleVariationOverridesWithConfig","DimensionsTool","ResolutionTool","TextAlignmentControl","usesContextKey","ExperimentalBlockCanvas","getDuotoneFilter","useFlashEditableBlocks","selectBlockPatternsKey","reusableBlocksSelectKey","globalStylesDataKey","globalStylesLinksDataKey","sectionRootClientIdKey","requiresWrapperOnCopy","PrivateRichText","PrivateBlockPopover","PrivateInserterLibrary","PrivatePublishDateTimePicker","useSpacingSizes","useBlockDisplayTitle","TabbedSidebar","
|
|
1
|
+
{"version":3,"names":["globalStyles","ExperimentalBlockEditorProvider","lock","getRichTextValues","ResizableBoxPopover","default","PrivateQuickInserter","extractWords","getNormalizedSearchTerms","normalizeString","PrivateListView","BlockInfo","useHasBlockToolbar","cleanEmptyObject","BlockQuickNavigation","LayoutStyle","BlockRemovalWarningModal","setBackgroundStyleDefaults","useLayoutClasses","useLayoutStyles","__unstableBlockStyleVariationOverridesWithConfig","DimensionsTool","ResolutionTool","TextAlignmentControl","usesContextKey","ExperimentalBlockCanvas","getDuotoneFilter","useFlashEditableBlocks","selectBlockPatternsKey","reusableBlocksSelectKey","globalStylesDataKey","globalStylesLinksDataKey","sectionRootClientIdKey","requiresWrapperOnCopy","PrivateRichText","PrivateBlockPopover","PrivateInserterLibrary","PrivatePublishDateTimePicker","useSpacingSizes","useBlockDisplayTitle","TabbedSidebar","privateApis"],"sources":["@wordpress/block-editor/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport * as globalStyles from './components/global-styles';\nimport { ExperimentalBlockEditorProvider } from './components/provider';\nimport { lock } from './lock-unlock';\nimport { getRichTextValues } from './components/rich-text/get-rich-text-values';\nimport ResizableBoxPopover from './components/resizable-box-popover';\nimport { default as PrivateQuickInserter } from './components/inserter/quick-inserter';\nimport {\n\textractWords,\n\tgetNormalizedSearchTerms,\n\tnormalizeString,\n} from './components/inserter/search-items';\nimport { PrivateListView } from './components/list-view';\nimport BlockInfo from './components/block-info-slot-fill';\nimport { useHasBlockToolbar } from './components/block-toolbar/use-has-block-toolbar';\nimport { cleanEmptyObject } from './hooks/utils';\nimport BlockQuickNavigation from './components/block-quick-navigation';\nimport { LayoutStyle } from './components/block-list/layout';\nimport { BlockRemovalWarningModal } from './components/block-removal-warning-modal';\nimport {\n\tsetBackgroundStyleDefaults,\n\tuseLayoutClasses,\n\tuseLayoutStyles,\n\t__unstableBlockStyleVariationOverridesWithConfig,\n} from './hooks';\nimport DimensionsTool from './components/dimensions-tool';\nimport ResolutionTool from './components/resolution-tool';\nimport TextAlignmentControl from './components/text-alignment-control';\nimport { usesContextKey } from './components/rich-text/format-edit';\nimport { ExperimentalBlockCanvas } from './components/block-canvas';\nimport { getDuotoneFilter } from './components/duotone/utils';\nimport { useFlashEditableBlocks } from './components/use-flash-editable-blocks';\nimport {\n\tselectBlockPatternsKey,\n\treusableBlocksSelectKey,\n\tglobalStylesDataKey,\n\tglobalStylesLinksDataKey,\n\tsectionRootClientIdKey,\n} from './store/private-keys';\nimport { requiresWrapperOnCopy } from './components/writing-flow/utils';\nimport { PrivateRichText } from './components/rich-text/';\nimport { PrivateBlockPopover } from './components/block-popover';\nimport { PrivateInserterLibrary } from './components/inserter/library';\nimport { PrivatePublishDateTimePicker } from './components/publish-date-time-picker';\nimport useSpacingSizes from './components/spacing-sizes-control/hooks/use-spacing-sizes';\nimport useBlockDisplayTitle from './components/block-title/use-block-display-title';\nimport TabbedSidebar from './components/tabbed-sidebar';\n\n/**\n * Private @wordpress/block-editor APIs.\n */\nexport const privateApis = {};\nlock( privateApis, {\n\t...globalStyles,\n\tExperimentalBlockCanvas,\n\tExperimentalBlockEditorProvider,\n\tgetDuotoneFilter,\n\tgetRichTextValues,\n\tPrivateQuickInserter,\n\textractWords,\n\tgetNormalizedSearchTerms,\n\tnormalizeString,\n\tPrivateListView,\n\tResizableBoxPopover,\n\tBlockInfo,\n\tuseHasBlockToolbar,\n\tcleanEmptyObject,\n\tBlockQuickNavigation,\n\tLayoutStyle,\n\tBlockRemovalWarningModal,\n\tuseLayoutClasses,\n\tuseLayoutStyles,\n\tDimensionsTool,\n\tResolutionTool,\n\tTabbedSidebar,\n\tTextAlignmentControl,\n\tusesContextKey,\n\tuseFlashEditableBlocks,\n\tglobalStylesDataKey,\n\tglobalStylesLinksDataKey,\n\tselectBlockPatternsKey,\n\trequiresWrapperOnCopy,\n\tPrivateRichText,\n\tPrivateInserterLibrary,\n\treusableBlocksSelectKey,\n\tPrivateBlockPopover,\n\tPrivatePublishDateTimePicker,\n\tuseSpacingSizes,\n\tuseBlockDisplayTitle,\n\t__unstableBlockStyleVariationOverridesWithConfig,\n\tsetBackgroundStyleDefaults,\n\tsectionRootClientIdKey,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,KAAKA,YAAY,MAAM,4BAA4B;AAC1D,SAASC,+BAA+B,QAAQ,uBAAuB;AACvE,SAASC,IAAI,QAAQ,eAAe;AACpC,SAASC,iBAAiB,QAAQ,6CAA6C;AAC/E,OAAOC,mBAAmB,MAAM,oCAAoC;AACpE,SAASC,OAAO,IAAIC,oBAAoB,QAAQ,sCAAsC;AACtF,SACCC,YAAY,EACZC,wBAAwB,EACxBC,eAAe,QACT,oCAAoC;AAC3C,SAASC,eAAe,QAAQ,wBAAwB;AACxD,OAAOC,SAAS,MAAM,mCAAmC;AACzD,SAASC,kBAAkB,QAAQ,kDAAkD;AACrF,SAASC,gBAAgB,QAAQ,eAAe;AAChD,OAAOC,oBAAoB,MAAM,qCAAqC;AACtE,SAASC,WAAW,QAAQ,gCAAgC;AAC5D,SAASC,wBAAwB,QAAQ,0CAA0C;AACnF,SACCC,0BAA0B,EAC1BC,gBAAgB,EAChBC,eAAe,EACfC,gDAAgD,QAC1C,SAAS;AAChB,OAAOC,cAAc,MAAM,8BAA8B;AACzD,OAAOC,cAAc,MAAM,8BAA8B;AACzD,OAAOC,oBAAoB,MAAM,qCAAqC;AACtE,SAASC,cAAc,QAAQ,oCAAoC;AACnE,SAASC,uBAAuB,QAAQ,2BAA2B;AACnE,SAASC,gBAAgB,QAAQ,4BAA4B;AAC7D,SAASC,sBAAsB,QAAQ,wCAAwC;AAC/E,SACCC,sBAAsB,EACtBC,uBAAuB,EACvBC,mBAAmB,EACnBC,wBAAwB,EACxBC,sBAAsB,QAChB,sBAAsB;AAC7B,SAASC,qBAAqB,QAAQ,iCAAiC;AACvE,SAASC,eAAe,QAAQ,yBAAyB;AACzD,SAASC,mBAAmB,QAAQ,4BAA4B;AAChE,SAASC,sBAAsB,QAAQ,+BAA+B;AACtE,SAASC,4BAA4B,QAAQ,uCAAuC;AACpF,OAAOC,eAAe,MAAM,4DAA4D;AACxF,OAAOC,oBAAoB,MAAM,kDAAkD;AACnF,OAAOC,aAAa,MAAM,6BAA6B;;AAEvD;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GAAG,CAAC,CAAC;AAC7BvC,IAAI,CAAEuC,WAAW,EAAE;EAClB,GAAGzC,YAAY;EACfyB,uBAAuB;EACvBxB,+BAA+B;EAC/ByB,gBAAgB;EAChBvB,iBAAiB;EACjBG,oBAAoB;EACpBC,YAAY;EACZC,wBAAwB;EACxBC,eAAe;EACfC,eAAe;EACfN,mBAAmB;EACnBO,SAAS;EACTC,kBAAkB;EAClBC,gBAAgB;EAChBC,oBAAoB;EACpBC,WAAW;EACXC,wBAAwB;EACxBE,gBAAgB;EAChBC,eAAe;EACfE,cAAc;EACdC,cAAc;EACdkB,aAAa;EACbjB,oBAAoB;EACpBC,cAAc;EACdG,sBAAsB;EACtBG,mBAAmB;EACnBC,wBAAwB;EACxBH,sBAAsB;EACtBK,qBAAqB;EACrBC,eAAe;EACfE,sBAAsB;EACtBP,uBAAuB;EACvBM,mBAAmB;EACnBE,4BAA4B;EAC5BC,eAAe;EACfC,oBAAoB;EACpBnB,gDAAgD;EAChDH,0BAA0B;EAC1Be;AACD,CAAE,CAAC","ignoreList":[]}
|
|
@@ -11,6 +11,54 @@ import { useBlockEditContext } from '../components/block-edit';
|
|
|
11
11
|
function isObjectEmpty(object) {
|
|
12
12
|
return !object || Object.keys(object).length === 0;
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Contains utils to update the block `bindings` metadata.
|
|
17
|
+
*
|
|
18
|
+
* @typedef {Object} WPBlockBindingsUtils
|
|
19
|
+
*
|
|
20
|
+
* @property {Function} updateBlockBindings Updates the value of the bindings connected to block attributes.
|
|
21
|
+
* @property {Function} removeAllBlockBindings Removes the bindings property of the `metadata` attribute.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves the existing utils needed to update the block `bindings` metadata.
|
|
26
|
+
* They can be used to create, modify, or remove connections from the existing block attributes.
|
|
27
|
+
*
|
|
28
|
+
* It contains the following utils:
|
|
29
|
+
* - `updateBlockBindings`: Updates the value of the bindings connected to block attributes. It can be used to remove a specific binding by setting the value to `undefined`.
|
|
30
|
+
* - `removeAllBlockBindings`: Removes the bindings property of the `metadata` attribute.
|
|
31
|
+
*
|
|
32
|
+
* @return {?WPBlockBindingsUtils} Object containing the block bindings utils.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```js
|
|
36
|
+
* import { useBlockBindingsUtils } from '@wordpress/block-editor'
|
|
37
|
+
* const { updateBlockBindings, removeAllBlockBindings } = useBlockBindingsUtils();
|
|
38
|
+
*
|
|
39
|
+
* // Update url and alt attributes.
|
|
40
|
+
* updateBlockBindings( {
|
|
41
|
+
* url: {
|
|
42
|
+
* source: 'core/post-meta',
|
|
43
|
+
* args: {
|
|
44
|
+
* key: 'url_custom_field',
|
|
45
|
+
* },
|
|
46
|
+
* },
|
|
47
|
+
* alt: {
|
|
48
|
+
* source: 'core/post-meta',
|
|
49
|
+
* args: {
|
|
50
|
+
* key: 'text_custom_field',
|
|
51
|
+
* },
|
|
52
|
+
* },
|
|
53
|
+
* } );
|
|
54
|
+
*
|
|
55
|
+
* // Remove binding from url attribute.
|
|
56
|
+
* updateBlockBindings( { url: undefined } );
|
|
57
|
+
*
|
|
58
|
+
* // Remove bindings from all attributes.
|
|
59
|
+
* removeAllBlockBindings();
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
14
62
|
export function useBlockBindingsUtils() {
|
|
15
63
|
const {
|
|
16
64
|
clientId
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useDispatch","useRegistry","store","blockEditorStore","useBlockEditContext","isObjectEmpty","object","Object","keys","length","useBlockBindingsUtils","clientId","updateBlockAttributes","getBlockAttributes","select","updateBlockBindings","bindings","metadata","currentBindings","newBindings","entries","forEach","attribute","binding","newMetadata","undefined","removeAllBlockBindings"],"sources":["@wordpress/block-editor/src/utils/block-bindings.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useRegistry } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { useBlockEditContext } from '../components/block-edit';\n\nfunction isObjectEmpty( object ) {\n\treturn ! object || Object.keys( object ).length === 0;\n}\n\nexport function useBlockBindingsUtils() {\n\tconst { clientId } = useBlockEditContext();\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\tconst { getBlockAttributes } = useRegistry().select( blockEditorStore );\n\n\t/**\n\t * Updates the value of the bindings connected to block attributes.\n\t * It removes the binding when the new value is `undefined`.\n\t *\n\t * @param {Object} bindings Bindings including the attributes to update and the new object.\n\t * @param {string} bindings.source The source name to connect to.\n\t * @param {Object} [bindings.args] Object containing the arguments needed by the source.\n\t *\n\t * @example\n\t * ```js\n\t * import { useBlockBindingsUtils } from '@wordpress/block-editor'\n\t *\n\t * const { updateBlockBindings } = useBlockBindingsUtils();\n\t * updateBlockBindings( {\n\t * url: {\n\t * source: 'core/post-meta',\n\t * args: {\n\t * key: 'url_custom_field',\n\t * },\n\t * \t },\n\t * alt: {\n\t * source: 'core/post-meta',\n\t * args: {\n\t * key: 'text_custom_field',\n\t * },\n\t * \t }\n\t * } );\n\t * ```\n\t */\n\tconst updateBlockBindings = ( bindings ) => {\n\t\tconst { metadata: { bindings: currentBindings, ...metadata } = {} } =\n\t\t\tgetBlockAttributes( clientId );\n\t\tconst newBindings = { ...currentBindings };\n\n\t\tObject.entries( bindings ).forEach( ( [ attribute, binding ] ) => {\n\t\t\tif ( ! binding && newBindings[ attribute ] ) {\n\t\t\t\tdelete newBindings[ attribute ];\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tnewBindings[ attribute ] = binding;\n\t\t} );\n\n\t\tconst newMetadata = {\n\t\t\t...metadata,\n\t\t\tbindings: newBindings,\n\t\t};\n\n\t\tif ( isObjectEmpty( newMetadata.bindings ) ) {\n\t\t\tdelete newMetadata.bindings;\n\t\t}\n\n\t\tupdateBlockAttributes( clientId, {\n\t\t\tmetadata: isObjectEmpty( newMetadata ) ? undefined : newMetadata,\n\t\t} );\n\t};\n\n\t/**\n\t * Removes the bindings property of the `metadata` attribute.\n\t *\n\t * @example\n\t * ```js\n\t * import { useBlockBindingsUtils } from '@wordpress/block-editor'\n\t *\n\t * const { removeAllBlockBindings } = useBlockBindingsUtils();\n\t * removeAllBlockBindings();\n\t * ```\n\t */\n\tconst removeAllBlockBindings = () => {\n\t\tconst { metadata: { bindings, ...metadata } = {} } =\n\t\t\tgetBlockAttributes( clientId );\n\t\tupdateBlockAttributes( clientId, {\n\t\t\tmetadata: isObjectEmpty( metadata ) ? undefined : metadata,\n\t\t} );\n\t};\n\n\treturn { updateBlockBindings, removeAllBlockBindings };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,WAAW,QAAQ,iBAAiB;;AAE1D;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,UAAU;AACpD,SAASC,mBAAmB,QAAQ,0BAA0B;AAE9D,SAASC,aAAaA,CAAEC,MAAM,EAAG;EAChC,OAAO,CAAEA,MAAM,IAAIC,MAAM,CAACC,IAAI,CAAEF,MAAO,CAAC,CAACG,MAAM,KAAK,CAAC;AACtD;AAEA,OAAO,SAASC,qBAAqBA,CAAA,EAAG;EACvC,MAAM;IAAEC;EAAS,CAAC,G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,MAAME,sBAAsB,GAAGA,CAAA,KAAM;IACpC,MAAM;MAAET,QAAQ,EAAE;QAAED,QAAQ;QAAE,GAAGC;MAAS,CAAC,GAAG,CAAC;IAAE,CAAC,GACjDJ,kBAAkB,CAAEF,QAAS,CAAC;IAC/BC,qBAAqB,CAAED,QAAQ,EAAE;MAChCM,QAAQ,EAAEZ,aAAa,CAAEY,QAAS,CAAC,GAAGQ,SAAS,GAAGR;IACnD,CAAE,CAAC;EACJ,CAAC;EAED,OAAO;IAAEF,mBAAmB;IAAEW;EAAuB,CAAC;AACvD","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["useDispatch","useRegistry","store","blockEditorStore","useBlockEditContext","isObjectEmpty","object","Object","keys","length","useBlockBindingsUtils","clientId","updateBlockAttributes","getBlockAttributes","select","updateBlockBindings","bindings","metadata","currentBindings","newBindings","entries","forEach","attribute","binding","newMetadata","undefined","removeAllBlockBindings"],"sources":["@wordpress/block-editor/src/utils/block-bindings.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useRegistry } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../store';\nimport { useBlockEditContext } from '../components/block-edit';\n\nfunction isObjectEmpty( object ) {\n\treturn ! object || Object.keys( object ).length === 0;\n}\n\n/**\n * Contains utils to update the block `bindings` metadata.\n *\n * @typedef {Object} WPBlockBindingsUtils\n *\n * @property {Function} updateBlockBindings Updates the value of the bindings connected to block attributes.\n * @property {Function} removeAllBlockBindings Removes the bindings property of the `metadata` attribute.\n */\n\n/**\n * Retrieves the existing utils needed to update the block `bindings` metadata.\n * They can be used to create, modify, or remove connections from the existing block attributes.\n *\n * It contains the following utils:\n * - `updateBlockBindings`: Updates the value of the bindings connected to block attributes. It can be used to remove a specific binding by setting the value to `undefined`.\n * - `removeAllBlockBindings`: Removes the bindings property of the `metadata` attribute.\n *\n * @return {?WPBlockBindingsUtils} Object containing the block bindings utils.\n *\n * @example\n * ```js\n * import { useBlockBindingsUtils } from '@wordpress/block-editor'\n * const { updateBlockBindings, removeAllBlockBindings } = useBlockBindingsUtils();\n *\n * // Update url and alt attributes.\n * updateBlockBindings( {\n * url: {\n * source: 'core/post-meta',\n * args: {\n * key: 'url_custom_field',\n * },\n * },\n * alt: {\n * source: 'core/post-meta',\n * args: {\n * key: 'text_custom_field',\n * },\n * },\n * } );\n *\n * // Remove binding from url attribute.\n * updateBlockBindings( { url: undefined } );\n *\n * // Remove bindings from all attributes.\n * removeAllBlockBindings();\n * ```\n */\nexport function useBlockBindingsUtils() {\n\tconst { clientId } = useBlockEditContext();\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\tconst { getBlockAttributes } = useRegistry().select( blockEditorStore );\n\n\t/**\n\t * Updates the value of the bindings connected to block attributes.\n\t * It removes the binding when the new value is `undefined`.\n\t *\n\t * @param {Object} bindings Bindings including the attributes to update and the new object.\n\t * @param {string} bindings.source The source name to connect to.\n\t * @param {Object} [bindings.args] Object containing the arguments needed by the source.\n\t *\n\t * @example\n\t * ```js\n\t * import { useBlockBindingsUtils } from '@wordpress/block-editor'\n\t *\n\t * const { updateBlockBindings } = useBlockBindingsUtils();\n\t * updateBlockBindings( {\n\t * url: {\n\t * source: 'core/post-meta',\n\t * args: {\n\t * key: 'url_custom_field',\n\t * },\n\t * \t },\n\t * alt: {\n\t * source: 'core/post-meta',\n\t * args: {\n\t * key: 'text_custom_field',\n\t * },\n\t * \t }\n\t * } );\n\t * ```\n\t */\n\tconst updateBlockBindings = ( bindings ) => {\n\t\tconst { metadata: { bindings: currentBindings, ...metadata } = {} } =\n\t\t\tgetBlockAttributes( clientId );\n\t\tconst newBindings = { ...currentBindings };\n\n\t\tObject.entries( bindings ).forEach( ( [ attribute, binding ] ) => {\n\t\t\tif ( ! binding && newBindings[ attribute ] ) {\n\t\t\t\tdelete newBindings[ attribute ];\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tnewBindings[ attribute ] = binding;\n\t\t} );\n\n\t\tconst newMetadata = {\n\t\t\t...metadata,\n\t\t\tbindings: newBindings,\n\t\t};\n\n\t\tif ( isObjectEmpty( newMetadata.bindings ) ) {\n\t\t\tdelete newMetadata.bindings;\n\t\t}\n\n\t\tupdateBlockAttributes( clientId, {\n\t\t\tmetadata: isObjectEmpty( newMetadata ) ? undefined : newMetadata,\n\t\t} );\n\t};\n\n\t/**\n\t * Removes the bindings property of the `metadata` attribute.\n\t *\n\t * @example\n\t * ```js\n\t * import { useBlockBindingsUtils } from '@wordpress/block-editor'\n\t *\n\t * const { removeAllBlockBindings } = useBlockBindingsUtils();\n\t * removeAllBlockBindings();\n\t * ```\n\t */\n\tconst removeAllBlockBindings = () => {\n\t\tconst { metadata: { bindings, ...metadata } = {} } =\n\t\t\tgetBlockAttributes( clientId );\n\t\tupdateBlockAttributes( clientId, {\n\t\t\tmetadata: isObjectEmpty( metadata ) ? undefined : metadata,\n\t\t} );\n\t};\n\n\treturn { updateBlockBindings, removeAllBlockBindings };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,WAAW,QAAQ,iBAAiB;;AAE1D;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,UAAU;AACpD,SAASC,mBAAmB,QAAQ,0BAA0B;AAE9D,SAASC,aAAaA,CAAEC,MAAM,EAAG;EAChC,OAAO,CAAEA,MAAM,IAAIC,MAAM,CAACC,IAAI,CAAEF,MAAO,CAAC,CAACG,MAAM,KAAK,CAAC;AACtD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAAA,EAAG;EACvC,MAAM;IAAEC;EAAS,CAAC,GAAGP,mBAAmB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B,GAAGA,CAAA,KAAM;IACpC,MAAM;MAAET,QAAQ,EAAE;QAAED,QAAQ;QAAE,GAAGC;MAAS,CAAC,GAAG,CAAC;IAAE,CAAC,GACjDJ,kBAAkB,CAAEF,QAAS,CAAC;IAC/BC,qBAAqB,CAAED,QAAQ,EAAE;MAChCM,QAAQ,EAAEZ,aAAa,CAAEY,QAAS,CAAC,GAAGQ,SAAS,GAAGR;IACnD,CAAE,CAAC;EACJ,CAAC;EAED,OAAO;IAAEF,mBAAmB;IAAEW;EAAuB,CAAC;AACvD","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["default","transformStyles","getPxFromCssUnit"],"sources":["@wordpress/block-editor/src/utils/index.js"],"sourcesContent":["export { default as transformStyles } from './transform-styles';\nexport { default as getPxFromCssUnit } from './get-px-from-css-unit';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,eAAe,QAAQ,oBAAoB;AAC/D,SAASD,OAAO,IAAIE,gBAAgB,QAAQ,wBAAwB","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["default","transformStyles","getPxFromCssUnit","useBlockBindingsUtils"],"sources":["@wordpress/block-editor/src/utils/index.js"],"sourcesContent":["export { default as transformStyles } from './transform-styles';\nexport { default as getPxFromCssUnit } from './get-px-from-css-unit';\nexport { useBlockBindingsUtils } from './block-bindings';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,eAAe,QAAQ,oBAAoB;AAC/D,SAASD,OAAO,IAAIE,gBAAgB,QAAQ,wBAAwB;AACpE,SAASC,qBAAqB,QAAQ,kBAAkB","ignoreList":[]}
|
|
@@ -866,26 +866,14 @@ _::-webkit-full-page-media, _:future, :root .has-multi-selection .block-editor-b
|
|
|
866
866
|
}
|
|
867
867
|
|
|
868
868
|
.block-editor-media-placeholder__url-input-form {
|
|
869
|
-
|
|
870
|
-
}
|
|
871
|
-
.block-editor-media-placeholder__url-input-form input[type=url].block-editor-media-placeholder__url-input-field {
|
|
872
|
-
width: 100%;
|
|
873
|
-
min-width: 200px;
|
|
874
|
-
flex-grow: 1;
|
|
875
|
-
border: none;
|
|
876
|
-
border-radius: 0;
|
|
877
|
-
margin: 2px;
|
|
869
|
+
min-width: 260px;
|
|
878
870
|
}
|
|
879
871
|
@media (min-width: 600px) {
|
|
880
|
-
.block-editor-media-placeholder__url-input-form
|
|
872
|
+
.block-editor-media-placeholder__url-input-form {
|
|
881
873
|
width: 300px;
|
|
882
874
|
}
|
|
883
875
|
}
|
|
884
876
|
|
|
885
|
-
.block-editor-media-placeholder__url-input-submit-button {
|
|
886
|
-
flex-shrink: 1;
|
|
887
|
-
}
|
|
888
|
-
|
|
889
877
|
.block-editor-media-placeholder__cancel-button.is-link {
|
|
890
878
|
margin: 1em;
|
|
891
879
|
display: block;
|
package/build-style/content.css
CHANGED
|
@@ -866,26 +866,14 @@ _::-webkit-full-page-media, _:future, :root .has-multi-selection .block-editor-b
|
|
|
866
866
|
}
|
|
867
867
|
|
|
868
868
|
.block-editor-media-placeholder__url-input-form {
|
|
869
|
-
|
|
870
|
-
}
|
|
871
|
-
.block-editor-media-placeholder__url-input-form input[type=url].block-editor-media-placeholder__url-input-field {
|
|
872
|
-
width: 100%;
|
|
873
|
-
min-width: 200px;
|
|
874
|
-
flex-grow: 1;
|
|
875
|
-
border: none;
|
|
876
|
-
border-radius: 0;
|
|
877
|
-
margin: 2px;
|
|
869
|
+
min-width: 260px;
|
|
878
870
|
}
|
|
879
871
|
@media (min-width: 600px) {
|
|
880
|
-
.block-editor-media-placeholder__url-input-form
|
|
872
|
+
.block-editor-media-placeholder__url-input-form {
|
|
881
873
|
width: 300px;
|
|
882
874
|
}
|
|
883
875
|
}
|
|
884
876
|
|
|
885
|
-
.block-editor-media-placeholder__url-input-submit-button {
|
|
886
|
-
flex-shrink: 1;
|
|
887
|
-
}
|
|
888
|
-
|
|
889
877
|
.block-editor-media-placeholder__cancel-button.is-link {
|
|
890
878
|
margin: 1em;
|
|
891
879
|
display: block;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/block-editor",
|
|
3
|
-
"version": "14.3.
|
|
3
|
+
"version": "14.3.4",
|
|
4
4
|
"description": "Generic block editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"@wordpress/api-fetch": "^7.8.2",
|
|
41
41
|
"@wordpress/blob": "^4.8.1",
|
|
42
42
|
"@wordpress/block-serialization-default-parser": "^5.8.1",
|
|
43
|
-
"@wordpress/blocks": "^13.8.
|
|
44
|
-
"@wordpress/commands": "^1.8.
|
|
45
|
-
"@wordpress/components": "^28.8.
|
|
43
|
+
"@wordpress/blocks": "^13.8.4",
|
|
44
|
+
"@wordpress/commands": "^1.8.4",
|
|
45
|
+
"@wordpress/components": "^28.8.4",
|
|
46
46
|
"@wordpress/compose": "^7.8.3",
|
|
47
47
|
"@wordpress/data": "^10.8.3",
|
|
48
48
|
"@wordpress/date": "^5.8.2",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@wordpress/keyboard-shortcuts": "^5.8.3",
|
|
59
59
|
"@wordpress/keycodes": "^4.8.2",
|
|
60
60
|
"@wordpress/notices": "^5.8.3",
|
|
61
|
-
"@wordpress/preferences": "^4.8.
|
|
61
|
+
"@wordpress/preferences": "^4.8.4",
|
|
62
62
|
"@wordpress/private-apis": "^1.8.1",
|
|
63
63
|
"@wordpress/rich-text": "^7.8.3",
|
|
64
64
|
"@wordpress/style-engine": "^2.8.1",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"publishConfig": {
|
|
89
89
|
"access": "public"
|
|
90
90
|
},
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "07c75154341d1e5a1b8aaa1c226029b6666a52a9"
|
|
92
92
|
}
|
|
@@ -1,27 +1,11 @@
|
|
|
1
1
|
.block-editor-media-placeholder__url-input-form {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// Selector requires a lot of specificity to override base styles.
|
|
5
|
-
input[type="url"].block-editor-media-placeholder__url-input-field {
|
|
6
|
-
width: 100%;
|
|
7
|
-
min-width: 200px;
|
|
8
|
-
|
|
9
|
-
@include break-small() {
|
|
10
|
-
width: 300px;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
flex-grow: 1;
|
|
14
|
-
border: none;
|
|
15
|
-
border-radius: 0;
|
|
16
|
-
margin: 2px;
|
|
2
|
+
min-width: 260px;
|
|
17
3
|
|
|
4
|
+
@include break-small() {
|
|
5
|
+
width: 300px;
|
|
18
6
|
}
|
|
19
7
|
}
|
|
20
8
|
|
|
21
|
-
.block-editor-media-placeholder__url-input-submit-button {
|
|
22
|
-
flex-shrink: 1;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
9
|
.block-editor-media-placeholder__cancel-button.is-link {
|
|
26
10
|
margin: 1em;
|
|
27
11
|
display: block;
|
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
FormFileUpload,
|
|
12
12
|
Placeholder,
|
|
13
13
|
DropZone,
|
|
14
|
+
__experimentalInputControl as InputControl,
|
|
15
|
+
__experimentalInputControlSuffixWrapper as InputControlSuffixWrapper,
|
|
14
16
|
withFilters,
|
|
15
17
|
} from '@wordpress/components';
|
|
16
18
|
import { __ } from '@wordpress/i18n';
|
|
@@ -42,21 +44,23 @@ const InsertFromURLPopover = ( {
|
|
|
42
44
|
className="block-editor-media-placeholder__url-input-form"
|
|
43
45
|
onSubmit={ onSubmit }
|
|
44
46
|
>
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
<InputControl
|
|
48
|
+
__next40pxDefaultSize
|
|
49
|
+
label={ __( 'URL' ) }
|
|
50
|
+
hideLabelFromVision
|
|
49
51
|
placeholder={ __( 'Paste or type URL' ) }
|
|
50
52
|
onChange={ onChange }
|
|
51
53
|
value={ src }
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
suffix={
|
|
55
|
+
<InputControlSuffixWrapper variant="control">
|
|
56
|
+
<Button
|
|
57
|
+
size="small"
|
|
58
|
+
icon={ keyboardReturn }
|
|
59
|
+
label={ __( 'Apply' ) }
|
|
60
|
+
type="submit"
|
|
61
|
+
/>
|
|
62
|
+
</InputControlSuffixWrapper>
|
|
63
|
+
}
|
|
60
64
|
/>
|
|
61
65
|
</form>
|
|
62
66
|
</URLPopover>
|
|
@@ -167,10 +171,6 @@ export function MediaPlaceholder( {
|
|
|
167
171
|
);
|
|
168
172
|
};
|
|
169
173
|
|
|
170
|
-
const onChangeSrc = ( event ) => {
|
|
171
|
-
setSrc( event.target.value );
|
|
172
|
-
};
|
|
173
|
-
|
|
174
174
|
const onFilesUpload = ( files ) => {
|
|
175
175
|
if (
|
|
176
176
|
! handleUpload ||
|
|
@@ -407,7 +407,7 @@ export function MediaPlaceholder( {
|
|
|
407
407
|
onSelectURL && (
|
|
408
408
|
<URLSelectionUI
|
|
409
409
|
src={ src }
|
|
410
|
-
onChangeSrc={
|
|
410
|
+
onChangeSrc={ setSrc }
|
|
411
411
|
onSelectURL={ onSelectURL }
|
|
412
412
|
/>
|
|
413
413
|
)
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
removeFormat,
|
|
21
21
|
} from '@wordpress/rich-text';
|
|
22
22
|
import { Popover } from '@wordpress/components';
|
|
23
|
-
import {
|
|
23
|
+
import { getBlockBindingsSource } from '@wordpress/blocks';
|
|
24
24
|
import deprecated from '@wordpress/deprecated';
|
|
25
25
|
import { __, sprintf } from '@wordpress/i18n';
|
|
26
26
|
|
|
@@ -39,7 +39,6 @@ import FormatEdit from './format-edit';
|
|
|
39
39
|
import { getAllowedFormats } from './utils';
|
|
40
40
|
import { Content, valueToHTMLString } from './content';
|
|
41
41
|
import { withDeprecations } from './with-deprecations';
|
|
42
|
-
import { unlock } from '../../lock-unlock';
|
|
43
42
|
import { canBindBlock } from '../../hooks/use-bindings-attributes';
|
|
44
43
|
import BlockContext from '../block-context';
|
|
45
44
|
|
|
@@ -175,7 +174,6 @@ export function RichTextWrapper(
|
|
|
175
174
|
}
|
|
176
175
|
|
|
177
176
|
const relatedBinding = blockBindings[ identifier ];
|
|
178
|
-
const { getBlockBindingsSource } = unlock( select( blocksStore ) );
|
|
179
177
|
const blockBindingsSource = getBlockBindingsSource(
|
|
180
178
|
relatedBinding.source
|
|
181
179
|
);
|
|
@@ -188,7 +186,7 @@ export function RichTextWrapper(
|
|
|
188
186
|
|
|
189
187
|
const _disableBoundBlock =
|
|
190
188
|
! blockBindingsSource?.canUserEditValue?.( {
|
|
191
|
-
|
|
189
|
+
select,
|
|
192
190
|
context: blockBindingsContext,
|
|
193
191
|
args: relatedBinding.args,
|
|
194
192
|
} );
|
|
@@ -206,7 +204,7 @@ export function RichTextWrapper(
|
|
|
206
204
|
const { getBlockAttributes } = select( blockEditorStore );
|
|
207
205
|
const blockAttributes = getBlockAttributes( clientId );
|
|
208
206
|
const fieldsList = blockBindingsSource?.getFieldsList?.( {
|
|
209
|
-
|
|
207
|
+
select,
|
|
210
208
|
context: blockBindingsContext,
|
|
211
209
|
} );
|
|
212
210
|
const bindingKey =
|
|
@@ -235,14 +233,7 @@ export function RichTextWrapper(
|
|
|
235
233
|
bindingsLabel: _bindingsLabel,
|
|
236
234
|
};
|
|
237
235
|
},
|
|
238
|
-
[
|
|
239
|
-
blockBindings,
|
|
240
|
-
identifier,
|
|
241
|
-
blockName,
|
|
242
|
-
blockContext,
|
|
243
|
-
registry,
|
|
244
|
-
adjustedValue,
|
|
245
|
-
]
|
|
236
|
+
[ blockBindings, identifier, blockName, blockContext, adjustedValue ]
|
|
246
237
|
);
|
|
247
238
|
|
|
248
239
|
const shouldDisableEditing = readOnly || disableBoundBlock;
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
getBlockBindingsSource,
|
|
7
|
+
getBlockBindingsSources,
|
|
8
|
+
} from '@wordpress/blocks';
|
|
6
9
|
import {
|
|
7
10
|
__experimentalItemGroup as ItemGroup,
|
|
8
11
|
__experimentalItem as Item,
|
|
@@ -12,7 +15,7 @@ import {
|
|
|
12
15
|
__experimentalVStack as VStack,
|
|
13
16
|
privateApis as componentsPrivateApis,
|
|
14
17
|
} from '@wordpress/components';
|
|
15
|
-
import {
|
|
18
|
+
import { useSelect } from '@wordpress/data';
|
|
16
19
|
import { useContext, Fragment } from '@wordpress/element';
|
|
17
20
|
import { useViewportMatch } from '@wordpress/compose';
|
|
18
21
|
|
|
@@ -47,7 +50,6 @@ const useToolsPanelDropdownMenuProps = () => {
|
|
|
47
50
|
};
|
|
48
51
|
|
|
49
52
|
function BlockBindingsPanelDropdown( { fieldsList, attribute, binding } ) {
|
|
50
|
-
const { getBlockBindingsSources } = unlock( blocksPrivateApis );
|
|
51
53
|
const registeredSources = getBlockBindingsSources();
|
|
52
54
|
const { updateBlockBindings } = useBlockBindingsUtils();
|
|
53
55
|
const currentKey = binding?.args?.key;
|
|
@@ -96,8 +98,7 @@ function BlockBindingsPanelDropdown( { fieldsList, attribute, binding } ) {
|
|
|
96
98
|
|
|
97
99
|
function BlockBindingsAttribute( { attribute, binding, fieldsList } ) {
|
|
98
100
|
const { source: sourceName, args } = binding || {};
|
|
99
|
-
const sourceProps =
|
|
100
|
-
unlock( blocksPrivateApis ).getBlockBindingsSource( sourceName );
|
|
101
|
+
const sourceProps = getBlockBindingsSource( sourceName );
|
|
101
102
|
const isSourceInvalid = ! sourceProps;
|
|
102
103
|
return (
|
|
103
104
|
<VStack className="block-editor-bindings__item" spacing={ 0 }>
|
|
@@ -186,7 +187,6 @@ function EditableBlockBindingsPanelItems( {
|
|
|
186
187
|
}
|
|
187
188
|
|
|
188
189
|
export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
189
|
-
const registry = useRegistry();
|
|
190
190
|
const blockContext = useContext( BlockContext );
|
|
191
191
|
const { removeAllBlockBindings } = useBlockBindingsUtils();
|
|
192
192
|
const bindableAttributes = getBindableAttributes( blockName );
|
|
@@ -194,14 +194,13 @@ export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
|
194
194
|
|
|
195
195
|
// `useSelect` is used purposely here to ensure `getFieldsList`
|
|
196
196
|
// is updated whenever there are updates in block context.
|
|
197
|
-
// `source.getFieldsList` may also call a selector via `
|
|
197
|
+
// `source.getFieldsList` may also call a selector via `select`.
|
|
198
198
|
const _fieldsList = {};
|
|
199
199
|
const { fieldsList, canUpdateBlockBindings } = useSelect(
|
|
200
200
|
( select ) => {
|
|
201
201
|
if ( ! bindableAttributes || bindableAttributes.length === 0 ) {
|
|
202
202
|
return EMPTY_OBJECT;
|
|
203
203
|
}
|
|
204
|
-
const { getBlockBindingsSources } = unlock( blocksPrivateApis );
|
|
205
204
|
const registeredSources = getBlockBindingsSources();
|
|
206
205
|
Object.entries( registeredSources ).forEach(
|
|
207
206
|
( [ sourceName, { getFieldsList, usesContext } ] ) => {
|
|
@@ -214,7 +213,7 @@ export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
|
214
213
|
}
|
|
215
214
|
}
|
|
216
215
|
const sourceList = getFieldsList( {
|
|
217
|
-
|
|
216
|
+
select,
|
|
218
217
|
context,
|
|
219
218
|
} );
|
|
220
219
|
// Only add source if the list is not empty.
|
|
@@ -234,7 +233,7 @@ export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
|
234
233
|
.canUpdateBlockBindings,
|
|
235
234
|
};
|
|
236
235
|
},
|
|
237
|
-
[ blockContext, bindableAttributes
|
|
236
|
+
[ blockContext, bindableAttributes ]
|
|
238
237
|
);
|
|
239
238
|
// Return early if there are no bindable attributes.
|
|
240
239
|
if ( ! bindableAttributes || bindableAttributes.length === 0 ) {
|