@wordpress/block-library 9.40.1 → 9.40.2-next.v.202602271551.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/accordion/view.cjs +0 -34
- package/build/accordion/view.cjs.map +2 -2
- package/build/icon/block.json +9 -1
- package/build/icon/components/custom-inserter/icon-grid.cjs +1 -1
- package/build/icon/components/custom-inserter/icon-grid.cjs.map +2 -2
- package/build/icon/components/custom-inserter/index.cjs +1 -1
- package/build/icon/components/custom-inserter/index.cjs.map +2 -2
- package/build/icon/edit.cjs +15 -7
- package/build/icon/edit.cjs.map +2 -2
- package/build/image/edit.cjs +1 -1
- package/build/image/edit.cjs.map +2 -2
- package/build/navigation/edit/index.cjs +4 -2
- package/build/navigation/edit/index.cjs.map +3 -3
- package/build/navigation/edit/leaf-more-menu.cjs +68 -6
- package/build/navigation/edit/leaf-more-menu.cjs.map +3 -3
- package/build/navigation/edit/menu-inspector-controls.cjs +20 -91
- package/build/navigation/edit/menu-inspector-controls.cjs.map +3 -3
- package/build/navigation/edit/navigation-link-ui.cjs +97 -0
- package/build/navigation/edit/navigation-link-ui.cjs.map +7 -0
- package/build/navigation/edit/navigation-list-view-header.cjs +86 -0
- package/build/navigation/edit/navigation-list-view-header.cjs.map +7 -0
- package/build/navigation/edit/navigation-menu-selector.cjs +4 -2
- package/build/navigation/edit/navigation-menu-selector.cjs.map +3 -3
- package/build/navigation/edit/placeholder/index.cjs +2 -2
- package/build/navigation/edit/placeholder/index.cjs.map +3 -3
- package/build/navigation-link/shared/controls.cjs +29 -52
- package/build/navigation-link/shared/controls.cjs.map +3 -3
- package/build/navigation-link/shared/use-link-preview.cjs +7 -8
- package/build/navigation-link/shared/use-link-preview.cjs.map +2 -2
- package/build/navigation-overlay-close/edit.cjs +2 -3
- package/build/navigation-overlay-close/edit.cjs.map +2 -2
- package/build/page-list-item/edit.cjs +6 -3
- package/build/page-list-item/edit.cjs.map +2 -2
- package/build/post-navigation-link/block.json +1 -3
- package/build/post-navigation-link/deprecated.cjs +100 -0
- package/build/post-navigation-link/deprecated.cjs.map +7 -0
- package/build/post-navigation-link/edit.cjs +2 -36
- package/build/post-navigation-link/edit.cjs.map +3 -3
- package/build/post-navigation-link/index.cjs +2 -0
- package/build/post-navigation-link/index.cjs.map +3 -3
- package/build/post-title/block.json +1 -3
- package/build/post-title/deprecated.cjs +82 -1
- package/build/post-title/deprecated.cjs.map +3 -3
- package/build/post-title/edit.cjs +10 -36
- package/build/post-title/edit.cjs.map +3 -3
- package/build/pullquote/deprecated.cjs +6 -6
- package/build/pullquote/deprecated.cjs.map +2 -2
- package/build/query/block.json +1 -2
- package/build/query-title/block.json +1 -3
- package/build/query-title/deprecated.cjs +70 -1
- package/build/query-title/deprecated.cjs.map +3 -3
- package/build/query-title/edit.cjs +17 -35
- package/build/query-title/edit.cjs.map +3 -3
- package/build/site-tagline/block.json +6 -4
- package/build/site-tagline/deprecated.cjs +66 -1
- package/build/site-tagline/deprecated.cjs.map +3 -3
- package/build/site-tagline/edit.cjs +14 -28
- package/build/site-tagline/edit.cjs.map +3 -3
- package/build/site-title/block.json +1 -3
- package/build/site-title/deprecated.cjs +79 -1
- package/build/site-title/deprecated.cjs.map +3 -3
- package/build/site-title/edit.cjs +14 -30
- package/build/site-title/edit.cjs.map +3 -3
- package/build/tabs-menu-item/block.json +1 -26
- package/build/tabs-menu-item/controls.cjs +2 -100
- package/build/tabs-menu-item/controls.cjs.map +3 -3
- package/build/tabs-menu-item/edit.cjs +6 -65
- package/build/tabs-menu-item/edit.cjs.map +2 -2
- package/build/tabs-menu-item/save.cjs +1 -15
- package/build/tabs-menu-item/save.cjs.map +2 -2
- package/build-module/accordion/view.mjs +1 -35
- package/build-module/accordion/view.mjs.map +2 -2
- package/build-module/icon/block.json +9 -1
- package/build-module/icon/components/custom-inserter/icon-grid.mjs +1 -1
- package/build-module/icon/components/custom-inserter/icon-grid.mjs.map +2 -2
- package/build-module/icon/components/custom-inserter/index.mjs +1 -1
- package/build-module/icon/components/custom-inserter/index.mjs.map +2 -2
- package/build-module/icon/edit.mjs +15 -7
- package/build-module/icon/edit.mjs.map +2 -2
- package/build-module/image/edit.mjs +1 -1
- package/build-module/image/edit.mjs.map +2 -2
- package/build-module/navigation/edit/index.mjs +4 -2
- package/build-module/navigation/edit/index.mjs.map +2 -2
- package/build-module/navigation/edit/leaf-more-menu.mjs +73 -7
- package/build-module/navigation/edit/leaf-more-menu.mjs.map +2 -2
- package/build-module/navigation/edit/menu-inspector-controls.mjs +21 -101
- package/build-module/navigation/edit/menu-inspector-controls.mjs.map +2 -2
- package/build-module/navigation/edit/navigation-link-ui.mjs +76 -0
- package/build-module/navigation/edit/navigation-link-ui.mjs.map +7 -0
- package/build-module/navigation/edit/navigation-list-view-header.mjs +58 -0
- package/build-module/navigation/edit/navigation-list-view-header.mjs.map +7 -0
- package/build-module/navigation/edit/navigation-menu-selector.mjs +5 -3
- package/build-module/navigation/edit/navigation-menu-selector.mjs.map +2 -2
- package/build-module/navigation/edit/placeholder/index.mjs +2 -2
- package/build-module/navigation/edit/placeholder/index.mjs.map +2 -2
- package/build-module/navigation-link/shared/controls.mjs +29 -53
- package/build-module/navigation-link/shared/controls.mjs.map +2 -2
- package/build-module/navigation-link/shared/use-link-preview.mjs +7 -8
- package/build-module/navigation-link/shared/use-link-preview.mjs.map +2 -2
- package/build-module/navigation-overlay-close/edit.mjs +2 -3
- package/build-module/navigation-overlay-close/edit.mjs.map +2 -2
- package/build-module/page-list-item/edit.mjs +6 -3
- package/build-module/page-list-item/edit.mjs.map +2 -2
- package/build-module/post-navigation-link/block.json +1 -3
- package/build-module/post-navigation-link/deprecated.mjs +69 -0
- package/build-module/post-navigation-link/deprecated.mjs.map +7 -0
- package/build-module/post-navigation-link/edit.mjs +3 -30
- package/build-module/post-navigation-link/edit.mjs.map +2 -2
- package/build-module/post-navigation-link/index.mjs +2 -0
- package/build-module/post-navigation-link/index.mjs.map +2 -2
- package/build-module/post-title/block.json +1 -3
- package/build-module/post-title/deprecated.mjs +82 -1
- package/build-module/post-title/deprecated.mjs.map +2 -2
- package/build-module/post-title/edit.mjs +10 -27
- package/build-module/post-title/edit.mjs.map +2 -2
- package/build-module/pullquote/deprecated.mjs +6 -6
- package/build-module/pullquote/deprecated.mjs.map +2 -2
- package/build-module/query/block.json +1 -2
- package/build-module/query-title/block.json +1 -3
- package/build-module/query-title/deprecated.mjs +70 -1
- package/build-module/query-title/deprecated.mjs.map +2 -2
- package/build-module/query-title/edit.mjs +17 -36
- package/build-module/query-title/edit.mjs.map +2 -2
- package/build-module/site-tagline/block.json +6 -4
- package/build-module/site-tagline/deprecated.mjs +66 -1
- package/build-module/site-tagline/deprecated.mjs.map +2 -2
- package/build-module/site-tagline/edit.mjs +14 -29
- package/build-module/site-tagline/edit.mjs.map +2 -2
- package/build-module/site-title/block.json +1 -3
- package/build-module/site-title/deprecated.mjs +79 -1
- package/build-module/site-title/deprecated.mjs.map +2 -2
- package/build-module/site-title/edit.mjs +14 -31
- package/build-module/site-title/edit.mjs.map +2 -2
- package/build-module/tabs-menu-item/block.json +1 -26
- package/build-module/tabs-menu-item/controls.mjs +3 -104
- package/build-module/tabs-menu-item/controls.mjs.map +2 -2
- package/build-module/tabs-menu-item/edit.mjs +6 -66
- package/build-module/tabs-menu-item/edit.mjs.map +2 -2
- package/build-module/tabs-menu-item/save.mjs +1 -15
- package/build-module/tabs-menu-item/save.mjs.map +2 -2
- package/build-style/editor-rtl.css +10 -5
- package/build-style/editor.css +10 -5
- package/build-style/navigation-link/editor-rtl.css +10 -0
- package/build-style/navigation-link/editor.css +10 -0
- package/build-style/style-rtl.css +3 -12
- package/build-style/style.css +3 -12
- package/build-style/tabs-menu-item/editor-rtl.css +0 -5
- package/build-style/tabs-menu-item/editor.css +0 -5
- package/build-style/tabs-menu-item/style-rtl.css +3 -12
- package/build-style/tabs-menu-item/style.css +3 -12
- package/package.json +38 -38
- package/src/accordion/view.js +1 -44
- package/src/accordion-item/index.php +0 -1
- package/src/cover/index.php +4 -4
- package/src/icon/block.json +9 -1
- package/src/icon/components/custom-inserter/icon-grid.js +1 -1
- package/src/icon/components/custom-inserter/index.js +1 -1
- package/src/icon/edit.js +20 -10
- package/src/icon/index.php +1 -3
- package/src/image/edit.js +1 -1
- package/src/image/index.php +1 -4
- package/src/navigation/edit/index.js +4 -2
- package/src/navigation/edit/leaf-more-menu.js +86 -11
- package/src/navigation/edit/menu-inspector-controls.js +23 -142
- package/src/navigation/edit/navigation-link-ui.js +115 -0
- package/src/navigation/edit/navigation-list-view-header.js +62 -0
- package/src/navigation/edit/navigation-menu-selector.js +5 -3
- package/src/navigation/edit/placeholder/index.js +3 -2
- package/src/navigation/edit/test/navigation-menu-selector.js +23 -20
- package/src/navigation-link/editor.scss +18 -0
- package/src/navigation-link/shared/controls.js +35 -62
- package/src/navigation-link/shared/test/controls.js +5 -5
- package/src/navigation-link/shared/test/use-link-preview.test.js +10 -1
- package/src/navigation-link/shared/use-link-preview.js +13 -11
- package/src/navigation-overlay-close/edit.js +4 -3
- package/src/page-list/index.php +1 -1
- package/src/page-list-item/edit.js +8 -7
- package/src/post-featured-image/index.php +2 -4
- package/src/post-navigation-link/block.json +1 -3
- package/src/post-navigation-link/deprecated.js +72 -0
- package/src/post-navigation-link/edit.js +2 -35
- package/src/post-navigation-link/index.js +2 -0
- package/src/post-title/block.json +1 -3
- package/src/post-title/deprecated.js +86 -1
- package/src/post-title/edit.js +2 -18
- package/src/pullquote/deprecated.js +3 -3
- package/src/query/block.json +1 -2
- package/src/query-title/block.json +1 -3
- package/src/query-title/deprecated.js +74 -1
- package/src/query-title/edit.js +11 -27
- package/src/query-title/index.php +1 -1
- package/src/site-tagline/block.json +6 -4
- package/src/site-tagline/deprecated.js +70 -1
- package/src/site-tagline/edit.js +9 -22
- package/src/site-title/block.json +1 -3
- package/src/site-title/deprecated.js +83 -1
- package/src/site-title/edit.js +9 -22
- package/src/tabs-menu-item/block.json +1 -26
- package/src/tabs-menu-item/controls.js +0 -108
- package/src/tabs-menu-item/edit.js +6 -79
- package/src/tabs-menu-item/editor.scss +0 -6
- package/src/tabs-menu-item/save.js +1 -26
- package/src/tabs-menu-item/style.scss +3 -14
- package/build/navigation/use-navigation-entities.cjs +0 -67
- package/build/navigation/use-navigation-entities.cjs.map +0 -7
- package/build-module/navigation/use-navigation-entities.mjs +0 -46
- package/build-module/navigation/use-navigation-entities.mjs.map +0 -7
- package/src/navigation/use-navigation-entities.js +0 -72
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
Button,
|
|
4
4
|
__experimentalToolsPanel as ToolsPanel,
|
|
5
5
|
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
6
|
-
__experimentalHStack as HStack,
|
|
7
6
|
CheckboxControl,
|
|
8
7
|
TextControl,
|
|
9
8
|
TextareaControl
|
|
@@ -102,12 +101,8 @@ function Controls({
|
|
|
102
101
|
hasBinding: hasUrlBinding,
|
|
103
102
|
isEntityAvailable: isBoundEntityAvailable
|
|
104
103
|
});
|
|
105
|
-
const isViewableUrl = url && (!isHashLink(url) || isRelativePath(url) && !url.startsWith("/"));
|
|
104
|
+
const isViewableUrl = !!url && (!isHashLink(url) || isRelativePath(url) && !url.startsWith("/"));
|
|
106
105
|
const viewUrl = isViewableUrl && url.startsWith("/") && homeUrl ? homeUrl + url : url;
|
|
107
|
-
const entityTypeName = getEntityTypeName(
|
|
108
|
-
attributes.type,
|
|
109
|
-
attributes.kind
|
|
110
|
-
);
|
|
111
106
|
return /* @__PURE__ */ jsxs(
|
|
112
107
|
ToolsPanel,
|
|
113
108
|
{
|
|
@@ -172,53 +167,6 @@ function Controls({
|
|
|
172
167
|
)
|
|
173
168
|
}
|
|
174
169
|
),
|
|
175
|
-
url && /* @__PURE__ */ jsxs(
|
|
176
|
-
HStack,
|
|
177
|
-
{
|
|
178
|
-
className: "navigation-link-to__actions",
|
|
179
|
-
alignment: "left",
|
|
180
|
-
justify: "left",
|
|
181
|
-
style: { gridColumn: "1 / -1" },
|
|
182
|
-
children: [
|
|
183
|
-
hasUrlBinding && isBoundEntityAvailable && entityRecord?.id && attributes.kind === "post-type" && onNavigateToEntityRecord && /* @__PURE__ */ jsx(
|
|
184
|
-
Button,
|
|
185
|
-
{
|
|
186
|
-
size: "compact",
|
|
187
|
-
variant: "secondary",
|
|
188
|
-
onClick: () => {
|
|
189
|
-
onNavigateToEntityRecord({
|
|
190
|
-
postId: entityRecord.id,
|
|
191
|
-
postType: attributes.type
|
|
192
|
-
});
|
|
193
|
-
},
|
|
194
|
-
__next40pxDefaultSize: true,
|
|
195
|
-
children: sprintf(
|
|
196
|
-
/* translators: %s: entity type (e.g., "page", "post", "category") */
|
|
197
|
-
__("Edit %s"),
|
|
198
|
-
entityTypeName
|
|
199
|
-
)
|
|
200
|
-
}
|
|
201
|
-
),
|
|
202
|
-
isViewableUrl && /* @__PURE__ */ jsx(
|
|
203
|
-
Button,
|
|
204
|
-
{
|
|
205
|
-
size: "compact",
|
|
206
|
-
variant: "secondary",
|
|
207
|
-
href: viewUrl,
|
|
208
|
-
target: "_blank",
|
|
209
|
-
icon: external,
|
|
210
|
-
iconPosition: "right",
|
|
211
|
-
__next40pxDefaultSize: true,
|
|
212
|
-
children: sprintf(
|
|
213
|
-
/* translators: %s: entity type (e.g., "page", "post", "category") or "link" for external links */
|
|
214
|
-
__("View %s"),
|
|
215
|
-
attributes.kind && attributes.type && attributes.kind !== "custom" ? entityTypeName : __("link")
|
|
216
|
-
)
|
|
217
|
-
}
|
|
218
|
-
)
|
|
219
|
-
]
|
|
220
|
-
}
|
|
221
|
-
),
|
|
222
170
|
/* @__PURE__ */ jsx(
|
|
223
171
|
ToolsPanelItem,
|
|
224
172
|
{
|
|
@@ -235,6 +183,34 @@ function Controls({
|
|
|
235
183
|
}
|
|
236
184
|
)
|
|
237
185
|
}
|
|
186
|
+
),
|
|
187
|
+
!!url && hasUrlBinding && isBoundEntityAvailable && entityRecord?.id && attributes.kind === "post-type" && onNavigateToEntityRecord && /* @__PURE__ */ jsx(
|
|
188
|
+
Button,
|
|
189
|
+
{
|
|
190
|
+
variant: "secondary",
|
|
191
|
+
onClick: () => {
|
|
192
|
+
onNavigateToEntityRecord({
|
|
193
|
+
postId: entityRecord.id,
|
|
194
|
+
postType: attributes.type
|
|
195
|
+
});
|
|
196
|
+
},
|
|
197
|
+
__next40pxDefaultSize: true,
|
|
198
|
+
className: "navigation-link-to__action-button",
|
|
199
|
+
children: __("Edit")
|
|
200
|
+
}
|
|
201
|
+
),
|
|
202
|
+
isViewableUrl && /* @__PURE__ */ jsx(
|
|
203
|
+
Button,
|
|
204
|
+
{
|
|
205
|
+
variant: "secondary",
|
|
206
|
+
href: viewUrl,
|
|
207
|
+
target: "_blank",
|
|
208
|
+
icon: external,
|
|
209
|
+
iconPosition: "right",
|
|
210
|
+
__next40pxDefaultSize: true,
|
|
211
|
+
className: "navigation-link-to__action-button",
|
|
212
|
+
children: __("View")
|
|
213
|
+
}
|
|
238
214
|
)
|
|
239
215
|
] }),
|
|
240
216
|
/* @__PURE__ */ jsx(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/navigation-link/shared/controls.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalHStack as HStack,\n\tCheckboxControl,\n\tTextControl,\n\tTextareaControl,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { external } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelDropdownMenuProps } from '../../utils/hooks';\nimport { useHandleLinkChange } from './use-handle-link-change';\nimport { useEntityBinding } from './use-entity-binding';\nimport { getSuggestionsQuery } from '../link-ui';\nimport { useLinkPreview } from './use-link-preview';\nimport { useIsInvalidLink } from './use-is-invalid-link';\nimport { unlock } from '../../lock-unlock';\n\nconst { LinkPicker, isHashLink, isRelativePath } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Get a human-readable entity type name.\n *\n * @param {string} type - The entity type\n * @param {string} kind - The entity kind\n * @return {string} Human-readable entity type name\n */\nfunction getEntityTypeName( type, kind ) {\n\tif ( kind === 'post-type' ) {\n\t\tswitch ( type ) {\n\t\t\tcase 'post':\n\t\t\t\treturn __( 'post' );\n\t\t\tcase 'page':\n\t\t\t\treturn __( 'page' );\n\t\t\tdefault:\n\t\t\t\treturn type || __( 'post' );\n\t\t}\n\t}\n\tif ( kind === 'taxonomy' ) {\n\t\tswitch ( type ) {\n\t\t\tcase 'category':\n\t\t\t\treturn __( 'category' );\n\t\t\tcase 'tag':\n\t\t\t\treturn __( 'tag' );\n\t\t\tdefault:\n\t\t\t\treturn type || __( 'term' );\n\t\t}\n\t}\n\treturn type || __( 'item' );\n}\n\n/**\n * Shared Controls component for Navigation Link and Navigation Submenu blocks.\n *\n * This component provides the inspector controls (ToolsPanel) that are identical\n * between both navigation blocks.\n *\n * @param {Object} props - Component props\n * @param {Object} props.attributes - Block attributes\n * @param {Function} props.setAttributes - Function to update block attributes\n * @param {string} props.clientId - Block client ID\n * @param {boolean} props.isLinkEditable - Whether link editing should be allowed\n */\nexport function Controls( {\n\tattributes,\n\tsetAttributes,\n\tclientId,\n\tisLinkEditable = true,\n} ) {\n\tconst { label, url, description, rel, opensInNewTab } = attributes;\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\t// Use the entity binding hook for UI state (help text, link preview, etc.)\n\tconst { hasUrlBinding, isBoundEntityAvailable, entityRecord } =\n\t\tuseEntityBinding( {\n\t\t\tclientId,\n\t\t\tattributes,\n\t\t} );\n\n\tconst [ isInvalid, isDraft ] = useIsInvalidLink(\n\t\tattributes.kind,\n\t\tattributes.type,\n\t\tentityRecord?.id,\n\t\thasUrlBinding\n\t);\n\n\tlet helpText = '';\n\n\tif ( isInvalid || ( hasUrlBinding && ! isBoundEntityAvailable ) ) {\n\t\t// Show invalid link help text for:\n\t\t// 1. Invalid post-type links (trashed/deleted posts/pages) - via useIsInvalidLink\n\t\t// 2. Missing bound taxonomy entities (deleted categories/tags) - useIsInvalidLink only checks post-types\n\t\thelpText = getInvalidLinkHelpText();\n\t} else if ( isDraft ) {\n\t\thelpText = getDraftHelpText( {\n\t\t\ttype: attributes.type,\n\t\t\tkind: attributes.kind,\n\t\t} );\n\t}\n\t// Get the link change handler with built-in binding management\n\tconst handleLinkChange = useHandleLinkChange( {\n\t\tclientId,\n\t\tattributes,\n\t\tsetAttributes,\n\t} );\n\n\tconst onNavigateToEntityRecord = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings().onNavigateToEntityRecord,\n\t\t[]\n\t);\n\n\tconst homeUrl = useSelect( ( select ) => {\n\t\treturn select( coreStore ).getEntityRecord( 'root', '__unstableBase' )\n\t\t\t?.home;\n\t}, [] );\n\n\tconst blockEditingMode = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getBlockEditingMode( clientId ),\n\t\t[ clientId ]\n\t);\n\n\tconst isContentOnly = blockEditingMode === 'contentOnly';\n\n\tconst preview = useLinkPreview( {\n\t\turl,\n\t\tentityRecord,\n\t\ttype: attributes.type,\n\t\thasBinding: hasUrlBinding,\n\t\tisEntityAvailable: isBoundEntityAvailable,\n\t} );\n\n\t// Check if URL is viewable (not hash link or other relative path like ./ or ../)\n\tconst isViewableUrl =\n\t\turl &&\n\t\t( ! isHashLink( url ) ||\n\t\t\t( isRelativePath( url ) && ! url.startsWith( '/' ) ) );\n\n\t// Construct full URL for viewing (prepend home URL for absolute paths starting with /)\n\tconst viewUrl =\n\t\tisViewableUrl && url.startsWith( '/' ) && homeUrl ? homeUrl + url : url;\n\n\tconst entityTypeName = getEntityTypeName(\n\t\tattributes.type,\n\t\tattributes.kind\n\t);\n\n\treturn (\n\t\t<ToolsPanel\n\t\t\tlabel={ __( 'Settings' ) }\n\t\t\tresetAll={ () => {\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tlabel: '',\n\t\t\t\t\turl: '',\n\t\t\t\t\tdescription: '',\n\t\t\t\t\trel: '',\n\t\t\t\t\topensInNewTab: false,\n\t\t\t\t} );\n\t\t\t} }\n\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t>\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => !! label }\n\t\t\t\tlabel={ __( 'Text' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { label: '' } ) }\n\t\t\t\tisShownByDefault\n\t\t\t>\n\t\t\t\t<TextControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'Text' ) }\n\t\t\t\t\tvalue={ label ? stripHTML( label ) : '' }\n\t\t\t\t\tonChange={ ( labelValue ) => {\n\t\t\t\t\t\tsetAttributes( { label: labelValue } );\n\t\t\t\t\t} }\n\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\n\t\t\t{ isLinkEditable && (\n\t\t\t\t<>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => !! url }\n\t\t\t\t\t\tlabel={ __( 'Link to' ) }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\turl: undefined,\n\t\t\t\t\t\t\t\tid: undefined,\n\t\t\t\t\t\t\t\tkind: undefined,\n\t\t\t\t\t\t\t\ttype: undefined,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t>\n\t\t\t\t\t\t<LinkPicker\n\t\t\t\t\t\t\tpreview={ preview }\n\t\t\t\t\t\t\tonSelect={ handleLinkChange }\n\t\t\t\t\t\t\tsuggestionsQuery={ getSuggestionsQuery(\n\t\t\t\t\t\t\t\tattributes.type,\n\t\t\t\t\t\t\t\tattributes.kind\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tlabel={ __( 'Link to' ) }\n\t\t\t\t\t\t\thelp={ helpText ? helpText : undefined }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\n\t\t\t\t\t{ url && (\n\t\t\t\t\t\t<HStack\n\t\t\t\t\t\t\tclassName=\"navigation-link-to__actions\"\n\t\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\t\tjustify=\"left\"\n\t\t\t\t\t\t\tstyle={ { gridColumn: '1 / -1' } }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ hasUrlBinding &&\n\t\t\t\t\t\t\t\tisBoundEntityAvailable &&\n\t\t\t\t\t\t\t\tentityRecord?.id &&\n\t\t\t\t\t\t\t\tattributes.kind === 'post-type' &&\n\t\t\t\t\t\t\t\tonNavigateToEntityRecord && (\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\tonNavigateToEntityRecord( {\n\t\t\t\t\t\t\t\t\t\t\t\tpostId: entityRecord.id,\n\t\t\t\t\t\t\t\t\t\t\t\tpostType: attributes.type,\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\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t\t\t\t\t/* translators: %s: entity type (e.g., \"page\", \"post\", \"category\") */\n\t\t\t\t\t\t\t\t\t\t\t__( 'Edit %s' ),\n\t\t\t\t\t\t\t\t\t\t\tentityTypeName\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ isViewableUrl && (\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\t\thref={ viewUrl }\n\t\t\t\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\t\t\t\ticon={ external }\n\t\t\t\t\t\t\t\t\ticonPosition=\"right\"\n\t\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t\t\t\t/* translators: %s: entity type (e.g., \"page\", \"post\", \"category\") or \"link\" for external links */\n\t\t\t\t\t\t\t\t\t\t__( 'View %s' ),\n\t\t\t\t\t\t\t\t\t\tattributes.kind &&\n\t\t\t\t\t\t\t\t\t\t\tattributes.type &&\n\t\t\t\t\t\t\t\t\t\t\tattributes.kind !== 'custom'\n\t\t\t\t\t\t\t\t\t\t\t? entityTypeName\n\t\t\t\t\t\t\t\t\t\t\t: __( 'link' )\n\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</HStack>\n\t\t\t\t\t) }\n\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => !! opensInNewTab }\n\t\t\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( { opensInNewTab: false } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t>\n\t\t\t\t\t\t<CheckboxControl\n\t\t\t\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\t\t\t\tchecked={ opensInNewTab }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { opensInNewTab: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t</>\n\t\t\t) }\n\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => !! description }\n\t\t\t\tlabel={ __( 'Description' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { description: '' } ) }\n\t\t\t\tisShownByDefault={ ! isContentOnly }\n\t\t\t>\n\t\t\t\t<TextareaControl\n\t\t\t\t\tlabel={ __( 'Description' ) }\n\t\t\t\t\tvalue={ description || '' }\n\t\t\t\t\tonChange={ ( descriptionValue ) => {\n\t\t\t\t\t\tsetAttributes( { description: descriptionValue } );\n\t\t\t\t\t} }\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'The description will be displayed in the menu if the current theme supports it.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => !! rel }\n\t\t\t\tlabel={ __( 'Rel attribute' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { rel: '' } ) }\n\t\t\t\tisShownByDefault={ ! isContentOnly }\n\t\t\t>\n\t\t\t\t<TextControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'Rel attribute' ) }\n\t\t\t\t\tvalue={ rel || '' }\n\t\t\t\t\tonChange={ ( relValue ) => {\n\t\t\t\t\t\tsetAttributes( { rel: relValue } );\n\t\t\t\t\t} }\n\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'The relationship of the linked URL as space-separated link types.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\t\t</ToolsPanel>\n\t);\n}\n/**\n * Returns help text for invalid links.\n *\n * @return {string} Error help text string (empty string if valid).\n */\nexport function getInvalidLinkHelpText() {\n\treturn __(\n\t\t'This link is invalid and will not appear on your site. Please update the link.'\n\t);\n}\n\n/**\n * Returns the help text for links to draft entities\n *\n * @param {Object} props - Function props\n * @param {string} props.type - The entity type\n * @param {string} props.kind - The entity kind\n * @return {string} Draft help text\n */\nfunction getDraftHelpText( { type, kind } ) {\n\tconst entityType = getEntityTypeName( type, kind );\n\treturn sprintf(\n\t\t/* translators: %1$s is the entity type (e.g., \"page\", \"post\", \"category\") */\n\t\t__(\n\t\t\t'This link is to a draft %1$s and will not appear on your site until the %1$s is published.'\n\t\t),\n\t\tentityType\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA,4BAA4B;AAAA,EAC5B,gCAAgC;AAAA,EAChC
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\tCheckboxControl,\n\tTextControl,\n\tTextareaControl,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { external } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelDropdownMenuProps } from '../../utils/hooks';\nimport { useHandleLinkChange } from './use-handle-link-change';\nimport { useEntityBinding } from './use-entity-binding';\nimport { getSuggestionsQuery } from '../link-ui';\nimport { useLinkPreview } from './use-link-preview';\nimport { useIsInvalidLink } from './use-is-invalid-link';\nimport { unlock } from '../../lock-unlock';\n\nconst { LinkPicker, isHashLink, isRelativePath } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Get a human-readable entity type name.\n *\n * @param {string} type - The entity type\n * @param {string} kind - The entity kind\n * @return {string} Human-readable entity type name\n */\nfunction getEntityTypeName( type, kind ) {\n\tif ( kind === 'post-type' ) {\n\t\tswitch ( type ) {\n\t\t\tcase 'post':\n\t\t\t\treturn __( 'post' );\n\t\t\tcase 'page':\n\t\t\t\treturn __( 'page' );\n\t\t\tdefault:\n\t\t\t\treturn type || __( 'post' );\n\t\t}\n\t}\n\tif ( kind === 'taxonomy' ) {\n\t\tswitch ( type ) {\n\t\t\tcase 'category':\n\t\t\t\treturn __( 'category' );\n\t\t\tcase 'tag':\n\t\t\t\treturn __( 'tag' );\n\t\t\tdefault:\n\t\t\t\treturn type || __( 'term' );\n\t\t}\n\t}\n\treturn type || __( 'item' );\n}\n\n/**\n * Shared Controls component for Navigation Link and Navigation Submenu blocks.\n *\n * This component provides the inspector controls (ToolsPanel) that are identical\n * between both navigation blocks.\n *\n * @param {Object} props - Component props\n * @param {Object} props.attributes - Block attributes\n * @param {Function} props.setAttributes - Function to update block attributes\n * @param {string} props.clientId - Block client ID\n * @param {boolean} props.isLinkEditable - Whether link editing should be allowed\n */\nexport function Controls( {\n\tattributes,\n\tsetAttributes,\n\tclientId,\n\tisLinkEditable = true,\n} ) {\n\tconst { label, url, description, rel, opensInNewTab } = attributes;\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\t// Use the entity binding hook for UI state (help text, link preview, etc.)\n\tconst { hasUrlBinding, isBoundEntityAvailable, entityRecord } =\n\t\tuseEntityBinding( {\n\t\t\tclientId,\n\t\t\tattributes,\n\t\t} );\n\n\tconst [ isInvalid, isDraft ] = useIsInvalidLink(\n\t\tattributes.kind,\n\t\tattributes.type,\n\t\tentityRecord?.id,\n\t\thasUrlBinding\n\t);\n\n\tlet helpText = '';\n\n\tif ( isInvalid || ( hasUrlBinding && ! isBoundEntityAvailable ) ) {\n\t\t// Show invalid link help text for:\n\t\t// 1. Invalid post-type links (trashed/deleted posts/pages) - via useIsInvalidLink\n\t\t// 2. Missing bound taxonomy entities (deleted categories/tags) - useIsInvalidLink only checks post-types\n\t\thelpText = getInvalidLinkHelpText();\n\t} else if ( isDraft ) {\n\t\thelpText = getDraftHelpText( {\n\t\t\ttype: attributes.type,\n\t\t\tkind: attributes.kind,\n\t\t} );\n\t}\n\t// Get the link change handler with built-in binding management\n\tconst handleLinkChange = useHandleLinkChange( {\n\t\tclientId,\n\t\tattributes,\n\t\tsetAttributes,\n\t} );\n\n\tconst onNavigateToEntityRecord = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings().onNavigateToEntityRecord,\n\t\t[]\n\t);\n\n\tconst homeUrl = useSelect( ( select ) => {\n\t\treturn select( coreStore ).getEntityRecord( 'root', '__unstableBase' )\n\t\t\t?.home;\n\t}, [] );\n\n\tconst blockEditingMode = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getBlockEditingMode( clientId ),\n\t\t[ clientId ]\n\t);\n\n\tconst isContentOnly = blockEditingMode === 'contentOnly';\n\n\tconst preview = useLinkPreview( {\n\t\turl,\n\t\tentityRecord,\n\t\ttype: attributes.type,\n\t\thasBinding: hasUrlBinding,\n\t\tisEntityAvailable: isBoundEntityAvailable,\n\t} );\n\n\t// Check if URL is viewable (not hash link or other relative path like ./ or ../)\n\tconst isViewableUrl =\n\t\t!! url &&\n\t\t( ! isHashLink( url ) ||\n\t\t\t( isRelativePath( url ) && ! url.startsWith( '/' ) ) );\n\n\t// Construct full URL for viewing (prepend home URL for absolute paths starting with /)\n\tconst viewUrl =\n\t\tisViewableUrl && url.startsWith( '/' ) && homeUrl ? homeUrl + url : url;\n\n\treturn (\n\t\t<ToolsPanel\n\t\t\tlabel={ __( 'Settings' ) }\n\t\t\tresetAll={ () => {\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tlabel: '',\n\t\t\t\t\turl: '',\n\t\t\t\t\tdescription: '',\n\t\t\t\t\trel: '',\n\t\t\t\t\topensInNewTab: false,\n\t\t\t\t} );\n\t\t\t} }\n\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t>\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => !! label }\n\t\t\t\tlabel={ __( 'Text' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { label: '' } ) }\n\t\t\t\tisShownByDefault\n\t\t\t>\n\t\t\t\t<TextControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'Text' ) }\n\t\t\t\t\tvalue={ label ? stripHTML( label ) : '' }\n\t\t\t\t\tonChange={ ( labelValue ) => {\n\t\t\t\t\t\tsetAttributes( { label: labelValue } );\n\t\t\t\t\t} }\n\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\n\t\t\t{ isLinkEditable && (\n\t\t\t\t<>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => !! url }\n\t\t\t\t\t\tlabel={ __( 'Link to' ) }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\turl: undefined,\n\t\t\t\t\t\t\t\tid: undefined,\n\t\t\t\t\t\t\t\tkind: undefined,\n\t\t\t\t\t\t\t\ttype: undefined,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t>\n\t\t\t\t\t\t<LinkPicker\n\t\t\t\t\t\t\tpreview={ preview }\n\t\t\t\t\t\t\tonSelect={ handleLinkChange }\n\t\t\t\t\t\t\tsuggestionsQuery={ getSuggestionsQuery(\n\t\t\t\t\t\t\t\tattributes.type,\n\t\t\t\t\t\t\t\tattributes.kind\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tlabel={ __( 'Link to' ) }\n\t\t\t\t\t\t\thelp={ helpText ? helpText : undefined }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => !! opensInNewTab }\n\t\t\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( { opensInNewTab: false } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t>\n\t\t\t\t\t\t<CheckboxControl\n\t\t\t\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\t\t\t\tchecked={ opensInNewTab }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { opensInNewTab: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\n\t\t\t\t\t{ !! url &&\n\t\t\t\t\t\thasUrlBinding &&\n\t\t\t\t\t\tisBoundEntityAvailable &&\n\t\t\t\t\t\tentityRecord?.id &&\n\t\t\t\t\t\tattributes.kind === 'post-type' &&\n\t\t\t\t\t\tonNavigateToEntityRecord && (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tonNavigateToEntityRecord( {\n\t\t\t\t\t\t\t\t\t\tpostId: entityRecord.id,\n\t\t\t\t\t\t\t\t\t\tpostType: attributes.type,\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tclassName=\"navigation-link-to__action-button\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Edit' ) }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t) }\n\t\t\t\t\t{ isViewableUrl && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\thref={ viewUrl }\n\t\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\t\ticon={ external }\n\t\t\t\t\t\t\ticonPosition=\"right\"\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tclassName=\"navigation-link-to__action-button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'View' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => !! description }\n\t\t\t\tlabel={ __( 'Description' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { description: '' } ) }\n\t\t\t\tisShownByDefault={ ! isContentOnly }\n\t\t\t>\n\t\t\t\t<TextareaControl\n\t\t\t\t\tlabel={ __( 'Description' ) }\n\t\t\t\t\tvalue={ description || '' }\n\t\t\t\t\tonChange={ ( descriptionValue ) => {\n\t\t\t\t\t\tsetAttributes( { description: descriptionValue } );\n\t\t\t\t\t} }\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'The description will be displayed in the menu if the current theme supports it.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => !! rel }\n\t\t\t\tlabel={ __( 'Rel attribute' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { rel: '' } ) }\n\t\t\t\tisShownByDefault={ ! isContentOnly }\n\t\t\t>\n\t\t\t\t<TextControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tlabel={ __( 'Rel attribute' ) }\n\t\t\t\t\tvalue={ rel || '' }\n\t\t\t\t\tonChange={ ( relValue ) => {\n\t\t\t\t\t\tsetAttributes( { rel: relValue } );\n\t\t\t\t\t} }\n\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'The relationship of the linked URL as space-separated link types.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\t\t</ToolsPanel>\n\t);\n}\n/**\n * Returns help text for invalid links.\n *\n * @return {string} Error help text string (empty string if valid).\n */\nexport function getInvalidLinkHelpText() {\n\treturn __(\n\t\t'This link is invalid and will not appear on your site. Please update the link.'\n\t);\n}\n\n/**\n * Returns the help text for links to draft entities\n *\n * @param {Object} props - Function props\n * @param {string} props.type - The entity type\n * @param {string} props.kind - The entity kind\n * @return {string} Draft help text\n */\nfunction getDraftHelpText( { type, kind } ) {\n\tconst entityType = getEntityTypeName( type, kind );\n\treturn sprintf(\n\t\t/* translators: %1$s is the entity type (e.g., \"page\", \"post\", \"category\") */\n\t\t__(\n\t\t\t'This link is to a draft %1$s and will not appear on your site until the %1$s is published.'\n\t\t),\n\t\tentityType\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA,4BAA4B;AAAA,EAC5B,gCAAgC;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,IAAI,eAAe;AAC5B,SAAS,uBAAuB,iBAAiB;AACjD;AAAA,EACC,eAAe;AAAA,EACf,SAAS;AAAA,OACH;AACP,SAAS,iBAAiB;AAC1B,SAAS,SAAS,iBAAiB;AACnC,SAAS,gBAAgB;AAKzB,SAAS,sCAAsC;AAC/C,SAAS,2BAA2B;AACpC,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC,SAAS,cAAc;AAqJnB,SAYA,UAZA,KAYA,YAZA;AAnJJ,IAAM,EAAE,YAAY,YAAY,eAAe,IAAI;AAAA,EAClD;AACD;AASA,SAAS,kBAAmB,MAAM,MAAO;AACxC,MAAK,SAAS,aAAc;AAC3B,YAAS,MAAO;AAAA,MACf,KAAK;AACJ,eAAO,GAAI,MAAO;AAAA,MACnB,KAAK;AACJ,eAAO,GAAI,MAAO;AAAA,MACnB;AACC,eAAO,QAAQ,GAAI,MAAO;AAAA,IAC5B;AAAA,EACD;AACA,MAAK,SAAS,YAAa;AAC1B,YAAS,MAAO;AAAA,MACf,KAAK;AACJ,eAAO,GAAI,UAAW;AAAA,MACvB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AC;AAAA;AAAA,gBACA,OAAQ,GAAI,aAAc;AAAA,gBAC1B,OAAQ,eAAe;AAAA,gBACvB,UAAW,CAAE,qBAAsB;AAClC,gCAAe,EAAE,aAAa,iBAAiB,CAAE;AAAA,gBAClD;AAAA,gBACA,MAAO;AAAA,kBACN;AAAA,gBACD;AAAA;AAAA,YACD;AAAA;AAAA,QACD;AAAA,QAEA;AAAA,UAAC;AAAA;AAAA,YACA,UAAW,MAAM,CAAC,CAAE;AAAA,YACpB,OAAQ,GAAI,eAAgB;AAAA,YAC5B,YAAa,MAAM,cAAe,EAAE,KAAK,GAAG,CAAE;AAAA,YAC9C,kBAAmB,CAAE;AAAA,YAErB;AAAA,cAAC;AAAA;AAAA,gBACA,uBAAqB;AAAA,gBACrB,OAAQ,GAAI,eAAgB;AAAA,gBAC5B,OAAQ,OAAO;AAAA,gBACf,UAAW,CAAE,aAAc;AAC1B,gCAAe,EAAE,KAAK,SAAS,CAAE;AAAA,gBAClC;AAAA,gBACA,cAAa;AAAA,gBACb,MAAO;AAAA,kBACN;AAAA,gBACD;AAAA;AAAA,YACD;AAAA;AAAA,QACD;AAAA;AAAA;AAAA,EACD;AAEF;AAMO,SAAS,yBAAyB;AACxC,SAAO;AAAA,IACN;AAAA,EACD;AACD;AAUA,SAAS,iBAAkB,EAAE,MAAM,KAAK,GAAI;AAC3C,QAAM,aAAa,kBAAmB,MAAM,IAAK;AACjD,SAAO;AAAA;AAAA,IAEN;AAAA,MACC;AAAA,IACD;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -11,7 +11,7 @@ var { useRemoteUrlData, isHashLink, isRelativePath } = unlock(
|
|
|
11
11
|
function capitalize(str) {
|
|
12
12
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
13
13
|
}
|
|
14
|
-
function computeDisplayUrl({ linkUrl,
|
|
14
|
+
function computeDisplayUrl({ linkUrl, homeUrl } = {}) {
|
|
15
15
|
if (!linkUrl) {
|
|
16
16
|
return { displayUrl: "", isExternal: false };
|
|
17
17
|
}
|
|
@@ -22,7 +22,7 @@ function computeDisplayUrl({ linkUrl, siteUrl } = {}) {
|
|
|
22
22
|
}
|
|
23
23
|
try {
|
|
24
24
|
const parsedUrl = new URL(linkUrl);
|
|
25
|
-
const siteDomain =
|
|
25
|
+
const siteDomain = homeUrl ? new URL(homeUrl).origin : window.location.origin;
|
|
26
26
|
if (parsedUrl.origin === siteDomain) {
|
|
27
27
|
let path = parsedUrl.pathname + parsedUrl.search + parsedUrl.hash;
|
|
28
28
|
if (path.endsWith("/") && path.length > 1) {
|
|
@@ -100,18 +100,17 @@ function useLinkPreview({
|
|
|
100
100
|
hasBinding,
|
|
101
101
|
isEntityAvailable
|
|
102
102
|
}) {
|
|
103
|
-
const
|
|
104
|
-
|
|
103
|
+
const homeUrl = useSelect((select) => {
|
|
104
|
+
return select(coreDataStore).getEntityRecord(
|
|
105
105
|
"root",
|
|
106
|
-
"
|
|
107
|
-
);
|
|
108
|
-
return siteEntity?.url;
|
|
106
|
+
"__unstableBase"
|
|
107
|
+
)?.home;
|
|
109
108
|
}, []);
|
|
110
109
|
const title = entityRecord?.title?.rendered || entityRecord?.title || entityRecord?.name;
|
|
111
110
|
const { richData } = useRemoteUrlData(title ? null : url);
|
|
112
111
|
const { displayUrl, isExternal } = computeDisplayUrl({
|
|
113
112
|
linkUrl: url,
|
|
114
|
-
|
|
113
|
+
homeUrl
|
|
115
114
|
});
|
|
116
115
|
const image = useSelect(
|
|
117
116
|
(select) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/navigation-link/shared/use-link-preview.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { safeDecodeURI } from '@wordpress/url';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\nconst { useRemoteUrlData, isHashLink, isRelativePath } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Capitalize the first letter of a string.\n *\n * @param {string} str - The string to capitalize\n * @return {string} Capitalized string\n */\nfunction capitalize( str ) {\n\treturn str.charAt( 0 ).toUpperCase() + str.slice( 1 );\n}\n\n/**\n * Compute display URL - strips site URL if internal, shows full URL if external.\n *\n * @param {Object} options - Parameters object\n * @param {string} options.linkUrl - The URL to process\n * @param {string} options.
|
|
5
|
-
"mappings": ";AAGA,SAAS,IAAI,eAAe;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,eAAe,8BAA8B;AACtD,SAAS,iBAAiB;AAC1B,SAAS,SAAS,qBAAqB;AAKvC,SAAS,cAAc;AAEvB,IAAM,EAAE,kBAAkB,YAAY,eAAe,IAAI;AAAA,EACxD;AACD;AAQA,SAAS,WAAY,KAAM;AAC1B,SAAO,IAAI,OAAQ,CAAE,EAAE,YAAY,IAAI,IAAI,MAAO,CAAE;AACrD;AAUO,SAAS,kBAAmB,EAAE,SAAS,QAAQ,IAAI,CAAC,GAAI;AAC9D,MAAK,CAAE,SAAU;AAChB,WAAO,EAAE,YAAY,IAAI,YAAY,MAAM;AAAA,EAC5C;AAEA,MAAI,aAAa,cAAe,OAAQ;AACxC,MAAI,aAAa;AAGjB,MAAK,eAAgB,OAAQ,KAAK,WAAY,OAAQ,GAAI;AACzD,WAAO,EAAE,YAAY,YAAY,MAAM;AAAA,EACxC;AAIA,MAAI;AACH,UAAM,YAAY,IAAI,IAAK,OAAQ;AAEnC,UAAM,aAAa,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { safeDecodeURI } from '@wordpress/url';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\nconst { useRemoteUrlData, isHashLink, isRelativePath } = unlock(\n\tblockEditorPrivateApis\n);\n\n/**\n * Capitalize the first letter of a string.\n *\n * @param {string} str - The string to capitalize\n * @return {string} Capitalized string\n */\nfunction capitalize( str ) {\n\treturn str.charAt( 0 ).toUpperCase() + str.slice( 1 );\n}\n\n/**\n * Compute display URL - strips site URL if internal, shows full URL if external.\n *\n * @param {Object} options - Parameters object\n * @param {string} options.linkUrl - The URL to process\n * @param {string} options.homeUrl - The WordPress site URL (falls back to window.location.origin)\n * @return {Object} Object with displayUrl and isExternal flag\n */\nexport function computeDisplayUrl( { linkUrl, homeUrl } = {} ) {\n\tif ( ! linkUrl ) {\n\t\treturn { displayUrl: '', isExternal: false };\n\t}\n\n\tlet displayUrl = safeDecodeURI( linkUrl );\n\tlet isExternal = false;\n\n\t// Check hash links and relative paths first - these are always internal\n\tif ( isRelativePath( linkUrl ) || isHashLink( linkUrl ) ) {\n\t\treturn { displayUrl, isExternal: false };\n\t}\n\n\t// Try to parse as a full URL to determine if it's actually external\n\t// This must happen before trusting the type attribute\n\ttry {\n\t\tconst parsedUrl = new URL( linkUrl );\n\t\t// Use provided homeUrl or fall back to window.location.origin\n\t\tconst siteDomain = homeUrl\n\t\t\t? new URL( homeUrl ).origin\n\t\t\t: window.location.origin;\n\n\t\tif ( parsedUrl.origin === siteDomain ) {\n\t\t\t// Show only the pathname (and search/hash if present)\n\t\t\tlet path = parsedUrl.pathname + parsedUrl.search + parsedUrl.hash;\n\t\t\t// Remove trailing slash\n\t\t\tif ( path.endsWith( '/' ) && path.length > 1 ) {\n\t\t\t\tpath = path.slice( 0, -1 );\n\t\t\t}\n\t\t\tdisplayUrl = path;\n\t\t} else {\n\t\t\t// Different origin - this is an external link\n\t\t\tisExternal = true;\n\t\t}\n\t} catch ( e ) {\n\t\t// URL parsing failed - this means it's likely a URL without a protocol (e.g., \"www.example.com\")\n\t\t// Since we already checked for relative paths and hash links above, treat as external\n\t\tisExternal = true;\n\t}\n\n\treturn { displayUrl, isExternal };\n}\n\n/**\n * Compute badges for the link preview.\n *\n * @param {Object} options - Options object\n * @param {string} options.url - Link URL\n * @param {string} options.type - Entity type (page, post, etc.)\n * @param {boolean} options.isExternal - Whether link is external\n * @param {string} options.entityStatus - Entity status (publish, draft, etc.)\n * @param {boolean} options.hasBinding - Whether link has entity binding\n * @param {boolean} options.isEntityAvailable - Whether bound entity exists\n * @return {Array} Array of badge objects with label and intent\n */\nexport function computeBadges( {\n\turl,\n\ttype,\n\tisExternal,\n\tentityStatus,\n\thasBinding,\n\tisEntityAvailable,\n} ) {\n\tconst badges = [];\n\n\t// Kind badge\n\tif ( url ) {\n\t\tif ( isExternal ) {\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'External link' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t} else if ( isHashLink( url ) ) {\n\t\t\t// Hash links should be detected before type check\n\t\t\t// because they're not entity links even if type is set\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'Internal link' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t} else if ( type && type !== 'custom' ) {\n\t\t\t// Show entity type badge (page, post, category, etc.)\n\t\t\t// but not 'custom' since that's just a manual link\n\t\t\tbadges.push( { label: capitalize( type ), intent: 'default' } );\n\t\t} else {\n\t\t\t// Internal link (not external, not hash, not entity)\n\t\t\tbadges.push( {\n\t\t\t\tlabel: __( 'Page' ),\n\t\t\t\tintent: 'default',\n\t\t\t} );\n\t\t}\n\t}\n\n\t// Status badge\n\tif ( hasBinding && ! isEntityAvailable ) {\n\t\tbadges.push( {\n\t\t\tlabel: sprintf(\n\t\t\t\t/* translators: %s is the entity type (e.g., \"page\", \"post\", \"category\") */\n\t\t\t\t__( 'Missing %s' ),\n\t\t\t\ttype\n\t\t\t),\n\t\t\tintent: 'error',\n\t\t} );\n\t} else if ( ! url ) {\n\t\tbadges.push( { label: __( 'No link selected' ), intent: 'error' } );\n\t} else if ( entityStatus ) {\n\t\tconst statusMap = {\n\t\t\tpublish: { label: __( 'Published' ), intent: 'success' },\n\t\t\tfuture: { label: __( 'Scheduled' ), intent: 'warning' },\n\t\t\tdraft: { label: __( 'Draft' ), intent: 'warning' },\n\t\t\tpending: { label: __( 'Pending' ), intent: 'warning' },\n\t\t\tprivate: { label: __( 'Private' ), intent: 'default' },\n\t\t\ttrash: { label: __( 'Trash' ), intent: 'error' },\n\t\t};\n\t\tconst badge = statusMap[ entityStatus ];\n\t\tif ( badge ) {\n\t\t\tbadges.push( badge );\n\t\t}\n\t}\n\n\treturn badges;\n}\n\n/**\n * Hook to compute link preview data for display.\n *\n * This hook takes raw link data and entity information and computes\n * presentation-ready preview data including formatted title, URL, and badges.\n *\n * @param {Object} options - Options object\n * @param {string} options.url - Link URL\n * @param {string} options.type - Entity type (page, post, etc.)\n * @param {Object} options.entityRecord - Entity record\n * @param {boolean} options.hasBinding - Whether link has entity binding\n * @param {boolean} options.isEntityAvailable - Whether bound entity exists\n * @return {Object} Preview data object with title, url, image, and badges\n */\nexport function useLinkPreview( {\n\turl,\n\tentityRecord,\n\ttype,\n\thasBinding,\n\tisEntityAvailable,\n} ) {\n\t// Get the WordPress homepage URL from settings\n\tconst homeUrl = useSelect( ( select ) => {\n\t\treturn select( coreDataStore ).getEntityRecord(\n\t\t\t'root',\n\t\t\t'__unstableBase'\n\t\t)?.home;\n\t}, [] );\n\n\tconst title =\n\t\tentityRecord?.title?.rendered ||\n\t\tentityRecord?.title ||\n\t\tentityRecord?.name;\n\n\t// Fetch rich URL data if we don't have a title. Internal links should have passed a title.\n\tconst { richData } = useRemoteUrlData( title ? null : url );\n\n\t// Compute display URL and external flag\n\tconst { displayUrl, isExternal } = computeDisplayUrl( {\n\t\tlinkUrl: url,\n\t\thomeUrl,\n\t} );\n\n\tconst image = useSelect(\n\t\t( select ) => {\n\t\t\t// Only fetch for post-type entities with featured media\n\t\t\tif ( ! entityRecord?.featured_media ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst { getEntityRecord } = select( coreDataStore );\n\n\t\t\t// Get the media entity to fetch the image URL\n\t\t\tconst media = getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tentityRecord.featured_media\n\t\t\t);\n\n\t\t\t// Return the thumbnail or medium size URL, fallback to source_url\n\t\t\treturn (\n\t\t\t\tmedia?.media_details?.sizes?.thumbnail?.source_url ||\n\t\t\t\tmedia?.media_details?.sizes?.medium?.source_url ||\n\t\t\t\tmedia?.source_url ||\n\t\t\t\tnull\n\t\t\t);\n\t\t},\n\t\t[ entityRecord?.featured_media ]\n\t);\n\n\t// Compute badges\n\tconst badges = computeBadges( {\n\t\turl,\n\t\ttype,\n\t\tisExternal,\n\t\tentityStatus: entityRecord?.status,\n\t\thasBinding,\n\t\tisEntityAvailable,\n\t} );\n\n\t// Get display title - use provided title, fallback to rich data, or URL\n\tconst displayTitle = url\n\t\t? title || richData?.title || safeDecodeURI( url )\n\t\t: __( 'Add link' );\n\n\treturn {\n\t\ttitle: displayTitle,\n\t\turl: displayUrl,\n\t\timage,\n\t\tbadges,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,IAAI,eAAe;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,eAAe,8BAA8B;AACtD,SAAS,iBAAiB;AAC1B,SAAS,SAAS,qBAAqB;AAKvC,SAAS,cAAc;AAEvB,IAAM,EAAE,kBAAkB,YAAY,eAAe,IAAI;AAAA,EACxD;AACD;AAQA,SAAS,WAAY,KAAM;AAC1B,SAAO,IAAI,OAAQ,CAAE,EAAE,YAAY,IAAI,IAAI,MAAO,CAAE;AACrD;AAUO,SAAS,kBAAmB,EAAE,SAAS,QAAQ,IAAI,CAAC,GAAI;AAC9D,MAAK,CAAE,SAAU;AAChB,WAAO,EAAE,YAAY,IAAI,YAAY,MAAM;AAAA,EAC5C;AAEA,MAAI,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BAAiB;AACrC,eAAO;AAAA,MACR;AAEA,YAAM,EAAE,gBAAgB,IAAI,OAAQ,aAAc;AAGlD,YAAM,QAAQ;AAAA,QACb;AAAA,QACA;AAAA,QACA,aAAa;AAAA,MACd;AAGA,aACC,OAAO,eAAe,OAAO,WAAW,cACxC,OAAO,eAAe,OAAO,QAAQ,cACrC,OAAO,cACP;AAAA,IAEF;AAAA,IACA,CAAE,cAAc,cAAe;AAAA,EAChC;AAGA,QAAM,SAAS,cAAe;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,EACD,CAAE;AAGF,QAAM,eAAe,MAClB,SAAS,UAAU,SAAS,cAAe,GAAI,IAC/C,GAAI,UAAW;AAElB,SAAO;AAAA,IACN,OAAO;AAAA,IACP,KAAK;AAAA,IACL;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -21,6 +21,7 @@ function NavigationOverlayCloseEdit({
|
|
|
21
21
|
const { displayMode, text } = attributes;
|
|
22
22
|
const showIcon = displayMode === "icon" || displayMode === "both";
|
|
23
23
|
const showText = displayMode === "text" || displayMode === "both";
|
|
24
|
+
const displayText = text || __("Close");
|
|
24
25
|
const blockProps = useBlockProps({
|
|
25
26
|
className: "wp-block-navigation-overlay-close"
|
|
26
27
|
});
|
|
@@ -88,10 +89,8 @@ function NavigationOverlayCloseEdit({
|
|
|
88
89
|
RichText,
|
|
89
90
|
{
|
|
90
91
|
identifier: "text",
|
|
91
|
-
value:
|
|
92
|
+
value: displayText,
|
|
92
93
|
onChange: (value) => setAttributes({ text: value }),
|
|
93
|
-
placeholder: __("Close"),
|
|
94
|
-
withoutInteractiveFormatting: true,
|
|
95
94
|
tagName: "span",
|
|
96
95
|
className: "wp-block-navigation-overlay-close__text",
|
|
97
96
|
allowedFormats: ["core/bold", "core/italic"]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/navigation-overlay-close/edit.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tInspectorControls,\n\tuseBlockProps,\n\tRichText,\n} from '@wordpress/block-editor';\nimport {\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { Icon, close } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nexport default function NavigationOverlayCloseEdit( {\n\tattributes,\n\tsetAttributes,\n} ) {\n\tconst { displayMode, text } = attributes;\n\tconst showIcon = displayMode === 'icon' || displayMode === 'both';\n\tconst showText = displayMode === 'text' || displayMode === 'both';\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wp-block-navigation-overlay-close',\n\t} );\n\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<ToolsPanel\n\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\tresetAll={ () => setAttributes( { displayMode: 'icon' } ) }\n\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\tlabel={ __( 'Display Mode' ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\thasValue={ () => displayMode !== 'icon' }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( { displayMode: 'icon' } )\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\t\tlabel={ __( 'Display Mode' ) }\n\t\t\t\t\t\t\tvalue={ displayMode }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { displayMode: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\tvalue=\"icon\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Icon' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\tvalue=\"text\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Text' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\tvalue=\"both\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Both' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t</ToolsPanel>\n\t\t\t</InspectorControls>\n\t\t\t<button\n\t\t\t\t{ ...blockProps }\n\t\t\t\ttype=\"button\"\n\t\t\t\taria-label={ ! showText ? __( 'Close' ) : undefined }\n\t\t\t>\n\t\t\t\t{ showIcon && <Icon icon={ close } /> }\n\t\t\t\t{ showText && (\n\t\t\t\t\t<RichText\n\t\t\t\t\t\tidentifier=\"text\"\n\t\t\t\t\t\tvalue={
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC,4BAA4B;AAAA,EAC5B,gCAAgC;AAAA,EAChC,oCAAoC;AAAA,EACpC,0CAA0C;AAAA,OACpC;AACP,SAAS,UAAU;AACnB,SAAS,MAAM,aAAa;AAK5B,SAAS,sCAAsC;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tInspectorControls,\n\tuseBlockProps,\n\tRichText,\n} from '@wordpress/block-editor';\nimport {\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { Icon, close } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nexport default function NavigationOverlayCloseEdit( {\n\tattributes,\n\tsetAttributes,\n} ) {\n\tconst { displayMode, text } = attributes;\n\tconst showIcon = displayMode === 'icon' || displayMode === 'both';\n\tconst showText = displayMode === 'text' || displayMode === 'both';\n\n\t// Use translated default if text is empty\n\tconst displayText = text || __( 'Close' );\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wp-block-navigation-overlay-close',\n\t} );\n\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<ToolsPanel\n\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\tresetAll={ () => setAttributes( { displayMode: 'icon' } ) }\n\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\tlabel={ __( 'Display Mode' ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\thasValue={ () => displayMode !== 'icon' }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( { displayMode: 'icon' } )\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\t\tlabel={ __( 'Display Mode' ) }\n\t\t\t\t\t\t\tvalue={ displayMode }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { displayMode: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\tvalue=\"icon\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Icon' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\tvalue=\"text\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Text' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\t\tvalue=\"both\"\n\t\t\t\t\t\t\t\tlabel={ __( 'Both' ) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t</ToolsPanel>\n\t\t\t</InspectorControls>\n\t\t\t<button\n\t\t\t\t{ ...blockProps }\n\t\t\t\ttype=\"button\"\n\t\t\t\taria-label={ ! showText ? __( 'Close' ) : undefined }\n\t\t\t>\n\t\t\t\t{ showIcon && <Icon icon={ close } /> }\n\t\t\t\t{ showText && (\n\t\t\t\t\t<RichText\n\t\t\t\t\t\tidentifier=\"text\"\n\t\t\t\t\t\tvalue={ displayText }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( { text: value } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\t\tclassName=\"wp-block-navigation-overlay-close__text\"\n\t\t\t\t\t\tallowedFormats={ [ 'core/bold', 'core/italic' ] }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</button>\n\t\t</>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC,4BAA4B;AAAA,EAC5B,gCAAgC;AAAA,EAChC,oCAAoC;AAAA,EACpC,0CAA0C;AAAA,OACpC;AACP,SAAS,UAAU;AACnB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AAA,IACD,GACD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACL,MAAK;AAAA,QACL,cAAa,CAAE,WAAW,GAAI,OAAQ,IAAI;AAAA,QAExC;AAAA,sBAAY,oBAAC,QAAK,MAAO,OAAQ;AAAA,UACjC,YACD;AAAA,YAAC;AAAA;AAAA,cACA,YAAW;AAAA,cACX,OAAQ;AAAA,cACR,UAAW,CAAE,UACZ,cAAe,EAAE,MAAM,MAAM,CAAE;AAAA,cAEhC,SAAQ;AAAA,cACR,WAAU;AAAA,cACV,gBAAiB,CAAE,aAAa,aAAc;AAAA;AAAA,UAC/C;AAAA;AAAA;AAAA,IAEF;AAAA,KACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,7 +3,6 @@ import clsx from "clsx";
|
|
|
3
3
|
import { useBlockProps, useInnerBlocksProps } from "@wordpress/block-editor";
|
|
4
4
|
import { useSelect } from "@wordpress/data";
|
|
5
5
|
import { store as coreStore } from "@wordpress/core-data";
|
|
6
|
-
import { RawHTML } from "@wordpress/element";
|
|
7
6
|
import { safeHTML } from "@wordpress/dom";
|
|
8
7
|
import { ItemSubmenuIcon } from "../navigation-link/icons.mjs";
|
|
9
8
|
import {
|
|
@@ -57,7 +56,9 @@ function PageListItemEdit({ context, attributes }) {
|
|
|
57
56
|
type: "button",
|
|
58
57
|
className: "wp-block-navigation-item__content wp-block-navigation-submenu__toggle",
|
|
59
58
|
"aria-expanded": "false",
|
|
60
|
-
|
|
59
|
+
dangerouslySetInnerHTML: {
|
|
60
|
+
__html: safeHTML(label)
|
|
61
|
+
}
|
|
61
62
|
}
|
|
62
63
|
),
|
|
63
64
|
/* @__PURE__ */ jsx("span", { className: "wp-block-page-list__submenu-icon wp-block-navigation__submenu-icon", children: /* @__PURE__ */ jsx(ItemSubmenuIcon, {}) })
|
|
@@ -68,7 +69,9 @@ function PageListItemEdit({ context, attributes }) {
|
|
|
68
69
|
"wp-block-navigation-item__content": isNavigationChild
|
|
69
70
|
}),
|
|
70
71
|
href: link,
|
|
71
|
-
|
|
72
|
+
dangerouslySetInnerHTML: {
|
|
73
|
+
__html: safeHTML(title)
|
|
74
|
+
}
|
|
72
75
|
}
|
|
73
76
|
),
|
|
74
77
|
hasChildren && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/page-list-item/edit.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n/**\n * WordPress dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {
|
|
5
|
-
"mappings": ";AAGA,OAAO,UAAU;AAIjB,SAAS,eAAe,2BAA2B;AACnD,SAAS,iBAAiB;AAC1B,SAAS,SAAS,iBAAiB;AACnC,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n/**\n * WordPress dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { safeHTML } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { ItemSubmenuIcon } from '../navigation-link/icons';\nimport {\n\tgetColors,\n\tgetNavigationChildBlockProps,\n} from '../navigation/edit/utils';\n\nfunction useFrontPageId() {\n\treturn useSelect( ( select ) => {\n\t\tconst canReadSettings = select( coreStore ).canUser( 'read', {\n\t\t\tkind: 'root',\n\t\t\tname: 'site',\n\t\t} );\n\t\tif ( ! canReadSettings ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst site = select( coreStore ).getEntityRecord( 'root', 'site' );\n\t\treturn site?.show_on_front === 'page' && site?.page_on_front;\n\t}, [] );\n}\n\nexport default function PageListItemEdit( { context, attributes } ) {\n\tconst { id, label, link, hasChildren, title } = attributes;\n\tconst isNavigationChild = 'showSubmenuIcon' in context;\n\tconst frontPageId = useFrontPageId();\n\n\t// Get submenu visibility from context. The Navigation block handles\n\t// backward compatibility by migrating openSubmenusOnClick to submenuVisibility\n\t// via its deprecation handler before this context is received.\n\tconst submenuVisibility = context.submenuVisibility;\n\n\tconst openOnClick = submenuVisibility === 'click';\n\n\tconst innerBlocksColors = getColors( context, true );\n\n\tconst navigationChildBlockProps =\n\t\tgetNavigationChildBlockProps( innerBlocksColors );\n\tconst blockProps = useBlockProps( navigationChildBlockProps, {\n\t\tclassName: 'wp-block-pages-list__item',\n\t} );\n\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps );\n\n\treturn (\n\t\t<li\n\t\t\tkey={ id }\n\t\t\tclassName={ clsx( 'wp-block-pages-list__item', {\n\t\t\t\t'has-child': hasChildren,\n\t\t\t\t'wp-block-navigation-item': isNavigationChild,\n\t\t\t\t// Class assignment logic matches PHP rendering in page-list/index.php\n\t\t\t\t'open-on-click': openOnClick,\n\t\t\t\t'open-always': submenuVisibility === 'always',\n\t\t\t\t// Must check hover mode explicitly to match PHP elseif structure (index.php:212)\n\t\t\t\t'open-on-hover-click':\n\t\t\t\t\tsubmenuVisibility === 'hover' && context.showSubmenuIcon,\n\t\t\t\t'menu-item-home': id === frontPageId,\n\t\t\t} ) }\n\t\t>\n\t\t\t{ hasChildren && openOnClick ? (\n\t\t\t\t<>\n\t\t\t\t\t<button\n\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\tclassName=\"wp-block-navigation-item__content wp-block-navigation-submenu__toggle\"\n\t\t\t\t\t\taria-expanded=\"false\"\n\t\t\t\t\t\tdangerouslySetInnerHTML={ {\n\t\t\t\t\t\t\t__html: safeHTML( label ),\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t<span className=\"wp-block-page-list__submenu-icon wp-block-navigation__submenu-icon\">\n\t\t\t\t\t\t<ItemSubmenuIcon />\n\t\t\t\t\t</span>\n\t\t\t\t</>\n\t\t\t) : (\n\t\t\t\t<a\n\t\t\t\t\tclassName={ clsx( 'wp-block-pages-list__item__link', {\n\t\t\t\t\t\t'wp-block-navigation-item__content': isNavigationChild,\n\t\t\t\t\t} ) }\n\t\t\t\t\thref={ link }\n\t\t\t\t\tdangerouslySetInnerHTML={ {\n\t\t\t\t\t\t__html: safeHTML( title ),\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ hasChildren && (\n\t\t\t\t<>\n\t\t\t\t\t{ ! openOnClick && context.showSubmenuIcon && (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tclassName=\"wp-block-navigation-item__content wp-block-navigation-submenu__toggle wp-block-page-list__submenu-icon wp-block-navigation__submenu-icon\"\n\t\t\t\t\t\t\taria-expanded=\"false\"\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ItemSubmenuIcon />\n\t\t\t\t\t\t</button>\n\t\t\t\t\t) }\n\t\t\t\t\t<ul { ...innerBlocksProps }></ul>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</li>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,UAAU;AAIjB,SAAS,eAAe,2BAA2B;AACnD,SAAS,iBAAiB;AAC1B,SAAS,SAAS,iBAAiB;AACnC,SAAS,gBAAgB;AAKzB,SAAS,uBAAuB;AAChC;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAuDH,mBACC,KADD;AArDJ,SAAS,iBAAiB;AACzB,SAAO,UAAW,CAAE,WAAY;AAC/B,UAAM,kBAAkB,OAAQ,SAAU,EAAE,QAAS,QAAQ;AAAA,MAC5D,MAAM;AAAA,MACN,MAAM;AAAA,IACP,CAAE;AACF,QAAK,CAAE,iBAAkB;AACxB,aAAO;AAAA,IACR;AAEA,UAAM,OAAO,OAAQ,SAAU,EAAE,gBAAiB,QAAQ,MAAO;AACjE,WAAO,MAAM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AAU;AAAA,cACV,iBAAc;AAAA,cACd,MAAK;AAAA,cAEL,8BAAC,mBAAgB;AAAA;AAAA,UAClB;AAAA,UAED,oBAAC,QAAK,GAAG,kBAAmB;AAAA,WAC7B;AAAA;AAAA;AAAA,IAlDK;AAAA,EAoDP;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,9 +7,6 @@
|
|
|
7
7
|
"description": "Displays the next or previous post link that is adjacent to the current post.",
|
|
8
8
|
"textdomain": "default",
|
|
9
9
|
"attributes": {
|
|
10
|
-
"textAlign": {
|
|
11
|
-
"type": "string"
|
|
12
|
-
},
|
|
13
10
|
"type": {
|
|
14
11
|
"type": "string",
|
|
15
12
|
"default": "next"
|
|
@@ -46,6 +43,7 @@
|
|
|
46
43
|
"typography": {
|
|
47
44
|
"fontSize": true,
|
|
48
45
|
"lineHeight": true,
|
|
46
|
+
"textAlign": true,
|
|
49
47
|
"__experimentalFontFamily": true,
|
|
50
48
|
"__experimentalFontWeight": true,
|
|
51
49
|
"__experimentalFontStyle": true,
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// packages/block-library/src/post-navigation-link/deprecated.js
|
|
2
|
+
import migrateTextAlign from "../utils/migrate-text-align.mjs";
|
|
3
|
+
var v1 = {
|
|
4
|
+
attributes: {
|
|
5
|
+
textAlign: {
|
|
6
|
+
type: "string"
|
|
7
|
+
},
|
|
8
|
+
type: {
|
|
9
|
+
type: "string",
|
|
10
|
+
default: "next"
|
|
11
|
+
},
|
|
12
|
+
label: {
|
|
13
|
+
type: "string",
|
|
14
|
+
role: "content"
|
|
15
|
+
},
|
|
16
|
+
showTitle: {
|
|
17
|
+
type: "boolean",
|
|
18
|
+
default: false
|
|
19
|
+
},
|
|
20
|
+
linkLabel: {
|
|
21
|
+
type: "boolean",
|
|
22
|
+
default: false
|
|
23
|
+
},
|
|
24
|
+
arrow: {
|
|
25
|
+
type: "string",
|
|
26
|
+
default: "none"
|
|
27
|
+
},
|
|
28
|
+
taxonomy: {
|
|
29
|
+
type: "string",
|
|
30
|
+
default: ""
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
supports: {
|
|
34
|
+
anchor: true,
|
|
35
|
+
reusable: false,
|
|
36
|
+
html: false,
|
|
37
|
+
color: {
|
|
38
|
+
link: true
|
|
39
|
+
},
|
|
40
|
+
typography: {
|
|
41
|
+
fontSize: true,
|
|
42
|
+
lineHeight: true,
|
|
43
|
+
__experimentalFontFamily: true,
|
|
44
|
+
__experimentalFontWeight: true,
|
|
45
|
+
__experimentalFontStyle: true,
|
|
46
|
+
__experimentalTextTransform: true,
|
|
47
|
+
__experimentalTextDecoration: true,
|
|
48
|
+
__experimentalLetterSpacing: true,
|
|
49
|
+
__experimentalDefaultControls: {
|
|
50
|
+
fontSize: true
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
interactivity: {
|
|
54
|
+
clientNavigation: true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
migrate: migrateTextAlign,
|
|
58
|
+
isEligible(attributes) {
|
|
59
|
+
return !!attributes.textAlign || !!attributes.className?.match(
|
|
60
|
+
/\bhas-text-align-(left|center|right)\b/
|
|
61
|
+
);
|
|
62
|
+
},
|
|
63
|
+
save: () => null
|
|
64
|
+
};
|
|
65
|
+
var deprecated_default = [v1];
|
|
66
|
+
export {
|
|
67
|
+
deprecated_default as default
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=deprecated.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/post-navigation-link/deprecated.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport migrateTextAlign from '../utils/migrate-text-align';\n\nconst v1 = {\n\tattributes: {\n\t\ttextAlign: {\n\t\t\ttype: 'string',\n\t\t},\n\t\ttype: {\n\t\t\ttype: 'string',\n\t\t\tdefault: 'next',\n\t\t},\n\t\tlabel: {\n\t\t\ttype: 'string',\n\t\t\trole: 'content',\n\t\t},\n\t\tshowTitle: {\n\t\t\ttype: 'boolean',\n\t\t\tdefault: false,\n\t\t},\n\t\tlinkLabel: {\n\t\t\ttype: 'boolean',\n\t\t\tdefault: false,\n\t\t},\n\t\tarrow: {\n\t\t\ttype: 'string',\n\t\t\tdefault: 'none',\n\t\t},\n\t\ttaxonomy: {\n\t\t\ttype: 'string',\n\t\t\tdefault: '',\n\t\t},\n\t},\n\tsupports: {\n\t\tanchor: true,\n\t\treusable: false,\n\t\thtml: false,\n\t\tcolor: {\n\t\t\tlink: true,\n\t\t},\n\t\ttypography: {\n\t\t\tfontSize: true,\n\t\t\tlineHeight: true,\n\t\t\t__experimentalFontFamily: true,\n\t\t\t__experimentalFontWeight: true,\n\t\t\t__experimentalFontStyle: true,\n\t\t\t__experimentalTextTransform: true,\n\t\t\t__experimentalTextDecoration: true,\n\t\t\t__experimentalLetterSpacing: true,\n\t\t\t__experimentalDefaultControls: {\n\t\t\t\tfontSize: true,\n\t\t\t},\n\t\t},\n\t\tinteractivity: {\n\t\t\tclientNavigation: true,\n\t\t},\n\t},\n\tmigrate: migrateTextAlign,\n\tisEligible( attributes ) {\n\t\treturn (\n\t\t\t!! attributes.textAlign ||\n\t\t\t!! attributes.className?.match(\n\t\t\t\t/\\bhas-text-align-(left|center|right)\\b/\n\t\t\t)\n\t\t);\n\t},\n\tsave: () => null,\n};\n\nexport default [ v1 ];\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,sBAAsB;AAE7B,IAAM,KAAK;AAAA,EACV,YAAY;AAAA,IACX,WAAW;AAAA,MACV,MAAM;AAAA,IACP;AAAA,IACA,MAAM;AAAA,MACL,MAAM;AAAA,MACN,SAAS;AAAA,IACV;AAAA,IACA,OAAO;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,IACP;AAAA,IACA,WAAW;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,IACV;AAAA,IACA,WAAW;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,IACV;AAAA,IACA,OAAO;AAAA,MACN,MAAM;AAAA,MACN,SAAS;AAAA,IACV;AAAA,IACA,UAAU;AAAA,MACT,MAAM;AAAA,MACN,SAAS;AAAA,IACV;AAAA,EACD;AAAA,EACA,UAAU;AAAA,IACT,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,MAAM;AAAA,IACN,OAAO;AAAA,MACN,MAAM;AAAA,IACP;AAAA,IACA,YAAY;AAAA,MACX,UAAU;AAAA,MACV,YAAY;AAAA,MACZ,0BAA0B;AAAA,MAC1B,0BAA0B;AAAA,MAC1B,yBAAyB;AAAA,MACzB,6BAA6B;AAAA,MAC7B,8BAA8B;AAAA,MAC9B,6BAA6B;AAAA,MAC7B,+BAA+B;AAAA,QAC9B,UAAU;AAAA,MACX;AAAA,IACD;AAAA,IACA,eAAe;AAAA,MACd,kBAAkB;AAAA,IACnB;AAAA,EACD;AAAA,EACA,SAAS;AAAA,EACT,WAAY,YAAa;AACxB,WACC,CAAC,CAAE,WAAW,aACd,CAAC,CAAE,WAAW,WAAW;AAAA,MACxB;AAAA,IACD;AAAA,EAEF;AAAA,EACA,MAAM,MAAM;AACb;AAEA,IAAO,qBAAQ,CAAE,EAAG;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// packages/block-library/src/post-navigation-link/edit.js
|
|
2
|
-
import clsx from "clsx";
|
|
3
2
|
import {
|
|
4
3
|
__experimentalToggleGroupControl as ToggleGroupControl,
|
|
5
4
|
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
|
|
@@ -11,10 +10,7 @@ import {
|
|
|
11
10
|
import {
|
|
12
11
|
InspectorControls,
|
|
13
12
|
RichText,
|
|
14
|
-
|
|
15
|
-
AlignmentToolbar,
|
|
16
|
-
useBlockProps,
|
|
17
|
-
useBlockEditingMode
|
|
13
|
+
useBlockProps
|
|
18
14
|
} from "@wordpress/block-editor";
|
|
19
15
|
import { __, _x } from "@wordpress/i18n";
|
|
20
16
|
import { useSelect } from "@wordpress/data";
|
|
@@ -23,19 +19,9 @@ import { useToolsPanelDropdownMenuProps } from "../utils/hooks.mjs";
|
|
|
23
19
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
24
20
|
function PostNavigationLinkEdit({
|
|
25
21
|
context: { postType },
|
|
26
|
-
attributes: {
|
|
27
|
-
type,
|
|
28
|
-
label,
|
|
29
|
-
showTitle,
|
|
30
|
-
textAlign,
|
|
31
|
-
linkLabel,
|
|
32
|
-
arrow,
|
|
33
|
-
taxonomy
|
|
34
|
-
},
|
|
22
|
+
attributes: { type, label, showTitle, linkLabel, arrow, taxonomy },
|
|
35
23
|
setAttributes
|
|
36
24
|
}) {
|
|
37
|
-
const blockEditingMode = useBlockEditingMode();
|
|
38
|
-
const showControls = blockEditingMode === "default";
|
|
39
25
|
const isNext = type === "next";
|
|
40
26
|
let placeholder = isNext ? __("Next") : __("Previous");
|
|
41
27
|
const arrowMap = {
|
|
@@ -54,11 +40,7 @@ function PostNavigationLinkEdit({
|
|
|
54
40
|
);
|
|
55
41
|
}
|
|
56
42
|
const ariaLabel = isNext ? __("Next post") : __("Previous post");
|
|
57
|
-
const blockProps = useBlockProps(
|
|
58
|
-
className: clsx({
|
|
59
|
-
[`has-text-align-${textAlign}`]: textAlign
|
|
60
|
-
})
|
|
61
|
-
});
|
|
43
|
+
const blockProps = useBlockProps();
|
|
62
44
|
const taxonomies = useSelect(
|
|
63
45
|
(select) => {
|
|
64
46
|
const { getTaxonomies } = select(coreStore);
|
|
@@ -217,15 +199,6 @@ function PostNavigationLinkEdit({
|
|
|
217
199
|
)
|
|
218
200
|
}
|
|
219
201
|
) }),
|
|
220
|
-
showControls && /* @__PURE__ */ jsx(BlockControls, { children: /* @__PURE__ */ jsx(
|
|
221
|
-
AlignmentToolbar,
|
|
222
|
-
{
|
|
223
|
-
value: textAlign,
|
|
224
|
-
onChange: (nextAlign) => {
|
|
225
|
-
setAttributes({ textAlign: nextAlign });
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
) }),
|
|
229
202
|
/* @__PURE__ */ jsxs("div", { ...blockProps, children: [
|
|
230
203
|
!isNext && displayArrow && /* @__PURE__ */ jsx(
|
|
231
204
|
"span",
|