@wordpress/block-library 8.26.0 → 8.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/avatar/edit.js +2 -2
- package/build/avatar/edit.js.map +1 -1
- package/build/block/edit.js +76 -13
- package/build/block/edit.js.map +1 -1
- package/build/block/{v1/edit.native.js → edit.native.js} +4 -4
- package/build/block/edit.native.js.map +1 -0
- package/build/block/index.js +5 -3
- package/build/block/index.js.map +1 -1
- package/build/button/edit.js +24 -6
- package/build/button/edit.js.map +1 -1
- package/build/button/index.js +1 -0
- package/build/button/index.js.map +1 -1
- package/build/button/save.js +3 -1
- package/build/button/save.js.map +1 -1
- package/build/cover/edit.native.js +1 -0
- package/build/cover/edit.native.js.map +1 -1
- package/build/embed/edit.js +3 -2
- package/build/embed/edit.js.map +1 -1
- package/build/file/index.js +0 -1
- package/build/file/index.js.map +1 -1
- package/build/footnotes/edit.js +2 -1
- package/build/footnotes/edit.js.map +1 -1
- package/build/footnotes/format.js +17 -19
- package/build/footnotes/format.js.map +1 -1
- package/build/heading/edit.js +2 -1
- package/build/heading/edit.js.map +1 -1
- package/build/heading/edit.native.js +141 -0
- package/build/heading/edit.native.js.map +1 -0
- package/build/heading/index.js +1 -0
- package/build/heading/index.js.map +1 -1
- package/build/image/edit.js +8 -4
- package/build/image/edit.js.map +1 -1
- package/build/image/image.js +33 -7
- package/build/image/image.js.map +1 -1
- package/build/image/index.js +6 -3
- package/build/image/index.js.map +1 -1
- package/build/more/index.js +4 -0
- package/build/more/index.js.map +1 -1
- package/build/navigation/edit/index.js +2 -2
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/index.js +0 -1
- package/build/navigation/index.js.map +1 -1
- package/build/paragraph/edit.js +2 -1
- package/build/paragraph/edit.js.map +1 -1
- package/build/paragraph/index.js +1 -2
- package/build/paragraph/index.js.map +1 -1
- package/build/paragraph/transforms.js +1 -2
- package/build/paragraph/transforms.js.map +1 -1
- package/build/post-content/edit.js +2 -2
- package/build/post-content/edit.js.map +1 -1
- package/build/post-date/edit.js +1 -1
- package/build/post-date/edit.js.map +1 -1
- package/build/post-navigation-link/edit.js +43 -2
- package/build/post-navigation-link/edit.js.map +1 -1
- package/build/post-navigation-link/index.js +8 -0
- package/build/post-navigation-link/index.js.map +1 -1
- package/build/pullquote/index.js +4 -0
- package/build/pullquote/index.js.map +1 -1
- package/build/query/edit/inspector-controls/index.js +3 -3
- package/build/query/edit/inspector-controls/index.js.map +1 -1
- package/build/query/edit/query-content.js +2 -2
- package/build/query/edit/query-content.js.map +1 -1
- package/build/query/edit/query-placeholder.js +6 -7
- package/build/query/edit/query-placeholder.js.map +1 -1
- package/build/query/index.js +1 -2
- package/build/query/index.js.map +1 -1
- package/build/query/variations.js +8 -1
- package/build/query/variations.js.map +1 -1
- package/build/query/view.js +31 -12
- package/build/query/view.js.map +1 -1
- package/build/search/index.js +0 -1
- package/build/search/index.js.map +1 -1
- package/build/table-of-contents/hooks.js +2 -2
- package/build/table-of-contents/hooks.js.map +1 -1
- package/build/template-part/edit/advanced-controls.js +1 -4
- package/build/template-part/edit/advanced-controls.js.map +1 -1
- package/build/template-part/edit/index.js +39 -17
- package/build/template-part/edit/index.js.map +1 -1
- package/build/video/edit.native.js +7 -2
- package/build/video/edit.native.js.map +1 -1
- package/build/video/transforms.js +17 -0
- package/build/video/transforms.js.map +1 -1
- package/build-module/avatar/edit.js +2 -2
- package/build-module/avatar/edit.js.map +1 -1
- package/build-module/block/edit.js +76 -13
- package/build-module/block/edit.js.map +1 -1
- package/build-module/block/{v1/edit.native.js → edit.native.js} +3 -3
- package/build-module/block/edit.native.js.map +1 -0
- package/build-module/block/index.js +5 -3
- package/build-module/block/index.js.map +1 -1
- package/build-module/button/edit.js +25 -7
- package/build-module/button/edit.js.map +1 -1
- package/build-module/button/index.js +1 -0
- package/build-module/button/index.js.map +1 -1
- package/build-module/button/save.js +4 -2
- package/build-module/button/save.js.map +1 -1
- package/build-module/cover/edit.native.js +1 -0
- package/build-module/cover/edit.native.js.map +1 -1
- package/build-module/embed/edit.js +3 -2
- package/build-module/embed/edit.js.map +1 -1
- package/build-module/file/index.js +0 -1
- package/build-module/file/index.js.map +1 -1
- package/build-module/footnotes/edit.js +2 -1
- package/build-module/footnotes/edit.js.map +1 -1
- package/build-module/footnotes/format.js +17 -19
- package/build-module/footnotes/format.js.map +1 -1
- package/build-module/heading/edit.js +3 -2
- package/build-module/heading/edit.js.map +1 -1
- package/build-module/heading/edit.native.js +132 -0
- package/build-module/heading/edit.native.js.map +1 -0
- package/build-module/heading/index.js +1 -0
- package/build-module/heading/index.js.map +1 -1
- package/build-module/image/edit.js +9 -5
- package/build-module/image/edit.js.map +1 -1
- package/build-module/image/image.js +33 -7
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/index.js +6 -3
- package/build-module/image/index.js.map +1 -1
- package/build-module/more/index.js +4 -0
- package/build-module/more/index.js.map +1 -1
- package/build-module/navigation/edit/index.js +1 -1
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/index.js +0 -1
- package/build-module/navigation/index.js.map +1 -1
- package/build-module/paragraph/edit.js +3 -2
- package/build-module/paragraph/edit.js.map +1 -1
- package/build-module/paragraph/index.js +1 -2
- package/build-module/paragraph/index.js.map +1 -1
- package/build-module/paragraph/transforms.js +1 -2
- package/build-module/paragraph/transforms.js.map +1 -1
- package/build-module/post-content/edit.js +1 -1
- package/build-module/post-content/edit.js.map +1 -1
- package/build-module/post-date/edit.js +1 -1
- package/build-module/post-date/edit.js.map +1 -1
- package/build-module/post-navigation-link/edit.js +44 -3
- package/build-module/post-navigation-link/edit.js.map +1 -1
- package/build-module/post-navigation-link/index.js +8 -0
- package/build-module/post-navigation-link/index.js.map +1 -1
- package/build-module/pullquote/index.js +4 -0
- package/build-module/pullquote/index.js.map +1 -1
- package/build-module/query/edit/inspector-controls/index.js +4 -4
- package/build-module/query/edit/inspector-controls/index.js.map +1 -1
- package/build-module/query/edit/query-content.js +2 -2
- package/build-module/query/edit/query-content.js.map +1 -1
- package/build-module/query/edit/query-placeholder.js +7 -8
- package/build-module/query/edit/query-placeholder.js.map +1 -1
- package/build-module/query/index.js +1 -2
- package/build-module/query/index.js.map +1 -1
- package/build-module/query/variations.js +8 -1
- package/build-module/query/variations.js.map +1 -1
- package/build-module/query/view.js +30 -9
- package/build-module/query/view.js.map +1 -1
- package/build-module/search/index.js +0 -1
- package/build-module/search/index.js.map +1 -1
- package/build-module/table-of-contents/hooks.js +2 -2
- package/build-module/table-of-contents/hooks.js.map +1 -1
- package/build-module/template-part/edit/advanced-controls.js +1 -4
- package/build-module/template-part/edit/advanced-controls.js.map +1 -1
- package/build-module/template-part/edit/index.js +38 -16
- package/build-module/template-part/edit/index.js.map +1 -1
- package/build-module/video/edit.native.js +7 -2
- package/build-module/video/edit.native.js.map +1 -1
- package/build-module/video/transforms.js +17 -0
- package/build-module/video/transforms.js.map +1 -1
- package/build-style/common-rtl.css +4 -2
- package/build-style/common.css +4 -2
- package/build-style/cover/style-rtl.css +1 -2
- package/build-style/cover/style.css +1 -2
- package/build-style/editor-rtl.css +6 -4
- package/build-style/editor.css +6 -4
- package/build-style/gallery/style-rtl.css +2 -4
- package/build-style/gallery/style.css +2 -4
- package/build-style/image/editor-rtl.css +6 -0
- package/build-style/image/editor.css +6 -0
- package/build-style/page-list/editor-rtl.css +0 -4
- package/build-style/page-list/editor.css +0 -4
- package/build-style/pullquote/style-rtl.css +10 -1
- package/build-style/pullquote/style.css +10 -1
- package/build-style/search/style-rtl.css +2 -1
- package/build-style/search/style.css +2 -1
- package/build-style/style-rtl.css +19 -11
- package/build-style/style.css +19 -11
- package/build-style/video/style-rtl.css +1 -2
- package/build-style/video/style.css +1 -2
- package/package.json +34 -32
- package/src/avatar/edit.js +16 -18
- package/src/block/block.json +3 -0
- package/src/block/edit.js +102 -20
- package/src/block/{v1/edit.native.js → edit.native.js} +4 -4
- package/src/block/index.js +2 -3
- package/src/block/index.php +3 -31
- package/src/button/block.json +1 -0
- package/src/button/edit.js +76 -43
- package/src/button/save.js +3 -0
- package/src/buttons/test/__snapshots__/edit.native.js.snap +6 -0
- package/src/buttons/test/edit.native.js +49 -0
- package/src/cover/edit.native.js +1 -0
- package/src/embed/edit.js +3 -2
- package/src/file/block.json +0 -1
- package/src/file/index.php +11 -57
- package/src/footnotes/edit.js +2 -1
- package/src/footnotes/format.js +34 -31
- package/src/footnotes/index.php +20 -11
- package/src/gallery/index.php +0 -3
- package/src/heading/block.json +1 -0
- package/src/heading/edit.js +18 -14
- package/src/heading/edit.native.js +144 -0
- package/src/image/block.json +7 -3
- package/src/image/edit.js +19 -6
- package/src/image/editor.scss +6 -1
- package/src/image/image.js +101 -42
- package/src/image/index.js +6 -0
- package/src/image/index.php +14 -51
- package/src/more/index.js +6 -0
- package/src/navigation/block.json +0 -1
- package/src/navigation/edit/index.js +2 -2
- package/src/navigation/index.php +777 -28
- package/src/navigation-link/index.php +78 -16
- package/src/page-list/editor.scss +0 -4
- package/src/paragraph/block.json +1 -2
- package/src/paragraph/edit.js +23 -19
- package/src/post-content/edit.js +2 -2
- package/src/post-date/edit.js +38 -33
- package/src/post-navigation-link/block.json +8 -0
- package/src/post-navigation-link/edit.js +63 -1
- package/src/post-navigation-link/index.php +17 -3
- package/src/post-terms/index.php +13 -4
- package/src/pullquote/block.json +4 -0
- package/src/pullquote/style.scss +13 -1
- package/src/query/block.json +1 -2
- package/src/query/edit/inspector-controls/index.js +137 -146
- package/src/query/edit/query-content.js +9 -7
- package/src/query/edit/query-placeholder.js +11 -11
- package/src/query/index.php +33 -71
- package/src/query/variations.js +4 -0
- package/src/query/view.js +24 -19
- package/src/search/block.json +0 -1
- package/src/search/index.php +18 -36
- package/src/table-of-contents/hooks.js +2 -2
- package/src/template-part/edit/advanced-controls.js +2 -3
- package/src/template-part/edit/index.js +77 -50
- package/src/template-part/index.php +2 -2
- package/src/video/edit.native.js +5 -2
- package/src/video/test/edit.native.js +38 -0
- package/src/video/transforms.js +32 -0
- package/tsconfig.json +1 -0
- package/build/block/v1/edit.js +0 -116
- package/build/block/v1/edit.js.map +0 -1
- package/build/block/v1/edit.native.js.map +0 -1
- package/build-module/block/v1/edit.js +0 -108
- package/build-module/block/v1/edit.js.map +0 -1
- package/build-module/block/v1/edit.native.js.map +0 -1
- package/src/block/v1/edit.js +0 -163
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createUpgradedEmbedBlock","getClassNames","removeAspectRatioClasses","fallback","getEmbedInfoByProvider","getMergedAttributesWithPreview","EmbedControls","embedContentIcon","EmbedLoading","EmbedPlaceholder","EmbedPreview","classnames","__","_x","sprintf","useState","useEffect","useDispatch","useSelect","useBlockProps","store","coreStore","View","getAuthority","EmbedEdit","props","attributes","providerNameSlug","previewable","responsive","url","attributesUrl","isSelected","onReplace","setAttributes","insertBlocksAfter","onFocus","defaultEmbedInfo","title","icon","setURL","isEditingURL","setIsEditingURL","invalidateResolution","preview","fetching","themeSupportsResponsive","cannotEmbed","select","getEmbedPreview","isPreviewEmbedFallback","isRequestingEmbedPreview","getThemeSupports","embedPreview","previewIsFallback","badEmbedProvider","html","type","undefined","wordpressCantEmbed","data","status","validPreview","getMergedAttributes","toggleResponsive","allowResponsive","className","newAllowResponsive","newURL","replace","URL","host","toString","mergedAttributes","upgradedBlock","blockProps","createElement","label","showEmbedPlaceholder","onSubmit","event","preventDefault","blockClass","value","onChange","target","tryAgain","caption","classFromPreview","Fragment","showEditButton","blockSupportsResponsive","switchBackToURLInput","onCaptionChange"],"sources":["@wordpress/block-library/src/embed/edit.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport {\n\tcreateUpgradedEmbedBlock,\n\tgetClassNames,\n\tremoveAspectRatioClasses,\n\tfallback,\n\tgetEmbedInfoByProvider,\n\tgetMergedAttributesWithPreview,\n} from './util';\nimport EmbedControls from './embed-controls';\nimport { embedContentIcon } from './icons';\nimport EmbedLoading from './embed-loading';\nimport EmbedPlaceholder from './embed-placeholder';\nimport EmbedPreview from './embed-preview';\n\n/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { useState, useEffect } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { View } from '@wordpress/primitives';\nimport { getAuthority } from '@wordpress/url';\n\nconst EmbedEdit = ( props ) => {\n\tconst {\n\t\tattributes: {\n\t\t\tproviderNameSlug,\n\t\t\tpreviewable,\n\t\t\tresponsive,\n\t\t\turl: attributesUrl,\n\t\t},\n\t\tattributes,\n\t\tisSelected,\n\t\tonReplace,\n\t\tsetAttributes,\n\t\tinsertBlocksAfter,\n\t\tonFocus,\n\t} = props;\n\n\tconst defaultEmbedInfo = {\n\t\ttitle: _x( 'Embed', 'block title' ),\n\t\ticon: embedContentIcon,\n\t};\n\tconst { icon, title } =\n\t\tgetEmbedInfoByProvider( providerNameSlug ) || defaultEmbedInfo;\n\n\tconst [ url, setURL ] = useState( attributesUrl );\n\tconst [ isEditingURL, setIsEditingURL ] = useState( false );\n\tconst { invalidateResolution } = useDispatch( coreStore );\n\n\tconst { preview, fetching, themeSupportsResponsive, cannotEmbed } =\n\t\tuseSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst {\n\t\t\t\t\tgetEmbedPreview,\n\t\t\t\t\tisPreviewEmbedFallback,\n\t\t\t\t\tisRequestingEmbedPreview,\n\t\t\t\t\tgetThemeSupports,\n\t\t\t\t} = select( coreStore );\n\t\t\t\tif ( ! attributesUrl ) {\n\t\t\t\t\treturn { fetching: false, cannotEmbed: false };\n\t\t\t\t}\n\n\t\t\t\tconst embedPreview = getEmbedPreview( attributesUrl );\n\t\t\t\tconst previewIsFallback =\n\t\t\t\t\tisPreviewEmbedFallback( attributesUrl );\n\n\t\t\t\t// The external oEmbed provider does not exist. We got no type info and no html.\n\t\t\t\tconst badEmbedProvider =\n\t\t\t\t\tembedPreview?.html === false &&\n\t\t\t\t\tembedPreview?.type === undefined;\n\t\t\t\t// Some WordPress URLs that can't be embedded will cause the API to return\n\t\t\t\t// a valid JSON response with no HTML and `data.status` set to 404, rather\n\t\t\t\t// than generating a fallback response as other embeds do.\n\t\t\t\tconst wordpressCantEmbed = embedPreview?.data?.status === 404;\n\t\t\t\tconst validPreview =\n\t\t\t\t\t!! embedPreview &&\n\t\t\t\t\t! badEmbedProvider &&\n\t\t\t\t\t! wordpressCantEmbed;\n\t\t\t\treturn {\n\t\t\t\t\tpreview: validPreview ? embedPreview : undefined,\n\t\t\t\t\tfetching: isRequestingEmbedPreview( attributesUrl ),\n\t\t\t\t\tthemeSupportsResponsive:\n\t\t\t\t\t\tgetThemeSupports()[ 'responsive-embeds' ],\n\t\t\t\t\tcannotEmbed: ! validPreview || previewIsFallback,\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ attributesUrl ]\n\t\t);\n\n\t/**\n\t * Returns the attributes derived from the preview, merged with the current attributes.\n\t *\n\t * @return {Object} Merged attributes.\n\t */\n\tconst getMergedAttributes = () =>\n\t\tgetMergedAttributesWithPreview(\n\t\t\tattributes,\n\t\t\tpreview,\n\t\t\ttitle,\n\t\t\tresponsive\n\t\t);\n\n\tconst toggleResponsive = () => {\n\t\tconst { allowResponsive, className } = attributes;\n\t\tconst { html } = preview;\n\t\tconst newAllowResponsive = ! allowResponsive;\n\n\t\tsetAttributes( {\n\t\t\tallowResponsive: newAllowResponsive,\n\t\t\tclassName: getClassNames(\n\t\t\t\thtml,\n\t\t\t\tclassName,\n\t\t\t\tresponsive && newAllowResponsive\n\t\t\t),\n\t\t} );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( ! preview?.html || ! cannotEmbed || fetching ) {\n\t\t\treturn;\n\t\t}\n\t\t// At this stage, we're not fetching the preview and know it can't be embedded,\n\t\t// so try removing any trailing slash, and resubmit.\n\t\tconst newURL = attributesUrl.replace( /\\/$/, '' );\n\t\tsetURL( newURL );\n\t\tsetIsEditingURL( false );\n\t\tsetAttributes( { url: newURL } );\n\t}, [ preview?.html, attributesUrl, cannotEmbed, fetching ] );\n\n\t// Try a different provider in case the embed url is not supported.\n\tuseEffect( () => {\n\t\tif ( ! cannotEmbed || fetching || ! url ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Until X provider is supported in WordPress, as a workaround we use Twitter provider.\n\t\tif ( getAuthority( url ) === 'x.com' ) {\n\t\t\tconst newURL = new URL( url );\n\t\t\tnewURL.host = 'twitter.com';\n\t\t\tsetAttributes( { url: newURL.toString() } );\n\t\t}\n\t}, [ url, cannotEmbed, fetching, setAttributes ] );\n\n\t// Handle incoming preview.\n\tuseEffect( () => {\n\t\tif ( preview && ! isEditingURL ) {\n\t\t\t// When obtaining an incoming preview,\n\t\t\t// we set the attributes derived from the preview data.\n\t\t\tconst mergedAttributes = getMergedAttributes();\n\t\t\tsetAttributes( mergedAttributes );\n\n\t\t\tif ( onReplace ) {\n\t\t\t\tconst upgradedBlock = createUpgradedEmbedBlock(\n\t\t\t\t\tprops,\n\t\t\t\t\tmergedAttributes\n\t\t\t\t);\n\n\t\t\t\tif ( upgradedBlock ) {\n\t\t\t\t\tonReplace( upgradedBlock );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [ preview, isEditingURL ] );\n\n\tconst blockProps = useBlockProps();\n\n\tif ( fetching ) {\n\t\treturn (\n\t\t\t<View { ...blockProps }>\n\t\t\t\t<EmbedLoading />\n\t\t\t</View>\n\t\t);\n\t}\n\n\t// translators: %s: type of embed e.g: \"YouTube\", \"Twitter\", etc. \"Embed\" is used when no specific type exists\n\tconst label = sprintf( __( '%s URL' ), title );\n\n\t// No preview, or we can't embed the current URL, or we've clicked the edit button.\n\tconst showEmbedPlaceholder = ! preview || cannotEmbed || isEditingURL;\n\n\tif ( showEmbedPlaceholder ) {\n\t\treturn (\n\t\t\t<View { ...blockProps }>\n\t\t\t\t<EmbedPlaceholder\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tlabel={ label }\n\t\t\t\t\tonFocus={ onFocus }\n\t\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\t\tif ( event ) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// If the embed URL was changed, we need to reset the aspect ratio class.\n\t\t\t\t\t\t// To do this we have to remove the existing ratio class so it can be recalculated.\n\t\t\t\t\t\tconst blockClass = removeAspectRatioClasses(\n\t\t\t\t\t\t\tattributes.className\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tsetIsEditingURL( false );\n\t\t\t\t\t\tsetAttributes( { url, className: blockClass } );\n\t\t\t\t\t} }\n\t\t\t\t\tvalue={ url }\n\t\t\t\t\tcannotEmbed={ cannotEmbed }\n\t\t\t\t\tonChange={ ( event ) => setURL( event.target.value ) }\n\t\t\t\t\tfallback={ () => fallback( url, onReplace ) }\n\t\t\t\t\ttryAgain={ () => {\n\t\t\t\t\t\tinvalidateResolution( 'getEmbedPreview', [ url ] );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</View>\n\t\t);\n\t}\n\n\t// Even though we set attributes that get derived from the preview,\n\t// we don't access them directly because for the initial render,\n\t// the `setAttributes` call will not have taken effect. If we're\n\t// rendering responsive content, setting the responsive classes\n\t// after the preview has been rendered can result in unwanted\n\t// clipping or scrollbars. The `getAttributesFromPreview` function\n\t// that `getMergedAttributes` uses is memoized so that we're not\n\t// calculating them on every render.\n\tconst {\n\t\tcaption,\n\t\ttype,\n\t\tallowResponsive,\n\t\tclassName: classFromPreview,\n\t} = getMergedAttributes();\n\tconst className = classnames( classFromPreview, props.className );\n\n\treturn (\n\t\t<>\n\t\t\t<EmbedControls\n\t\t\t\tshowEditButton={ preview && ! cannotEmbed }\n\t\t\t\tthemeSupportsResponsive={ themeSupportsResponsive }\n\t\t\t\tblockSupportsResponsive={ responsive }\n\t\t\t\tallowResponsive={ allowResponsive }\n\t\t\t\ttoggleResponsive={ toggleResponsive }\n\t\t\t\tswitchBackToURLInput={ () => setIsEditingURL( true ) }\n\t\t\t/>\n\t\t\t<View { ...blockProps }>\n\t\t\t\t<EmbedPreview\n\t\t\t\t\tpreview={ preview }\n\t\t\t\t\tpreviewable={ previewable }\n\t\t\t\t\tclassName={ className }\n\t\t\t\t\turl={ url }\n\t\t\t\t\ttype={ type }\n\t\t\t\t\tcaption={ caption }\n\t\t\t\t\tonCaptionChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { caption: value } )\n\t\t\t\t\t}\n\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tlabel={ label }\n\t\t\t\t\tinsertBlocksAfter={ insertBlocksAfter }\n\t\t\t\t/>\n\t\t\t</View>\n\t\t</>\n\t);\n};\n\nexport default EmbedEdit;\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,wBAAwB,EACxBC,aAAa,EACbC,wBAAwB,EACxBC,QAAQ,EACRC,sBAAsB,EACtBC,8BAA8B,QACxB,QAAQ;AACf,OAAOC,aAAa,MAAM,kBAAkB;AAC5C,SAASC,gBAAgB,QAAQ,SAAS;AAC1C,OAAOC,YAAY,MAAM,iBAAiB;AAC1C,OAAOC,gBAAgB,MAAM,qBAAqB;AAClD,OAAOC,YAAY,MAAM,iBAAiB;;AAE1C;AACA;AACA;AACA,OAAOC,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,EAAE,EAAEC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AACjD,SAASC,QAAQ,EAAEC,SAAS,QAAQ,oBAAoB;AACxD,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,aAAa,QAAQ,yBAAyB;AACvD,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,IAAI,QAAQ,uBAAuB;AAC5C,SAASC,YAAY,QAAQ,gBAAgB;AAE7C,MAAMC,SAAS,GAAKC,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G9C,OAAO,IAAI,CAAEG,WAAa;IAC3CD,uBAAuB,EAAGA,uBAAyB;IACnD6C,uBAAuB,EAAG9D,UAAY;IACtCoC,eAAe,EAAGA,eAAiB;IACnCD,gBAAgB,EAAGA,gBAAkB;IACrC4B,oBAAoB,EAAGA,CAAA,KAAMlD,eAAe,CAAE,IAAK;EAAG,CACtD,CAAC,EACFkC,aAAA,CAACtD,IAAI;IAAA,GAAMqD;EAAU,GACpBC,aAAA,CAAClE,YAAY;IACZkC,OAAO,EAAGA,OAAS;IACnBhB,WAAW,EAAGA,WAAa;IAC3BsC,SAAS,EAAGA,SAAW;IACvBpC,GAAG,EAAGA,GAAK;IACX2B,IAAI,EAAGA,IAAM;IACb8B,OAAO,EAAGA,OAAS;IACnBM,eAAe,EAAKV,KAAK,IACxBjD,aAAa,CAAE;MAAEqD,OAAO,EAAEJ;IAAM,CAAE,CAClC;IACDnD,UAAU,EAAGA,UAAY;IACzBO,IAAI,EAAGA,IAAM;IACbsC,KAAK,EAAGA,KAAO;IACf1C,iBAAiB,EAAGA;EAAmB,CACvC,CACI,CACL,CAAC;AAEL,CAAC;AAED,eAAeX,SAAS"}
|
|
1
|
+
{"version":3,"names":["createUpgradedEmbedBlock","getClassNames","removeAspectRatioClasses","fallback","getEmbedInfoByProvider","getMergedAttributesWithPreview","EmbedControls","embedContentIcon","EmbedLoading","EmbedPlaceholder","EmbedPreview","classnames","__","_x","sprintf","useState","useEffect","useDispatch","useSelect","useBlockProps","store","coreStore","View","getAuthority","EmbedEdit","props","attributes","providerNameSlug","previewable","responsive","url","attributesUrl","isSelected","onReplace","setAttributes","insertBlocksAfter","onFocus","defaultEmbedInfo","title","icon","setURL","isEditingURL","setIsEditingURL","invalidateResolution","preview","fetching","themeSupportsResponsive","cannotEmbed","select","getEmbedPreview","isPreviewEmbedFallback","isRequestingEmbedPreview","getThemeSupports","embedPreview","previewIsFallback","badEmbedProvider","html","type","undefined","wordpressCantEmbed","data","status","validPreview","getMergedAttributes","toggleResponsive","allowResponsive","className","newAllowResponsive","newURL","replace","URL","host","toString","mergedAttributes","upgradedBlock","blockProps","createElement","label","showEmbedPlaceholder","onSubmit","event","preventDefault","blockClass","value","onChange","target","tryAgain","caption","classFromPreview","Fragment","showEditButton","blockSupportsResponsive","switchBackToURLInput","onCaptionChange"],"sources":["@wordpress/block-library/src/embed/edit.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport {\n\tcreateUpgradedEmbedBlock,\n\tgetClassNames,\n\tremoveAspectRatioClasses,\n\tfallback,\n\tgetEmbedInfoByProvider,\n\tgetMergedAttributesWithPreview,\n} from './util';\nimport EmbedControls from './embed-controls';\nimport { embedContentIcon } from './icons';\nimport EmbedLoading from './embed-loading';\nimport EmbedPlaceholder from './embed-placeholder';\nimport EmbedPreview from './embed-preview';\n\n/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { useState, useEffect } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { View } from '@wordpress/primitives';\nimport { getAuthority } from '@wordpress/url';\n\nconst EmbedEdit = ( props ) => {\n\tconst {\n\t\tattributes: {\n\t\t\tproviderNameSlug,\n\t\t\tpreviewable,\n\t\t\tresponsive,\n\t\t\turl: attributesUrl,\n\t\t},\n\t\tattributes,\n\t\tisSelected,\n\t\tonReplace,\n\t\tsetAttributes,\n\t\tinsertBlocksAfter,\n\t\tonFocus,\n\t} = props;\n\n\tconst defaultEmbedInfo = {\n\t\ttitle: _x( 'Embed', 'block title' ),\n\t\ticon: embedContentIcon,\n\t};\n\tconst { icon, title } =\n\t\tgetEmbedInfoByProvider( providerNameSlug ) || defaultEmbedInfo;\n\n\tconst [ url, setURL ] = useState( attributesUrl );\n\tconst [ isEditingURL, setIsEditingURL ] = useState( false );\n\tconst { invalidateResolution } = useDispatch( coreStore );\n\n\tconst { preview, fetching, themeSupportsResponsive, cannotEmbed } =\n\t\tuseSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst {\n\t\t\t\t\tgetEmbedPreview,\n\t\t\t\t\tisPreviewEmbedFallback,\n\t\t\t\t\tisRequestingEmbedPreview,\n\t\t\t\t\tgetThemeSupports,\n\t\t\t\t} = select( coreStore );\n\t\t\t\tif ( ! attributesUrl ) {\n\t\t\t\t\treturn { fetching: false, cannotEmbed: false };\n\t\t\t\t}\n\n\t\t\t\tconst embedPreview = getEmbedPreview( attributesUrl );\n\t\t\t\tconst previewIsFallback =\n\t\t\t\t\tisPreviewEmbedFallback( attributesUrl );\n\n\t\t\t\t// The external oEmbed provider does not exist. We got no type info and no html.\n\t\t\t\tconst badEmbedProvider =\n\t\t\t\t\tembedPreview?.html === false &&\n\t\t\t\t\tembedPreview?.type === undefined;\n\t\t\t\t// Some WordPress URLs that can't be embedded will cause the API to return\n\t\t\t\t// a valid JSON response with no HTML and `data.status` set to 404, rather\n\t\t\t\t// than generating a fallback response as other embeds do.\n\t\t\t\tconst wordpressCantEmbed = embedPreview?.data?.status === 404;\n\t\t\t\tconst validPreview =\n\t\t\t\t\t!! embedPreview &&\n\t\t\t\t\t! badEmbedProvider &&\n\t\t\t\t\t! wordpressCantEmbed;\n\t\t\t\treturn {\n\t\t\t\t\tpreview: validPreview ? embedPreview : undefined,\n\t\t\t\t\tfetching: isRequestingEmbedPreview( attributesUrl ),\n\t\t\t\t\tthemeSupportsResponsive:\n\t\t\t\t\t\tgetThemeSupports()[ 'responsive-embeds' ],\n\t\t\t\t\tcannotEmbed: ! validPreview || previewIsFallback,\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ attributesUrl ]\n\t\t);\n\n\t/**\n\t * Returns the attributes derived from the preview, merged with the current attributes.\n\t *\n\t * @return {Object} Merged attributes.\n\t */\n\tconst getMergedAttributes = () =>\n\t\tgetMergedAttributesWithPreview(\n\t\t\tattributes,\n\t\t\tpreview,\n\t\t\ttitle,\n\t\t\tresponsive\n\t\t);\n\n\tconst toggleResponsive = () => {\n\t\tconst { allowResponsive, className } = attributes;\n\t\tconst { html } = preview;\n\t\tconst newAllowResponsive = ! allowResponsive;\n\n\t\tsetAttributes( {\n\t\t\tallowResponsive: newAllowResponsive,\n\t\t\tclassName: getClassNames(\n\t\t\t\thtml,\n\t\t\t\tclassName,\n\t\t\t\tresponsive && newAllowResponsive\n\t\t\t),\n\t\t} );\n\t};\n\n\tuseEffect( () => {\n\t\tif ( preview?.html || ! cannotEmbed || fetching ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// At this stage, we're not fetching the preview and know it can't be embedded,\n\t\t// so try removing any trailing slash, and resubmit.\n\t\tconst newURL = attributesUrl.replace( /\\/$/, '' );\n\t\tsetURL( newURL );\n\t\tsetIsEditingURL( false );\n\t\tsetAttributes( { url: newURL } );\n\t}, [ preview?.html, attributesUrl, cannotEmbed, fetching, setAttributes ] );\n\n\t// Try a different provider in case the embed url is not supported.\n\tuseEffect( () => {\n\t\tif ( ! cannotEmbed || fetching || ! url ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Until X provider is supported in WordPress, as a workaround we use Twitter provider.\n\t\tif ( getAuthority( url ) === 'x.com' ) {\n\t\t\tconst newURL = new URL( url );\n\t\t\tnewURL.host = 'twitter.com';\n\t\t\tsetAttributes( { url: newURL.toString() } );\n\t\t}\n\t}, [ url, cannotEmbed, fetching, setAttributes ] );\n\n\t// Handle incoming preview.\n\tuseEffect( () => {\n\t\tif ( preview && ! isEditingURL ) {\n\t\t\t// When obtaining an incoming preview,\n\t\t\t// we set the attributes derived from the preview data.\n\t\t\tconst mergedAttributes = getMergedAttributes();\n\t\t\tsetAttributes( mergedAttributes );\n\n\t\t\tif ( onReplace ) {\n\t\t\t\tconst upgradedBlock = createUpgradedEmbedBlock(\n\t\t\t\t\tprops,\n\t\t\t\t\tmergedAttributes\n\t\t\t\t);\n\n\t\t\t\tif ( upgradedBlock ) {\n\t\t\t\t\tonReplace( upgradedBlock );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [ preview, isEditingURL ] );\n\n\tconst blockProps = useBlockProps();\n\n\tif ( fetching ) {\n\t\treturn (\n\t\t\t<View { ...blockProps }>\n\t\t\t\t<EmbedLoading />\n\t\t\t</View>\n\t\t);\n\t}\n\n\t// translators: %s: type of embed e.g: \"YouTube\", \"Twitter\", etc. \"Embed\" is used when no specific type exists\n\tconst label = sprintf( __( '%s URL' ), title );\n\n\t// No preview, or we can't embed the current URL, or we've clicked the edit button.\n\tconst showEmbedPlaceholder = ! preview || cannotEmbed || isEditingURL;\n\n\tif ( showEmbedPlaceholder ) {\n\t\treturn (\n\t\t\t<View { ...blockProps }>\n\t\t\t\t<EmbedPlaceholder\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tlabel={ label }\n\t\t\t\t\tonFocus={ onFocus }\n\t\t\t\t\tonSubmit={ ( event ) => {\n\t\t\t\t\t\tif ( event ) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// If the embed URL was changed, we need to reset the aspect ratio class.\n\t\t\t\t\t\t// To do this we have to remove the existing ratio class so it can be recalculated.\n\t\t\t\t\t\tconst blockClass = removeAspectRatioClasses(\n\t\t\t\t\t\t\tattributes.className\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tsetIsEditingURL( false );\n\t\t\t\t\t\tsetAttributes( { url, className: blockClass } );\n\t\t\t\t\t} }\n\t\t\t\t\tvalue={ url }\n\t\t\t\t\tcannotEmbed={ cannotEmbed }\n\t\t\t\t\tonChange={ ( event ) => setURL( event.target.value ) }\n\t\t\t\t\tfallback={ () => fallback( url, onReplace ) }\n\t\t\t\t\ttryAgain={ () => {\n\t\t\t\t\t\tinvalidateResolution( 'getEmbedPreview', [ url ] );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</View>\n\t\t);\n\t}\n\n\t// Even though we set attributes that get derived from the preview,\n\t// we don't access them directly because for the initial render,\n\t// the `setAttributes` call will not have taken effect. If we're\n\t// rendering responsive content, setting the responsive classes\n\t// after the preview has been rendered can result in unwanted\n\t// clipping or scrollbars. The `getAttributesFromPreview` function\n\t// that `getMergedAttributes` uses is memoized so that we're not\n\t// calculating them on every render.\n\tconst {\n\t\tcaption,\n\t\ttype,\n\t\tallowResponsive,\n\t\tclassName: classFromPreview,\n\t} = getMergedAttributes();\n\tconst className = classnames( classFromPreview, props.className );\n\n\treturn (\n\t\t<>\n\t\t\t<EmbedControls\n\t\t\t\tshowEditButton={ preview && ! cannotEmbed }\n\t\t\t\tthemeSupportsResponsive={ themeSupportsResponsive }\n\t\t\t\tblockSupportsResponsive={ responsive }\n\t\t\t\tallowResponsive={ allowResponsive }\n\t\t\t\ttoggleResponsive={ toggleResponsive }\n\t\t\t\tswitchBackToURLInput={ () => setIsEditingURL( true ) }\n\t\t\t/>\n\t\t\t<View { ...blockProps }>\n\t\t\t\t<EmbedPreview\n\t\t\t\t\tpreview={ preview }\n\t\t\t\t\tpreviewable={ previewable }\n\t\t\t\t\tclassName={ className }\n\t\t\t\t\turl={ url }\n\t\t\t\t\ttype={ type }\n\t\t\t\t\tcaption={ caption }\n\t\t\t\t\tonCaptionChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { caption: value } )\n\t\t\t\t\t}\n\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\ticon={ icon }\n\t\t\t\t\tlabel={ label }\n\t\t\t\t\tinsertBlocksAfter={ insertBlocksAfter }\n\t\t\t\t/>\n\t\t\t</View>\n\t\t</>\n\t);\n};\n\nexport default EmbedEdit;\n"],"mappings":";AAAA;AACA;AACA;AACA,SACCA,wBAAwB,EACxBC,aAAa,EACbC,wBAAwB,EACxBC,QAAQ,EACRC,sBAAsB,EACtBC,8BAA8B,QACxB,QAAQ;AACf,OAAOC,aAAa,MAAM,kBAAkB;AAC5C,SAASC,gBAAgB,QAAQ,SAAS;AAC1C,OAAOC,YAAY,MAAM,iBAAiB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version":3,"names":["_x","file","icon","initBlock","deprecated","edit","metadata","$schema","apiVersion","name","title","category","description","keywords","textdomain","attributes","id","type","href","fileId","source","selector","attribute","fileName","textLinkHref","textLinkTarget","showDownloadButton","downloadButtonText","displayPreview","previewHeight","supports","anchor","align","spacing","margin","padding","color","gradients","link","text","__experimentalDefaultControls","background","interactivity","
|
|
1
|
+
{"version":3,"names":["_x","file","icon","initBlock","deprecated","edit","metadata","$schema","apiVersion","name","title","category","description","keywords","textdomain","attributes","id","type","href","fileId","source","selector","attribute","fileName","textLinkHref","textLinkTarget","showDownloadButton","downloadButtonText","displayPreview","previewHeight","supports","anchor","align","spacing","margin","padding","color","gradients","link","text","__experimentalDefaultControls","background","interactivity","editorStyle","style","save","transforms","settings","example","init"],"sources":["@wordpress/block-library/src/file/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { _x } from '@wordpress/i18n';\nimport { file as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\thref: 'https://upload.wikimedia.org/wikipedia/commons/d/dd/Armstrong_Small_Step.ogg',\n\t\t\tfileName: _x( 'Armstrong_Small_Step', 'Name of the file' ),\n\t\t},\n\t},\n\ttransforms,\n\tdeprecated,\n\tedit,\n\tsave,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,IAAI,IAAIC,IAAI,QAAQ,kBAAkB;;AAE/C;AACA;AACA;AACA,OAAOC,SAAS,MAAM,qBAAqB;AAC3C,OAAOC,UAAU,MAAM,cAAc;AACrC,OAAOC,IAAI,MAAM,QAAQ;AAAC,MAAAC,QAAA;EAAAC,OAAA;E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C,IAAI;EACJwC;AACD,CAAC;AAED,OAAO,MAAMI,IAAI,GAAGA,CAAA,KAAM9C,SAAS,CAAE;EAAEM,IAAI;EAAEH,QAAQ;EAAEyC;AAAS,CAAE,CAAC"}
|
|
@@ -14,9 +14,10 @@ export default function FootnotesEdit({
|
|
|
14
14
|
}
|
|
15
15
|
}) {
|
|
16
16
|
const [meta, updateMeta] = useEntityProp('postType', postType, 'meta', postId);
|
|
17
|
+
const footnotesSupported = 'string' === typeof meta?.footnotes;
|
|
17
18
|
const footnotes = meta?.footnotes ? JSON.parse(meta.footnotes) : [];
|
|
18
19
|
const blockProps = useBlockProps();
|
|
19
|
-
if (
|
|
20
|
+
if (!footnotesSupported) {
|
|
20
21
|
return createElement("div", {
|
|
21
22
|
...blockProps
|
|
22
23
|
}, createElement(Placeholder, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BlockIcon","RichText","useBlockProps","useEntityProp","__","Placeholder","formatListNumbered","icon","FootnotesEdit","context","postType","postId","meta","updateMeta","footnotes","JSON","parse","blockProps","createElement","label","instructions","length","map","id","content","key","onMouseDown","event","target","currentTarget","firstElementChild","focus","preventDefault","tagName","value","identifier","onFocus","textContent","trim","scrollIntoView","onChange","nextFootnote","stringify","footnote","href"],"sources":["@wordpress/block-library/src/footnotes/edit.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { BlockIcon, RichText, useBlockProps } from '@wordpress/block-editor';\nimport { useEntityProp } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { Placeholder } from '@wordpress/components';\nimport { formatListNumbered as icon } from '@wordpress/icons';\n\nexport default function FootnotesEdit( { context: { postType, postId } } ) {\n\tconst [ meta, updateMeta ] = useEntityProp(\n\t\t'postType',\n\t\tpostType,\n\t\t'meta',\n\t\tpostId\n\t);\n\tconst footnotes = meta?.footnotes ? JSON.parse( meta.footnotes ) : [];\n\tconst blockProps = useBlockProps();\n\n\tif (
|
|
1
|
+
{"version":3,"names":["BlockIcon","RichText","useBlockProps","useEntityProp","__","Placeholder","formatListNumbered","icon","FootnotesEdit","context","postType","postId","meta","updateMeta","footnotesSupported","footnotes","JSON","parse","blockProps","createElement","label","instructions","length","map","id","content","key","onMouseDown","event","target","currentTarget","firstElementChild","focus","preventDefault","tagName","value","identifier","onFocus","textContent","trim","scrollIntoView","onChange","nextFootnote","stringify","footnote","href"],"sources":["@wordpress/block-library/src/footnotes/edit.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { BlockIcon, RichText, useBlockProps } from '@wordpress/block-editor';\nimport { useEntityProp } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { Placeholder } from '@wordpress/components';\nimport { formatListNumbered as icon } from '@wordpress/icons';\n\nexport default function FootnotesEdit( { context: { postType, postId } } ) {\n\tconst [ meta, updateMeta ] = useEntityProp(\n\t\t'postType',\n\t\tpostType,\n\t\t'meta',\n\t\tpostId\n\t);\n\tconst footnotesSupported = 'string' === typeof meta?.footnotes;\n\tconst footnotes = meta?.footnotes ? JSON.parse( meta.footnotes ) : [];\n\tconst blockProps = useBlockProps();\n\n\tif ( ! footnotesSupported ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Placeholder\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\tlabel={ __( 'Footnotes' ) }\n\t\t\t\t\tinstructions={ __(\n\t\t\t\t\t\t'Footnotes are not supported here. Add this block to post or page content.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( ! footnotes.length ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Placeholder\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\tlabel={ __( 'Footnotes' ) }\n\t\t\t\t\tinstructions={ __(\n\t\t\t\t\t\t'Footnotes found in blocks within this document will be displayed here.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<ol { ...blockProps }>\n\t\t\t{ footnotes.map( ( { id, content } ) => (\n\t\t\t\t/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */\n\t\t\t\t<li\n\t\t\t\t\tkey={ id }\n\t\t\t\t\tonMouseDown={ ( event ) => {\n\t\t\t\t\t\t// When clicking on the list item (not on descendants),\n\t\t\t\t\t\t// focus the rich text element since it's only 1px wide when\n\t\t\t\t\t\t// empty.\n\t\t\t\t\t\tif ( event.target === event.currentTarget ) {\n\t\t\t\t\t\t\tevent.target.firstElementChild.focus();\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<RichText\n\t\t\t\t\t\tid={ id }\n\t\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\t\tvalue={ content }\n\t\t\t\t\t\tidentifier={ id }\n\t\t\t\t\t\t// To do: figure out why the browser is not scrolling\n\t\t\t\t\t\t// into view when it receives focus.\n\t\t\t\t\t\tonFocus={ ( event ) => {\n\t\t\t\t\t\t\tif ( ! event.target.textContent.trim() ) {\n\t\t\t\t\t\t\t\tevent.target.scrollIntoView();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonChange={ ( nextFootnote ) => {\n\t\t\t\t\t\t\tupdateMeta( {\n\t\t\t\t\t\t\t\t...meta,\n\t\t\t\t\t\t\t\tfootnotes: JSON.stringify(\n\t\t\t\t\t\t\t\t\tfootnotes.map( ( footnote ) => {\n\t\t\t\t\t\t\t\t\t\treturn footnote.id === id\n\t\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\t\tcontent: nextFootnote,\n\t\t\t\t\t\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t\t\t\t\t: footnote;\n\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t),\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ACPzB,aAAA;IAAG0B,IAAI,EAAI,IAAIrB,EAAI;EAAQ,GAAC,cAAK,CAC9B,CACH,CACC,CAAC;AAEP"}
|
|
@@ -12,6 +12,7 @@ import { formatListNumbered as icon } from '@wordpress/icons';
|
|
|
12
12
|
import { insertObject } from '@wordpress/rich-text';
|
|
13
13
|
import { RichTextToolbarButton, store as blockEditorStore, privateApis } from '@wordpress/block-editor';
|
|
14
14
|
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
|
|
15
|
+
import { store as coreDataStore } from '@wordpress/core-data';
|
|
15
16
|
import { createBlock, store as blocksStore } from '@wordpress/blocks';
|
|
16
17
|
|
|
17
18
|
/**
|
|
@@ -33,13 +34,14 @@ export const format = {
|
|
|
33
34
|
},
|
|
34
35
|
interactive: true,
|
|
35
36
|
contentEditable: false,
|
|
36
|
-
[usesContextKey]: ['postType'],
|
|
37
|
+
[usesContextKey]: ['postType', 'postId'],
|
|
37
38
|
edit: function Edit({
|
|
38
39
|
value,
|
|
39
40
|
onChange,
|
|
40
41
|
isObjectActive,
|
|
41
42
|
context: {
|
|
42
|
-
postType
|
|
43
|
+
postType,
|
|
44
|
+
postId
|
|
43
45
|
}
|
|
44
46
|
}) {
|
|
45
47
|
const registry = useRegistry();
|
|
@@ -50,32 +52,28 @@ export const format = {
|
|
|
50
52
|
getBlockName,
|
|
51
53
|
getBlockParentsByBlockName
|
|
52
54
|
} = registry.select(blockEditorStore);
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
const isFootnotesSupported = useSelect(select => {
|
|
56
|
+
if (!select(blocksStore).getBlockType('core/footnotes')) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const entityRecord = select(coreDataStore).getEntityRecord('postType', postType, postId);
|
|
60
|
+
if ('string' !== typeof entityRecord?.meta?.footnotes) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Checks if the selected block lives within a pattern.
|
|
59
65
|
const {
|
|
60
66
|
getBlockParentsByBlockName: _getBlockParentsByBlockName,
|
|
61
67
|
getSelectedBlockClientId: _getSelectedBlockClientId
|
|
62
68
|
} = select(blockEditorStore);
|
|
63
69
|
const parentCoreBlocks = _getBlockParentsByBlockName(_getSelectedBlockClientId(), SYNCED_PATTERN_BLOCK_NAME);
|
|
64
|
-
return parentCoreBlocks
|
|
65
|
-
}, []);
|
|
70
|
+
return !parentCoreBlocks || parentCoreBlocks.length === 0;
|
|
71
|
+
}, [postType, postId]);
|
|
66
72
|
const {
|
|
67
73
|
selectionChange,
|
|
68
74
|
insertBlock
|
|
69
75
|
} = useDispatch(blockEditorStore);
|
|
70
|
-
if (!
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
if (postType !== 'post' && postType !== 'page') {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Checks if the selected block lives within a pattern.
|
|
78
|
-
if (isBlockWithinPattern) {
|
|
76
|
+
if (!isFootnotesSupported) {
|
|
79
77
|
return null;
|
|
80
78
|
}
|
|
81
79
|
function onClick() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["v4","createId","__","formatListNumbered","icon","insertObject","RichTextToolbarButton","store","blockEditorStore","privateApis","useSelect","useDispatch","useRegistry","createBlock","blocksStore","unlock","usesContextKey","formatName","POST_CONTENT_BLOCK_NAME","SYNCED_PATTERN_BLOCK_NAME","format","title","tagName","className","attributes","interactive","contentEditable","edit","Edit","value","onChange","isObjectActive","context","postType","registry","getSelectedBlockClientId","getBlocks","getBlockRootClientId","getBlockName","getBlockParentsByBlockName","select","
|
|
1
|
+
{"version":3,"names":["v4","createId","__","formatListNumbered","icon","insertObject","RichTextToolbarButton","store","blockEditorStore","privateApis","useSelect","useDispatch","useRegistry","coreDataStore","createBlock","blocksStore","unlock","usesContextKey","formatName","POST_CONTENT_BLOCK_NAME","SYNCED_PATTERN_BLOCK_NAME","format","title","tagName","className","attributes","interactive","contentEditable","edit","Edit","value","onChange","isObjectActive","context","postType","postId","registry","getSelectedBlockClientId","getBlocks","getBlockRootClientId","getBlockName","getBlockParentsByBlockName","select","isFootnotesSupported","getBlockType","entityRecord","getEntityRecord","meta","footnotes","_getBlockParentsByBlockName","_getSelectedBlockClientId","parentCoreBlocks","length","selectionChange","insertBlock","onClick","batch","id","object","replacements","start","newValue","type","innerHTML","end","selectedClientId","parentPostContent","blocks","fnBlock","queue","block","shift","name","push","innerBlocks","rootClientId","undefined","clientId","createElement","isActive"],"sources":["@wordpress/block-library/src/footnotes/format.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { v4 as createId } from 'uuid';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { formatListNumbered as icon } from '@wordpress/icons';\nimport { insertObject } from '@wordpress/rich-text';\nimport {\n\tRichTextToolbarButton,\n\tstore as blockEditorStore,\n\tprivateApis,\n} from '@wordpress/block-editor';\nimport { useSelect, useDispatch, useRegistry } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { createBlock, store as blocksStore } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\nconst { usesContextKey } = unlock( privateApis );\n\nexport const formatName = 'core/footnote';\n\nconst POST_CONTENT_BLOCK_NAME = 'core/post-content';\nconst SYNCED_PATTERN_BLOCK_NAME = 'core/block';\n\nexport const format = {\n\ttitle: __( 'Footnote' ),\n\ttagName: 'sup',\n\tclassName: 'fn',\n\tattributes: {\n\t\t'data-fn': 'data-fn',\n\t},\n\tinteractive: true,\n\tcontentEditable: false,\n\t[ usesContextKey ]: [ 'postType', 'postId' ],\n\tedit: function Edit( {\n\t\tvalue,\n\t\tonChange,\n\t\tisObjectActive,\n\t\tcontext: { postType, postId },\n\t} ) {\n\t\tconst registry = useRegistry();\n\t\tconst {\n\t\t\tgetSelectedBlockClientId,\n\t\t\tgetBlocks,\n\t\t\tgetBlockRootClientId,\n\t\t\tgetBlockName,\n\t\t\tgetBlockParentsByBlockName,\n\t\t} = registry.select( blockEditorStore );\n\t\tconst isFootnotesSupported = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tif (\n\t\t\t\t\t! select( blocksStore ).getBlockType( 'core/footnotes' )\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tconst entityRecord = select( coreDataStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\tpostType,\n\t\t\t\t\tpostId\n\t\t\t\t);\n\n\t\t\t\tif ( 'string' !== typeof entityRecord?.meta?.footnotes ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\t// Checks if the selected block lives within a pattern.\n\t\t\t\tconst {\n\t\t\t\t\tgetBlockParentsByBlockName: _getBlockParentsByBlockName,\n\t\t\t\t\tgetSelectedBlockClientId: _getSelectedBlockClientId,\n\t\t\t\t} = select( blockEditorStore );\n\t\t\t\tconst parentCoreBlocks = _getBlockParentsByBlockName(\n\t\t\t\t\t_getSelectedBlockClientId(),\n\t\t\t\t\tSYNCED_PATTERN_BLOCK_NAME\n\t\t\t\t);\n\t\t\t\treturn ! parentCoreBlocks || parentCoreBlocks.length === 0;\n\t\t\t},\n\t\t\t[ postType, postId ]\n\t\t);\n\n\t\tconst { selectionChange, insertBlock } =\n\t\t\tuseDispatch( blockEditorStore );\n\n\t\tif ( ! isFootnotesSupported ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tfunction onClick() {\n\t\t\tregistry.batch( () => {\n\t\t\t\tlet id;\n\t\t\t\tif ( isObjectActive ) {\n\t\t\t\t\tconst object = value.replacements[ value.start ];\n\t\t\t\t\tid = object?.attributes?.[ 'data-fn' ];\n\t\t\t\t} else {\n\t\t\t\t\tid = createId();\n\t\t\t\t\tconst newValue = insertObject(\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: formatName,\n\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\t'data-fn': id,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tinnerHTML: `<a href=\"#${ id }\" id=\"${ id }-link\">*</a>`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tvalue.end,\n\t\t\t\t\t\tvalue.end\n\t\t\t\t\t);\n\t\t\t\t\tnewValue.start = newValue.end - 1;\n\t\t\t\t\tonChange( newValue );\n\t\t\t\t}\n\n\t\t\t\tconst selectedClientId = getSelectedBlockClientId();\n\n\t\t\t\t/*\n\t\t\t\t * Attempts to find a common parent post content block.\n\t\t\t\t * This allows for locating blocks within a page edited in the site editor.\n\t\t\t\t */\n\t\t\t\tconst parentPostContent = getBlockParentsByBlockName(\n\t\t\t\t\tselectedClientId,\n\t\t\t\t\tPOST_CONTENT_BLOCK_NAME\n\t\t\t\t);\n\n\t\t\t\t// When called with a post content block, getBlocks will return\n\t\t\t\t// the block with controlled inner blocks included.\n\t\t\t\tconst blocks = parentPostContent.length\n\t\t\t\t\t? getBlocks( parentPostContent[ 0 ] )\n\t\t\t\t\t: getBlocks();\n\n\t\t\t\t// BFS search to find the first footnote block.\n\t\t\t\tlet fnBlock = null;\n\t\t\t\t{\n\t\t\t\t\tconst queue = [ ...blocks ];\n\t\t\t\t\twhile ( queue.length ) {\n\t\t\t\t\t\tconst block = queue.shift();\n\t\t\t\t\t\tif ( block.name === 'core/footnotes' ) {\n\t\t\t\t\t\t\tfnBlock = block;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tqueue.push( ...block.innerBlocks );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Maybe this should all also be moved to the entity provider.\n\t\t\t\t// When there is no footnotes block in the post, create one and\n\t\t\t\t// insert it at the bottom.\n\t\t\t\tif ( ! fnBlock ) {\n\t\t\t\t\tlet rootClientId = getBlockRootClientId( selectedClientId );\n\n\t\t\t\t\twhile (\n\t\t\t\t\t\trootClientId &&\n\t\t\t\t\t\tgetBlockName( rootClientId ) !== POST_CONTENT_BLOCK_NAME\n\t\t\t\t\t) {\n\t\t\t\t\t\trootClientId = getBlockRootClientId( rootClientId );\n\t\t\t\t\t}\n\n\t\t\t\t\tfnBlock = createBlock( 'core/footnotes' );\n\n\t\t\t\t\tinsertBlock( fnBlock, undefined, rootClientId );\n\t\t\t\t}\n\n\t\t\t\tselectionChange( fnBlock.clientId, id, 0, 0 );\n\t\t\t} );\n\t\t}\n\n\t\treturn (\n\t\t\t<RichTextToolbarButton\n\t\t\t\ticon={ icon }\n\t\t\t\ttitle={ __( 'Footnote' ) }\n\t\t\t\tonClick={ onClick }\n\t\t\t\tisActive={ isObjectActive }\n\t\t\t/>\n\t\t);\n\t},\n};\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,IAAIC,QAAQ,QAAQ,MAAM;;AAErC;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,kBAAkB,IAAIC,IAAI,QAAQ,kBAAkB;AAC7D,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SACCC,qBAAqB,EACrBC,KAAK,IAAIC,gBAAgB,EACzBC,WAAW,QACL,yBAAyB;AAChC,SAASC,SAAS,EAAEC,WAAW,EAAEC,WAAW,QAAQ,iBAAiB;AACrE,SAASL,KAAK,IAAIM,aAAa,QAAQ,sBAAsB;AAC7D,SAASC,WAAW,EAAEP,KAAK,IAAIQ,WAAW,QAAQ,mBAAmB;;AAErE;AACA;AACA;AACA,SAASC,MAAM,QAAQ,gBAAgB;AAEvC,MAAM;EAAEC;AAAe,CAAC,GAAGD,MAAM,CAAEP,WAAY,CAAC;AAEhD,OAAO,MAAMS,UAAU,GAAG,eAAe;AAEzC,MAAMC,uBAAuB,GAAG,mBAAmB;AACnD,MAAMC,yBAAyB,GAAG,YAAY;AAE9C,OAAO,MAAMC,MAAM,GAAG;EACrBC,KAAK,EAAEpB,EAAE,CAAE,UAAW,CAAC;EACvBqB,OAAO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kB,KAAK,GAAGD,KAAK,CAACE,KAAK,CAAC,CAAC;YAC3B,IAAKD,KAAK,CAACE,IAAI,KAAK,gBAAgB,EAAG;cACtCJ,OAAO,GAAGE,KAAK;cACf;YACD;YACAD,KAAK,CAACI,IAAI,CAAE,GAAGH,KAAK,CAACI,WAAY,CAAC;UACnC;QACD;;QAEA;QACA;QACA;QACA,IAAK,CAAEN,OAAO,EAAG;UAChB,IAAIO,YAAY,GAAGpC,oBAAoB,CAAE0B,gBAAiB,CAAC;UAE3D,OACCU,YAAY,IACZnC,YAAY,CAAEmC,YAAa,CAAC,KAAKxD,uBAAuB,EACvD;YACDwD,YAAY,GAAGpC,oBAAoB,CAAEoC,YAAa,CAAC;UACpD;UAEAP,OAAO,GAAGtD,WAAW,CAAE,gBAAiB,CAAC;UAEzCwC,WAAW,CAAEc,OAAO,EAAEQ,SAAS,EAAED,YAAa,CAAC;QAChD;QAEAtB,eAAe,CAAEe,OAAO,CAACS,QAAQ,EAAEpB,EAAE,EAAE,CAAC,EAAE,CAAE,CAAC;MAC9C,CAAE,CAAC;IACJ;IAEA,OACCqB,aAAA,CAACxE,qBAAqB;MACrBF,IAAI,EAAGA,IAAM;MACbkB,KAAK,EAAGpB,EAAE,CAAE,UAAW,CAAG;MAC1BqD,OAAO,EAAGA,OAAS;MACnBwB,QAAQ,EAAG/C;IAAgB,CAC3B,CAAC;EAEJ;AACD,CAAC"}
|
|
@@ -11,7 +11,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
11
11
|
import { useEffect, Platform } from '@wordpress/element';
|
|
12
12
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
13
13
|
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
|
|
14
|
-
import { AlignmentControl, BlockControls, RichText, useBlockProps, store as blockEditorStore, HeadingLevelDropdown } from '@wordpress/block-editor';
|
|
14
|
+
import { AlignmentControl, BlockControls, RichText, useBlockProps, store as blockEditorStore, HeadingLevelDropdown, useBlockEditingMode } from '@wordpress/block-editor';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Internal dependencies
|
|
@@ -39,6 +39,7 @@ function HeadingEdit({
|
|
|
39
39
|
}),
|
|
40
40
|
style
|
|
41
41
|
});
|
|
42
|
+
const blockEditingMode = useBlockEditingMode();
|
|
42
43
|
const {
|
|
43
44
|
canGenerateAnchors
|
|
44
45
|
} = useSelect(select => {
|
|
@@ -82,7 +83,7 @@ function HeadingEdit({
|
|
|
82
83
|
}
|
|
83
84
|
setAttributes(newAttrs);
|
|
84
85
|
};
|
|
85
|
-
return createElement(Fragment, null, createElement(BlockControls, {
|
|
86
|
+
return createElement(Fragment, null, blockEditingMode === 'default' && createElement(BlockControls, {
|
|
86
87
|
group: "block"
|
|
87
88
|
}, createElement(HeadingLevelDropdown, {
|
|
88
89
|
value: level,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["classnames","__","useEffect","Platform","useDispatch","useSelect","createBlock","getDefaultBlockName","AlignmentControl","BlockControls","RichText","useBlockProps","store","blockEditorStore","HeadingLevelDropdown","generateAnchor","setAnchor","HeadingEdit","attributes","setAttributes","mergeBlocks","onReplace","style","clientId","textAlign","content","level","placeholder","anchor","tagName","blockProps","className","canGenerateAnchors","select","getGlobalBlockCount","getSettings","settings","generateAnchors","__unstableMarkNextChangeAsNotPersistent","onContentChange","value","newAttrs","createElement","Fragment","group","onChange","newLevel","nextAlign","identifier","onMerge","onSplit","isOriginal","block","_getDefaultBlockName","onRemove","isNative","deleteEnter"],"sources":["@wordpress/block-library/src/heading/edit.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useEffect, Platform } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\nimport {\n\tAlignmentControl,\n\tBlockControls,\n\tRichText,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\tHeadingLevelDropdown,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { generateAnchor, setAnchor } from './autogenerate-anchors';\n\nfunction HeadingEdit( {\n\tattributes,\n\tsetAttributes,\n\tmergeBlocks,\n\tonReplace,\n\tstyle,\n\tclientId,\n} ) {\n\tconst { textAlign, content, level, placeholder, anchor } = attributes;\n\tconst tagName = 'h' + level;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t\tstyle,\n\t} );\n\n\tconst { canGenerateAnchors } = useSelect( ( select ) => {\n\t\tconst { getGlobalBlockCount, getSettings } = select( blockEditorStore );\n\t\tconst settings = getSettings();\n\n\t\treturn {\n\t\t\tcanGenerateAnchors:\n\t\t\t\t!! settings.generateAnchors ||\n\t\t\t\tgetGlobalBlockCount( 'core/table-of-contents' ) > 0,\n\t\t};\n\t}, [] );\n\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\n\t// Initially set anchor for headings that have content but no anchor set.\n\t// This is used when transforming a block to heading, or for legacy anchors.\n\tuseEffect( () => {\n\t\tif ( ! canGenerateAnchors ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! anchor && content ) {\n\t\t\t// This side-effect should not create an undo level.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( {\n\t\t\t\tanchor: generateAnchor( clientId, content ),\n\t\t\t} );\n\t\t}\n\t\tsetAnchor( clientId, anchor );\n\n\t\t// Remove anchor map when block unmounts.\n\t\treturn () => setAnchor( clientId, null );\n\t}, [ anchor, content, clientId, canGenerateAnchors ] );\n\n\tconst onContentChange = ( value ) => {\n\t\tconst newAttrs = { content: value };\n\t\tif (\n\t\t\tcanGenerateAnchors &&\n\t\t\t( ! anchor ||\n\t\t\t\t! value ||\n\t\t\t\tgenerateAnchor( clientId, content ) === anchor )\n\t\t) {\n\t\t\tnewAttrs.anchor = generateAnchor( clientId, value );\n\t\t}\n\t\tsetAttributes( newAttrs );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t<HeadingLevelDropdown\n\t\t\t\t\tvalue={ level }\n\t\t\t\t\tonChange={ ( newLevel ) =>\n\t\t\t\t\t\tsetAttributes( { level: newLevel } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<AlignmentControl\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( nextAlign ) => {\n\t\t\t\t\t\tsetAttributes( { textAlign: nextAlign } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<RichText\n\t\t\t\tidentifier=\"content\"\n\t\t\t\ttagName={ tagName }\n\t\t\t\tvalue={ content }\n\t\t\t\tonChange={ onContentChange }\n\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\tonSplit={ ( value, isOriginal ) => {\n\t\t\t\t\tlet block;\n\n\t\t\t\t\tif ( isOriginal || value ) {\n\t\t\t\t\t\tblock = createBlock( 'core/heading', {\n\t\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t\tcontent: value,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tblock = createBlock(\n\t\t\t\t\t\t\tgetDefaultBlockName() ?? 'core/heading'\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( isOriginal ) {\n\t\t\t\t\t\tblock.clientId = clientId;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn block;\n\t\t\t\t} }\n\t\t\t\tonReplace={ onReplace }\n\t\t\t\tonRemove={ () => onReplace( [] ) }\n\t\t\t\tplaceholder={ placeholder || __( 'Heading' ) }\n\t\t\t\ttextAlign={ textAlign }\n\t\t\t\t{ ...( Platform.isNative && { deleteEnter: true } ) } // setup RichText on native mobile to delete the \"Enter\" key as it's handled by the JS/RN side\n\t\t\t\t{ ...blockProps }\n\t\t\t/>\n\t\t</>\n\t);\n}\n\nexport default HeadingEdit;\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,oBAAoB;AACxD,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,mBAAmB;AACpE,SACCC,gBAAgB,EAChBC,aAAa,EACbC,QAAQ,EACRC,aAAa,EACbC,KAAK,IAAIC,gBAAgB,EACzBC,oBAAoB,
|
|
1
|
+
{"version":3,"names":["classnames","__","useEffect","Platform","useDispatch","useSelect","createBlock","getDefaultBlockName","AlignmentControl","BlockControls","RichText","useBlockProps","store","blockEditorStore","HeadingLevelDropdown","useBlockEditingMode","generateAnchor","setAnchor","HeadingEdit","attributes","setAttributes","mergeBlocks","onReplace","style","clientId","textAlign","content","level","placeholder","anchor","tagName","blockProps","className","blockEditingMode","canGenerateAnchors","select","getGlobalBlockCount","getSettings","settings","generateAnchors","__unstableMarkNextChangeAsNotPersistent","onContentChange","value","newAttrs","createElement","Fragment","group","onChange","newLevel","nextAlign","identifier","onMerge","onSplit","isOriginal","block","_getDefaultBlockName","onRemove","isNative","deleteEnter"],"sources":["@wordpress/block-library/src/heading/edit.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useEffect, Platform } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\nimport {\n\tAlignmentControl,\n\tBlockControls,\n\tRichText,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\tHeadingLevelDropdown,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { generateAnchor, setAnchor } from './autogenerate-anchors';\n\nfunction HeadingEdit( {\n\tattributes,\n\tsetAttributes,\n\tmergeBlocks,\n\tonReplace,\n\tstyle,\n\tclientId,\n} ) {\n\tconst { textAlign, content, level, placeholder, anchor } = attributes;\n\tconst tagName = 'h' + level;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t\tstyle,\n\t} );\n\tconst blockEditingMode = useBlockEditingMode();\n\n\tconst { canGenerateAnchors } = useSelect( ( select ) => {\n\t\tconst { getGlobalBlockCount, getSettings } = select( blockEditorStore );\n\t\tconst settings = getSettings();\n\n\t\treturn {\n\t\t\tcanGenerateAnchors:\n\t\t\t\t!! settings.generateAnchors ||\n\t\t\t\tgetGlobalBlockCount( 'core/table-of-contents' ) > 0,\n\t\t};\n\t}, [] );\n\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\n\t// Initially set anchor for headings that have content but no anchor set.\n\t// This is used when transforming a block to heading, or for legacy anchors.\n\tuseEffect( () => {\n\t\tif ( ! canGenerateAnchors ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! anchor && content ) {\n\t\t\t// This side-effect should not create an undo level.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( {\n\t\t\t\tanchor: generateAnchor( clientId, content ),\n\t\t\t} );\n\t\t}\n\t\tsetAnchor( clientId, anchor );\n\n\t\t// Remove anchor map when block unmounts.\n\t\treturn () => setAnchor( clientId, null );\n\t}, [ anchor, content, clientId, canGenerateAnchors ] );\n\n\tconst onContentChange = ( value ) => {\n\t\tconst newAttrs = { content: value };\n\t\tif (\n\t\t\tcanGenerateAnchors &&\n\t\t\t( ! anchor ||\n\t\t\t\t! value ||\n\t\t\t\tgenerateAnchor( clientId, content ) === anchor )\n\t\t) {\n\t\t\tnewAttrs.anchor = generateAnchor( clientId, value );\n\t\t}\n\t\tsetAttributes( newAttrs );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t{ blockEditingMode === 'default' && (\n\t\t\t\t<BlockControls group=\"block\">\n\t\t\t\t\t<HeadingLevelDropdown\n\t\t\t\t\t\tvalue={ level }\n\t\t\t\t\t\tonChange={ ( newLevel ) =>\n\t\t\t\t\t\t\tsetAttributes( { level: newLevel } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<AlignmentControl\n\t\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\t\tonChange={ ( nextAlign ) => {\n\t\t\t\t\t\t\tsetAttributes( { textAlign: nextAlign } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\t\t\t) }\n\t\t\t<RichText\n\t\t\t\tidentifier=\"content\"\n\t\t\t\ttagName={ tagName }\n\t\t\t\tvalue={ content }\n\t\t\t\tonChange={ onContentChange }\n\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\tonSplit={ ( value, isOriginal ) => {\n\t\t\t\t\tlet block;\n\n\t\t\t\t\tif ( isOriginal || value ) {\n\t\t\t\t\t\tblock = createBlock( 'core/heading', {\n\t\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t\tcontent: value,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tblock = createBlock(\n\t\t\t\t\t\t\tgetDefaultBlockName() ?? 'core/heading'\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( isOriginal ) {\n\t\t\t\t\t\tblock.clientId = clientId;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn block;\n\t\t\t\t} }\n\t\t\t\tonReplace={ onReplace }\n\t\t\t\tonRemove={ () => onReplace( [] ) }\n\t\t\t\tplaceholder={ placeholder || __( 'Heading' ) }\n\t\t\t\ttextAlign={ textAlign }\n\t\t\t\t{ ...( Platform.isNative && { deleteEnter: true } ) } // setup RichText on native mobile to delete the \"Enter\" key as it's handled by the JS/RN side\n\t\t\t\t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|
3
|
+
* External dependencies
|
|
4
|
+
*/
|
|
5
|
+
import classnames from 'classnames';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { __ } from '@wordpress/i18n';
|
|
11
|
+
import { useEffect, Platform } from '@wordpress/element';
|
|
12
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
13
|
+
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
|
|
14
|
+
import { AlignmentControl, BlockControls, RichText, useBlockProps, store as blockEditorStore, HeadingLevelDropdown } from '@wordpress/block-editor';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal dependencies
|
|
18
|
+
*/
|
|
19
|
+
import { generateAnchor, setAnchor } from './autogenerate-anchors';
|
|
20
|
+
function HeadingEdit({
|
|
21
|
+
attributes,
|
|
22
|
+
setAttributes,
|
|
23
|
+
mergeBlocks,
|
|
24
|
+
onReplace,
|
|
25
|
+
style,
|
|
26
|
+
clientId
|
|
27
|
+
}) {
|
|
28
|
+
const {
|
|
29
|
+
textAlign,
|
|
30
|
+
content,
|
|
31
|
+
level,
|
|
32
|
+
placeholder,
|
|
33
|
+
anchor
|
|
34
|
+
} = attributes;
|
|
35
|
+
const tagName = 'h' + level;
|
|
36
|
+
const blockProps = useBlockProps({
|
|
37
|
+
className: classnames({
|
|
38
|
+
[`has-text-align-${textAlign}`]: textAlign
|
|
39
|
+
}),
|
|
40
|
+
style
|
|
41
|
+
});
|
|
42
|
+
const {
|
|
43
|
+
canGenerateAnchors
|
|
44
|
+
} = useSelect(select => {
|
|
45
|
+
const {
|
|
46
|
+
getGlobalBlockCount,
|
|
47
|
+
getSettings
|
|
48
|
+
} = select(blockEditorStore);
|
|
49
|
+
const settings = getSettings();
|
|
50
|
+
return {
|
|
51
|
+
canGenerateAnchors: !!settings.generateAnchors || getGlobalBlockCount('core/table-of-contents') > 0
|
|
52
|
+
};
|
|
53
|
+
}, []);
|
|
54
|
+
const {
|
|
55
|
+
__unstableMarkNextChangeAsNotPersistent
|
|
56
|
+
} = useDispatch(blockEditorStore);
|
|
57
|
+
|
|
58
|
+
// Initially set anchor for headings that have content but no anchor set.
|
|
59
|
+
// This is used when transforming a block to heading, or for legacy anchors.
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!canGenerateAnchors) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!anchor && content) {
|
|
65
|
+
// This side-effect should not create an undo level.
|
|
66
|
+
__unstableMarkNextChangeAsNotPersistent();
|
|
67
|
+
setAttributes({
|
|
68
|
+
anchor: generateAnchor(clientId, content)
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
setAnchor(clientId, anchor);
|
|
72
|
+
|
|
73
|
+
// Remove anchor map when block unmounts.
|
|
74
|
+
return () => setAnchor(clientId, null);
|
|
75
|
+
}, [anchor, content, clientId, canGenerateAnchors]);
|
|
76
|
+
const onContentChange = value => {
|
|
77
|
+
const newAttrs = {
|
|
78
|
+
content: value
|
|
79
|
+
};
|
|
80
|
+
if (canGenerateAnchors && (!anchor || !value || generateAnchor(clientId, content) === anchor)) {
|
|
81
|
+
newAttrs.anchor = generateAnchor(clientId, value);
|
|
82
|
+
}
|
|
83
|
+
setAttributes(newAttrs);
|
|
84
|
+
};
|
|
85
|
+
return createElement(Fragment, null, createElement(BlockControls, {
|
|
86
|
+
group: "block"
|
|
87
|
+
}, createElement(HeadingLevelDropdown, {
|
|
88
|
+
value: level,
|
|
89
|
+
onChange: newLevel => setAttributes({
|
|
90
|
+
level: newLevel
|
|
91
|
+
})
|
|
92
|
+
}), createElement(AlignmentControl, {
|
|
93
|
+
value: textAlign,
|
|
94
|
+
onChange: nextAlign => {
|
|
95
|
+
setAttributes({
|
|
96
|
+
textAlign: nextAlign
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
})), createElement(RichText, {
|
|
100
|
+
identifier: "content",
|
|
101
|
+
tagName: tagName,
|
|
102
|
+
value: content,
|
|
103
|
+
onChange: onContentChange,
|
|
104
|
+
onMerge: mergeBlocks,
|
|
105
|
+
onSplit: (value, isOriginal) => {
|
|
106
|
+
let block;
|
|
107
|
+
if (isOriginal || value) {
|
|
108
|
+
block = createBlock('core/heading', {
|
|
109
|
+
...attributes,
|
|
110
|
+
content: value
|
|
111
|
+
});
|
|
112
|
+
} else {
|
|
113
|
+
var _getDefaultBlockName;
|
|
114
|
+
block = createBlock((_getDefaultBlockName = getDefaultBlockName()) !== null && _getDefaultBlockName !== void 0 ? _getDefaultBlockName : 'core/heading');
|
|
115
|
+
}
|
|
116
|
+
if (isOriginal) {
|
|
117
|
+
block.clientId = clientId;
|
|
118
|
+
}
|
|
119
|
+
return block;
|
|
120
|
+
},
|
|
121
|
+
onReplace: onReplace,
|
|
122
|
+
onRemove: () => onReplace([]),
|
|
123
|
+
placeholder: placeholder || __('Heading'),
|
|
124
|
+
textAlign: textAlign,
|
|
125
|
+
...(Platform.isNative && {
|
|
126
|
+
deleteEnter: true
|
|
127
|
+
}),
|
|
128
|
+
...blockProps
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
export default HeadingEdit;
|
|
132
|
+
//# sourceMappingURL=edit.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["classnames","__","useEffect","Platform","useDispatch","useSelect","createBlock","getDefaultBlockName","AlignmentControl","BlockControls","RichText","useBlockProps","store","blockEditorStore","HeadingLevelDropdown","generateAnchor","setAnchor","HeadingEdit","attributes","setAttributes","mergeBlocks","onReplace","style","clientId","textAlign","content","level","placeholder","anchor","tagName","blockProps","className","canGenerateAnchors","select","getGlobalBlockCount","getSettings","settings","generateAnchors","__unstableMarkNextChangeAsNotPersistent","onContentChange","value","newAttrs","createElement","Fragment","group","onChange","newLevel","nextAlign","identifier","onMerge","onSplit","isOriginal","block","_getDefaultBlockName","onRemove","isNative","deleteEnter"],"sources":["@wordpress/block-library/src/heading/edit.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useEffect, Platform } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\nimport {\n\tAlignmentControl,\n\tBlockControls,\n\tRichText,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\tHeadingLevelDropdown,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { generateAnchor, setAnchor } from './autogenerate-anchors';\n\nfunction HeadingEdit( {\n\tattributes,\n\tsetAttributes,\n\tmergeBlocks,\n\tonReplace,\n\tstyle,\n\tclientId,\n} ) {\n\tconst { textAlign, content, level, placeholder, anchor } = attributes;\n\tconst tagName = 'h' + level;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t\tstyle,\n\t} );\n\n\tconst { canGenerateAnchors } = useSelect( ( select ) => {\n\t\tconst { getGlobalBlockCount, getSettings } = select( blockEditorStore );\n\t\tconst settings = getSettings();\n\n\t\treturn {\n\t\t\tcanGenerateAnchors:\n\t\t\t\t!! settings.generateAnchors ||\n\t\t\t\tgetGlobalBlockCount( 'core/table-of-contents' ) > 0,\n\t\t};\n\t}, [] );\n\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\n\t// Initially set anchor for headings that have content but no anchor set.\n\t// This is used when transforming a block to heading, or for legacy anchors.\n\tuseEffect( () => {\n\t\tif ( ! canGenerateAnchors ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! anchor && content ) {\n\t\t\t// This side-effect should not create an undo level.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( {\n\t\t\t\tanchor: generateAnchor( clientId, content ),\n\t\t\t} );\n\t\t}\n\t\tsetAnchor( clientId, anchor );\n\n\t\t// Remove anchor map when block unmounts.\n\t\treturn () => setAnchor( clientId, null );\n\t}, [ anchor, content, clientId, canGenerateAnchors ] );\n\n\tconst onContentChange = ( value ) => {\n\t\tconst newAttrs = { content: value };\n\t\tif (\n\t\t\tcanGenerateAnchors &&\n\t\t\t( ! anchor ||\n\t\t\t\t! value ||\n\t\t\t\tgenerateAnchor( clientId, content ) === anchor )\n\t\t) {\n\t\t\tnewAttrs.anchor = generateAnchor( clientId, value );\n\t\t}\n\t\tsetAttributes( newAttrs );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t<HeadingLevelDropdown\n\t\t\t\t\tvalue={ level }\n\t\t\t\t\tonChange={ ( newLevel ) =>\n\t\t\t\t\t\tsetAttributes( { level: newLevel } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<AlignmentControl\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( nextAlign ) => {\n\t\t\t\t\t\tsetAttributes( { textAlign: nextAlign } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<RichText\n\t\t\t\tidentifier=\"content\"\n\t\t\t\ttagName={ tagName }\n\t\t\t\tvalue={ content }\n\t\t\t\tonChange={ onContentChange }\n\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\tonSplit={ ( value, isOriginal ) => {\n\t\t\t\t\tlet block;\n\n\t\t\t\t\tif ( isOriginal || value ) {\n\t\t\t\t\t\tblock = createBlock( 'core/heading', {\n\t\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t\tcontent: value,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tblock = createBlock(\n\t\t\t\t\t\t\tgetDefaultBlockName() ?? 'core/heading'\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( isOriginal ) {\n\t\t\t\t\t\tblock.clientId = clientId;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn block;\n\t\t\t\t} }\n\t\t\t\tonReplace={ onReplace }\n\t\t\t\tonRemove={ () => onReplace( [] ) }\n\t\t\t\tplaceholder={ placeholder || __( 'Heading' ) }\n\t\t\t\ttextAlign={ textAlign }\n\t\t\t\t{ ...( Platform.isNative && { deleteEnter: true } ) } // setup RichText on native mobile to delete the \"Enter\" key as it's handled by the JS/RN side\n\t\t\t\t{ ...blockProps }\n\t\t\t/>\n\t\t</>\n\t);\n}\n\nexport default HeadingEdit;\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,oBAAoB;AACxD,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,mBAAmB;AACpE,SACCC,gBAAgB,EAChBC,aAAa,EACbC,QAAQ,EACRC,aAAa,EACbC,KAAK,IAAIC,gBAAgB,EACzBC,oBAAoB,QACd,yBAAyB;;AAEhC;AACA;AACA;AACA,SAASC,cAAc,EAAEC,SAAS,QAAQ,wBAAwB;AAElE,SAASC,WAAWA,CAAE;EACrBC,UAAU;EACVC,aAAa;EACbC,WAAW;EACXC,SAAS;EACTC,KAAK;EACLC;AACD,CAAC,EAAG;EACH,MAAM;IAAEC,SAAS;IAAEC,OAAO;IAAEC,KAAK;IAAEC,WAAW;IAAEC;EAAO,CAAC,GAAGV,UAAU;EACrE,MAAMW,OAAO,GAAG,GAAG,GAAGH,KAAK;EAC3B,MAAMI,UAAU,GAAGnB,aAAa,CAAE;IACjCoB,SAAS,EAAE/B,UAAU,CAAE;MACtB,CAAG,kBAAkBwB,SAAW,EAAC,GAAIA;IACtC,CAAE,CAAC;IACHF;EACD,CAAE,CAAC;EAEH,MAAM;IAAEU;EAAmB,CAAC,GAAG3B,SAAS,CAAI4B,MAAM,IAAM;IACvD,MAAM;MAAEC,mBAAmB;MAA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GAC5C1B;EAAU,CACf,CACA,CAAC;AAEL;AAEA,eAAeb,WAAW"}
|
|
@@ -19,6 +19,7 @@ const metadata = {
|
|
|
19
19
|
description: "Introduce new sections and organize content to help visitors (and search engines) understand the structure of your content.",
|
|
20
20
|
keywords: ["title", "subtitle"],
|
|
21
21
|
textdomain: "default",
|
|
22
|
+
usesContext: ["pattern/overrides"],
|
|
22
23
|
attributes: {
|
|
23
24
|
textAlign: {
|
|
24
25
|
type: "string"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["heading","icon","__","sprintf","initBlock","deprecated","edit","metadata","$schema","apiVersion","name","title","category","description","keywords","textdomain","attributes","textAlign","type","content","source","selector","__experimentalRole","level","placeholder","supports","align","anchor","className","color","gradients","link","__experimentalDefaultControls","background","text","spacing","margin","padding","typography","fontSize","lineHeight","__experimentalFontFamily","__experimentalFontStyle","__experimentalFontWeight","__experimentalLetterSpacing","__experimentalTextTransform","__experimentalTextDecoration","__experimentalWritingMode","__unstablePasteTextInline","__experimentalSlashInserter","editorStyle","style","save","transforms","settings","example","__experimentalLabel","context","customName","length","merge","attributesToMerge","init"],"sources":["@wordpress/block-library/src/heading/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { heading as icon } from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tcontent: __( 'Code is Poetry' ),\n\t\t\tlevel: 2,\n\t\t},\n\t},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst { content, level } = attributes;\n\n\t\tconst customName = attributes?.metadata?.name;\n\n\t\t// In the list view, use the block's content as the label.\n\t\t// If the content is empty, fall back to the default label.\n\t\tif ( context === 'list-view' && ( customName || content ) ) {\n\t\t\treturn attributes?.metadata?.name || content;\n\t\t}\n\n\t\tif ( context === 'accessibility' ) {\n\t\t\treturn ! content || content.length === 0\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. %s: heading level. */\n\t\t\t\t\t\t__( 'Level %s. Empty.' ),\n\t\t\t\t\t\tlevel\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. 1: heading level. 2: heading content. */\n\t\t\t\t\t\t__( 'Level %1$s. %2$s' ),\n\t\t\t\t\t\tlevel,\n\t\t\t\t\t\tcontent\n\t\t\t\t );\n\t\t}\n\t},\n\ttransforms,\n\tdeprecated,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\tcontent:\n\t\t\t\t( attributes.content || '' ) +\n\t\t\t\t( attributesToMerge.content || '' ),\n\t\t};\n\t},\n\tedit,\n\tsave,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,IAAIC,IAAI,QAAQ,kBAAkB;AAClD,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;;AAE7C;AACA;AACA;AACA,OAAOC,SAAS,MAAM,qBAAqB;AAC3C,OAAOC,UAAU,MAAM,cAAc;AACrC,OAAOC,IAAI,MAAM,QAAQ;AAAC,MAAAC,QAAA;EAAAC,OAAA;EAAAC,UAAA;EAAAC,IAAA;EAAAC,KAAA;EAAAC,QAAA;EAAAC,WAAA;EAAAC,QAAA;EAAAC,UAAA;EAAAC,UAAA;IAAAC,SAAA;MAAAC,IAAA;IAAA;IAAAC,OAAA;MAAAD,IAAA;MAAAE,MAAA;MAAAC,QAAA;MAAAC,kBAAA;IAAA;IAAAC,KAAA;MAAAL,IAAA;MAAA;IAAA;IAAAM,WAAA;MAAAN,IAAA;IAAA;EAAA;EAAAO,QAAA;IAAAC,KAAA;IAAAC,MAAA;IAAAC,SAAA;IAAAC,KAAA;MAAAC,SAAA;MAAAC,IAAA;MAAAC,6BAAA;QAAAC,UAAA;QAAAC,IAAA;MAAA;IAAA;IAAAC,OAAA;MAAAC,MAAA;MAAAC,OAAA;MAAAL,6BAAA;QAAAI,MAAA;QAAAC,OAAA;MAAA;IAAA;IAAAC,UAAA;MAAAC,QAAA;MAAAC,UAAA;MAAAC,wBAAA;MAAAC,uBAAA;MAAAC,wBAAA;MAAAC,2BAAA;MAAAC,2BAAA;MAAAC,4BAAA;MAAAC,yBAAA;MAAAf,6BAAA;QAAAO,QAAA;MAAA;IAAA;IAAAS,yBAAA;IAAAC,2BAAA;EAAA;EAAAC,WAAA;EAAAC,KAAA;AAAA;AAE1B,OAAOC,IAAI,MAAM,QAAQ;AACzB,OAAOC,UAAU,MAAM,cAAc;AAErC,MAAM;
|
|
1
|
+
{"version":3,"names":["heading","icon","__","sprintf","initBlock","deprecated","edit","metadata","$schema","apiVersion","name","title","category","description","keywords","textdomain","usesContext","attributes","textAlign","type","content","source","selector","__experimentalRole","level","placeholder","supports","align","anchor","className","color","gradients","link","__experimentalDefaultControls","background","text","spacing","margin","padding","typography","fontSize","lineHeight","__experimentalFontFamily","__experimentalFontStyle","__experimentalFontWeight","__experimentalLetterSpacing","__experimentalTextTransform","__experimentalTextDecoration","__experimentalWritingMode","__unstablePasteTextInline","__experimentalSlashInserter","editorStyle","style","save","transforms","settings","example","__experimentalLabel","context","customName","length","merge","attributesToMerge","init"],"sources":["@wordpress/block-library/src/heading/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { heading as icon } from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tcontent: __( 'Code is Poetry' ),\n\t\t\tlevel: 2,\n\t\t},\n\t},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst { content, level } = attributes;\n\n\t\tconst customName = attributes?.metadata?.name;\n\n\t\t// In the list view, use the block's content as the label.\n\t\t// If the content is empty, fall back to the default label.\n\t\tif ( context === 'list-view' && ( customName || content ) ) {\n\t\t\treturn attributes?.metadata?.name || content;\n\t\t}\n\n\t\tif ( context === 'accessibility' ) {\n\t\t\treturn ! content || content.length === 0\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. %s: heading level. */\n\t\t\t\t\t\t__( 'Level %s. Empty.' ),\n\t\t\t\t\t\tlevel\n\t\t\t\t )\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: accessibility text. 1: heading level. 2: heading content. */\n\t\t\t\t\t\t__( 'Level %1$s. %2$s' ),\n\t\t\t\t\t\tlevel,\n\t\t\t\t\t\tcontent\n\t\t\t\t );\n\t\t}\n\t},\n\ttransforms,\n\tdeprecated,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\tcontent:\n\t\t\t\t( attributes.content || '' ) +\n\t\t\t\t( attributesToMerge.content || '' ),\n\t\t};\n\t},\n\tedit,\n\tsave,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,IAAIC,IAAI,QAAQ,kBAAkB;AAClD,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;;AAE7C;AACA;AACA;AACA,OAAOC,SAAS,MAAM,qBAAqB;AAC3C,OAAOC,UAAU,MAAM,cAAc;AACrC,OAAOC,IAAI,MAAM,QAAQ;AAAC,MAAAC,QAAA;EAAAC,OAAA;EAAAC,UAAA;EAAAC,IAAA;EAAAC,KAAA;EAAAC,QAAA;EAAAC,WAAA;EAAAC,QAAA;EAAAC,UAAA;EAAAC,WAAA;EAAAC,UAAA;IAAAC,SAAA;MAAAC,IAAA;IAAA;IAAAC,OAAA;MAAAD,IA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Q,EAAEG,IAAI,IAAIU,OAAO;IAC7C;IAEA,IAAKsC,OAAO,KAAK,eAAe,EAAG;MAClC,OAAO,CAAEtC,OAAO,IAAIA,OAAO,CAACwC,MAAM,KAAK,CAAC,GACrCzD,OAAO,EACP;MACAD,EAAE,CAAE,kBAAmB,CAAC,EACxBsB,KACA,CAAC,GACDrB,OAAO,EACP;MACAD,EAAE,CAAE,kBAAmB,CAAC,EACxBsB,KAAK,EACLJ,OACA,CAAC;IACL;EACD,CAAC;EACDkC,UAAU;EACVjD,UAAU;EACVwD,KAAKA,CAAE5C,UAAU,EAAE6C,iBAAiB,EAAG;IACtC,OAAO;MACN1C,OAAO,EACN,CAAEH,UAAU,CAACG,OAAO,IAAI,EAAE,KACxB0C,iBAAiB,CAAC1C,OAAO,IAAI,EAAE;IACnC,CAAC;EACF,CAAC;EACDd,IAAI;EACJ+C;AACD,CAAC;AAED,OAAO,MAAMU,IAAI,GAAGA,CAAA,KAAM3D,SAAS,CAAE;EAAEM,IAAI;EAAEH,QAAQ;EAAEgD;AAAS,CAAE,CAAC"}
|
|
@@ -13,7 +13,7 @@ import { useDispatch, useSelect } from '@wordpress/data';
|
|
|
13
13
|
import { BlockIcon, MediaPlaceholder, useBlockProps, store as blockEditorStore, __experimentalUseBorderProps as useBorderProps, useBlockEditingMode } from '@wordpress/block-editor';
|
|
14
14
|
import { useEffect, useRef, useState } from '@wordpress/element';
|
|
15
15
|
import { __ } from '@wordpress/i18n';
|
|
16
|
-
import { image as icon } from '@wordpress/icons';
|
|
16
|
+
import { image as icon, plugins as pluginsIcon } from '@wordpress/icons';
|
|
17
17
|
import { store as noticesStore } from '@wordpress/notices';
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -86,7 +86,8 @@ export function ImageEdit({
|
|
|
86
86
|
sizeSlug,
|
|
87
87
|
aspectRatio,
|
|
88
88
|
scale,
|
|
89
|
-
align
|
|
89
|
+
align,
|
|
90
|
+
metadata
|
|
90
91
|
} = attributes;
|
|
91
92
|
const [temporaryURL, setTemporaryURL] = useState();
|
|
92
93
|
const altRef = useRef();
|
|
@@ -293,15 +294,16 @@ export function ImageEdit({
|
|
|
293
294
|
});
|
|
294
295
|
|
|
295
296
|
// Much of this description is duplicated from MediaPlaceholder.
|
|
297
|
+
const isUrlAttributeConnected = !!metadata?.bindings?.url;
|
|
296
298
|
const placeholder = content => {
|
|
297
299
|
return createElement(Placeholder, {
|
|
298
300
|
className: classnames('block-editor-media-placeholder', {
|
|
299
301
|
[borderProps.className]: !!borderProps.className && !isSelected
|
|
300
302
|
}),
|
|
301
303
|
withIllustration: true,
|
|
302
|
-
icon: icon,
|
|
304
|
+
icon: isUrlAttributeConnected ? pluginsIcon : icon,
|
|
303
305
|
label: __('Image'),
|
|
304
|
-
instructions: __('Upload an image file, pick one from your media library, or add one with a URL.'),
|
|
306
|
+
instructions: !isUrlAttributeConnected && __('Upload an image file, pick one from your media library, or add one with a URL.'),
|
|
305
307
|
style: {
|
|
306
308
|
aspectRatio: !(width && height) && aspectRatio ? aspectRatio : undefined,
|
|
307
309
|
width: height && aspectRatio ? '100%' : width,
|
|
@@ -309,7 +311,9 @@ export function ImageEdit({
|
|
|
309
311
|
objectFit: scale,
|
|
310
312
|
...borderProps.style
|
|
311
313
|
}
|
|
312
|
-
},
|
|
314
|
+
}, isUrlAttributeConnected ? createElement("span", {
|
|
315
|
+
className: 'block-bindings-media-placeholder-message'
|
|
316
|
+
}, __('Connected to a custom field')) : content);
|
|
313
317
|
};
|
|
314
318
|
return createElement("figure", {
|
|
315
319
|
...blockProps
|