@wordpress/block-library 9.45.1-next.v.202605131032.0 → 9.47.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 +8 -0
- package/build/button/edit.cjs +7 -4
- package/build/button/edit.cjs.map +3 -3
- package/build/columns/edit.cjs +4 -10
- package/build/columns/edit.cjs.map +2 -2
- package/build/comments/edit/placeholder.cjs +1 -1
- package/build/comments/edit/placeholder.cjs.map +2 -2
- package/build/cover/edit/inspector-controls.cjs +4 -2
- package/build/cover/edit/inspector-controls.cjs.map +2 -2
- package/build/freeform/migration-notice.cjs +1 -1
- package/build/freeform/migration-notice.cjs.map +1 -1
- package/build/home-link/block.json +7 -0
- package/build/home-link/edit.cjs +167 -24
- package/build/home-link/edit.cjs.map +3 -3
- package/build/html/edit.cjs +2 -4
- package/build/html/edit.cjs.map +2 -2
- package/build/html/modal.cjs +0 -4
- package/build/html/modal.cjs.map +2 -2
- package/build/image/block.json +4 -0
- package/build/image/deprecated.cjs +202 -4
- package/build/image/deprecated.cjs.map +3 -3
- package/build/image/image.cjs +80 -27
- package/build/image/image.cjs.map +2 -2
- package/build/image/index.cjs +23 -4
- package/build/image/index.cjs.map +2 -2
- package/build/image/save.cjs +25 -10
- package/build/image/save.cjs.map +2 -2
- package/build/image/transforms.cjs +15 -3
- package/build/image/transforms.cjs.map +2 -2
- package/build/image/use-open-image-media-editor-modal.cjs +29 -12
- package/build/image/use-open-image-media-editor-modal.cjs.map +2 -2
- package/build/list-item/hooks/use-enter.cjs +8 -4
- package/build/list-item/hooks/use-enter.cjs.map +3 -3
- package/build/list-item/hooks/use-space.cjs +8 -4
- package/build/list-item/hooks/use-space.cjs.map +3 -3
- package/build/navigation-link/edit.cjs +2 -1
- package/build/navigation-link/edit.cjs.map +2 -2
- package/build/navigation-link/shared/use-handle-link-change.cjs +19 -3
- package/build/navigation-link/shared/use-handle-link-change.cjs.map +3 -3
- package/build/navigation-submenu/edit.cjs +8 -22
- package/build/navigation-submenu/edit.cjs.map +2 -2
- package/build/paragraph/use-enter.cjs +8 -4
- package/build/paragraph/use-enter.cjs.map +3 -3
- package/build/post-date/edit.cjs +9 -1
- package/build/post-date/edit.cjs.map +2 -2
- package/build/post-featured-image/edit.cjs +0 -1
- package/build/post-featured-image/edit.cjs.map +2 -2
- package/build/site-logo/edit.cjs +1 -1
- package/build/site-logo/edit.cjs.map +2 -2
- package/build/social-link/edit.cjs.map +3 -3
- package/build/tab-list/edit.cjs +2 -0
- package/build/tab-list/edit.cjs.map +2 -2
- package/build/tab-panels/edit.cjs +5 -1
- package/build/tab-panels/edit.cjs.map +2 -2
- package/build/table/edit.cjs +1 -0
- package/build/table/edit.cjs.map +2 -2
- package/build/tabs/edit.cjs +1 -36
- package/build/tabs/edit.cjs.map +2 -2
- package/build-module/button/edit.mjs +12 -5
- package/build-module/button/edit.mjs.map +2 -2
- package/build-module/columns/edit.mjs +4 -10
- package/build-module/columns/edit.mjs.map +2 -2
- package/build-module/comments/edit/placeholder.mjs +1 -1
- package/build-module/comments/edit/placeholder.mjs.map +2 -2
- package/build-module/cover/edit/inspector-controls.mjs +4 -3
- package/build-module/cover/edit/inspector-controls.mjs.map +2 -2
- package/build-module/freeform/migration-notice.mjs +1 -1
- package/build-module/freeform/migration-notice.mjs.map +1 -1
- package/build-module/home-link/block.json +7 -0
- package/build-module/home-link/edit.mjs +181 -26
- package/build-module/home-link/edit.mjs.map +2 -2
- package/build-module/html/edit.mjs +2 -4
- package/build-module/html/edit.mjs.map +2 -2
- package/build-module/html/modal.mjs +0 -4
- package/build-module/html/modal.mjs.map +2 -2
- package/build-module/image/block.json +4 -0
- package/build-module/image/deprecated.mjs +204 -5
- package/build-module/image/deprecated.mjs.map +2 -2
- package/build-module/image/image.mjs +81 -27
- package/build-module/image/image.mjs.map +2 -2
- package/build-module/image/index.mjs +23 -4
- package/build-module/image/index.mjs.map +2 -2
- package/build-module/image/save.mjs +25 -10
- package/build-module/image/save.mjs.map +2 -2
- package/build-module/image/transforms.mjs +15 -3
- package/build-module/image/transforms.mjs.map +2 -2
- package/build-module/image/use-open-image-media-editor-modal.mjs +29 -12
- package/build-module/image/use-open-image-media-editor-modal.mjs.map +2 -2
- package/build-module/list-item/hooks/use-enter.mjs +12 -5
- package/build-module/list-item/hooks/use-enter.mjs.map +2 -2
- package/build-module/list-item/hooks/use-space.mjs +12 -5
- package/build-module/list-item/hooks/use-space.mjs.map +2 -2
- package/build-module/navigation-link/edit.mjs +2 -1
- package/build-module/navigation-link/edit.mjs.map +2 -2
- package/build-module/navigation-link/shared/use-handle-link-change.mjs +19 -3
- package/build-module/navigation-link/shared/use-handle-link-change.mjs.map +2 -2
- package/build-module/navigation-submenu/edit.mjs +9 -23
- package/build-module/navigation-submenu/edit.mjs.map +2 -2
- package/build-module/paragraph/use-enter.mjs +12 -5
- package/build-module/paragraph/use-enter.mjs.map +2 -2
- package/build-module/post-date/edit.mjs +9 -1
- package/build-module/post-date/edit.mjs.map +2 -2
- package/build-module/post-featured-image/edit.mjs +0 -1
- package/build-module/post-featured-image/edit.mjs.map +2 -2
- package/build-module/site-logo/edit.mjs +1 -1
- package/build-module/site-logo/edit.mjs.map +2 -2
- package/build-module/social-link/edit.mjs +2 -2
- package/build-module/social-link/edit.mjs.map +2 -2
- package/build-module/tab-list/edit.mjs +2 -0
- package/build-module/tab-list/edit.mjs.map +2 -2
- package/build-module/tab-panels/edit.mjs +5 -1
- package/build-module/tab-panels/edit.mjs.map +2 -2
- package/build-module/table/edit.mjs +1 -0
- package/build-module/table/edit.mjs.map +2 -2
- package/build-module/tabs/edit.mjs +2 -37
- package/build-module/tabs/edit.mjs.map +2 -2
- package/build-style/breadcrumbs/style-rtl.css +1 -1
- package/build-style/breadcrumbs/style.css +1 -1
- package/build-style/editor-rtl.css +0 -11
- package/build-style/editor.css +0 -11
- package/build-style/gallery/editor-rtl.css +0 -11
- package/build-style/gallery/editor.css +0 -11
- package/build-style/style-rtl.css +1 -1
- package/build-style/style.css +1 -1
- package/package.json +42 -42
- package/src/block/edit-title.native.js +3 -3
- package/src/block/edit.native.js +2 -2
- package/src/breadcrumbs/style.scss +1 -1
- package/src/button/edit.js +14 -5
- package/src/columns/edit.js +3 -9
- package/src/comments/edit/placeholder.js +1 -1
- package/src/cover/controls.native.js +2 -2
- package/src/cover/edit/inspector-controls.js +8 -7
- package/src/cover/edit.native.js +6 -4
- package/src/cover/focal-point-settings-button.native.js +2 -2
- package/src/cover/test/edit.js +32 -31
- package/src/embed/embed-no-preview.native.js +7 -3
- package/src/embed/embed-placeholder.native.js +2 -2
- package/src/file/edit.native.js +2 -2
- package/src/freeform/migration-notice.js +1 -1
- package/src/gallery/editor.scss +0 -14
- package/src/home-link/block.json +7 -0
- package/src/home-link/edit.js +185 -22
- package/src/home-link/index.php +14 -2
- package/src/html/edit.js +14 -12
- package/src/html/modal.js +0 -5
- package/src/image/block.json +4 -0
- package/src/image/deprecated.js +236 -4
- package/src/image/edit.native.js +2 -2
- package/src/image/image.js +116 -41
- package/src/image/index.js +20 -1
- package/src/image/index.php +1 -1
- package/src/image/save.js +39 -12
- package/src/image/test/use-open-image-media-editor-modal.js +60 -0
- package/src/image/transforms.js +21 -5
- package/src/image/use-open-image-media-editor-modal.js +34 -16
- package/src/latest-posts/edit.native.js +2 -2
- package/src/list-item/hooks/use-enter.js +15 -5
- package/src/list-item/hooks/use-space.js +15 -5
- package/src/list-item/list-style-type.native.js +2 -2
- package/src/media-text/media-container.native.js +7 -3
- package/src/missing/edit.native.js +4 -4
- package/src/missing/test/edit.native.js +3 -3
- package/src/navigation/test/use-navigation-menu.js +8 -2
- package/src/navigation-link/edit.js +1 -0
- package/src/navigation-link/shared/test/use-handle-link-change.test.js +212 -0
- package/src/navigation-link/shared/use-handle-link-change.js +36 -9
- package/src/navigation-link/test/__snapshots__/hooks.js.snap +134 -45
- package/src/navigation-submenu/edit.js +11 -28
- package/src/navigation-submenu/index.php +13 -0
- package/src/paragraph/use-enter.js +19 -5
- package/src/post-date/edit.js +7 -3
- package/src/post-featured-image/edit.js +0 -1
- package/src/search/edit.native.js +2 -2
- package/src/search/test/edit.native.js +2 -2
- package/src/site-logo/edit.js +2 -1
- package/src/social-link/edit.js +2 -2
- package/src/tab-list/edit.js +3 -0
- package/src/tab-panels/edit.js +10 -1
- package/src/table/edit.js +1 -0
- package/src/tabs/edit.js +14 -42
- package/src/video/edit.native.js +3 -3
|
@@ -108,12 +108,22 @@ function useOpenImageMediaEditorModal({ attributes, setAttributes }) {
|
|
|
108
108
|
(select) => select(import_block_editor.store).getSettings()[openMediaEditorModalKey],
|
|
109
109
|
[]
|
|
110
110
|
);
|
|
111
|
-
const
|
|
111
|
+
const blockAttributesRef = (0, import_element.useRef)({
|
|
112
|
+
id,
|
|
113
|
+
url,
|
|
114
|
+
alt,
|
|
115
|
+
caption: caption?.toString()
|
|
116
|
+
});
|
|
112
117
|
const mediaEditorMetadataBaselineRef = (0, import_element.useRef)();
|
|
113
118
|
const mediaEditorMetadataSyncRequestRef = (0, import_element.useRef)(0);
|
|
114
119
|
(0, import_element.useEffect)(() => {
|
|
115
|
-
|
|
116
|
-
|
|
120
|
+
blockAttributesRef.current = {
|
|
121
|
+
id,
|
|
122
|
+
url,
|
|
123
|
+
alt,
|
|
124
|
+
caption: caption?.toString()
|
|
125
|
+
};
|
|
126
|
+
}, [alt, caption, id, url]);
|
|
117
127
|
const getCachedAttachmentRecord = (0, import_element.useCallback)(
|
|
118
128
|
(attachmentId) => {
|
|
119
129
|
const { getEditedEntityRecord, getEntityRecord } = registry.select(import_core_data.store);
|
|
@@ -177,33 +187,40 @@ function useOpenImageMediaEditorModal({ attributes, setAttributes }) {
|
|
|
177
187
|
mediaEditorMetadataBaselineRef.current = void 0;
|
|
178
188
|
const syncRequest = ++mediaEditorMetadataSyncRequestRef.current;
|
|
179
189
|
const nextAttributes = {};
|
|
180
|
-
|
|
190
|
+
const currentBlockAttributes = blockAttributesRef.current;
|
|
191
|
+
if (newId !== currentBlockAttributes.id) {
|
|
181
192
|
nextAttributes.id = newId;
|
|
182
|
-
nextAttributes.url = newUrl ?? url;
|
|
193
|
+
nextAttributes.url = newUrl ?? currentBlockAttributes.url;
|
|
194
|
+
blockAttributesRef.current = {
|
|
195
|
+
...blockAttributesRef.current,
|
|
196
|
+
id: nextAttributes.id,
|
|
197
|
+
url: nextAttributes.url
|
|
198
|
+
};
|
|
183
199
|
}
|
|
184
200
|
if (originalAttachment) {
|
|
185
201
|
const resolvedAttachment = await resolveFreshAttachmentRecord(newId);
|
|
186
202
|
if (syncRequest !== mediaEditorMetadataSyncRequestRef.current) {
|
|
187
203
|
return;
|
|
188
204
|
}
|
|
205
|
+
const latestBlockAttributes = blockAttributesRef.current;
|
|
189
206
|
const resolvedMetadataAttributes = getSyncedImageBlockAttributes(
|
|
190
|
-
|
|
207
|
+
latestBlockAttributes,
|
|
191
208
|
originalAttachment,
|
|
192
209
|
resolvedAttachment
|
|
193
210
|
);
|
|
194
211
|
if (Object.keys(resolvedMetadataAttributes).length) {
|
|
195
212
|
Object.assign(nextAttributes, resolvedMetadataAttributes);
|
|
196
|
-
blockMetadataRef.current = {
|
|
197
|
-
...blockMetadataRef.current,
|
|
198
|
-
...resolvedMetadataAttributes
|
|
199
|
-
};
|
|
200
213
|
}
|
|
201
214
|
}
|
|
202
215
|
if (Object.keys(nextAttributes).length) {
|
|
216
|
+
blockAttributesRef.current = {
|
|
217
|
+
...blockAttributesRef.current,
|
|
218
|
+
...nextAttributes
|
|
219
|
+
};
|
|
203
220
|
setAttributes(nextAttributes);
|
|
204
221
|
}
|
|
205
222
|
},
|
|
206
|
-
[
|
|
223
|
+
[resolveFreshAttachmentRecord, setAttributes]
|
|
207
224
|
);
|
|
208
225
|
const openImageMediaEditorModal = (0, import_element.useCallback)(async () => {
|
|
209
226
|
if (!id || !openMediaEditorModal) {
|
|
@@ -211,7 +228,7 @@ function useOpenImageMediaEditorModal({ attributes, setAttributes }) {
|
|
|
211
228
|
}
|
|
212
229
|
const cachedAttachmentRecord = getCachedAttachmentRecord(id);
|
|
213
230
|
const fallbackAttachmentRecord = getAttachmentFallbackForEmptyBlockMetadata(
|
|
214
|
-
|
|
231
|
+
blockAttributesRef.current
|
|
215
232
|
);
|
|
216
233
|
const resolvedAttachmentRecord = hasKnownAttachmentMetadata(
|
|
217
234
|
cachedAttachmentRecord
|
|
@@ -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// Caption sync needs `caption.raw`; view/default attachment records can contain\n// only rendered caption data or be tied to an in-flight stale resolution.\nconst ATTACHMENT_EDIT_QUERY = { context: 'edit' };\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( { attributes, setAttributes } ) {\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 alt and caption in a ref so handleMediaUpdate\n\t// can read the latest values without being listed as a dependency (which\n\t// would recreate the callback and re-register the onUpdate handler on every\n\t// keystroke while the modal is open).\n\tconst blockMetadataRef = useRef( { alt, caption: caption?.toString() } );\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\tblockMetadataRef.current = { alt, caption: caption?.toString() };\n\t}, [ alt, caption ] );\n\n\tconst getCachedAttachmentRecord = useCallback(\n\t\t( attachmentId ) => {\n\t\t\tconst { getEditedEntityRecord, getEntityRecord } =\n\t\t\t\tregistry.select( coreStore );\n\t\t\treturn (\n\t\t\t\tgetEditedEntityRecord(\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\tgetEntityRecord(\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\tATTACHMENT_EDIT_QUERY\n\t\t\t\t) ||\n\t\t\t\tgetEntityRecord( 'postType', 'attachment', attachmentId )\n\t\t\t);\n\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 (\n\t\t\t\t\t( await resolveSelect.getEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tattachmentId,\n\t\t\t\t\t\tATTACHMENT_EDIT_QUERY\n\t\t\t\t\t) ) ||\n\t\t\t\t\t( await resolveSelect.getEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tattachmentId\n\t\t\t\t\t) )\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// Bust cached records so resolveAttachmentRecord fetches the\n\t\t\t// server state that reflects the media editor's 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\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tattachmentId,\n\t\t\t\tATTACHMENT_EDIT_QUERY,\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\tif ( newId !== id ) {\n\t\t\t\tnextAttributes.id = newId;\n\t\t\t\tnextAttributes.url = newUrl ?? url;\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 resolvedMetadataAttributes =\n\t\t\t\t\tgetSyncedImageBlockAttributes(\n\t\t\t\t\t\tblockMetadataRef.current,\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\tblockMetadataRef.current = {\n\t\t\t\t\t\t...blockMetadataRef.current,\n\t\t\t\t\t\t...resolvedMetadataAttributes,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( Object.keys( nextAttributes ).length ) {\n\t\t\t\tsetAttributes( nextAttributes );\n\t\t\t}\n\t\t},\n\t\t[ id, resolveFreshAttachmentRecord, setAttributes, url ]\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.\n\t\t// Prefer a freshly resolved edit-context record for accuracy; fall\n\t\t// back to whatever is in the cache, or a minimal object derived from\n\t\t// the block's own attributes when nothing is cached yet.\n\t\tconst cachedAttachmentRecord = getCachedAttachmentRecord( id );\n\t\tconst fallbackAttachmentRecord =\n\t\t\tgetAttachmentFallbackForEmptyBlockMetadata(\n\t\t\t\tblockMetadataRef.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} );\n\t}, [\n\t\tgetCachedAttachmentRecord,\n\t\thandleMediaUpdate,\n\t\tid,\n\t\topenMediaEditorModal,\n\t\tresolveAttachmentRecord,\n\t] );\n\n\treturn id && openMediaEditorModal ? openImageMediaEditorModal : undefined;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAmC;AACnC,0BAGO;AACP,iBAAiD;AACjD,kBAAuC;AACvC,qBAA+C;AAK/C,yBAAuB;AAEvB,SAAS,2BAA4B,SAAU;AAC9C,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO;AAAA,EACR;AAEA,QAAM,kBAAc,WA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AC,WAAuB;AAGnE,IAAM,wBAAwB,EAAE,SAAS,OAAO;AAEhD,SAAS,2CAA4C,EAAE,KAAK,QAAQ,GAAI;AACvE,QAAM,aAAa,CAAC;AAEpB,MAAK,CAAE,KAAM;AACZ,eAAW,WAAW;AAAA,EACvB;AAEA,MAAK,CAAE,SAAS,SAAS,GAAI;AAC5B,eAAW,UAAU;AAAA,EACtB;AAEA,SAAO,OAAO,KAAM,UAAW,EAAE,SAAS,aAAa;AACxD;AAEA,SAAS,2BAA4B,YAAa;AACjD,MAAK,CAAE,YAAa;AACnB,WAAO;AAAA,EACR;AAEA,QAAM,cACL,OAAO,WAAW,aAAa,YAC/B,OAAO,WAAW,QAAQ;AAC3B,QAAM,kBACL,oCAAqC,UAAW,EAAE,YAAY;AAE/D,SAAO,eAAe;AACvB;AAEO,SAAS,6BAA8B,EAAE,YAAY,cAAc,GAAI;AAI7E,QAAM,EAAE,IAAI,KAAK,KAAK,QAAQ,IAAI;AAClC,QAAM,eAAW,yBAAY;AAC7B,QAAM,2BAAuB;AAAA,IAC5B,CAAE,WACD,OAAQ,oBAAAC,KAAiB,EAAE,YAAY,EAAG,uBAAwB;AAAA,IACnE,CAAC;AAAA,EACF;AAKA,QAAM,
|
|
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// Caption sync needs `caption.raw`; view/default attachment records can contain\n// only rendered caption data or be tied to an in-flight stale resolution.\nconst ATTACHMENT_EDIT_QUERY = { context: 'edit' };\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( { attributes, setAttributes } ) {\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\tconst getCachedAttachmentRecord = useCallback(\n\t\t( attachmentId ) => {\n\t\t\tconst { getEditedEntityRecord, getEntityRecord } =\n\t\t\t\tregistry.select( coreStore );\n\t\t\treturn (\n\t\t\t\tgetEditedEntityRecord(\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\tgetEntityRecord(\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\tATTACHMENT_EDIT_QUERY\n\t\t\t\t) ||\n\t\t\t\tgetEntityRecord( 'postType', 'attachment', attachmentId )\n\t\t\t);\n\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 (\n\t\t\t\t\t( await resolveSelect.getEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tattachmentId,\n\t\t\t\t\t\tATTACHMENT_EDIT_QUERY\n\t\t\t\t\t) ) ||\n\t\t\t\t\t( await resolveSelect.getEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tattachmentId\n\t\t\t\t\t) )\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// Bust cached records so resolveAttachmentRecord fetches the\n\t\t\t// server state that reflects the media editor's 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\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tattachmentId,\n\t\t\t\tATTACHMENT_EDIT_QUERY,\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.\n\t\t// Prefer a freshly resolved edit-context record for accuracy; fall\n\t\t// back to whatever is in the cache, or a minimal object derived from\n\t\t// the block's own attributes when nothing is cached yet.\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} );\n\t}, [\n\t\tgetCachedAttachmentRecord,\n\t\thandleMediaUpdate,\n\t\tid,\n\t\topenMediaEditorModal,\n\t\tresolveAttachmentRecord,\n\t] );\n\n\treturn id && openMediaEditorModal ? openImageMediaEditorModal : undefined;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAmC;AACnC,0BAGO;AACP,iBAAiD;AACjD,kBAAuC;AACvC,qBAA+C;AAK/C,yBAAuB;AAEvB,SAAS,2BAA4B,SAAU;AAC9C,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO;AAAA,EACR;AAEA,QAAM,kBAAc,WAAAA,qBAAW,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,YAAY,UAAW;AAClC,WAAO,2BAA4B,OAAQ;AAAA,EAC5C;AAEA,MACC,WACA,OAAO,YAAY,YACnB,OAAO,OAAQ,SAAS,KAAM,GAC7B;AACD,WAAO,2BAA4B,QAAQ,GAAI;AAAA,EAChD;AAEA,SAAO;AACR;AAEO,SAAS,oCAAqC,YAAa;AACjE,SAAO;AAAA,IACN,KACC,OAAO,YAAY,aAAa,WAC7B,WAAW,WACX,YAAY,OAAO;AAAA,IACvB,SAAS,qBA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GAAG;AAAA,QACJ;AACA,sBAAe,cAAe;AAAA,MAC/B;AAAA,IACD;AAAA,IACA,CAAE,8BAA8B,aAAc;AAAA,EAC/C;AAEA,QAAM,gCAA4B,4BAAa,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,IACX,CAAE;AAAA,EACH,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,SAAO,MAAM,uBAAuB,4BAA4B;AACjE;",
|
|
6
6
|
"names": ["stripHTML", "blockEditorPrivateApis", "blockEditorStore", "coreStore"]
|
|
7
7
|
}
|
|
@@ -40,6 +40,8 @@ var import_keycodes = require("@wordpress/keycodes");
|
|
|
40
40
|
var import_data = require("@wordpress/data");
|
|
41
41
|
var import_block_editor = require("@wordpress/block-editor");
|
|
42
42
|
var import_use_outdent_list_item = __toESM(require("./use-outdent-list-item.cjs"));
|
|
43
|
+
var import_lock_unlock = require("../../lock-unlock.cjs");
|
|
44
|
+
var { subscribeDelegatedListener } = (0, import_lock_unlock.unlock)(import_compose.privateApis);
|
|
43
45
|
function useEnter(props) {
|
|
44
46
|
const { replaceBlocks, selectionChange } = (0, import_data.useDispatch)(import_block_editor.store);
|
|
45
47
|
const { getBlock, getBlockRootClientId, getBlockIndex, getBlockName } = (0, import_data.useSelect)(import_block_editor.store);
|
|
@@ -94,10 +96,12 @@ function useEnter(props) {
|
|
|
94
96
|
);
|
|
95
97
|
selectionChange(middle.clientId);
|
|
96
98
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
return subscribeDelegatedListener(
|
|
100
|
+
element,
|
|
101
|
+
"keydown",
|
|
102
|
+
onKeyDown,
|
|
103
|
+
true
|
|
104
|
+
);
|
|
101
105
|
}, []);
|
|
102
106
|
}
|
|
103
107
|
//# sourceMappingURL=use-enter.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/list-item/hooks/use-enter.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tcreateBlock,\n\tgetDefaultBlockName,\n\tcloneBlock,\n} from '@wordpress/blocks';\nimport { useRef } from '@wordpress/element';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAIO;AACP,qBAAuB;AACvB,
|
|
6
|
-
"names": ["blockEditorStore", "useOutdentListItem"]
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tcreateBlock,\n\tgetDefaultBlockName,\n\tcloneBlock,\n} from '@wordpress/blocks';\nimport { useRef } from '@wordpress/element';\nimport {\n\tuseRefEffect,\n\tprivateApis as composePrivateApis,\n} from '@wordpress/compose';\nimport { ENTER } from '@wordpress/keycodes';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport useOutdentListItem from './use-outdent-list-item';\nimport { unlock } from '../../lock-unlock';\n\nconst { subscribeDelegatedListener } = unlock( composePrivateApis );\n\nexport default function useEnter( props ) {\n\tconst { replaceBlocks, selectionChange } = useDispatch( blockEditorStore );\n\tconst { getBlock, getBlockRootClientId, getBlockIndex, getBlockName } =\n\t\tuseSelect( blockEditorStore );\n\tconst propsRef = useRef( props );\n\tpropsRef.current = props;\n\tconst outdentListItem = useOutdentListItem();\n\treturn useRefEffect( ( element ) => {\n\t\tfunction onKeyDown( event ) {\n\t\t\tif ( event.defaultPrevented || event.keyCode !== ENTER ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { content, clientId } = propsRef.current;\n\t\t\tif ( content.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tevent.preventDefault();\n\t\t\tconst canOutdent =\n\t\t\t\tgetBlockName(\n\t\t\t\t\tgetBlockRootClientId(\n\t\t\t\t\t\tgetBlockRootClientId( propsRef.current.clientId )\n\t\t\t\t\t)\n\t\t\t\t) === 'core/list-item';\n\t\t\tif ( canOutdent ) {\n\t\t\t\toutdentListItem();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Here we are in top level list so we need to split.\n\t\t\tconst topParentListBlock = getBlock(\n\t\t\t\tgetBlockRootClientId( clientId )\n\t\t\t);\n\t\t\tconst blockIndex = getBlockIndex( clientId );\n\t\t\tconst head = cloneBlock( {\n\t\t\t\t...topParentListBlock,\n\t\t\t\tinnerBlocks: topParentListBlock.innerBlocks.slice(\n\t\t\t\t\t0,\n\t\t\t\t\tblockIndex\n\t\t\t\t),\n\t\t\t} );\n\t\t\tconst middle = createBlock( getDefaultBlockName() );\n\t\t\t// Last list item might contain a `list` block innerBlock\n\t\t\t// In that case append remaining innerBlocks blocks.\n\t\t\tconst after = [\n\t\t\t\t...( topParentListBlock.innerBlocks[ blockIndex ]\n\t\t\t\t\t.innerBlocks[ 0 ]?.innerBlocks || [] ),\n\t\t\t\t...topParentListBlock.innerBlocks.slice( blockIndex + 1 ),\n\t\t\t];\n\t\t\tconst tail = after.length\n\t\t\t\t? [\n\t\t\t\t\t\tcloneBlock( {\n\t\t\t\t\t\t\t...topParentListBlock,\n\t\t\t\t\t\t\tinnerBlocks: after,\n\t\t\t\t\t\t} ),\n\t\t\t\t ]\n\t\t\t\t: [];\n\t\t\treplaceBlocks(\n\t\t\t\ttopParentListBlock.clientId,\n\t\t\t\t[ head, middle, ...tail ],\n\t\t\t\t1\n\t\t\t);\n\t\t\t// We manually change the selection here because we are replacing\n\t\t\t// a different block than the selected one.\n\t\t\tselectionChange( middle.clientId );\n\t\t}\n\n\t\t// Capture phase so we run before writing-flow's ancestor-bubble\n\t\t// keydown handlers that gate on `event.defaultPrevented`.\n\t\treturn subscribeDelegatedListener(\n\t\t\telement,\n\t\t\t'keydown',\n\t\t\tonKeyDown,\n\t\t\ttrue\n\t\t);\n\t}, [] );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAIO;AACP,qBAAuB;AACvB,qBAGO;AACP,sBAAsB;AACtB,kBAAuC;AACvC,0BAA0C;AAK1C,mCAA+B;AAC/B,yBAAuB;AAEvB,IAAM,EAAE,2BAA2B,QAAI,2BAAQ,eAAAA,WAAmB;AAEnD,SAAR,SAA2B,OAAQ;AACzC,QAAM,EAAE,eAAe,gBAAgB,QAAI,yBAAa,oBAAAC,KAAiB;AACzE,QAAM,EAAE,UAAU,sBAAsB,eAAe,aAAa,QACnE,uBAAW,oBAAAA,KAAiB;AAC7B,QAAM,eAAW,uBAAQ,KAAM;AAC/B,WAAS,UAAU;AACnB,QAAM,sBAAkB,6BAAAC,SAAmB;AAC3C,aAAO,6BAAc,CAAE,YAAa;AACnC,aAAS,UAAW,OAAQ;AAC3B,UAAK,MAAM,oBAAoB,MAAM,YAAY,uBAAQ;AACxD;AAAA,MACD;AACA,YAAM,EAAE,SAAS,SAAS,IAAI,SAAS;AACvC,UAAK,QAAQ,QAAS;AACrB;AAAA,MACD;AACA,YAAM,eAAe;AACrB,YAAM,aACL;AAAA,QACC;AAAA,UACC,qBAAsB,SAAS,QAAQ,QAAS;AAAA,QACjD;AAAA,MACD,MAAM;AACP,UAAK,YAAa;AACjB,wBAAgB;AAChB;AAAA,MACD;AAEA,YAAM,qBAAqB;AAAA,QAC1B,qBAAsB,QAAS;AAAA,MAChC;AACA,YAAM,aAAa,cAAe,QAAS;AAC3C,YAAM,WAAO,0BAAY;AAAA,QACxB,GAAG;AAAA,QACH,aAAa,mBAAmB,YAAY;AAAA,UAC3C;AAAA,UACA;AAAA,QACD;AAAA,MACD,CAAE;AACF,YAAM,aAAS,+BAAa,mCAAoB,CAAE;AAGlD,YAAM,QAAQ;AAAA,QACb,GAAK,mBAAmB,YAAa,UAAW,EAC9C,YAAa,CAAE,GAAG,eAAe,CAAC;AAAA,QACpC,GAAG,mBAAmB,YAAY,MAAO,aAAa,CAAE;AAAA,MACzD;AACA,YAAM,OAAO,MAAM,SAChB;AAAA,YACA,0BAAY;AAAA,UACX,GAAG;AAAA,UACH,aAAa;AAAA,QACd,CAAE;AAAA,MACF,IACA,CAAC;AACJ;AAAA,QACC,mBAAmB;AAAA,QACnB,CAAE,MAAM,QAAQ,GAAG,IAAK;AAAA,QACxB;AAAA,MACD;AAGA,sBAAiB,OAAO,QAAS;AAAA,IAClC;AAIA,WAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
|
|
6
|
+
"names": ["composePrivateApis", "blockEditorStore", "useOutdentListItem"]
|
|
7
7
|
}
|
|
@@ -39,6 +39,8 @@ var import_block_editor = require("@wordpress/block-editor");
|
|
|
39
39
|
var import_data = require("@wordpress/data");
|
|
40
40
|
var import_use_indent_list_item = __toESM(require("./use-indent-list-item.cjs"));
|
|
41
41
|
var import_use_outdent_list_item = __toESM(require("./use-outdent-list-item.cjs"));
|
|
42
|
+
var import_lock_unlock = require("../../lock-unlock.cjs");
|
|
43
|
+
var { subscribeDelegatedListener } = (0, import_lock_unlock.unlock)(import_compose.privateApis);
|
|
42
44
|
function useSpace(clientId) {
|
|
43
45
|
const { getSelectionStart, getSelectionEnd, getBlockIndex } = (0, import_data.useSelect)(import_block_editor.store);
|
|
44
46
|
const indentListItem = (0, import_use_indent_list_item.default)(clientId);
|
|
@@ -67,10 +69,12 @@ function useSpace(clientId) {
|
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
return subscribeDelegatedListener(
|
|
73
|
+
element,
|
|
74
|
+
"keydown",
|
|
75
|
+
onKeyDown,
|
|
76
|
+
true
|
|
77
|
+
);
|
|
74
78
|
},
|
|
75
79
|
[clientId, indentListItem]
|
|
76
80
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/list-item/hooks/use-space.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,
|
|
6
|
-
"names": ["blockEditorStore", "useIndentListItem", "useOutdentListItem"]
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tuseRefEffect,\n\tprivateApis as composePrivateApis,\n} from '@wordpress/compose';\nimport { SPACE, TAB } from '@wordpress/keycodes';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport useIndentListItem from './use-indent-list-item';\nimport useOutdentListItem from './use-outdent-list-item';\nimport { unlock } from '../../lock-unlock';\n\nconst { subscribeDelegatedListener } = unlock( composePrivateApis );\n\nexport default function useSpace( clientId ) {\n\tconst { getSelectionStart, getSelectionEnd, getBlockIndex } =\n\t\tuseSelect( blockEditorStore );\n\tconst indentListItem = useIndentListItem( clientId );\n\tconst outdentListItem = useOutdentListItem();\n\n\treturn useRefEffect(\n\t\t( element ) => {\n\t\t\tfunction onKeyDown( event ) {\n\t\t\t\tconst { keyCode, shiftKey, altKey, metaKey, ctrlKey } = event;\n\n\t\t\t\tif (\n\t\t\t\t\tevent.defaultPrevented ||\n\t\t\t\t\t( keyCode !== SPACE && keyCode !== TAB ) ||\n\t\t\t\t\t// Only override when no modifiers are pressed.\n\t\t\t\t\taltKey ||\n\t\t\t\t\tmetaKey ||\n\t\t\t\t\tctrlKey\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst selectionStart = getSelectionStart();\n\t\t\t\tconst selectionEnd = getSelectionEnd();\n\t\t\t\tif (\n\t\t\t\t\tselectionStart.offset === 0 &&\n\t\t\t\t\tselectionEnd.offset === 0\n\t\t\t\t) {\n\t\t\t\t\tif ( shiftKey ) {\n\t\t\t\t\t\t// Note that backspace behaviour in defined in onMerge.\n\t\t\t\t\t\tif ( keyCode === TAB ) {\n\t\t\t\t\t\t\tif ( outdentListItem() ) {\n\t\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if ( getBlockIndex( clientId ) !== 0 ) {\n\t\t\t\t\t\tif ( indentListItem() ) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Capture phase so we run before writing-flow's ancestor-bubble\n\t\t\t// keydown handlers that gate on `event.defaultPrevented`.\n\t\t\treturn subscribeDelegatedListener(\n\t\t\t\telement,\n\t\t\t\t'keydown',\n\t\t\t\tonKeyDown,\n\t\t\t\ttrue\n\t\t\t);\n\t\t},\n\t\t[ clientId, indentListItem ]\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAGO;AACP,sBAA2B;AAC3B,0BAA0C;AAC1C,kBAA0B;AAK1B,kCAA8B;AAC9B,mCAA+B;AAC/B,yBAAuB;AAEvB,IAAM,EAAE,2BAA2B,QAAI,2BAAQ,eAAAA,WAAmB;AAEnD,SAAR,SAA2B,UAAW;AAC5C,QAAM,EAAE,mBAAmB,iBAAiB,cAAc,QACzD,uBAAW,oBAAAC,KAAiB;AAC7B,QAAM,qBAAiB,4BAAAC,SAAmB,QAAS;AACnD,QAAM,sBAAkB,6BAAAC,SAAmB;AAE3C,aAAO;AAAA,IACN,CAAE,YAAa;AACd,eAAS,UAAW,OAAQ;AAC3B,cAAM,EAAE,SAAS,UAAU,QAAQ,SAAS,QAAQ,IAAI;AAExD,YACC,MAAM,oBACJ,YAAY,yBAAS,YAAY;AAAA,QAEnC,UACA,WACA,SACC;AACD;AAAA,QACD;AAEA,cAAM,iBAAiB,kBAAkB;AACzC,cAAM,eAAe,gBAAgB;AACrC,YACC,eAAe,WAAW,KAC1B,aAAa,WAAW,GACvB;AACD,cAAK,UAAW;AAEf,gBAAK,YAAY,qBAAM;AACtB,kBAAK,gBAAgB,GAAI;AACxB,sBAAM,eAAe;AAAA,cACtB;AAAA,YACD;AAAA,UACD,WAAY,cAAe,QAAS,MAAM,GAAI;AAC7C,gBAAK,eAAe,GAAI;AACvB,oBAAM,eAAe;AAAA,YACtB;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAIA,aAAO;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,UAAU,cAAe;AAAA,EAC5B;AACD;",
|
|
6
|
+
"names": ["composePrivateApis", "blockEditorStore", "useIndentListItem", "useOutdentListItem"]
|
|
7
7
|
}
|
|
@@ -146,7 +146,8 @@ function NavigationLinkEdit({
|
|
|
146
146
|
const handleLinkChange = (0, import_shared.useHandleLinkChange)({
|
|
147
147
|
clientId,
|
|
148
148
|
attributes,
|
|
149
|
-
setAttributes
|
|
149
|
+
setAttributes,
|
|
150
|
+
allowTextUpdate: true
|
|
150
151
|
});
|
|
151
152
|
const [isInvalid, isDraft] = (0, import_shared.useIsInvalidLink)(
|
|
152
153
|
kind,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/navigation-link/edit.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tRichText,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\tgetColorClassName,\n\tuseInnerBlocksProps,\n} from '@wordpress/block-editor';\nimport { isURL, prependHTTP } from '@wordpress/url';\nimport { useState, useEffect, useRef, useCallback } from '@wordpress/element';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { link as linkIcon, addSubmenu } from '@wordpress/icons';\nimport { useMergeRefs, useInstanceId } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getColors } from '../navigation/edit/utils';\nimport {\n\tControls,\n\tLinkUI,\n\tuseEntityBinding,\n\tgetInvalidLinkHelpText,\n\tuseHandleLinkChange,\n\tuseIsInvalidLink,\n\tInvalidDraftDisplay,\n\tuseEnableLinkStatusValidation,\n\tuseIsDraggingWithin,\n\tselectLabelText,\n} from './shared';\n\nconst DEFAULT_BLOCK = { name: 'core/navigation-link' };\nconst NESTING_BLOCK_NAMES = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n];\n\nfunction getMissingText( type ) {\n\tlet missingText = '';\n\n\tswitch ( type ) {\n\t\tcase 'post':\n\t\t\t/* translators: label for missing post in navigation link block */\n\t\t\tmissingText = __( 'Select post' );\n\t\t\tbreak;\n\t\tcase 'page':\n\t\t\t/* translators: label for missing page in navigation link block */\n\t\t\tmissingText = __( 'Select page' );\n\t\t\tbreak;\n\t\tcase 'category':\n\t\t\t/* translators: label for missing category in navigation link block */\n\t\t\tmissingText = __( 'Select category' );\n\t\t\tbreak;\n\t\tcase 'tag':\n\t\t\t/* translators: label for missing tag in navigation link block */\n\t\t\tmissingText = __( 'Select tag' );\n\t\t\tbreak;\n\t\tdefault:\n\t\t\t/* translators: label for missing values in navigation link block */\n\t\t\tmissingText = __( 'Add link' );\n\t}\n\n\treturn missingText;\n}\n\nexport default function NavigationLinkEdit( {\n\tattributes,\n\tisSelected,\n\tsetAttributes,\n\tinsertBlocksAfter,\n\tmergeBlocks,\n\tonReplace,\n\tcontext,\n\tclientId,\n} ) {\n\tconst { id, label, type, url, description, kind, metadata } = attributes;\n\tconst { maxNestingLevel } = context;\n\n\tconst {\n\t\treplaceBlock,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\tselectBlock,\n\t} = useDispatch( blockEditorStore );\n\t// Have the link editing ui open on mount when lacking a url and selected.\n\tconst [ isLinkOpen, setIsLinkOpen ] = useState( isSelected && ! url );\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\tconst listItemRef = useRef( null );\n\tconst isDraggingWithin = useIsDraggingWithin( listItemRef );\n\tconst itemLabelPlaceholder = __( 'Add label\u2026' );\n\tconst ref = useRef();\n\tconst linkUIref = useRef();\n\t// A link is \"new\" only if it has an undefined label\n\t// After the link is created, even if no label is provided, it's set to an empty string.\n\tconst isNewLink = useRef( label === undefined );\n\t// Track whether we should focus the submenu appender when closing the link UI\n\tconst shouldSelectSubmenuAppenderOnClose = useRef( false );\n\n\tconst {\n\t\tisAtMaxNesting,\n\t\tisTopLevelLink,\n\t\tisParentOfSelectedBlock,\n\t\thasChildren,\n\t\tparentBlockClientId,\n\t\tisSubmenu,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockCount,\n\t\t\t\tgetBlockName,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\thasSelectedInnerBlock,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\t\t\tconst parentBlockName = getBlockName( rootClientId );\n\t\t\tconst isTopLevel = parentBlockName === 'core/navigation';\n\t\t\tconst rootNavigationClientId = isTopLevel\n\t\t\t\t? rootClientId\n\t\t\t\t: getBlockParentsByBlockName(\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t'core/navigation'\n\t\t\t\t )[ 0 ];\n\n\t\t\t// Get the immediate parent - if it's a submenu, use it; otherwise use the navigation block\n\t\t\tconst parentBlockId =\n\t\t\t\tparentBlockName === 'core/navigation-submenu'\n\t\t\t\t\t? rootClientId\n\t\t\t\t\t: rootNavigationClientId;\n\n\t\t\treturn {\n\t\t\t\tisAtMaxNesting:\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, NESTING_BLOCK_NAMES )\n\t\t\t\t\t\t.length >= maxNestingLevel,\n\t\t\t\tisTopLevelLink: isTopLevel,\n\t\t\t\tisParentOfSelectedBlock: hasSelectedInnerBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\ttrue\n\t\t\t\t),\n\t\t\t\thasChildren: !! getBlockCount( clientId ),\n\t\t\t\tparentBlockClientId: parentBlockId,\n\t\t\t\tisSubmenu: parentBlockName === 'core/navigation-submenu',\n\t\t\t};\n\t\t},\n\t\t[ clientId, maxNestingLevel ]\n\t);\n\n\tconst validateLinkStatus = useEnableLinkStatusValidation( clientId );\n\tconst { getBlocks } = useSelect( blockEditorStore );\n\n\t// URL binding logic\n\tconst { hasUrlBinding, isBoundEntityAvailable, entityRecord } =\n\t\tuseEntityBinding( {\n\t\t\tclientId,\n\t\t\tattributes,\n\t\t} );\n\n\tconst handleLinkChange = useHandleLinkChange( {\n\t\tclientId,\n\t\tattributes,\n\t\tsetAttributes,\n\t} );\n\n\tconst [ isInvalid, isDraft ] = useIsInvalidLink(\n\t\tkind,\n\t\ttype,\n\t\tid,\n\t\tvalidateLinkStatus\n\t);\n\n\t/**\n\t * Transform to submenu block.\n\t */\n\tconst transformToSubmenu = useCallback( () => {\n\t\tlet innerBlocks = getBlocks( clientId );\n\t\tif ( innerBlocks.length === 0 ) {\n\t\t\tinnerBlocks = [ createBlock( 'core/navigation-link' ) ];\n\t\t\tselectBlock( innerBlocks[ 0 ].clientId );\n\t\t}\n\t\tconst newSubmenu = createBlock(\n\t\t\t'core/navigation-submenu',\n\t\t\tattributes,\n\t\t\tinnerBlocks\n\t\t);\n\t\treplaceBlock( clientId, newSubmenu );\n\t}, [ getBlocks, clientId, selectBlock, replaceBlock, attributes ] );\n\n\t// On mount, if this is a new link without a URL and it's selected,\n\t// select the parent block (submenu or navigation) instead to keep the appender visible.\n\t// This helps us return focus to the appender if the user closes the link ui without creating a link.\n\t// If we leave focus on this block, then when we close the link without creating a link, focus will\n\t// be lost during the new block selection process.\n\tuseEffect( () => {\n\t\tif ( isNewLink.current && isSelected ) {\n\t\t\tselectBlock( parentBlockClientId );\n\t\t}\n\t}, [] ); // eslint-disable-line react-hooks/exhaustive-deps\n\n\tuseEffect( () => {\n\t\t// If block has inner blocks, transform to Submenu.\n\t\tif ( hasChildren ) {\n\t\t\t// This side-effect should not create an undo level as those should\n\t\t\t// only be created via user interactions.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\ttransformToSubmenu();\n\t\t}\n\t}, [\n\t\thasChildren,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\ttransformToSubmenu,\n\t] );\n\n\t// Handle link UI when a new link is created\n\tuseEffect( () => {\n\t\t// We know if a link was just created from our link UI if\n\t\t// 1. isNewLink.current is true\n\t\t// 2. url has a value\n\t\t// 3. isLinkOpen is true\n\t\tif ( ! isNewLink.current || ! url || ! isLinkOpen ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Ensure this only runs once\n\t\tisNewLink.current = false;\n\n\t\t// We just created a link and the block is now selected.\n\t\t// If the label looks like a URL, focus and select the label text.\n\t\tif ( isURL( prependHTTP( label ) ) && /^.+\\.[a-z]+/.test( label ) ) {\n\t\t\t// Focus and select the label text.\n\t\t\tselectLabelText( ref );\n\t\t} else {\n\t\t\t// If the link was just created, we want to select the block so the inspector controls\n\t\t\t// are accurate.\n\t\t\tselectBlock( clientId, null );\n\n\t\t\t// Edge case: When the created link is the first child of a submenu, the focus will have\n\t\t\t// originated from the add submenu toolbar button. In this case, we need to return focus\n\t\t\t// to the submenu appender if the user closes the link ui using the keyboard.\n\t\t\t// Check if this is the first and only child of a newly created submenu.\n\t\t\tif ( isSubmenu ) {\n\t\t\t\tconst parentBlocks = getBlocks( parentBlockClientId );\n\t\t\t\t// If this is the only child, then this is a new submenu.\n\t\t\t\t// Set the flag to select the submenu appender when the link ui is closed.\n\t\t\t\tif (\n\t\t\t\t\tparentBlocks.length === 1 &&\n\t\t\t\t\tparentBlocks[ 0 ].clientId === clientId\n\t\t\t\t) {\n\t\t\t\t\tshouldSelectSubmenuAppenderOnClose.current = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [ url, isLinkOpen, isNewLink, label ] );\n\n\t/**\n\t * Removes the current link if set.\n\t */\n\tfunction removeLink() {\n\t\t// Reset all attributes that comprise the link.\n\t\t// It is critical that all attributes are reset\n\t\t// to their default values otherwise this may\n\t\t// in advertently trigger side effects because\n\t\t// the values will have \"changed\".\n\t\tsetAttributes( {\n\t\t\turl: undefined,\n\t\t\tlabel: undefined,\n\t\t\tid: undefined,\n\t\t\tkind: undefined,\n\t\t\ttype: undefined,\n\t\t\topensInNewTab: false,\n\t\t} );\n\n\t\t// Close the link editing UI.\n\t\tsetIsLinkOpen( false );\n\t}\n\n\tconst {\n\t\ttextColor,\n\t\tcustomTextColor,\n\t\tbackgroundColor,\n\t\tcustomBackgroundColor,\n\t} = getColors( context, ! isTopLevelLink );\n\n\tfunction onKeyDown( event ) {\n\t\tif ( isKeyboardEvent.primary( event, 'k' ) ) {\n\t\t\t// Required to prevent the command center from opening,\n\t\t\t// as it shares the CMD+K shortcut.\n\t\t\t// See https://github.com/WordPress/gutenberg/pull/59845.\n\t\t\tevent.preventDefault();\n\t\t\t// If this link is a child of a parent submenu item, the parent submenu item event will also open, closing this popover\n\t\t\tevent.stopPropagation();\n\t\t\tsetIsLinkOpen( true );\n\t\t}\n\t}\n\n\tconst instanceId = useInstanceId( NavigationLinkEdit );\n\tconst hasMissingEntity = hasUrlBinding && ! isBoundEntityAvailable;\n\tconst missingEntityDescriptionId = hasMissingEntity\n\t\t? sprintf( 'navigation-link-edit-%d-desc', instanceId )\n\t\t: undefined;\n\n\tconst blockProps = useBlockProps( {\n\t\tref: useMergeRefs( [ setPopoverAnchor, listItemRef ] ),\n\t\tclassName: clsx( 'wp-block-navigation-item', {\n\t\t\t'is-editing': isSelected || isParentOfSelectedBlock,\n\t\t\t'is-dragging-within': isDraggingWithin,\n\t\t\t'has-link': !! url,\n\t\t\t'has-child': hasChildren,\n\t\t\t'has-text-color': !! textColor || !! customTextColor,\n\t\t\t[ getColorClassName( 'color', textColor ) ]: !! textColor,\n\t\t\t'has-background': !! backgroundColor || customBackgroundColor,\n\t\t\t[ getColorClassName( 'background-color', backgroundColor ) ]:\n\t\t\t\t!! backgroundColor,\n\t\t} ),\n\t\t'aria-describedby': missingEntityDescriptionId,\n\t\t'aria-invalid': hasMissingEntity,\n\t\tstyle: {\n\t\t\tcolor: ! textColor && customTextColor,\n\t\t\tbackgroundColor: ! backgroundColor && customBackgroundColor,\n\t\t},\n\t\tonKeyDown,\n\t} );\n\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{\n\t\t\t...blockProps,\n\t\t\tclassName: 'remove-outline', // Remove the outline from the inner blocks container.\n\t\t},\n\t\t{\n\t\t\tdefaultBlock: DEFAULT_BLOCK,\n\t\t\tdirectInsert: true,\n\t\t\trenderAppender: false,\n\t\t}\n\t);\n\n\tconst needsValidLink =\n\t\t( ! url && ! ( hasUrlBinding && isBoundEntityAvailable ) ) ||\n\t\tisInvalid ||\n\t\tisDraft ||\n\t\t( hasUrlBinding && ! isBoundEntityAvailable );\n\n\tif ( needsValidLink ) {\n\t\tblockProps.onClick = () => {\n\t\t\tsetIsLinkOpen( true );\n\t\t};\n\t}\n\n\tconst classes = clsx( 'wp-block-navigation-item__content', {\n\t\t'wp-block-navigation-link__placeholder': needsValidLink,\n\t} );\n\n\tconst missingText = getMissingText( type );\n\tconst invalidLinkHelpText = getInvalidLinkHelpText();\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\tshortcut={ displayShortcut.primary( 'k' ) }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetIsLinkOpen( true );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t{ ! isAtMaxNesting && (\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tname=\"submenu\"\n\t\t\t\t\t\t\ticon={ addSubmenu }\n\t\t\t\t\t\t\ttitle={ __( 'Add submenu' ) }\n\t\t\t\t\t\t\tonClick={ transformToSubmenu }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls group=\"content\">\n\t\t\t\t<Controls\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ hasMissingEntity && (\n\t\t\t\t\t<VisuallyHidden id={ missingEntityDescriptionId }>\n\t\t\t\t\t\t{ invalidLinkHelpText }\n\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t) }\n\t\t\t\t{ /* eslint-disable jsx-a11y/anchor-is-valid */ }\n\t\t\t\t<a className={ classes }>\n\t\t\t\t\t{ /* eslint-enable */ }\n\t\t\t\t\t{ ! url && ! metadata?.bindings?.url ? (\n\t\t\t\t\t\t<div className=\"wp-block-navigation-link__placeholder-text\">\n\t\t\t\t\t\t\t<span>{ missingText }</span>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t{ ! isInvalid && ! isDraft && (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\t\t\t\t\tidentifier=\"label\"\n\t\t\t\t\t\t\t\t\t\tclassName=\"wp-block-navigation-item__label\"\n\t\t\t\t\t\t\t\t\t\tvalue={ label }\n\t\t\t\t\t\t\t\t\t\tonChange={ ( labelValue ) =>\n\t\t\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\t\t\tlabel: labelValue,\n\t\t\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\t\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\t\t\t\t\t\t__unstableOnSplitAtEnd={ () =>\n\t\t\t\t\t\t\t\t\t\t\tinsertBlocksAfter(\n\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t\t\t\t\t\t\t'core/navigation-link'\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\taria-label={ __(\n\t\t\t\t\t\t\t\t\t\t\t'Navigation link text'\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tplaceholder={ itemLabelPlaceholder }\n\t\t\t\t\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t{ description && (\n\t\t\t\t\t\t\t\t\t\t<span className=\"wp-block-navigation-item__description\">\n\t\t\t\t\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t\t\t\t\t</span>\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) }\n\t\t\t\t\t\t\t{ ( isInvalid || isDraft ) && (\n\t\t\t\t\t\t\t\t<InvalidDraftDisplay\n\t\t\t\t\t\t\t\t\tlabel={ label }\n\t\t\t\t\t\t\t\t\tisInvalid={ isInvalid }\n\t\t\t\t\t\t\t\t\tisDraft={ isDraft }\n\t\t\t\t\t\t\t\t\tclassName=\"wp-block-navigation-link__label\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t\t{ isLinkOpen && (\n\t\t\t\t\t\t<LinkUI\n\t\t\t\t\t\t\tref={ linkUIref }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tlink={ attributes }\n\t\t\t\t\t\t\tentity={ {\n\t\t\t\t\t\t\t\tentityRecord,\n\t\t\t\t\t\t\t\thasBinding: hasUrlBinding,\n\t\t\t\t\t\t\t\tisEntityAvailable: isBoundEntityAvailable,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\t\t\tsetIsLinkOpen( false );\n\t\t\t\t\t\t\t\t// If there is no link and no binding, remove the auto-inserted block.\n\t\t\t\t\t\t\t\t// This avoids empty blocks which can provided a poor UX.\n\t\t\t\t\t\t\t\t// Don't remove if binding exists (even if entity is unavailable) so user can fix it.\n\t\t\t\t\t\t\t\tif ( ! url && ! hasUrlBinding ) {\n\t\t\t\t\t\t\t\t\tonReplace( [] );\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// Edge case: If this is the first child of a new submenu, focus the submenu's appender\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tshouldSelectSubmenuAppenderOnClose.current\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tshouldSelectSubmenuAppenderOnClose.current = false;\n\n\t\t\t\t\t\t\t\t\t// The appender is the next sibling in the DOM after the current block\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tlistItemRef.current?.nextElementSibling\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\tconst appenderButton =\n\t\t\t\t\t\t\t\t\t\t\tlistItemRef.current.nextElementSibling.querySelector(\n\t\t\t\t\t\t\t\t\t\t\t\t'.block-editor-button-block-appender'\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\tif ( appenderButton ) {\n\t\t\t\t\t\t\t\t\t\t\tappenderButton.focus();\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} }\n\t\t\t\t\t\t\tanchor={ popoverAnchor }\n\t\t\t\t\t\t\tonRemove={ removeLink }\n\t\t\t\t\t\t\tonChange={ handleLinkChange }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</a>\n\t\t\t\t<div { ...innerBlocksProps } />\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,oBAA4B;AAC5B,kBAAuC;AACvC,wBAA4C;AAC5C,sBAAiD;AACjD,kBAA4B;AAC5B,0BAQO;AACP,iBAAmC;AACnC,qBAAyD;AACzD,gBAA+B;AAC/B,mBAA6C;AAC7C,qBAA4C;AAK5C,mBAA0B;AAC1B,oBAWO;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { createBlock } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tRichText,\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\tgetColorClassName,\n\tuseInnerBlocksProps,\n} from '@wordpress/block-editor';\nimport { isURL, prependHTTP } from '@wordpress/url';\nimport { useState, useEffect, useRef, useCallback } from '@wordpress/element';\nimport { VisuallyHidden } from '@wordpress/ui';\nimport { link as linkIcon, addSubmenu } from '@wordpress/icons';\nimport { useMergeRefs, useInstanceId } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { getColors } from '../navigation/edit/utils';\nimport {\n\tControls,\n\tLinkUI,\n\tuseEntityBinding,\n\tgetInvalidLinkHelpText,\n\tuseHandleLinkChange,\n\tuseIsInvalidLink,\n\tInvalidDraftDisplay,\n\tuseEnableLinkStatusValidation,\n\tuseIsDraggingWithin,\n\tselectLabelText,\n} from './shared';\n\nconst DEFAULT_BLOCK = { name: 'core/navigation-link' };\nconst NESTING_BLOCK_NAMES = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n];\n\nfunction getMissingText( type ) {\n\tlet missingText = '';\n\n\tswitch ( type ) {\n\t\tcase 'post':\n\t\t\t/* translators: label for missing post in navigation link block */\n\t\t\tmissingText = __( 'Select post' );\n\t\t\tbreak;\n\t\tcase 'page':\n\t\t\t/* translators: label for missing page in navigation link block */\n\t\t\tmissingText = __( 'Select page' );\n\t\t\tbreak;\n\t\tcase 'category':\n\t\t\t/* translators: label for missing category in navigation link block */\n\t\t\tmissingText = __( 'Select category' );\n\t\t\tbreak;\n\t\tcase 'tag':\n\t\t\t/* translators: label for missing tag in navigation link block */\n\t\t\tmissingText = __( 'Select tag' );\n\t\t\tbreak;\n\t\tdefault:\n\t\t\t/* translators: label for missing values in navigation link block */\n\t\t\tmissingText = __( 'Add link' );\n\t}\n\n\treturn missingText;\n}\n\nexport default function NavigationLinkEdit( {\n\tattributes,\n\tisSelected,\n\tsetAttributes,\n\tinsertBlocksAfter,\n\tmergeBlocks,\n\tonReplace,\n\tcontext,\n\tclientId,\n} ) {\n\tconst { id, label, type, url, description, kind, metadata } = attributes;\n\tconst { maxNestingLevel } = context;\n\n\tconst {\n\t\treplaceBlock,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\tselectBlock,\n\t} = useDispatch( blockEditorStore );\n\t// Have the link editing ui open on mount when lacking a url and selected.\n\tconst [ isLinkOpen, setIsLinkOpen ] = useState( isSelected && ! url );\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState( null );\n\tconst listItemRef = useRef( null );\n\tconst isDraggingWithin = useIsDraggingWithin( listItemRef );\n\tconst itemLabelPlaceholder = __( 'Add label\u2026' );\n\tconst ref = useRef();\n\tconst linkUIref = useRef();\n\t// A link is \"new\" only if it has an undefined label\n\t// After the link is created, even if no label is provided, it's set to an empty string.\n\tconst isNewLink = useRef( label === undefined );\n\t// Track whether we should focus the submenu appender when closing the link UI\n\tconst shouldSelectSubmenuAppenderOnClose = useRef( false );\n\n\tconst {\n\t\tisAtMaxNesting,\n\t\tisTopLevelLink,\n\t\tisParentOfSelectedBlock,\n\t\thasChildren,\n\t\tparentBlockClientId,\n\t\tisSubmenu,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockCount,\n\t\t\t\tgetBlockName,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\thasSelectedInnerBlock,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\t\t\tconst parentBlockName = getBlockName( rootClientId );\n\t\t\tconst isTopLevel = parentBlockName === 'core/navigation';\n\t\t\tconst rootNavigationClientId = isTopLevel\n\t\t\t\t? rootClientId\n\t\t\t\t: getBlockParentsByBlockName(\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t'core/navigation'\n\t\t\t\t )[ 0 ];\n\n\t\t\t// Get the immediate parent - if it's a submenu, use it; otherwise use the navigation block\n\t\t\tconst parentBlockId =\n\t\t\t\tparentBlockName === 'core/navigation-submenu'\n\t\t\t\t\t? rootClientId\n\t\t\t\t\t: rootNavigationClientId;\n\n\t\t\treturn {\n\t\t\t\tisAtMaxNesting:\n\t\t\t\t\tgetBlockParentsByBlockName( clientId, NESTING_BLOCK_NAMES )\n\t\t\t\t\t\t.length >= maxNestingLevel,\n\t\t\t\tisTopLevelLink: isTopLevel,\n\t\t\t\tisParentOfSelectedBlock: hasSelectedInnerBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\ttrue\n\t\t\t\t),\n\t\t\t\thasChildren: !! getBlockCount( clientId ),\n\t\t\t\tparentBlockClientId: parentBlockId,\n\t\t\t\tisSubmenu: parentBlockName === 'core/navigation-submenu',\n\t\t\t};\n\t\t},\n\t\t[ clientId, maxNestingLevel ]\n\t);\n\n\tconst validateLinkStatus = useEnableLinkStatusValidation( clientId );\n\tconst { getBlocks } = useSelect( blockEditorStore );\n\n\t// URL binding logic\n\tconst { hasUrlBinding, isBoundEntityAvailable, entityRecord } =\n\t\tuseEntityBinding( {\n\t\t\tclientId,\n\t\t\tattributes,\n\t\t} );\n\n\tconst handleLinkChange = useHandleLinkChange( {\n\t\tclientId,\n\t\tattributes,\n\t\tsetAttributes,\n\t\tallowTextUpdate: true,\n\t} );\n\n\tconst [ isInvalid, isDraft ] = useIsInvalidLink(\n\t\tkind,\n\t\ttype,\n\t\tid,\n\t\tvalidateLinkStatus\n\t);\n\n\t/**\n\t * Transform to submenu block.\n\t */\n\tconst transformToSubmenu = useCallback( () => {\n\t\tlet innerBlocks = getBlocks( clientId );\n\t\tif ( innerBlocks.length === 0 ) {\n\t\t\tinnerBlocks = [ createBlock( 'core/navigation-link' ) ];\n\t\t\tselectBlock( innerBlocks[ 0 ].clientId );\n\t\t}\n\t\tconst newSubmenu = createBlock(\n\t\t\t'core/navigation-submenu',\n\t\t\tattributes,\n\t\t\tinnerBlocks\n\t\t);\n\t\treplaceBlock( clientId, newSubmenu );\n\t}, [ getBlocks, clientId, selectBlock, replaceBlock, attributes ] );\n\n\t// On mount, if this is a new link without a URL and it's selected,\n\t// select the parent block (submenu or navigation) instead to keep the appender visible.\n\t// This helps us return focus to the appender if the user closes the link ui without creating a link.\n\t// If we leave focus on this block, then when we close the link without creating a link, focus will\n\t// be lost during the new block selection process.\n\tuseEffect( () => {\n\t\tif ( isNewLink.current && isSelected ) {\n\t\t\tselectBlock( parentBlockClientId );\n\t\t}\n\t}, [] ); // eslint-disable-line react-hooks/exhaustive-deps\n\n\tuseEffect( () => {\n\t\t// If block has inner blocks, transform to Submenu.\n\t\tif ( hasChildren ) {\n\t\t\t// This side-effect should not create an undo level as those should\n\t\t\t// only be created via user interactions.\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\ttransformToSubmenu();\n\t\t}\n\t}, [\n\t\thasChildren,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\ttransformToSubmenu,\n\t] );\n\n\t// Handle link UI when a new link is created\n\tuseEffect( () => {\n\t\t// We know if a link was just created from our link UI if\n\t\t// 1. isNewLink.current is true\n\t\t// 2. url has a value\n\t\t// 3. isLinkOpen is true\n\t\tif ( ! isNewLink.current || ! url || ! isLinkOpen ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Ensure this only runs once\n\t\tisNewLink.current = false;\n\n\t\t// We just created a link and the block is now selected.\n\t\t// If the label looks like a URL, focus and select the label text.\n\t\tif ( isURL( prependHTTP( label ) ) && /^.+\\.[a-z]+/.test( label ) ) {\n\t\t\t// Focus and select the label text.\n\t\t\tselectLabelText( ref );\n\t\t} else {\n\t\t\t// If the link was just created, we want to select the block so the inspector controls\n\t\t\t// are accurate.\n\t\t\tselectBlock( clientId, null );\n\n\t\t\t// Edge case: When the created link is the first child of a submenu, the focus will have\n\t\t\t// originated from the add submenu toolbar button. In this case, we need to return focus\n\t\t\t// to the submenu appender if the user closes the link ui using the keyboard.\n\t\t\t// Check if this is the first and only child of a newly created submenu.\n\t\t\tif ( isSubmenu ) {\n\t\t\t\tconst parentBlocks = getBlocks( parentBlockClientId );\n\t\t\t\t// If this is the only child, then this is a new submenu.\n\t\t\t\t// Set the flag to select the submenu appender when the link ui is closed.\n\t\t\t\tif (\n\t\t\t\t\tparentBlocks.length === 1 &&\n\t\t\t\t\tparentBlocks[ 0 ].clientId === clientId\n\t\t\t\t) {\n\t\t\t\t\tshouldSelectSubmenuAppenderOnClose.current = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [ url, isLinkOpen, isNewLink, label ] );\n\n\t/**\n\t * Removes the current link if set.\n\t */\n\tfunction removeLink() {\n\t\t// Reset all attributes that comprise the link.\n\t\t// It is critical that all attributes are reset\n\t\t// to their default values otherwise this may\n\t\t// in advertently trigger side effects because\n\t\t// the values will have \"changed\".\n\t\tsetAttributes( {\n\t\t\turl: undefined,\n\t\t\tlabel: undefined,\n\t\t\tid: undefined,\n\t\t\tkind: undefined,\n\t\t\ttype: undefined,\n\t\t\topensInNewTab: false,\n\t\t} );\n\n\t\t// Close the link editing UI.\n\t\tsetIsLinkOpen( false );\n\t}\n\n\tconst {\n\t\ttextColor,\n\t\tcustomTextColor,\n\t\tbackgroundColor,\n\t\tcustomBackgroundColor,\n\t} = getColors( context, ! isTopLevelLink );\n\n\tfunction onKeyDown( event ) {\n\t\tif ( isKeyboardEvent.primary( event, 'k' ) ) {\n\t\t\t// Required to prevent the command center from opening,\n\t\t\t// as it shares the CMD+K shortcut.\n\t\t\t// See https://github.com/WordPress/gutenberg/pull/59845.\n\t\t\tevent.preventDefault();\n\t\t\t// If this link is a child of a parent submenu item, the parent submenu item event will also open, closing this popover\n\t\t\tevent.stopPropagation();\n\t\t\tsetIsLinkOpen( true );\n\t\t}\n\t}\n\n\tconst instanceId = useInstanceId( NavigationLinkEdit );\n\tconst hasMissingEntity = hasUrlBinding && ! isBoundEntityAvailable;\n\tconst missingEntityDescriptionId = hasMissingEntity\n\t\t? sprintf( 'navigation-link-edit-%d-desc', instanceId )\n\t\t: undefined;\n\n\tconst blockProps = useBlockProps( {\n\t\tref: useMergeRefs( [ setPopoverAnchor, listItemRef ] ),\n\t\tclassName: clsx( 'wp-block-navigation-item', {\n\t\t\t'is-editing': isSelected || isParentOfSelectedBlock,\n\t\t\t'is-dragging-within': isDraggingWithin,\n\t\t\t'has-link': !! url,\n\t\t\t'has-child': hasChildren,\n\t\t\t'has-text-color': !! textColor || !! customTextColor,\n\t\t\t[ getColorClassName( 'color', textColor ) ]: !! textColor,\n\t\t\t'has-background': !! backgroundColor || customBackgroundColor,\n\t\t\t[ getColorClassName( 'background-color', backgroundColor ) ]:\n\t\t\t\t!! backgroundColor,\n\t\t} ),\n\t\t'aria-describedby': missingEntityDescriptionId,\n\t\t'aria-invalid': hasMissingEntity,\n\t\tstyle: {\n\t\t\tcolor: ! textColor && customTextColor,\n\t\t\tbackgroundColor: ! backgroundColor && customBackgroundColor,\n\t\t},\n\t\tonKeyDown,\n\t} );\n\n\tconst innerBlocksProps = useInnerBlocksProps(\n\t\t{\n\t\t\t...blockProps,\n\t\t\tclassName: 'remove-outline', // Remove the outline from the inner blocks container.\n\t\t},\n\t\t{\n\t\t\tdefaultBlock: DEFAULT_BLOCK,\n\t\t\tdirectInsert: true,\n\t\t\trenderAppender: false,\n\t\t}\n\t);\n\n\tconst needsValidLink =\n\t\t( ! url && ! ( hasUrlBinding && isBoundEntityAvailable ) ) ||\n\t\tisInvalid ||\n\t\tisDraft ||\n\t\t( hasUrlBinding && ! isBoundEntityAvailable );\n\n\tif ( needsValidLink ) {\n\t\tblockProps.onClick = () => {\n\t\t\tsetIsLinkOpen( true );\n\t\t};\n\t}\n\n\tconst classes = clsx( 'wp-block-navigation-item__content', {\n\t\t'wp-block-navigation-link__placeholder': needsValidLink,\n\t} );\n\n\tconst missingText = getMissingText( type );\n\tconst invalidLinkHelpText = getInvalidLinkHelpText();\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\tshortcut={ displayShortcut.primary( 'k' ) }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetIsLinkOpen( true );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t{ ! isAtMaxNesting && (\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tname=\"submenu\"\n\t\t\t\t\t\t\ticon={ addSubmenu }\n\t\t\t\t\t\t\ttitle={ __( 'Add submenu' ) }\n\t\t\t\t\t\t\tonClick={ transformToSubmenu }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls group=\"content\">\n\t\t\t\t<Controls\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ hasMissingEntity && (\n\t\t\t\t\t<VisuallyHidden id={ missingEntityDescriptionId }>\n\t\t\t\t\t\t{ invalidLinkHelpText }\n\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t) }\n\t\t\t\t{ /* eslint-disable jsx-a11y/anchor-is-valid */ }\n\t\t\t\t<a className={ classes }>\n\t\t\t\t\t{ /* eslint-enable */ }\n\t\t\t\t\t{ ! url && ! metadata?.bindings?.url ? (\n\t\t\t\t\t\t<div className=\"wp-block-navigation-link__placeholder-text\">\n\t\t\t\t\t\t\t<span>{ missingText }</span>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t{ ! isInvalid && ! isDraft && (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\t\t\t\t\tidentifier=\"label\"\n\t\t\t\t\t\t\t\t\t\tclassName=\"wp-block-navigation-item__label\"\n\t\t\t\t\t\t\t\t\t\tvalue={ label }\n\t\t\t\t\t\t\t\t\t\tonChange={ ( labelValue ) =>\n\t\t\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\t\t\tlabel: labelValue,\n\t\t\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\t\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\t\t\t\t\t\t__unstableOnSplitAtEnd={ () =>\n\t\t\t\t\t\t\t\t\t\t\tinsertBlocksAfter(\n\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t\t\t\t\t\t\t'core/navigation-link'\n\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\taria-label={ __(\n\t\t\t\t\t\t\t\t\t\t\t'Navigation link text'\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\tplaceholder={ itemLabelPlaceholder }\n\t\t\t\t\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t{ description && (\n\t\t\t\t\t\t\t\t\t\t<span className=\"wp-block-navigation-item__description\">\n\t\t\t\t\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t\t\t\t\t</span>\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) }\n\t\t\t\t\t\t\t{ ( isInvalid || isDraft ) && (\n\t\t\t\t\t\t\t\t<InvalidDraftDisplay\n\t\t\t\t\t\t\t\t\tlabel={ label }\n\t\t\t\t\t\t\t\t\tisInvalid={ isInvalid }\n\t\t\t\t\t\t\t\t\tisDraft={ isDraft }\n\t\t\t\t\t\t\t\t\tclassName=\"wp-block-navigation-link__label\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t\t{ isLinkOpen && (\n\t\t\t\t\t\t<LinkUI\n\t\t\t\t\t\t\tref={ linkUIref }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tlink={ attributes }\n\t\t\t\t\t\t\tentity={ {\n\t\t\t\t\t\t\t\tentityRecord,\n\t\t\t\t\t\t\t\thasBinding: hasUrlBinding,\n\t\t\t\t\t\t\t\tisEntityAvailable: isBoundEntityAvailable,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\t\t\tsetIsLinkOpen( false );\n\t\t\t\t\t\t\t\t// If there is no link and no binding, remove the auto-inserted block.\n\t\t\t\t\t\t\t\t// This avoids empty blocks which can provided a poor UX.\n\t\t\t\t\t\t\t\t// Don't remove if binding exists (even if entity is unavailable) so user can fix it.\n\t\t\t\t\t\t\t\tif ( ! url && ! hasUrlBinding ) {\n\t\t\t\t\t\t\t\t\tonReplace( [] );\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// Edge case: If this is the first child of a new submenu, focus the submenu's appender\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tshouldSelectSubmenuAppenderOnClose.current\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tshouldSelectSubmenuAppenderOnClose.current = false;\n\n\t\t\t\t\t\t\t\t\t// The appender is the next sibling in the DOM after the current block\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tlistItemRef.current?.nextElementSibling\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\tconst appenderButton =\n\t\t\t\t\t\t\t\t\t\t\tlistItemRef.current.nextElementSibling.querySelector(\n\t\t\t\t\t\t\t\t\t\t\t\t'.block-editor-button-block-appender'\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\tif ( appenderButton ) {\n\t\t\t\t\t\t\t\t\t\t\tappenderButton.focus();\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} }\n\t\t\t\t\t\t\tanchor={ popoverAnchor }\n\t\t\t\t\t\t\tonRemove={ removeLink }\n\t\t\t\t\t\t\tonChange={ handleLinkChange }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</a>\n\t\t\t\t<div { ...innerBlocksProps } />\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,oBAA4B;AAC5B,kBAAuC;AACvC,wBAA4C;AAC5C,sBAAiD;AACjD,kBAA4B;AAC5B,0BAQO;AACP,iBAAmC;AACnC,qBAAyD;AACzD,gBAA+B;AAC/B,mBAA6C;AAC7C,qBAA4C;AAK5C,mBAA0B;AAC1B,oBAWO;AAyUH;AAvUJ,IAAM,gBAAgB,EAAE,MAAM,uBAAuB;AACrD,IAAM,sBAAsB;AAAA,EAC3B;AAAA,EACA;AACD;AAEA,SAAS,eAAgB,MAAO;AAC/B,MAAI,cAAc;AAElB,UAAS,MAAO;AAAA,IACf,KAAK;AAEJ,wBAAc,gBAAI,aAAc;AAChC;AAAA,IACD,KAAK;AAEJ,wBAAc,gBAAI,aAAc;AAChC;AAAA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AAM;AAIrB,kBAAK,CAAE,OAAO,CAAE,eAAgB;AAC/B,0BAAW,CAAC,CAAE;AACd;AAAA,cACD;AAGA,kBACC,mCAAmC,SAClC;AACD,mDAAmC,UAAU;AAG7C,oBACC,YAAY,SAAS,oBACpB;AACD,wBAAM,iBACL,YAAY,QAAQ,mBAAmB;AAAA,oBACtC;AAAA,kBACD;AACD,sBAAK,gBAAiB;AACrB,mCAAe,MAAM;AAAA,kBACtB;AAAA,gBACD;AAAA,cACD;AAAA,YACD;AAAA,YACA,QAAS;AAAA,YACT,UAAW;AAAA,YACX,UAAW;AAAA;AAAA,QACZ;AAAA,SAEF;AAAA,MACA,4CAAC,SAAM,GAAG,kBAAmB;AAAA,OAC9B;AAAA,KACD;AAEF;",
|
|
6
6
|
"names": ["blockEditorStore", "clsx", "linkIcon"]
|
|
7
7
|
}
|
|
@@ -26,9 +26,16 @@ module.exports = __toCommonJS(use_handle_link_change_exports);
|
|
|
26
26
|
var import_element = require("@wordpress/element");
|
|
27
27
|
var import_data = require("@wordpress/data");
|
|
28
28
|
var import_block_editor = require("@wordpress/block-editor");
|
|
29
|
+
var import_dom = require("@wordpress/dom");
|
|
30
|
+
var import_escape_html = require("@wordpress/escape-html");
|
|
29
31
|
var import_update_attributes = require("./update-attributes.cjs");
|
|
30
32
|
var import_use_entity_binding = require("./use-entity-binding.cjs");
|
|
31
|
-
function useHandleLinkChange({
|
|
33
|
+
function useHandleLinkChange({
|
|
34
|
+
clientId,
|
|
35
|
+
attributes,
|
|
36
|
+
setAttributes,
|
|
37
|
+
allowTextUpdate = false
|
|
38
|
+
}) {
|
|
32
39
|
const { updateBlockAttributes } = (0, import_data.useDispatch)(import_block_editor.store);
|
|
33
40
|
const { hasUrlBinding, createBinding, clearBinding } = (0, import_use_entity_binding.useEntityBinding)({
|
|
34
41
|
clientId,
|
|
@@ -45,7 +52,11 @@ function useHandleLinkChange({ clientId, attributes, setAttributes }) {
|
|
|
45
52
|
type: updatedLink.type,
|
|
46
53
|
id: updatedLink.id
|
|
47
54
|
};
|
|
48
|
-
|
|
55
|
+
const currentText = attributes.label ? (0, import_dom.__unstableStripHTML)(attributes.label) : "";
|
|
56
|
+
const updatedText = updatedLink.title ?? "";
|
|
57
|
+
const hasTextUpdate = allowTextUpdate && updatedLink.title !== void 0 && updatedText !== currentText;
|
|
58
|
+
const textUpdateAttributes = hasTextUpdate ? { label: (0, import_escape_html.escapeHTML)(updatedText) } : {};
|
|
59
|
+
if (!attributes.label || attributes.label === "" || hasTextUpdate) {
|
|
49
60
|
attrs.title = updatedLink.title;
|
|
50
61
|
}
|
|
51
62
|
const willBeCustomLink = !updatedLink.id && hasUrlBinding;
|
|
@@ -55,7 +66,8 @@ function useHandleLinkChange({ clientId, attributes, setAttributes }) {
|
|
|
55
66
|
url: updatedLink.url,
|
|
56
67
|
kind: "custom",
|
|
57
68
|
type: "custom",
|
|
58
|
-
id: void 0
|
|
69
|
+
id: void 0,
|
|
70
|
+
...textUpdateAttributes
|
|
59
71
|
});
|
|
60
72
|
} else {
|
|
61
73
|
const { isEntityLink, attributes: updatedAttributes } = (0, import_update_attributes.updateAttributes)(attrs, setAttributes, attributes);
|
|
@@ -64,10 +76,14 @@ function useHandleLinkChange({ clientId, attributes, setAttributes }) {
|
|
|
64
76
|
} else {
|
|
65
77
|
clearBinding();
|
|
66
78
|
}
|
|
79
|
+
if (Object.keys(textUpdateAttributes).length) {
|
|
80
|
+
updateBlockAttributes(clientId, textUpdateAttributes);
|
|
81
|
+
}
|
|
67
82
|
}
|
|
68
83
|
},
|
|
69
84
|
[
|
|
70
85
|
attributes,
|
|
86
|
+
allowTextUpdate,
|
|
71
87
|
clientId,
|
|
72
88
|
hasUrlBinding,
|
|
73
89
|
createBinding,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/navigation-link/shared/use-handle-link-change.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { updateAttributes } from './update-attributes';\nimport { useEntityBinding } from './use-entity-binding';\n\n/**\n * Custom hook that returns a callback for handling link selection/change.\n * Manages the transition between entity links and custom links,\n * including proper binding creation and cleanup.\n *\n * @param {Object} options
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA4B;AAC5B,kBAA4B;AAC5B,0BAA0C;
|
|
6
|
-
"names": ["blockEditorStore"]
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { escapeHTML } from '@wordpress/escape-html';\n\n/**\n * Internal dependencies\n */\nimport { updateAttributes } from './update-attributes';\nimport { useEntityBinding } from './use-entity-binding';\n\n/**\n * Custom hook that returns a callback for handling link selection/change.\n * Manages the transition between entity links and custom links,\n * including proper binding creation and cleanup.\n *\n * @param {Object} options - Configuration options\n * @param {string} options.clientId - Block client ID\n * @param {Object} options.attributes - Current block attributes\n * @param {Function} options.setAttributes - Standard setAttribute function\n * @param {boolean} options.allowTextUpdate - Whether this control can update the link text\n * @return {Function} Callback function to handle link changes\n */\nexport function useHandleLinkChange( {\n\tclientId,\n\tattributes,\n\tsetAttributes,\n\tallowTextUpdate = false,\n} ) {\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\tconst { hasUrlBinding, createBinding, clearBinding } = useEntityBinding( {\n\t\tclientId,\n\t\tattributes,\n\t} );\n\n\treturn useCallback(\n\t\t( updatedLink ) => {\n\t\t\tif ( ! updatedLink ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst attrs = {\n\t\t\t\turl: updatedLink.url,\n\t\t\t\tkind: updatedLink.kind,\n\t\t\t\ttype: updatedLink.type,\n\t\t\t\tid: updatedLink.id,\n\t\t\t};\n\n\t\t\tconst currentText = attributes.label\n\t\t\t\t? stripHTML( attributes.label )\n\t\t\t\t: '';\n\t\t\tconst updatedText = updatedLink.title ?? '';\n\t\t\tconst hasTextUpdate =\n\t\t\t\tallowTextUpdate &&\n\t\t\t\tupdatedLink.title !== undefined &&\n\t\t\t\tupdatedText !== currentText;\n\t\t\tconst textUpdateAttributes = hasTextUpdate\n\t\t\t\t? { label: escapeHTML( updatedText ) }\n\t\t\t\t: {};\n\n\t\t\tif (\n\t\t\t\t! attributes.label ||\n\t\t\t\tattributes.label === '' ||\n\t\t\t\thasTextUpdate\n\t\t\t) {\n\t\t\t\tattrs.title = updatedLink.title;\n\t\t\t}\n\t\t\t// Check if transitioning from entity to custom link\n\t\t\tconst willBeCustomLink = ! updatedLink.id && hasUrlBinding;\n\n\t\t\tif ( willBeCustomLink ) {\n\t\t\t\t// Clear the binding first\n\t\t\t\tclearBinding();\n\n\t\t\t\t// Use direct store dispatch to bypass setBoundAttributes wrapper\n\t\t\t\t// which prevents updates to bound attributes.\n\t\t\t\tupdateBlockAttributes( clientId, {\n\t\t\t\t\turl: updatedLink.url,\n\t\t\t\t\tkind: 'custom',\n\t\t\t\t\ttype: 'custom',\n\t\t\t\t\tid: undefined,\n\t\t\t\t\t...textUpdateAttributes,\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\t// Normal flow for entity links or unbound custom links\n\t\t\t\tconst { isEntityLink, attributes: updatedAttributes } =\n\t\t\t\t\tupdateAttributes( attrs, setAttributes, attributes );\n\n\t\t\t\t// Handle URL binding based on the final computed state\n\t\t\t\t// Only create bindings for entity links (posts, pages, taxonomies)\n\t\t\t\t// Never create bindings for custom links (manual URLs)\n\t\t\t\tif ( isEntityLink ) {\n\t\t\t\t\tcreateBinding( updatedAttributes );\n\t\t\t\t} else {\n\t\t\t\t\tclearBinding();\n\t\t\t\t}\n\n\t\t\t\tif ( Object.keys( textUpdateAttributes ).length ) {\n\t\t\t\t\tupdateBlockAttributes( clientId, textUpdateAttributes );\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tattributes,\n\t\t\tallowTextUpdate,\n\t\t\tclientId,\n\t\t\thasUrlBinding,\n\t\t\tcreateBinding,\n\t\t\tclearBinding,\n\t\t\tsetAttributes,\n\t\t\tupdateBlockAttributes,\n\t\t]\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA4B;AAC5B,kBAA4B;AAC5B,0BAA0C;AAC1C,iBAAiD;AACjD,yBAA2B;AAK3B,+BAAiC;AACjC,gCAAiC;AAc1B,SAAS,oBAAqB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA,kBAAkB;AACnB,GAAI;AACH,QAAM,EAAE,sBAAsB,QAAI,yBAAa,oBAAAA,KAAiB;AAChE,QAAM,EAAE,eAAe,eAAe,aAAa,QAAI,4CAAkB;AAAA,IACxE;AAAA,IACA;AAAA,EACD,CAAE;AAEF,aAAO;AAAA,IACN,CAAE,gBAAiB;AAClB,UAAK,CAAE,aAAc;AACpB;AAAA,MACD;AAEA,YAAM,QAAQ;AAAA,QACb,KAAK,YAAY;AAAA,QACjB,MAAM,YAAY;AAAA,QAClB,MAAM,YAAY;AAAA,QAClB,IAAI,YAAY;AAAA,MACjB;AAEA,YAAM,cAAc,WAAW,YAC5B,WAAAC,qBAAW,WAAW,KAAM,IAC5B;AACH,YAAM,cAAc,YAAY,SAAS;AACzC,YAAM,gBACL,mBACA,YAAY,UAAU,UACtB,gBAAgB;AACjB,YAAM,uBAAuB,gBAC1B,EAAE,WAAO,+BAAY,WAAY,EAAE,IACnC,CAAC;AAEJ,UACC,CAAE,WAAW,SACb,WAAW,UAAU,MACrB,eACC;AACD,cAAM,QAAQ,YAAY;AAAA,MAC3B;AAEA,YAAM,mBAAmB,CAAE,YAAY,MAAM;AAE7C,UAAK,kBAAmB;AAEvB,qBAAa;AAIb,8BAAuB,UAAU;AAAA,UAChC,KAAK,YAAY;AAAA,UACjB,MAAM;AAAA,UACN,MAAM;AAAA,UACN,IAAI;AAAA,UACJ,GAAG;AAAA,QACJ,CAAE;AAAA,MACH,OAAO;AAEN,cAAM,EAAE,cAAc,YAAY,kBAAkB,QACnD,2CAAkB,OAAO,eAAe,UAAW;AAKpD,YAAK,cAAe;AACnB,wBAAe,iBAAkB;AAAA,QAClC,OAAO;AACN,uBAAa;AAAA,QACd;AAEA,YAAK,OAAO,KAAM,oBAAqB,EAAE,QAAS;AACjD,gCAAuB,UAAU,oBAAqB;AAAA,QACvD;AAAA,MACD;AAAA,IACD;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
|
+
"names": ["blockEditorStore", "stripHTML"]
|
|
7
7
|
}
|
|
@@ -68,16 +68,16 @@ function NavigationSubmenuEdit({
|
|
|
68
68
|
const { showSubmenuIcon, maxNestingLevel, submenuVisibility } = context;
|
|
69
69
|
const blockEditingMode = (0, import_block_editor.useBlockEditingMode)();
|
|
70
70
|
const openSubmenusOnClick = blockEditingMode !== "default" ? true : submenuVisibility === "click";
|
|
71
|
-
const {
|
|
72
|
-
clearBinding,
|
|
73
|
-
createBinding,
|
|
74
|
-
hasUrlBinding,
|
|
75
|
-
isBoundEntityAvailable,
|
|
76
|
-
entityRecord
|
|
77
|
-
} = (0, import_shared.useEntityBinding)({
|
|
71
|
+
const { hasUrlBinding, isBoundEntityAvailable, entityRecord } = (0, import_shared.useEntityBinding)({
|
|
78
72
|
clientId,
|
|
79
73
|
attributes
|
|
80
74
|
});
|
|
75
|
+
const handleLinkChange = (0, import_shared.useHandleLinkChange)({
|
|
76
|
+
clientId,
|
|
77
|
+
attributes,
|
|
78
|
+
setAttributes,
|
|
79
|
+
allowTextUpdate: true
|
|
80
|
+
});
|
|
81
81
|
const { __unstableMarkNextChangeAsNotPersistent, replaceBlock } = (0, import_data.useDispatch)(import_block_editor.store);
|
|
82
82
|
const [isLinkOpen, setIsLinkOpen] = (0, import_element.useState)(false);
|
|
83
83
|
const [popoverAnchor, setPopoverAnchor] = (0, import_element.useState)(null);
|
|
@@ -302,21 +302,7 @@ function NavigationSubmenuEdit({
|
|
|
302
302
|
setAttributes({ url: "" });
|
|
303
303
|
(0, import_a11y.speak)((0, import_i18n.__)("Link removed."), "assertive");
|
|
304
304
|
},
|
|
305
|
-
onChange:
|
|
306
|
-
const {
|
|
307
|
-
isEntityLink,
|
|
308
|
-
attributes: updatedAttributes
|
|
309
|
-
} = (0, import_shared.updateAttributes)(
|
|
310
|
-
updatedValue,
|
|
311
|
-
setAttributes,
|
|
312
|
-
attributes
|
|
313
|
-
);
|
|
314
|
-
if (isEntityLink) {
|
|
315
|
-
createBinding(updatedAttributes);
|
|
316
|
-
} else {
|
|
317
|
-
clearBinding();
|
|
318
|
-
}
|
|
319
|
-
}
|
|
305
|
+
onChange: handleLinkChange
|
|
320
306
|
}
|
|
321
307
|
)
|
|
322
308
|
] }),
|