@wordpress/block-library 9.33.2-next.36001005c.0 → 9.33.3
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/block.json +1 -1
- package/build/accordion/edit.js +11 -9
- package/build/accordion/edit.js.map +2 -2
- package/build/accordion-heading/block.json +1 -1
- package/build/accordion-item/block.json +1 -1
- package/build/accordion-panel/block.json +1 -1
- package/build/buttons/transforms.js +1 -0
- package/build/buttons/transforms.js.map +2 -2
- package/build/code/transforms.js +2 -0
- package/build/code/transforms.js.map +2 -2
- package/build/freeform/block.json +5 -1
- package/build/home-link/block.json +2 -1
- package/build/image/view.js +4 -1
- package/build/image/view.js.map +2 -2
- package/build/math/deprecated.js +54 -0
- package/build/math/deprecated.js.map +7 -0
- package/build/math/edit.js +1 -0
- package/build/math/edit.js.map +2 -2
- package/build/math/index.js +3 -1
- package/build/math/index.js.map +3 -3
- package/build/math/save.js +2 -3
- package/build/math/save.js.map +2 -2
- package/build/missing/block.json +3 -0
- package/build/navigation/edit/menu-inspector-controls.js +1 -1
- package/build/navigation/edit/menu-inspector-controls.js.map +2 -2
- package/build/navigation/menu-items-to-blocks.js +8 -3
- package/build/navigation/menu-items-to-blocks.js.map +2 -2
- package/build/navigation/view.js +2 -2
- package/build/navigation/view.js.map +2 -2
- package/build/navigation-link/edit.js +1 -1
- package/build/navigation-link/edit.js.map +2 -2
- package/build/navigation-link/shared/controls.js +16 -36
- package/build/navigation-link/shared/controls.js.map +2 -2
- package/build/navigation-link/shared/use-entity-binding.js +1 -1
- package/build/navigation-link/shared/use-entity-binding.js.map +2 -2
- package/build/navigation-submenu/edit.js +1 -1
- package/build/navigation-submenu/edit.js.map +2 -2
- package/build/post-date/block.json +1 -1
- package/build/post-date/edit.js +11 -5
- package/build/post-date/edit.js.map +3 -3
- package/build/post-date/variations.js +4 -7
- package/build/post-date/variations.js.map +2 -2
- package/build/post-template/edit.js +13 -1
- package/build/post-template/edit.js.map +2 -2
- package/build/query/index.js +11 -1
- package/build/query/index.js.map +2 -2
- package/build/query/variations.js +16 -11
- package/build/query/variations.js.map +2 -2
- package/build/search/view.js +4 -4
- package/build/search/view.js.map +2 -2
- package/build/terms-query/edit/inspector-controls/index.js +1 -1
- package/build/terms-query/edit/inspector-controls/index.js.map +2 -2
- package/build/terms-query/edit/inspector-controls/inherit-control.js +2 -4
- package/build/terms-query/edit/inspector-controls/inherit-control.js.map +2 -2
- package/build/utils/get-transformed-attributes.js +1 -13
- package/build/utils/get-transformed-attributes.js.map +2 -2
- package/build-module/accordion/block.json +1 -1
- package/build-module/accordion/edit.js +11 -9
- package/build-module/accordion/edit.js.map +2 -2
- package/build-module/accordion-heading/block.json +1 -1
- package/build-module/accordion-item/block.json +1 -1
- package/build-module/accordion-panel/block.json +1 -1
- package/build-module/buttons/transforms.js +1 -0
- package/build-module/buttons/transforms.js.map +2 -2
- package/build-module/code/transforms.js +2 -0
- package/build-module/code/transforms.js.map +2 -2
- package/build-module/freeform/block.json +5 -1
- package/build-module/home-link/block.json +2 -1
- package/build-module/image/view.js +4 -1
- package/build-module/image/view.js.map +2 -2
- package/build-module/math/deprecated.js +34 -0
- package/build-module/math/deprecated.js.map +7 -0
- package/build-module/math/edit.js +1 -0
- package/build-module/math/edit.js.map +2 -2
- package/build-module/math/index.js +3 -1
- package/build-module/math/index.js.map +2 -2
- package/build-module/math/save.js +2 -3
- package/build-module/math/save.js.map +2 -2
- package/build-module/missing/block.json +3 -0
- package/build-module/navigation/edit/menu-inspector-controls.js +1 -1
- package/build-module/navigation/edit/menu-inspector-controls.js.map +2 -2
- package/build-module/navigation/menu-items-to-blocks.js +8 -3
- package/build-module/navigation/menu-items-to-blocks.js.map +2 -2
- package/build-module/navigation/view.js +2 -2
- package/build-module/navigation/view.js.map +2 -2
- package/build-module/navigation-link/edit.js +1 -1
- package/build-module/navigation-link/edit.js.map +2 -2
- package/build-module/navigation-link/shared/controls.js +17 -37
- package/build-module/navigation-link/shared/controls.js.map +2 -2
- package/build-module/navigation-link/shared/use-entity-binding.js +1 -1
- package/build-module/navigation-link/shared/use-entity-binding.js.map +2 -2
- package/build-module/navigation-submenu/edit.js +1 -1
- package/build-module/navigation-submenu/edit.js.map +2 -2
- package/build-module/post-date/block.json +1 -1
- package/build-module/post-date/edit.js +11 -5
- package/build-module/post-date/edit.js.map +2 -2
- package/build-module/post-date/variations.js +4 -7
- package/build-module/post-date/variations.js.map +2 -2
- package/build-module/post-template/edit.js +13 -1
- package/build-module/post-template/edit.js.map +2 -2
- package/build-module/query/index.js +11 -1
- package/build-module/query/index.js.map +2 -2
- package/build-module/query/variations.js +16 -11
- package/build-module/query/variations.js.map +2 -2
- package/build-module/search/view.js +4 -4
- package/build-module/search/view.js.map +2 -2
- package/build-module/terms-query/edit/inspector-controls/index.js +1 -1
- package/build-module/terms-query/edit/inspector-controls/index.js.map +2 -2
- package/build-module/terms-query/edit/inspector-controls/inherit-control.js +2 -4
- package/build-module/terms-query/edit/inspector-controls/inherit-control.js.map +2 -2
- package/build-module/utils/get-transformed-attributes.js +1 -13
- package/build-module/utils/get-transformed-attributes.js.map +2 -2
- package/build-style/editor-rtl.css +7 -2
- package/build-style/editor.css +8 -2
- package/build-style/math/editor-rtl.css +49 -0
- package/build-style/math/editor.css +50 -0
- package/build-style/math/style-rtl.css +4 -0
- package/build-style/math/style.css +4 -0
- package/build-style/navigation-link/editor-rtl.css +1 -1
- package/build-style/navigation-link/editor.css +1 -1
- package/build-style/style-rtl.css +5 -0
- package/build-style/style.css +5 -0
- package/build-style/video/editor-rtl.css +1 -1
- package/build-style/video/editor.css +1 -1
- package/package.json +37 -37
- package/src/accordion/block.json +1 -1
- package/src/accordion/edit.js +16 -16
- package/src/accordion-heading/block.json +1 -1
- package/src/accordion-item/block.json +1 -1
- package/src/accordion-panel/block.json +1 -1
- package/src/archives/index.php +53 -1
- package/src/buttons/transforms.js +1 -0
- package/src/categories/index.php +25 -7
- package/src/code/transforms.js +2 -0
- package/src/editor.scss +1 -0
- package/src/freeform/block.json +5 -1
- package/src/home-link/block.json +2 -1
- package/src/image/index.php +9 -9
- package/src/image/view.js +11 -1
- package/src/math/deprecated.js +44 -0
- package/src/math/edit.js +1 -0
- package/src/math/editor.scss +7 -0
- package/src/math/index.js +2 -0
- package/src/math/save.js +6 -5
- package/src/math/style.scss +4 -0
- package/src/missing/block.json +3 -0
- package/src/navigation/edit/menu-inspector-controls.js +1 -1
- package/src/navigation/index.php +7 -7
- package/src/navigation/menu-items-to-blocks.js +12 -2
- package/src/navigation/test/menu-items-to-blocks.js +144 -0
- package/src/navigation/view.js +2 -2
- package/src/navigation-link/edit.js +1 -1
- package/src/navigation-link/editor.scss +1 -1
- package/src/navigation-link/shared/controls.js +18 -58
- package/src/navigation-link/shared/test/controls.js +9 -14
- package/src/navigation-link/shared/use-entity-binding.js +1 -1
- package/src/navigation-submenu/edit.js +1 -1
- package/src/post-date/block.json +1 -1
- package/src/post-date/edit.js +15 -10
- package/src/post-date/variations.js +2 -5
- package/src/post-template/edit.js +13 -1
- package/src/query/index.js +10 -0
- package/src/query/variations.js +17 -11
- package/src/query-pagination-next/index.php +1 -1
- package/src/query-pagination-previous/index.php +1 -1
- package/src/search/index.php +2 -2
- package/src/search/view.js +4 -4
- package/src/style.scss +1 -0
- package/src/term-template/index.php +8 -2
- package/src/terms-query/edit/inspector-controls/index.js +2 -2
- package/src/terms-query/edit/inspector-controls/inherit-control.js +1 -3
- package/src/utils/get-transformed-attributes.js +5 -22
- package/src/video/editor.scss +1 -1
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
TextareaControl
|
|
10
10
|
} from "@wordpress/components";
|
|
11
11
|
import { __, sprintf } from "@wordpress/i18n";
|
|
12
|
-
import { useRef
|
|
12
|
+
import { useRef } from "@wordpress/element";
|
|
13
13
|
import { useInstanceId } from "@wordpress/compose";
|
|
14
14
|
import { safeDecodeURI } from "@wordpress/url";
|
|
15
15
|
import { __unstableStripHTML as stripHTML } from "@wordpress/dom";
|
|
@@ -46,34 +46,17 @@ function Controls({ attributes, setAttributes, clientId }) {
|
|
|
46
46
|
const { label, url, description, rel, opensInNewTab } = attributes;
|
|
47
47
|
const lastURLRef = useRef(url);
|
|
48
48
|
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
|
|
49
|
-
const urlInputRef = useRef();
|
|
50
|
-
const shouldFocusURLInputRef = useRef(false);
|
|
51
49
|
const inputId = useInstanceId(Controls, "link-input");
|
|
52
50
|
const helpTextId = `${inputId}__help`;
|
|
53
|
-
const [inputValue, setInputValue] = useState(url);
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
setInputValue(url);
|
|
56
|
-
lastURLRef.current = url;
|
|
57
|
-
}, [url]);
|
|
58
51
|
const { hasUrlBinding, clearBinding } = useEntityBinding({
|
|
59
52
|
clientId,
|
|
60
53
|
attributes
|
|
61
54
|
});
|
|
62
55
|
const { updateBlockAttributes } = useDispatch(blockEditorStore);
|
|
63
|
-
const
|
|
56
|
+
const editBoundLink = () => {
|
|
64
57
|
clearBinding();
|
|
65
|
-
updateBlockAttributes(clientId, {
|
|
66
|
-
url: lastURLRef.current,
|
|
67
|
-
// set the lastURLRef as the new editable value so we avoid bugs from empty link states
|
|
68
|
-
id: void 0
|
|
69
|
-
});
|
|
58
|
+
updateBlockAttributes(clientId, { url: "", id: void 0 });
|
|
70
59
|
};
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
if (!hasUrlBinding && shouldFocusURLInputRef.current) {
|
|
73
|
-
urlInputRef.current?.select();
|
|
74
|
-
}
|
|
75
|
-
shouldFocusURLInputRef.current = false;
|
|
76
|
-
}, [hasUrlBinding]);
|
|
77
60
|
return /* @__PURE__ */ jsxs(
|
|
78
61
|
ToolsPanel,
|
|
79
62
|
{
|
|
@@ -121,21 +104,22 @@ function Controls({ attributes, setAttributes, clientId }) {
|
|
|
121
104
|
children: /* @__PURE__ */ jsx(
|
|
122
105
|
InputControl,
|
|
123
106
|
{
|
|
124
|
-
ref: urlInputRef,
|
|
125
107
|
__nextHasNoMarginBottom: true,
|
|
126
108
|
__next40pxDefaultSize: true,
|
|
127
109
|
id: inputId,
|
|
128
110
|
label: __("Link"),
|
|
129
|
-
value:
|
|
130
|
-
|
|
131
|
-
type: "url",
|
|
132
|
-
disabled: hasUrlBinding,
|
|
133
|
-
onChange: (newValue) => {
|
|
111
|
+
value: url ? safeDecodeURI(url) : "",
|
|
112
|
+
onChange: (urlValue) => {
|
|
134
113
|
if (hasUrlBinding) {
|
|
135
114
|
return;
|
|
136
115
|
}
|
|
137
|
-
|
|
116
|
+
setAttributes({
|
|
117
|
+
url: encodeURI(safeDecodeURI(urlValue))
|
|
118
|
+
});
|
|
138
119
|
},
|
|
120
|
+
autoComplete: "off",
|
|
121
|
+
type: "url",
|
|
122
|
+
disabled: hasUrlBinding,
|
|
139
123
|
onFocus: () => {
|
|
140
124
|
if (hasUrlBinding) {
|
|
141
125
|
return;
|
|
@@ -146,12 +130,11 @@ function Controls({ attributes, setAttributes, clientId }) {
|
|
|
146
130
|
if (hasUrlBinding) {
|
|
147
131
|
return;
|
|
148
132
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
...attributes,
|
|
153
|
-
|
|
154
|
-
});
|
|
133
|
+
updateAttributes(
|
|
134
|
+
{ url: !url ? lastURLRef.current : url },
|
|
135
|
+
setAttributes,
|
|
136
|
+
{ ...attributes, url: lastURLRef.current }
|
|
137
|
+
);
|
|
155
138
|
},
|
|
156
139
|
help: hasUrlBinding && /* @__PURE__ */ jsx(
|
|
157
140
|
BindingHelpText,
|
|
@@ -164,10 +147,7 @@ function Controls({ attributes, setAttributes, clientId }) {
|
|
|
164
147
|
Button,
|
|
165
148
|
{
|
|
166
149
|
icon: unlinkIcon,
|
|
167
|
-
onClick:
|
|
168
|
-
unsyncBoundLink();
|
|
169
|
-
shouldFocusURLInputRef.current = true;
|
|
170
|
-
},
|
|
150
|
+
onClick: editBoundLink,
|
|
171
151
|
"aria-describedby": helpTextId,
|
|
172
152
|
showTooltip: true,
|
|
173
153
|
label: __("Unsync and edit"),
|
|
@@ -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\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalInputControl as InputControl,\n\tButton,\n\tCheckboxControl,\n\tTextControl,\n\tTextareaControl,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useRef, useEffect, useState } from '@wordpress/element';\nimport { useInstanceId } from '@wordpress/compose';\nimport { safeDecodeURI } from '@wordpress/url';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { linkOff as unlinkIcon } from '@wordpress/icons';\nimport { useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelDropdownMenuProps } from '../../utils/hooks';\nimport { updateAttributes } from './update-attributes';\nimport { useEntityBinding } from './use-entity-binding';\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 */\nexport function Controls( { attributes, setAttributes, clientId } ) {\n\tconst { label, url, description, rel, opensInNewTab } = attributes;\n\tconst lastURLRef = useRef( url );\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\tconst urlInputRef = useRef();\n\tconst shouldFocusURLInputRef = useRef( false );\n\tconst inputId = useInstanceId( Controls, 'link-input' );\n\tconst helpTextId = `${ inputId }__help`;\n\n\t// Local state to control the input value\n\tconst [ inputValue, setInputValue ] = useState( url );\n\n\t// Sync local state when url prop changes (e.g., from undo/redo or external updates)\n\tuseEffect( () => {\n\t\tsetInputValue( url );\n\t\tlastURLRef.current = url;\n\t}, [ url ] );\n\n\t// Use the entity binding hook internally\n\tconst { hasUrlBinding, clearBinding } = useEntityBinding( {\n\t\tclientId,\n\t\tattributes,\n\t} );\n\n\t// Get direct store dispatch to bypass setBoundAttributes wrapper\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\n\tconst unsyncBoundLink = () => {\n\t\t// Clear the binding first\n\t\tclearBinding();\n\n\t\t// Use direct store dispatch to bypass block bindings safeguards\n\t\t// which prevent updates to bound attributes when calling setAttributes.\n\t\t// setAttributes is actually setBoundAttributes, a wrapper function that\n\t\t// processes attributes through the binding system.\n\t\t// See: packages/block-editor/src/components/block-edit/edit.js\n\t\tupdateBlockAttributes( clientId, {\n\t\t\turl: lastURLRef.current, // set the lastURLRef as the new editable value so we avoid bugs from empty link states\n\t\t\tid: undefined,\n\t\t} );\n\t};\n\n\tuseEffect( () => {\n\t\t// Checking for ! hasUrlBinding is a defensive check, as we would\n\t\t// only want to focus the input if the url is not bound to an entity.\n\t\tif ( ! hasUrlBinding && shouldFocusURLInputRef.current ) {\n\t\t\t// focuses and highlights the url input value, giving the user\n\t\t\t// the ability to delete the value quickly or edit it.\n\t\t\turlInputRef.current?.select();\n\t\t}\n\t\tshouldFocusURLInputRef.current = false;\n\t}, [ hasUrlBinding ] );\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__nextHasNoMarginBottom\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<ToolsPanelItem\n\t\t\t\thasValue={ () => !! url }\n\t\t\t\tlabel={ __( 'Link' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { url: '' } ) }\n\t\t\t\tisShownByDefault\n\t\t\t>\n\t\t\t\t<InputControl\n\t\t\t\t\tref={ urlInputRef }\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tid={ inputId }\n\t\t\t\t\tlabel={ __( 'Link' ) }\n\t\t\t\t\tvalue={ inputValue ? safeDecodeURI( inputValue ) : '' }\n\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\ttype=\"url\"\n\t\t\t\t\tdisabled={ hasUrlBinding }\n\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\tif ( hasUrlBinding ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Defer updating the url attribute until onBlur to prevent the canvas from\n\t\t\t\t\t\t// treating a temporary empty value as a committed value, which replaces the\n\t\t\t\t\t\t// label with placeholder text.\n\t\t\t\t\t\tsetInputValue( newValue );\n\t\t\t\t\t} }\n\t\t\t\t\tonFocus={ () => {\n\t\t\t\t\t\tif ( hasUrlBinding ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlastURLRef.current = url;\n\t\t\t\t\t} }\n\t\t\t\t\tonBlur={ () => {\n\t\t\t\t\t\tif ( hasUrlBinding ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst finalValue = ! inputValue\n\t\t\t\t\t\t\t? lastURLRef.current\n\t\t\t\t\t\t\t: inputValue;\n\n\t\t\t\t\t\t// Update local state immediately so input reflects the reverted value if the value was cleared\n\t\t\t\t\t\tsetInputValue( finalValue );\n\n\t\t\t\t\t\t// Defer the updateAttributes call to ensure entity connection isn't severed by accident.\n\t\t\t\t\t\tupdateAttributes( { url: finalValue }, setAttributes, {\n\t\t\t\t\t\t\t...attributes,\n\t\t\t\t\t\t\turl: lastURLRef.current,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\thelp={\n\t\t\t\t\t\thasUrlBinding && (\n\t\t\t\t\t\t\t<BindingHelpText\n\t\t\t\t\t\t\t\ttype={ attributes.type }\n\t\t\t\t\t\t\t\tkind={ attributes.kind }\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\tsuffix={\n\t\t\t\t\t\thasUrlBinding && (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\ticon={ unlinkIcon }\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tunsyncBoundLink();\n\t\t\t\t\t\t\t\t\t// Focus management to send focus to the URL input\n\t\t\t\t\t\t\t\t\t// on next render after disabled state is removed.\n\t\t\t\t\t\t\t\t\tshouldFocusURLInputRef.current = true;\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\taria-describedby={ helpTextId }\n\t\t\t\t\t\t\t\tshowTooltip\n\t\t\t\t\t\t\t\tlabel={ __( 'Unsync and edit' ) }\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => !! opensInNewTab }\n\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { opensInNewTab: false } ) }\n\t\t\t\tisShownByDefault\n\t\t\t>\n\t\t\t\t<CheckboxControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\t\tchecked={ opensInNewTab }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { opensInNewTab: value } )\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={ () => !! description }\n\t\t\t\tlabel={ __( 'Description' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { description: '' } ) }\n\t\t\t\tisShownByDefault\n\t\t\t>\n\t\t\t\t<TextareaControl\n\t\t\t\t\t__nextHasNoMarginBottom\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\n\t\t\t>\n\t\t\t\t<TextControl\n\t\t\t\t\t__nextHasNoMarginBottom\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/**\n * Component to display help text for bound URL attributes.\n *\n * @param {Object} props - Component props\n * @param {string} props.type - The entity type\n * @param {string} props.kind - The entity kind\n * @return {string} Help text for the bound URL\n */\nfunction BindingHelpText( { type, kind } ) {\n\tconst entityType = getEntityTypeName( type, kind );\n\treturn sprintf(\n\t\t/* translators: %s is the entity type (e.g., \"page\", \"post\", \"category\") */\n\t\t__( 'Synced with the selected %s.' ),\n\t\tentityType\n\t);\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalInputControl as InputControl,\n\tButton,\n\tCheckboxControl,\n\tTextControl,\n\tTextareaControl,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useRef } from '@wordpress/element';\nimport { useInstanceId } from '@wordpress/compose';\nimport { safeDecodeURI } from '@wordpress/url';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { linkOff as unlinkIcon } from '@wordpress/icons';\nimport { useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelDropdownMenuProps } from '../../utils/hooks';\nimport { updateAttributes } from './update-attributes';\nimport { useEntityBinding } from './use-entity-binding';\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 */\nexport function Controls( { attributes, setAttributes, clientId } ) {\n\tconst { label, url, description, rel, opensInNewTab } = attributes;\n\tconst lastURLRef = useRef( url );\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\tconst inputId = useInstanceId( Controls, 'link-input' );\n\tconst helpTextId = `${ inputId }__help`;\n\n\t// Use the entity binding hook internally\n\tconst { hasUrlBinding, clearBinding } = useEntityBinding( {\n\t\tclientId,\n\t\tattributes,\n\t} );\n\n\t// Get direct store dispatch to bypass setBoundAttributes wrapper\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\n\tconst editBoundLink = () => {\n\t\t// Clear the binding first\n\t\tclearBinding();\n\n\t\t// Use direct store dispatch to bypass block bindings safeguards\n\t\t// which prevent updates to bound attributes when calling setAttributes.\n\t\t// setAttributes is actually setBoundAttributes, a wrapper function that\n\t\t// processes attributes through the binding system.\n\t\t// See: packages/block-editor/src/components/block-edit/edit.js\n\t\tupdateBlockAttributes( clientId, { url: '', id: undefined } );\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__nextHasNoMarginBottom\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<ToolsPanelItem\n\t\t\t\thasValue={ () => !! url }\n\t\t\t\tlabel={ __( 'Link' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { url: '' } ) }\n\t\t\t\tisShownByDefault\n\t\t\t>\n\t\t\t\t<InputControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tid={ inputId }\n\t\t\t\t\tlabel={ __( 'Link' ) }\n\t\t\t\t\tvalue={ url ? safeDecodeURI( url ) : '' }\n\t\t\t\t\tonChange={ ( urlValue ) => {\n\t\t\t\t\t\tif ( hasUrlBinding ) {\n\t\t\t\t\t\t\treturn; // Prevent editing when URL is bound\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\turl: encodeURI( safeDecodeURI( urlValue ) ),\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\ttype=\"url\"\n\t\t\t\t\tdisabled={ hasUrlBinding }\n\t\t\t\t\tonFocus={ () => {\n\t\t\t\t\t\tif ( hasUrlBinding ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlastURLRef.current = url;\n\t\t\t\t\t} }\n\t\t\t\t\tonBlur={ () => {\n\t\t\t\t\t\tif ( hasUrlBinding ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Defer the updateAttributes call to ensure entity connection isn't severed by accident.\n\t\t\t\t\t\tupdateAttributes(\n\t\t\t\t\t\t\t{ url: ! url ? lastURLRef.current : url },\n\t\t\t\t\t\t\tsetAttributes,\n\t\t\t\t\t\t\t{ ...attributes, url: lastURLRef.current }\n\t\t\t\t\t\t);\n\t\t\t\t\t} }\n\t\t\t\t\thelp={\n\t\t\t\t\t\thasUrlBinding && (\n\t\t\t\t\t\t\t<BindingHelpText\n\t\t\t\t\t\t\t\ttype={ attributes.type }\n\t\t\t\t\t\t\t\tkind={ attributes.kind }\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\tsuffix={\n\t\t\t\t\t\thasUrlBinding && (\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\ticon={ unlinkIcon }\n\t\t\t\t\t\t\t\tonClick={ editBoundLink }\n\t\t\t\t\t\t\t\taria-describedby={ helpTextId }\n\t\t\t\t\t\t\t\tshowTooltip\n\t\t\t\t\t\t\t\tlabel={ __( 'Unsync and edit' ) }\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => !! opensInNewTab }\n\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { opensInNewTab: false } ) }\n\t\t\t\tisShownByDefault\n\t\t\t>\n\t\t\t\t<CheckboxControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Open in new tab' ) }\n\t\t\t\t\tchecked={ opensInNewTab }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { opensInNewTab: value } )\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={ () => !! description }\n\t\t\t\tlabel={ __( 'Description' ) }\n\t\t\t\tonDeselect={ () => setAttributes( { description: '' } ) }\n\t\t\t\tisShownByDefault\n\t\t\t>\n\t\t\t\t<TextareaControl\n\t\t\t\t\t__nextHasNoMarginBottom\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\n\t\t\t>\n\t\t\t\t<TextControl\n\t\t\t\t\t__nextHasNoMarginBottom\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/**\n * Component to display help text for bound URL attributes.\n *\n * @param {Object} props - Component props\n * @param {string} props.type - The entity type\n * @param {string} props.kind - The entity kind\n * @return {string} Help text for the bound URL\n */\nfunction BindingHelpText( { type, kind } ) {\n\tconst entityType = getEntityTypeName( type, kind );\n\treturn sprintf(\n\t\t/* translators: %s is the entity type (e.g., \"page\", \"post\", \"category\") */\n\t\t__( 'Synced with the selected %s.' ),\n\t\tentityType\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAmGE,SAmBE,KAnBF;AAhGF;AAAA,EACC,4BAA4B;AAAA,EAC5B,gCAAgC;AAAA,EAChC,8BAA8B;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,IAAI,eAAe;AAC5B,SAAS,cAAc;AACvB,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB,iBAAiB;AACjD,SAAS,WAAW,kBAAkB;AACtC,SAAS,mBAAmB;AAC5B,SAAS,SAAS,wBAAwB;AAK1C,SAAS,sCAAsC;AAC/C,SAAS,wBAAwB;AACjC,SAAS,wBAAw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CAAE;AAAA,YACpB,OAAQ,GAAI,eAAgB;AAAA,YAC5B,YAAa,MAAM,cAAe,EAAE,KAAK,GAAG,CAAE;AAAA,YAC9C,kBAAgB;AAAA,YAEhB;AAAA,cAAC;AAAA;AAAA,gBACA,yBAAuB;AAAA,gBACvB,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;AAUA,SAAS,gBAAiB,EAAE,MAAM,KAAK,GAAI;AAC1C,QAAM,aAAa,kBAAmB,MAAM,IAAK;AACjD,SAAO;AAAA;AAAA,IAEN,GAAI,8BAA+B;AAAA,IACnC;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -31,7 +31,7 @@ function useEntityBinding({ clientId, attributes }) {
|
|
|
31
31
|
if (hasUrlBinding) {
|
|
32
32
|
updateBlockBindings({ url: void 0 });
|
|
33
33
|
}
|
|
34
|
-
}, [updateBlockBindings, hasUrlBinding]);
|
|
34
|
+
}, [updateBlockBindings, hasUrlBinding, metadata, id]);
|
|
35
35
|
const createBinding = useCallback(
|
|
36
36
|
(updatedAttributes) => {
|
|
37
37
|
const kindToUse = updatedAttributes?.kind ?? kind;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/navigation-link/shared/use-entity-binding.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { useBlockBindingsUtils } from '@wordpress/block-editor';\n\n/**\n * Builds entity binding configuration for navigation link URLs.\n * This function generates the structure used to bind navigation link URLs to their entity sources.\n *\n * Using a function instead of a constant allows for future enhancements where the binding\n * might need dynamic data (e.g., entity ID, context-specific arguments).\n *\n * @param {('post-type'|'taxonomy')} kind - The kind of entity. Only 'post-type' and 'taxonomy' are supported.\n * @return {Object} Entity binding configuration object\n * @throws {Error} If kind is not 'post-type' or 'taxonomy'\n */\nexport function buildNavigationLinkEntityBinding( kind ) {\n\t// Validate kind parameter exists\n\tif ( kind === undefined ) {\n\t\tthrow new Error(\n\t\t\t'buildNavigationLinkEntityBinding requires a kind parameter. ' +\n\t\t\t\t'Only \"post-type\" and \"taxonomy\" are supported.'\n\t\t);\n\t}\n\n\t// Validate kind parameter value\n\tif ( kind !== 'post-type' && kind !== 'taxonomy' ) {\n\t\tthrow new Error(\n\t\t\t`Invalid kind \"${ kind }\" provided to buildNavigationLinkEntityBinding. ` +\n\t\t\t\t`Only 'post-type' and 'taxonomy' are supported.`\n\t\t);\n\t}\n\n\tconst source = kind === 'taxonomy' ? 'core/term-data' : 'core/post-data';\n\n\treturn {\n\t\turl: {\n\t\t\tsource,\n\t\t\targs: {\n\t\t\t\tfield: 'link',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Shared hook for entity binding functionality in Navigation blocks.\n *\n * This hook provides common entity binding logic that can be used by both\n * Navigation Link and Navigation Submenu blocks to maintain feature parity.\n *\n * @param {Object} props - Hook parameters\n * @param {string} props.clientId - Block client ID\n * @param {Object} props.attributes - Block attributes\n * @return {Object} Hook return value\n */\nexport function useEntityBinding( { clientId, attributes } ) {\n\tconst { updateBlockBindings } = useBlockBindingsUtils( clientId );\n\tconst { metadata, id, kind } = attributes;\n\n\tconst hasUrlBinding = !! metadata?.bindings?.url && !! id;\n\tconst expectedSource =\n\t\tkind === 'post-type' ? 'core/post-data' : 'core/term-data';\n\tconst hasCorrectBinding =\n\t\thasUrlBinding && metadata?.bindings?.url?.source === expectedSource;\n\n\tconst clearBinding = useCallback( () => {\n\t\tif ( hasUrlBinding ) {\n\t\t\tupdateBlockBindings( { url: undefined } );\n\t\t}\n\t}, [ updateBlockBindings, hasUrlBinding ] );\n\n\tconst createBinding = useCallback(\n\t\t( updatedAttributes ) => {\n\t\t\t// Use updated attributes if provided, otherwise fall back to closure attributes\n\t\t\t// updatedAttributes needed to access the most up-to-date data when called synchronously\n\t\t\tconst kindToUse = updatedAttributes?.kind ?? kind;\n\n\t\t\t// Avoid creating binding if no kind is provided\n\t\t\tif ( ! kindToUse ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst binding = buildNavigationLinkEntityBinding( kindToUse );\n\t\t\t\tupdateBlockBindings( binding );\n\t\t\t} catch ( error ) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'Failed to create entity binding:',\n\t\t\t\t\terror.message\n\t\t\t\t);\n\t\t\t\t// Don't create binding if validation fails\n\t\t\t}\n\t\t},\n\t\t[ updateBlockBindings, kind, id ]\n\t);\n\n\treturn {\n\t\thasUrlBinding: hasCorrectBinding,\n\t\tclearBinding,\n\t\tcreateBinding,\n\t};\n}\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AAa/B,SAAS,iCAAkC,MAAO;AAExD,MAAK,SAAS,QAAY;AACzB,UAAM,IAAI;AAAA,MACT;AAAA,IAED;AAAA,EACD;AAGA,MAAK,SAAS,eAAe,SAAS,YAAa;AAClD,UAAM,IAAI;AAAA,MACT,iBAAkB,IAAK;AAAA,IAExB;AAAA,EACD;AAEA,QAAM,SAAS,SAAS,aAAa,mBAAmB;AAExD,SAAO;AAAA,IACN,KAAK;AAAA,MACJ;AAAA,MACA,MAAM;AAAA,QACL,OAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AACD;AAaO,SAAS,iBAAkB,EAAE,UAAU,WAAW,GAAI;AAC5D,QAAM,EAAE,oBAAoB,IAAI,sBAAuB,QAAS;AAChE,QAAM,EAAE,UAAU,IAAI,KAAK,IAAI;AAE/B,QAAM,gBAAgB,CAAC,CAAE,UAAU,UAAU,OAAO,CAAC,CAAE;AACvD,QAAM,iBACL,SAAS,cAAc,mBAAmB;AAC3C,QAAM,oBACL,iBAAiB,UAAU,UAAU,KAAK,WAAW;AAEtD,QAAM,eAAe,YAAa,MAAM;AACvC,QAAK,eAAgB;AACpB,0BAAqB,EAAE,KAAK,OAAU,CAAE;AAAA,IACzC;AAAA,EACD,GAAG,CAAE,qBAAqB,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { useBlockBindingsUtils } from '@wordpress/block-editor';\n\n/**\n * Builds entity binding configuration for navigation link URLs.\n * This function generates the structure used to bind navigation link URLs to their entity sources.\n *\n * Using a function instead of a constant allows for future enhancements where the binding\n * might need dynamic data (e.g., entity ID, context-specific arguments).\n *\n * @param {('post-type'|'taxonomy')} kind - The kind of entity. Only 'post-type' and 'taxonomy' are supported.\n * @return {Object} Entity binding configuration object\n * @throws {Error} If kind is not 'post-type' or 'taxonomy'\n */\nexport function buildNavigationLinkEntityBinding( kind ) {\n\t// Validate kind parameter exists\n\tif ( kind === undefined ) {\n\t\tthrow new Error(\n\t\t\t'buildNavigationLinkEntityBinding requires a kind parameter. ' +\n\t\t\t\t'Only \"post-type\" and \"taxonomy\" are supported.'\n\t\t);\n\t}\n\n\t// Validate kind parameter value\n\tif ( kind !== 'post-type' && kind !== 'taxonomy' ) {\n\t\tthrow new Error(\n\t\t\t`Invalid kind \"${ kind }\" provided to buildNavigationLinkEntityBinding. ` +\n\t\t\t\t`Only 'post-type' and 'taxonomy' are supported.`\n\t\t);\n\t}\n\n\tconst source = kind === 'taxonomy' ? 'core/term-data' : 'core/post-data';\n\n\treturn {\n\t\turl: {\n\t\t\tsource,\n\t\t\targs: {\n\t\t\t\tfield: 'link',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Shared hook for entity binding functionality in Navigation blocks.\n *\n * This hook provides common entity binding logic that can be used by both\n * Navigation Link and Navigation Submenu blocks to maintain feature parity.\n *\n * @param {Object} props - Hook parameters\n * @param {string} props.clientId - Block client ID\n * @param {Object} props.attributes - Block attributes\n * @return {Object} Hook return value\n */\nexport function useEntityBinding( { clientId, attributes } ) {\n\tconst { updateBlockBindings } = useBlockBindingsUtils( clientId );\n\tconst { metadata, id, kind } = attributes;\n\n\tconst hasUrlBinding = !! metadata?.bindings?.url && !! id;\n\tconst expectedSource =\n\t\tkind === 'post-type' ? 'core/post-data' : 'core/term-data';\n\tconst hasCorrectBinding =\n\t\thasUrlBinding && metadata?.bindings?.url?.source === expectedSource;\n\n\tconst clearBinding = useCallback( () => {\n\t\tif ( hasUrlBinding ) {\n\t\t\tupdateBlockBindings( { url: undefined } );\n\t\t}\n\t}, [ updateBlockBindings, hasUrlBinding, metadata, id ] );\n\n\tconst createBinding = useCallback(\n\t\t( updatedAttributes ) => {\n\t\t\t// Use updated attributes if provided, otherwise fall back to closure attributes\n\t\t\t// updatedAttributes needed to access the most up-to-date data when called synchronously\n\t\t\tconst kindToUse = updatedAttributes?.kind ?? kind;\n\n\t\t\t// Avoid creating binding if no kind is provided\n\t\t\tif ( ! kindToUse ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst binding = buildNavigationLinkEntityBinding( kindToUse );\n\t\t\t\tupdateBlockBindings( binding );\n\t\t\t} catch ( error ) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'Failed to create entity binding:',\n\t\t\t\t\terror.message\n\t\t\t\t);\n\t\t\t\t// Don't create binding if validation fails\n\t\t\t}\n\t\t},\n\t\t[ updateBlockBindings, kind, id ]\n\t);\n\n\treturn {\n\t\thasUrlBinding: hasCorrectBinding,\n\t\tclearBinding,\n\t\tcreateBinding,\n\t};\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AAa/B,SAAS,iCAAkC,MAAO;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,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/navigation-submenu/edit.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockControls,\n\tInnerBlocks,\n\tuseInnerBlocksProps,\n\tInspectorControls,\n\tRichText,\n\tuseBlockProps,\n\tuseBlockEditingMode,\n\tstore as blockEditorStore,\n\tgetColorClassName,\n} from '@wordpress/block-editor';\nimport { isURL, prependHTTP } from '@wordpress/url';\nimport { useState, useEffect, useRef } from '@wordpress/element';\nimport { link as linkIcon, removeSubmenu } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\nimport { createBlock } from '@wordpress/blocks';\nimport { useMergeRefs, usePrevious } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { ItemSubmenuIcon } from './icons';\nimport {\n\tControls,\n\tLinkUI,\n\tupdateAttributes,\n\tuseEntityBinding,\n} from '../navigation-link/shared';\nimport {\n\tgetColors,\n\tgetNavigationChildBlockProps,\n} from '../navigation/edit/utils';\nimport { DEFAULT_BLOCK } from '../navigation/constants';\n\nconst ALLOWED_BLOCKS = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n\t'core/page-list',\n];\n\n/**\n * A React hook to determine if it's dragging within the target element.\n *\n * @typedef {import('@wordpress/element').RefObject} RefObject\n *\n * @param {RefObject<HTMLElement>} elementRef The target elementRef object.\n *\n * @return {boolean} Is dragging within the target element.\n */\nconst useIsDraggingWithin = ( elementRef ) => {\n\tconst [ isDraggingWithin, setIsDraggingWithin ] = useState( false );\n\n\tuseEffect( () => {\n\t\tconst { ownerDocument } = elementRef.current;\n\n\t\tfunction handleDragStart( event ) {\n\t\t\t// Check the first time when the dragging starts.\n\t\t\thandleDragEnter( event );\n\t\t}\n\n\t\t// Set to false whenever the user cancel the drag event by either releasing the mouse or press Escape.\n\t\tfunction handleDragEnd() {\n\t\t\tsetIsDraggingWithin( false );\n\t\t}\n\n\t\tfunction handleDragEnter( event ) {\n\t\t\t// Check if the current target is inside the item element.\n\t\t\tif ( elementRef.current.contains( event.target ) ) {\n\t\t\t\tsetIsDraggingWithin( true );\n\t\t\t} else {\n\t\t\t\tsetIsDraggingWithin( false );\n\t\t\t}\n\t\t}\n\n\t\t// Bind these events to the document to catch all drag events.\n\t\t// Ideally, we can also use `event.relatedTarget`, but sadly that\n\t\t// doesn't work in Safari.\n\t\townerDocument.addEventListener( 'dragstart', handleDragStart );\n\t\townerDocument.addEventListener( 'dragend', handleDragEnd );\n\t\townerDocument.addEventListener( 'dragenter', handleDragEnter );\n\n\t\treturn () => {\n\t\t\townerDocument.removeEventListener( 'dragstart', handleDragStart );\n\t\t\townerDocument.removeEventListener( 'dragend', handleDragEnd );\n\t\t\townerDocument.removeEventListener( 'dragenter', handleDragEnter );\n\t\t};\n\t}, [] );\n\n\treturn isDraggingWithin;\n};\n\n/**\n * @typedef {'post-type'|'custom'|'taxonomy'|'post-type-archive'} WPNavigationLinkKind\n */\n\n/**\n * Navigation Link Block Attributes\n *\n * @typedef {Object} WPNavigationLinkBlockAttributes\n *\n * @property {string} [label] Link text.\n * @property {WPNavigationLinkKind} [kind] Kind is used to differentiate between term and post ids to check post draft status.\n * @property {string} [type] The type such as post, page, tag, category and other custom types.\n * @property {string} [rel] The relationship of the linked URL.\n * @property {number} [id] A post or term id.\n * @property {boolean} [opensInNewTab] Sets link target to _blank when true.\n * @property {string} [url] Link href.\n */\n\nexport default function NavigationSubmenuEdit( {\n\tattributes,\n\tisSelected,\n\tsetAttributes,\n\tmergeBlocks,\n\tonReplace,\n\tcontext,\n\tclientId,\n} ) {\n\tconst { label, url, description } = attributes;\n\n\tconst {\n\t\tshowSubmenuIcon,\n\t\tmaxNestingLevel,\n\t\topenSubmenusOnClick: contextOpenSubmenusOnClick,\n\t} = context;\n\tconst blockEditingMode = useBlockEditingMode();\n\n\t// Force click-only behavior in contentOnly mode to prevent hover dropdowns\n\tconst openSubmenusOnClick =\n\t\tblockEditingMode !== 'default' ? true : contextOpenSubmenusOnClick;\n\n\t// URL binding logic\n\tconst { clearBinding, createBinding } = useEntityBinding( {\n\t\tclientId,\n\t\tattributes,\n\t} );\n\n\tconst { __unstableMarkNextChangeAsNotPersistent, replaceBlock } =\n\t\tuseDispatch( blockEditorStore );\n\tconst [ isLinkOpen, setIsLinkOpen ] = useState( false );\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 text\u2026' );\n\tconst ref = useRef();\n\n\tconst {\n\t\tparentCount,\n\t\tisParentOfSelectedBlock,\n\t\tisImmediateParentOfSelectedBlock,\n\t\thasChildren,\n\t\tselectedBlockHasChildren,\n\t\tonlyDescendantIsEmptyLink,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\thasSelectedInnerBlock,\n\t\t\t\tgetSelectedBlockClientId,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t\tgetBlock,\n\t\t\t\tgetBlockCount,\n\t\t\t\tgetBlockOrder,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tlet _onlyDescendantIsEmptyLink;\n\n\t\t\tconst selectedBlockId = getSelectedBlockClientId();\n\n\t\t\tconst selectedBlockChildren = getBlockOrder( selectedBlockId );\n\n\t\t\t// Check for a single descendant in the submenu. If that block\n\t\t\t// is a link block in a \"placeholder\" state with no label then\n\t\t\t// we can consider as an \"empty\" link.\n\t\t\tif ( selectedBlockChildren?.length === 1 ) {\n\t\t\t\tconst singleBlock = getBlock( selectedBlockChildren[ 0 ] );\n\n\t\t\t\t_onlyDescendantIsEmptyLink =\n\t\t\t\t\tsingleBlock?.name === 'core/navigation-link' &&\n\t\t\t\t\t! singleBlock?.attributes?.label;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tparentCount: getBlockParentsByBlockName(\n\t\t\t\t\tclientId,\n\t\t\t\t\t'core/navigation-submenu'\n\t\t\t\t).length,\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\tisImmediateParentOfSelectedBlock: hasSelectedInnerBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\tfalse\n\t\t\t\t),\n\t\t\t\thasChildren: !! getBlockCount( clientId ),\n\t\t\t\tselectedBlockHasChildren: !! selectedBlockChildren?.length,\n\t\t\t\tonlyDescendantIsEmptyLink: _onlyDescendantIsEmptyLink,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst prevHasChildren = usePrevious( hasChildren );\n\n\t// Show the LinkControl on mount if the URL is empty\n\t// ( When adding a new menu item)\n\t// This can't be done in the useState call because it conflicts\n\t// with the autofocus behavior of the BlockListBlock component.\n\tuseEffect( () => {\n\t\tif ( ! openSubmenusOnClick && ! url ) {\n\t\t\tsetIsLinkOpen( true );\n\t\t}\n\t}, [] );\n\n\t/**\n\t * The hook shouldn't be necessary but due to a focus loss happening\n\t * when selecting a suggestion in the link popover, we force close on block unselection.\n\t */\n\tuseEffect( () => {\n\t\tif ( ! isSelected ) {\n\t\t\tsetIsLinkOpen( false );\n\t\t}\n\t}, [ isSelected ] );\n\n\t// If the LinkControl popover is open and the URL has changed, close the LinkControl and focus the label text.\n\tuseEffect( () => {\n\t\tif ( isLinkOpen && url ) {\n\t\t\t// Does this look like a URL and have something TLD-ish?\n\t\t\tif (\n\t\t\t\tisURL( prependHTTP( label ) ) &&\n\t\t\t\t/^.+\\.[a-z]+/.test( label )\n\t\t\t) {\n\t\t\t\t// Focus and select the label text.\n\t\t\t\tselectLabelText();\n\t\t\t}\n\t\t}\n\t}, [ url ] );\n\n\t/**\n\t * Focus the Link label text and select it.\n\t */\n\tfunction selectLabelText() {\n\t\tref.current.focus();\n\t\tconst { ownerDocument } = ref.current;\n\t\tconst { defaultView } = ownerDocument;\n\t\tconst selection = defaultView.getSelection();\n\t\tconst range = ownerDocument.createRange();\n\t\t// Get the range of the current ref contents so we can add this range to the selection.\n\t\trange.selectNodeContents( ref.current );\n\t\tselection.removeAllRanges();\n\t\tselection.addRange( range );\n\t}\n\n\tconst {\n\t\ttextColor,\n\t\tcustomTextColor,\n\t\tbackgroundColor,\n\t\tcustomBackgroundColor,\n\t} = getColors( context, parentCount > 0 );\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 we don't stop propagation, this event bubbles up to the parent submenu item\n\t\t\tevent.stopPropagation();\n\t\t\tsetIsLinkOpen( true );\n\t\t}\n\t}\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\t'open-on-click': openSubmenusOnClick,\n\t\t} ),\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\t// Always use overlay colors for submenus.\n\tconst innerBlocksColors = getColors( context, true );\n\n\tconst allowedBlocks =\n\t\tparentCount >= maxNestingLevel\n\t\t\t? ALLOWED_BLOCKS.filter(\n\t\t\t\t\t( blockName ) => blockName !== 'core/navigation-submenu'\n\t\t\t )\n\t\t\t: ALLOWED_BLOCKS;\n\n\tconst navigationChildBlockProps =\n\t\tgetNavigationChildBlockProps( innerBlocksColors );\n\tconst innerBlocksProps = useInnerBlocksProps( navigationChildBlockProps, {\n\t\tallowedBlocks,\n\t\tdefaultBlock: DEFAULT_BLOCK,\n\t\tdirectInsert: true,\n\n\t\t// Ensure block toolbar is not too far removed from item\n\t\t// being edited.\n\t\t// see: https://github.com/WordPress/gutenberg/pull/34615.\n\t\t__experimentalCaptureToolbars: true,\n\n\t\trenderAppender:\n\t\t\tisSelected ||\n\t\t\t( isImmediateParentOfSelectedBlock &&\n\t\t\t\t! selectedBlockHasChildren ) ||\n\t\t\t// Show the appender while dragging to allow inserting element between item and the appender.\n\t\t\thasChildren\n\t\t\t\t? InnerBlocks.ButtonBlockAppender\n\t\t\t\t: false,\n\t} );\n\n\tconst ParentElement = openSubmenusOnClick ? 'button' : 'a';\n\n\tfunction transformToLink() {\n\t\tconst newLinkBlock = createBlock( 'core/navigation-link', attributes );\n\t\treplaceBlock( clientId, newLinkBlock );\n\t}\n\n\tuseEffect( () => {\n\t\t// If block becomes empty, transform to Navigation Link.\n\t\tif ( ! hasChildren && prevHasChildren ) {\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\ttransformToLink();\n\t\t}\n\t}, [ hasChildren, prevHasChildren ] );\n\n\tconst canConvertToLink =\n\t\t! selectedBlockHasChildren || onlyDescendantIsEmptyLink;\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t{ ! openSubmenusOnClick && (\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\t\tshortcut={ displayShortcut.primary( 'k' ) }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetIsLinkOpen( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"revert\"\n\t\t\t\t\t\ticon={ removeSubmenu }\n\t\t\t\t\t\ttitle={ __( 'Convert to Link' ) }\n\t\t\t\t\t\tonClick={ transformToLink }\n\t\t\t\t\t\tclassName=\"wp-block-navigation__submenu__revert\"\n\t\t\t\t\t\tdisabled={ ! canConvertToLink }\n\t\t\t\t\t/>\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\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{ /* eslint-disable jsx-a11y/anchor-is-valid */ }\n\t\t\t\t<ParentElement className=\"wp-block-navigation-item__content\">\n\t\t\t\t\t{ /* eslint-enable */ }\n\t\t\t\t\t<RichText\n\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\tidentifier=\"label\"\n\t\t\t\t\t\tclassName=\"wp-block-navigation-item__label\"\n\t\t\t\t\t\tvalue={ label }\n\t\t\t\t\t\tonChange={ ( labelValue ) =>\n\t\t\t\t\t\t\tsetAttributes( { label: labelValue } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\t\taria-label={ __( 'Navigation link text' ) }\n\t\t\t\t\t\tplaceholder={ itemLabelPlaceholder }\n\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tif ( ! openSubmenusOnClick && ! url ) {\n\t\t\t\t\t\t\t\tsetIsLinkOpen( true );\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{ description && (\n\t\t\t\t\t\t<span className=\"wp-block-navigation-item__description\">\n\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ! openSubmenusOnClick && isLinkOpen && (\n\t\t\t\t\t\t<LinkUI\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\tonClose={ () => {\n\t\t\t\t\t\t\t\tsetIsLinkOpen( false );\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={ () => {\n\t\t\t\t\t\t\t\tsetAttributes( { url: '' } );\n\t\t\t\t\t\t\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonChange={ ( updatedValue ) => {\n\t\t\t\t\t\t\t\t// updateAttributes determines the final state and returns metadata\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\tisEntityLink,\n\t\t\t\t\t\t\t\t\tattributes: updatedAttributes,\n\t\t\t\t\t\t\t\t} = updateAttributes(\n\t\t\t\t\t\t\t\t\tupdatedValue,\n\t\t\t\t\t\t\t\t\tsetAttributes,\n\t\t\t\t\t\t\t\t\tattributes\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t// Handle URL binding based on the final computed state\n\t\t\t\t\t\t\t\t// Only create bindings for entity links (posts, pages, taxonomies)\n\t\t\t\t\t\t\t\t// Never create bindings for custom links (manual URLs)\n\t\t\t\t\t\t\t\tif ( isEntityLink ) {\n\t\t\t\t\t\t\t\t\tcreateBinding( updatedAttributes );\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tclearBinding();\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</ParentElement>\n\t\t\t\t{ ( showSubmenuIcon || openSubmenusOnClick ) && (\n\t\t\t\t\t<span className=\"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\t<div { ...innerBlocksProps } />\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"],
|
|
5
|
-
"mappings": "AAwWE,mBAII,KAFF,YAFF;AArWF,OAAO,UAAU;AAKjB,SAAS,WAAW,mBAAmB;AACvC,SAAS,eAAe,oBAAoB;AAC5C,SAAS,iBAAiB,uBAAuB;AACjD,SAAS,UAAU;AACnB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,OACM;AACP,SAAS,OAAO,mBAAmB;AACnC,SAAS,UAAU,WAAW,cAAc;AAC5C,SAAS,QAAQ,UAAU,qBAAqB;AAChD,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAC5B,SAAS,cAAc,mBAAmB;AAK1C,SAAS,uBAAuB;AAChC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,qBAAqB;AAE9B,MAAM,iBAAiB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AACD;AAWA,MAAM,sBAAsB,CAAE,eAAgB;AAC7C,QAAM,CAAE,kBAAkB,mBAAoB,IAAI,SAAU,KAAM;AAElE,YAAW,MAAM;AAChB,UAAM,EAAE,cAAc,IAAI,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UAAW,CAAE,eACZ,cAAe,EAAE,OAAO,WAAW,CAAE;AAAA,YAEtC,SAAU;AAAA,YACV;AAAA,YACA,cAAa,GAAI,sBAAuB;AAAA,YACxC,aAAc;AAAA,YACd,8BAA4B;AAAA,YAC5B,SAAU,MAAM;AACf,kBAAK,CAAE,uBAAuB,CAAE,KAAM;AACrC,8BAAe,IAAK;AAAA,cACrB;AAAA,YACD;AAAA;AAAA,QACD;AAAA,QACE,eACD,oBAAC,UAAK,WAAU,yCACb,uBACH;AAAA,QAEC,CAAE,uBAAuB,cAC1B;AAAA,UAAC;AAAA;AAAA,YACA;AAAA,YACA,MAAO;AAAA,YACP,SAAU,MAAM;AACf,4BAAe,KAAM;AAAA,YACtB;AAAA,YACA,QAAS;AAAA,YACT,UAAW,MAAM;AAChB,4BAAe,EAAE,KAAK,GAAG,CAAE;AAC3B,oBAAO,GAAI,eAAgB,GAAG,WAAY;AAAA,YAC3C;AAAA,YACA,UAAW,CAAE,iBAAkB;AAE9B,oBAAM;AAAA,gBACL;AAAA,gBACA,YAAY;AAAA,cACb,IAAI;AAAA,gBACH;AAAA,gBACA;AAAA,gBACA;AAAA,cACD;AAKA,kBAAK,cAAe;AACnB,8BAAe,iBAAkB;AAAA,cAClC,OAAO;AACN,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tBlockControls,\n\tInnerBlocks,\n\tuseInnerBlocksProps,\n\tInspectorControls,\n\tRichText,\n\tuseBlockProps,\n\tuseBlockEditingMode,\n\tstore as blockEditorStore,\n\tgetColorClassName,\n} from '@wordpress/block-editor';\nimport { isURL, prependHTTP } from '@wordpress/url';\nimport { useState, useEffect, useRef } from '@wordpress/element';\nimport { link as linkIcon, removeSubmenu } from '@wordpress/icons';\nimport { speak } from '@wordpress/a11y';\nimport { createBlock } from '@wordpress/blocks';\nimport { useMergeRefs, usePrevious } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { ItemSubmenuIcon } from './icons';\nimport {\n\tControls,\n\tLinkUI,\n\tupdateAttributes,\n\tuseEntityBinding,\n} from '../navigation-link/shared';\nimport {\n\tgetColors,\n\tgetNavigationChildBlockProps,\n} from '../navigation/edit/utils';\nimport { DEFAULT_BLOCK } from '../navigation/constants';\n\nconst ALLOWED_BLOCKS = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n\t'core/page-list',\n];\n\n/**\n * A React hook to determine if it's dragging within the target element.\n *\n * @typedef {import('@wordpress/element').RefObject} RefObject\n *\n * @param {RefObject<HTMLElement>} elementRef The target elementRef object.\n *\n * @return {boolean} Is dragging within the target element.\n */\nconst useIsDraggingWithin = ( elementRef ) => {\n\tconst [ isDraggingWithin, setIsDraggingWithin ] = useState( false );\n\n\tuseEffect( () => {\n\t\tconst { ownerDocument } = elementRef.current;\n\n\t\tfunction handleDragStart( event ) {\n\t\t\t// Check the first time when the dragging starts.\n\t\t\thandleDragEnter( event );\n\t\t}\n\n\t\t// Set to false whenever the user cancel the drag event by either releasing the mouse or press Escape.\n\t\tfunction handleDragEnd() {\n\t\t\tsetIsDraggingWithin( false );\n\t\t}\n\n\t\tfunction handleDragEnter( event ) {\n\t\t\t// Check if the current target is inside the item element.\n\t\t\tif ( elementRef.current.contains( event.target ) ) {\n\t\t\t\tsetIsDraggingWithin( true );\n\t\t\t} else {\n\t\t\t\tsetIsDraggingWithin( false );\n\t\t\t}\n\t\t}\n\n\t\t// Bind these events to the document to catch all drag events.\n\t\t// Ideally, we can also use `event.relatedTarget`, but sadly that\n\t\t// doesn't work in Safari.\n\t\townerDocument.addEventListener( 'dragstart', handleDragStart );\n\t\townerDocument.addEventListener( 'dragend', handleDragEnd );\n\t\townerDocument.addEventListener( 'dragenter', handleDragEnter );\n\n\t\treturn () => {\n\t\t\townerDocument.removeEventListener( 'dragstart', handleDragStart );\n\t\t\townerDocument.removeEventListener( 'dragend', handleDragEnd );\n\t\t\townerDocument.removeEventListener( 'dragenter', handleDragEnter );\n\t\t};\n\t}, [] );\n\n\treturn isDraggingWithin;\n};\n\n/**\n * @typedef {'post-type'|'custom'|'taxonomy'|'post-type-archive'} WPNavigationLinkKind\n */\n\n/**\n * Navigation Link Block Attributes\n *\n * @typedef {Object} WPNavigationLinkBlockAttributes\n *\n * @property {string} [label] Link text.\n * @property {WPNavigationLinkKind} [kind] Kind is used to differentiate between term and post ids to check post draft status.\n * @property {string} [type] The type such as post, page, tag, category and other custom types.\n * @property {string} [rel] The relationship of the linked URL.\n * @property {number} [id] A post or term id.\n * @property {boolean} [opensInNewTab] Sets link target to _blank when true.\n * @property {string} [url] Link href.\n */\n\nexport default function NavigationSubmenuEdit( {\n\tattributes,\n\tisSelected,\n\tsetAttributes,\n\tmergeBlocks,\n\tonReplace,\n\tcontext,\n\tclientId,\n} ) {\n\tconst { label, url, description } = attributes;\n\n\tconst {\n\t\tshowSubmenuIcon,\n\t\tmaxNestingLevel,\n\t\topenSubmenusOnClick: contextOpenSubmenusOnClick,\n\t} = context;\n\tconst blockEditingMode = useBlockEditingMode();\n\n\t// Force click-only behavior in contentOnly mode to prevent hover dropdowns\n\tconst openSubmenusOnClick =\n\t\tblockEditingMode !== 'default' ? true : contextOpenSubmenusOnClick;\n\n\t// URL binding logic\n\tconst { clearBinding, createBinding } = useEntityBinding( {\n\t\tclientId,\n\t\tattributes,\n\t} );\n\n\tconst { __unstableMarkNextChangeAsNotPersistent, replaceBlock } =\n\t\tuseDispatch( blockEditorStore );\n\tconst [ isLinkOpen, setIsLinkOpen ] = useState( false );\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 text\u2026' );\n\tconst ref = useRef();\n\n\tconst {\n\t\tparentCount,\n\t\tisParentOfSelectedBlock,\n\t\tisImmediateParentOfSelectedBlock,\n\t\thasChildren,\n\t\tselectedBlockHasChildren,\n\t\tonlyDescendantIsEmptyLink,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\thasSelectedInnerBlock,\n\t\t\t\tgetSelectedBlockClientId,\n\t\t\t\tgetBlockParentsByBlockName,\n\t\t\t\tgetBlock,\n\t\t\t\tgetBlockCount,\n\t\t\t\tgetBlockOrder,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tlet _onlyDescendantIsEmptyLink;\n\n\t\t\tconst selectedBlockId = getSelectedBlockClientId();\n\n\t\t\tconst selectedBlockChildren = getBlockOrder( selectedBlockId );\n\n\t\t\t// Check for a single descendant in the submenu. If that block\n\t\t\t// is a link block in a \"placeholder\" state with no label then\n\t\t\t// we can consider as an \"empty\" link.\n\t\t\tif ( selectedBlockChildren?.length === 1 ) {\n\t\t\t\tconst singleBlock = getBlock( selectedBlockChildren[ 0 ] );\n\n\t\t\t\t_onlyDescendantIsEmptyLink =\n\t\t\t\t\tsingleBlock?.name === 'core/navigation-link' &&\n\t\t\t\t\t! singleBlock?.attributes?.label;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tparentCount: getBlockParentsByBlockName(\n\t\t\t\t\tclientId,\n\t\t\t\t\t'core/navigation-submenu'\n\t\t\t\t).length,\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\tisImmediateParentOfSelectedBlock: hasSelectedInnerBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\tfalse\n\t\t\t\t),\n\t\t\t\thasChildren: !! getBlockCount( clientId ),\n\t\t\t\tselectedBlockHasChildren: !! selectedBlockChildren?.length,\n\t\t\t\tonlyDescendantIsEmptyLink: _onlyDescendantIsEmptyLink,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst prevHasChildren = usePrevious( hasChildren );\n\n\t// Show the LinkControl on mount if the URL is empty\n\t// ( When adding a new menu item)\n\t// This can't be done in the useState call because it conflicts\n\t// with the autofocus behavior of the BlockListBlock component.\n\tuseEffect( () => {\n\t\tif ( ! openSubmenusOnClick && ! url ) {\n\t\t\tsetIsLinkOpen( true );\n\t\t}\n\t}, [] );\n\n\t/**\n\t * The hook shouldn't be necessary but due to a focus loss happening\n\t * when selecting a suggestion in the link popover, we force close on block unselection.\n\t */\n\tuseEffect( () => {\n\t\tif ( ! isSelected ) {\n\t\t\tsetIsLinkOpen( false );\n\t\t}\n\t}, [ isSelected ] );\n\n\t// If the LinkControl popover is open and the URL has changed, close the LinkControl and focus the label text.\n\tuseEffect( () => {\n\t\tif ( isLinkOpen && url ) {\n\t\t\t// Does this look like a URL and have something TLD-ish?\n\t\t\tif (\n\t\t\t\tisURL( prependHTTP( label ) ) &&\n\t\t\t\t/^.+\\.[a-z]+/.test( label )\n\t\t\t) {\n\t\t\t\t// Focus and select the label text.\n\t\t\t\tselectLabelText();\n\t\t\t}\n\t\t}\n\t}, [ url ] );\n\n\t/**\n\t * Focus the Link label text and select it.\n\t */\n\tfunction selectLabelText() {\n\t\tref.current.focus();\n\t\tconst { ownerDocument } = ref.current;\n\t\tconst { defaultView } = ownerDocument;\n\t\tconst selection = defaultView.getSelection();\n\t\tconst range = ownerDocument.createRange();\n\t\t// Get the range of the current ref contents so we can add this range to the selection.\n\t\trange.selectNodeContents( ref.current );\n\t\tselection.removeAllRanges();\n\t\tselection.addRange( range );\n\t}\n\n\tconst {\n\t\ttextColor,\n\t\tcustomTextColor,\n\t\tbackgroundColor,\n\t\tcustomBackgroundColor,\n\t} = getColors( context, parentCount > 0 );\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 we don't stop propagation, this event bubbles up to the parent submenu item\n\t\t\tevent.stopPropagation();\n\t\t\tsetIsLinkOpen( true );\n\t\t}\n\t}\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\t'open-on-click': openSubmenusOnClick,\n\t\t} ),\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\t// Always use overlay colors for submenus.\n\tconst innerBlocksColors = getColors( context, true );\n\n\tconst allowedBlocks =\n\t\tparentCount >= maxNestingLevel\n\t\t\t? ALLOWED_BLOCKS.filter(\n\t\t\t\t\t( blockName ) => blockName !== 'core/navigation-submenu'\n\t\t\t )\n\t\t\t: ALLOWED_BLOCKS;\n\n\tconst navigationChildBlockProps =\n\t\tgetNavigationChildBlockProps( innerBlocksColors );\n\tconst innerBlocksProps = useInnerBlocksProps( navigationChildBlockProps, {\n\t\tallowedBlocks,\n\t\tdefaultBlock: DEFAULT_BLOCK,\n\t\tdirectInsert: true,\n\n\t\t// Ensure block toolbar is not too far removed from item\n\t\t// being edited.\n\t\t// see: https://github.com/WordPress/gutenberg/pull/34615.\n\t\t__experimentalCaptureToolbars: true,\n\n\t\trenderAppender:\n\t\t\tisSelected ||\n\t\t\t( isImmediateParentOfSelectedBlock &&\n\t\t\t\t! selectedBlockHasChildren ) ||\n\t\t\t// Show the appender while dragging to allow inserting element between item and the appender.\n\t\t\thasChildren\n\t\t\t\t? InnerBlocks.ButtonBlockAppender\n\t\t\t\t: false,\n\t} );\n\n\tconst ParentElement = openSubmenusOnClick ? 'button' : 'a';\n\n\tfunction transformToLink() {\n\t\tconst newLinkBlock = createBlock( 'core/navigation-link', attributes );\n\t\treplaceBlock( clientId, newLinkBlock );\n\t}\n\n\tuseEffect( () => {\n\t\t// If block becomes empty, transform to Navigation Link.\n\t\tif ( ! hasChildren && prevHasChildren ) {\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\ttransformToLink();\n\t\t}\n\t}, [ hasChildren, prevHasChildren ] );\n\n\tconst canConvertToLink =\n\t\t! selectedBlockHasChildren || onlyDescendantIsEmptyLink;\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t{ ! openSubmenusOnClick && (\n\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\tname=\"link\"\n\t\t\t\t\t\t\ticon={ linkIcon }\n\t\t\t\t\t\t\ttitle={ __( 'Link' ) }\n\t\t\t\t\t\t\tshortcut={ displayShortcut.primary( 'k' ) }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetIsLinkOpen( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\n\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\tname=\"revert\"\n\t\t\t\t\t\ticon={ removeSubmenu }\n\t\t\t\t\t\ttitle={ __( 'Convert to Link' ) }\n\t\t\t\t\t\tonClick={ transformToLink }\n\t\t\t\t\t\tclassName=\"wp-block-navigation__submenu__revert\"\n\t\t\t\t\t\tdisabled={ ! canConvertToLink }\n\t\t\t\t\t/>\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\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{ /* eslint-disable jsx-a11y/anchor-is-valid */ }\n\t\t\t\t<ParentElement className=\"wp-block-navigation-item__content\">\n\t\t\t\t\t{ /* eslint-enable */ }\n\t\t\t\t\t<RichText\n\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\tidentifier=\"label\"\n\t\t\t\t\t\tclassName=\"wp-block-navigation-item__label\"\n\t\t\t\t\t\tvalue={ label }\n\t\t\t\t\t\tonChange={ ( labelValue ) =>\n\t\t\t\t\t\t\tsetAttributes( { label: labelValue } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\t\taria-label={ __( 'Navigation link text' ) }\n\t\t\t\t\t\tplaceholder={ itemLabelPlaceholder }\n\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tif ( ! openSubmenusOnClick && ! url ) {\n\t\t\t\t\t\t\t\tsetIsLinkOpen( true );\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{ description && (\n\t\t\t\t\t\t<span className=\"wp-block-navigation-item__description\">\n\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ! openSubmenusOnClick && isLinkOpen && (\n\t\t\t\t\t\t<LinkUI\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\tonClose={ () => {\n\t\t\t\t\t\t\t\tsetIsLinkOpen( false );\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={ () => {\n\t\t\t\t\t\t\t\tsetAttributes( { url: '' } );\n\t\t\t\t\t\t\t\tspeak( __( 'Link removed.' ), 'assertive' );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonChange={ ( updatedValue ) => {\n\t\t\t\t\t\t\t\t// updateAttributes determines the final state and returns metadata\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\tisEntityLink,\n\t\t\t\t\t\t\t\t\tattributes: updatedAttributes,\n\t\t\t\t\t\t\t\t} = updateAttributes(\n\t\t\t\t\t\t\t\t\tupdatedValue,\n\t\t\t\t\t\t\t\t\tsetAttributes,\n\t\t\t\t\t\t\t\t\tattributes\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t// Handle URL binding based on the final computed state\n\t\t\t\t\t\t\t\t// Only create bindings for entity links (posts, pages, taxonomies)\n\t\t\t\t\t\t\t\t// Never create bindings for custom links (manual URLs)\n\t\t\t\t\t\t\t\tif ( isEntityLink ) {\n\t\t\t\t\t\t\t\t\tcreateBinding( updatedAttributes );\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tclearBinding( updatedAttributes );\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</ParentElement>\n\t\t\t\t{ ( showSubmenuIcon || openSubmenusOnClick ) && (\n\t\t\t\t\t<span className=\"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\t<div { ...innerBlocksProps } />\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAwWE,mBAII,KAFF,YAFF;AArWF,OAAO,UAAU;AAKjB,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AAC3B,oBAAO,GAAI,eAAgB,GAAG,WAAY;AAAA,YAC3C;AAAA,YACA,UAAW,CAAE,iBAAkB;AAE9B,oBAAM;AAAA,gBACL;AAAA,gBACA,YAAY;AAAA,cACb,IAAI;AAAA,gBACH;AAAA,gBACA;AAAA,gBACA;AAAA,cACD;AAKA,kBAAK,cAAe;AACnB,8BAAe,iBAAkB;AAAA,cAClC,OAAO;AACN,6BAAc,iBAAkB;AAAA,cACjC;AAAA,YACD;AAAA;AAAA,QACD;AAAA,SAEF;AAAA,OACI,mBAAmB,wBACtB,oBAAC,UAAK,WAAU,qCACf,8BAAC,mBAAgB,GAClB;AAAA,MAED,oBAAC,SAAM,GAAG,kBAAmB;AAAA,OAC9B;AAAA,KACD;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -29,13 +29,15 @@ import { __, _x, sprintf } from "@wordpress/i18n";
|
|
|
29
29
|
import { pencil } from "@wordpress/icons";
|
|
30
30
|
import { DOWN } from "@wordpress/keycodes";
|
|
31
31
|
import { useSelect, useDispatch } from "@wordpress/data";
|
|
32
|
+
import { store as blocksStore } from "@wordpress/blocks";
|
|
32
33
|
import { useToolsPanelDropdownMenuProps } from "../utils/hooks";
|
|
33
34
|
function PostDateEdit({
|
|
34
|
-
attributes
|
|
35
|
+
attributes,
|
|
35
36
|
context: { postType: postTypeSlug, queryId },
|
|
36
|
-
setAttributes
|
|
37
|
+
setAttributes,
|
|
38
|
+
name
|
|
37
39
|
}) {
|
|
38
|
-
const
|
|
40
|
+
const { datetime, textAlign, format, isLink } = attributes;
|
|
39
41
|
const blockProps = useBlockProps({
|
|
40
42
|
className: clsx({
|
|
41
43
|
[`has-text-align-${textAlign}`]: textAlign
|
|
@@ -72,6 +74,10 @@ function PostDateEdit({
|
|
|
72
74
|
},
|
|
73
75
|
[postTypeSlug]
|
|
74
76
|
);
|
|
77
|
+
const activeBlockVariationName = useSelect(
|
|
78
|
+
(select) => select(blocksStore).getActiveBlockVariation(name, attributes)?.name,
|
|
79
|
+
[name, attributes]
|
|
80
|
+
);
|
|
75
81
|
const blockEditingMode = useBlockEditingMode();
|
|
76
82
|
let postDate = /* @__PURE__ */ jsx("time", { dateTime: dateI18n("c", datetime), ref: setPopoverAnchor, children: format === "human-diff" ? humanTimeDiff(datetime) : dateI18n(format || siteFormat, datetime) });
|
|
77
83
|
if (isLink && datetime) {
|
|
@@ -95,14 +101,14 @@ function PostDateEdit({
|
|
|
95
101
|
}
|
|
96
102
|
}
|
|
97
103
|
),
|
|
98
|
-
|
|
104
|
+
activeBlockVariationName !== "post-date-modified" && (!isDescendentOfQueryLoop || !activeBlockVariationName) && /* @__PURE__ */ jsx(ToolbarGroup, { children: /* @__PURE__ */ jsx(
|
|
99
105
|
Dropdown,
|
|
100
106
|
{
|
|
101
107
|
popoverProps,
|
|
102
108
|
renderContent: ({ onClose }) => /* @__PURE__ */ jsx(
|
|
103
109
|
PublishDateTimePicker,
|
|
104
110
|
{
|
|
105
|
-
title:
|
|
111
|
+
title: activeBlockVariationName === "post-date" ? __("Publish Date") : __("Date"),
|
|
106
112
|
currentDate: datetime,
|
|
107
113
|
onChange: (newDatetime) => setAttributes({
|
|
108
114
|
datetime: newDatetime
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/post-date/edit.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useEffect, useMemo, useState } from '@wordpress/element';\nimport {\n\tdateI18n,\n\thumanTimeDiff,\n\tgetSettings as getDateSettings,\n} from '@wordpress/date';\nimport {\n\tAlignmentControl,\n\tBlockControls,\n\tInspectorControls,\n\tstore as blockEditorStore,\n\tuseBlockProps,\n\tuseBlockEditingMode,\n\t__experimentalDateFormatPicker as DateFormatPicker,\n\t__experimentalPublishDateTimePicker as PublishDateTimePicker,\n} from '@wordpress/block-editor';\nimport {\n\tDropdown,\n\tToolbarGroup,\n\tToolbarButton,\n\tToggleControl,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { pencil } from '@wordpress/icons';\nimport { DOWN } from '@wordpress/keycodes';\nimport { useSelect, useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nexport default function PostDateEdit( {\n\tattributes
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useEffect, useMemo, useState } from '@wordpress/element';\nimport {\n\tdateI18n,\n\thumanTimeDiff,\n\tgetSettings as getDateSettings,\n} from '@wordpress/date';\nimport {\n\tAlignmentControl,\n\tBlockControls,\n\tInspectorControls,\n\tstore as blockEditorStore,\n\tuseBlockProps,\n\tuseBlockEditingMode,\n\t__experimentalDateFormatPicker as DateFormatPicker,\n\t__experimentalPublishDateTimePicker as PublishDateTimePicker,\n} from '@wordpress/block-editor';\nimport {\n\tDropdown,\n\tToolbarGroup,\n\tToolbarButton,\n\tToggleControl,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { __, _x, sprintf } from '@wordpress/i18n';\nimport { pencil } from '@wordpress/icons';\nimport { DOWN } from '@wordpress/keycodes';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blocksStore } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nexport default function PostDateEdit( {\n\tattributes,\n\tcontext: { postType: postTypeSlug, queryId },\n\tsetAttributes,\n\tname,\n} ) {\n\tconst { datetime, textAlign, format, isLink } = attributes;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t} );\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\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\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( { anchor: popoverAnchor } ),\n\t\t[ popoverAnchor ]\n\t);\n\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\n\t// We need to set the datetime to a default value upon first loading\n\t// to discern the block from its legacy version (which would default\n\t// to the containing post's publish date).\n\tuseEffect( () => {\n\t\tif ( datetime === undefined ) {\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( { datetime: new Date() } );\n\t\t}\n\t}, [ datetime ] );\n\n\tconst isDescendentOfQueryLoop = Number.isFinite( queryId );\n\tconst dateSettings = getDateSettings();\n\n\tconst {\n\t\tpostType,\n\t\tsiteFormat = dateSettings.formats.date,\n\t\tsiteTimeFormat = dateSettings.formats.time,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getPostType, getEntityRecord } = select( coreStore );\n\t\t\tconst siteSettings = getEntityRecord( 'root', 'site' );\n\t\t\treturn {\n\t\t\t\tsiteFormat: siteSettings?.date_format,\n\t\t\t\tsiteTimeFormat: siteSettings?.time_format,\n\t\t\t\tpostType: postTypeSlug ? getPostType( postTypeSlug ) : null,\n\t\t\t};\n\t\t},\n\t\t[ postTypeSlug ]\n\t);\n\tconst activeBlockVariationName = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blocksStore ).getActiveBlockVariation( name, attributes )\n\t\t\t\t?.name,\n\t\t[ name, attributes ]\n\t);\n\n\tconst blockEditingMode = useBlockEditingMode();\n\n\tlet postDate = (\n\t\t<time dateTime={ dateI18n( 'c', datetime ) } ref={ setPopoverAnchor }>\n\t\t\t{ format === 'human-diff'\n\t\t\t\t? humanTimeDiff( datetime )\n\t\t\t\t: dateI18n( format || siteFormat, datetime ) }\n\t\t</time>\n\t);\n\n\tif ( isLink && datetime ) {\n\t\tpostDate = (\n\t\t\t<a\n\t\t\t\thref=\"#post-date-pseudo-link\"\n\t\t\t\tonClick={ ( event ) => event.preventDefault() }\n\t\t\t>\n\t\t\t\t{ postDate }\n\t\t\t</a>\n\t\t);\n\t}\n\treturn (\n\t\t<>\n\t\t\t{ ( blockEditingMode === 'default' ||\n\t\t\t\t! isDescendentOfQueryLoop ) && (\n\t\t\t\t<BlockControls group=\"block\">\n\t\t\t\t\t<AlignmentControl\n\t\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\t\tonChange={ ( nextAlign ) => {\n\t\t\t\t\t\t\tsetAttributes( { textAlign: nextAlign } );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\n\t\t\t\t\t{ activeBlockVariationName !== 'post-date-modified' &&\n\t\t\t\t\t\t( ! isDescendentOfQueryLoop ||\n\t\t\t\t\t\t\t! activeBlockVariationName ) && (\n\t\t\t\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t\t\t\t<Dropdown\n\t\t\t\t\t\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\t\t\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t\t\t\t\t\t<PublishDateTimePicker\n\t\t\t\t\t\t\t\t\t\t\ttitle={\n\t\t\t\t\t\t\t\t\t\t\t\tactiveBlockVariationName ===\n\t\t\t\t\t\t\t\t\t\t\t\t'post-date'\n\t\t\t\t\t\t\t\t\t\t\t\t\t? __( 'Publish Date' )\n\t\t\t\t\t\t\t\t\t\t\t\t\t: __( 'Date' )\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tcurrentDate={ datetime }\n\t\t\t\t\t\t\t\t\t\t\tonChange={ ( newDatetime ) =>\n\t\t\t\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\t\t\t\tdatetime: newDatetime,\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\tis12Hour={ is12HourFormat(\n\t\t\t\t\t\t\t\t\t\t\t\tsiteTimeFormat\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\t\t\t\t\t\t\tdateOrder={\n\t\t\t\t\t\t\t\t\t\t\t\t/* translators: Order of day, month, and year. Available formats are 'dmy', 'mdy', and 'ymd'. */\n\t\t\t\t\t\t\t\t\t\t\t\t_x( 'dmy', 'date order' )\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) }\n\t\t\t\t\t\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => {\n\t\t\t\t\t\t\t\t\t\tconst openOnArrowDown = ( event ) => {\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t! isOpen &&\n\t\t\t\t\t\t\t\t\t\t\t\tevent.keyCode === DOWN\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\t\t\t\t\t\tonToggle();\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\treturn (\n\t\t\t\t\t\t\t\t\t\t\t<ToolbarButton\n\t\t\t\t\t\t\t\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\t\t\t\t\t\t\t\ticon={ pencil }\n\t\t\t\t\t\t\t\t\t\t\t\ttitle={ __( 'Change Date' ) }\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\t\t\t\t\t\t\tonKeyDown={ openOnArrowDown }\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} }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ToolbarGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t</BlockControls>\n\t\t\t) }\n\n\t\t\t<InspectorControls>\n\t\t\t\t<ToolsPanel\n\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\tresetAll={ () => {\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\tdatetime: undefined,\n\t\t\t\t\t\t\tformat: undefined,\n\t\t\t\t\t\t\tisLink: false,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => !! format }\n\t\t\t\t\t\tlabel={ __( 'Date Format' ) }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetAttributes( { format: undefined } )\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<DateFormatPicker\n\t\t\t\t\t\t\tformat={ format }\n\t\t\t\t\t\t\tdefaultFormat={ siteFormat }\n\t\t\t\t\t\t\tonChange={ ( nextFormat ) =>\n\t\t\t\t\t\t\t\tsetAttributes( { format: nextFormat } )\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\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => isLink !== false }\n\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\tpostType?.labels.singular_name\n\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t// translators: %s: Name of the post type e.g: \"post\".\n\t\t\t\t\t\t\t\t\t\t__( 'Link to %s' ),\n\t\t\t\t\t\t\t\t\t\tpostType.labels.singular_name.toLowerCase()\n\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t: __( 'Link to post' )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonDeselect={ () => setAttributes( { isLink: false } ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\tpostType?.labels.singular_name\n\t\t\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t\t\t// translators: %s: Name of the post type e.g: \"post\".\n\t\t\t\t\t\t\t\t\t\t\t__( 'Link to %s' ),\n\t\t\t\t\t\t\t\t\t\t\tpostType.labels.singular_name.toLowerCase()\n\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t: __( 'Link to post' )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( { isLink: ! isLink } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tchecked={ isLink }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t</ToolsPanel>\n\t\t\t</InspectorControls>\n\n\t\t\t<div { ...blockProps }>{ postDate }</div>\n\t\t</>\n\t);\n}\n\nexport function is12HourFormat( format ) {\n\t// To know if the time format is a 12 hour time, look for any of the 12 hour\n\t// format characters: 'a', 'A', 'g', and 'h'. The character must be\n\t// unescaped, i.e. not preceded by a '\\'. Coincidentally, 'aAgh' is how I\n\t// feel when working with regular expressions.\n\t// https://www.php.net/manual/en/datetime.format.php\n\treturn /(?:^|[^\\\\])[aAgh]/.test( format );\n}\n"],
|
|
5
|
+
"mappings": "AA6GE,SAkBA,UAlBA,KAqBE,YArBF;AA1GF,OAAO,UAAU;AAKjB,SAAS,SAAS,iBAAiB;AACnC,SAAS,WAAW,SAAS,gBAAgB;AAC7C;AAAA,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AY;AAAA,cAC1C,IACA,GAAI,cAAe;AAAA,cAEvB,YAAa,MAAM,cAAe,EAAE,QAAQ,MAAM,CAAE;AAAA,cACpD,kBAAgB;AAAA,cAEhB;AAAA,gBAAC;AAAA;AAAA,kBACA,yBAAuB;AAAA,kBACvB,OACC,UAAU,OAAO,gBACd;AAAA;AAAA,oBAEA,GAAI,YAAa;AAAA,oBACjB,SAAS,OAAO,cAAc,YAAY;AAAA,kBAC1C,IACA,GAAI,cAAe;AAAA,kBAEvB,UAAW,MACV,cAAe,EAAE,QAAQ,CAAE,OAAO,CAAE;AAAA,kBAErC,SAAU;AAAA;AAAA,cACX;AAAA;AAAA,UACD;AAAA;AAAA;AAAA,IACD,GACD;AAAA,IAEA,oBAAC,SAAM,GAAG,YAAe,oBAAU;AAAA,KACpC;AAEF;AAEO,SAAS,eAAgB,QAAS;AAMxC,SAAO,oBAAoB,KAAM,MAAO;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { __ } from "@wordpress/i18n";
|
|
2
|
-
import { postDate } from "@wordpress/icons";
|
|
3
2
|
const variations = [
|
|
4
3
|
{
|
|
5
4
|
name: "post-date",
|
|
@@ -15,9 +14,8 @@ const variations = [
|
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
16
|
},
|
|
18
|
-
scope: ["
|
|
19
|
-
isActive: (blockAttributes) => blockAttributes?.metadata?.bindings?.datetime?.source === "core/post-data" && blockAttributes?.metadata?.bindings?.datetime?.args?.field === "date"
|
|
20
|
-
icon: postDate
|
|
17
|
+
scope: ["inserter", "transform"],
|
|
18
|
+
isActive: (blockAttributes) => blockAttributes?.metadata?.bindings?.datetime?.source === "core/post-data" && blockAttributes?.metadata?.bindings?.datetime?.args?.field === "date"
|
|
21
19
|
},
|
|
22
20
|
{
|
|
23
21
|
name: "post-date-modified",
|
|
@@ -34,9 +32,8 @@ const variations = [
|
|
|
34
32
|
},
|
|
35
33
|
className: "wp-block-post-date__modified-date"
|
|
36
34
|
},
|
|
37
|
-
scope: ["
|
|
38
|
-
isActive: (blockAttributes) => blockAttributes?.metadata?.bindings?.datetime?.source === "core/post-data" && blockAttributes?.metadata?.bindings?.datetime?.args?.field === "modified"
|
|
39
|
-
icon: postDate
|
|
35
|
+
scope: ["inserter", "transform"],
|
|
36
|
+
isActive: (blockAttributes) => blockAttributes?.metadata?.bindings?.datetime?.source === "core/post-data" && blockAttributes?.metadata?.bindings?.datetime?.args?.field === "modified"
|
|
40
37
|
}
|
|
41
38
|
];
|
|
42
39
|
var variations_default = variations;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/post-date/variations.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\
|
|
5
|
-
"mappings": "AAGA,SAAS,UAAU;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\nconst variations = [\n\t{\n\t\tname: 'post-date',\n\t\ttitle: __( 'Post Date' ),\n\t\tdescription: __( \"Display a post's publish date.\" ),\n\t\tattributes: {\n\t\t\tmetadata: {\n\t\t\t\tbindings: {\n\t\t\t\t\tdatetime: {\n\t\t\t\t\t\tsource: 'core/post-data',\n\t\t\t\t\t\targs: { field: 'date' },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tscope: [ 'inserter', 'transform' ],\n\t\tisActive: ( blockAttributes ) =>\n\t\t\tblockAttributes?.metadata?.bindings?.datetime?.source ===\n\t\t\t\t'core/post-data' &&\n\t\t\tblockAttributes?.metadata?.bindings?.datetime?.args?.field ===\n\t\t\t\t'date',\n\t},\n\t{\n\t\tname: 'post-date-modified',\n\t\ttitle: __( 'Modified Date' ),\n\t\tdescription: __( \"Display a post's last updated date.\" ),\n\t\tattributes: {\n\t\t\tmetadata: {\n\t\t\t\tbindings: {\n\t\t\t\t\tdatetime: {\n\t\t\t\t\t\tsource: 'core/post-data',\n\t\t\t\t\t\targs: { field: 'modified' },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tclassName: 'wp-block-post-date__modified-date',\n\t\t},\n\t\tscope: [ 'inserter', 'transform' ],\n\t\tisActive: ( blockAttributes ) =>\n\t\t\tblockAttributes?.metadata?.bindings?.datetime?.source ===\n\t\t\t\t'core/post-data' &&\n\t\t\tblockAttributes?.metadata?.bindings?.datetime?.args?.field ===\n\t\t\t\t'modified',\n\t},\n];\n\nexport default variations;\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,UAAU;AAEnB,MAAM,aAAa;AAAA,EAClB;AAAA,IACC,MAAM;AAAA,IACN,OAAO,GAAI,WAAY;AAAA,IACvB,aAAa,GAAI,gCAAiC;AAAA,IAClD,YAAY;AAAA,MACX,UAAU;AAAA,QACT,UAAU;AAAA,UACT,UAAU;AAAA,YACT,QAAQ;AAAA,YACR,MAAM,EAAE,OAAO,OAAO;AAAA,UACvB;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,IACA,OAAO,CAAE,YAAY,WAAY;AAAA,IACjC,UAAU,CAAE,oBACX,iBAAiB,UAAU,UAAU,UAAU,WAC9C,oBACD,iBAAiB,UAAU,UAAU,UAAU,MAAM,UACpD;AAAA,EACH;AAAA,EACA;AAAA,IACC,MAAM;AAAA,IACN,OAAO,GAAI,eAAgB;AAAA,IAC3B,aAAa,GAAI,qCAAsC;AAAA,IACvD,YAAY;AAAA,MACX,UAAU;AAAA,QACT,UAAU;AAAA,UACT,UAAU;AAAA,YACT,QAAQ;AAAA,YACR,MAAM,EAAE,OAAO,WAAW;AAAA,UAC3B;AAAA,QACD;AAAA,MACD;AAAA,MACA,WAAW;AAAA,IACZ;AAAA,IACA,OAAO,CAAE,YAAY,WAAY;AAAA,IACjC,UAAU,CAAE,oBACX,iBAAiB,UAAU,UAAU,UAAU,WAC9C,oBACD,iBAAiB,UAAU,UAAU,UAAU,MAAM,UACpD;AAAA,EACH;AACD;AAEA,IAAO,qBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -16,7 +16,19 @@ import { store as coreStore } from "@wordpress/core-data";
|
|
|
16
16
|
import { list, grid } from "@wordpress/icons";
|
|
17
17
|
const TEMPLATE = [
|
|
18
18
|
["core/post-title"],
|
|
19
|
-
[
|
|
19
|
+
[
|
|
20
|
+
"core/post-date",
|
|
21
|
+
{
|
|
22
|
+
metadata: {
|
|
23
|
+
bindings: {
|
|
24
|
+
datetime: {
|
|
25
|
+
source: "core/post-data",
|
|
26
|
+
args: { field: "date" }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
],
|
|
20
32
|
["core/post-excerpt"]
|
|
21
33
|
];
|
|
22
34
|
function PostTemplateInnerBlocks({ classList }) {
|