@wordpress/block-library 10.2.0 → 10.3.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 +16 -0
- package/build/accordion-panel/block.json +1 -0
- package/build/code/edit.cjs +3 -1
- package/build/code/edit.cjs.map +2 -2
- package/build/cover/block.json +1 -0
- package/build/cover/edit/block-controls.cjs +3 -1
- package/build/cover/edit/block-controls.cjs.map +2 -2
- package/build/cover/edit/index.cjs +75 -31
- package/build/cover/edit/index.cjs.map +2 -2
- package/build/embed/edit.cjs +1 -1
- package/build/embed/edit.cjs.map +2 -2
- package/build/embed/embed-placeholder.cjs +1 -1
- package/build/embed/embed-placeholder.cjs.map +2 -2
- package/build/gallery/dynamic-gallery.cjs +104 -61
- package/build/gallery/dynamic-gallery.cjs.map +3 -3
- package/build/gallery/use-dynamic-gallery.cjs +15 -8
- package/build/gallery/use-dynamic-gallery.cjs.map +2 -2
- package/build/heading/edit.cjs +1 -1
- package/build/heading/edit.cjs.map +2 -2
- package/build/html/modal.cjs +63 -54
- package/build/html/modal.cjs.map +3 -3
- package/build/icon/block.json +5 -3
- package/build/image/edit.cjs +1 -1
- package/build/image/edit.cjs.map +2 -2
- package/build/image/image.cjs +29 -5
- package/build/image/image.cjs.map +3 -3
- package/build/image/use-open-image-media-editor-modal.cjs +6 -2
- package/build/image/use-open-image-media-editor-modal.cjs.map +2 -2
- package/build/list-item/hooks/use-indent-list-item.cjs +10 -2
- package/build/list-item/hooks/use-indent-list-item.cjs.map +2 -2
- package/build/math/edit.cjs +39 -56
- package/build/math/edit.cjs.map +3 -3
- package/build/media-text/edit.cjs +2 -1
- package/build/media-text/edit.cjs.map +2 -2
- package/build/more/edit.cjs +2 -2
- package/build/more/edit.cjs.map +2 -2
- package/build/navigation/edit/index.cjs +30 -16
- package/build/navigation/edit/index.cjs.map +3 -3
- package/build/navigation/edit/use-layout-custom-properties.cjs +72 -0
- package/build/navigation/edit/use-layout-custom-properties.cjs.map +7 -0
- package/build/navigation/view.cjs +9 -6
- package/build/navigation/view.cjs.map +2 -2
- package/build/navigation-link/edit.cjs +3 -3
- package/build/navigation-link/edit.cjs.map +2 -2
- package/build/navigation-link/link-ui/index.cjs +2 -2
- package/build/navigation-link/link-ui/index.cjs.map +2 -2
- package/build/paragraph/block.json +0 -1
- package/build/paragraph/edit.cjs +5 -2
- package/build/paragraph/edit.cjs.map +3 -3
- package/build/paragraph/index.cjs +4 -1
- package/build/paragraph/index.cjs.map +2 -2
- package/build/playlist/context.cjs +2 -1
- package/build/playlist/context.cjs.map +2 -2
- package/build/playlist/edit.cjs +113 -26
- package/build/playlist/edit.cjs.map +2 -2
- package/build/playlist/utils.cjs +19 -4
- package/build/playlist/utils.cjs.map +2 -2
- package/build/playlist-track/edit.cjs +21 -6
- package/build/playlist-track/edit.cjs.map +2 -2
- package/build/post-content/edit.cjs +36 -15
- package/build/post-content/edit.cjs.map +2 -2
- package/build/post-featured-image/edit.cjs +3 -2
- package/build/post-featured-image/edit.cjs.map +2 -2
- package/build/post-terms/edit.cjs +2 -2
- package/build/post-terms/edit.cjs.map +2 -2
- package/build/post-title/edit.cjs +2 -2
- package/build/post-title/edit.cjs.map +2 -2
- package/build/preformatted/edit.cjs +3 -1
- package/build/preformatted/edit.cjs.map +2 -2
- package/build/pullquote/edit.cjs +5 -3
- package/build/pullquote/edit.cjs.map +2 -2
- package/build/query/edit/inspector-controls/index.cjs +4 -1
- package/build/query/edit/inspector-controls/index.cjs.map +2 -2
- package/build/query/edit/inspector-controls/offset-controls.cjs +1 -1
- package/build/query/edit/inspector-controls/offset-controls.cjs.map +2 -2
- package/build/read-more/edit.cjs +3 -1
- package/build/read-more/edit.cjs.map +2 -2
- package/build/site-tagline/edit.cjs +3 -1
- package/build/site-tagline/edit.cjs.map +2 -2
- package/build/site-title/edit.cjs +3 -1
- package/build/site-title/edit.cjs.map +2 -2
- package/build/social-links/edit.cjs +11 -4
- package/build/social-links/edit.cjs.map +2 -2
- package/build/tab-list/block.json +2 -1
- package/build/tab-list/edit.cjs +2 -0
- package/build/tab-list/edit.cjs.map +3 -3
- package/build/tab-list/tab-movers.cjs +87 -0
- package/build/tab-list/tab-movers.cjs.map +7 -0
- package/build/tab-panel/edit.cjs +1 -9
- package/build/tab-panel/edit.cjs.map +2 -2
- package/build/table/edit.cjs +1 -1
- package/build/table/edit.cjs.map +2 -2
- package/build/tabs/use-tab-actions.cjs +23 -1
- package/build/tabs/use-tab-actions.cjs.map +2 -2
- package/build/utils/caption.cjs +2 -2
- package/build/utils/caption.cjs.map +2 -2
- package/build/verse/edit.cjs +3 -1
- package/build/verse/edit.cjs.map +2 -2
- package/build/video/tracks-editor.cjs +0 -1
- package/build/video/tracks-editor.cjs.map +2 -2
- package/build-module/accordion-panel/block.json +1 -0
- package/build-module/code/edit.mjs +3 -1
- package/build-module/code/edit.mjs.map +2 -2
- package/build-module/cover/block.json +1 -0
- package/build-module/cover/edit/block-controls.mjs +3 -1
- package/build-module/cover/edit/block-controls.mjs.map +2 -2
- package/build-module/cover/edit/index.mjs +78 -34
- package/build-module/cover/edit/index.mjs.map +2 -2
- package/build-module/embed/edit.mjs +1 -1
- package/build-module/embed/edit.mjs.map +2 -2
- package/build-module/embed/embed-placeholder.mjs +1 -1
- package/build-module/embed/embed-placeholder.mjs.map +2 -2
- package/build-module/gallery/dynamic-gallery.mjs +104 -61
- package/build-module/gallery/dynamic-gallery.mjs.map +2 -2
- package/build-module/gallery/use-dynamic-gallery.mjs +16 -9
- package/build-module/gallery/use-dynamic-gallery.mjs.map +2 -2
- package/build-module/heading/edit.mjs +1 -1
- package/build-module/heading/edit.mjs.map +2 -2
- package/build-module/html/modal.mjs +68 -55
- package/build-module/html/modal.mjs.map +2 -2
- package/build-module/icon/block.json +5 -3
- package/build-module/image/edit.mjs +1 -1
- package/build-module/image/edit.mjs.map +2 -2
- package/build-module/image/image.mjs +19 -5
- package/build-module/image/image.mjs.map +2 -2
- package/build-module/image/use-open-image-media-editor-modal.mjs +6 -2
- package/build-module/image/use-open-image-media-editor-modal.mjs.map +2 -2
- package/build-module/list-item/hooks/use-indent-list-item.mjs +10 -2
- package/build-module/list-item/hooks/use-indent-list-item.mjs.map +2 -2
- package/build-module/math/edit.mjs +41 -60
- package/build-module/math/edit.mjs.map +2 -2
- package/build-module/media-text/edit.mjs +2 -1
- package/build-module/media-text/edit.mjs.map +2 -2
- package/build-module/more/edit.mjs +2 -2
- package/build-module/more/edit.mjs.map +2 -2
- package/build-module/navigation/edit/index.mjs +30 -16
- package/build-module/navigation/edit/index.mjs.map +2 -2
- package/build-module/navigation/edit/use-layout-custom-properties.mjs +51 -0
- package/build-module/navigation/edit/use-layout-custom-properties.mjs.map +7 -0
- package/build-module/navigation/view.mjs +9 -6
- package/build-module/navigation/view.mjs.map +2 -2
- package/build-module/navigation-link/edit.mjs +3 -3
- package/build-module/navigation-link/edit.mjs.map +2 -2
- package/build-module/navigation-link/link-ui/index.mjs +2 -2
- package/build-module/navigation-link/link-ui/index.mjs.map +2 -2
- package/build-module/paragraph/block.json +0 -1
- package/build-module/paragraph/edit.mjs +6 -2
- package/build-module/paragraph/edit.mjs.map +2 -2
- package/build-module/paragraph/index.mjs +4 -1
- package/build-module/paragraph/index.mjs.map +2 -2
- package/build-module/playlist/context.mjs +2 -1
- package/build-module/playlist/context.mjs.map +2 -2
- package/build-module/playlist/edit.mjs +113 -27
- package/build-module/playlist/edit.mjs.map +2 -2
- package/build-module/playlist/utils.mjs +19 -4
- package/build-module/playlist/utils.mjs.map +2 -2
- package/build-module/playlist-track/edit.mjs +21 -6
- package/build-module/playlist-track/edit.mjs.map +2 -2
- package/build-module/post-content/edit.mjs +37 -15
- package/build-module/post-content/edit.mjs.map +2 -2
- package/build-module/post-featured-image/edit.mjs +3 -2
- package/build-module/post-featured-image/edit.mjs.map +2 -2
- package/build-module/post-terms/edit.mjs +2 -2
- package/build-module/post-terms/edit.mjs.map +2 -2
- package/build-module/post-title/edit.mjs +2 -2
- package/build-module/post-title/edit.mjs.map +2 -2
- package/build-module/preformatted/edit.mjs +3 -1
- package/build-module/preformatted/edit.mjs.map +2 -2
- package/build-module/pullquote/edit.mjs +5 -3
- package/build-module/pullquote/edit.mjs.map +2 -2
- package/build-module/query/edit/inspector-controls/index.mjs +5 -2
- package/build-module/query/edit/inspector-controls/index.mjs.map +2 -2
- package/build-module/query/edit/inspector-controls/offset-controls.mjs +2 -2
- package/build-module/query/edit/inspector-controls/offset-controls.mjs.map +2 -2
- package/build-module/read-more/edit.mjs +3 -1
- package/build-module/read-more/edit.mjs.map +2 -2
- package/build-module/site-tagline/edit.mjs +3 -1
- package/build-module/site-tagline/edit.mjs.map +2 -2
- package/build-module/site-title/edit.mjs +3 -1
- package/build-module/site-title/edit.mjs.map +2 -2
- package/build-module/social-links/edit.mjs +11 -4
- package/build-module/social-links/edit.mjs.map +2 -2
- package/build-module/tab-list/block.json +2 -1
- package/build-module/tab-list/edit.mjs +2 -0
- package/build-module/tab-list/edit.mjs.map +2 -2
- package/build-module/tab-list/tab-movers.mjs +59 -0
- package/build-module/tab-list/tab-movers.mjs.map +7 -0
- package/build-module/tab-panel/edit.mjs +1 -9
- package/build-module/tab-panel/edit.mjs.map +2 -2
- package/build-module/table/edit.mjs +1 -1
- package/build-module/table/edit.mjs.map +2 -2
- package/build-module/tabs/use-tab-actions.mjs +23 -1
- package/build-module/tabs/use-tab-actions.mjs.map +2 -2
- package/build-module/utils/caption.mjs +2 -2
- package/build-module/utils/caption.mjs.map +2 -2
- package/build-module/verse/edit.mjs +3 -1
- package/build-module/verse/edit.mjs.map +2 -2
- package/build-module/video/tracks-editor.mjs +0 -1
- package/build-module/video/tracks-editor.mjs.map +2 -2
- package/build-style/cover/editor-rtl.css +3 -0
- package/build-style/cover/editor.css +3 -0
- package/build-style/editor-rtl.css +18 -41
- package/build-style/editor.css +18 -41
- package/build-style/icon/editor-rtl.css +1 -4
- package/build-style/icon/editor.css +1 -4
- package/build-style/image/editor-rtl.css +3 -32
- package/build-style/image/editor.css +3 -32
- package/build-style/playlist/editor-rtl.css +0 -5
- package/build-style/playlist/editor.css +0 -5
- package/build-style/playlist/style-rtl.css +44 -4
- package/build-style/playlist/style.css +44 -4
- package/build-style/pullquote/editor-rtl.css +4 -0
- package/build-style/pullquote/editor.css +4 -0
- package/build-style/style-rtl.css +44 -4
- package/build-style/style.css +44 -4
- package/build-style/tab-list/editor-rtl.css +101 -0
- package/build-style/tab-list/editor.css +101 -0
- package/package.json +43 -43
- package/src/accordion-panel/block.json +1 -0
- package/src/breadcrumbs/index.php +3 -1
- package/src/button/index.php +1 -1
- package/src/code/edit.js +7 -2
- package/src/cover/block.json +1 -0
- package/src/cover/edit/block-controls.js +5 -0
- package/src/cover/edit/index.js +100 -35
- package/src/cover/editor.scss +6 -0
- package/src/cover/index.php +9 -2
- package/src/editor.scss +1 -0
- package/src/embed/edit.js +3 -1
- package/src/embed/embed-placeholder.js +9 -7
- package/src/form/index.php +6 -4
- package/src/gallery/dynamic-gallery.js +133 -74
- package/src/gallery/use-dynamic-gallery.js +27 -12
- package/src/heading/edit.js +1 -1
- package/src/html/modal.js +13 -2
- package/src/icon/README.md +1 -3
- package/src/icon/block.json +5 -3
- package/src/icon/editor.scss +1 -4
- package/src/image/edit.js +1 -5
- package/src/image/editor.scss +6 -46
- package/src/image/image.js +37 -3
- package/src/image/test/use-open-image-media-editor-modal.js +37 -1
- package/src/image/use-open-image-media-editor-modal.js +8 -1
- package/src/latest-posts/index.php +3 -2
- package/src/list-item/hooks/use-indent-list-item.js +10 -1
- package/src/math/edit.js +42 -59
- package/src/media-text/edit.js +1 -0
- package/src/media-text/index.php +11 -2
- package/src/more/edit.js +7 -4
- package/src/navigation/edit/index.js +52 -36
- package/src/navigation/edit/test/layout-custom-properties.js +138 -0
- package/src/navigation/edit/use-layout-custom-properties.js +84 -0
- package/src/navigation/index.php +123 -12
- package/src/navigation/test/view.js +51 -0
- package/src/navigation/view.js +15 -14
- package/src/navigation-link/edit.js +11 -7
- package/src/navigation-link/index.php +64 -0
- package/src/navigation-link/link-ui/index.js +2 -1
- package/src/navigation-link/test/__snapshots__/hooks.js.snap +1 -1
- package/src/page-list/index.php +4 -3
- package/src/paragraph/README.md +0 -1
- package/src/paragraph/block.json +0 -1
- package/src/paragraph/edit.js +9 -2
- package/src/paragraph/index.js +4 -1
- package/src/pattern/index.php +5 -5
- package/src/playlist/context.js +1 -0
- package/src/playlist/edit.js +151 -47
- package/src/playlist/editor.scss +0 -7
- package/src/playlist/index.php +14 -9
- package/src/playlist/style.scss +3 -0
- package/src/playlist/test/edit-component.js +139 -0
- package/src/playlist/test/edit.js +30 -0
- package/src/playlist/utils.js +25 -4
- package/src/playlist-track/edit.js +22 -5
- package/src/playlist-track/index.php +8 -7
- package/src/playlist-track/test/edit.js +87 -3
- package/src/post-content/edit.js +45 -16
- package/src/post-excerpt/index.php +4 -1
- package/src/post-featured-image/edit.js +3 -2
- package/src/post-featured-image/index.php +4 -1
- package/src/post-terms/edit.js +7 -4
- package/src/post-title/edit.js +5 -3
- package/src/preformatted/edit.js +7 -2
- package/src/pullquote/edit.js +9 -4
- package/src/pullquote/editor.scss +6 -0
- package/src/query/edit/inspector-controls/index.js +5 -2
- package/src/query/edit/inspector-controls/offset-controls.js +2 -2
- package/src/read-more/edit.js +7 -2
- package/src/rss/index.php +9 -3
- package/src/site-tagline/edit.js +7 -2
- package/src/site-title/edit.js +7 -2
- package/src/social-link/index.php +19 -9
- package/src/social-links/edit.js +21 -12
- package/src/tab-list/block.json +2 -1
- package/src/tab-list/edit.js +2 -0
- package/src/tab-list/editor.scss +9 -0
- package/src/tab-list/tab-movers.js +72 -0
- package/src/tab-panel/edit.js +1 -9
- package/src/table/edit.js +1 -1
- package/src/table-of-contents/index.php +386 -1
- package/src/tabs/use-tab-actions.js +32 -3
- package/src/tag-cloud/index.php +3 -2
- package/src/template-part/index.php +2 -1
- package/src/utils/caption.js +7 -4
- package/src/utils/test/waveform-utils.js +63 -0
- package/src/verse/edit.js +7 -2
- package/src/video/index.php +2 -2
- package/src/video/tracks-editor.js +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/image/use-open-image-media-editor-modal.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\nfunction normalizeImageBlockCaption( caption ) {\n\tif ( typeof caption !== 'string' ) {\n\t\treturn '';\n\t}\n\n\tconst textContent = stripHTML( caption ).trim();\n\n\tif ( ! textContent ) {\n\t\treturn '';\n\t}\n\n\treturn caption.replace( /\\n/g, '<br>' );\n}\n\nfunction getAttachmentCaption( attachment ) {\n\tconst caption = attachment?.caption;\n\n\tif ( typeof caption === 'string' ) {\n\t\treturn normalizeImageBlockCaption( caption );\n\t}\n\n\tif (\n\t\tcaption &&\n\t\ttypeof caption === 'object' &&\n\t\tObject.hasOwn( caption, 'raw' )\n\t) {\n\t\treturn normalizeImageBlockCaption( caption.raw );\n\t}\n\n\treturn undefined;\n}\n\nexport function getImageBlockMetadataFromAttachment( attachment ) {\n\treturn {\n\t\talt:\n\t\t\ttypeof attachment?.alt_text === 'string'\n\t\t\t\t? attachment.alt_text\n\t\t\t\t: attachment?.alt || '',\n\t\tcaption: getAttachmentCaption( attachment ),\n\t};\n}\n\nfunction normalizeMetadataAttribute( value ) {\n\treturn value || '';\n}\n\nexport function getSyncedImageBlockAttributes(\n\tcurrentAttributes,\n\toriginalAttachment,\n\tupdatedAttachment\n) {\n\tif ( ! originalAttachment || ! updatedAttachment ) {\n\t\treturn {};\n\t}\n\n\tconst originalMetadata =\n\t\tgetImageBlockMetadataFromAttachment( originalAttachment );\n\tconst updatedMetadata =\n\t\tgetImageBlockMetadataFromAttachment( updatedAttachment );\n\tconst syncedAttributes = {};\n\n\tconst normalizedCurrentAlt = normalizeMetadataAttribute(\n\t\tcurrentAttributes.alt\n\t);\n\tif (\n\t\toriginalMetadata.alt !== updatedMetadata.alt &&\n\t\t( normalizedCurrentAlt === originalMetadata.alt ||\n\t\t\t! normalizedCurrentAlt )\n\t) {\n\t\tsyncedAttributes.alt = updatedMetadata.alt;\n\t}\n\n\tconst normalizedCurrentCaption = normalizeMetadataAttribute(\n\t\tcurrentAttributes.caption\n\t);\n\tif (\n\t\toriginalMetadata.caption !== undefined &&\n\t\tupdatedMetadata.caption !== undefined &&\n\t\toriginalMetadata.caption !== updatedMetadata.caption &&\n\t\t( normalizedCurrentCaption === originalMetadata.caption ||\n\t\t\t! normalizedCurrentCaption )\n\t) {\n\t\tsyncedAttributes.caption = updatedMetadata.caption || undefined;\n\t}\n\n\treturn syncedAttributes;\n}\n\nconst { openMediaEditorModalKey } = unlock( blockEditorPrivateApis );\n\nfunction getAttachmentFallbackForEmptyBlockMetadata( { alt, caption } ) {\n\tconst attachment = {};\n\n\tif ( ! alt ) {\n\t\tattachment.alt_text = '';\n\t}\n\n\tif ( ! caption?.toString() ) {\n\t\tattachment.caption = '';\n\t}\n\n\treturn Object.keys( attachment ).length ? attachment : undefined;\n}\n\nfunction hasKnownAttachmentMetadata( attachment ) {\n\tif ( ! attachment ) {\n\t\treturn false;\n\t}\n\n\tconst hasKnownAlt =\n\t\ttypeof attachment.alt_text === 'string' ||\n\t\ttypeof attachment.alt === 'string';\n\tconst hasKnownCaption =\n\t\tgetImageBlockMetadataFromAttachment( attachment ).caption !== undefined;\n\n\treturn hasKnownAlt && hasKnownCaption;\n}\n\nexport function useOpenImageMediaEditorModal( {\n\tattributes,\n\tsetAttributes,\n\tonClose,\n} ) {\n\t// Keep this hook private to the Image block and pass the block attributes\n\t// object so the callsite stays compact. Destructure only the attributes\n\t// currently used for metadata sync; add more here if the sync policy grows.\n\tconst { id, url, alt, caption } = attributes;\n\tconst registry = useRegistry();\n\tconst openMediaEditorModal = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings()[ openMediaEditorModalKey ],\n\t\t[]\n\t);\n\t// Track the block's current attachment and metadata in a ref so\n\t// handleMediaUpdate can read the latest values without being listed as\n\t// dependencies (which would recreate the callback and re-register the\n\t// onUpdate handler on every block change while the modal is open).\n\tconst blockAttributesRef = useRef( {\n\t\tid,\n\t\turl,\n\t\talt,\n\t\tcaption: caption?.toString(),\n\t} );\n\t// Snapshot of the attachment's metadata taken just before the modal opens,\n\t// used as the baseline for detecting what changed during the editing session.\n\tconst mediaEditorMetadataBaselineRef = useRef();\n\t// Incremented on every handleMediaUpdate call; stale async continuations\n\t// check against this to bail out if a newer update has since started.\n\tconst mediaEditorMetadataSyncRequestRef = useRef( 0 );\n\n\tuseEffect( () => {\n\t\tblockAttributesRef.current = {\n\t\t\tid,\n\t\t\turl,\n\t\t\talt,\n\t\t\tcaption: caption?.toString(),\n\t\t};\n\t}, [ alt, caption, id, url ] );\n\n\t// Reads the cached attachment record. The `attachment` postType entity\n\t// fetches with `context: 'edit'` by default, so `getEditedEntityRecord`\n\t// returns the edit-context record — carrying `caption` as `{ raw }` and a\n\t// usable `alt_text` — without us specifying a context. It is resolver-\n\t// backed, so on a cold cache this also kicks off the fetch and returns a\n\t// falsy value synchronously; that resolution shares its cache key with the\n\t// `resolveAttachmentRecord` call below (both keyed on the no-query\n\t// `getEntityRecord`), so the two dedupe into a single request.\n\tconst getCachedAttachmentRecord = useCallback(\n\t\t( attachmentId ) =>\n\t\t\tregistry\n\t\t\t\t.select( coreStore )\n\t\t\t\t.getEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tattachmentId\n\t\t\t\t),\n\t\t[ registry ]\n\t);\n\n\tconst resolveAttachmentRecord = useCallback(\n\t\tasync ( attachmentId ) => {\n\t\t\tconst resolveSelect = registry.resolveSelect( coreStore );\n\n\t\t\ttry {\n\t\t\t\treturn await resolveSelect.getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tattachmentId\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\t\t[ registry ]\n\t);\n\n\tconst resolveFreshAttachmentRecord = useCallback(\n\t\tasync ( attachmentId ) => {\n\t\t\t// Invalidate the cached resolution so resolveAttachmentRecord\n\t\t\t// re-fetches the server state that reflects the media editor's\n\t\t\t// saved changes.\n\t\t\tconst { invalidateResolution } = registry.dispatch( coreStore );\n\n\t\t\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tattachmentId,\n\t\t\t] );\n\t\t\treturn resolveAttachmentRecord( attachmentId );\n\t\t},\n\t\t[ registry, resolveAttachmentRecord ]\n\t);\n\n\tconst handleMediaUpdate = useCallback(\n\t\tasync ( { id: newId, url: newUrl } ) => {\n\t\t\tif ( typeof newId !== 'number' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Capture and clear the baseline so a rapid second save doesn't\n\t\t\t// reuse a stale snapshot.\n\t\t\tconst originalAttachment = mediaEditorMetadataBaselineRef.current;\n\t\t\tmediaEditorMetadataBaselineRef.current = undefined;\n\t\t\tconst syncRequest = ++mediaEditorMetadataSyncRequestRef.current;\n\t\t\tconst nextAttributes = {};\n\n\t\t\tconst currentBlockAttributes = blockAttributesRef.current;\n\n\t\t\tif ( newId !== currentBlockAttributes.id ) {\n\t\t\t\tnextAttributes.id = newId;\n\t\t\t\tnextAttributes.url = newUrl ?? currentBlockAttributes.url;\n\t\t\t\tblockAttributesRef.current = {\n\t\t\t\t\t...blockAttributesRef.current,\n\t\t\t\t\tid: nextAttributes.id,\n\t\t\t\t\turl: nextAttributes.url,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif ( originalAttachment ) {\n\t\t\t\t// Fetch fresh server state so the comparison reflects what\n\t\t\t\t// the media editor actually saved, not a potentially stale\n\t\t\t\t// cache.\n\t\t\t\tconst resolvedAttachment =\n\t\t\t\t\tawait resolveFreshAttachmentRecord( newId );\n\n\t\t\t\t// A newer update started while we were awaiting; discard\n\t\t\t\t// this one.\n\t\t\t\tif (\n\t\t\t\t\tsyncRequest !== mediaEditorMetadataSyncRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Sync alt text and caption back to the block only when\n\t\t\t\t// they were changed in the media editor. Fields the user\n\t\t\t\t// has independently customised on the block (i.e. values\n\t\t\t\t// that don't match the pre-session attachment metadata)\n\t\t\t\t// are left untouched.\n\t\t\t\tconst latestBlockAttributes = blockAttributesRef.current;\n\t\t\t\tconst resolvedMetadataAttributes =\n\t\t\t\t\tgetSyncedImageBlockAttributes(\n\t\t\t\t\t\tlatestBlockAttributes,\n\t\t\t\t\t\toriginalAttachment,\n\t\t\t\t\t\tresolvedAttachment\n\t\t\t\t\t);\n\n\t\t\t\tif ( Object.keys( resolvedMetadataAttributes ).length ) {\n\t\t\t\t\tObject.assign( nextAttributes, resolvedMetadataAttributes );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( Object.keys( nextAttributes ).length ) {\n\t\t\t\tblockAttributesRef.current = {\n\t\t\t\t\t...blockAttributesRef.current,\n\t\t\t\t\t...nextAttributes,\n\t\t\t\t};\n\t\t\t\tsetAttributes( nextAttributes );\n\t\t\t}\n\t\t},\n\t\t[ resolveFreshAttachmentRecord, setAttributes ]\n\t);\n\n\tconst openImageMediaEditorModal = useCallback( async () => {\n\t\tif ( ! id || ! openMediaEditorModal ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Snapshot the attachment's current metadata before the user makes\n\t\t// any changes so handleMediaUpdate can compare against it later. Use\n\t\t// the cached record when it's already present; only resolve when\n\t\t// nothing is cached yet, then fall back to a minimal object derived\n\t\t// from the block's own attributes.\n\t\tconst cachedAttachmentRecord = getCachedAttachmentRecord( id );\n\t\tconst fallbackAttachmentRecord =\n\t\t\tgetAttachmentFallbackForEmptyBlockMetadata(\n\t\t\t\tblockAttributesRef.current\n\t\t\t);\n\t\tconst resolvedAttachmentRecord = hasKnownAttachmentMetadata(\n\t\t\tcachedAttachmentRecord\n\t\t)\n\t\t\t? undefined\n\t\t\t: await resolveAttachmentRecord( id );\n\n\t\tmediaEditorMetadataBaselineRef.current =\n\t\t\tresolvedAttachmentRecord ||\n\t\t\t( hasKnownAttachmentMetadata( cachedAttachmentRecord )\n\t\t\t\t? cachedAttachmentRecord\n\t\t\t\t: fallbackAttachmentRecord ) ||\n\t\t\tcachedAttachmentRecord;\n\n\t\topenMediaEditorModal( {\n\t\t\tid,\n\t\t\tonUpdate: handleMediaUpdate,\n\t\t\tonClose,\n\t\t} );\n\t}, [\n\t\tgetCachedAttachmentRecord,\n\t\thandleMediaUpdate,\n\t\tid,\n\t\tonClose,\n\t\topenMediaEditorModal,\n\t\tresolveAttachmentRecord,\n\t] );\n\n\treturn id && openMediaEditorModal ? openImageMediaEditorModal : undefined;\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,SAAS,iBAAiB;AACnC;AAAA,EACC,eAAe;AAAA,EACf,SAAS;AAAA,OACH;AACP,SAAS,uBAAuB,iBAAiB;AACjD,SAAS,aAAa,iBAAiB;AACvC,SAAS,aAAa,WAAW,cAAc;AAK/C,SAAS,cAAc;AAEvB,SAAS,2BAA4B,SAAU;AAC9C,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO;AAAA,EACR;AAEA,QAAM,cAAc,UAAW,OAAQ,EAAE,KAAK;AAE9C,MAAK,CAAE,aAAc;AACpB,WAAO;AAAA,EACR;AAEA,SAAO,QAAQ,QAAS,OAAO,MAAO;AACvC;AAEA,SAAS,qBAAsB,YAAa;AAC3C,QAAM,UAAU,YAAY;AAE5B,MAAK,OAAO,YA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AE,8BAA8B,aAAc;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\nfunction normalizeImageBlockCaption( caption ) {\n\tif ( typeof caption !== 'string' ) {\n\t\treturn '';\n\t}\n\n\tconst textContent = stripHTML( caption ).trim();\n\n\tif ( ! textContent ) {\n\t\treturn '';\n\t}\n\n\treturn caption.replace( /\\n/g, '<br>' );\n}\n\nfunction getAttachmentCaption( attachment ) {\n\tconst caption = attachment?.caption;\n\n\tif ( typeof caption === 'string' ) {\n\t\treturn normalizeImageBlockCaption( caption );\n\t}\n\n\tif (\n\t\tcaption &&\n\t\ttypeof caption === 'object' &&\n\t\tObject.hasOwn( caption, 'raw' )\n\t) {\n\t\treturn normalizeImageBlockCaption( caption.raw );\n\t}\n\n\treturn undefined;\n}\n\nexport function getImageBlockMetadataFromAttachment( attachment ) {\n\treturn {\n\t\talt:\n\t\t\ttypeof attachment?.alt_text === 'string'\n\t\t\t\t? attachment.alt_text\n\t\t\t\t: attachment?.alt || '',\n\t\tcaption: getAttachmentCaption( attachment ),\n\t};\n}\n\nfunction normalizeMetadataAttribute( value ) {\n\treturn value || '';\n}\n\nexport function getSyncedImageBlockAttributes(\n\tcurrentAttributes,\n\toriginalAttachment,\n\tupdatedAttachment\n) {\n\tif ( ! originalAttachment || ! updatedAttachment ) {\n\t\treturn {};\n\t}\n\n\tconst originalMetadata =\n\t\tgetImageBlockMetadataFromAttachment( originalAttachment );\n\tconst updatedMetadata =\n\t\tgetImageBlockMetadataFromAttachment( updatedAttachment );\n\tconst syncedAttributes = {};\n\n\tconst normalizedCurrentAlt = normalizeMetadataAttribute(\n\t\tcurrentAttributes.alt\n\t);\n\tif (\n\t\toriginalMetadata.alt !== updatedMetadata.alt &&\n\t\t( normalizedCurrentAlt === originalMetadata.alt ||\n\t\t\t! normalizedCurrentAlt )\n\t) {\n\t\tsyncedAttributes.alt = updatedMetadata.alt;\n\t}\n\n\tconst normalizedCurrentCaption = normalizeMetadataAttribute(\n\t\tcurrentAttributes.caption\n\t);\n\tif (\n\t\toriginalMetadata.caption !== undefined &&\n\t\tupdatedMetadata.caption !== undefined &&\n\t\toriginalMetadata.caption !== updatedMetadata.caption &&\n\t\t( normalizedCurrentCaption === originalMetadata.caption ||\n\t\t\t! normalizedCurrentCaption )\n\t) {\n\t\tsyncedAttributes.caption = updatedMetadata.caption || undefined;\n\t}\n\n\treturn syncedAttributes;\n}\n\nconst { openMediaEditorModalKey } = unlock( blockEditorPrivateApis );\n\nfunction getAttachmentFallbackForEmptyBlockMetadata( { alt, caption } ) {\n\tconst attachment = {};\n\n\tif ( ! alt ) {\n\t\tattachment.alt_text = '';\n\t}\n\n\tif ( ! caption?.toString() ) {\n\t\tattachment.caption = '';\n\t}\n\n\treturn Object.keys( attachment ).length ? attachment : undefined;\n}\n\nfunction hasKnownAttachmentMetadata( attachment ) {\n\tif ( ! attachment ) {\n\t\treturn false;\n\t}\n\n\tconst hasKnownAlt =\n\t\ttypeof attachment.alt_text === 'string' ||\n\t\ttypeof attachment.alt === 'string';\n\tconst hasKnownCaption =\n\t\tgetImageBlockMetadataFromAttachment( attachment ).caption !== undefined;\n\n\treturn hasKnownAlt && hasKnownCaption;\n}\n\nexport function useOpenImageMediaEditorModal( {\n\tattributes,\n\tsetAttributes,\n\tonClose,\n\tonUrlChange,\n} ) {\n\t// Keep this hook private to the Image block and pass the block attributes\n\t// object so the callsite stays compact. Destructure only the attributes\n\t// currently used for metadata sync; add more here if the sync policy grows.\n\tconst { id, url, alt, caption } = attributes;\n\tconst registry = useRegistry();\n\tconst openMediaEditorModal = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings()[ openMediaEditorModalKey ],\n\t\t[]\n\t);\n\t// Track the block's current attachment and metadata in a ref so\n\t// handleMediaUpdate can read the latest values without being listed as\n\t// dependencies (which would recreate the callback and re-register the\n\t// onUpdate handler on every block change while the modal is open).\n\tconst blockAttributesRef = useRef( {\n\t\tid,\n\t\turl,\n\t\talt,\n\t\tcaption: caption?.toString(),\n\t} );\n\t// Snapshot of the attachment's metadata taken just before the modal opens,\n\t// used as the baseline for detecting what changed during the editing session.\n\tconst mediaEditorMetadataBaselineRef = useRef();\n\t// Incremented on every handleMediaUpdate call; stale async continuations\n\t// check against this to bail out if a newer update has since started.\n\tconst mediaEditorMetadataSyncRequestRef = useRef( 0 );\n\n\tuseEffect( () => {\n\t\tblockAttributesRef.current = {\n\t\t\tid,\n\t\t\turl,\n\t\t\talt,\n\t\t\tcaption: caption?.toString(),\n\t\t};\n\t}, [ alt, caption, id, url ] );\n\n\t// Reads the cached attachment record. The `attachment` postType entity\n\t// fetches with `context: 'edit'` by default, so `getEditedEntityRecord`\n\t// returns the edit-context record — carrying `caption` as `{ raw }` and a\n\t// usable `alt_text` — without us specifying a context. It is resolver-\n\t// backed, so on a cold cache this also kicks off the fetch and returns a\n\t// falsy value synchronously; that resolution shares its cache key with the\n\t// `resolveAttachmentRecord` call below (both keyed on the no-query\n\t// `getEntityRecord`), so the two dedupe into a single request.\n\tconst getCachedAttachmentRecord = useCallback(\n\t\t( attachmentId ) =>\n\t\t\tregistry\n\t\t\t\t.select( coreStore )\n\t\t\t\t.getEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tattachmentId\n\t\t\t\t),\n\t\t[ registry ]\n\t);\n\n\tconst resolveAttachmentRecord = useCallback(\n\t\tasync ( attachmentId ) => {\n\t\t\tconst resolveSelect = registry.resolveSelect( coreStore );\n\n\t\t\ttry {\n\t\t\t\treturn await resolveSelect.getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tattachmentId\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\t\t[ registry ]\n\t);\n\n\tconst resolveFreshAttachmentRecord = useCallback(\n\t\tasync ( attachmentId ) => {\n\t\t\t// Invalidate the cached resolution so resolveAttachmentRecord\n\t\t\t// re-fetches the server state that reflects the media editor's\n\t\t\t// saved changes.\n\t\t\tconst { invalidateResolution } = registry.dispatch( coreStore );\n\n\t\t\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tattachmentId,\n\t\t\t] );\n\t\t\treturn resolveAttachmentRecord( attachmentId );\n\t\t},\n\t\t[ registry, resolveAttachmentRecord ]\n\t);\n\n\tconst handleMediaUpdate = useCallback(\n\t\tasync ( { id: newId, url: newUrl } ) => {\n\t\t\tif ( typeof newId !== 'number' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Capture and clear the baseline so a rapid second save doesn't\n\t\t\t// reuse a stale snapshot.\n\t\t\tconst originalAttachment = mediaEditorMetadataBaselineRef.current;\n\t\t\tmediaEditorMetadataBaselineRef.current = undefined;\n\t\t\tconst syncRequest = ++mediaEditorMetadataSyncRequestRef.current;\n\t\t\tconst nextAttributes = {};\n\n\t\t\tconst currentBlockAttributes = blockAttributesRef.current;\n\n\t\t\tif ( newId !== currentBlockAttributes.id ) {\n\t\t\t\tnextAttributes.id = newId;\n\t\t\t\tnextAttributes.url = newUrl ?? currentBlockAttributes.url;\n\t\t\t\tif ( nextAttributes.url !== currentBlockAttributes.url ) {\n\t\t\t\t\t// The block is about to point at a freshly generated file\n\t\t\t\t\t// the browser hasn't loaded yet; let the caller show a\n\t\t\t\t\t// loading state until its <img> fires load/error.\n\t\t\t\t\tonUrlChange?.( nextAttributes.url );\n\t\t\t\t}\n\t\t\t\tblockAttributesRef.current = {\n\t\t\t\t\t...blockAttributesRef.current,\n\t\t\t\t\tid: nextAttributes.id,\n\t\t\t\t\turl: nextAttributes.url,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif ( originalAttachment ) {\n\t\t\t\t// Fetch fresh server state so the comparison reflects what\n\t\t\t\t// the media editor actually saved, not a potentially stale\n\t\t\t\t// cache.\n\t\t\t\tconst resolvedAttachment =\n\t\t\t\t\tawait resolveFreshAttachmentRecord( newId );\n\n\t\t\t\t// A newer update started while we were awaiting; discard\n\t\t\t\t// this one.\n\t\t\t\tif (\n\t\t\t\t\tsyncRequest !== mediaEditorMetadataSyncRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Sync alt text and caption back to the block only when\n\t\t\t\t// they were changed in the media editor. Fields the user\n\t\t\t\t// has independently customised on the block (i.e. values\n\t\t\t\t// that don't match the pre-session attachment metadata)\n\t\t\t\t// are left untouched.\n\t\t\t\tconst latestBlockAttributes = blockAttributesRef.current;\n\t\t\t\tconst resolvedMetadataAttributes =\n\t\t\t\t\tgetSyncedImageBlockAttributes(\n\t\t\t\t\t\tlatestBlockAttributes,\n\t\t\t\t\t\toriginalAttachment,\n\t\t\t\t\t\tresolvedAttachment\n\t\t\t\t\t);\n\n\t\t\t\tif ( Object.keys( resolvedMetadataAttributes ).length ) {\n\t\t\t\t\tObject.assign( nextAttributes, resolvedMetadataAttributes );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( Object.keys( nextAttributes ).length ) {\n\t\t\t\tblockAttributesRef.current = {\n\t\t\t\t\t...blockAttributesRef.current,\n\t\t\t\t\t...nextAttributes,\n\t\t\t\t};\n\t\t\t\tsetAttributes( nextAttributes );\n\t\t\t}\n\t\t},\n\t\t[ onUrlChange, resolveFreshAttachmentRecord, setAttributes ]\n\t);\n\n\tconst openImageMediaEditorModal = useCallback( async () => {\n\t\tif ( ! id || ! openMediaEditorModal ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Snapshot the attachment's current metadata before the user makes\n\t\t// any changes so handleMediaUpdate can compare against it later. Use\n\t\t// the cached record when it's already present; only resolve when\n\t\t// nothing is cached yet, then fall back to a minimal object derived\n\t\t// from the block's own attributes.\n\t\tconst cachedAttachmentRecord = getCachedAttachmentRecord( id );\n\t\tconst fallbackAttachmentRecord =\n\t\t\tgetAttachmentFallbackForEmptyBlockMetadata(\n\t\t\t\tblockAttributesRef.current\n\t\t\t);\n\t\tconst resolvedAttachmentRecord = hasKnownAttachmentMetadata(\n\t\t\tcachedAttachmentRecord\n\t\t)\n\t\t\t? undefined\n\t\t\t: await resolveAttachmentRecord( id );\n\n\t\tmediaEditorMetadataBaselineRef.current =\n\t\t\tresolvedAttachmentRecord ||\n\t\t\t( hasKnownAttachmentMetadata( cachedAttachmentRecord )\n\t\t\t\t? cachedAttachmentRecord\n\t\t\t\t: fallbackAttachmentRecord ) ||\n\t\t\tcachedAttachmentRecord;\n\n\t\topenMediaEditorModal( {\n\t\t\tid,\n\t\t\tonUpdate: handleMediaUpdate,\n\t\t\tonClose,\n\t\t} );\n\t}, [\n\t\tgetCachedAttachmentRecord,\n\t\thandleMediaUpdate,\n\t\tid,\n\t\tonClose,\n\t\topenMediaEditorModal,\n\t\tresolveAttachmentRecord,\n\t] );\n\n\treturn id && openMediaEditorModal ? openImageMediaEditorModal : undefined;\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,SAAS,iBAAiB;AACnC;AAAA,EACC,eAAe;AAAA,EACf,SAAS;AAAA,OACH;AACP,SAAS,uBAAuB,iBAAiB;AACjD,SAAS,aAAa,iBAAiB;AACvC,SAAS,aAAa,WAAW,cAAc;AAK/C,SAAS,cAAc;AAEvB,SAAS,2BAA4B,SAAU;AAC9C,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO;AAAA,EACR;AAEA,QAAM,cAAc,UAAW,OAAQ,EAAE,KAAK;AAE9C,MAAK,CAAE,aAAc;AACpB,WAAO;AAAA,EACR;AAEA,SAAO,QAAQ,QAAS,OAAO,M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,UAAK,OAAO,KAAM,cAAe,EAAE,QAAS;AAC3C,2BAAmB,UAAU;AAAA,UAC5B,GAAG,mBAAmB;AAAA,UACtB,GAAG;AAAA,QACJ;AACA,sBAAe,cAAe;AAAA,MAC/B;AAAA,IACD;AAAA,IACA,CAAE,aAAa,8BAA8B,aAAc;AAAA,EAC5D;AAEA,QAAM,4BAA4B,YAAa,YAAY;AAC1D,QAAK,CAAE,MAAM,CAAE,sBAAuB;AACrC;AAAA,IACD;AAOA,UAAM,yBAAyB,0BAA2B,EAAG;AAC7D,UAAM,2BACL;AAAA,MACC,mBAAmB;AAAA,IACpB;AACD,UAAM,2BAA2B;AAAA,MAChC;AAAA,IACD,IACG,SACA,MAAM,wBAAyB,EAAG;AAErC,mCAA+B,UAC9B,6BACE,2BAA4B,sBAAuB,IAClD,yBACA,6BACH;AAED,yBAAsB;AAAA,MACrB;AAAA,MACA,UAAU;AAAA,MACV;AAAA,IACD,CAAE;AAAA,EACH,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,SAAO,MAAM,uBAAuB,4BAA4B;AACjE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -11,7 +11,9 @@ function useIndentListItem(clientId) {
|
|
|
11
11
|
getSelectionStart,
|
|
12
12
|
getSelectionEnd,
|
|
13
13
|
hasMultiSelection,
|
|
14
|
-
getMultiSelectedBlockClientIds
|
|
14
|
+
getMultiSelectedBlockClientIds,
|
|
15
|
+
getBlockRootClientId,
|
|
16
|
+
getBlockAttributes
|
|
15
17
|
} = useSelect(blockEditorStore);
|
|
16
18
|
return useCallback(() => {
|
|
17
19
|
const _hasMultiSelection = hasMultiSelection();
|
|
@@ -21,8 +23,14 @@ function useIndentListItem(clientId) {
|
|
|
21
23
|
);
|
|
22
24
|
const previousSiblingId = getPreviousBlockClientId(clientId);
|
|
23
25
|
const newListItem = cloneBlock(getBlock(previousSiblingId));
|
|
26
|
+
const parentListId = getBlockRootClientId(clientId);
|
|
27
|
+
const parentListAttributes = getBlockAttributes(parentListId);
|
|
24
28
|
if (!newListItem.innerBlocks?.length) {
|
|
25
|
-
newListItem.innerBlocks = [
|
|
29
|
+
newListItem.innerBlocks = [
|
|
30
|
+
createBlock("core/list", {
|
|
31
|
+
ordered: parentListAttributes.ordered
|
|
32
|
+
})
|
|
33
|
+
];
|
|
26
34
|
}
|
|
27
35
|
newListItem.innerBlocks[newListItem.innerBlocks.length - 1].innerBlocks.push(...clonedBlocks);
|
|
28
36
|
const selectionStart = getSelectionStart();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/list-item/hooks/use-indent-list-item.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { createBlock, cloneBlock } from '@wordpress/blocks';\n\nexport default function useIndentListItem( clientId ) {\n\tconst { replaceBlocks, selectionChange, multiSelect } =\n\t\tuseDispatch( blockEditorStore );\n\tconst {\n\t\tgetBlock,\n\t\tgetPreviousBlockClientId,\n\t\tgetSelectionStart,\n\t\tgetSelectionEnd,\n\t\thasMultiSelection,\n\t\tgetMultiSelectedBlockClientIds,\n\t} = useSelect( blockEditorStore );\n\treturn useCallback( () => {\n\t\tconst _hasMultiSelection = hasMultiSelection();\n\t\tconst clientIds = _hasMultiSelection\n\t\t\t? getMultiSelectedBlockClientIds()\n\t\t\t: [ clientId ];\n\t\tconst clonedBlocks = clientIds.map( ( _clientId ) =>\n\t\t\tcloneBlock( getBlock( _clientId ) )\n\t\t);\n\t\tconst previousSiblingId = getPreviousBlockClientId( clientId );\n\t\tconst newListItem = cloneBlock( getBlock( previousSiblingId ) );\n\t\t// If the sibling has no innerBlocks, create a new `list` block.\n\t\tif ( ! newListItem.innerBlocks?.length ) {\n\t\t\tnewListItem.innerBlocks = [
|
|
5
|
-
"mappings": ";AAGA,SAAS,mBAAmB;AAC5B,SAAS,WAAW,mBAAmB;AACvC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,aAAa,kBAAkB;AAEzB,SAAR,kBAAoC,UAAW;AACrD,QAAM,EAAE,eAAe,iBAAiB,YAAY,IACnD,YAAa,gBAAiB;AAC/B,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI,UAAW,gBAAiB;AAChC,SAAO,YAAa,MAAM;AACzB,UAAM,qBAAqB,kBAAkB;AAC7C,UAAM,YAAY,qBACf,+BAA+B,IAC/B,CAAE,QAAS;AACd,UAAM,eAAe,UAAU;AAAA,MAAK,CAAE,cACrC,WAAY,SAAU,SAAU,CAAE;AAAA,IACnC;AACA,UAAM,oBAAoB,yBAA0B,QAAS;AAC7D,UAAM,cAAc,WAAY,SAAU,iBAAkB,CAAE;AAE9D,QAAK,CAAE,YAAY,aAAa,QAAS;AACxC,kBAAY,cAAc,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { createBlock, cloneBlock } from '@wordpress/blocks';\n\nexport default function useIndentListItem( clientId ) {\n\tconst { replaceBlocks, selectionChange, multiSelect } =\n\t\tuseDispatch( blockEditorStore );\n\tconst {\n\t\tgetBlock,\n\t\tgetPreviousBlockClientId,\n\t\tgetSelectionStart,\n\t\tgetSelectionEnd,\n\t\thasMultiSelection,\n\t\tgetMultiSelectedBlockClientIds,\n\t\tgetBlockRootClientId,\n\t\tgetBlockAttributes,\n\t} = useSelect( blockEditorStore );\n\treturn useCallback( () => {\n\t\tconst _hasMultiSelection = hasMultiSelection();\n\t\tconst clientIds = _hasMultiSelection\n\t\t\t? getMultiSelectedBlockClientIds()\n\t\t\t: [ clientId ];\n\t\tconst clonedBlocks = clientIds.map( ( _clientId ) =>\n\t\t\tcloneBlock( getBlock( _clientId ) )\n\t\t);\n\t\tconst previousSiblingId = getPreviousBlockClientId( clientId );\n\t\tconst newListItem = cloneBlock( getBlock( previousSiblingId ) );\n\t\t// Get the parent list's attributes to inherit the ordered property\n\t\tconst parentListId = getBlockRootClientId( clientId );\n\t\tconst parentListAttributes = getBlockAttributes( parentListId );\n\t\t// If the sibling has no innerBlocks, create a new `list` block.\n\t\tif ( ! newListItem.innerBlocks?.length ) {\n\t\t\tnewListItem.innerBlocks = [\n\t\t\t\tcreateBlock( 'core/list', {\n\t\t\t\t\tordered: parentListAttributes.ordered,\n\t\t\t\t} ),\n\t\t\t];\n\t\t}\n\t\t// A list item usually has one `list`, but it's possible to have\n\t\t// more. So we need to preserve the previous `list` blocks and\n\t\t// merge the new blocks to the last `list`.\n\t\tnewListItem.innerBlocks[\n\t\t\tnewListItem.innerBlocks.length - 1\n\t\t].innerBlocks.push( ...clonedBlocks );\n\n\t\t// We get the selection start/end here, because when\n\t\t// we replace blocks, the selection is updated too.\n\t\tconst selectionStart = getSelectionStart();\n\t\tconst selectionEnd = getSelectionEnd();\n\t\t// Replace the previous sibling of the block being indented and the indented blocks,\n\t\t// with a new block whose attributes are equal to the ones of the previous sibling and\n\t\t// whose descendants are the children of the previous sibling, followed by the indented blocks.\n\t\treplaceBlocks( [ previousSiblingId, ...clientIds ], [ newListItem ] );\n\t\tif ( ! _hasMultiSelection ) {\n\t\t\tselectionChange(\n\t\t\t\tclonedBlocks[ 0 ].clientId,\n\t\t\t\tselectionEnd.attributeKey,\n\t\t\t\tselectionEnd.clientId === selectionStart.clientId\n\t\t\t\t\t? selectionStart.offset\n\t\t\t\t\t: selectionEnd.offset,\n\t\t\t\tselectionEnd.offset\n\t\t\t);\n\t\t} else {\n\t\t\tmultiSelect(\n\t\t\t\tclonedBlocks[ 0 ].clientId,\n\t\t\t\tclonedBlocks[ clonedBlocks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AChB,aAAa;AAAA,MACd;AAAA,IACD,OAAO;AACN;AAAA,QACC,aAAc,CAAE,EAAE;AAAA,QAClB,aAAc,aAAa,SAAS,CAAE,EAAE;AAAA,MACzC;AAAA,IACD;AAEA,WAAO;AAAA,EACR,GAAG,CAAE,QAAS,CAAE;AACjB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
// packages/block-library/src/math/edit.js
|
|
2
|
-
import { __
|
|
2
|
+
import { __ } from "@wordpress/i18n";
|
|
3
3
|
import {
|
|
4
4
|
useBlockProps,
|
|
5
5
|
store as blockEditorStore
|
|
6
6
|
} from "@wordpress/block-editor";
|
|
7
7
|
import {
|
|
8
|
-
TextareaControl,
|
|
9
8
|
Popover,
|
|
10
|
-
__experimentalVStack as VStack,
|
|
11
9
|
privateApis as componentsPrivateApis
|
|
12
10
|
} from "@wordpress/components";
|
|
13
11
|
import { useState, useEffect, useRef } from "@wordpress/element";
|
|
14
12
|
import { useDispatch } from "@wordpress/data";
|
|
15
|
-
import { speak } from "@wordpress/a11y";
|
|
16
13
|
import { unlock } from "../lock-unlock.mjs";
|
|
17
|
-
import {
|
|
18
|
-
var {
|
|
14
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
var { ValidatedTextareaControl } = unlock(componentsPrivateApis);
|
|
19
16
|
function MathEdit({ attributes, setAttributes, isSelected }) {
|
|
20
17
|
const { latex, mathML } = attributes;
|
|
21
18
|
const [blockRef, setBlockRef] = useState();
|
|
22
19
|
const [error, setError] = useState(null);
|
|
23
20
|
const [latexToMathML, setLatexToMathML] = useState();
|
|
24
21
|
const initialLatex = useRef(latex);
|
|
22
|
+
const formRef = useRef();
|
|
25
23
|
const { __unstableMarkNextChangeAsNotPersistent } = useDispatch(blockEditorStore);
|
|
26
24
|
useEffect(() => {
|
|
27
25
|
import("@wordpress/latex-to-mathml").then((module) => {
|
|
@@ -59,63 +57,46 @@ function MathEdit({ attributes, setAttributes, isSelected }) {
|
|
|
59
57
|
offset: 8,
|
|
60
58
|
anchor: blockRef,
|
|
61
59
|
focusOnMount: false,
|
|
60
|
+
onFocusOutside: () => formRef.current?.reportValidity(),
|
|
62
61
|
__unstableSlotName: "__unstable-block-tools-after",
|
|
63
|
-
children: /* @__PURE__ */ jsx(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
className: "wp-block-math__textarea-control",
|
|
72
|
-
onChange: (newLatex) => {
|
|
73
|
-
if (!latexToMathML) {
|
|
74
|
-
setAttributes({ latex: newLatex });
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
let newMathML = "";
|
|
78
|
-
try {
|
|
79
|
-
newMathML = latexToMathML(newLatex, {
|
|
80
|
-
displayMode: true
|
|
81
|
-
});
|
|
82
|
-
setError(null);
|
|
83
|
-
} catch (err) {
|
|
84
|
-
setError(err.message);
|
|
85
|
-
speak(
|
|
86
|
-
sprintf(
|
|
87
|
-
/* translators: %s: error message returned when parsing LaTeX. */
|
|
88
|
-
__(
|
|
89
|
-
"Error parsing mathematical expression: %s"
|
|
90
|
-
),
|
|
91
|
-
err.message
|
|
92
|
-
)
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
setAttributes({
|
|
96
|
-
mathML: newMathML,
|
|
97
|
-
latex: newLatex
|
|
98
|
-
});
|
|
99
|
-
},
|
|
100
|
-
placeholder: __("e.g., x^2, \\frac{a}{b}")
|
|
101
|
-
}
|
|
102
|
-
),
|
|
103
|
-
error && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
104
|
-
/* @__PURE__ */ jsx(
|
|
105
|
-
WCBadge,
|
|
62
|
+
children: /* @__PURE__ */ jsx(
|
|
63
|
+
"form",
|
|
64
|
+
{
|
|
65
|
+
ref: formRef,
|
|
66
|
+
style: { padding: "4px", minWidth: "300px" },
|
|
67
|
+
onSubmit: (event) => event.preventDefault(),
|
|
68
|
+
children: /* @__PURE__ */ jsx(
|
|
69
|
+
ValidatedTextareaControl,
|
|
106
70
|
{
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
71
|
+
label: __("LaTeX math syntax"),
|
|
72
|
+
hideLabelFromVision: true,
|
|
73
|
+
value: latex,
|
|
74
|
+
className: "wp-block-math__textarea-control",
|
|
75
|
+
customValidity: error ? { type: "invalid", message: error } : void 0,
|
|
76
|
+
onChange: (newLatex) => {
|
|
77
|
+
if (!latexToMathML) {
|
|
78
|
+
setAttributes({ latex: newLatex });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
let newMathML = "";
|
|
82
|
+
try {
|
|
83
|
+
newMathML = latexToMathML(newLatex, {
|
|
84
|
+
displayMode: true
|
|
85
|
+
});
|
|
86
|
+
setError(null);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
setError(err.message);
|
|
89
|
+
}
|
|
90
|
+
setAttributes({
|
|
91
|
+
mathML: newMathML,
|
|
92
|
+
latex: newLatex
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
placeholder: __("e.g., x^2, \\frac{a}{b}")
|
|
114
96
|
}
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
] }) })
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
)
|
|
119
100
|
}
|
|
120
101
|
)
|
|
121
102
|
] });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/math/edit.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __
|
|
5
|
-
"mappings": ";AAGA,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tuseBlockProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport {\n\tPopover,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { useState, useEffect, useRef } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\n\nconst { ValidatedTextareaControl } = unlock( componentsPrivateApis );\n\nexport default function MathEdit( { attributes, setAttributes, isSelected } ) {\n\tconst { latex, mathML } = attributes;\n\tconst [ blockRef, setBlockRef ] = useState();\n\tconst [ error, setError ] = useState( null );\n\tconst [ latexToMathML, setLatexToMathML ] = useState();\n\tconst initialLatex = useRef( latex );\n\tconst formRef = useRef();\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\n\tuseEffect( () => {\n\t\timport( '@wordpress/latex-to-mathml' ).then( ( module ) => {\n\t\t\tsetLatexToMathML( () => module.default );\n\t\t\tif ( initialLatex.current ) {\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tmathML: module.default( initialLatex.current, {\n\t\t\t\t\t\tdisplayMode: true,\n\t\t\t\t\t} ),\n\t\t\t\t} );\n\t\t\t}\n\t\t} );\n\t}, [\n\t\tinitialLatex,\n\t\tsetAttributes,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t] );\n\n\tconst blockProps = useBlockProps( {\n\t\tref: setBlockRef,\n\t\tposition: 'relative',\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ mathML ? (\n\t\t\t\t<math\n\t\t\t\t\t// We can't spread block props on the math element because\n\t\t\t\t\t// it only supports a limited amount of global attributes.\n\t\t\t\t\t// For example, draggable will have no effect.\n\t\t\t\t\tdisplay=\"block\"\n\t\t\t\t\tdangerouslySetInnerHTML={ { __html: mathML } }\n\t\t\t\t/>\n\t\t\t) : (\n\t\t\t\t'\\u200B'\n\t\t\t) }\n\t\t\t{ isSelected && (\n\t\t\t\t<Popover\n\t\t\t\t\tplacement=\"bottom-start\"\n\t\t\t\t\toffset={ 8 }\n\t\t\t\t\tanchor={ blockRef }\n\t\t\t\t\tfocusOnMount={ false }\n\t\t\t\t\t// Surface any parsing error before focus leaves the block.\n\t\t\t\t\t// An invalid field is refocused, keeping the popover open.\n\t\t\t\t\tonFocusOutside={ () => formRef.current?.reportValidity() }\n\t\t\t\t\t__unstableSlotName=\"__unstable-block-tools-after\"\n\t\t\t\t>\n\t\t\t\t\t<form\n\t\t\t\t\t\tref={ formRef }\n\t\t\t\t\t\tstyle={ { padding: '4px', minWidth: '300px' } }\n\t\t\t\t\t\tonSubmit={ ( event ) => event.preventDefault() }\n\t\t\t\t\t>\n\t\t\t\t\t\t<ValidatedTextareaControl\n\t\t\t\t\t\t\tlabel={ __( 'LaTeX math syntax' ) }\n\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\tvalue={ latex }\n\t\t\t\t\t\t\tclassName=\"wp-block-math__textarea-control\"\n\t\t\t\t\t\t\tcustomValidity={\n\t\t\t\t\t\t\t\terror\n\t\t\t\t\t\t\t\t\t? { type: 'invalid', message: error }\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonChange={ ( newLatex ) => {\n\t\t\t\t\t\t\t\tif ( ! latexToMathML ) {\n\t\t\t\t\t\t\t\t\tsetAttributes( { latex: newLatex } );\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tlet newMathML = '';\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tnewMathML = latexToMathML( newLatex, {\n\t\t\t\t\t\t\t\t\t\tdisplayMode: true,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\tsetError( null );\n\t\t\t\t\t\t\t\t} catch ( err ) {\n\t\t\t\t\t\t\t\t\tsetError( err.message );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tmathML: new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mentControl,
|
|
431
431
|
{
|
|
432
432
|
onChange: onVerticalAlignmentChange,
|
|
433
|
-
value: verticalAlignment
|
|
433
|
+
value: verticalAlignment,
|
|
434
|
+
label: __("Align media and text vertically")
|
|
434
435
|
}
|
|
435
436
|
),
|
|
436
437
|
/* @__PURE__ */ jsx(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/media-text/edit.js"],
|
|
4
|
-
"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 { useState, useRef } from '@wordpress/element';\nimport {\n\tBlockControls,\n\tBlockVerticalAlignmentControl,\n\tuseInnerBlocksProps,\n\tInspectorControls,\n\tuseBlockProps,\n\t__experimentalImageURLInputUI as ImageURLInputUI,\n\tstore as blockEditorStore,\n\tuseBlockEditingMode,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport {\n\tRangeControl,\n\tTextareaControl,\n\tToggleControl,\n\tToolbarButton,\n\tExternalLink,\n\tFocalPointPicker,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { isBlobURL, getBlobTypeByURL } from '@wordpress/blob';\nimport { pullLeft, pullRight } from '@wordpress/icons';\nimport { useEntityProp, store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport MediaContainer from './media-container';\nimport {\n\tDEFAULT_MEDIA_SIZE_SLUG,\n\tWIDTH_CONSTRAINT_PERCENTAGE,\n\tLINK_DESTINATION_NONE,\n\tLINK_DESTINATION_MEDIA,\n\tLINK_DESTINATION_ATTACHMENT,\n\tTEMPLATE,\n} from './constants';\nimport { unlock } from '../lock-unlock';\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nconst { ResolutionTool } = unlock( blockEditorPrivateApis );\n\n// this limits the resize to a safe zone to avoid making broken layouts\nconst applyWidthConstraints = ( width ) =>\n\tMath.max(\n\t\tWIDTH_CONSTRAINT_PERCENTAGE,\n\t\tMath.min( width, 100 - WIDTH_CONSTRAINT_PERCENTAGE )\n\t);\n\nfunction getImageSourceUrlBySizeSlug( image, slug ) {\n\treturn image?.media_details?.sizes?.[ slug ]?.source_url;\n}\n\nfunction attributesFromMedia( {\n\tattributes: { linkDestination, href },\n\tsetAttributes,\n} ) {\n\treturn ( media ) => {\n\t\tif ( ! media || ! media.url ) {\n\t\t\tsetAttributes( {\n\t\t\t\tmediaAlt: undefined,\n\t\t\t\tmediaId: undefined,\n\t\t\t\tmediaType: undefined,\n\t\t\t\tmediaUrl: undefined,\n\t\t\t\tmediaLink: undefined,\n\t\t\t\thref: undefined,\n\t\t\t\tfocalPoint: undefined,\n\t\t\t\tuseFeaturedImage: false,\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isBlobURL( media.url ) ) {\n\t\t\tmedia.type = getBlobTypeByURL( media.url );\n\t\t}\n\n\t\tlet mediaType;\n\t\tlet src;\n\t\t// For media selections originated from a file upload.\n\t\tif ( media.media_type ) {\n\t\t\tif ( media.media_type === 'image' ) {\n\t\t\t\tmediaType = 'image';\n\t\t\t} else {\n\t\t\t\t// only images and videos are accepted so if the media_type is not an image we can assume it is a video.\n\t\t\t\t// video contain the media type of 'file' in the object returned from the rest api.\n\t\t\t\tmediaType = 'video';\n\t\t\t}\n\t\t} else {\n\t\t\t// For media selections originated from existing files in the media library.\n\t\t\tmediaType = media.type;\n\t\t}\n\n\t\tif ( mediaType === 'image' ) {\n\t\t\t// Try the \"large\" size URL, falling back to the \"full\" size URL below.\n\t\t\tsrc =\n\t\t\t\tmedia.sizes?.large?.url ||\n\t\t\t\tmedia.media_details?.sizes?.large?.source_url;\n\t\t}\n\n\t\tlet newLinkDestination = linkDestination;\n\t\tlet newHref = href;\n\n\t\t// Only apply default link behavior for images (not videos).\n\t\tif ( mediaType === 'image' ) {\n\t\t\t// Check if default link setting should be used.\n\t\t\tif ( ! newLinkDestination ) {\n\t\t\t\t// Use the WordPress option to determine the proper default.\n\t\t\t\t// The constants used in Gutenberg do not match WP options so a little more complicated than ideal.\n\t\t\t\tswitch (\n\t\t\t\t\twindow?.wp?.media?.view?.settings?.defaultProps?.link ||\n\t\t\t\t\tLINK_DESTINATION_NONE\n\t\t\t\t) {\n\t\t\t\t\tcase 'file':\n\t\t\t\t\tcase LINK_DESTINATION_MEDIA:\n\t\t\t\t\t\tnewLinkDestination = LINK_DESTINATION_MEDIA;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'post':\n\t\t\t\t\tcase LINK_DESTINATION_ATTACHMENT:\n\t\t\t\t\t\tnewLinkDestination = LINK_DESTINATION_ATTACHMENT;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase LINK_DESTINATION_NONE:\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tnewLinkDestination = LINK_DESTINATION_NONE;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Set href based on linkDestination.\n\t\t\tswitch ( newLinkDestination ) {\n\t\t\t\tcase LINK_DESTINATION_MEDIA:\n\t\t\t\t\tnewHref = media.url;\n\t\t\t\t\tbreak;\n\t\t\t\tcase LINK_DESTINATION_ATTACHMENT:\n\t\t\t\t\tnewHref = media.link;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tsetAttributes( {\n\t\t\tmediaAlt: media.alt,\n\t\t\tmediaId: media.id,\n\t\t\tmediaType,\n\t\t\tmediaUrl: src || media.url,\n\t\t\tmediaLink: media.link || undefined,\n\t\t\thref: newHref,\n\t\t\tlinkDestination: newLinkDestination,\n\t\t\tfocalPoint: undefined,\n\t\t\tuseFeaturedImage: false,\n\t\t} );\n\t};\n}\n\nfunction MediaTextResolutionTool( { image, value, onChange } ) {\n\tconst { imageSizes } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn {\n\t\t\timageSizes: getSettings().imageSizes,\n\t\t};\n\t}, [] );\n\n\tif ( ! imageSizes?.length ) {\n\t\treturn null;\n\t}\n\n\tconst imageSizeOptions = imageSizes\n\t\t.filter( ( { slug } ) => getImageSourceUrlBySizeSlug( image, slug ) )\n\t\t.map( ( { name, slug } ) => ( { value: slug, label: name } ) );\n\n\treturn (\n\t\t<ResolutionTool\n\t\t\tvalue={ value }\n\t\t\tdefaultValue={ DEFAULT_MEDIA_SIZE_SLUG }\n\t\t\toptions={ imageSizeOptions }\n\t\t\tonChange={ onChange }\n\t\t/>\n\t);\n}\n\nfunction MediaTextEdit( {\n\tattributes,\n\tisSelected,\n\tsetAttributes,\n\tcontext: { postId, postType },\n} ) {\n\tconst {\n\t\tfocalPoint,\n\t\thref,\n\t\timageFill,\n\t\tisStackedOnMobile,\n\t\tlinkClass,\n\t\tlinkDestination,\n\t\tlinkTarget,\n\t\tmediaAlt,\n\t\tmediaId,\n\t\tmediaPosition,\n\t\tmediaType,\n\t\tmediaUrl,\n\t\tmediaWidth,\n\t\tmediaSizeSlug,\n\t\trel,\n\t\tverticalAlignment,\n\t\tallowedBlocks,\n\t\tuseFeaturedImage,\n\t} = attributes;\n\n\tconst [ featuredImage ] = useEntityProp(\n\t\t'postType',\n\t\tpostType,\n\t\t'featured_media',\n\t\tpostId\n\t);\n\n\tconst { featuredImageMedia } = useSelect(\n\t\t( select ) => {\n\t\t\treturn {\n\t\t\t\tfeaturedImageMedia:\n\t\t\t\t\tfeaturedImage && useFeaturedImage\n\t\t\t\t\t\t? select( coreStore ).getEntityRecord(\n\t\t\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\t\t\tfeaturedImage,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: undefined,\n\t\t\t};\n\t\t},\n\t\t[ featuredImage, useFeaturedImage ]\n\t);\n\n\tconst { image } = useSelect(\n\t\t( select ) => {\n\t\t\treturn {\n\t\t\t\timage:\n\t\t\t\t\tmediaId && isSelected\n\t\t\t\t\t\t? select( coreStore ).getEntityRecord(\n\t\t\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\t\t\tmediaId,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: null,\n\t\t\t};\n\t\t},\n\t\t[ isSelected, mediaId ]\n\t);\n\n\tconst featuredImageURL = useFeaturedImage\n\t\t? featuredImageMedia?.source_url\n\t\t: '';\n\tconst featuredImageAlt = useFeaturedImage\n\t\t? featuredImageMedia?.alt_text\n\t\t: '';\n\n\tconst toggleUseFeaturedImage = () => {\n\t\tsetAttributes( {\n\t\t\timageFill: false,\n\t\t\tmediaType: 'image',\n\t\t\tmediaId: undefined,\n\t\t\tmediaUrl: undefined,\n\t\t\tmediaAlt: undefined,\n\t\t\tmediaLink: undefined,\n\t\t\tlinkDestination: undefined,\n\t\t\tlinkTarget: undefined,\n\t\t\tlinkClass: undefined,\n\t\t\trel: undefined,\n\t\t\thref: undefined,\n\t\t\tuseFeaturedImage: ! useFeaturedImage,\n\t\t} );\n\t};\n\n\tconst refMedia = useRef();\n\tconst imperativeFocalPointPreview = ( value ) => {\n\t\tconst { style } = refMedia.current;\n\t\tconst { x, y } = value;\n\t\tstyle.objectPosition = `${ x * 100 }% ${ y * 100 }%`;\n\t};\n\n\tconst [ temporaryMediaWidth, setTemporaryMediaWidth ] = useState( null );\n\n\tconst onSelectMedia = attributesFromMedia( { attributes, setAttributes } );\n\n\tconst onSetHref = ( props ) => {\n\t\tsetAttributes( props );\n\t};\n\n\tconst onWidthChange = ( width ) => {\n\t\tsetTemporaryMediaWidth( applyWidthConstraints( width ) );\n\t};\n\tconst commitWidthChange = ( width ) => {\n\t\tsetAttributes( {\n\t\t\tmediaWidth: applyWidthConstraints( width ),\n\t\t} );\n\t\tsetTemporaryMediaWidth( null );\n\t};\n\n\tconst classNames = clsx( {\n\t\t'has-media-on-the-right': 'right' === mediaPosition,\n\t\t'is-selected': isSelected,\n\t\t'is-stacked-on-mobile': isStackedOnMobile,\n\t\t[ `is-vertically-aligned-${ verticalAlignment }` ]: verticalAlignment,\n\t\t'is-image-fill-element': imageFill,\n\t} );\n\tconst widthString = `${ temporaryMediaWidth || mediaWidth }%`;\n\tconst gridTemplateColumns =\n\t\t'right' === mediaPosition\n\t\t\t? `1fr ${ widthString }`\n\t\t\t: `${ widthString } 1fr`;\n\tconst style = {\n\t\tgridTemplateColumns,\n\t\tmsGridColumns: gridTemplateColumns,\n\t};\n\tconst onMediaAltChange = ( newMediaAlt ) => {\n\t\tsetAttributes( { mediaAlt: newMediaAlt } );\n\t};\n\tconst onVerticalAlignmentChange = ( alignment ) => {\n\t\tsetAttributes( { verticalAlignment: alignment } );\n\t};\n\tconst updateImage = ( newMediaSizeSlug ) => {\n\t\tconst newUrl = getImageSourceUrlBySizeSlug( image, newMediaSizeSlug );\n\n\t\tif ( ! newUrl ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tsetAttributes( {\n\t\t\tmediaUrl: newUrl,\n\t\t\tmediaSizeSlug: newMediaSizeSlug,\n\t\t} );\n\t};\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\tconst mediaTextGeneralSettings = (\n\t\t<ToolsPanel\n\t\t\tlabel={ __( 'Settings' ) }\n\t\t\tresetAll={ () => {\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tisStackedOnMobile: true,\n\t\t\t\t\timageFill: false,\n\t\t\t\t\tmediaAlt: '',\n\t\t\t\t\tfocalPoint: undefined,\n\t\t\t\t\tmediaWidth: 50,\n\t\t\t\t} );\n\t\t\t\tupdateImage( DEFAULT_MEDIA_SIZE_SLUG );\n\t\t\t} }\n\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t>\n\t\t\t<ToolsPanelItem\n\t\t\t\tlabel={ __( 'Media width' ) }\n\t\t\t\tisShownByDefault\n\t\t\t\thasValue={ () => mediaWidth !== 50 }\n\t\t\t\tonDeselect={ () => setAttributes( { mediaWidth: 50 } ) }\n\t\t\t>\n\t\t\t\t<RangeControl\n\t\t\t\t\tlabel={ __( 'Media width' ) }\n\t\t\t\t\tvalue={ temporaryMediaWidth || mediaWidth }\n\t\t\t\t\tonChange={ commitWidthChange }\n\t\t\t\t\tmin={ WIDTH_CONSTRAINT_PERCENTAGE }\n\t\t\t\t\tmax={ 100 - WIDTH_CONSTRAINT_PERCENTAGE }\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\t\t\t<ToolsPanelItem\n\t\t\t\tlabel={ __( 'Stack on mobile' ) }\n\t\t\t\tisShownByDefault\n\t\t\t\thasValue={ () => ! isStackedOnMobile }\n\t\t\t\tonDeselect={ () =>\n\t\t\t\t\tsetAttributes( { isStackedOnMobile: true } )\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t<ToggleControl\n\t\t\t\t\tlabel={ __( 'Stack on mobile' ) }\n\t\t\t\t\tchecked={ isStackedOnMobile }\n\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\tisStackedOnMobile: ! isStackedOnMobile,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\t\t\t{ mediaType === 'image' && (\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\tlabel={ __( 'Crop image to fill' ) }\n\t\t\t\t\tisShownByDefault\n\t\t\t\t\thasValue={ () => !! imageFill }\n\t\t\t\t\tonDeselect={ () => setAttributes( { imageFill: false } ) }\n\t\t\t\t>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Crop image to fill' ) }\n\t\t\t\t\t\tchecked={ !! imageFill }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\timageFill: ! imageFill,\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</ToolsPanelItem>\n\t\t\t) }\n\t\t\t{ imageFill &&\n\t\t\t\t( mediaUrl || featuredImageURL ) &&\n\t\t\t\tmediaType === 'image' && (\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\tlabel={ __( 'Focal point' ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\thasValue={ () => !! focalPoint }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( { focalPoint: undefined } )\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t<FocalPointPicker\n\t\t\t\t\t\t\tlabel={ __( 'Focal point' ) }\n\t\t\t\t\t\t\turl={\n\t\t\t\t\t\t\t\tuseFeaturedImage && featuredImageURL\n\t\t\t\t\t\t\t\t\t? featuredImageURL\n\t\t\t\t\t\t\t\t\t: mediaUrl\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tvalue={ focalPoint }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { focalPoint: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonDragStart={ imperativeFocalPointPreview }\n\t\t\t\t\t\t\tonDrag={ imperativeFocalPointPreview }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t) }\n\t\t\t{ mediaType === 'image' && mediaUrl && ! useFeaturedImage && (\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\tlabel={ __( 'Alternative text' ) }\n\t\t\t\t\tisShownByDefault\n\t\t\t\t\thasValue={ () => !! mediaAlt }\n\t\t\t\t\tonDeselect={ () => setAttributes( { mediaAlt: '' } ) }\n\t\t\t\t>\n\t\t\t\t\t<TextareaControl\n\t\t\t\t\t\tlabel={ __( 'Alternative text' ) }\n\t\t\t\t\t\tvalue={ mediaAlt }\n\t\t\t\t\t\tonChange={ onMediaAltChange }\n\t\t\t\t\t\thelp={\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\t\t\thref={\n\t\t\t\t\t\t\t\t\t\t// translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations.\n\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t'https://www.w3.org/WAI/tutorials/images/decision-tree/'\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>\n\t\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t\t'Describe the purpose of the image.'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t\t\t\t<br />\n\t\t\t\t\t\t\t\t{ __( 'Leave empty if decorative.' ) }\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</ToolsPanelItem>\n\t\t\t) }\n\t\t\t{ mediaType === 'image' && ! useFeaturedImage && (\n\t\t\t\t<MediaTextResolutionTool\n\t\t\t\t\timage={ image }\n\t\t\t\t\tvalue={ mediaSizeSlug }\n\t\t\t\t\tonChange={ updateImage }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</ToolsPanel>\n\t);\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classNames,\n\t\tstyle,\n\t} );\n\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{ className: 'wp-block-media-text__content' },\n\t\t{ template: TEMPLATE, allowedBlocks }\n\t);\n\n\tconst blockEditingMode = useBlockEditingMode();\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>{ mediaTextGeneralSettings }</InspectorControls>\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t{ blockEditingMode === 'default' && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<BlockVerticalAlignmentControl\n\t\t\t\t\t\t\tonChange={ onVerticalAlignmentChange }\n\t\t\t\t\t\t\tvalue={ verticalAlignment }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\ticon={ pullLeft }\n\t\t\t\t\t\t\ttitle={ __( 'Show media on left' ) }\n\t\t\t\t\t\t\tisActive={ mediaPosition === 'left' }\n\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( { mediaPosition: 'left' } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\ticon={ pullRight }\n\t\t\t\t\t\t\ttitle={ __( 'Show media on right' ) }\n\t\t\t\t\t\t\tisActive={ mediaPosition === 'right' }\n\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( { mediaPosition: 'right' } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\n\t\t\t\t{ mediaType === 'image' && ! useFeaturedImage && (\n\t\t\t\t\t<ImageURLInputUI\n\t\t\t\t\t\turl={ href || '' }\n\t\t\t\t\t\tonChangeUrl={ onSetHref }\n\t\t\t\t\t\tlinkDestination={ linkDestination }\n\t\t\t\t\t\tmediaType={ mediaType }\n\t\t\t\t\t\tmediaUrl={ image && image.source_url }\n\t\t\t\t\t\tmediaLink={ image && image.link }\n\t\t\t\t\t\tlinkTarget={ linkTarget }\n\t\t\t\t\t\tlinkClass={ linkClass }\n\t\t\t\t\t\trel={ rel }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</BlockControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ mediaPosition === 'right' && <div { ...innerBlocksProps } /> }\n\t\t\t\t<MediaContainer\n\t\t\t\t\tclassName=\"wp-block-media-text__media\"\n\t\t\t\t\tonSelectMedia={ onSelectMedia }\n\t\t\t\t\tonWidthChange={ onWidthChange }\n\t\t\t\t\tcommitWidthChange={ commitWidthChange }\n\t\t\t\t\trefMedia={ refMedia }\n\t\t\t\t\tenableResize={ blockEditingMode === 'default' }\n\t\t\t\t\ttoggleUseFeaturedImage={ toggleUseFeaturedImage }\n\t\t\t\t\t{ ...{\n\t\t\t\t\t\tfocalPoint,\n\t\t\t\t\t\timageFill,\n\t\t\t\t\t\tisSelected,\n\t\t\t\t\t\tisStackedOnMobile,\n\t\t\t\t\t\tmediaAlt,\n\t\t\t\t\t\tmediaId,\n\t\t\t\t\t\tmediaPosition,\n\t\t\t\t\t\tmediaType,\n\t\t\t\t\t\tmediaUrl,\n\t\t\t\t\t\tmediaWidth,\n\t\t\t\t\t\tuseFeaturedImage,\n\t\t\t\t\t\tfeaturedImageURL,\n\t\t\t\t\t\tfeaturedImageAlt,\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t\t{ mediaPosition !== 'right' && <div { ...innerBlocksProps } /> }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default MediaTextEdit;\n"],
|
|
5
|
-
"mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,UAAU;AACnB,SAAS,iBAAiB;AAC1B,SAAS,UAAU,cAAc;AACjC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,iCAAiC;AAAA,EACjC,SAAS;AAAA,EACT;AAAA,EACA,eAAe;AAAA,OACT;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,4BAA4B;AAAA,EAC5B,gCAAgC;AAAA,OAC1B;AACP,SAAS,WAAW,wBAAwB;AAC5C,SAAS,UAAU,iBAAiB;AACpC,SAAS,eAAe,SAAS,iBAAiB;AAKlD,OAAO,oBAAoB;AAC3B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;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ACA,OAAQ;AAAA,YACR,UAAW;AAAA;AAAA,QACZ;AAAA;AAAA;AAAA,EAEF;AAGD,QAAM,aAAa,cAAe;AAAA,IACjC,WAAW;AAAA,IACX;AAAA,EACD,CAAE;AAEF,QAAM,mBAAmB;AAAA,IACxB,EAAE,WAAW,+BAA+B;AAAA,IAC5C,EAAE,UAAU,UAAU,cAAc;AAAA,EACrC;AAEA,QAAM,mBAAmB,oBAAoB;AAE7C,SACC,iCACC;AAAA,wBAAC,qBAAoB,oCAA0B;AAAA,IAC/C,qBAAC,iBAAc,OAAM,SAClB;AAAA,2BAAqB,aACtB,iCACC;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,UAAW;AAAA,YACX,OAAQ;AAAA;AAAA,
|
|
4
|
+
"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 { useState, useRef } from '@wordpress/element';\nimport {\n\tBlockControls,\n\tBlockVerticalAlignmentControl,\n\tuseInnerBlocksProps,\n\tInspectorControls,\n\tuseBlockProps,\n\t__experimentalImageURLInputUI as ImageURLInputUI,\n\tstore as blockEditorStore,\n\tuseBlockEditingMode,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport {\n\tRangeControl,\n\tTextareaControl,\n\tToggleControl,\n\tToolbarButton,\n\tExternalLink,\n\tFocalPointPicker,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { isBlobURL, getBlobTypeByURL } from '@wordpress/blob';\nimport { pullLeft, pullRight } from '@wordpress/icons';\nimport { useEntityProp, store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport MediaContainer from './media-container';\nimport {\n\tDEFAULT_MEDIA_SIZE_SLUG,\n\tWIDTH_CONSTRAINT_PERCENTAGE,\n\tLINK_DESTINATION_NONE,\n\tLINK_DESTINATION_MEDIA,\n\tLINK_DESTINATION_ATTACHMENT,\n\tTEMPLATE,\n} from './constants';\nimport { unlock } from '../lock-unlock';\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nconst { ResolutionTool } = unlock( blockEditorPrivateApis );\n\n// this limits the resize to a safe zone to avoid making broken layouts\nconst applyWidthConstraints = ( width ) =>\n\tMath.max(\n\t\tWIDTH_CONSTRAINT_PERCENTAGE,\n\t\tMath.min( width, 100 - WIDTH_CONSTRAINT_PERCENTAGE )\n\t);\n\nfunction getImageSourceUrlBySizeSlug( image, slug ) {\n\treturn image?.media_details?.sizes?.[ slug ]?.source_url;\n}\n\nfunction attributesFromMedia( {\n\tattributes: { linkDestination, href },\n\tsetAttributes,\n} ) {\n\treturn ( media ) => {\n\t\tif ( ! media || ! media.url ) {\n\t\t\tsetAttributes( {\n\t\t\t\tmediaAlt: undefined,\n\t\t\t\tmediaId: undefined,\n\t\t\t\tmediaType: undefined,\n\t\t\t\tmediaUrl: undefined,\n\t\t\t\tmediaLink: undefined,\n\t\t\t\thref: undefined,\n\t\t\t\tfocalPoint: undefined,\n\t\t\t\tuseFeaturedImage: false,\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isBlobURL( media.url ) ) {\n\t\t\tmedia.type = getBlobTypeByURL( media.url );\n\t\t}\n\n\t\tlet mediaType;\n\t\tlet src;\n\t\t// For media selections originated from a file upload.\n\t\tif ( media.media_type ) {\n\t\t\tif ( media.media_type === 'image' ) {\n\t\t\t\tmediaType = 'image';\n\t\t\t} else {\n\t\t\t\t// only images and videos are accepted so if the media_type is not an image we can assume it is a video.\n\t\t\t\t// video contain the media type of 'file' in the object returned from the rest api.\n\t\t\t\tmediaType = 'video';\n\t\t\t}\n\t\t} else {\n\t\t\t// For media selections originated from existing files in the media library.\n\t\t\tmediaType = media.type;\n\t\t}\n\n\t\tif ( mediaType === 'image' ) {\n\t\t\t// Try the \"large\" size URL, falling back to the \"full\" size URL below.\n\t\t\tsrc =\n\t\t\t\tmedia.sizes?.large?.url ||\n\t\t\t\tmedia.media_details?.sizes?.large?.source_url;\n\t\t}\n\n\t\tlet newLinkDestination = linkDestination;\n\t\tlet newHref = href;\n\n\t\t// Only apply default link behavior for images (not videos).\n\t\tif ( mediaType === 'image' ) {\n\t\t\t// Check if default link setting should be used.\n\t\t\tif ( ! newLinkDestination ) {\n\t\t\t\t// Use the WordPress option to determine the proper default.\n\t\t\t\t// The constants used in Gutenberg do not match WP options so a little more complicated than ideal.\n\t\t\t\tswitch (\n\t\t\t\t\twindow?.wp?.media?.view?.settings?.defaultProps?.link ||\n\t\t\t\t\tLINK_DESTINATION_NONE\n\t\t\t\t) {\n\t\t\t\t\tcase 'file':\n\t\t\t\t\tcase LINK_DESTINATION_MEDIA:\n\t\t\t\t\t\tnewLinkDestination = LINK_DESTINATION_MEDIA;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'post':\n\t\t\t\t\tcase LINK_DESTINATION_ATTACHMENT:\n\t\t\t\t\t\tnewLinkDestination = LINK_DESTINATION_ATTACHMENT;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase LINK_DESTINATION_NONE:\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tnewLinkDestination = LINK_DESTINATION_NONE;\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Set href based on linkDestination.\n\t\t\tswitch ( newLinkDestination ) {\n\t\t\t\tcase LINK_DESTINATION_MEDIA:\n\t\t\t\t\tnewHref = media.url;\n\t\t\t\t\tbreak;\n\t\t\t\tcase LINK_DESTINATION_ATTACHMENT:\n\t\t\t\t\tnewHref = media.link;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tsetAttributes( {\n\t\t\tmediaAlt: media.alt,\n\t\t\tmediaId: media.id,\n\t\t\tmediaType,\n\t\t\tmediaUrl: src || media.url,\n\t\t\tmediaLink: media.link || undefined,\n\t\t\thref: newHref,\n\t\t\tlinkDestination: newLinkDestination,\n\t\t\tfocalPoint: undefined,\n\t\t\tuseFeaturedImage: false,\n\t\t} );\n\t};\n}\n\nfunction MediaTextResolutionTool( { image, value, onChange } ) {\n\tconst { imageSizes } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn {\n\t\t\timageSizes: getSettings().imageSizes,\n\t\t};\n\t}, [] );\n\n\tif ( ! imageSizes?.length ) {\n\t\treturn null;\n\t}\n\n\tconst imageSizeOptions = imageSizes\n\t\t.filter( ( { slug } ) => getImageSourceUrlBySizeSlug( image, slug ) )\n\t\t.map( ( { name, slug } ) => ( { value: slug, label: name } ) );\n\n\treturn (\n\t\t<ResolutionTool\n\t\t\tvalue={ value }\n\t\t\tdefaultValue={ DEFAULT_MEDIA_SIZE_SLUG }\n\t\t\toptions={ imageSizeOptions }\n\t\t\tonChange={ onChange }\n\t\t/>\n\t);\n}\n\nfunction MediaTextEdit( {\n\tattributes,\n\tisSelected,\n\tsetAttributes,\n\tcontext: { postId, postType },\n} ) {\n\tconst {\n\t\tfocalPoint,\n\t\thref,\n\t\timageFill,\n\t\tisStackedOnMobile,\n\t\tlinkClass,\n\t\tlinkDestination,\n\t\tlinkTarget,\n\t\tmediaAlt,\n\t\tmediaId,\n\t\tmediaPosition,\n\t\tmediaType,\n\t\tmediaUrl,\n\t\tmediaWidth,\n\t\tmediaSizeSlug,\n\t\trel,\n\t\tverticalAlignment,\n\t\tallowedBlocks,\n\t\tuseFeaturedImage,\n\t} = attributes;\n\n\tconst [ featuredImage ] = useEntityProp(\n\t\t'postType',\n\t\tpostType,\n\t\t'featured_media',\n\t\tpostId\n\t);\n\n\tconst { featuredImageMedia } = useSelect(\n\t\t( select ) => {\n\t\t\treturn {\n\t\t\t\tfeaturedImageMedia:\n\t\t\t\t\tfeaturedImage && useFeaturedImage\n\t\t\t\t\t\t? select( coreStore ).getEntityRecord(\n\t\t\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\t\t\tfeaturedImage,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: undefined,\n\t\t\t};\n\t\t},\n\t\t[ featuredImage, useFeaturedImage ]\n\t);\n\n\tconst { image } = useSelect(\n\t\t( select ) => {\n\t\t\treturn {\n\t\t\t\timage:\n\t\t\t\t\tmediaId && isSelected\n\t\t\t\t\t\t? select( coreStore ).getEntityRecord(\n\t\t\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\t\t\tmediaId,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: null,\n\t\t\t};\n\t\t},\n\t\t[ isSelected, mediaId ]\n\t);\n\n\tconst featuredImageURL = useFeaturedImage\n\t\t? featuredImageMedia?.source_url\n\t\t: '';\n\tconst featuredImageAlt = useFeaturedImage\n\t\t? featuredImageMedia?.alt_text\n\t\t: '';\n\n\tconst toggleUseFeaturedImage = () => {\n\t\tsetAttributes( {\n\t\t\timageFill: false,\n\t\t\tmediaType: 'image',\n\t\t\tmediaId: undefined,\n\t\t\tmediaUrl: undefined,\n\t\t\tmediaAlt: undefined,\n\t\t\tmediaLink: undefined,\n\t\t\tlinkDestination: undefined,\n\t\t\tlinkTarget: undefined,\n\t\t\tlinkClass: undefined,\n\t\t\trel: undefined,\n\t\t\thref: undefined,\n\t\t\tuseFeaturedImage: ! useFeaturedImage,\n\t\t} );\n\t};\n\n\tconst refMedia = useRef();\n\tconst imperativeFocalPointPreview = ( value ) => {\n\t\tconst { style } = refMedia.current;\n\t\tconst { x, y } = value;\n\t\tstyle.objectPosition = `${ x * 100 }% ${ y * 100 }%`;\n\t};\n\n\tconst [ temporaryMediaWidth, setTemporaryMediaWidth ] = useState( null );\n\n\tconst onSelectMedia = attributesFromMedia( { attributes, setAttributes } );\n\n\tconst onSetHref = ( props ) => {\n\t\tsetAttributes( props );\n\t};\n\n\tconst onWidthChange = ( width ) => {\n\t\tsetTemporaryMediaWidth( applyWidthConstraints( width ) );\n\t};\n\tconst commitWidthChange = ( width ) => {\n\t\tsetAttributes( {\n\t\t\tmediaWidth: applyWidthConstraints( width ),\n\t\t} );\n\t\tsetTemporaryMediaWidth( null );\n\t};\n\n\tconst classNames = clsx( {\n\t\t'has-media-on-the-right': 'right' === mediaPosition,\n\t\t'is-selected': isSelected,\n\t\t'is-stacked-on-mobile': isStackedOnMobile,\n\t\t[ `is-vertically-aligned-${ verticalAlignment }` ]: verticalAlignment,\n\t\t'is-image-fill-element': imageFill,\n\t} );\n\tconst widthString = `${ temporaryMediaWidth || mediaWidth }%`;\n\tconst gridTemplateColumns =\n\t\t'right' === mediaPosition\n\t\t\t? `1fr ${ widthString }`\n\t\t\t: `${ widthString } 1fr`;\n\tconst style = {\n\t\tgridTemplateColumns,\n\t\tmsGridColumns: gridTemplateColumns,\n\t};\n\tconst onMediaAltChange = ( newMediaAlt ) => {\n\t\tsetAttributes( { mediaAlt: newMediaAlt } );\n\t};\n\tconst onVerticalAlignmentChange = ( alignment ) => {\n\t\tsetAttributes( { verticalAlignment: alignment } );\n\t};\n\tconst updateImage = ( newMediaSizeSlug ) => {\n\t\tconst newUrl = getImageSourceUrlBySizeSlug( image, newMediaSizeSlug );\n\n\t\tif ( ! newUrl ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tsetAttributes( {\n\t\t\tmediaUrl: newUrl,\n\t\t\tmediaSizeSlug: newMediaSizeSlug,\n\t\t} );\n\t};\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\tconst mediaTextGeneralSettings = (\n\t\t<ToolsPanel\n\t\t\tlabel={ __( 'Settings' ) }\n\t\t\tresetAll={ () => {\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tisStackedOnMobile: true,\n\t\t\t\t\timageFill: false,\n\t\t\t\t\tmediaAlt: '',\n\t\t\t\t\tfocalPoint: undefined,\n\t\t\t\t\tmediaWidth: 50,\n\t\t\t\t} );\n\t\t\t\tupdateImage( DEFAULT_MEDIA_SIZE_SLUG );\n\t\t\t} }\n\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t>\n\t\t\t<ToolsPanelItem\n\t\t\t\tlabel={ __( 'Media width' ) }\n\t\t\t\tisShownByDefault\n\t\t\t\thasValue={ () => mediaWidth !== 50 }\n\t\t\t\tonDeselect={ () => setAttributes( { mediaWidth: 50 } ) }\n\t\t\t>\n\t\t\t\t<RangeControl\n\t\t\t\t\tlabel={ __( 'Media width' ) }\n\t\t\t\t\tvalue={ temporaryMediaWidth || mediaWidth }\n\t\t\t\t\tonChange={ commitWidthChange }\n\t\t\t\t\tmin={ WIDTH_CONSTRAINT_PERCENTAGE }\n\t\t\t\t\tmax={ 100 - WIDTH_CONSTRAINT_PERCENTAGE }\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\t\t\t<ToolsPanelItem\n\t\t\t\tlabel={ __( 'Stack on mobile' ) }\n\t\t\t\tisShownByDefault\n\t\t\t\thasValue={ () => ! isStackedOnMobile }\n\t\t\t\tonDeselect={ () =>\n\t\t\t\t\tsetAttributes( { isStackedOnMobile: true } )\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t<ToggleControl\n\t\t\t\t\tlabel={ __( 'Stack on mobile' ) }\n\t\t\t\t\tchecked={ isStackedOnMobile }\n\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\tisStackedOnMobile: ! isStackedOnMobile,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\t\t\t{ mediaType === 'image' && (\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\tlabel={ __( 'Crop image to fill' ) }\n\t\t\t\t\tisShownByDefault\n\t\t\t\t\thasValue={ () => !! imageFill }\n\t\t\t\t\tonDeselect={ () => setAttributes( { imageFill: false } ) }\n\t\t\t\t>\n\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\tlabel={ __( 'Crop image to fill' ) }\n\t\t\t\t\t\tchecked={ !! imageFill }\n\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\timageFill: ! imageFill,\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</ToolsPanelItem>\n\t\t\t) }\n\t\t\t{ imageFill &&\n\t\t\t\t( mediaUrl || featuredImageURL ) &&\n\t\t\t\tmediaType === 'image' && (\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\tlabel={ __( 'Focal point' ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\thasValue={ () => !! focalPoint }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( { focalPoint: undefined } )\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t<FocalPointPicker\n\t\t\t\t\t\t\tlabel={ __( 'Focal point' ) }\n\t\t\t\t\t\t\turl={\n\t\t\t\t\t\t\t\tuseFeaturedImage && featuredImageURL\n\t\t\t\t\t\t\t\t\t? featuredImageURL\n\t\t\t\t\t\t\t\t\t: mediaUrl\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tvalue={ focalPoint }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { focalPoint: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonDragStart={ imperativeFocalPointPreview }\n\t\t\t\t\t\t\tonDrag={ imperativeFocalPointPreview }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t) }\n\t\t\t{ mediaType === 'image' && mediaUrl && ! useFeaturedImage && (\n\t\t\t\t<ToolsPanelItem\n\t\t\t\t\tlabel={ __( 'Alternative text' ) }\n\t\t\t\t\tisShownByDefault\n\t\t\t\t\thasValue={ () => !! mediaAlt }\n\t\t\t\t\tonDeselect={ () => setAttributes( { mediaAlt: '' } ) }\n\t\t\t\t>\n\t\t\t\t\t<TextareaControl\n\t\t\t\t\t\tlabel={ __( 'Alternative text' ) }\n\t\t\t\t\t\tvalue={ mediaAlt }\n\t\t\t\t\t\tonChange={ onMediaAltChange }\n\t\t\t\t\t\thelp={\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\t\t\thref={\n\t\t\t\t\t\t\t\t\t\t// translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations.\n\t\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t\t'https://www.w3.org/WAI/tutorials/images/decision-tree/'\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>\n\t\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t\t'Describe the purpose of the image.'\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t\t\t\t<br />\n\t\t\t\t\t\t\t\t{ __( 'Leave empty if decorative.' ) }\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</ToolsPanelItem>\n\t\t\t) }\n\t\t\t{ mediaType === 'image' && ! useFeaturedImage && (\n\t\t\t\t<MediaTextResolutionTool\n\t\t\t\t\timage={ image }\n\t\t\t\t\tvalue={ mediaSizeSlug }\n\t\t\t\t\tonChange={ updateImage }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</ToolsPanel>\n\t);\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classNames,\n\t\tstyle,\n\t} );\n\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{ className: 'wp-block-media-text__content' },\n\t\t{ template: TEMPLATE, allowedBlocks }\n\t);\n\n\tconst blockEditingMode = useBlockEditingMode();\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>{ mediaTextGeneralSettings }</InspectorControls>\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t{ blockEditingMode === 'default' && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<BlockVerticalAlignmentControl\n\t\t\t\t\t\t\tonChange={ onVerticalAlignmentChange }\n\t\t\t\t\t\t\tvalue={ verticalAlignment }\n\t\t\t\t\t\t\tlabel={ __( 'Align media and text vertically' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\ticon={ pullLeft }\n\t\t\t\t\t\t\ttitle={ __( 'Show media on left' ) }\n\t\t\t\t\t\t\tisActive={ mediaPosition === 'left' }\n\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( { mediaPosition: 'left' } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\ticon={ pullRight }\n\t\t\t\t\t\t\ttitle={ __( 'Show media on right' ) }\n\t\t\t\t\t\t\tisActive={ mediaPosition === 'right' }\n\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( { mediaPosition: 'right' } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</>\n\t\t\t\t) }\n\n\t\t\t\t{ mediaType === 'image' && ! useFeaturedImage && (\n\t\t\t\t\t<ImageURLInputUI\n\t\t\t\t\t\turl={ href || '' }\n\t\t\t\t\t\tonChangeUrl={ onSetHref }\n\t\t\t\t\t\tlinkDestination={ linkDestination }\n\t\t\t\t\t\tmediaType={ mediaType }\n\t\t\t\t\t\tmediaUrl={ image && image.source_url }\n\t\t\t\t\t\tmediaLink={ image && image.link }\n\t\t\t\t\t\tlinkTarget={ linkTarget }\n\t\t\t\t\t\tlinkClass={ linkClass }\n\t\t\t\t\t\trel={ rel }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</BlockControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ mediaPosition === 'right' && <div { ...innerBlocksProps } /> }\n\t\t\t\t<MediaContainer\n\t\t\t\t\tclassName=\"wp-block-media-text__media\"\n\t\t\t\t\tonSelectMedia={ onSelectMedia }\n\t\t\t\t\tonWidthChange={ onWidthChange }\n\t\t\t\t\tcommitWidthChange={ commitWidthChange }\n\t\t\t\t\trefMedia={ refMedia }\n\t\t\t\t\tenableResize={ blockEditingMode === 'default' }\n\t\t\t\t\ttoggleUseFeaturedImage={ toggleUseFeaturedImage }\n\t\t\t\t\t{ ...{\n\t\t\t\t\t\tfocalPoint,\n\t\t\t\t\t\timageFill,\n\t\t\t\t\t\tisSelected,\n\t\t\t\t\t\tisStackedOnMobile,\n\t\t\t\t\t\tmediaAlt,\n\t\t\t\t\t\tmediaId,\n\t\t\t\t\t\tmediaPosition,\n\t\t\t\t\t\tmediaType,\n\t\t\t\t\t\tmediaUrl,\n\t\t\t\t\t\tmediaWidth,\n\t\t\t\t\t\tuseFeaturedImage,\n\t\t\t\t\t\tfeaturedImageURL,\n\t\t\t\t\t\tfeaturedImageAlt,\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t\t{ mediaPosition !== 'right' && <div { ...innerBlocksProps } /> }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default MediaTextEdit;\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,UAAU;AACnB,SAAS,iBAAiB;AAC1B,SAAS,UAAU,cAAc;AACjC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,iCAAiC;AAAA,EACjC,SAAS;AAAA,EACT;AAAA,EACA,eAAe;AAAA,OACT;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AA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B,WAAY,SAAS,MAAM;AAAA,UAC3B;AAAA,UACA;AAAA,UACA;AAAA;AAAA,MACD;AAAA,OAEF;AAAA,IACA,qBAAC,SAAM,GAAG,YACP;AAAA,wBAAkB,WAAW,oBAAC,SAAM,GAAG,kBAAmB;AAAA,MAC5D;AAAA,QAAC;AAAA;AAAA,UACA,WAAU;AAAA,UACV;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,cAAe,qBAAqB;AAAA,UACpC;AAAA,UACE,GAAG;AAAA,YACJ;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACD;AAAA;AAAA,MACD;AAAA,MACE,kBAAkB,WAAW,oBAAC,SAAM,GAAG,kBAAmB;AAAA,OAC7D;AAAA,KACD;AAEF;AAEA,IAAO,eAAQ;",
|
|
6
6
|
"names": ["style"]
|
|
7
7
|
}
|
|
@@ -63,9 +63,9 @@ function MoreEdit({
|
|
|
63
63
|
placeholder: DEFAULT_TEXT,
|
|
64
64
|
onChange: (value) => setAttributes({ customText: value }),
|
|
65
65
|
disableLineBreaks: true,
|
|
66
|
-
__unstableOnSplitAtEnd: () => insertBlocksAfter(
|
|
66
|
+
__unstableOnSplitAtEnd: insertBlocksAfter ? () => insertBlocksAfter(
|
|
67
67
|
createBlock(getDefaultBlockName())
|
|
68
|
-
)
|
|
68
|
+
) : void 0
|
|
69
69
|
}
|
|
70
70
|
) })
|
|
71
71
|
] });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/more/edit.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\tToggleControl,\n} from '@wordpress/components';\nimport {\n\tInspectorControls,\n\tPlainText,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { getDefaultBlockName, createBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nconst DEFAULT_TEXT = __( 'Read more' );\n\nexport default function MoreEdit( {\n\tattributes: { customText, noTeaser },\n\tinsertBlocksAfter,\n\tsetAttributes,\n} ) {\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<ToolsPanel\n\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\tresetAll={ () => {\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\tnoTeaser: false,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\tlabel={ __( 'Hide excerpt' ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\thasValue={ () => noTeaser }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( { noTeaser: false } )\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t\t'Hide the excerpt on the full content page'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tchecked={ !! noTeaser }\n\t\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( { noTeaser: ! noTeaser } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\thelp={ ( checked ) =>\n\t\t\t\t\t\t\t\tchecked\n\t\t\t\t\t\t\t\t\t? __( 'The excerpt is hidden.' )\n\t\t\t\t\t\t\t\t\t: __( 'The excerpt is visible.' )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t</ToolsPanel>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...useBlockProps() }>\n\t\t\t\t<PlainText\n\t\t\t\t\t__experimentalVersion={ 2 }\n\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\taria-label={ __( '\"Read more\" text' ) }\n\t\t\t\t\tvalue={ customText }\n\t\t\t\t\tplaceholder={ DEFAULT_TEXT }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { customText: value } )\n\t\t\t\t\t}\n\t\t\t\t\tdisableLineBreaks\n\t\t\t\t\t__unstableOnSplitAtEnd={ () =>\n\t\t\t\t\t\tinsertBlocksAfter(\n\t\t\t\t\t\t\tcreateBlock( getDefaultBlockName() )\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,UAAU;AACnB;AAAA,EACC,4BAA4B;AAAA,EAC5B,gCAAgC;AAAA,EAChC;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,qBAAqB,mBAAmB;AAKjD,SAAS,sCAAsC;AAY7C,mBAmBI,KAnBJ;AAVF,IAAM,eAAe,GAAI,WAAY;AAEtB,SAAR,SAA2B;AAAA,EACjC,YAAY,EAAE,YAAY,SAAS;AAAA,EACnC;AAAA,EACA;AACD,GAAI;AACH,QAAM,oBAAoB,+BAA+B;AAEzD,SACC,iCACC;AAAA,wBAAC,qBACA;AAAA,MAAC;AAAA;AAAA,QACA,OAAQ,GAAI,UAAW;AAAA,QACvB,UAAW,MAAM;AAChB,wBAAe;AAAA,YACd,UAAU;AAAA,UACX,CAAE;AAAA,QACH;AAAA,QACA;AAAA,QAEA;AAAA,UAAC;AAAA;AAAA,YACA,OAAQ,GAAI,cAAe;AAAA,YAC3B,kBAAgB;AAAA,YAChB,UAAW,MAAM;AAAA,YACjB,YAAa,MACZ,cAAe,EAAE,UAAU,MAAM,CAAE;AAAA,YAGpC;AAAA,cAAC;AAAA;AAAA,gBACA,OAAQ;AAAA,kBACP;AAAA,gBACD;AAAA,gBACA,SAAU,CAAC,CAAE;AAAA,gBACb,UAAW,MACV,cAAe,EAAE,UAAU,CAAE,SAAS,CAAE;AAAA,gBAEzC,MAAO,CAAE,YACR,UACG,GAAI,wBAAyB,IAC7B,GAAI,yBAA0B;AAAA;AAAA,YAEnC;AAAA;AAAA,QACD;AAAA;AAAA,IACD,GACD;AAAA,IACA,oBAAC,SAAM,GAAG,cAAc,GACvB;AAAA,MAAC;AAAA;AAAA,QACA,uBAAwB;AAAA,QACxB,SAAQ;AAAA,QACR,cAAa,GAAI,kBAAmB;AAAA,QACpC,OAAQ;AAAA,QACR,aAAc;AAAA,QACd,UAAW,CAAE,UACZ,cAAe,EAAE,YAAY,MAAM,CAAE;AAAA,QAEtC,mBAAiB;AAAA,QACjB,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\tToggleControl,\n} from '@wordpress/components';\nimport {\n\tInspectorControls,\n\tPlainText,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { getDefaultBlockName, createBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nconst DEFAULT_TEXT = __( 'Read more' );\n\nexport default function MoreEdit( {\n\tattributes: { customText, noTeaser },\n\tinsertBlocksAfter,\n\tsetAttributes,\n} ) {\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<ToolsPanel\n\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\tresetAll={ () => {\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\tnoTeaser: false,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\tlabel={ __( 'Hide excerpt' ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\thasValue={ () => noTeaser }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( { noTeaser: false } )\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __(\n\t\t\t\t\t\t\t\t'Hide the excerpt on the full content page'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tchecked={ !! noTeaser }\n\t\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( { noTeaser: ! noTeaser } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\thelp={ ( checked ) =>\n\t\t\t\t\t\t\t\tchecked\n\t\t\t\t\t\t\t\t\t? __( 'The excerpt is hidden.' )\n\t\t\t\t\t\t\t\t\t: __( 'The excerpt is visible.' )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t</ToolsPanel>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...useBlockProps() }>\n\t\t\t\t<PlainText\n\t\t\t\t\t__experimentalVersion={ 2 }\n\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\taria-label={ __( '\"Read more\" text' ) }\n\t\t\t\t\tvalue={ customText }\n\t\t\t\t\tplaceholder={ DEFAULT_TEXT }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { customText: value } )\n\t\t\t\t\t}\n\t\t\t\t\tdisableLineBreaks\n\t\t\t\t\t__unstableOnSplitAtEnd={\n\t\t\t\t\t\tinsertBlocksAfter\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ACD;AAAA,IACA,oBAAC,SAAM,GAAG,cAAc,GACvB;AAAA,MAAC;AAAA;AAAA,QACA,uBAAwB;AAAA,QACxB,SAAQ;AAAA,QACR,cAAa,GAAI,kBAAmB;AAAA,QACpC,OAAQ;AAAA,QACR,aAAc;AAAA,QACd,UAAW,CAAE,UACZ,cAAe,EAAE,YAAY,MAAM,CAAE;AAAA,QAEtC,mBAAiB;AAAA,QACjB,wBACC,oBACG,MACA;AAAA,UACC,YAAa,oBAAoB,CAAE;AAAA,QACpC,IACA;AAAA;AAAA,IAEL,GACD;AAAA,KACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -65,6 +65,7 @@ import AccessibleMenuDescription from "./accessible-menu-description.mjs";
|
|
|
65
65
|
import { unlock } from "../../lock-unlock.mjs";
|
|
66
66
|
import { useToolsPanelDropdownMenuProps } from "../../utils/hooks.mjs";
|
|
67
67
|
import { isWithinNavigationOverlay } from "../../utils/is-within-overlay.mjs";
|
|
68
|
+
import useLayoutCustomProperties from "./use-layout-custom-properties.mjs";
|
|
68
69
|
import {
|
|
69
70
|
DEFAULT_BLOCK,
|
|
70
71
|
NAVIGATION_OVERLAY_TEMPLATE_PART_AREA
|
|
@@ -235,6 +236,11 @@ function Navigation({
|
|
|
235
236
|
icon = "handle"
|
|
236
237
|
} = attributes;
|
|
237
238
|
const ref = attributes.ref;
|
|
239
|
+
useLayoutCustomProperties({
|
|
240
|
+
clientId,
|
|
241
|
+
layout: attributes.layout,
|
|
242
|
+
style: attributes.style
|
|
243
|
+
});
|
|
238
244
|
const setRef = useCallback(
|
|
239
245
|
(postId) => {
|
|
240
246
|
setAttributes({ ref: postId });
|
|
@@ -247,21 +253,29 @@ function Navigation({
|
|
|
247
253
|
isPreviewMode,
|
|
248
254
|
onNavigateToEntityRecord,
|
|
249
255
|
currentTheme,
|
|
250
|
-
editorDisabledResponsive
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
256
|
+
editorDisabledResponsive,
|
|
257
|
+
hasSelectedStyleState
|
|
258
|
+
} = useSelect(
|
|
259
|
+
(select) => {
|
|
260
|
+
const {
|
|
261
|
+
getSettings,
|
|
262
|
+
hasSelectedStyleState: hasSelectedBlockStyleState
|
|
263
|
+
} = unlock(select(blockEditorStore));
|
|
264
|
+
const settings = getSettings();
|
|
265
|
+
return {
|
|
266
|
+
isPreviewMode: settings.isPreviewMode,
|
|
267
|
+
onNavigateToEntityRecord: settings?.onNavigateToEntityRecord,
|
|
268
|
+
// Needed to construct the template part ID for the overlay preview.
|
|
269
|
+
currentTheme: select(coreStore).getCurrentTheme()?.stylesheet,
|
|
270
|
+
// When editing a navigation post directly in an isolated editor,
|
|
271
|
+
// always show navigation expanded (no hamburger) so users can see
|
|
272
|
+
// and interact with all menu items.
|
|
273
|
+
editorDisabledResponsive: !!settings?.[isNavigationPostEditorKey],
|
|
274
|
+
hasSelectedStyleState: hasSelectedBlockStyleState(clientId)
|
|
275
|
+
};
|
|
276
|
+
},
|
|
277
|
+
[clientId]
|
|
278
|
+
);
|
|
265
279
|
const hasAlreadyRendered = isPreviewMode ? false : recursionDetected;
|
|
266
280
|
const blockEditingMode = useBlockEditingMode();
|
|
267
281
|
const { records: classicMenus } = useEntityRecords("root", "menu", {
|
|
@@ -712,7 +726,7 @@ function Navigation({
|
|
|
712
726
|
hasOverlays
|
|
713
727
|
}
|
|
714
728
|
) }),
|
|
715
|
-
/* @__PURE__ */ jsx(InspectorControls, { group: "color", children: /* @__PURE__ */ jsx(
|
|
729
|
+
!hasSelectedStyleState && /* @__PURE__ */ jsx(InspectorControls, { group: "color", children: /* @__PURE__ */ jsx(
|
|
716
730
|
ColorTools,
|
|
717
731
|
{
|
|
718
732
|
textColor,
|