@wordpress/block-library 9.38.0 → 9.38.1-next.v.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/block/block.json +2 -1
- package/build/breadcrumbs/edit.cjs +15 -5
- package/build/breadcrumbs/edit.cjs.map +2 -2
- package/build/breadcrumbs/index.cjs +1 -0
- package/build/breadcrumbs/index.cjs.map +2 -2
- package/build/comment-date/block.json +1 -0
- package/build/comment-edit-link/block.json +1 -3
- package/build/comment-edit-link/deprecated.cjs +91 -0
- package/build/comment-edit-link/deprecated.cjs.map +7 -0
- package/build/comment-edit-link/edit.cjs +6 -18
- package/build/comment-edit-link/edit.cjs.map +3 -3
- package/build/comment-edit-link/index.cjs +2 -0
- package/build/comment-edit-link/index.cjs.map +3 -3
- package/build/comment-reply-link/block.json +1 -5
- package/build/comment-reply-link/deprecated.cjs +84 -0
- package/build/comment-reply-link/deprecated.cjs.map +7 -0
- package/build/comment-reply-link/edit.cjs +10 -23
- package/build/comment-reply-link/edit.cjs.map +3 -3
- package/build/comment-reply-link/index.cjs +2 -0
- package/build/comment-reply-link/index.cjs.map +3 -3
- package/build/cover/edit/inspector-controls.cjs +1 -1
- package/build/cover/edit/inspector-controls.cjs.map +2 -2
- package/build/embed/util.cjs +9 -0
- package/build/embed/util.cjs.map +2 -2
- package/build/freeform/block.json +2 -1
- package/build/html/block.json +2 -1
- package/build/image/image.cjs +43 -9
- package/build/image/image.cjs.map +2 -2
- package/build/list-item/index.cjs +9 -1
- package/build/list-item/index.cjs.map +2 -2
- package/build/missing/block.json +2 -1
- package/build/more/block.json +2 -1
- package/build/navigation/block.json +5 -4
- package/build/navigation/deprecated.cjs +133 -5
- package/build/navigation/deprecated.cjs.map +2 -2
- package/build/navigation/edit/deleted-overlay-warning.cjs +70 -0
- package/build/navigation/edit/deleted-overlay-warning.cjs.map +7 -0
- package/build/navigation/edit/index.cjs +122 -65
- package/build/navigation/edit/index.cjs.map +3 -3
- package/build/navigation/edit/overlay-panel.cjs +10 -1
- package/build/navigation/edit/overlay-panel.cjs.map +3 -3
- package/build/navigation/edit/overlay-preview.cjs +120 -0
- package/build/navigation/edit/overlay-preview.cjs.map +7 -0
- package/build/navigation/edit/overlay-template-part-selector.cjs +59 -24
- package/build/navigation/edit/overlay-template-part-selector.cjs.map +3 -3
- package/build/navigation/edit/responsive-wrapper.cjs +12 -1
- package/build/navigation/edit/responsive-wrapper.cjs.map +3 -3
- package/build/navigation/edit/use-create-overlay.cjs +19 -2
- package/build/navigation/edit/use-create-overlay.cjs.map +3 -3
- package/build/navigation/utils/get-submenu-visibility.cjs +37 -0
- package/build/navigation/utils/get-submenu-visibility.cjs.map +7 -0
- package/build/navigation-link/edit.cjs +2 -40
- package/build/navigation-link/edit.cjs.map +2 -2
- package/build/navigation-link/shared/index.cjs +6 -0
- package/build/navigation-link/shared/index.cjs.map +2 -2
- package/build/navigation-link/shared/select-label-text.cjs +40 -0
- package/build/navigation-link/shared/select-label-text.cjs.map +7 -0
- package/build/navigation-link/shared/use-is-dragging-within.cjs +59 -0
- package/build/navigation-link/shared/use-is-dragging-within.cjs.map +7 -0
- package/build/navigation-submenu/block.json +1 -1
- package/build/navigation-submenu/edit.cjs +8 -47
- package/build/navigation-submenu/edit.cjs.map +2 -2
- package/build/nextpage/block.json +2 -1
- package/build/paragraph/block.json +1 -0
- package/build/shortcode/block.json +2 -1
- package/build/template-part/edit/index.cjs +1 -1
- package/build/template-part/edit/index.cjs.map +2 -2
- package/build/verse/block.json +1 -3
- package/build/verse/deprecated.cjs +74 -5
- package/build/verse/deprecated.cjs.map +3 -3
- package/build/verse/edit.cjs +33 -48
- package/build/verse/edit.cjs.map +3 -3
- package/build/verse/save.cjs +2 -16
- package/build/verse/save.cjs.map +3 -3
- package/build-module/block/block.json +2 -1
- package/build-module/breadcrumbs/edit.mjs +15 -5
- package/build-module/breadcrumbs/edit.mjs.map +2 -2
- package/build-module/breadcrumbs/index.mjs +1 -0
- package/build-module/breadcrumbs/index.mjs.map +2 -2
- package/build-module/comment-date/block.json +1 -0
- package/build-module/comment-edit-link/block.json +1 -3
- package/build-module/comment-edit-link/deprecated.mjs +60 -0
- package/build-module/comment-edit-link/deprecated.mjs.map +7 -0
- package/build-module/comment-edit-link/edit.mjs +7 -24
- package/build-module/comment-edit-link/edit.mjs.map +2 -2
- package/build-module/comment-edit-link/index.mjs +2 -0
- package/build-module/comment-edit-link/index.mjs.map +2 -2
- package/build-module/comment-reply-link/block.json +1 -5
- package/build-module/comment-reply-link/deprecated.mjs +53 -0
- package/build-module/comment-reply-link/deprecated.mjs.map +7 -0
- package/build-module/comment-reply-link/edit.mjs +12 -29
- package/build-module/comment-reply-link/edit.mjs.map +2 -2
- package/build-module/comment-reply-link/index.mjs +2 -0
- package/build-module/comment-reply-link/index.mjs.map +2 -2
- package/build-module/cover/edit/inspector-controls.mjs +1 -1
- package/build-module/cover/edit/inspector-controls.mjs.map +2 -2
- package/build-module/embed/util.mjs +8 -0
- package/build-module/embed/util.mjs.map +2 -2
- package/build-module/freeform/block.json +2 -1
- package/build-module/html/block.json +2 -1
- package/build-module/image/image.mjs +43 -9
- package/build-module/image/image.mjs.map +2 -2
- package/build-module/list-item/index.mjs +9 -1
- package/build-module/list-item/index.mjs.map +2 -2
- package/build-module/missing/block.json +2 -1
- package/build-module/more/block.json +2 -1
- package/build-module/navigation/block.json +5 -4
- package/build-module/navigation/deprecated.mjs +133 -5
- package/build-module/navigation/deprecated.mjs.map +2 -2
- package/build-module/navigation/edit/deleted-overlay-warning.mjs +49 -0
- package/build-module/navigation/edit/deleted-overlay-warning.mjs.map +7 -0
- package/build-module/navigation/edit/index.mjs +124 -65
- package/build-module/navigation/edit/index.mjs.map +2 -2
- package/build-module/navigation/edit/overlay-panel.mjs +10 -1
- package/build-module/navigation/edit/overlay-panel.mjs.map +2 -2
- package/build-module/navigation/edit/overlay-preview.mjs +99 -0
- package/build-module/navigation/edit/overlay-preview.mjs.map +7 -0
- package/build-module/navigation/edit/overlay-template-part-selector.mjs +61 -26
- package/build-module/navigation/edit/overlay-template-part-selector.mjs.map +2 -2
- package/build-module/navigation/edit/responsive-wrapper.mjs +12 -1
- package/build-module/navigation/edit/responsive-wrapper.mjs.map +2 -2
- package/build-module/navigation/edit/use-create-overlay.mjs +21 -4
- package/build-module/navigation/edit/use-create-overlay.mjs.map +2 -2
- package/build-module/navigation/utils/get-submenu-visibility.mjs +12 -0
- package/build-module/navigation/utils/get-submenu-visibility.mjs.map +7 -0
- package/build-module/navigation-link/edit.mjs +4 -40
- package/build-module/navigation-link/edit.mjs.map +2 -2
- package/build-module/navigation-link/shared/index.mjs +4 -0
- package/build-module/navigation-link/shared/index.mjs.map +2 -2
- package/build-module/navigation-link/shared/select-label-text.mjs +15 -0
- package/build-module/navigation-link/shared/select-label-text.mjs.map +7 -0
- package/build-module/navigation-link/shared/use-is-dragging-within.mjs +34 -0
- package/build-module/navigation-link/shared/use-is-dragging-within.mjs.map +7 -0
- package/build-module/navigation-submenu/block.json +1 -1
- package/build-module/navigation-submenu/edit.mjs +10 -47
- package/build-module/navigation-submenu/edit.mjs.map +2 -2
- package/build-module/nextpage/block.json +2 -1
- package/build-module/paragraph/block.json +1 -0
- package/build-module/shortcode/block.json +2 -1
- package/build-module/template-part/edit/index.mjs +1 -1
- package/build-module/template-part/edit/index.mjs.map +2 -2
- package/build-module/verse/block.json +1 -3
- package/build-module/verse/deprecated.mjs +74 -5
- package/build-module/verse/deprecated.mjs.map +2 -2
- package/build-module/verse/edit.mjs +35 -55
- package/build-module/verse/edit.mjs.map +2 -2
- package/build-module/verse/save.mjs +2 -6
- package/build-module/verse/save.mjs.map +2 -2
- package/build-style/editor-rtl.css +48 -0
- package/build-style/editor.css +48 -0
- package/build-style/media-text/style-rtl.css +2 -0
- package/build-style/media-text/style.css +2 -0
- package/build-style/navigation/editor-rtl.css +48 -0
- package/build-style/navigation/editor.css +48 -0
- package/build-style/navigation/style-rtl.css +64 -18
- package/build-style/navigation/style.css +64 -18
- package/build-style/style-rtl.css +67 -18
- package/build-style/style.css +67 -18
- package/build-style/verse/style-rtl.css +1 -0
- package/build-style/verse/style.css +1 -0
- package/package.json +37 -37
- package/src/block/block.json +2 -1
- package/src/breadcrumbs/edit.js +10 -2
- package/src/breadcrumbs/index.js +1 -0
- package/src/categories/index.php +5 -1
- package/src/comment-date/block.json +1 -0
- package/src/comment-edit-link/block.json +1 -3
- package/src/comment-edit-link/deprecated.js +63 -0
- package/src/comment-edit-link/edit.js +7 -31
- package/src/comment-edit-link/index.js +2 -0
- package/src/comment-reply-link/block.json +1 -5
- package/src/comment-reply-link/deprecated.js +56 -0
- package/src/comment-reply-link/edit.js +6 -35
- package/src/comment-reply-link/index.js +2 -0
- package/src/cover/edit/inspector-controls.js +1 -3
- package/src/embed/test/index.js +49 -0
- package/src/embed/util.js +21 -0
- package/src/freeform/block.json +2 -1
- package/src/html/block.json +2 -1
- package/src/image/image.js +63 -11
- package/src/list-item/index.js +12 -0
- package/src/media-text/style.scss +2 -0
- package/src/missing/block.json +2 -1
- package/src/more/block.json +2 -1
- package/src/navigation/block.json +5 -4
- package/src/navigation/deprecated.js +144 -5
- package/src/navigation/edit/deleted-overlay-warning.js +56 -0
- package/src/navigation/edit/index.js +157 -70
- package/src/navigation/edit/overlay-panel.js +10 -0
- package/src/navigation/edit/overlay-preview.js +133 -0
- package/src/navigation/edit/overlay-template-part-selector.js +76 -26
- package/src/navigation/edit/responsive-wrapper.js +14 -1
- package/src/navigation/edit/test/overlay-template-part-selector.js +24 -16
- package/src/navigation/edit/test/responsive-wrapper.js +179 -0
- package/src/navigation/edit/test/use-create-overlay.js +129 -2
- package/src/navigation/edit/use-create-overlay.js +26 -4
- package/src/navigation/editor.scss +51 -0
- package/src/navigation/index.php +59 -11
- package/src/navigation/style.scss +140 -76
- package/src/navigation/utils/get-submenu-visibility.js +27 -0
- package/src/navigation/utils/test/get-submenu-visibility.js +47 -0
- package/src/navigation-link/edit.js +3 -67
- package/src/navigation-link/shared/index.js +2 -0
- package/src/navigation-link/shared/select-label-text.js +16 -0
- package/src/navigation-link/shared/use-is-dragging-within.js +55 -0
- package/src/navigation-submenu/block.json +1 -1
- package/src/navigation-submenu/edit.js +10 -73
- package/src/navigation-submenu/index.php +36 -5
- package/src/nextpage/block.json +2 -1
- package/src/paragraph/block.json +1 -0
- package/src/shortcode/block.json +2 -1
- package/src/template-part/edit/index.js +1 -1
- package/src/verse/block.json +1 -3
- package/src/verse/deprecated.js +83 -4
- package/src/verse/edit.js +37 -56
- package/src/verse/save.js +2 -11
- package/src/verse/style.scss +1 -0
|
@@ -29,47 +29,22 @@ import {
|
|
|
29
29
|
useEntityBinding,
|
|
30
30
|
useIsInvalidLink,
|
|
31
31
|
InvalidDraftDisplay,
|
|
32
|
-
useEnableLinkStatusValidation
|
|
32
|
+
useEnableLinkStatusValidation,
|
|
33
|
+
useIsDraggingWithin,
|
|
34
|
+
selectLabelText
|
|
33
35
|
} from "../navigation-link/shared/index.mjs";
|
|
34
36
|
import {
|
|
35
37
|
getColors,
|
|
36
38
|
getNavigationChildBlockProps
|
|
37
39
|
} from "../navigation/edit/utils.mjs";
|
|
38
40
|
import { DEFAULT_BLOCK } from "../navigation/constants.mjs";
|
|
41
|
+
import { getSubmenuVisibility } from "../navigation/utils/get-submenu-visibility.mjs";
|
|
39
42
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
40
43
|
var ALLOWED_BLOCKS = [
|
|
41
44
|
"core/navigation-link",
|
|
42
45
|
"core/navigation-submenu",
|
|
43
46
|
"core/page-list"
|
|
44
47
|
];
|
|
45
|
-
var useIsDraggingWithin = (elementRef) => {
|
|
46
|
-
const [isDraggingWithin, setIsDraggingWithin] = useState(false);
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
const { ownerDocument } = elementRef.current;
|
|
49
|
-
function handleDragStart(event) {
|
|
50
|
-
handleDragEnter(event);
|
|
51
|
-
}
|
|
52
|
-
function handleDragEnd() {
|
|
53
|
-
setIsDraggingWithin(false);
|
|
54
|
-
}
|
|
55
|
-
function handleDragEnter(event) {
|
|
56
|
-
if (elementRef.current.contains(event.target)) {
|
|
57
|
-
setIsDraggingWithin(true);
|
|
58
|
-
} else {
|
|
59
|
-
setIsDraggingWithin(false);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
ownerDocument.addEventListener("dragstart", handleDragStart);
|
|
63
|
-
ownerDocument.addEventListener("dragend", handleDragEnd);
|
|
64
|
-
ownerDocument.addEventListener("dragenter", handleDragEnter);
|
|
65
|
-
return () => {
|
|
66
|
-
ownerDocument.removeEventListener("dragstart", handleDragStart);
|
|
67
|
-
ownerDocument.removeEventListener("dragend", handleDragEnd);
|
|
68
|
-
ownerDocument.removeEventListener("dragenter", handleDragEnter);
|
|
69
|
-
};
|
|
70
|
-
}, []);
|
|
71
|
-
return isDraggingWithin;
|
|
72
|
-
};
|
|
73
48
|
function NavigationSubmenuEdit({
|
|
74
49
|
attributes,
|
|
75
50
|
isSelected,
|
|
@@ -80,13 +55,10 @@ function NavigationSubmenuEdit({
|
|
|
80
55
|
clientId
|
|
81
56
|
}) {
|
|
82
57
|
const { label, url, description, kind, type, id } = attributes;
|
|
83
|
-
const {
|
|
84
|
-
showSubmenuIcon,
|
|
85
|
-
maxNestingLevel,
|
|
86
|
-
openSubmenusOnClick: contextOpenSubmenusOnClick
|
|
87
|
-
} = context;
|
|
58
|
+
const { showSubmenuIcon, maxNestingLevel } = context;
|
|
88
59
|
const blockEditingMode = useBlockEditingMode();
|
|
89
|
-
const
|
|
60
|
+
const submenuVisibility = getSubmenuVisibility(context);
|
|
61
|
+
const openSubmenusOnClick = blockEditingMode !== "default" ? true : submenuVisibility === "click";
|
|
90
62
|
const { clearBinding, createBinding } = useEntityBinding({
|
|
91
63
|
clientId,
|
|
92
64
|
attributes
|
|
@@ -163,20 +135,10 @@ function NavigationSubmenuEdit({
|
|
|
163
135
|
useEffect(() => {
|
|
164
136
|
if (isLinkOpen && url) {
|
|
165
137
|
if (isURL(prependHTTP(label)) && /^.+\.[a-z]+/.test(label)) {
|
|
166
|
-
selectLabelText();
|
|
138
|
+
selectLabelText(ref);
|
|
167
139
|
}
|
|
168
140
|
}
|
|
169
141
|
}, [url]);
|
|
170
|
-
function selectLabelText() {
|
|
171
|
-
ref.current.focus();
|
|
172
|
-
const { ownerDocument } = ref.current;
|
|
173
|
-
const { defaultView } = ownerDocument;
|
|
174
|
-
const selection = defaultView.getSelection();
|
|
175
|
-
const range = ownerDocument.createRange();
|
|
176
|
-
range.selectNodeContents(ref.current);
|
|
177
|
-
selection.removeAllRanges();
|
|
178
|
-
selection.addRange(range);
|
|
179
|
-
}
|
|
180
142
|
const {
|
|
181
143
|
textColor,
|
|
182
144
|
customTextColor,
|
|
@@ -201,7 +163,8 @@ function NavigationSubmenuEdit({
|
|
|
201
163
|
[getColorClassName("color", textColor)]: !!textColor,
|
|
202
164
|
"has-background": !!backgroundColor || customBackgroundColor,
|
|
203
165
|
[getColorClassName("background-color", backgroundColor)]: !!backgroundColor,
|
|
204
|
-
"open-on-click": openSubmenusOnClick
|
|
166
|
+
"open-on-click": openSubmenusOnClick,
|
|
167
|
+
"open-always": submenuVisibility === "always"
|
|
205
168
|
}),
|
|
206
169
|
style: {
|
|
207
170
|
color: !textColor && customTextColor,
|
|
@@ -1,7 +1,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\tuseIsInvalidLink,\n\tInvalidDraftDisplay,\n\tuseEnableLinkStatusValidation,\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, kind, type, id } = 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 validateLinkStatus = useEnableLinkStatusValidation( clientId );\n\n\tconst prevHasChildren = usePrevious( hasChildren );\n\n\t// Check if the submenu's parent link is invalid or draft\n\tconst [ isInvalid, isDraft ] = useIsInvalidLink(\n\t\tkind,\n\t\ttype,\n\t\tid,\n\t\tvalidateLinkStatus\n\t);\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<ParentElement className=\"wp-block-navigation-item__content\">\n\t\t\t\t\t{ ! isInvalid && ! isDraft && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\t\t\tidentifier=\"label\"\n\t\t\t\t\t\t\t\tclassName=\"wp-block-navigation-item__label\"\n\t\t\t\t\t\t\t\tvalue={ label }\n\t\t\t\t\t\t\t\tonChange={ ( labelValue ) =>\n\t\t\t\t\t\t\t\t\tsetAttributes( { label: labelValue } )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\t\t\t\taria-label={ __( 'Navigation link text' ) }\n\t\t\t\t\t\t\t\tplaceholder={ itemLabelPlaceholder }\n\t\t\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tif ( ! openSubmenusOnClick && ! url ) {\n\t\t\t\t\t\t\t\t\t\tsetIsLinkOpen( true );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{ description && (\n\t\t\t\t\t\t\t\t<span className=\"wp-block-navigation-item__description\">\n\t\t\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t\t\t</span>\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{ ( isInvalid || isDraft ) && (\n\t\t\t\t\t\t<InvalidDraftDisplay\n\t\t\t\t\t\t\tlabel={ label }\n\t\t\t\t\t\t\tisInvalid={ isInvalid }\n\t\t\t\t\t\t\tisDraft={ isDraft }\n\t\t\t\t\t\t\tclassName=\"wp-block-navigation-item__label\"\n\t\t\t\t\t\t/>\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": ";AAGA,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,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,qBAAqB;
|
|
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\tuseIsInvalidLink,\n\tInvalidDraftDisplay,\n\tuseEnableLinkStatusValidation,\n\tuseIsDraggingWithin,\n\tselectLabelText,\n} from '../navigation-link/shared';\nimport {\n\tgetColors,\n\tgetNavigationChildBlockProps,\n} from '../navigation/edit/utils';\nimport { DEFAULT_BLOCK } from '../navigation/constants';\nimport { getSubmenuVisibility } from '../navigation/utils/get-submenu-visibility';\n\nconst ALLOWED_BLOCKS = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n\t'core/page-list',\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, kind, type, id } = attributes;\n\n\tconst { showSubmenuIcon, maxNestingLevel } = context;\n\tconst blockEditingMode = useBlockEditingMode();\n\n\t// Determine effective submenu visibility with backward compatibility\n\tconst submenuVisibility = getSubmenuVisibility( context );\n\n\t// Force click-only behavior in contentOnly mode to prevent hover dropdowns\n\tconst openSubmenusOnClick =\n\t\tblockEditingMode !== 'default' ? true : submenuVisibility === 'click';\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 validateLinkStatus = useEnableLinkStatusValidation( clientId );\n\n\tconst prevHasChildren = usePrevious( hasChildren );\n\n\t// Check if the submenu's parent link is invalid or draft\n\tconst [ isInvalid, isDraft ] = useIsInvalidLink(\n\t\tkind,\n\t\ttype,\n\t\tid,\n\t\tvalidateLinkStatus\n\t);\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( ref );\n\t\t\t}\n\t\t}\n\t}, [ url ] );\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\t'open-always': submenuVisibility === 'always',\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<ParentElement className=\"wp-block-navigation-item__content\">\n\t\t\t\t\t{ ! isInvalid && ! isDraft && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<RichText\n\t\t\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\t\t\tidentifier=\"label\"\n\t\t\t\t\t\t\t\tclassName=\"wp-block-navigation-item__label\"\n\t\t\t\t\t\t\t\tvalue={ label }\n\t\t\t\t\t\t\t\tonChange={ ( labelValue ) =>\n\t\t\t\t\t\t\t\t\tsetAttributes( { label: labelValue } )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\t\t\t\t\tonReplace={ onReplace }\n\t\t\t\t\t\t\t\taria-label={ __( 'Navigation link text' ) }\n\t\t\t\t\t\t\t\tplaceholder={ itemLabelPlaceholder }\n\t\t\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tif ( ! openSubmenusOnClick && ! url ) {\n\t\t\t\t\t\t\t\t\t\tsetIsLinkOpen( true );\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{ description && (\n\t\t\t\t\t\t\t\t<span className=\"wp-block-navigation-item__description\">\n\t\t\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t\t\t</span>\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{ ( isInvalid || isDraft ) && (\n\t\t\t\t\t\t<InvalidDraftDisplay\n\t\t\t\t\t\t\tlabel={ label }\n\t\t\t\t\t\t\tisInvalid={ isInvalid }\n\t\t\t\t\t\t\tisDraft={ isDraft }\n\t\t\t\t\t\t\tclassName=\"wp-block-navigation-item__label\"\n\t\t\t\t\t\t/>\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": ";AAGA,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,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Aa,GAAI,sBAAuB;AAAA,cACxC,aAAc;AAAA,cACd,8BAA4B;AAAA,cAC5B,SAAU,MAAM;AACf,oBAAK,CAAE,uBAAuB,CAAE,KAAM;AACrC,gCAAe,IAAK;AAAA,gBACrB;AAAA,cACD;AAAA;AAAA,UACD;AAAA,UACE,eACD,oBAAC,UAAK,WAAU,yCACb,uBACH;AAAA,WAEF;AAAA,SAEG,aAAa,YAChB;AAAA,UAAC;AAAA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA,WAAU;AAAA;AAAA,QACX;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,6BAAa;AAAA,cACd;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
|
}
|
|
@@ -232,7 +232,7 @@ function TemplatePartEdit({
|
|
|
232
232
|
}
|
|
233
233
|
);
|
|
234
234
|
} }),
|
|
235
|
-
/* @__PURE__ */ jsx(InspectorControls, { children: /* @__PURE__ */ jsx(
|
|
235
|
+
/* @__PURE__ */ jsx(InspectorControls, { group: "settings", children: /* @__PURE__ */ jsx(
|
|
236
236
|
TemplatesList,
|
|
237
237
|
{
|
|
238
238
|
area,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/template-part/edit/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { serialize } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tBlockSettingsMenuControls,\n\tuseBlockProps,\n\tWarning,\n\tstore as blockEditorStore,\n\tRecursionProvider,\n\tuseHasRecursion,\n\tInspectorControls,\n\t__experimentalBlockPatternsList as BlockPatternsList,\n\tBlockControls,\n} from '@wordpress/block-editor';\nimport {\n\tPanelBody,\n\tSpinner,\n\tModal,\n\tMenuItem,\n\tToolbarButton,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useState } from '@wordpress/element';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport TemplatePartPlaceholder from './placeholder';\nimport TemplatePartSelectionModal from './selection-modal';\nimport { TemplatePartAdvancedControls } from './advanced-controls';\nimport TemplatePartInnerBlocks from './inner-blocks';\nimport { createTemplatePartId } from './utils/create-template-part-id';\nimport {\n\tuseAlternativeBlockPatterns,\n\tuseAlternativeTemplateParts,\n\tuseTemplatePartArea,\n} from './utils/hooks';\n\nconst SUPPORTED_AREAS = [ 'header', 'footer' ];\n\n/**\n * Returns the list of supported template part areas for pattern replacement.\n * Includes 'overlay' only if the navigation overlays experiment is enabled.\n *\n * @return {string[]} Array of supported area names.\n */\nfunction getSupportedAreas() {\n\tconst isOverlayExperimentEnabled =\n\t\ttypeof window !== 'undefined' &&\n\t\twindow.__experimentalNavigationOverlays === true;\n\treturn isOverlayExperimentEnabled\n\t\t? [ ...SUPPORTED_AREAS, 'navigation-overlay' ]\n\t\t: SUPPORTED_AREAS;\n}\n\nfunction ReplaceButton( {\n\tisEntityAvailable,\n\tarea,\n\ttemplatePartId,\n\tisTemplatePartSelectionOpen,\n\tsetIsTemplatePartSelectionOpen,\n} ) {\n\t// This hook fetches patterns, so don't run it unconditionally in the main\n\t// edit function!\n\tconst { templateParts } = useAlternativeTemplateParts(\n\t\tarea,\n\t\ttemplatePartId\n\t);\n\tconst hasReplacements = !! templateParts.length;\n\tconst supportedAreas = getSupportedAreas();\n\tconst canReplace =\n\t\tisEntityAvailable && hasReplacements && supportedAreas.includes( area );\n\n\tif ( ! canReplace ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<MenuItem\n\t\t\tonClick={ () => {\n\t\t\t\tsetIsTemplatePartSelectionOpen( true );\n\t\t\t} }\n\t\t\taria-expanded={ isTemplatePartSelectionOpen }\n\t\t\taria-haspopup=\"dialog\"\n\t\t>\n\t\t\t{ __( 'Replace' ) }\n\t\t</MenuItem>\n\t);\n}\n\nfunction TemplatesList( { area, clientId, isEntityAvailable, onSelect } ) {\n\t// This hook fetches patterns, so don't run it unconditionally in the main\n\t// edit function!\n\tconst blockPatterns = useAlternativeBlockPatterns( area, clientId );\n\tconst supportedAreas = getSupportedAreas();\n\tconst canReplace =\n\t\tisEntityAvailable &&\n\t\t!! blockPatterns.length &&\n\t\tsupportedAreas.includes( area );\n\n\tif ( ! canReplace ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PanelBody title={ __( 'Design' ) }>\n\t\t\t<BlockPatternsList\n\t\t\t\tlabel={ __( 'Templates' ) }\n\t\t\t\tblockPatterns={ blockPatterns }\n\t\t\t\tonClickPattern={ onSelect }\n\t\t\t\tshowTitlesAsTooltip\n\t\t\t/>\n\t\t</PanelBody>\n\t);\n}\n\nexport default function TemplatePartEdit( {\n\tattributes,\n\tsetAttributes,\n\tclientId,\n} ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst { editEntityRecord } = useDispatch( coreStore );\n\tconst currentTheme = useSelect(\n\t\t( select ) => select( coreStore ).getCurrentTheme()?.stylesheet,\n\t\t[]\n\t);\n\tconst { slug, theme = currentTheme, tagName, layout = {} } = attributes;\n\tconst templatePartId = createTemplatePartId( theme, slug );\n\tconst hasAlreadyRendered = useHasRecursion( templatePartId );\n\tconst [ isTemplatePartSelectionOpen, setIsTemplatePartSelectionOpen ] =\n\t\tuseState( false );\n\n\tconst {\n\t\tisResolved,\n\t\thasInnerBlocks,\n\t\tisMissing,\n\t\tarea,\n\t\tonNavigateToEntityRecord,\n\t\ttitle,\n\t\tcanUserEdit,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst { getBlockCount, getSettings } = select( blockEditorStore );\n\n\t\t\tconst getEntityArgs = [\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\ttemplatePartId,\n\t\t\t];\n\t\t\tconst entityRecord = templatePartId\n\t\t\t\t? getEditedEntityRecord( ...getEntityArgs )\n\t\t\t\t: null;\n\t\t\tconst _area = entityRecord?.area || attributes.area;\n\t\t\tconst hasResolvedEntity = templatePartId\n\t\t\t\t? hasFinishedResolution(\n\t\t\t\t\t\t'getEditedEntityRecord',\n\t\t\t\t\t\tgetEntityArgs\n\t\t\t\t )\n\t\t\t\t: false;\n\n\t\t\tconst _canUserEdit = hasResolvedEntity\n\t\t\t\t? select( coreStore ).canUser( 'update', {\n\t\t\t\t\t\tkind: 'postType',\n\t\t\t\t\t\tname: 'wp_template_part',\n\t\t\t\t\t\tid: templatePartId,\n\t\t\t\t } )\n\t\t\t\t: false;\n\n\t\t\treturn {\n\t\t\t\thasInnerBlocks: getBlockCount( clientId ) > 0,\n\t\t\t\tisResolved: hasResolvedEntity,\n\t\t\t\tisMissing:\n\t\t\t\t\thasResolvedEntity &&\n\t\t\t\t\t( ! entityRecord ||\n\t\t\t\t\t\tObject.keys( entityRecord ).length === 0 ),\n\t\t\t\tarea: _area,\n\t\t\t\tonNavigateToEntityRecord:\n\t\t\t\t\tgetSettings().onNavigateToEntityRecord,\n\t\t\t\ttitle: entityRecord?.title,\n\t\t\t\tcanUserEdit: !! _canUserEdit,\n\t\t\t};\n\t\t},\n\t\t[ templatePartId, attributes.area, clientId ]\n\t);\n\n\tconst areaObject = useTemplatePartArea( area );\n\tconst blockProps = useBlockProps();\n\tconst isPlaceholder = ! slug;\n\tconst isEntityAvailable = ! isPlaceholder && ! isMissing && isResolved;\n\tconst TagName = tagName || areaObject.tagName;\n\n\tconst onPatternSelect = async ( pattern ) => {\n\t\tawait editEntityRecord(\n\t\t\t'postType',\n\t\t\t'wp_template_part',\n\t\t\ttemplatePartId,\n\t\t\t{\n\t\t\t\tblocks: pattern.blocks,\n\t\t\t\tcontent: serialize( pattern.blocks ),\n\t\t\t}\n\t\t);\n\t\tcreateSuccessNotice(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %s: template part title. */\n\t\t\t\t__( 'Template Part \"%s\" updated.' ),\n\t\t\t\ttitle || slug\n\t\t\t),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t}\n\t\t);\n\t};\n\n\t// We don't want to render a missing state if we have any inner blocks.\n\t// A new template part is automatically created if we have any inner blocks but no entity.\n\tif (\n\t\t! hasInnerBlocks &&\n\t\t( ( slug && ! theme ) || ( slug && isMissing ) )\n\t) {\n\t\treturn (\n\t\t\t<TagName { ...blockProps }>\n\t\t\t\t<Warning>\n\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t/* translators: %s: Template part slug. */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Template part has been deleted or is unavailable: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\tslug\n\t\t\t\t\t) }\n\t\t\t\t</Warning>\n\t\t\t</TagName>\n\t\t);\n\t}\n\n\tif ( isEntityAvailable && hasAlreadyRendered ) {\n\t\treturn (\n\t\t\t<TagName { ...blockProps }>\n\t\t\t\t<Warning>\n\t\t\t\t\t{ __( 'Block cannot be rendered inside itself.' ) }\n\t\t\t\t</Warning>\n\t\t\t</TagName>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<RecursionProvider uniqueId={ templatePartId }>\n\t\t\t\t{ isEntityAvailable &&\n\t\t\t\t\tonNavigateToEntityRecord &&\n\t\t\t\t\tcanUserEdit && (\n\t\t\t\t\t\t<BlockControls group=\"other\">\n\t\t\t\t\t\t\t<ToolbarButton\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: templatePartId,\n\t\t\t\t\t\t\t\t\t\tpostType: 'wp_template_part',\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ window?.__experimentalContentOnlyPatternInsertion\n\t\t\t\t\t\t\t\t\t? __( 'Edit section' )\n\t\t\t\t\t\t\t\t\t: __( 'Edit' ) }\n\t\t\t\t\t\t\t</ToolbarButton>\n\t\t\t\t\t\t</BlockControls>\n\t\t\t\t\t) }\n\t\t\t\t{ canUserEdit && (\n\t\t\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t\t\t<TemplatePartAdvancedControls\n\t\t\t\t\t\t\ttagName={ tagName }\n\t\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\t\tisEntityAvailable={ isEntityAvailable }\n\t\t\t\t\t\t\ttemplatePartId={ templatePartId }\n\t\t\t\t\t\t\tdefaultWrapper={ areaObject.tagName }\n\t\t\t\t\t\t\thasInnerBlocks={ hasInnerBlocks }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</InspectorControls>\n\t\t\t\t) }\n\t\t\t\t{ isPlaceholder && (\n\t\t\t\t\t<TagName { ...blockProps }>\n\t\t\t\t\t\t<TemplatePartPlaceholder\n\t\t\t\t\t\t\tarea={ attributes.area }\n\t\t\t\t\t\t\ttemplatePartId={ templatePartId }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\t\tonOpenSelectionModal={ () =>\n\t\t\t\t\t\t\t\tsetIsTemplatePartSelectionOpen( true )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</TagName>\n\t\t\t\t) }\n\t\t\t\t<BlockSettingsMenuControls>\n\t\t\t\t\t{ ( { selectedClientIds } ) => {\n\t\t\t\t\t\t// Only enable for single selection that matches the current block.\n\t\t\t\t\t\t// Ensures menu item doesn't render multiple times.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t! (\n\t\t\t\t\t\t\t\tselectedClientIds.length === 1 &&\n\t\t\t\t\t\t\t\tclientId === selectedClientIds[ 0 ]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<ReplaceButton\n\t\t\t\t\t\t\t\t{ ...{\n\t\t\t\t\t\t\t\t\tisEntityAvailable,\n\t\t\t\t\t\t\t\t\tarea,\n\t\t\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\t\t\ttemplatePartId,\n\t\t\t\t\t\t\t\t\tisTemplatePartSelectionOpen,\n\t\t\t\t\t\t\t\t\tsetIsTemplatePartSelectionOpen,\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</BlockSettingsMenuControls>\n\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<TemplatesList\n\t\t\t\t\t\tarea={ area }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tisEntityAvailable={ isEntityAvailable }\n\t\t\t\t\t\tonSelect={ ( pattern ) => onPatternSelect( pattern ) }\n\t\t\t\t\t/>\n\t\t\t\t</InspectorControls>\n\n\t\t\t\t{ isEntityAvailable && (\n\t\t\t\t\t<TemplatePartInnerBlocks\n\t\t\t\t\t\ttagName={ TagName }\n\t\t\t\t\t\tblockProps={ blockProps }\n\t\t\t\t\t\tpostId={ templatePartId }\n\t\t\t\t\t\thasInnerBlocks={ hasInnerBlocks }\n\t\t\t\t\t\tlayout={ layout }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ ! isPlaceholder && ! isResolved && (\n\t\t\t\t\t<TagName { ...blockProps }>\n\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t</TagName>\n\t\t\t\t) }\n\t\t\t</RecursionProvider>\n\t\t\t{ isTemplatePartSelectionOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\toverlayClassName=\"block-editor-template-part__selection-modal\"\n\t\t\t\t\ttitle={ sprintf(\n\t\t\t\t\t\t// Translators: %s as template part area title (\"Header\", \"Footer\", etc.).\n\t\t\t\t\t\t__( 'Choose a %s' ),\n\t\t\t\t\t\tareaObject.label.toLowerCase()\n\t\t\t\t\t) }\n\t\t\t\t\tonRequestClose={ () =>\n\t\t\t\t\t\tsetIsTemplatePartSelectionOpen( false )\n\t\t\t\t\t}\n\t\t\t\t\tisFullScreen\n\t\t\t\t>\n\t\t\t\t\t<TemplatePartSelectionModal\n\t\t\t\t\t\ttemplatePartId={ templatePartId }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tarea={ area }\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\tonClose={ () =>\n\t\t\t\t\t\t\tsetIsTemplatePartSelectionOpen( false )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,WAAW,mBAAmB;AACvC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAA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AAM,SACpB;AAAA,QAAC;AAAA;AAAA,UACA,SAAU,MAAM;AACf,qCAA0B;AAAA,cACzB,QAAQ;AAAA,cACR,UAAU;AAAA,YACX,CAAE;AAAA,UACH;AAAA,UAEE,kBAAQ,4CACP,GAAI,cAAe,IACnB,GAAI,MAAO;AAAA;AAAA,MACf,GACD;AAAA,MAEA,eACD,oBAAC,qBAAkB,OAAM,YACxB;AAAA,QAAC;AAAA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,gBAAiB,WAAW;AAAA,UAC5B;AAAA,UACA;AAAA;AAAA,MACD,GACD;AAAA,MAEC,iBACD,oBAAC,WAAU,GAAG,YACb;AAAA,QAAC;AAAA;AAAA,UACA,MAAO,WAAW;AAAA,UAClB;AAAA,UACA;AAAA,UACA;AAAA,UACA,sBAAuB,MACtB,+BAAgC,IAAK;AAAA;AAAA,MAEvC,GACD;AAAA,MAED,oBAAC,6BACE,WAAE,EAAE,kBAAkB,MAAO;AAG9B,YACC,EACC,kBAAkB,WAAW,KAC7B,aAAa,kBAAmB,CAAE,IAElC;AACD,iBAAO;AAAA,QACR;AAEA,eACC;AAAA,UAAC;AAAA;AAAA,YACE,GAAG;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YACD;AAAA;AAAA,QACD;AAAA,MAEF,GACD;AAAA,MAEA,oBAAC,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { serialize } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tBlockSettingsMenuControls,\n\tuseBlockProps,\n\tWarning,\n\tstore as blockEditorStore,\n\tRecursionProvider,\n\tuseHasRecursion,\n\tInspectorControls,\n\t__experimentalBlockPatternsList as BlockPatternsList,\n\tBlockControls,\n} from '@wordpress/block-editor';\nimport {\n\tPanelBody,\n\tSpinner,\n\tModal,\n\tMenuItem,\n\tToolbarButton,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useState } from '@wordpress/element';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport TemplatePartPlaceholder from './placeholder';\nimport TemplatePartSelectionModal from './selection-modal';\nimport { TemplatePartAdvancedControls } from './advanced-controls';\nimport TemplatePartInnerBlocks from './inner-blocks';\nimport { createTemplatePartId } from './utils/create-template-part-id';\nimport {\n\tuseAlternativeBlockPatterns,\n\tuseAlternativeTemplateParts,\n\tuseTemplatePartArea,\n} from './utils/hooks';\n\nconst SUPPORTED_AREAS = [ 'header', 'footer' ];\n\n/**\n * Returns the list of supported template part areas for pattern replacement.\n * Includes 'overlay' only if the navigation overlays experiment is enabled.\n *\n * @return {string[]} Array of supported area names.\n */\nfunction getSupportedAreas() {\n\tconst isOverlayExperimentEnabled =\n\t\ttypeof window !== 'undefined' &&\n\t\twindow.__experimentalNavigationOverlays === true;\n\treturn isOverlayExperimentEnabled\n\t\t? [ ...SUPPORTED_AREAS, 'navigation-overlay' ]\n\t\t: SUPPORTED_AREAS;\n}\n\nfunction ReplaceButton( {\n\tisEntityAvailable,\n\tarea,\n\ttemplatePartId,\n\tisTemplatePartSelectionOpen,\n\tsetIsTemplatePartSelectionOpen,\n} ) {\n\t// This hook fetches patterns, so don't run it unconditionally in the main\n\t// edit function!\n\tconst { templateParts } = useAlternativeTemplateParts(\n\t\tarea,\n\t\ttemplatePartId\n\t);\n\tconst hasReplacements = !! templateParts.length;\n\tconst supportedAreas = getSupportedAreas();\n\tconst canReplace =\n\t\tisEntityAvailable && hasReplacements && supportedAreas.includes( area );\n\n\tif ( ! canReplace ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<MenuItem\n\t\t\tonClick={ () => {\n\t\t\t\tsetIsTemplatePartSelectionOpen( true );\n\t\t\t} }\n\t\t\taria-expanded={ isTemplatePartSelectionOpen }\n\t\t\taria-haspopup=\"dialog\"\n\t\t>\n\t\t\t{ __( 'Replace' ) }\n\t\t</MenuItem>\n\t);\n}\n\nfunction TemplatesList( { area, clientId, isEntityAvailable, onSelect } ) {\n\t// This hook fetches patterns, so don't run it unconditionally in the main\n\t// edit function!\n\tconst blockPatterns = useAlternativeBlockPatterns( area, clientId );\n\tconst supportedAreas = getSupportedAreas();\n\tconst canReplace =\n\t\tisEntityAvailable &&\n\t\t!! blockPatterns.length &&\n\t\tsupportedAreas.includes( area );\n\n\tif ( ! canReplace ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<PanelBody title={ __( 'Design' ) }>\n\t\t\t<BlockPatternsList\n\t\t\t\tlabel={ __( 'Templates' ) }\n\t\t\t\tblockPatterns={ blockPatterns }\n\t\t\t\tonClickPattern={ onSelect }\n\t\t\t\tshowTitlesAsTooltip\n\t\t\t/>\n\t\t</PanelBody>\n\t);\n}\n\nexport default function TemplatePartEdit( {\n\tattributes,\n\tsetAttributes,\n\tclientId,\n} ) {\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst { editEntityRecord } = useDispatch( coreStore );\n\tconst currentTheme = useSelect(\n\t\t( select ) => select( coreStore ).getCurrentTheme()?.stylesheet,\n\t\t[]\n\t);\n\tconst { slug, theme = currentTheme, tagName, layout = {} } = attributes;\n\tconst templatePartId = createTemplatePartId( theme, slug );\n\tconst hasAlreadyRendered = useHasRecursion( templatePartId );\n\tconst [ isTemplatePartSelectionOpen, setIsTemplatePartSelectionOpen ] =\n\t\tuseState( false );\n\n\tconst {\n\t\tisResolved,\n\t\thasInnerBlocks,\n\t\tisMissing,\n\t\tarea,\n\t\tonNavigateToEntityRecord,\n\t\ttitle,\n\t\tcanUserEdit,\n\t} = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst { getBlockCount, getSettings } = select( blockEditorStore );\n\n\t\t\tconst getEntityArgs = [\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\ttemplatePartId,\n\t\t\t];\n\t\t\tconst entityRecord = templatePartId\n\t\t\t\t? getEditedEntityRecord( ...getEntityArgs )\n\t\t\t\t: null;\n\t\t\tconst _area = entityRecord?.area || attributes.area;\n\t\t\tconst hasResolvedEntity = templatePartId\n\t\t\t\t? hasFinishedResolution(\n\t\t\t\t\t\t'getEditedEntityRecord',\n\t\t\t\t\t\tgetEntityArgs\n\t\t\t\t )\n\t\t\t\t: false;\n\n\t\t\tconst _canUserEdit = hasResolvedEntity\n\t\t\t\t? select( coreStore ).canUser( 'update', {\n\t\t\t\t\t\tkind: 'postType',\n\t\t\t\t\t\tname: 'wp_template_part',\n\t\t\t\t\t\tid: templatePartId,\n\t\t\t\t } )\n\t\t\t\t: false;\n\n\t\t\treturn {\n\t\t\t\thasInnerBlocks: getBlockCount( clientId ) > 0,\n\t\t\t\tisResolved: hasResolvedEntity,\n\t\t\t\tisMissing:\n\t\t\t\t\thasResolvedEntity &&\n\t\t\t\t\t( ! entityRecord ||\n\t\t\t\t\t\tObject.keys( entityRecord ).length === 0 ),\n\t\t\t\tarea: _area,\n\t\t\t\tonNavigateToEntityRecord:\n\t\t\t\t\tgetSettings().onNavigateToEntityRecord,\n\t\t\t\ttitle: entityRecord?.title,\n\t\t\t\tcanUserEdit: !! _canUserEdit,\n\t\t\t};\n\t\t},\n\t\t[ templatePartId, attributes.area, clientId ]\n\t);\n\n\tconst areaObject = useTemplatePartArea( area );\n\tconst blockProps = useBlockProps();\n\tconst isPlaceholder = ! slug;\n\tconst isEntityAvailable = ! isPlaceholder && ! isMissing && isResolved;\n\tconst TagName = tagName || areaObject.tagName;\n\n\tconst onPatternSelect = async ( pattern ) => {\n\t\tawait editEntityRecord(\n\t\t\t'postType',\n\t\t\t'wp_template_part',\n\t\t\ttemplatePartId,\n\t\t\t{\n\t\t\t\tblocks: pattern.blocks,\n\t\t\t\tcontent: serialize( pattern.blocks ),\n\t\t\t}\n\t\t);\n\t\tcreateSuccessNotice(\n\t\t\tsprintf(\n\t\t\t\t/* translators: %s: template part title. */\n\t\t\t\t__( 'Template Part \"%s\" updated.' ),\n\t\t\t\ttitle || slug\n\t\t\t),\n\t\t\t{\n\t\t\t\ttype: 'snackbar',\n\t\t\t}\n\t\t);\n\t};\n\n\t// We don't want to render a missing state if we have any inner blocks.\n\t// A new template part is automatically created if we have any inner blocks but no entity.\n\tif (\n\t\t! hasInnerBlocks &&\n\t\t( ( slug && ! theme ) || ( slug && isMissing ) )\n\t) {\n\t\treturn (\n\t\t\t<TagName { ...blockProps }>\n\t\t\t\t<Warning>\n\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t/* translators: %s: Template part slug. */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Template part has been deleted or is unavailable: %s'\n\t\t\t\t\t\t),\n\t\t\t\t\t\tslug\n\t\t\t\t\t) }\n\t\t\t\t</Warning>\n\t\t\t</TagName>\n\t\t);\n\t}\n\n\tif ( isEntityAvailable && hasAlreadyRendered ) {\n\t\treturn (\n\t\t\t<TagName { ...blockProps }>\n\t\t\t\t<Warning>\n\t\t\t\t\t{ __( 'Block cannot be rendered inside itself.' ) }\n\t\t\t\t</Warning>\n\t\t\t</TagName>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<RecursionProvider uniqueId={ templatePartId }>\n\t\t\t\t{ isEntityAvailable &&\n\t\t\t\t\tonNavigateToEntityRecord &&\n\t\t\t\t\tcanUserEdit && (\n\t\t\t\t\t\t<BlockControls group=\"other\">\n\t\t\t\t\t\t\t<ToolbarButton\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: templatePartId,\n\t\t\t\t\t\t\t\t\t\tpostType: 'wp_template_part',\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ window?.__experimentalContentOnlyPatternInsertion\n\t\t\t\t\t\t\t\t\t? __( 'Edit section' )\n\t\t\t\t\t\t\t\t\t: __( 'Edit' ) }\n\t\t\t\t\t\t\t</ToolbarButton>\n\t\t\t\t\t\t</BlockControls>\n\t\t\t\t\t) }\n\t\t\t\t{ canUserEdit && (\n\t\t\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t\t\t<TemplatePartAdvancedControls\n\t\t\t\t\t\t\ttagName={ tagName }\n\t\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\t\tisEntityAvailable={ isEntityAvailable }\n\t\t\t\t\t\t\ttemplatePartId={ templatePartId }\n\t\t\t\t\t\t\tdefaultWrapper={ areaObject.tagName }\n\t\t\t\t\t\t\thasInnerBlocks={ hasInnerBlocks }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</InspectorControls>\n\t\t\t\t) }\n\t\t\t\t{ isPlaceholder && (\n\t\t\t\t\t<TagName { ...blockProps }>\n\t\t\t\t\t\t<TemplatePartPlaceholder\n\t\t\t\t\t\t\tarea={ attributes.area }\n\t\t\t\t\t\t\ttemplatePartId={ templatePartId }\n\t\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\t\tonOpenSelectionModal={ () =>\n\t\t\t\t\t\t\t\tsetIsTemplatePartSelectionOpen( true )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</TagName>\n\t\t\t\t) }\n\t\t\t\t<BlockSettingsMenuControls>\n\t\t\t\t\t{ ( { selectedClientIds } ) => {\n\t\t\t\t\t\t// Only enable for single selection that matches the current block.\n\t\t\t\t\t\t// Ensures menu item doesn't render multiple times.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t! (\n\t\t\t\t\t\t\t\tselectedClientIds.length === 1 &&\n\t\t\t\t\t\t\t\tclientId === selectedClientIds[ 0 ]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<ReplaceButton\n\t\t\t\t\t\t\t\t{ ...{\n\t\t\t\t\t\t\t\t\tisEntityAvailable,\n\t\t\t\t\t\t\t\t\tarea,\n\t\t\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\t\t\ttemplatePartId,\n\t\t\t\t\t\t\t\t\tisTemplatePartSelectionOpen,\n\t\t\t\t\t\t\t\t\tsetIsTemplatePartSelectionOpen,\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</BlockSettingsMenuControls>\n\n\t\t\t\t<InspectorControls group=\"settings\">\n\t\t\t\t\t<TemplatesList\n\t\t\t\t\t\tarea={ area }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tisEntityAvailable={ isEntityAvailable }\n\t\t\t\t\t\tonSelect={ ( pattern ) => onPatternSelect( pattern ) }\n\t\t\t\t\t/>\n\t\t\t\t</InspectorControls>\n\n\t\t\t\t{ isEntityAvailable && (\n\t\t\t\t\t<TemplatePartInnerBlocks\n\t\t\t\t\t\ttagName={ TagName }\n\t\t\t\t\t\tblockProps={ blockProps }\n\t\t\t\t\t\tpostId={ templatePartId }\n\t\t\t\t\t\thasInnerBlocks={ hasInnerBlocks }\n\t\t\t\t\t\tlayout={ layout }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ ! isPlaceholder && ! isResolved && (\n\t\t\t\t\t<TagName { ...blockProps }>\n\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t</TagName>\n\t\t\t\t) }\n\t\t\t</RecursionProvider>\n\t\t\t{ isTemplatePartSelectionOpen && (\n\t\t\t\t<Modal\n\t\t\t\t\toverlayClassName=\"block-editor-template-part__selection-modal\"\n\t\t\t\t\ttitle={ sprintf(\n\t\t\t\t\t\t// Translators: %s as template part area title (\"Header\", \"Footer\", etc.).\n\t\t\t\t\t\t__( 'Choose a %s' ),\n\t\t\t\t\t\tareaObject.label.toLowerCase()\n\t\t\t\t\t) }\n\t\t\t\t\tonRequestClose={ () =>\n\t\t\t\t\t\tsetIsTemplatePartSelectionOpen( false )\n\t\t\t\t\t}\n\t\t\t\t\tisFullScreen\n\t\t\t\t>\n\t\t\t\t\t<TemplatePartSelectionModal\n\t\t\t\t\t\ttemplatePartId={ templatePartId }\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\tarea={ area }\n\t\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\t\tonClose={ () =>\n\t\t\t\t\t\t\tsetIsTemplatePartSelectionOpen( false )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,WAAW,mBAAmB;AACvC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA,mCAAmC;AAAA,EACnC;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,IAAI,eAAe;AAC5B,SAAS,SAAS,iBAAiB;AACnC,SAAS,gBAAgB;AACzB,SAAS,SAAS,oBAAoB;AAKtC,OAAO,6BAA6B;AACpC,OAAO,gCAAgC;AACvC,SAAS,oCAAoC;AAC7C,OAAO,6BAA6B;AACpC,SAAS,4BAA4B;AACrC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA0CL,SA0KA,UA1KA,KA2KC,YA3KD;AAxCF,IAAM,kBAAkB,CAAE,UAAU,QAAS;AAQ7C,SAAS,oBAAoB;AAC5B,QAAM,6BACL,OAAO,WAAW,eAClB,OAAO,qCAAqC;AAC7C,SAAO,6BACJ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AgC,IAAK;AAAA;AAAA,MAEvC,GACD;AAAA,MAED,oBAAC,6BACE,WAAE,EAAE,kBAAkB,MAAO;AAG9B,YACC,EACC,kBAAkB,WAAW,KAC7B,aAAa,kBAAmB,CAAE,IAElC;AACD,iBAAO;AAAA,QACR;AAEA,eACC;AAAA,UAAC;AAAA;AAAA,YACE,GAAG;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YACD;AAAA;AAAA,QACD;AAAA,MAEF,GACD;AAAA,MAEA,oBAAC,qBAAkB,OAAM,YACxB;AAAA,QAAC;AAAA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,UAAW,CAAE,YAAa,gBAAiB,OAAQ;AAAA;AAAA,MACpD,GACD;AAAA,MAEE,qBACD;AAAA,QAAC;AAAA;AAAA,UACA,SAAU;AAAA,UACV;AAAA,UACA,QAAS;AAAA,UACT;AAAA,UACA;AAAA;AAAA,MACD;AAAA,MAEC,CAAE,iBAAiB,CAAE,cACtB,oBAAC,WAAU,GAAG,YACb,8BAAC,WAAQ,GACV;AAAA,OAEF;AAAA,IACE,+BACD;AAAA,MAAC;AAAA;AAAA,QACA,kBAAiB;AAAA,QACjB,OAAQ;AAAA;AAAA,UAEP,GAAI,aAAc;AAAA,UAClB,WAAW,MAAM,YAAY;AAAA,QAC9B;AAAA,QACA,gBAAiB,MAChB,+BAAgC,KAAM;AAAA,QAEvC,cAAY;AAAA,QAEZ;AAAA,UAAC;AAAA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA,SAAU,MACT,+BAAgC,KAAM;AAAA;AAAA,QAExC;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -14,9 +14,6 @@
|
|
|
14
14
|
"selector": "pre",
|
|
15
15
|
"__unstablePreserveWhiteSpace": true,
|
|
16
16
|
"role": "content"
|
|
17
|
-
},
|
|
18
|
-
"textAlign": {
|
|
19
|
-
"type": "string"
|
|
20
17
|
}
|
|
21
18
|
},
|
|
22
19
|
"supports": {
|
|
@@ -46,6 +43,7 @@
|
|
|
46
43
|
"fontSize": true,
|
|
47
44
|
"__experimentalFontFamily": true,
|
|
48
45
|
"lineHeight": true,
|
|
46
|
+
"textAlign": true,
|
|
49
47
|
"__experimentalFontStyle": true,
|
|
50
48
|
"__experimentalFontWeight": true,
|
|
51
49
|
"__experimentalLetterSpacing": true,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import clsx from "clsx";
|
|
3
3
|
import { RichText, useBlockProps } from "@wordpress/block-editor";
|
|
4
4
|
import migrateFontFamily from "../utils/migrate-font-family.mjs";
|
|
5
|
+
import migrateTextAlign from "../utils/migrate-text-align.mjs";
|
|
5
6
|
import { jsx } from "react/jsx-runtime";
|
|
6
7
|
var v1 = {
|
|
7
8
|
attributes: {
|
|
@@ -25,7 +26,8 @@ var v1 = {
|
|
|
25
26
|
value: content
|
|
26
27
|
}
|
|
27
28
|
);
|
|
28
|
-
}
|
|
29
|
+
},
|
|
30
|
+
migrate: migrateTextAlign
|
|
29
31
|
};
|
|
30
32
|
var v2 = {
|
|
31
33
|
attributes: {
|
|
@@ -62,12 +64,79 @@ var v2 = {
|
|
|
62
64
|
});
|
|
63
65
|
return /* @__PURE__ */ jsx("pre", { ...useBlockProps.save({ className }), children: /* @__PURE__ */ jsx(RichText.Content, { value: content }) });
|
|
64
66
|
},
|
|
65
|
-
migrate
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
migrate(attributes) {
|
|
68
|
+
return migrateTextAlign(migrateFontFamily(attributes));
|
|
69
|
+
},
|
|
70
|
+
isEligible({ style, textAlign }) {
|
|
71
|
+
return style?.typography?.fontFamily || !!textAlign;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var v3 = {
|
|
75
|
+
attributes: {
|
|
76
|
+
content: {
|
|
77
|
+
type: "rich-text",
|
|
78
|
+
source: "rich-text",
|
|
79
|
+
selector: "pre",
|
|
80
|
+
__unstablePreserveWhiteSpace: true,
|
|
81
|
+
role: "content"
|
|
82
|
+
},
|
|
83
|
+
textAlign: {
|
|
84
|
+
type: "string"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
supports: {
|
|
88
|
+
anchor: true,
|
|
89
|
+
background: {
|
|
90
|
+
backgroundImage: true,
|
|
91
|
+
backgroundSize: true
|
|
92
|
+
},
|
|
93
|
+
color: {
|
|
94
|
+
gradients: true,
|
|
95
|
+
link: true
|
|
96
|
+
},
|
|
97
|
+
dimensions: {
|
|
98
|
+
minHeight: true
|
|
99
|
+
},
|
|
100
|
+
typography: {
|
|
101
|
+
fontSize: true,
|
|
102
|
+
__experimentalFontFamily: true,
|
|
103
|
+
lineHeight: true,
|
|
104
|
+
__experimentalFontStyle: true,
|
|
105
|
+
__experimentalFontWeight: true,
|
|
106
|
+
__experimentalLetterSpacing: true,
|
|
107
|
+
__experimentalTextTransform: true,
|
|
108
|
+
__experimentalTextDecoration: true,
|
|
109
|
+
__experimentalWritingMode: true
|
|
110
|
+
},
|
|
111
|
+
spacing: {
|
|
112
|
+
margin: true,
|
|
113
|
+
padding: true
|
|
114
|
+
},
|
|
115
|
+
__experimentalBorder: {
|
|
116
|
+
radius: true,
|
|
117
|
+
width: true,
|
|
118
|
+
color: true,
|
|
119
|
+
style: true
|
|
120
|
+
},
|
|
121
|
+
interactivity: {
|
|
122
|
+
clientNavigation: true
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
save({ attributes }) {
|
|
126
|
+
const { textAlign, content } = attributes;
|
|
127
|
+
const className = clsx({
|
|
128
|
+
[`has-text-align-${textAlign}`]: textAlign
|
|
129
|
+
});
|
|
130
|
+
return /* @__PURE__ */ jsx("pre", { ...useBlockProps.save({ className }), children: /* @__PURE__ */ jsx(RichText.Content, { value: content }) });
|
|
131
|
+
},
|
|
132
|
+
migrate: migrateTextAlign,
|
|
133
|
+
isEligible(attributes) {
|
|
134
|
+
return !!attributes.textAlign || !!attributes.className?.match(
|
|
135
|
+
/\bhas-text-align-(left|center|right)\b/
|
|
136
|
+
);
|
|
68
137
|
}
|
|
69
138
|
};
|
|
70
|
-
var deprecated_default = [v2, v1];
|
|
139
|
+
var deprecated_default = [v3, v2, v1];
|
|
71
140
|
export {
|
|
72
141
|
deprecated_default as default
|
|
73
142
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/verse/deprecated.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport migrateFontFamily from '../utils/migrate-font-family';\n\nconst v1 = {\n\tattributes: {\n\t\tcontent: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'pre',\n\t\t\tdefault: '',\n\t\t},\n\t\ttextAlign: {\n\t\t\ttype: 'string',\n\t\t},\n\t},\n\tsave( { attributes } ) {\n\t\tconst { textAlign, content } = attributes;\n\n\t\treturn (\n\t\t\t<RichText.Content\n\t\t\t\ttagName=\"pre\"\n\t\t\t\tstyle={ { textAlign } }\n\t\t\t\tvalue={ content }\n\t\t\t/>\n\t\t);\n\t},\n};\n\nconst v2 = {\n\tattributes: {\n\t\tcontent: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'pre',\n\t\t\tdefault: '',\n\t\t\t__unstablePreserveWhiteSpace: true,\n\t\t\trole: 'content',\n\t\t},\n\t\ttextAlign: {\n\t\t\ttype: 'string',\n\t\t},\n\t},\n\tsupports: {\n\t\tanchor: true,\n\t\tcolor: {\n\t\t\tgradients: true,\n\t\t\tlink: true,\n\t\t},\n\t\ttypography: {\n\t\t\tfontSize: true,\n\t\t\t__experimentalFontFamily: true,\n\t\t},\n\t\tspacing: {\n\t\t\tpadding: true,\n\t\t},\n\t},\n\tsave( { attributes } ) {\n\t\tconst { textAlign, content } = attributes;\n\n\t\tconst className = clsx( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} );\n\n\t\treturn (\n\t\t\t<pre { ...useBlockProps.save( { className } ) }>\n\t\t\t\t<RichText.Content value={ content } />\n\t\t\t</pre>\n\t\t);\n\t},\n\tmigrate
|
|
5
|
-
"mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,UAAU,qBAAqB;AAKxC,OAAO,uBAAuB;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport migrateFontFamily from '../utils/migrate-font-family';\nimport migrateTextAlign from '../utils/migrate-text-align';\n\nconst v1 = {\n\tattributes: {\n\t\tcontent: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'pre',\n\t\t\tdefault: '',\n\t\t},\n\t\ttextAlign: {\n\t\t\ttype: 'string',\n\t\t},\n\t},\n\tsave( { attributes } ) {\n\t\tconst { textAlign, content } = attributes;\n\n\t\treturn (\n\t\t\t<RichText.Content\n\t\t\t\ttagName=\"pre\"\n\t\t\t\tstyle={ { textAlign } }\n\t\t\t\tvalue={ content }\n\t\t\t/>\n\t\t);\n\t},\n\tmigrate: migrateTextAlign,\n};\n\nconst v2 = {\n\tattributes: {\n\t\tcontent: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'pre',\n\t\t\tdefault: '',\n\t\t\t__unstablePreserveWhiteSpace: true,\n\t\t\trole: 'content',\n\t\t},\n\t\ttextAlign: {\n\t\t\ttype: 'string',\n\t\t},\n\t},\n\tsupports: {\n\t\tanchor: true,\n\t\tcolor: {\n\t\t\tgradients: true,\n\t\t\tlink: true,\n\t\t},\n\t\ttypography: {\n\t\t\tfontSize: true,\n\t\t\t__experimentalFontFamily: true,\n\t\t},\n\t\tspacing: {\n\t\t\tpadding: true,\n\t\t},\n\t},\n\tsave( { attributes } ) {\n\t\tconst { textAlign, content } = attributes;\n\n\t\tconst className = clsx( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} );\n\n\t\treturn (\n\t\t\t<pre { ...useBlockProps.save( { className } ) }>\n\t\t\t\t<RichText.Content value={ content } />\n\t\t\t</pre>\n\t\t);\n\t},\n\tmigrate( attributes ) {\n\t\treturn migrateTextAlign( migrateFontFamily( attributes ) );\n\t},\n\tisEligible( { style, textAlign } ) {\n\t\treturn style?.typography?.fontFamily || !! textAlign;\n\t},\n};\n\nconst v3 = {\n\tattributes: {\n\t\tcontent: {\n\t\t\ttype: 'rich-text',\n\t\t\tsource: 'rich-text',\n\t\t\tselector: 'pre',\n\t\t\t__unstablePreserveWhiteSpace: true,\n\t\t\trole: 'content',\n\t\t},\n\t\ttextAlign: {\n\t\t\ttype: 'string',\n\t\t},\n\t},\n\tsupports: {\n\t\tanchor: true,\n\t\tbackground: {\n\t\t\tbackgroundImage: true,\n\t\t\tbackgroundSize: true,\n\t\t},\n\t\tcolor: {\n\t\t\tgradients: true,\n\t\t\tlink: true,\n\t\t},\n\t\tdimensions: {\n\t\t\tminHeight: true,\n\t\t},\n\t\ttypography: {\n\t\t\tfontSize: true,\n\t\t\t__experimentalFontFamily: true,\n\t\t\tlineHeight: true,\n\t\t\t__experimentalFontStyle: true,\n\t\t\t__experimentalFontWeight: true,\n\t\t\t__experimentalLetterSpacing: true,\n\t\t\t__experimentalTextTransform: true,\n\t\t\t__experimentalTextDecoration: true,\n\t\t\t__experimentalWritingMode: true,\n\t\t},\n\t\tspacing: {\n\t\t\tmargin: true,\n\t\t\tpadding: true,\n\t\t},\n\t\t__experimentalBorder: {\n\t\t\tradius: true,\n\t\t\twidth: true,\n\t\t\tcolor: true,\n\t\t\tstyle: true,\n\t\t},\n\t\tinteractivity: {\n\t\t\tclientNavigation: true,\n\t\t},\n\t},\n\tsave( { attributes } ) {\n\t\tconst { textAlign, content } = attributes;\n\n\t\tconst className = clsx( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} );\n\n\t\treturn (\n\t\t\t<pre { ...useBlockProps.save( { className } ) }>\n\t\t\t\t<RichText.Content value={ content } />\n\t\t\t</pre>\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};\n\n/**\n * New deprecations need to be placed first\n * for them to have higher priority.\n *\n * Old deprecations may need to be updated as well.\n *\n * See block-deprecation.md\n */\nexport default [ v3, v2, v1 ];\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,UAAU,qBAAqB;AAKxC,OAAO,uBAAuB;AAC9B,OAAO,sBAAsB;AAkB1B;AAhBH,IAAM,KAAK;AAAA,EACV,YAAY;AAAA,IACX,SAAS;AAAA,MACR,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,UAAU;AAAA,MACV,SAAS;AAAA,IACV;AAAA,IACA,WAAW;AAAA,MACV,MAAM;AAAA,IACP;AAAA,EACD;AAAA,EACA,KAAM,EAAE,WAAW,GAAI;AACtB,UAAM,EAAE,WAAW,QAAQ,IAAI;AAE/B,WACC;AAAA,MAAC,SAAS;AAAA,MAAT;AAAA,QACA,SAAQ;AAAA,QACR,OAAQ,EAAE,UAAU;AAAA,QACpB,OAAQ;AAAA;AAAA,IACT;AAAA,EAEF;AAAA,EACA,SAAS;AACV;AAEA,IAAM,KAAK;AAAA,EACV,YAAY;AAAA,IACX,SAAS;AAAA,MACR,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,UAAU;AAAA,MACV,SAAS;AAAA,MACT,8BAA8B;AAAA,MAC9B,MAAM;AAAA,IACP;AAAA,IACA,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AyB;AAAA,MACzB,0BAA0B;AAAA,MAC1B,6BAA6B;AAAA,MAC7B,6BAA6B;AAAA,MAC7B,8BAA8B;AAAA,MAC9B,2BAA2B;AAAA,IAC5B;AAAA,IACA,SAAS;AAAA,MACR,QAAQ;AAAA,MACR,SAAS;AAAA,IACV;AAAA,IACA,sBAAsB;AAAA,MACrB,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,OAAO;AAAA,MACP,OAAO;AAAA,IACR;AAAA,IACA,eAAe;AAAA,MACd,kBAAkB;AAAA,IACnB;AAAA,EACD;AAAA,EACA,KAAM,EAAE,WAAW,GAAI;AACtB,UAAM,EAAE,WAAW,QAAQ,IAAI;AAE/B,UAAM,YAAY,KAAM;AAAA,MACvB,CAAE,kBAAmB,SAAU,EAAG,GAAG;AAAA,IACtC,CAAE;AAEF,WACC,oBAAC,SAAM,GAAG,cAAc,KAAM,EAAE,UAAU,CAAE,GAC3C,8BAAC,SAAS,SAAT,EAAiB,OAAQ,SAAU,GACrC;AAAA,EAEF;AAAA,EACA,SAAS;AAAA,EACT,WAAY,YAAa;AACxB,WACC,CAAC,CAAE,WAAW,aACd,CAAC,CAAE,WAAW,WAAW;AAAA,MACxB;AAAA,IACD;AAAA,EAEF;AACD;AAUA,IAAO,qBAAQ,CAAE,IAAI,IAAI,EAAG;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,62 +1,42 @@
|
|
|
1
1
|
// packages/block-library/src/verse/edit.js
|
|
2
|
-
import clsx from "clsx";
|
|
3
2
|
import { __ } from "@wordpress/i18n";
|
|
4
|
-
import {
|
|
5
|
-
RichText,
|
|
6
|
-
BlockControls,
|
|
7
|
-
AlignmentToolbar,
|
|
8
|
-
useBlockProps
|
|
9
|
-
} from "@wordpress/block-editor";
|
|
3
|
+
import { RichText, useBlockProps } from "@wordpress/block-editor";
|
|
10
4
|
import { createBlock, getDefaultBlockName } from "@wordpress/blocks";
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const { textAlign, content } = attributes;
|
|
21
|
-
const blockProps = useBlockProps({
|
|
22
|
-
className: clsx({
|
|
23
|
-
[`has-text-align-${textAlign}`]: textAlign
|
|
24
|
-
}),
|
|
5
|
+
import useDeprecatedTextAlign from "../utils/deprecated-text-align-attributes.mjs";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
function VerseEdit(props) {
|
|
8
|
+
const {
|
|
9
|
+
attributes,
|
|
10
|
+
setAttributes,
|
|
11
|
+
mergeBlocks,
|
|
12
|
+
onRemove,
|
|
13
|
+
insertBlocksAfter,
|
|
25
14
|
style
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
onRemove,
|
|
52
|
-
onMerge: mergeBlocks,
|
|
53
|
-
textAlign,
|
|
54
|
-
...blockProps,
|
|
55
|
-
__unstablePastePlainText: true,
|
|
56
|
-
__unstableOnSplitAtDoubleLineEnd: () => insertBlocksAfter(createBlock(getDefaultBlockName()))
|
|
57
|
-
}
|
|
58
|
-
)
|
|
59
|
-
] });
|
|
15
|
+
} = props;
|
|
16
|
+
const { content } = attributes;
|
|
17
|
+
useDeprecatedTextAlign(props);
|
|
18
|
+
const blockProps = useBlockProps({ style });
|
|
19
|
+
return /* @__PURE__ */ jsx(
|
|
20
|
+
RichText,
|
|
21
|
+
{
|
|
22
|
+
tagName: "pre",
|
|
23
|
+
identifier: "content",
|
|
24
|
+
preserveWhiteSpace: true,
|
|
25
|
+
value: content,
|
|
26
|
+
onChange: (nextContent) => {
|
|
27
|
+
setAttributes({
|
|
28
|
+
content: nextContent
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
"aria-label": __("Verse text"),
|
|
32
|
+
placeholder: __("Write verse\u2026"),
|
|
33
|
+
onRemove,
|
|
34
|
+
onMerge: mergeBlocks,
|
|
35
|
+
...blockProps,
|
|
36
|
+
__unstablePastePlainText: true,
|
|
37
|
+
__unstableOnSplitAtDoubleLineEnd: () => insertBlocksAfter(createBlock(getDefaultBlockName()))
|
|
38
|
+
}
|
|
39
|
+
);
|
|
60
40
|
}
|
|
61
41
|
export {
|
|
62
42
|
VerseEdit as default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/verse/edit.js"],
|
|
4
|
-
"sourcesContent": ["/**\n *
|
|
5
|
-
"mappings": ";AAGA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { RichText, useBlockProps } from '@wordpress/block-editor';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport useDeprecatedTextAlign from '../utils/deprecated-text-align-attributes';\n\nexport default function VerseEdit( props ) {\n\tconst {\n\t\tattributes,\n\t\tsetAttributes,\n\t\tmergeBlocks,\n\t\tonRemove,\n\t\tinsertBlocksAfter,\n\t\tstyle,\n\t} = props;\n\tconst { content } = attributes;\n\tuseDeprecatedTextAlign( props );\n\tconst blockProps = useBlockProps( { style } );\n\n\treturn (\n\t\t<RichText\n\t\t\ttagName=\"pre\"\n\t\t\tidentifier=\"content\"\n\t\t\tpreserveWhiteSpace\n\t\t\tvalue={ content }\n\t\t\tonChange={ ( nextContent ) => {\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tcontent: nextContent,\n\t\t\t\t} );\n\t\t\t} }\n\t\t\taria-label={ __( 'Verse text' ) }\n\t\t\tplaceholder={ __( 'Write verse\u2026' ) }\n\t\t\tonRemove={ onRemove }\n\t\t\tonMerge={ mergeBlocks }\n\t\t\t{ ...blockProps }\n\t\t\t__unstablePastePlainText\n\t\t\t__unstableOnSplitAtDoubleLineEnd={ () =>\n\t\t\t\tinsertBlocksAfter( createBlock( getDefaultBlockName() ) )\n\t\t\t}\n\t\t/>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,UAAU,qBAAqB;AACxC,SAAS,aAAa,2BAA2B;AAKjD,OAAO,4BAA4B;AAgBjC;AAda,SAAR,UAA4B,OAAQ;AAC1C,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,IAAI;AACJ,QAAM,EAAE,QAAQ,IAAI;AACpB,yBAAwB,KAAM;AAC9B,QAAM,aAAa,cAAe,EAAE,MAAM,CAAE;AAE5C,SACC;AAAA,IAAC;AAAA;AAAA,MACA,SAAQ;AAAA,MACR,YAAW;AAAA,MACX,oBAAkB;AAAA,MAClB,OAAQ;AAAA,MACR,UAAW,CAAE,gBAAiB;AAC7B,sBAAe;AAAA,UACd,SAAS;AAAA,QACV,CAAE;AAAA,MACH;AAAA,MACA,cAAa,GAAI,YAAa;AAAA,MAC9B,aAAc,GAAI,mBAAe;AAAA,MACjC;AAAA,MACA,SAAU;AAAA,MACR,GAAG;AAAA,MACL,0BAAwB;AAAA,MACxB,kCAAmC,MAClC,kBAAmB,YAAa,oBAAoB,CAAE,CAAE;AAAA;AAAA,EAE1D;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
// packages/block-library/src/verse/save.js
|
|
2
|
-
import clsx from "clsx";
|
|
3
2
|
import { RichText, useBlockProps } from "@wordpress/block-editor";
|
|
4
3
|
import { jsx } from "react/jsx-runtime";
|
|
5
4
|
function save({ attributes }) {
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
[`has-text-align-${textAlign}`]: textAlign
|
|
9
|
-
});
|
|
10
|
-
return /* @__PURE__ */ jsx("pre", { ...useBlockProps.save({ className }), children: /* @__PURE__ */ jsx(RichText.Content, { value: content }) });
|
|
5
|
+
const { content } = attributes;
|
|
6
|
+
return /* @__PURE__ */ jsx("pre", { ...useBlockProps.save(), children: /* @__PURE__ */ jsx(RichText.Content, { value: content }) });
|
|
11
7
|
}
|
|
12
8
|
export {
|
|
13
9
|
save as default
|