@wordpress/block-editor 15.0.0 → 15.0.1-next.46f643fa0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/block-list/zoom-out-separator.js +0 -1
- package/build/components/block-list/zoom-out-separator.js.map +1 -1
- package/build/components/block-toolbar/index.js +6 -3
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/iframe/index.js +20 -15
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/image-editor/use-save-image.js +49 -30
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/inserter-button/index.native.js +54 -64
- package/build/components/inserter-button/index.native.js.map +1 -1
- package/build/components/list-view/block.js +2 -1
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/publish-date-time-picker/index.js +2 -1
- package/build/components/publish-date-time-picker/index.js.map +1 -1
- package/build/components/writing-flow/use-click-selection.js +3 -1
- package/build/components/writing-flow/use-click-selection.js.map +1 -1
- package/build/private-apis.js +2 -1
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +5 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/private-keys.js +2 -1
- package/build/store/private-keys.js.map +1 -1
- package/build/utils/block-bindings.js +2 -1
- package/build/utils/block-bindings.js.map +1 -1
- package/build-module/components/block-list/zoom-out-separator.js +0 -1
- package/build-module/components/block-list/zoom-out-separator.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +6 -3
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/iframe/index.js +20 -15
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/image-editor/use-save-image.js +50 -30
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/inserter-button/index.native.js +55 -65
- package/build-module/components/inserter-button/index.native.js.map +1 -1
- package/build-module/components/list-view/block.js +2 -1
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/publish-date-time-picker/index.js +2 -1
- package/build-module/components/publish-date-time-picker/index.js.map +1 -1
- package/build-module/components/writing-flow/use-click-selection.js +3 -1
- package/build-module/components/writing-flow/use-click-selection.js.map +1 -1
- package/build-module/private-apis.js +3 -2
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +5 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/private-keys.js +1 -0
- package/build-module/store/private-keys.js.map +1 -1
- package/build-module/utils/block-bindings.js +2 -1
- package/build-module/utils/block-bindings.js.map +1 -1
- package/build-style/style-rtl.css +4 -18
- package/build-style/style.css +4 -18
- package/package.json +34 -34
- package/src/components/block-list/zoom-out-separator.js +0 -1
- package/src/components/block-toolbar/index.js +8 -2
- package/src/components/grid/style.scss +3 -2
- package/src/components/iframe/index.js +25 -16
- package/src/components/image-editor/use-save-image.js +58 -31
- package/src/components/inserter/style.scss +1 -1
- package/src/components/inserter-button/index.native.js +69 -80
- package/src/components/list-view/block.js +1 -0
- package/src/components/list-view/style.scss +2 -20
- package/src/components/publish-date-time-picker/README.md +9 -0
- package/src/components/publish-date-time-picker/index.js +2 -1
- package/src/components/writing-flow/use-click-selection.js +3 -1
- package/src/private-apis.js +2 -0
- package/src/store/actions.js +8 -1
- package/src/store/private-keys.js +1 -0
- package/src/store/test/actions.js +15 -2
- package/src/utils/block-bindings.js +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_store","_blockEdit","DEFAULT_ATTRIBUTE","PATTERN_OVERRIDES_SOURCE","BLOCK_BINDINGS_ALLOWED_BLOCKS","isObjectEmpty","object","Object","keys","length","canBindBlock","blockName","canBindAttribute","attributeName","includes","getBindableAttributes","hasPatternOverridesDefaultBinding","bindings","source","replacePatternOverridesDefaultBinding","supportedAttributes","bindingsWithDefaults","bindingSource","useBlockBindingsUtils","clientId","contextClientId","useBlockEditContext","blockClientId","updateBlockAttributes","useDispatch","blockEditorStore","getBlockAttributes","useRegistry","select","updateBlockBindings","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\nconst DEFAULT_ATTRIBUTE = '__default';\nconst PATTERN_OVERRIDES_SOURCE = 'core/pattern-overrides';\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\n/**\n * Checks if the given object is empty.\n *\n * @param {?Object} object The object to check.\n *\n * @return {boolean} Whether the object is empty.\n */\nfunction isObjectEmpty( object ) {\n\treturn ! object || Object.keys( object ).length === 0;\n}\n\n/**\n * Based on the given block name, checks if it is possible to bind the block.\n *\n * @param {string} blockName The name of the block.\n *\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, checks if it is possible to bind the block attribute.\n *\n * @param {string} blockName The name of the block.\n * @param {string} attributeName The name of attribute.\n *\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\n/**\n * Gets the bindable attributes for a given block.\n *\n * @param {string} blockName The name of the block.\n *\n * @return {string[]} The bindable attributes for the block.\n */\nexport function getBindableAttributes( blockName ) {\n\treturn BLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ];\n}\n\n/**\n * Checks if the block has the `__default` binding for pattern overrides.\n *\n * @param {?Record<string, object>} bindings A block's bindings from the metadata attribute.\n *\n * @return {boolean} Whether the block has the `__default` binding for pattern overrides.\n */\nexport function hasPatternOverridesDefaultBinding( bindings ) {\n\treturn bindings?.[ DEFAULT_ATTRIBUTE ]?.source === PATTERN_OVERRIDES_SOURCE;\n}\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 {?Record<string, object>} bindings A block's bindings from the metadata attribute.\n *\n * @return {Object} The bindings with default replaced for pattern overrides.\n */\nexport function replacePatternOverridesDefaultBinding( blockName, bindings ) {\n\t// The `__default` binding currently only works for pattern overrides.\n\tif ( hasPatternOverridesDefaultBinding( bindings ) ) {\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: PATTERN_OVERRIDES_SOURCE };\n\t\t\tbindingsWithDefaults[ attributeName ] = bindingSource;\n\t\t}\n\n\t\treturn bindingsWithDefaults;\n\t}\n\n\treturn bindings;\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 * @since 6.7.0 Introduced in WordPress core.\n *\n * @param {?string} clientId Optional block client ID. If not set, it will use the current block client ID from the context.\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( clientId ) {\n\tconst { clientId: contextClientId } = useBlockEditContext();\n\tconst blockClientId = clientId || contextClientId;\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( blockClientId );\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( blockClientId, {\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( blockClientId );\n\t\tupdateBlockAttributes( blockClientId, {\n\t\t\tmetadata: isObjectEmpty( metadata ) ? undefined : metadata,\n\t\t} );\n\t};\n\n\treturn { updateBlockBindings, removeAllBlockBindings };\n}\n"],"mappings":";;;;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA,MAAMG,iBAAiB,GAAG,WAAW;AACrC,MAAMC,wBAAwB,GAAG,wBAAwB;AACzD,MAAMC,6BAA6B,GAAG;EACrC,gBAAgB,EAAE,CAAE,SAAS,CAAE;EAC/B,cAAc,EAAE,CAAE,SAAS,CAAE;EAC7B,YAAY,EAAE,CAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,CAAE;EAC7C,aAAa,EAAE,CAAE,KAA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AM;MACjE,IAAK,CAAEA,OAAO,IAAIJ,WAAW,CAAEG,SAAS,CAAE,EAAG;QAC5C,OAAOH,WAAW,CAAEG,SAAS,CAAE;QAC/B;MACD;MACAH,WAAW,CAAEG,SAAS,CAAE,GAAGC,OAAO;IACnC,CAAE,CAAC;IAEH,MAAMC,WAAW,GAAG;MACnB,GAAGP,QAAQ;MACXlB,QAAQ,EAAEoB;IACX,CAAC;IAED,IAAKhC,aAAa,CAAEqC,WAAW,CAACzB,QAAS,CAAC,EAAG;MAC5C,OAAOyB,WAAW,CAACzB,QAAQ;IAC5B;IAEAW,qBAAqB,CAAED,aAAa,EAAE;MACrCQ,QAAQ,EAAE9B,aAAa,CAAEqC,WAAY,CAAC,GAAGC,SAAS,GAAGD;IACtD,CAAE,CAAC;EACJ,CAAC;;EAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACC,MAAME,sBAAsB,GAAGA,CAAA,KAAM;IACpC,MAAM;MAAET,QAAQ,EAAE;QAAElB,QAAQ;QAAE,GAAGkB;MAAS,CAAC,GAAG,CAAC;IAAE,CAAC,GACjDJ,kBAAkB,CAAEJ,aAAc,CAAC;IACpCC,qBAAqB,CAAED,aAAa,EAAE;MACrCQ,QAAQ,EAAE9B,aAAa,CAAE8B,QAAS,CAAC,GAAGQ,SAAS,GAAGR;IACnD,CAAE,CAAC;EACJ,CAAC;EAED,OAAO;IAAED,mBAAmB;IAAEU;EAAuB,CAAC;AACvD","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_data","require","_store","_blockEdit","DEFAULT_ATTRIBUTE","PATTERN_OVERRIDES_SOURCE","BLOCK_BINDINGS_ALLOWED_BLOCKS","isObjectEmpty","object","Object","keys","length","canBindBlock","blockName","canBindAttribute","attributeName","includes","getBindableAttributes","hasPatternOverridesDefaultBinding","bindings","source","replacePatternOverridesDefaultBinding","supportedAttributes","bindingsWithDefaults","bindingSource","useBlockBindingsUtils","clientId","contextClientId","useBlockEditContext","blockClientId","updateBlockAttributes","useDispatch","blockEditorStore","getBlockAttributes","useRegistry","select","updateBlockBindings","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\nconst DEFAULT_ATTRIBUTE = '__default';\nconst PATTERN_OVERRIDES_SOURCE = 'core/pattern-overrides';\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\t'core/post-date': [ 'datetime' ],\n};\n\n/**\n * Checks if the given object is empty.\n *\n * @param {?Object} object The object to check.\n *\n * @return {boolean} Whether the object is empty.\n */\nfunction isObjectEmpty( object ) {\n\treturn ! object || Object.keys( object ).length === 0;\n}\n\n/**\n * Based on the given block name, checks if it is possible to bind the block.\n *\n * @param {string} blockName The name of the block.\n *\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, checks if it is possible to bind the block attribute.\n *\n * @param {string} blockName The name of the block.\n * @param {string} attributeName The name of attribute.\n *\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\n/**\n * Gets the bindable attributes for a given block.\n *\n * @param {string} blockName The name of the block.\n *\n * @return {string[]} The bindable attributes for the block.\n */\nexport function getBindableAttributes( blockName ) {\n\treturn BLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ];\n}\n\n/**\n * Checks if the block has the `__default` binding for pattern overrides.\n *\n * @param {?Record<string, object>} bindings A block's bindings from the metadata attribute.\n *\n * @return {boolean} Whether the block has the `__default` binding for pattern overrides.\n */\nexport function hasPatternOverridesDefaultBinding( bindings ) {\n\treturn bindings?.[ DEFAULT_ATTRIBUTE ]?.source === PATTERN_OVERRIDES_SOURCE;\n}\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 {?Record<string, object>} bindings A block's bindings from the metadata attribute.\n *\n * @return {Object} The bindings with default replaced for pattern overrides.\n */\nexport function replacePatternOverridesDefaultBinding( blockName, bindings ) {\n\t// The `__default` binding currently only works for pattern overrides.\n\tif ( hasPatternOverridesDefaultBinding( bindings ) ) {\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: PATTERN_OVERRIDES_SOURCE };\n\t\t\tbindingsWithDefaults[ attributeName ] = bindingSource;\n\t\t}\n\n\t\treturn bindingsWithDefaults;\n\t}\n\n\treturn bindings;\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 * @since 6.7.0 Introduced in WordPress core.\n *\n * @param {?string} clientId Optional block client ID. If not set, it will use the current block client ID from the context.\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( clientId ) {\n\tconst { clientId: contextClientId } = useBlockEditContext();\n\tconst blockClientId = clientId || contextClientId;\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( blockClientId );\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( blockClientId, {\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( blockClientId );\n\t\tupdateBlockAttributes( blockClientId, {\n\t\t\tmetadata: isObjectEmpty( metadata ) ? undefined : metadata,\n\t\t} );\n\t};\n\n\treturn { updateBlockBindings, removeAllBlockBindings };\n}\n"],"mappings":";;;;;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA,MAAMG,iBAAiB,GAAG,WAAW;AACrC,MAAMC,wBAAwB,GAAG,wBAAwB;AACzD,MAAMC,6BAA6B,GAAG;EACrC,gBAAgB,EAAE,CAAE,SAAS,CAAE;EAC/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,aAAc,CAAC;IACpC,MAAMU,WAAW,GAAG;MAAE,GAAGD;IAAgB,CAAC;IAE1C7B,MAAM,CAAC+B,OAAO,CAAErB,QAAS,CAAC,CAACsB,OAAO,CAAE,CAAE,CAAEC,SAAS,EAAEC,OAAO,CAAE,KAAM;MACjE,IAAK,CAAEA,OAAO,IAAIJ,WAAW,CAAEG,SAAS,CAAE,EAAG;QAC5C,OAAOH,WAAW,CAAEG,SAAS,CAAE;QAC/B;MACD;MACAH,WAAW,CAAEG,SAAS,CAAE,GAAGC,OAAO;IACnC,CAAE,CAAC;IAEH,MAAMC,WAAW,GAAG;MACnB,GAAGP,QAAQ;MACXlB,QAAQ,EAAEoB;IACX,CAAC;IAED,IAAKhC,aAAa,CAAEqC,WAAW,CAACzB,QAAS,CAAC,EAAG;MAC5C,OAAOyB,WAAW,CAACzB,QAAQ;IAC5B;IAEAW,qBAAqB,CAAED,aAAa,EAAE;MACrCQ,QAAQ,EAAE9B,aAAa,CAAEqC,WAAY,CAAC,GAAGC,SAAS,GAAGD;IACtD,CAAE,CAAC;EACJ,CAAC;;EAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACC,MAAME,sBAAsB,GAAGA,CAAA,KAAM;IACpC,MAAM;MAAET,QAAQ,EAAE;QAAElB,QAAQ;QAAE,GAAGkB;MAAS,CAAC,GAAG,CAAC;IAAE,CAAC,GACjDJ,kBAAkB,CAAEJ,aAAc,CAAC;IACpCC,qBAAqB,CAAED,aAAa,EAAE;MACrCQ,QAAQ,EAAE9B,aAAa,CAAE8B,QAAS,CAAC,GAAGQ,SAAS,GAAGR;IACnD,CAAE,CAAC;EACJ,CAAC;EAED,OAAO;IAAED,mBAAmB;IAAEU;EAAuB,CAAC;AACvD","ignoreList":[]}
|
|
@@ -45,7 +45,6 @@ export function ZoomOutSeparator({
|
|
|
45
45
|
return {
|
|
46
46
|
sectionRootClientId: root,
|
|
47
47
|
sectionClientIds: sectionRootClientIds,
|
|
48
|
-
blockOrder: getBlockOrder(root),
|
|
49
48
|
insertionPoint: getInsertionPoint(),
|
|
50
49
|
blockInsertionPoint: getBlockInsertionPoint(),
|
|
51
50
|
blockInsertionPointVisible: isBlockInsertionPointVisible(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["clsx","__unstableMotion","motion","__unstableAnimatePresence","AnimatePresence","useReducedMotion","useSelect","useState","__","store","blockEditorStore","unlock","jsx","_jsx","ZoomOutSeparator","clientId","rootClientId","position","isDraggedOver","setIsDraggedOver","sectionRootClientId","sectionClientIds","insertionPoint","blockInsertionPointVisible","blockInsertionPoint","blocksBeingDragged","select","getInsertionPoint","getBlockOrder","getSectionRootClientId","isBlockInsertionPointVisible","getBlockInsertionPoint","getDraggedBlockClientIds","root","sectionRootClientIds","
|
|
1
|
+
{"version":3,"names":["clsx","__unstableMotion","motion","__unstableAnimatePresence","AnimatePresence","useReducedMotion","useSelect","useState","__","store","blockEditorStore","unlock","jsx","_jsx","ZoomOutSeparator","clientId","rootClientId","position","isDraggedOver","setIsDraggedOver","sectionRootClientId","sectionClientIds","insertionPoint","blockInsertionPointVisible","blockInsertionPoint","blocksBeingDragged","select","getInsertionPoint","getBlockOrder","getSectionRootClientId","isBlockInsertionPointVisible","getBlockInsertionPoint","getDraggedBlockClientIds","root","sectionRootClientIds","isReducedMotion","isVisible","isSectionBlock","includes","hasTopInsertionPoint","index","hasBottomInsertionPoint","hasOwnProperty","blockBeingDraggedClientId","isCurrentBlockBeingDragged","blockBeingDraggedIndex","indexOf","blockBeingDraggedPreviousSiblingClientId","isCurrentBlockPreviousSiblingOfBlockBeingDragged","children","div","initial","height","animate","exit","transition","type","duration","ease","className","onDragOver","onDragLeave","opacity","delay"],"sources":["@wordpress/block-editor/src/components/block-list/zoom-out-separator.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__unstableMotion as motion,\n\t__unstableAnimatePresence as AnimatePresence,\n} from '@wordpress/components';\nimport { useReducedMotion } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nexport function ZoomOutSeparator( {\n\tclientId,\n\trootClientId = '',\n\tposition = 'top',\n} ) {\n\tconst [ isDraggedOver, setIsDraggedOver ] = useState( false );\n\tconst {\n\t\tsectionRootClientId,\n\t\tsectionClientIds,\n\t\tinsertionPoint,\n\t\tblockInsertionPointVisible,\n\t\tblockInsertionPoint,\n\t\tblocksBeingDragged,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetInsertionPoint,\n\t\t\tgetBlockOrder,\n\t\t\tgetSectionRootClientId,\n\t\t\tisBlockInsertionPointVisible,\n\t\t\tgetBlockInsertionPoint,\n\t\t\tgetDraggedBlockClientIds,\n\t\t} = unlock( select( blockEditorStore ) );\n\n\t\tconst root = getSectionRootClientId();\n\t\tconst sectionRootClientIds = getBlockOrder( root );\n\t\treturn {\n\t\t\tsectionRootClientId: root,\n\t\t\tsectionClientIds: sectionRootClientIds,\n\t\t\tinsertionPoint: getInsertionPoint(),\n\t\t\tblockInsertionPoint: getBlockInsertionPoint(),\n\t\t\tblockInsertionPointVisible: isBlockInsertionPointVisible(),\n\t\t\tblocksBeingDragged: getDraggedBlockClientIds(),\n\t\t};\n\t}, [] );\n\n\tconst isReducedMotion = useReducedMotion();\n\n\tif ( ! clientId ) {\n\t\treturn;\n\t}\n\n\tlet isVisible = false;\n\n\tconst isSectionBlock =\n\t\trootClientId === sectionRootClientId &&\n\t\tsectionClientIds &&\n\t\tsectionClientIds.includes( clientId );\n\n\tif ( ! isSectionBlock ) {\n\t\treturn null;\n\t}\n\n\tconst hasTopInsertionPoint =\n\t\tinsertionPoint?.index === 0 &&\n\t\tclientId === sectionClientIds[ insertionPoint.index ];\n\tconst hasBottomInsertionPoint =\n\t\tinsertionPoint &&\n\t\tinsertionPoint.hasOwnProperty( 'index' ) &&\n\t\tclientId === sectionClientIds[ insertionPoint.index - 1 ];\n\n\t// We want to show the zoom out separator in either of these conditions:\n\t// 1. If the inserter has an insertion index set\n\t// 2. We are dragging a pattern over an insertion point\n\tif ( position === 'top' ) {\n\t\tisVisible =\n\t\t\thasTopInsertionPoint ||\n\t\t\t( blockInsertionPointVisible &&\n\t\t\t\tblockInsertionPoint.index === 0 &&\n\t\t\t\tclientId === sectionClientIds[ blockInsertionPoint.index ] );\n\t}\n\n\tif ( position === 'bottom' ) {\n\t\tisVisible =\n\t\t\thasBottomInsertionPoint ||\n\t\t\t( blockInsertionPointVisible &&\n\t\t\t\tclientId ===\n\t\t\t\t\tsectionClientIds[ blockInsertionPoint.index - 1 ] );\n\t}\n\n\tconst blockBeingDraggedClientId = blocksBeingDragged[ 0 ];\n\n\tconst isCurrentBlockBeingDragged = blocksBeingDragged.includes( clientId );\n\n\tconst blockBeingDraggedIndex = sectionClientIds.indexOf(\n\t\tblockBeingDraggedClientId\n\t);\n\tconst blockBeingDraggedPreviousSiblingClientId =\n\t\tblockBeingDraggedIndex > 0\n\t\t\t? sectionClientIds[ blockBeingDraggedIndex - 1 ]\n\t\t\t: null;\n\n\tconst isCurrentBlockPreviousSiblingOfBlockBeingDragged =\n\t\tblockBeingDraggedPreviousSiblingClientId === clientId;\n\n\t// The separators are visually top/bottom of the block, but in actual fact\n\t// the \"top\" separator is the \"bottom\" separator of the previous block.\n\t// Therefore, this logic hides the separator if the current block is being dragged\n\t// or if the current block is the previous sibling of the block being dragged.\n\tif (\n\t\tisCurrentBlockBeingDragged ||\n\t\tisCurrentBlockPreviousSiblingOfBlockBeingDragged\n\t) {\n\t\tisVisible = false;\n\t}\n\n\treturn (\n\t\t<AnimatePresence>\n\t\t\t{ isVisible && (\n\t\t\t\t<motion.div\n\t\t\t\t\tinitial={ { height: 0 } }\n\t\t\t\t\tanimate={ {\n\t\t\t\t\t\t// Use a height equal to that of the zoom out frame size.\n\t\t\t\t\t\theight: 'calc(1 * var(--wp-block-editor-iframe-zoom-out-frame-size) / var(--wp-block-editor-iframe-zoom-out-scale)',\n\t\t\t\t\t} }\n\t\t\t\t\texit={ { height: 0 } }\n\t\t\t\t\ttransition={ {\n\t\t\t\t\t\ttype: 'tween',\n\t\t\t\t\t\tduration: isReducedMotion ? 0 : 0.2,\n\t\t\t\t\t\tease: [ 0.6, 0, 0.4, 1 ],\n\t\t\t\t\t} }\n\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t'block-editor-block-list__zoom-out-separator',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'is-dragged-over': isDraggedOver,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\tdata-is-insertion-point=\"true\"\n\t\t\t\t\tonDragOver={ () => setIsDraggedOver( true ) }\n\t\t\t\t\tonDragLeave={ () => setIsDraggedOver( false ) }\n\t\t\t\t>\n\t\t\t\t\t<motion.div\n\t\t\t\t\t\tinitial={ { opacity: 0 } }\n\t\t\t\t\t\tanimate={ { opacity: 1 } }\n\t\t\t\t\t\texit={ { opacity: 0, transition: { delay: -0.125 } } }\n\t\t\t\t\t\ttransition={ {\n\t\t\t\t\t\t\tease: 'linear',\n\t\t\t\t\t\t\tduration: 0.1,\n\t\t\t\t\t\t\tdelay: 0.125,\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Drop pattern.' ) }\n\t\t\t\t\t</motion.div>\n\t\t\t\t</motion.div>\n\t\t\t) }\n\t\t</AnimatePresence>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,SACCC,gBAAgB,IAAIC,MAAM,EAC1BC,yBAAyB,IAAIC,eAAe,QACtC,uBAAuB;AAC9B,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SA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ings,
|
|
87
87
|
getParentSectionBlock,
|
|
88
88
|
isZoomOut,
|
|
89
|
-
isNavigationMode: _isNavigationMode
|
|
89
|
+
isNavigationMode: _isNavigationMode,
|
|
90
|
+
isSectionBlock
|
|
90
91
|
} = unlock(select(blockEditorStore));
|
|
91
92
|
const selectedBlockClientIds = getSelectedBlockClientIds();
|
|
92
93
|
const selectedBlockClientId = selectedBlockClientIds[0];
|
|
@@ -96,6 +97,7 @@ export function PrivateBlockToolbar({
|
|
|
96
97
|
const parentBlockName = getBlockName(parentClientId);
|
|
97
98
|
const parentBlockType = getBlockType(parentBlockName);
|
|
98
99
|
const editingMode = getBlockEditingMode(selectedBlockClientId);
|
|
100
|
+
const isNavigationModeEnabled = _isNavigationMode();
|
|
99
101
|
const _isDefaultEditingMode = editingMode === 'default';
|
|
100
102
|
const _blockName = getBlockName(selectedBlockClientId);
|
|
101
103
|
const isValid = selectedBlockClientIds.every(id => isBlockValid(id));
|
|
@@ -121,9 +123,10 @@ export function PrivateBlockToolbar({
|
|
|
121
123
|
showSlots: !_isZoomOut,
|
|
122
124
|
showGroupButtons: !_isZoomOut,
|
|
123
125
|
showLockButtons: !_isZoomOut,
|
|
124
|
-
showSwitchSectionStyleButton: _isZoomOut,
|
|
126
|
+
showSwitchSectionStyleButton: _isZoomOut || isNavigationModeEnabled && editingMode === 'contentOnly' && isSectionBlock(selectedBlockClientId),
|
|
127
|
+
// Zoom out or Write Mode Section Blocks
|
|
125
128
|
hasFixedToolbar: getSettings().hasFixedToolbar,
|
|
126
|
-
isNavigationMode:
|
|
129
|
+
isNavigationMode: isNavigationModeEnabled
|
|
127
130
|
};
|
|
128
131
|
}, []);
|
|
129
132
|
const toolbarWrapperRef = useRef(null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["clsx","__","useSelect","useRef","useViewportMatch","getBlockType","hasBlockSupport","isReusableBlock","isTemplatePart","ToolbarGroup","BlockMover","BlockParentSelector","BlockSwitcher","BlockControls","__unstableBlockToolbarLastItem","BlockSettingsMenu","BlockLockToolbar","BlockGroupToolbar","BlockEditVisuallyButton","useShowHoveredOrFocusedGestures","store","blockEditorStore","__unstableBlockNameContext","NavigableToolbar","useHasBlockToolbar","ChangeDesign","SwitchSectionStyle","unlock","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","PrivateBlockToolbar","hideDragHandle","focusOnMount","__experimentalInitialIndex","__experimentalOnIndexChange","variant","blockClientId","blockClientIds","isDefaultEditingMode","blockType","toolbarKey","shouldShowVisualToolbar","showParentSelector","isUsingBindings","hasParentPattern","hasContentOnlyLocking","showShuffleButton","showSlots","showGroupButtons","showLockButtons","showSwitchSectionStyleButton","hasFixedToolbar","isNavigationMode","select","getBlockName","getBlockMode","getBlockParents","getSelectedBlockClientIds","isBlockValid","getBlockEditingMode","getBlockAttributes","getBlockParentsByBlockName","getTemplateLock","getSettings","getParentSectionBlock","isZoomOut","_isNavigationMode","selectedBlockClientIds","selectedBlockClientId","parents","parentSection","parentClientId","length","parentBlockName","parentBlockType","editingMode","_isDefaultEditingMode","_blockName","isValid","every","id","isVisual","_isUsingBindings","clientId","metadata","bindings","_hasParentPattern","_hasTemplateLock","some","_isZoomOut","toolbarWrapperRef","nodeRef","showHoveredOrFocusedGestures","ref","isLargeViewport","hasBlockToolbar","isMultiToolbar","isSynced","classes","innerClasses","focusEditorOnEscape","className","undefined","children","clientIds","Slot","group","Provider","value","name","BlockToolbar"],"sources":["@wordpress/block-editor/src/components/block-toolbar/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { useRef } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\tgetBlockType,\n\thasBlockSupport,\n\tisReusableBlock,\n\tisTemplatePart,\n} from '@wordpress/blocks';\nimport { ToolbarGroup } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport BlockMover from '../block-mover';\nimport BlockParentSelector from '../block-parent-selector';\nimport BlockSwitcher from '../block-switcher';\nimport BlockControls from '../block-controls';\nimport __unstableBlockToolbarLastItem from './block-toolbar-last-item';\nimport BlockSettingsMenu from '../block-settings-menu';\nimport { BlockLockToolbar } from '../block-lock';\nimport { BlockGroupToolbar } from '../convert-to-group-buttons';\nimport BlockEditVisuallyButton from '../block-edit-visually-button';\nimport { useShowHoveredOrFocusedGestures } from './utils';\nimport { store as blockEditorStore } from '../../store';\nimport __unstableBlockNameContext from './block-name-context';\nimport NavigableToolbar from '../navigable-toolbar';\nimport { useHasBlockToolbar } from './use-has-block-toolbar';\nimport ChangeDesign from './change-design';\nimport SwitchSectionStyle from './switch-section-style';\nimport { unlock } from '../../lock-unlock';\n\n/**\n * Renders the block toolbar.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/block-toolbar/README.md\n *\n * @param {Object} props Components props.\n * @param {boolean} props.hideDragHandle Show or hide the Drag Handle for drag and drop functionality.\n * @param {boolean} props.focusOnMount Focus the toolbar when mounted.\n * @param {number} props.__experimentalInitialIndex The initial index of the toolbar item to focus.\n * @param {Function} props.__experimentalOnIndexChange Callback function to be called when the index of the focused toolbar item changes.\n * @param {string} props.variant Style variant of the toolbar, also passed to the Dropdowns rendered from Block Toolbar Buttons.\n */\nexport function PrivateBlockToolbar( {\n\thideDragHandle,\n\tfocusOnMount,\n\t__experimentalInitialIndex,\n\t__experimentalOnIndexChange,\n\tvariant = 'unstyled',\n} ) {\n\tconst {\n\t\tblockClientId,\n\t\tblockClientIds,\n\t\tisDefaultEditingMode,\n\t\tblockType,\n\t\ttoolbarKey,\n\t\tshouldShowVisualToolbar,\n\t\tshowParentSelector,\n\t\tisUsingBindings,\n\t\thasParentPattern,\n\t\thasContentOnlyLocking,\n\t\tshowShuffleButton,\n\t\tshowSlots,\n\t\tshowGroupButtons,\n\t\tshowLockButtons,\n\t\tshowSwitchSectionStyleButton,\n\t\thasFixedToolbar,\n\t\tisNavigationMode,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetBlockName,\n\t\t\tgetBlockMode,\n\t\t\tgetBlockParents,\n\t\t\tgetSelectedBlockClientIds,\n\t\t\tisBlockValid,\n\t\t\tgetBlockEditingMode,\n\t\t\tgetBlockAttributes,\n\t\t\tgetBlockParentsByBlockName,\n\t\t\tgetTemplateLock,\n\t\t\tgetSettings,\n\t\t\tgetParentSectionBlock,\n\t\t\tisZoomOut,\n\t\t\tisNavigationMode: _isNavigationMode,\n\t\t} = unlock( select( blockEditorStore ) );\n\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\t\tconst selectedBlockClientId = selectedBlockClientIds[ 0 ];\n\t\tconst parents = getBlockParents( selectedBlockClientId );\n\t\tconst parentSection = getParentSectionBlock( selectedBlockClientId );\n\t\tconst parentClientId = parentSection ?? parents[ parents.length - 1 ];\n\t\tconst parentBlockName = getBlockName( parentClientId );\n\t\tconst parentBlockType = getBlockType( parentBlockName );\n\t\tconst editingMode = getBlockEditingMode( selectedBlockClientId );\n\t\tconst _isDefaultEditingMode = editingMode === 'default';\n\t\tconst _blockName = getBlockName( selectedBlockClientId );\n\t\tconst isValid = selectedBlockClientIds.every( ( id ) =>\n\t\t\tisBlockValid( id )\n\t\t);\n\t\tconst isVisual = selectedBlockClientIds.every(\n\t\t\t( id ) => getBlockMode( id ) === 'visual'\n\t\t);\n\t\tconst _isUsingBindings = selectedBlockClientIds.every(\n\t\t\t( clientId ) =>\n\t\t\t\t!! getBlockAttributes( clientId )?.metadata?.bindings\n\t\t);\n\n\t\tconst _hasParentPattern = selectedBlockClientIds.every(\n\t\t\t( clientId ) =>\n\t\t\t\tgetBlockParentsByBlockName( clientId, 'core/block', true )\n\t\t\t\t\t.length > 0\n\t\t);\n\n\t\t// If one or more selected blocks are locked, do not show the BlockGroupToolbar.\n\t\tconst _hasTemplateLock = selectedBlockClientIds.some(\n\t\t\t( id ) => getTemplateLock( id ) === 'contentOnly'\n\t\t);\n\n\t\tconst _isZoomOut = isZoomOut();\n\n\t\treturn {\n\t\t\tblockClientId: selectedBlockClientId,\n\t\t\tblockClientIds: selectedBlockClientIds,\n\t\t\tisDefaultEditingMode: _isDefaultEditingMode,\n\t\t\tblockType: selectedBlockClientId && getBlockType( _blockName ),\n\t\t\tshouldShowVisualToolbar: isValid && isVisual,\n\t\t\ttoolbarKey: `${ selectedBlockClientId }${ parentClientId }`,\n\t\t\tshowParentSelector:\n\t\t\t\t! _isZoomOut &&\n\t\t\t\tparentBlockType &&\n\t\t\t\teditingMode !== 'contentOnly' &&\n\t\t\t\tgetBlockEditingMode( parentClientId ) !== 'disabled' &&\n\t\t\t\thasBlockSupport(\n\t\t\t\t\tparentBlockType,\n\t\t\t\t\t'__experimentalParentSelector',\n\t\t\t\t\ttrue\n\t\t\t\t) &&\n\t\t\t\tselectedBlockClientIds.length === 1,\n\t\t\tisUsingBindings: _isUsingBindings,\n\t\t\thasParentPattern: _hasParentPattern,\n\t\t\thasContentOnlyLocking: _hasTemplateLock,\n\t\t\tshowShuffleButton: _isZoomOut,\n\t\t\tshowSlots: ! _isZoomOut,\n\t\t\tshowGroupButtons: ! _isZoomOut,\n\t\t\tshowLockButtons: ! _isZoomOut,\n\t\t\tshowSwitchSectionStyleButton: _isZoomOut,\n\t\t\thasFixedToolbar: getSettings().hasFixedToolbar,\n\t\t\tisNavigationMode: _isNavigationMode(),\n\t\t};\n\t}, [] );\n\n\tconst toolbarWrapperRef = useRef( null );\n\n\t// Handles highlighting the current block outline on hover or focus of the\n\t// block type toolbar area.\n\tconst nodeRef = useRef();\n\tconst showHoveredOrFocusedGestures = useShowHoveredOrFocusedGestures( {\n\t\tref: nodeRef,\n\t} );\n\n\tconst isLargeViewport = ! useViewportMatch( 'medium', '<' );\n\n\tconst hasBlockToolbar = useHasBlockToolbar();\n\tif ( ! hasBlockToolbar ) {\n\t\treturn null;\n\t}\n\n\tconst isMultiToolbar = blockClientIds.length > 1;\n\tconst isSynced =\n\t\tisReusableBlock( blockType ) || isTemplatePart( blockType );\n\n\t// Shifts the toolbar to make room for the parent block selector.\n\tconst classes = clsx( 'block-editor-block-contextual-toolbar', {\n\t\t'has-parent': showParentSelector,\n\t\t'is-inverted-toolbar': isNavigationMode && ! hasFixedToolbar,\n\t} );\n\n\tconst innerClasses = clsx( 'block-editor-block-toolbar', {\n\t\t'is-synced': isSynced,\n\t\t'is-connected': isUsingBindings,\n\t} );\n\n\treturn (\n\t\t<NavigableToolbar\n\t\t\tfocusEditorOnEscape\n\t\t\tclassName={ classes }\n\t\t\t/* translators: accessibility text for the block toolbar */\n\t\t\taria-label={ __( 'Block tools' ) }\n\t\t\t// The variant is applied as \"toolbar\" when undefined, which is the black border style of the dropdown from the toolbar popover.\n\t\t\tvariant={ variant === 'toolbar' ? undefined : variant }\n\t\t\tfocusOnMount={ focusOnMount }\n\t\t\t__experimentalInitialIndex={ __experimentalInitialIndex }\n\t\t\t__experimentalOnIndexChange={ __experimentalOnIndexChange }\n\t\t\t// Resets the index whenever the active block changes so\n\t\t\t// this is not persisted. See https://github.com/WordPress/gutenberg/pull/25760#issuecomment-717906169\n\t\t\tkey={ toolbarKey }\n\t\t>\n\t\t\t<div ref={ toolbarWrapperRef } className={ innerClasses }>\n\t\t\t\t{ showParentSelector && ! isMultiToolbar && isLargeViewport && (\n\t\t\t\t\t<BlockParentSelector />\n\t\t\t\t) }\n\t\t\t\t{ ( shouldShowVisualToolbar || isMultiToolbar ) &&\n\t\t\t\t\t! hasParentPattern && (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tref={ nodeRef }\n\t\t\t\t\t\t\t{ ...showHoveredOrFocusedGestures }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ToolbarGroup className=\"block-editor-block-toolbar__block-controls\">\n\t\t\t\t\t\t\t\t<BlockSwitcher clientIds={ blockClientIds } />\n\t\t\t\t\t\t\t\t{ ! isMultiToolbar &&\n\t\t\t\t\t\t\t\t\tisDefaultEditingMode &&\n\t\t\t\t\t\t\t\t\tshowLockButtons && (\n\t\t\t\t\t\t\t\t\t\t<BlockLockToolbar\n\t\t\t\t\t\t\t\t\t\t\tclientId={ blockClientId }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t<BlockMover\n\t\t\t\t\t\t\t\t\tclientIds={ blockClientIds }\n\t\t\t\t\t\t\t\t\thideDragHandle={ hideDragHandle }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ToolbarGroup>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\t\t\t\t{ ! hasContentOnlyLocking &&\n\t\t\t\t\tshouldShowVisualToolbar &&\n\t\t\t\t\tisMultiToolbar &&\n\t\t\t\t\tshowGroupButtons && <BlockGroupToolbar /> }\n\t\t\t\t{ showShuffleButton && (\n\t\t\t\t\t<ChangeDesign clientId={ blockClientIds[ 0 ] } />\n\t\t\t\t) }\n\t\t\t\t{ showSwitchSectionStyleButton && (\n\t\t\t\t\t<SwitchSectionStyle clientId={ blockClientIds[ 0 ] } />\n\t\t\t\t) }\n\t\t\t\t{ shouldShowVisualToolbar && showSlots && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\t\tgroup=\"parent\"\n\t\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\t\tgroup=\"block\"\n\t\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<BlockControls.Slot className=\"block-editor-block-toolbar__slot\" />\n\t\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\t\tgroup=\"inline\"\n\t\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\t\tgroup=\"other\"\n\t\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<__unstableBlockNameContext.Provider\n\t\t\t\t\t\t\tvalue={ blockType?.name }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<__unstableBlockToolbarLastItem.Slot />\n\t\t\t\t\t\t</__unstableBlockNameContext.Provider>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t\t<BlockEditVisuallyButton clientIds={ blockClientIds } />\n\t\t\t\t<BlockSettingsMenu clientIds={ blockClientIds } />\n\t\t\t</div>\n\t\t</NavigableToolbar>\n\t);\n}\n\n/**\n * Renders the block toolbar.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/block-toolbar/README.md\n *\n * @param {Object} props Components props.\n * @param {boolean} props.hideDragHandle Show or hide the Drag Handle for drag and drop functionality.\n * @param {string} props.variant Style variant of the toolbar, also passed to the Dropdowns rendered from Block Toolbar Buttons.\n */\nexport default function BlockToolbar( { hideDragHandle, variant } ) {\n\treturn (\n\t\t<PrivateBlockToolbar\n\t\t\thideDragHandle={ hideDragHandle }\n\t\t\tvariant={ variant }\n\t\t\tfocusOnMount={ undefined }\n\t\t\t__experimentalInitialIndex={ undefined }\n\t\t\t__experimentalOnIndexChange={ undefined }\n\t\t/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,MAAM,QAAQ,oBAAoB;AAC3C,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SACCC,YAAY,EACZC,eAAe,EACfC,eAAe,EACfC,cAAc,QACR,mBAAmB;AAC1B,SAASC,YAAY,QAAQ,uBAAuB;;AAEpD;AACA;AACA;AACA,OAAOC,UAAU,MAAM,gBAAgB;AACvC,OAAOC,mBAAmB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C,eACF5E,IAAA,CAAChB,aAAa,CAACgG,IAAI;UAClBC,KAAK,EAAC,OAAO;UACbL,SAAS,EAAC;QAAkC,CAC5C,CAAC,eACF5E,IAAA,CAACP,0BAA0B,CAACyF,QAAQ;UACnCC,KAAK,EAAGrE,SAAS,EAAEsE,IAAM;UAAAN,QAAA,eAEzB9E,IAAA,CAACf,8BAA8B,CAAC+F,IAAI,IAAE;QAAC,CACH,CAAC;MAAA,CACrC,CACF,eACDhF,IAAA,CAACX,uBAAuB;QAAC0F,SAAS,EAAGnE;MAAgB,CAAE,CAAC,eACxDZ,IAAA,CAACd,iBAAiB;QAAC6F,SAAS,EAAGnE;MAAgB,CAAE,CAAC;IAAA,CAC9C;EAAC,GAlEAG,UAmEW,CAAC;AAErB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASsE,YAAYA,CAAE;EAAE/E,cAAc;EAAEI;AAAQ,CAAC,EAAG;EACnE,oBACCV,IAAA,CAACK,mBAAmB;IACnBC,cAAc,EAAGA,cAAgB;IACjCI,OAAO,EAAGA,OAAS;IACnBH,YAAY,EAAGsE,SAAW;IAC1BrE,0BAA0B,EAAGqE,SAAW;IACxCpE,2BAA2B,EAAGoE;EAAW,CACzC,CAAC;AAEJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["clsx","__","useSelect","useRef","useViewportMatch","getBlockType","hasBlockSupport","isReusableBlock","isTemplatePart","ToolbarGroup","BlockMover","BlockParentSelector","BlockSwitcher","BlockControls","__unstableBlockToolbarLastItem","BlockSettingsMenu","BlockLockToolbar","BlockGroupToolbar","BlockEditVisuallyButton","useShowHoveredOrFocusedGestures","store","blockEditorStore","__unstableBlockNameContext","NavigableToolbar","useHasBlockToolbar","ChangeDesign","SwitchSectionStyle","unlock","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","PrivateBlockToolbar","hideDragHandle","focusOnMount","__experimentalInitialIndex","__experimentalOnIndexChange","variant","blockClientId","blockClientIds","isDefaultEditingMode","blockType","toolbarKey","shouldShowVisualToolbar","showParentSelector","isUsingBindings","hasParentPattern","hasContentOnlyLocking","showShuffleButton","showSlots","showGroupButtons","showLockButtons","showSwitchSectionStyleButton","hasFixedToolbar","isNavigationMode","select","getBlockName","getBlockMode","getBlockParents","getSelectedBlockClientIds","isBlockValid","getBlockEditingMode","getBlockAttributes","getBlockParentsByBlockName","getTemplateLock","getSettings","getParentSectionBlock","isZoomOut","_isNavigationMode","isSectionBlock","selectedBlockClientIds","selectedBlockClientId","parents","parentSection","parentClientId","length","parentBlockName","parentBlockType","editingMode","isNavigationModeEnabled","_isDefaultEditingMode","_blockName","isValid","every","id","isVisual","_isUsingBindings","clientId","metadata","bindings","_hasParentPattern","_hasTemplateLock","some","_isZoomOut","toolbarWrapperRef","nodeRef","showHoveredOrFocusedGestures","ref","isLargeViewport","hasBlockToolbar","isMultiToolbar","isSynced","classes","innerClasses","focusEditorOnEscape","className","undefined","children","clientIds","Slot","group","Provider","value","name","BlockToolbar"],"sources":["@wordpress/block-editor/src/components/block-toolbar/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { useRef } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\tgetBlockType,\n\thasBlockSupport,\n\tisReusableBlock,\n\tisTemplatePart,\n} from '@wordpress/blocks';\nimport { ToolbarGroup } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport BlockMover from '../block-mover';\nimport BlockParentSelector from '../block-parent-selector';\nimport BlockSwitcher from '../block-switcher';\nimport BlockControls from '../block-controls';\nimport __unstableBlockToolbarLastItem from './block-toolbar-last-item';\nimport BlockSettingsMenu from '../block-settings-menu';\nimport { BlockLockToolbar } from '../block-lock';\nimport { BlockGroupToolbar } from '../convert-to-group-buttons';\nimport BlockEditVisuallyButton from '../block-edit-visually-button';\nimport { useShowHoveredOrFocusedGestures } from './utils';\nimport { store as blockEditorStore } from '../../store';\nimport __unstableBlockNameContext from './block-name-context';\nimport NavigableToolbar from '../navigable-toolbar';\nimport { useHasBlockToolbar } from './use-has-block-toolbar';\nimport ChangeDesign from './change-design';\nimport SwitchSectionStyle from './switch-section-style';\nimport { unlock } from '../../lock-unlock';\n\n/**\n * Renders the block toolbar.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/block-toolbar/README.md\n *\n * @param {Object} props Components props.\n * @param {boolean} props.hideDragHandle Show or hide the Drag Handle for drag and drop functionality.\n * @param {boolean} props.focusOnMount Focus the toolbar when mounted.\n * @param {number} props.__experimentalInitialIndex The initial index of the toolbar item to focus.\n * @param {Function} props.__experimentalOnIndexChange Callback function to be called when the index of the focused toolbar item changes.\n * @param {string} props.variant Style variant of the toolbar, also passed to the Dropdowns rendered from Block Toolbar Buttons.\n */\nexport function PrivateBlockToolbar( {\n\thideDragHandle,\n\tfocusOnMount,\n\t__experimentalInitialIndex,\n\t__experimentalOnIndexChange,\n\tvariant = 'unstyled',\n} ) {\n\tconst {\n\t\tblockClientId,\n\t\tblockClientIds,\n\t\tisDefaultEditingMode,\n\t\tblockType,\n\t\ttoolbarKey,\n\t\tshouldShowVisualToolbar,\n\t\tshowParentSelector,\n\t\tisUsingBindings,\n\t\thasParentPattern,\n\t\thasContentOnlyLocking,\n\t\tshowShuffleButton,\n\t\tshowSlots,\n\t\tshowGroupButtons,\n\t\tshowLockButtons,\n\t\tshowSwitchSectionStyleButton,\n\t\thasFixedToolbar,\n\t\tisNavigationMode,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetBlockName,\n\t\t\tgetBlockMode,\n\t\t\tgetBlockParents,\n\t\t\tgetSelectedBlockClientIds,\n\t\t\tisBlockValid,\n\t\t\tgetBlockEditingMode,\n\t\t\tgetBlockAttributes,\n\t\t\tgetBlockParentsByBlockName,\n\t\t\tgetTemplateLock,\n\t\t\tgetSettings,\n\t\t\tgetParentSectionBlock,\n\t\t\tisZoomOut,\n\t\t\tisNavigationMode: _isNavigationMode,\n\t\t\tisSectionBlock,\n\t\t} = unlock( select( blockEditorStore ) );\n\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\t\tconst selectedBlockClientId = selectedBlockClientIds[ 0 ];\n\t\tconst parents = getBlockParents( selectedBlockClientId );\n\t\tconst parentSection = getParentSectionBlock( selectedBlockClientId );\n\t\tconst parentClientId = parentSection ?? parents[ parents.length - 1 ];\n\t\tconst parentBlockName = getBlockName( parentClientId );\n\t\tconst parentBlockType = getBlockType( parentBlockName );\n\t\tconst editingMode = getBlockEditingMode( selectedBlockClientId );\n\t\tconst isNavigationModeEnabled = _isNavigationMode();\n\t\tconst _isDefaultEditingMode = editingMode === 'default';\n\t\tconst _blockName = getBlockName( selectedBlockClientId );\n\t\tconst isValid = selectedBlockClientIds.every( ( id ) =>\n\t\t\tisBlockValid( id )\n\t\t);\n\t\tconst isVisual = selectedBlockClientIds.every(\n\t\t\t( id ) => getBlockMode( id ) === 'visual'\n\t\t);\n\t\tconst _isUsingBindings = selectedBlockClientIds.every(\n\t\t\t( clientId ) =>\n\t\t\t\t!! getBlockAttributes( clientId )?.metadata?.bindings\n\t\t);\n\n\t\tconst _hasParentPattern = selectedBlockClientIds.every(\n\t\t\t( clientId ) =>\n\t\t\t\tgetBlockParentsByBlockName( clientId, 'core/block', true )\n\t\t\t\t\t.length > 0\n\t\t);\n\n\t\t// If one or more selected blocks are locked, do not show the BlockGroupToolbar.\n\t\tconst _hasTemplateLock = selectedBlockClientIds.some(\n\t\t\t( id ) => getTemplateLock( id ) === 'contentOnly'\n\t\t);\n\n\t\tconst _isZoomOut = isZoomOut();\n\n\t\treturn {\n\t\t\tblockClientId: selectedBlockClientId,\n\t\t\tblockClientIds: selectedBlockClientIds,\n\t\t\tisDefaultEditingMode: _isDefaultEditingMode,\n\t\t\tblockType: selectedBlockClientId && getBlockType( _blockName ),\n\t\t\tshouldShowVisualToolbar: isValid && isVisual,\n\t\t\ttoolbarKey: `${ selectedBlockClientId }${ parentClientId }`,\n\t\t\tshowParentSelector:\n\t\t\t\t! _isZoomOut &&\n\t\t\t\tparentBlockType &&\n\t\t\t\teditingMode !== 'contentOnly' &&\n\t\t\t\tgetBlockEditingMode( parentClientId ) !== 'disabled' &&\n\t\t\t\thasBlockSupport(\n\t\t\t\t\tparentBlockType,\n\t\t\t\t\t'__experimentalParentSelector',\n\t\t\t\t\ttrue\n\t\t\t\t) &&\n\t\t\t\tselectedBlockClientIds.length === 1,\n\t\t\tisUsingBindings: _isUsingBindings,\n\t\t\thasParentPattern: _hasParentPattern,\n\t\t\thasContentOnlyLocking: _hasTemplateLock,\n\t\t\tshowShuffleButton: _isZoomOut,\n\t\t\tshowSlots: ! _isZoomOut,\n\t\t\tshowGroupButtons: ! _isZoomOut,\n\t\t\tshowLockButtons: ! _isZoomOut,\n\t\t\tshowSwitchSectionStyleButton:\n\t\t\t\t_isZoomOut ||\n\t\t\t\t( isNavigationModeEnabled &&\n\t\t\t\t\teditingMode === 'contentOnly' &&\n\t\t\t\t\tisSectionBlock( selectedBlockClientId ) ), // Zoom out or Write Mode Section Blocks\n\t\t\thasFixedToolbar: getSettings().hasFixedToolbar,\n\t\t\tisNavigationMode: isNavigationModeEnabled,\n\t\t};\n\t}, [] );\n\n\tconst toolbarWrapperRef = useRef( null );\n\n\t// Handles highlighting the current block outline on hover or focus of the\n\t// block type toolbar area.\n\tconst nodeRef = useRef();\n\tconst showHoveredOrFocusedGestures = useShowHoveredOrFocusedGestures( {\n\t\tref: nodeRef,\n\t} );\n\n\tconst isLargeViewport = ! useViewportMatch( 'medium', '<' );\n\n\tconst hasBlockToolbar = useHasBlockToolbar();\n\tif ( ! hasBlockToolbar ) {\n\t\treturn null;\n\t}\n\n\tconst isMultiToolbar = blockClientIds.length > 1;\n\tconst isSynced =\n\t\tisReusableBlock( blockType ) || isTemplatePart( blockType );\n\n\t// Shifts the toolbar to make room for the parent block selector.\n\tconst classes = clsx( 'block-editor-block-contextual-toolbar', {\n\t\t'has-parent': showParentSelector,\n\t\t'is-inverted-toolbar': isNavigationMode && ! hasFixedToolbar,\n\t} );\n\n\tconst innerClasses = clsx( 'block-editor-block-toolbar', {\n\t\t'is-synced': isSynced,\n\t\t'is-connected': isUsingBindings,\n\t} );\n\n\treturn (\n\t\t<NavigableToolbar\n\t\t\tfocusEditorOnEscape\n\t\t\tclassName={ classes }\n\t\t\t/* translators: accessibility text for the block toolbar */\n\t\t\taria-label={ __( 'Block tools' ) }\n\t\t\t// The variant is applied as \"toolbar\" when undefined, which is the black border style of the dropdown from the toolbar popover.\n\t\t\tvariant={ variant === 'toolbar' ? undefined : variant }\n\t\t\tfocusOnMount={ focusOnMount }\n\t\t\t__experimentalInitialIndex={ __experimentalInitialIndex }\n\t\t\t__experimentalOnIndexChange={ __experimentalOnIndexChange }\n\t\t\t// Resets the index whenever the active block changes so\n\t\t\t// this is not persisted. See https://github.com/WordPress/gutenberg/pull/25760#issuecomment-717906169\n\t\t\tkey={ toolbarKey }\n\t\t>\n\t\t\t<div ref={ toolbarWrapperRef } className={ innerClasses }>\n\t\t\t\t{ showParentSelector && ! isMultiToolbar && isLargeViewport && (\n\t\t\t\t\t<BlockParentSelector />\n\t\t\t\t) }\n\t\t\t\t{ ( shouldShowVisualToolbar || isMultiToolbar ) &&\n\t\t\t\t\t! hasParentPattern && (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tref={ nodeRef }\n\t\t\t\t\t\t\t{ ...showHoveredOrFocusedGestures }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ToolbarGroup className=\"block-editor-block-toolbar__block-controls\">\n\t\t\t\t\t\t\t\t<BlockSwitcher clientIds={ blockClientIds } />\n\t\t\t\t\t\t\t\t{ ! isMultiToolbar &&\n\t\t\t\t\t\t\t\t\tisDefaultEditingMode &&\n\t\t\t\t\t\t\t\t\tshowLockButtons && (\n\t\t\t\t\t\t\t\t\t\t<BlockLockToolbar\n\t\t\t\t\t\t\t\t\t\t\tclientId={ blockClientId }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t<BlockMover\n\t\t\t\t\t\t\t\t\tclientIds={ blockClientIds }\n\t\t\t\t\t\t\t\t\thideDragHandle={ hideDragHandle }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ToolbarGroup>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\t\t\t\t{ ! hasContentOnlyLocking &&\n\t\t\t\t\tshouldShowVisualToolbar &&\n\t\t\t\t\tisMultiToolbar &&\n\t\t\t\t\tshowGroupButtons && <BlockGroupToolbar /> }\n\t\t\t\t{ showShuffleButton && (\n\t\t\t\t\t<ChangeDesign clientId={ blockClientIds[ 0 ] } />\n\t\t\t\t) }\n\t\t\t\t{ showSwitchSectionStyleButton && (\n\t\t\t\t\t<SwitchSectionStyle clientId={ blockClientIds[ 0 ] } />\n\t\t\t\t) }\n\t\t\t\t{ shouldShowVisualToolbar && showSlots && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\t\tgroup=\"parent\"\n\t\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\t\tgroup=\"block\"\n\t\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<BlockControls.Slot className=\"block-editor-block-toolbar__slot\" />\n\t\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\t\tgroup=\"inline\"\n\t\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\t\tgroup=\"other\"\n\t\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<__unstableBlockNameContext.Provider\n\t\t\t\t\t\t\tvalue={ blockType?.name }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<__unstableBlockToolbarLastItem.Slot />\n\t\t\t\t\t\t</__unstableBlockNameContext.Provider>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t\t<BlockEditVisuallyButton clientIds={ blockClientIds } />\n\t\t\t\t<BlockSettingsMenu clientIds={ blockClientIds } />\n\t\t\t</div>\n\t\t</NavigableToolbar>\n\t);\n}\n\n/**\n * Renders the block toolbar.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/block-toolbar/README.md\n *\n * @param {Object} props Components props.\n * @param {boolean} props.hideDragHandle Show or hide the Drag Handle for drag and drop functionality.\n * @param {string} props.variant Style variant of the toolbar, also passed to the Dropdowns rendered from Block Toolbar Buttons.\n */\nexport default function BlockToolbar( { hideDragHandle, variant } ) {\n\treturn (\n\t\t<PrivateBlockToolbar\n\t\t\thideDragHandle={ hideDragHandle }\n\t\t\tvariant={ variant }\n\t\t\tfocusOnMount={ undefined }\n\t\t\t__experimentalInitialIndex={ undefined }\n\t\t\t__experimentalOnIndexChange={ undefined }\n\t\t/>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,MAAM,QAAQ,oBAAoB;AAC3C,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD,SACCC,YAAY,EACZC,eAAe,EACfC,eAAe,EACfC,cAAc,QACR,mBAAmB;AAC1B,SAASC,YAAY,QAAQ,uBAAuB;;AAEpD;AACA;AACA;AACA,OAAOC,UAAU,MAAM,gBAAgB;AACvC,OAAOC,mBAAmB,MAAM,0BAA0B;AAC1D,OAAOC,aAAa,MAAM,mBAAmB;AAC7C,OAAOC,aA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IAAI;UAClBC,KAAK,EAAC,QAAQ;UACdL,SAAS,EAAC;QAAkC,CAC5C,CAAC,eACF9E,IAAA,CAAChB,aAAa,CAACkG,IAAI;UAClBC,KAAK,EAAC,OAAO;UACbL,SAAS,EAAC;QAAkC,CAC5C,CAAC,eACF9E,IAAA,CAACP,0BAA0B,CAAC2F,QAAQ;UACnCC,KAAK,EAAGvE,SAAS,EAAEwE,IAAM;UAAAN,QAAA,eAEzBhF,IAAA,CAACf,8BAA8B,CAACiG,IAAI,IAAE;QAAC,CACH,CAAC;MAAA,CACrC,CACF,eACDlF,IAAA,CAACX,uBAAuB;QAAC4F,SAAS,EAAGrE;MAAgB,CAAE,CAAC,eACxDZ,IAAA,CAACd,iBAAiB;QAAC+F,SAAS,EAAGrE;MAAgB,CAAE,CAAC;IAAA,CAC9C;EAAC,GAlEAG,UAmEW,CAAC;AAErB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASwE,YAAYA,CAAE;EAAEjF,cAAc;EAAEI;AAAQ,CAAC,EAAG;EACnE,oBACCV,IAAA,CAACK,mBAAmB;IACnBC,cAAc,EAAGA,cAAgB;IACjCI,OAAO,EAAGA,OAAS;IACnBH,YAAY,EAAGwE,SAAW;IAC1BvE,0BAA0B,EAAGuE,SAAW;IACxCtE,2BAA2B,EAAGsE;EAAW,CACzC,CAAC;AAEJ","ignoreList":[]}
|
|
@@ -132,6 +132,24 @@ function Iframe({
|
|
|
132
132
|
function preventFileDropDefault(event) {
|
|
133
133
|
event.preventDefault();
|
|
134
134
|
}
|
|
135
|
+
// Prevent clicks on link fragments from navigating away. Note that links
|
|
136
|
+
// inside `contenteditable` are already disabled by the browser, so
|
|
137
|
+
// this is for links in blocks outside of `contenteditable`.
|
|
138
|
+
function interceptLinkClicks(event) {
|
|
139
|
+
if (event.target.tagName === 'A' && event.target.getAttribute('href')?.startsWith('#')) {
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
// Manually handle link fragment navigation within the iframe. The iframe's
|
|
142
|
+
// location is a blob URL, which can't be used to resolve relative links like
|
|
143
|
+
// `#hash`. The relative link would be resolved against the iframe's base URL
|
|
144
|
+
// or the parent frame's URL, causing the iframe to navigate to a completely
|
|
145
|
+
// different page. Setting the `location.hash` works because it really sets the
|
|
146
|
+
// blob URL's hash.
|
|
147
|
+
//
|
|
148
|
+
// Links with fragments are used for example with footnotes. Clicking on these
|
|
149
|
+
// links will scroll smoothly to the anchors in the editor canvas.
|
|
150
|
+
iFrameDocument.defaultView.location.hash = event.target.getAttribute('href').slice(1);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
135
153
|
const {
|
|
136
154
|
ownerDocument
|
|
137
155
|
} = node;
|
|
@@ -163,21 +181,7 @@ function Iframe({
|
|
|
163
181
|
}
|
|
164
182
|
iFrameDocument.addEventListener('dragover', preventFileDropDefault, false);
|
|
165
183
|
iFrameDocument.addEventListener('drop', preventFileDropDefault, false);
|
|
166
|
-
|
|
167
|
-
// inside `contenteditable` are already disabled by the browser, so
|
|
168
|
-
// this is for links in blocks outside of `contenteditable`.
|
|
169
|
-
iFrameDocument.addEventListener('click', event => {
|
|
170
|
-
if (event.target.tagName === 'A') {
|
|
171
|
-
event.preventDefault();
|
|
172
|
-
|
|
173
|
-
// Appending a hash to the current URL will not reload the
|
|
174
|
-
// page. This is useful for e.g. footnotes.
|
|
175
|
-
const href = event.target.getAttribute('href');
|
|
176
|
-
if (href?.startsWith('#')) {
|
|
177
|
-
iFrameDocument.defaultView.location.hash = href.slice(1);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
});
|
|
184
|
+
iFrameDocument.addEventListener('click', interceptLinkClicks);
|
|
181
185
|
}
|
|
182
186
|
node.addEventListener('load', onLoad);
|
|
183
187
|
return () => {
|
|
@@ -185,6 +189,7 @@ function Iframe({
|
|
|
185
189
|
node.removeEventListener('load', onLoad);
|
|
186
190
|
iFrameDocument?.removeEventListener('dragover', preventFileDropDefault);
|
|
187
191
|
iFrameDocument?.removeEventListener('drop', preventFileDropDefault);
|
|
192
|
+
iFrameDocument?.removeEventListener('click', interceptLinkClicks);
|
|
188
193
|
};
|
|
189
194
|
}, []);
|
|
190
195
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["clsx","useState","createPortal","forwardRef","useMemo","useEffect","__","useMergeRefs","useRefEffect","useDisabled","__experimentalStyleProvider","StyleProvider","useSelect","useBlockSelectionClearer","useWritingFlow","getCompatibilityStyles","useScaleCanvas","store","blockEditorStore","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","bubbleEvent","event","Constructor","frame","init","key","contentDocument","defaultView","MouseEvent","rect","getBoundingClientRect","clientX","left","clientY","top","newEvent","type","defaultPrevented","preventDefault","cancelled","dispatchEvent","useBubbleEvents","iframeDocument","frameElement","html","documentElement","eventTypes","handlers","name","prototype","Object","getPrototypeOf","constructorName","constructor","window","addEventListener","removeEventListener","Iframe","contentRef","children","tabIndex","scale","frameSize","readonly","forwardedRef","ref","title","props","resolvedAssets","isPreviewMode","select","getSettings","settings","__unstableResolvedAssets","styles","scripts","setIframeDocument","bodyClasses","setBodyClasses","clearerRef","before","writingFlowRef","after","setRef","node","_load","iFrameDocument","preventFileDropDefault","ownerDocument","Array","from","body","classList","filter","startsWith","onLoad","add","dir","compatStyle","getElementById","id","head","appendChild","cloneNode","console","warn","target","tagName","href","getAttribute","location","hash","slice","contentResizeListener","containerResizeListener","isZoomedOut","scaleContainerWidth","parseInt","disabledRef","isDisabled","bodyRef","origin","src","cleanup","_src","URL","createObjectURL","Blob","revokeObjectURL","shouldRenderFocusCaptureElements","iframe","style","height","border","onKeyDown","currentTarget","stopPropagation","nativeEvent","KeyboardEvent","className","document","IframeIfReady","isInitialised","__internalIsInitialized"],"sources":["@wordpress/block-editor/src/components/iframe/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tcreatePortal,\n\tforwardRef,\n\tuseMemo,\n\tuseEffect,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect, useDisabled } from '@wordpress/compose';\nimport { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useWritingFlow } from '../writing-flow';\nimport { getCompatibilityStyles } from './get-compatibility-styles';\nimport { useScaleCanvas } from './use-scale-canvas';\nimport { store as blockEditorStore } from '../../store';\n\nfunction bubbleEvent( event, Constructor, frame ) {\n\tconst init = {};\n\n\tfor ( const key in event ) {\n\t\tinit[ key ] = event[ key ];\n\t}\n\n\t// Check if the event is a MouseEvent generated within the iframe.\n\t// If so, adjust the coordinates to be relative to the position of\n\t// the iframe. This ensures that components such as Draggable\n\t// receive coordinates relative to the window, instead of relative\n\t// to the iframe. Without this, the Draggable event handler would\n\t// result in components \"jumping\" position as soon as the user\n\t// drags over the iframe.\n\tif ( event instanceof frame.contentDocument.defaultView.MouseEvent ) {\n\t\tconst rect = frame.getBoundingClientRect();\n\t\tinit.clientX += rect.left;\n\t\tinit.clientY += rect.top;\n\t}\n\n\tconst newEvent = new Constructor( event.type, init );\n\tif ( init.defaultPrevented ) {\n\t\tnewEvent.preventDefault();\n\t}\n\tconst cancelled = ! frame.dispatchEvent( newEvent );\n\n\tif ( cancelled ) {\n\t\tevent.preventDefault();\n\t}\n}\n\n/**\n * Bubbles some event types (keydown, keypress, and dragover) to parent document\n * document to ensure that the keyboard shortcuts and drag and drop work.\n *\n * Ideally, we should remove event bubbling in the future. Keyboard shortcuts\n * should be context dependent, e.g. actions on blocks like Cmd+A should not\n * work globally outside the block editor.\n *\n * @param {Document} iframeDocument Document to attach listeners to.\n */\nfunction useBubbleEvents( iframeDocument ) {\n\treturn useRefEffect( () => {\n\t\tconst { defaultView } = iframeDocument;\n\t\tif ( ! defaultView ) {\n\t\t\treturn;\n\t\t}\n\t\tconst { frameElement } = defaultView;\n\t\tconst html = iframeDocument.documentElement;\n\t\tconst eventTypes = [ 'dragover', 'mousemove' ];\n\t\tconst handlers = {};\n\t\tfor ( const name of eventTypes ) {\n\t\t\thandlers[ name ] = ( event ) => {\n\t\t\t\tconst prototype = Object.getPrototypeOf( event );\n\t\t\t\tconst constructorName = prototype.constructor.name;\n\t\t\t\tconst Constructor = window[ constructorName ];\n\t\t\t\tbubbleEvent( event, Constructor, frameElement );\n\t\t\t};\n\t\t\thtml.addEventListener( name, handlers[ name ] );\n\t\t}\n\n\t\treturn () => {\n\t\t\tfor ( const name of eventTypes ) {\n\t\t\t\thtml.removeEventListener( name, handlers[ name ] );\n\t\t\t}\n\t\t};\n\t} );\n}\n\nfunction Iframe( {\n\tcontentRef,\n\tchildren,\n\ttabIndex = 0,\n\tscale = 1,\n\tframeSize = 0,\n\treadonly,\n\tforwardedRef: ref,\n\ttitle = __( 'Editor canvas' ),\n\t...props\n} ) {\n\tconst { resolvedAssets, isPreviewMode } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst settings = getSettings();\n\t\treturn {\n\t\t\tresolvedAssets: settings.__unstableResolvedAssets,\n\t\t\tisPreviewMode: settings.isPreviewMode,\n\t\t};\n\t}, [] );\n\tconst { styles = '', scripts = '' } = resolvedAssets;\n\t/** @type {[Document, import('react').Dispatch<Document>]} */\n\tconst [ iframeDocument, setIframeDocument ] = useState();\n\tconst [ bodyClasses, setBodyClasses ] = useState( [] );\n\tconst clearerRef = useBlockSelectionClearer();\n\tconst [ before, writingFlowRef, after ] = useWritingFlow();\n\n\tconst setRef = useRefEffect( ( node ) => {\n\t\tnode._load = () => {\n\t\t\tsetIframeDocument( node.contentDocument );\n\t\t};\n\t\tlet iFrameDocument;\n\t\t// Prevent the default browser action for files dropped outside of dropzones.\n\t\tfunction preventFileDropDefault( event ) {\n\t\t\tevent.preventDefault();\n\t\t}\n\n\t\tconst { ownerDocument } = node;\n\n\t\t// Ideally ALL classes that are added through get_body_class should\n\t\t// be added in the editor too, which we'll somehow have to get from\n\t\t// the server in the future (which will run the PHP filters).\n\t\tsetBodyClasses(\n\t\t\tArray.from( ownerDocument.body.classList ).filter(\n\t\t\t\t( name ) =>\n\t\t\t\t\tname.startsWith( 'admin-color-' ) ||\n\t\t\t\t\tname.startsWith( 'post-type-' ) ||\n\t\t\t\t\tname === 'wp-embed-responsive'\n\t\t\t)\n\t\t);\n\n\t\tfunction onLoad() {\n\t\t\tconst { contentDocument } = node;\n\t\t\tconst { documentElement } = contentDocument;\n\t\t\tiFrameDocument = contentDocument;\n\n\t\t\tdocumentElement.classList.add( 'block-editor-iframe__html' );\n\n\t\t\tclearerRef( documentElement );\n\n\t\t\tcontentDocument.dir = ownerDocument.dir;\n\n\t\t\tfor ( const compatStyle of getCompatibilityStyles() ) {\n\t\t\t\tif ( contentDocument.getElementById( compatStyle.id ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tcontentDocument.head.appendChild(\n\t\t\t\t\tcompatStyle.cloneNode( true )\n\t\t\t\t);\n\n\t\t\t\tif ( ! isPreviewMode ) {\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`${ compatStyle.id } was added to the iframe incorrectly. Please use block.json or enqueue_block_assets to add styles to the iframe.`,\n\t\t\t\t\t\tcompatStyle\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tiFrameDocument.addEventListener(\n\t\t\t\t'dragover',\n\t\t\t\tpreventFileDropDefault,\n\t\t\t\tfalse\n\t\t\t);\n\t\t\tiFrameDocument.addEventListener(\n\t\t\t\t'drop',\n\t\t\t\tpreventFileDropDefault,\n\t\t\t\tfalse\n\t\t\t);\n\t\t\t// Prevent clicks on links from navigating away. Note that links\n\t\t\t// inside `contenteditable` are already disabled by the browser, so\n\t\t\t// this is for links in blocks outside of `contenteditable`.\n\t\t\tiFrameDocument.addEventListener( 'click', ( event ) => {\n\t\t\t\tif ( event.target.tagName === 'A' ) {\n\t\t\t\t\tevent.preventDefault();\n\n\t\t\t\t\t// Appending a hash to the current URL will not reload the\n\t\t\t\t\t// page. This is useful for e.g. footnotes.\n\t\t\t\t\tconst href = event.target.getAttribute( 'href' );\n\t\t\t\t\tif ( href?.startsWith( '#' ) ) {\n\t\t\t\t\t\tiFrameDocument.defaultView.location.hash =\n\t\t\t\t\t\t\thref.slice( 1 );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\tnode.addEventListener( 'load', onLoad );\n\n\t\treturn () => {\n\t\t\tdelete node._load;\n\t\t\tnode.removeEventListener( 'load', onLoad );\n\t\t\tiFrameDocument?.removeEventListener(\n\t\t\t\t'dragover',\n\t\t\t\tpreventFileDropDefault\n\t\t\t);\n\t\t\tiFrameDocument?.removeEventListener(\n\t\t\t\t'drop',\n\t\t\t\tpreventFileDropDefault\n\t\t\t);\n\t\t};\n\t}, [] );\n\n\tconst {\n\t\tcontentResizeListener,\n\t\tcontainerResizeListener,\n\t\tisZoomedOut,\n\t\tscaleContainerWidth,\n\t} = useScaleCanvas( {\n\t\tscale,\n\t\tframeSize: parseInt( frameSize ),\n\t\tiframeDocument,\n\t} );\n\n\tconst disabledRef = useDisabled( { isDisabled: ! readonly } );\n\tconst bodyRef = useMergeRefs( [\n\t\tuseBubbleEvents( iframeDocument ),\n\t\tcontentRef,\n\t\tclearerRef,\n\t\twritingFlowRef,\n\t\tdisabledRef,\n\t] );\n\n\t// Correct doctype is required to enable rendering in standards\n\t// mode. Also preload the styles to avoid a flash of unstyled\n\t// content.\n\tconst html = `<!doctype html>\n<html>\n\t<head>\n\t\t<meta charset=\"utf-8\">\n\t\t<base href=\"${ window.location.origin }\">\n\t\t<script>window.frameElement._load()</script>\n\t\t<style>\n\t\t\thtml{\n\t\t\t\theight: auto !important;\n\t\t\t\tmin-height: 100%;\n\t\t\t}\n\t\t\t/* Lowest specificity to not override global styles */\n\t\t\t:where(body) {\n\t\t\t\tmargin: 0;\n\t\t\t\t/* Default background color in case zoom out mode background\n\t\t\t\tcolors the html element */\n\t\t\t\tbackground-color: white;\n\t\t\t}\n\t\t</style>\n\t\t${ styles }\n\t\t${ scripts }\n\t</head>\n\t<body>\n\t\t<script>document.currentScript.parentElement.remove()</script>\n\t</body>\n</html>`;\n\n\tconst [ src, cleanup ] = useMemo( () => {\n\t\tconst _src = URL.createObjectURL(\n\t\t\tnew window.Blob( [ html ], { type: 'text/html' } )\n\t\t);\n\t\treturn [ _src, () => URL.revokeObjectURL( _src ) ];\n\t}, [ html ] );\n\n\tuseEffect( () => cleanup, [ cleanup ] );\n\n\t// Make sure to not render the before and after focusable div elements in view\n\t// mode. They're only needed to capture focus in edit mode.\n\tconst shouldRenderFocusCaptureElements = tabIndex >= 0 && ! isPreviewMode;\n\n\tconst iframe = (\n\t\t<>\n\t\t\t{ shouldRenderFocusCaptureElements && before }\n\t\t\t{ /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }\n\t\t\t<iframe\n\t\t\t\t{ ...props }\n\t\t\t\tstyle={ {\n\t\t\t\t\t...props.style,\n\t\t\t\t\theight: props.style?.height,\n\t\t\t\t\tborder: 0,\n\t\t\t\t} }\n\t\t\t\tref={ useMergeRefs( [ ref, setRef ] ) }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\t// Correct doctype is required to enable rendering in standards\n\t\t\t\t// mode. Also preload the styles to avoid a flash of unstyled\n\t\t\t\t// content.\n\t\t\t\tsrc={ src }\n\t\t\t\ttitle={ title }\n\t\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\t\tif ( props.onKeyDown ) {\n\t\t\t\t\t\tprops.onKeyDown( event );\n\t\t\t\t\t}\n\t\t\t\t\t// If the event originates from inside the iframe, it means\n\t\t\t\t\t// it bubbled through the portal, but only with React\n\t\t\t\t\t// events. We need to to bubble native events as well,\n\t\t\t\t\t// though by doing so we also trigger another React event,\n\t\t\t\t\t// so we need to stop the propagation of this event to avoid\n\t\t\t\t\t// duplication.\n\t\t\t\t\tif (\n\t\t\t\t\t\tevent.currentTarget.ownerDocument !==\n\t\t\t\t\t\tevent.target.ownerDocument\n\t\t\t\t\t) {\n\t\t\t\t\t\t// We should only stop propagation of the React event,\n\t\t\t\t\t\t// the native event should further bubble inside the\n\t\t\t\t\t\t// iframe to the document and window.\n\t\t\t\t\t\t// Alternatively, we could consider redispatching the\n\t\t\t\t\t\t// native event in the iframe.\n\t\t\t\t\t\tconst { stopPropagation } = event.nativeEvent;\n\t\t\t\t\t\tevent.nativeEvent.stopPropagation = () => {};\n\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\tevent.nativeEvent.stopPropagation = stopPropagation;\n\t\t\t\t\t\tbubbleEvent(\n\t\t\t\t\t\t\tevent,\n\t\t\t\t\t\t\twindow.KeyboardEvent,\n\t\t\t\t\t\t\tevent.currentTarget\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\t\t{ iframeDocument &&\n\t\t\t\t\tcreatePortal(\n\t\t\t\t\t\t// We want to prevent React events from bubbling through the iframe\n\t\t\t\t\t\t// we bubble these manually.\n\t\t\t\t\t\t/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */\n\t\t\t\t\t\t<body\n\t\t\t\t\t\t\tref={ bodyRef }\n\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t'block-editor-iframe__body',\n\t\t\t\t\t\t\t\t'editor-styles-wrapper',\n\t\t\t\t\t\t\t\t...bodyClasses\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ contentResizeListener }\n\t\t\t\t\t\t\t<StyleProvider document={ iframeDocument }>\n\t\t\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t\t</StyleProvider>\n\t\t\t\t\t\t</body>,\n\t\t\t\t\t\tiframeDocument.documentElement\n\t\t\t\t\t) }\n\t\t\t</iframe>\n\t\t\t{ shouldRenderFocusCaptureElements && after }\n\t\t</>\n\t);\n\n\treturn (\n\t\t<div className=\"block-editor-iframe__container\">\n\t\t\t{ containerResizeListener }\n\t\t\t<div\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'block-editor-iframe__scale-container',\n\t\t\t\t\tisZoomedOut && 'is-zoomed-out'\n\t\t\t\t) }\n\t\t\t\tstyle={ {\n\t\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale-container-width':\n\t\t\t\t\t\tisZoomedOut && `${ scaleContainerWidth }px`,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ iframe }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nfunction IframeIfReady( props, ref ) {\n\tconst isInitialised = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings().__internalIsInitialized,\n\t\t[]\n\t);\n\n\t// We shouldn't render the iframe until the editor settings are initialised.\n\t// The initial settings are needed to get the styles for the srcDoc, which\n\t// cannot be changed after the iframe is mounted. srcDoc is used to to set\n\t// the initial iframe HTML, which is required to avoid a flash of unstyled\n\t// content.\n\tif ( ! isInitialised ) {\n\t\treturn null;\n\t}\n\n\treturn <Iframe { ...props } forwardedRef={ ref } />;\n}\n\nexport default forwardRef( IframeIfReady );\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,SACCC,QAAQ,EACRC,YAAY,EACZC,UAAU,EACVC,OAAO,EACPC,SAAS,QACH,oBAAoB;AAC3B,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,YAAY,EAAEC,YAAY,EAAEC,WAAW,QAAQ,oBAAoB;AAC5E,SAASC,2BAA2B,IAAIC,aAAa,QAAQ,uBAAuB;AACpF,SAASC,SAAS,QAAQ,iBAAiB;;AAE3C;AACA;AACA;AACA,SAASC,wBAAwB,QAAQ,4BAA4B;AACrE,SAASC,cAAc,QAAQ,iBAAiB;AAChD,SAASC,sBAAs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;MACA;MACAoB,KAAA;QACCgD,GAAG,EAAGuD,OAAS;QACfmB,SAAS,EAAGhJ,IAAI,CACf,2BAA2B,EAC3B,uBAAuB,EACvB,GAAGkF,WACJ,CAAG;QAAAlB,QAAA,GAEDsD,qBAAqB,eACvBlG,IAAA,CAACT,aAAa;UAACsI,QAAQ,EAAGlG,cAAgB;UAAAiB,QAAA,EACvCA;QAAQ,CACI,CAAC;MAAA,CACX,CAAC,EACPjB,cAAc,CAACG,eAChB;IAAC,CACK,CAAC,EACPoF,gCAAgC,IAAI/C,KAAK;EAAA,CAC1C,CACF;EAED,oBACCjE,KAAA;IAAK0H,SAAS,EAAC,gCAAgC;IAAAhF,QAAA,GAC5CuD,uBAAuB,eACzBnG,IAAA;MACC4H,SAAS,EAAGhJ,IAAI,CACf,sCAAsC,EACtCwH,WAAW,IAAI,eAChB,CAAG;MACHgB,KAAK,EAAG;QACP,yDAAyD,EACxDhB,WAAW,IAAI,GAAIC,mBAAmB;MACxC,CAAG;MAAAzD,QAAA,EAEDuE;IAAM,CACJ,CAAC;EAAA,CACF,CAAC;AAER;AAEA,SAASW,aAAaA,CAAE1E,KAAK,EAAEF,GAAG,EAAG;EACpC,MAAM6E,aAAa,GAAGvI,SAAS,CAC5B+D,MAAM,IACPA,MAAM,CAAEzD,gBAAiB,CAAC,CAAC0D,WAAW,CAAC,CAAC,CAACwE,uBAAuB,EACjE,EACD,CAAC;;EAED;EACA;EACA;EACA;EACA;EACA,IAAK,CAAED,aAAa,EAAG;IACtB,OAAO,IAAI;EACZ;EAEA,oBAAO/H,IAAA,CAAC0C,MAAM;IAAA,GAAMU,KAAK;IAAGH,YAAY,EAAGC;EAAK,CAAE,CAAC;AACpD;AAEA,eAAenE,UAAU,CAAE+I,aAAc,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["clsx","useState","createPortal","forwardRef","useMemo","useEffect","__","useMergeRefs","useRefEffect","useDisabled","__experimentalStyleProvider","StyleProvider","useSelect","useBlockSelectionClearer","useWritingFlow","getCompatibilityStyles","useScaleCanvas","store","blockEditorStore","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","bubbleEvent","event","Constructor","frame","init","key","contentDocument","defaultView","MouseEvent","rect","getBoundingClientRect","clientX","left","clientY","top","newEvent","type","defaultPrevented","preventDefault","cancelled","dispatchEvent","useBubbleEvents","iframeDocument","frameElement","html","documentElement","eventTypes","handlers","name","prototype","Object","getPrototypeOf","constructorName","constructor","window","addEventListener","removeEventListener","Iframe","contentRef","children","tabIndex","scale","frameSize","readonly","forwardedRef","ref","title","props","resolvedAssets","isPreviewMode","select","getSettings","settings","__unstableResolvedAssets","styles","scripts","setIframeDocument","bodyClasses","setBodyClasses","clearerRef","before","writingFlowRef","after","setRef","node","_load","iFrameDocument","preventFileDropDefault","interceptLinkClicks","target","tagName","getAttribute","startsWith","location","hash","slice","ownerDocument","Array","from","body","classList","filter","onLoad","add","dir","compatStyle","getElementById","id","head","appendChild","cloneNode","console","warn","contentResizeListener","containerResizeListener","isZoomedOut","scaleContainerWidth","parseInt","disabledRef","isDisabled","bodyRef","origin","src","cleanup","_src","URL","createObjectURL","Blob","revokeObjectURL","shouldRenderFocusCaptureElements","iframe","style","height","border","onKeyDown","currentTarget","stopPropagation","nativeEvent","KeyboardEvent","className","document","IframeIfReady","isInitialised","__internalIsInitialized"],"sources":["@wordpress/block-editor/src/components/iframe/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tcreatePortal,\n\tforwardRef,\n\tuseMemo,\n\tuseEffect,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect, useDisabled } from '@wordpress/compose';\nimport { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useWritingFlow } from '../writing-flow';\nimport { getCompatibilityStyles } from './get-compatibility-styles';\nimport { useScaleCanvas } from './use-scale-canvas';\nimport { store as blockEditorStore } from '../../store';\n\nfunction bubbleEvent( event, Constructor, frame ) {\n\tconst init = {};\n\n\tfor ( const key in event ) {\n\t\tinit[ key ] = event[ key ];\n\t}\n\n\t// Check if the event is a MouseEvent generated within the iframe.\n\t// If so, adjust the coordinates to be relative to the position of\n\t// the iframe. This ensures that components such as Draggable\n\t// receive coordinates relative to the window, instead of relative\n\t// to the iframe. Without this, the Draggable event handler would\n\t// result in components \"jumping\" position as soon as the user\n\t// drags over the iframe.\n\tif ( event instanceof frame.contentDocument.defaultView.MouseEvent ) {\n\t\tconst rect = frame.getBoundingClientRect();\n\t\tinit.clientX += rect.left;\n\t\tinit.clientY += rect.top;\n\t}\n\n\tconst newEvent = new Constructor( event.type, init );\n\tif ( init.defaultPrevented ) {\n\t\tnewEvent.preventDefault();\n\t}\n\tconst cancelled = ! frame.dispatchEvent( newEvent );\n\n\tif ( cancelled ) {\n\t\tevent.preventDefault();\n\t}\n}\n\n/**\n * Bubbles some event types (keydown, keypress, and dragover) to parent document\n * document to ensure that the keyboard shortcuts and drag and drop work.\n *\n * Ideally, we should remove event bubbling in the future. Keyboard shortcuts\n * should be context dependent, e.g. actions on blocks like Cmd+A should not\n * work globally outside the block editor.\n *\n * @param {Document} iframeDocument Document to attach listeners to.\n */\nfunction useBubbleEvents( iframeDocument ) {\n\treturn useRefEffect( () => {\n\t\tconst { defaultView } = iframeDocument;\n\t\tif ( ! defaultView ) {\n\t\t\treturn;\n\t\t}\n\t\tconst { frameElement } = defaultView;\n\t\tconst html = iframeDocument.documentElement;\n\t\tconst eventTypes = [ 'dragover', 'mousemove' ];\n\t\tconst handlers = {};\n\t\tfor ( const name of eventTypes ) {\n\t\t\thandlers[ name ] = ( event ) => {\n\t\t\t\tconst prototype = Object.getPrototypeOf( event );\n\t\t\t\tconst constructorName = prototype.constructor.name;\n\t\t\t\tconst Constructor = window[ constructorName ];\n\t\t\t\tbubbleEvent( event, Constructor, frameElement );\n\t\t\t};\n\t\t\thtml.addEventListener( name, handlers[ name ] );\n\t\t}\n\n\t\treturn () => {\n\t\t\tfor ( const name of eventTypes ) {\n\t\t\t\thtml.removeEventListener( name, handlers[ name ] );\n\t\t\t}\n\t\t};\n\t} );\n}\n\nfunction Iframe( {\n\tcontentRef,\n\tchildren,\n\ttabIndex = 0,\n\tscale = 1,\n\tframeSize = 0,\n\treadonly,\n\tforwardedRef: ref,\n\ttitle = __( 'Editor canvas' ),\n\t...props\n} ) {\n\tconst { resolvedAssets, isPreviewMode } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst settings = getSettings();\n\t\treturn {\n\t\t\tresolvedAssets: settings.__unstableResolvedAssets,\n\t\t\tisPreviewMode: settings.isPreviewMode,\n\t\t};\n\t}, [] );\n\tconst { styles = '', scripts = '' } = resolvedAssets;\n\t/** @type {[Document, import('react').Dispatch<Document>]} */\n\tconst [ iframeDocument, setIframeDocument ] = useState();\n\tconst [ bodyClasses, setBodyClasses ] = useState( [] );\n\tconst clearerRef = useBlockSelectionClearer();\n\tconst [ before, writingFlowRef, after ] = useWritingFlow();\n\n\tconst setRef = useRefEffect( ( node ) => {\n\t\tnode._load = () => {\n\t\t\tsetIframeDocument( node.contentDocument );\n\t\t};\n\t\tlet iFrameDocument;\n\t\t// Prevent the default browser action for files dropped outside of dropzones.\n\t\tfunction preventFileDropDefault( event ) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t\t// Prevent clicks on link fragments from navigating away. Note that links\n\t\t// inside `contenteditable` are already disabled by the browser, so\n\t\t// this is for links in blocks outside of `contenteditable`.\n\t\tfunction interceptLinkClicks( event ) {\n\t\t\tif (\n\t\t\t\tevent.target.tagName === 'A' &&\n\t\t\t\tevent.target.getAttribute( 'href' )?.startsWith( '#' )\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\t// Manually handle link fragment navigation within the iframe. The iframe's\n\t\t\t\t// location is a blob URL, which can't be used to resolve relative links like\n\t\t\t\t// `#hash`. The relative link would be resolved against the iframe's base URL\n\t\t\t\t// or the parent frame's URL, causing the iframe to navigate to a completely\n\t\t\t\t// different page. Setting the `location.hash` works because it really sets the\n\t\t\t\t// blob URL's hash.\n\t\t\t\t//\n\t\t\t\t// Links with fragments are used for example with footnotes. Clicking on these\n\t\t\t\t// links will scroll smoothly to the anchors in the editor canvas.\n\t\t\t\tiFrameDocument.defaultView.location.hash = event.target\n\t\t\t\t\t.getAttribute( 'href' )\n\t\t\t\t\t.slice( 1 );\n\t\t\t}\n\t\t}\n\n\t\tconst { ownerDocument } = node;\n\n\t\t// Ideally ALL classes that are added through get_body_class should\n\t\t// be added in the editor too, which we'll somehow have to get from\n\t\t// the server in the future (which will run the PHP filters).\n\t\tsetBodyClasses(\n\t\t\tArray.from( ownerDocument.body.classList ).filter(\n\t\t\t\t( name ) =>\n\t\t\t\t\tname.startsWith( 'admin-color-' ) ||\n\t\t\t\t\tname.startsWith( 'post-type-' ) ||\n\t\t\t\t\tname === 'wp-embed-responsive'\n\t\t\t)\n\t\t);\n\n\t\tfunction onLoad() {\n\t\t\tconst { contentDocument } = node;\n\t\t\tconst { documentElement } = contentDocument;\n\t\t\tiFrameDocument = contentDocument;\n\n\t\t\tdocumentElement.classList.add( 'block-editor-iframe__html' );\n\n\t\t\tclearerRef( documentElement );\n\n\t\t\tcontentDocument.dir = ownerDocument.dir;\n\n\t\t\tfor ( const compatStyle of getCompatibilityStyles() ) {\n\t\t\t\tif ( contentDocument.getElementById( compatStyle.id ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tcontentDocument.head.appendChild(\n\t\t\t\t\tcompatStyle.cloneNode( true )\n\t\t\t\t);\n\n\t\t\t\tif ( ! isPreviewMode ) {\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`${ compatStyle.id } was added to the iframe incorrectly. Please use block.json or enqueue_block_assets to add styles to the iframe.`,\n\t\t\t\t\t\tcompatStyle\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tiFrameDocument.addEventListener(\n\t\t\t\t'dragover',\n\t\t\t\tpreventFileDropDefault,\n\t\t\t\tfalse\n\t\t\t);\n\t\t\tiFrameDocument.addEventListener(\n\t\t\t\t'drop',\n\t\t\t\tpreventFileDropDefault,\n\t\t\t\tfalse\n\t\t\t);\n\t\t\tiFrameDocument.addEventListener( 'click', interceptLinkClicks );\n\t\t}\n\n\t\tnode.addEventListener( 'load', onLoad );\n\n\t\treturn () => {\n\t\t\tdelete node._load;\n\t\t\tnode.removeEventListener( 'load', onLoad );\n\t\t\tiFrameDocument?.removeEventListener(\n\t\t\t\t'dragover',\n\t\t\t\tpreventFileDropDefault\n\t\t\t);\n\t\t\tiFrameDocument?.removeEventListener(\n\t\t\t\t'drop',\n\t\t\t\tpreventFileDropDefault\n\t\t\t);\n\t\t\tiFrameDocument?.removeEventListener( 'click', interceptLinkClicks );\n\t\t};\n\t}, [] );\n\n\tconst {\n\t\tcontentResizeListener,\n\t\tcontainerResizeListener,\n\t\tisZoomedOut,\n\t\tscaleContainerWidth,\n\t} = useScaleCanvas( {\n\t\tscale,\n\t\tframeSize: parseInt( frameSize ),\n\t\tiframeDocument,\n\t} );\n\n\tconst disabledRef = useDisabled( { isDisabled: ! readonly } );\n\tconst bodyRef = useMergeRefs( [\n\t\tuseBubbleEvents( iframeDocument ),\n\t\tcontentRef,\n\t\tclearerRef,\n\t\twritingFlowRef,\n\t\tdisabledRef,\n\t] );\n\n\t// Correct doctype is required to enable rendering in standards\n\t// mode. Also preload the styles to avoid a flash of unstyled\n\t// content.\n\tconst html = `<!doctype html>\n<html>\n\t<head>\n\t\t<meta charset=\"utf-8\">\n\t\t<base href=\"${ window.location.origin }\">\n\t\t<script>window.frameElement._load()</script>\n\t\t<style>\n\t\t\thtml{\n\t\t\t\theight: auto !important;\n\t\t\t\tmin-height: 100%;\n\t\t\t}\n\t\t\t/* Lowest specificity to not override global styles */\n\t\t\t:where(body) {\n\t\t\t\tmargin: 0;\n\t\t\t\t/* Default background color in case zoom out mode background\n\t\t\t\tcolors the html element */\n\t\t\t\tbackground-color: white;\n\t\t\t}\n\t\t</style>\n\t\t${ styles }\n\t\t${ scripts }\n\t</head>\n\t<body>\n\t\t<script>document.currentScript.parentElement.remove()</script>\n\t</body>\n</html>`;\n\n\tconst [ src, cleanup ] = useMemo( () => {\n\t\tconst _src = URL.createObjectURL(\n\t\t\tnew window.Blob( [ html ], { type: 'text/html' } )\n\t\t);\n\t\treturn [ _src, () => URL.revokeObjectURL( _src ) ];\n\t}, [ html ] );\n\n\tuseEffect( () => cleanup, [ cleanup ] );\n\n\t// Make sure to not render the before and after focusable div elements in view\n\t// mode. They're only needed to capture focus in edit mode.\n\tconst shouldRenderFocusCaptureElements = tabIndex >= 0 && ! isPreviewMode;\n\n\tconst iframe = (\n\t\t<>\n\t\t\t{ shouldRenderFocusCaptureElements && before }\n\t\t\t{ /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }\n\t\t\t<iframe\n\t\t\t\t{ ...props }\n\t\t\t\tstyle={ {\n\t\t\t\t\t...props.style,\n\t\t\t\t\theight: props.style?.height,\n\t\t\t\t\tborder: 0,\n\t\t\t\t} }\n\t\t\t\tref={ useMergeRefs( [ ref, setRef ] ) }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\t// Correct doctype is required to enable rendering in standards\n\t\t\t\t// mode. Also preload the styles to avoid a flash of unstyled\n\t\t\t\t// content.\n\t\t\t\tsrc={ src }\n\t\t\t\ttitle={ title }\n\t\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\t\tif ( props.onKeyDown ) {\n\t\t\t\t\t\tprops.onKeyDown( event );\n\t\t\t\t\t}\n\t\t\t\t\t// If the event originates from inside the iframe, it means\n\t\t\t\t\t// it bubbled through the portal, but only with React\n\t\t\t\t\t// events. We need to to bubble native events as well,\n\t\t\t\t\t// though by doing so we also trigger another React event,\n\t\t\t\t\t// so we need to stop the propagation of this event to avoid\n\t\t\t\t\t// duplication.\n\t\t\t\t\tif (\n\t\t\t\t\t\tevent.currentTarget.ownerDocument !==\n\t\t\t\t\t\tevent.target.ownerDocument\n\t\t\t\t\t) {\n\t\t\t\t\t\t// We should only stop propagation of the React event,\n\t\t\t\t\t\t// the native event should further bubble inside the\n\t\t\t\t\t\t// iframe to the document and window.\n\t\t\t\t\t\t// Alternatively, we could consider redispatching the\n\t\t\t\t\t\t// native event in the iframe.\n\t\t\t\t\t\tconst { stopPropagation } = event.nativeEvent;\n\t\t\t\t\t\tevent.nativeEvent.stopPropagation = () => {};\n\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\tevent.nativeEvent.stopPropagation = stopPropagation;\n\t\t\t\t\t\tbubbleEvent(\n\t\t\t\t\t\t\tevent,\n\t\t\t\t\t\t\twindow.KeyboardEvent,\n\t\t\t\t\t\t\tevent.currentTarget\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\t\t{ iframeDocument &&\n\t\t\t\t\tcreatePortal(\n\t\t\t\t\t\t// We want to prevent React events from bubbling through the iframe\n\t\t\t\t\t\t// we bubble these manually.\n\t\t\t\t\t\t/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */\n\t\t\t\t\t\t<body\n\t\t\t\t\t\t\tref={ bodyRef }\n\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t'block-editor-iframe__body',\n\t\t\t\t\t\t\t\t'editor-styles-wrapper',\n\t\t\t\t\t\t\t\t...bodyClasses\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ contentResizeListener }\n\t\t\t\t\t\t\t<StyleProvider document={ iframeDocument }>\n\t\t\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t\t</StyleProvider>\n\t\t\t\t\t\t</body>,\n\t\t\t\t\t\tiframeDocument.documentElement\n\t\t\t\t\t) }\n\t\t\t</iframe>\n\t\t\t{ shouldRenderFocusCaptureElements && after }\n\t\t</>\n\t);\n\n\treturn (\n\t\t<div className=\"block-editor-iframe__container\">\n\t\t\t{ containerResizeListener }\n\t\t\t<div\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'block-editor-iframe__scale-container',\n\t\t\t\t\tisZoomedOut && 'is-zoomed-out'\n\t\t\t\t) }\n\t\t\t\tstyle={ {\n\t\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale-container-width':\n\t\t\t\t\t\tisZoomedOut && `${ scaleContainerWidth }px`,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ iframe }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nfunction IframeIfReady( props, ref ) {\n\tconst isInitialised = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings().__internalIsInitialized,\n\t\t[]\n\t);\n\n\t// We shouldn't render the iframe until the editor settings are initialised.\n\t// The initial settings are needed to get the styles for the srcDoc, which\n\t// cannot be changed after the iframe is mounted. srcDoc is used to to set\n\t// the initial iframe HTML, which is required to avoid a flash of unstyled\n\t// content.\n\tif ( ! isInitialised ) {\n\t\treturn null;\n\t}\n\n\treturn <Iframe { ...props } forwardedRef={ ref } />;\n}\n\nexport default forwardRef( IframeIfReady );\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,SACCC,QAAQ,EACRC,YAAY,EACZC,UAAU,EACVC,OAAO,EACPC,SAAS,QACH,oBAAoB;AAC3B,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,YAAY,EAAEC,YAAY,EAAEC,WAAW,QAAQ,oBAAoB;AAC5E,SAASC,2BAA2B,IAAIC,aAAa,QAAQ,uBAAuB;AACpF,SAASC,SAAS,QAAQ,iBAAiB;;AAE3C;AACA;AACA;AACA,SAASC,wBAAwB,QAAQ,4BAA4B;AACrE,SAAS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enE,UAAU,CAAE+I,aAAc,CAAC","ignoreList":[]}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line no-restricted-imports
|
|
6
|
-
import apiFetch from '@wordpress/api-fetch';
|
|
7
|
-
import { useDispatch } from '@wordpress/data';
|
|
4
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
8
5
|
import { useCallback, useMemo, useState } from '@wordpress/element';
|
|
9
6
|
import { __, sprintf } from '@wordpress/i18n';
|
|
10
7
|
import { store as noticesStore } from '@wordpress/notices';
|
|
11
8
|
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { store as blockEditorStore } from '../../store';
|
|
14
|
+
import { mediaEditKey } from '../../store/private-keys';
|
|
12
15
|
const messages = {
|
|
13
16
|
crop: __('Image cropped.'),
|
|
14
17
|
rotate: __('Image rotated.'),
|
|
@@ -27,11 +30,27 @@ export default function useSaveImage({
|
|
|
27
30
|
createSuccessNotice
|
|
28
31
|
} = useDispatch(noticesStore);
|
|
29
32
|
const [isInProgress, setIsInProgress] = useState(false);
|
|
33
|
+
const {
|
|
34
|
+
editMediaEntity
|
|
35
|
+
} = useSelect(select => {
|
|
36
|
+
const settings = select(blockEditorStore).getSettings();
|
|
37
|
+
return {
|
|
38
|
+
editMediaEntity: settings?.[mediaEditKey]
|
|
39
|
+
};
|
|
40
|
+
}, []);
|
|
30
41
|
const cancel = useCallback(() => {
|
|
31
42
|
setIsInProgress(false);
|
|
32
43
|
onFinishEditing();
|
|
33
44
|
}, [onFinishEditing]);
|
|
34
|
-
const apply = useCallback(() => {
|
|
45
|
+
const apply = useCallback(async () => {
|
|
46
|
+
if (!editMediaEntity) {
|
|
47
|
+
onFinishEditing();
|
|
48
|
+
createErrorNotice(__('Sorry, you are not allowed to edit images on this site.'), {
|
|
49
|
+
id: 'image-editing-error',
|
|
50
|
+
type: 'snackbar'
|
|
51
|
+
});
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
35
54
|
setIsInProgress(true);
|
|
36
55
|
const modifiers = [];
|
|
37
56
|
if (rotation > 0) {
|
|
@@ -63,41 +82,42 @@ export default function useSaveImage({
|
|
|
63
82
|
return;
|
|
64
83
|
}
|
|
65
84
|
const modifierType = modifiers.length === 1 ? modifiers[0].type : 'cropAndRotate';
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
method: 'POST',
|
|
69
|
-
data: {
|
|
85
|
+
try {
|
|
86
|
+
const savedImage = await editMediaEntity(id, {
|
|
70
87
|
src: url,
|
|
71
88
|
modifiers
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
onSaveImage({
|
|
75
|
-
id: response.id,
|
|
76
|
-
url: response.source_url
|
|
89
|
+
}, {
|
|
90
|
+
throwOnError: true
|
|
77
91
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
if (savedImage) {
|
|
93
|
+
onSaveImage({
|
|
94
|
+
id: savedImage.id,
|
|
95
|
+
url: savedImage.source_url
|
|
96
|
+
});
|
|
97
|
+
createSuccessNotice(messages[modifierType], {
|
|
98
|
+
type: 'snackbar',
|
|
99
|
+
actions: [{
|
|
100
|
+
label: __('Undo'),
|
|
101
|
+
onClick: () => {
|
|
102
|
+
onSaveImage({
|
|
103
|
+
id,
|
|
104
|
+
url
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}]
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
} catch (error) {
|
|
91
111
|
createErrorNotice(sprintf(/* translators: %s: Error message. */
|
|
92
112
|
__('Could not edit image. %s'), stripHTML(error.message)), {
|
|
93
113
|
id: 'image-editing-error',
|
|
94
114
|
type: 'snackbar'
|
|
95
115
|
});
|
|
96
|
-
}
|
|
116
|
+
} finally {
|
|
97
117
|
setIsInProgress(false);
|
|
98
118
|
onFinishEditing();
|
|
99
|
-
}
|
|
100
|
-
}, [crop, rotation, id, url, onSaveImage, createErrorNotice, createSuccessNotice, onFinishEditing]);
|
|
119
|
+
}
|
|
120
|
+
}, [crop, rotation, id, url, onSaveImage, createErrorNotice, createSuccessNotice, onFinishEditing, editMediaEntity]);
|
|
101
121
|
return useMemo(() => ({
|
|
102
122
|
isInProgress,
|
|
103
123
|
apply,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["useDispatch","useSelect","useCallback","useMemo","useState","__","sprintf","store","noticesStore","__unstableStripHTML","stripHTML","blockEditorStore","mediaEditKey","messages","crop","rotate","cropAndRotate","useSaveImage","rotation","url","id","onSaveImage","onFinishEditing","createErrorNotice","createSuccessNotice","isInProgress","setIsInProgress","editMediaEntity","select","settings","getSettings","cancel","apply","type","modifiers","push","args","angle","width","height","left","x","top","y","length","modifierType","savedImage","src","throwOnError","source_url","actions","label","onClick","error","message"],"sources":["@wordpress/block-editor/src/components/image-editor/use-save-image.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { mediaEditKey } from '../../store/private-keys';\n\nconst messages = {\n\tcrop: __( 'Image cropped.' ),\n\trotate: __( 'Image rotated.' ),\n\tcropAndRotate: __( 'Image cropped and rotated.' ),\n};\n\nexport default function useSaveImage( {\n\tcrop,\n\trotation,\n\turl,\n\tid,\n\tonSaveImage,\n\tonFinishEditing,\n} ) {\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst [ isInProgress, setIsInProgress ] = useState( false );\n\tconst { editMediaEntity } = useSelect( ( select ) => {\n\t\tconst settings = select( blockEditorStore ).getSettings();\n\t\treturn {\n\t\t\teditMediaEntity: settings?.[ mediaEditKey ],\n\t\t};\n\t}, [] );\n\n\tconst cancel = useCallback( () => {\n\t\tsetIsInProgress( false );\n\t\tonFinishEditing();\n\t}, [ onFinishEditing ] );\n\n\tconst apply = useCallback( async () => {\n\t\tif ( ! editMediaEntity ) {\n\t\t\tonFinishEditing();\n\t\t\tcreateErrorNotice(\n\t\t\t\t__( 'Sorry, you are not allowed to edit images on this site.' ),\n\t\t\t\t{\n\t\t\t\t\tid: 'image-editing-error',\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsInProgress( true );\n\n\t\tconst modifiers = [];\n\n\t\tif ( rotation > 0 ) {\n\t\t\tmodifiers.push( {\n\t\t\t\ttype: 'rotate',\n\t\t\t\targs: {\n\t\t\t\t\tangle: rotation,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\t// The crop script may return some very small, sub-pixel values when the image was not cropped.\n\t\t// Crop only when the new size has changed by more than 0.1%.\n\t\tif ( crop.width < 99.9 || crop.height < 99.9 ) {\n\t\t\tmodifiers.push( {\n\t\t\t\ttype: 'crop',\n\t\t\t\targs: {\n\t\t\t\t\tleft: crop.x,\n\t\t\t\t\ttop: crop.y,\n\t\t\t\t\twidth: crop.width,\n\t\t\t\t\theight: crop.height,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\tif ( modifiers.length === 0 ) {\n\t\t\t// No changes to apply.\n\t\t\tsetIsInProgress( false );\n\t\t\tonFinishEditing();\n\t\t\treturn;\n\t\t}\n\n\t\tconst modifierType =\n\t\t\tmodifiers.length === 1 ? modifiers[ 0 ].type : 'cropAndRotate';\n\n\t\ttry {\n\t\t\tconst savedImage = await editMediaEntity(\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\tsrc: url,\n\t\t\t\t\tmodifiers,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\tif ( savedImage ) {\n\t\t\t\tonSaveImage( {\n\t\t\t\t\tid: savedImage.id,\n\t\t\t\t\turl: savedImage.source_url,\n\t\t\t\t} );\n\n\t\t\t\tcreateSuccessNotice( messages[ modifierType ], {\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\tonSaveImage( {\n\t\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\turl,\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} catch ( error ) {\n\t\t\tcreateErrorNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: Error message. */\n\t\t\t\t\t__( 'Could not edit image. %s' ),\n\t\t\t\t\tstripHTML( error.message )\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\tid: 'image-editing-error',\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t} finally {\n\t\t\tsetIsInProgress( false );\n\t\t\tonFinishEditing();\n\t\t}\n\t}, [\n\t\tcrop,\n\t\trotation,\n\t\tid,\n\t\turl,\n\t\tonSaveImage,\n\t\tcreateErrorNotice,\n\t\tcreateSuccessNotice,\n\t\tonFinishEditing,\n\t\teditMediaEntity,\n\t] );\n\n\treturn useMemo(\n\t\t() => ( {\n\t\t\tisInProgress,\n\t\t\tapply,\n\t\t\tcancel,\n\t\t} ),\n\t\t[ isInProgress, apply, cancel ]\n\t);\n}\n"],"mappings":"AAAA;AACA;A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