@wordpress/block-library 9.33.5 → 9.33.7
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/heading/index.js +3 -1
- package/build/heading/index.js.map +3 -3
- package/build/heading/variations.js +53 -0
- package/build/heading/variations.js.map +7 -0
- package/build/navigation-link/edit.js +25 -10
- package/build/navigation-link/edit.js.map +2 -2
- package/build/navigation-link/link-ui/index.js +8 -3
- package/build/navigation-link/link-ui/index.js.map +2 -2
- package/build/navigation-link/shared/controls.js +76 -21
- package/build/navigation-link/shared/controls.js.map +2 -2
- package/build/navigation-link/shared/use-entity-binding.js +31 -2
- package/build/navigation-link/shared/use-entity-binding.js.map +3 -3
- package/build/paragraph/index.js +3 -1
- package/build/paragraph/index.js.map +3 -3
- package/build/paragraph/variations.js +55 -0
- package/build/paragraph/variations.js.map +7 -0
- package/build-module/heading/index.js +3 -1
- package/build-module/heading/index.js.map +2 -2
- package/build-module/heading/variations.js +33 -0
- package/build-module/heading/variations.js.map +7 -0
- package/build-module/navigation-link/edit.js +25 -10
- package/build-module/navigation-link/edit.js.map +2 -2
- package/build-module/navigation-link/link-ui/index.js +8 -3
- package/build-module/navigation-link/link-ui/index.js.map +2 -2
- package/build-module/navigation-link/shared/controls.js +77 -22
- package/build-module/navigation-link/shared/controls.js.map +2 -2
- package/build-module/navigation-link/shared/use-entity-binding.js +35 -3
- package/build-module/navigation-link/shared/use-entity-binding.js.map +2 -2
- package/build-module/paragraph/index.js +3 -1
- package/build-module/paragraph/index.js.map +2 -2
- package/build-module/paragraph/variations.js +35 -0
- package/build-module/paragraph/variations.js.map +7 -0
- package/build-style/accordion-heading/style-rtl.css +19 -3
- package/build-style/accordion-heading/style.css +19 -3
- package/build-style/accordion-panel/style-rtl.css +4 -1
- package/build-style/accordion-panel/style.css +4 -1
- package/build-style/editor-rtl.css +7 -0
- package/build-style/editor.css +7 -0
- package/build-style/navigation-link/editor-rtl.css +7 -0
- package/build-style/navigation-link/editor.css +7 -0
- package/build-style/style-rtl.css +23 -4
- package/build-style/style.css +23 -4
- package/package.json +11 -11
- package/src/accordion-heading/style.scss +40 -7
- package/src/accordion-panel/style.scss +6 -1
- package/src/heading/index.js +2 -0
- package/src/heading/variations.js +37 -0
- package/src/navigation-link/edit.js +44 -13
- package/src/navigation-link/editor.scss +7 -0
- package/src/navigation-link/link-ui/index.js +9 -8
- package/src/navigation-link/shared/controls.js +123 -25
- package/src/navigation-link/shared/test/controls.js +19 -9
- package/src/navigation-link/shared/test/use-entity-binding.js +14 -1
- package/src/navigation-link/shared/use-entity-binding.js +57 -9
- package/src/paragraph/index.js +2 -0
- package/src/paragraph/variations.js +39 -0
|
@@ -20,6 +20,7 @@ import { plus } from "@wordpress/icons";
|
|
|
20
20
|
import { useInstanceId } from "@wordpress/compose";
|
|
21
21
|
import { LinkUIPageCreator } from "./page-creator";
|
|
22
22
|
import LinkUIBlockInserter from "./block-inserter";
|
|
23
|
+
import { useEntityBinding } from "../shared/use-entity-binding";
|
|
23
24
|
function getSuggestionsQuery(type, kind) {
|
|
24
25
|
switch (type) {
|
|
25
26
|
case "post":
|
|
@@ -50,7 +51,8 @@ function getSuggestionsQuery(type, kind) {
|
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
function UnforwardedLinkUI(props, ref) {
|
|
53
|
-
const { label, url, opensInNewTab, type, kind, id
|
|
54
|
+
const { label, url, opensInNewTab, type, kind, id } = props.link;
|
|
55
|
+
const { clientId } = props;
|
|
54
56
|
const postType = type || "page";
|
|
55
57
|
const [addingBlock, setAddingBlock] = useState(false);
|
|
56
58
|
const [addingPage, setAddingPage] = useState(false);
|
|
@@ -60,7 +62,10 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
60
62
|
kind: "postType",
|
|
61
63
|
name: postType
|
|
62
64
|
});
|
|
63
|
-
const
|
|
65
|
+
const { isBoundEntityAvailable } = useEntityBinding({
|
|
66
|
+
clientId,
|
|
67
|
+
attributes: props.link
|
|
68
|
+
});
|
|
64
69
|
const link = useMemo(
|
|
65
70
|
() => ({
|
|
66
71
|
url,
|
|
@@ -121,7 +126,7 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
121
126
|
onChange: props.onChange,
|
|
122
127
|
onRemove: props.onRemove,
|
|
123
128
|
onCancel: props.onCancel,
|
|
124
|
-
handleEntities:
|
|
129
|
+
handleEntities: isBoundEntityAvailable,
|
|
125
130
|
renderControlBottom: () => {
|
|
126
131
|
if (link?.url?.length) {
|
|
127
132
|
return null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/navigation-link/link-ui/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport {\n\tPopover,\n\tButton,\n\tVisuallyHidden,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { LinkControl, useBlockEditingMode } from '@wordpress/block-editor';\nimport {\n\tuseMemo,\n\tuseState,\n\tuseRef,\n\tuseEffect,\n\tforwardRef,\n} from '@wordpress/element';\nimport { useResourcePermissions } from '@wordpress/core-data';\nimport { plus } from '@wordpress/icons';\nimport { useInstanceId } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { LinkUIPageCreator } from './page-creator';\nimport LinkUIBlockInserter from './block-inserter';\n\n/**\n * Given the Link block's type attribute, return the query params to give to\n * /wp/v2/search.\n *\n * @param {string} type Link block's type attribute.\n * @param {string} kind Link block's entity of kind (post-type|taxonomy)\n * @return {{ type?: string, subtype?: string }} Search query params.\n */\nexport function getSuggestionsQuery( type, kind ) {\n\tswitch ( type ) {\n\t\tcase 'post':\n\t\tcase 'page':\n\t\t\treturn { type: 'post', subtype: type };\n\t\tcase 'category':\n\t\t\treturn { type: 'term', subtype: 'category' };\n\t\tcase 'tag':\n\t\t\treturn { type: 'term', subtype: 'post_tag' };\n\t\tcase 'post_format':\n\t\t\treturn { type: 'post-format' };\n\t\tdefault:\n\t\t\tif ( kind === 'taxonomy' ) {\n\t\t\t\treturn { type: 'term', subtype: type };\n\t\t\t}\n\t\t\tif ( kind === 'post-type' ) {\n\t\t\t\treturn { type: 'post', subtype: type };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t// for custom link which has no type\n\t\t\t\t// always show pages as initial suggestions\n\t\t\t\tinitialSuggestionsSearchOptions: {\n\t\t\t\t\ttype: 'post',\n\t\t\t\t\tsubtype: 'page',\n\t\t\t\t\tperPage: 20,\n\t\t\t\t},\n\t\t\t};\n\t}\n}\n\nfunction UnforwardedLinkUI( props, ref ) {\n\tconst { label, url, opensInNewTab, type, kind, id
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport {\n\tPopover,\n\tButton,\n\tVisuallyHidden,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { LinkControl, useBlockEditingMode } from '@wordpress/block-editor';\nimport {\n\tuseMemo,\n\tuseState,\n\tuseRef,\n\tuseEffect,\n\tforwardRef,\n} from '@wordpress/element';\nimport { useResourcePermissions } from '@wordpress/core-data';\nimport { plus } from '@wordpress/icons';\nimport { useInstanceId } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { LinkUIPageCreator } from './page-creator';\nimport LinkUIBlockInserter from './block-inserter';\nimport { useEntityBinding } from '../shared/use-entity-binding';\n\n/**\n * Given the Link block's type attribute, return the query params to give to\n * /wp/v2/search.\n *\n * @param {string} type Link block's type attribute.\n * @param {string} kind Link block's entity of kind (post-type|taxonomy)\n * @return {{ type?: string, subtype?: string }} Search query params.\n */\nexport function getSuggestionsQuery( type, kind ) {\n\tswitch ( type ) {\n\t\tcase 'post':\n\t\tcase 'page':\n\t\t\treturn { type: 'post', subtype: type };\n\t\tcase 'category':\n\t\t\treturn { type: 'term', subtype: 'category' };\n\t\tcase 'tag':\n\t\t\treturn { type: 'term', subtype: 'post_tag' };\n\t\tcase 'post_format':\n\t\t\treturn { type: 'post-format' };\n\t\tdefault:\n\t\t\tif ( kind === 'taxonomy' ) {\n\t\t\t\treturn { type: 'term', subtype: type };\n\t\t\t}\n\t\t\tif ( kind === 'post-type' ) {\n\t\t\t\treturn { type: 'post', subtype: type };\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t// for custom link which has no type\n\t\t\t\t// always show pages as initial suggestions\n\t\t\t\tinitialSuggestionsSearchOptions: {\n\t\t\t\t\ttype: 'post',\n\t\t\t\t\tsubtype: 'page',\n\t\t\t\t\tperPage: 20,\n\t\t\t\t},\n\t\t\t};\n\t}\n}\n\nfunction UnforwardedLinkUI( props, ref ) {\n\tconst { label, url, opensInNewTab, type, kind, id } = props.link;\n\tconst { clientId } = props;\n\tconst postType = type || 'page';\n\n\tconst [ addingBlock, setAddingBlock ] = useState( false );\n\tconst [ addingPage, setAddingPage ] = useState( false );\n\tconst [ focusAddBlockButton, setFocusAddBlockButton ] = useState( false );\n\tconst [ focusAddPageButton, setFocusAddPageButton ] = useState( false );\n\tconst permissions = useResourcePermissions( {\n\t\tkind: 'postType',\n\t\tname: postType,\n\t} );\n\n\t// Use the entity binding hook to get binding status\n\tconst { isBoundEntityAvailable } = useEntityBinding( {\n\t\tclientId,\n\t\tattributes: props.link,\n\t} );\n\n\t// Memoize link value to avoid overriding the LinkControl's internal state.\n\t// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.\n\tconst link = useMemo(\n\t\t() => ( {\n\t\t\turl,\n\t\t\topensInNewTab,\n\t\t\ttitle: label && stripHTML( label ),\n\t\t\tkind,\n\t\t\ttype,\n\t\t\tid,\n\t\t} ),\n\t\t[ label, opensInNewTab, url, kind, type, id ]\n\t);\n\n\tconst handlePageCreated = ( pageLink ) => {\n\t\t// Set the new page as the current link\n\t\tprops.onChange( pageLink );\n\t\t// Return to main Link UI\n\t\tsetAddingPage( false );\n\t};\n\n\tconst dialogTitleId = useInstanceId(\n\t\tLinkUI,\n\t\t'link-ui-link-control__title'\n\t);\n\tconst dialogDescriptionId = useInstanceId(\n\t\tLinkUI,\n\t\t'link-ui-link-control__description'\n\t);\n\n\tconst blockEditingMode = useBlockEditingMode();\n\n\treturn (\n\t\t<Popover\n\t\t\tref={ ref }\n\t\t\tplacement=\"bottom\"\n\t\t\tonClose={ props.onClose }\n\t\t\tanchor={ props.anchor }\n\t\t\tshift\n\t\t>\n\t\t\t{ ! addingBlock && ! addingPage && (\n\t\t\t\t<div\n\t\t\t\t\trole=\"dialog\"\n\t\t\t\t\taria-labelledby={ dialogTitleId }\n\t\t\t\t\taria-describedby={ dialogDescriptionId }\n\t\t\t\t>\n\t\t\t\t\t<VisuallyHidden>\n\t\t\t\t\t\t<h2 id={ dialogTitleId }>{ __( 'Add link' ) }</h2>\n\n\t\t\t\t\t\t<p id={ dialogDescriptionId }>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'Search for and add a link to your Navigation.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</p>\n\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t<LinkControl\n\t\t\t\t\t\thasTextControl\n\t\t\t\t\t\thasRichPreviews\n\t\t\t\t\t\tvalue={ link }\n\t\t\t\t\t\tshowInitialSuggestions\n\t\t\t\t\t\twithCreateSuggestion={ false }\n\t\t\t\t\t\tnoDirectEntry={ !! type }\n\t\t\t\t\t\tnoURLSuggestion={ !! type }\n\t\t\t\t\t\tsuggestionsQuery={ getSuggestionsQuery( type, kind ) }\n\t\t\t\t\t\tonChange={ props.onChange }\n\t\t\t\t\t\tonRemove={ props.onRemove }\n\t\t\t\t\t\tonCancel={ props.onCancel }\n\t\t\t\t\t\thandleEntities={ isBoundEntityAvailable }\n\t\t\t\t\t\trenderControlBottom={ () => {\n\t\t\t\t\t\t\t// Don't show the tools when there is submitted link (preview state).\n\t\t\t\t\t\t\tif ( link?.url?.length ) {\n\t\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<LinkUITools\n\t\t\t\t\t\t\t\t\tfocusAddBlockButton={ focusAddBlockButton }\n\t\t\t\t\t\t\t\t\tfocusAddPageButton={ focusAddPageButton }\n\t\t\t\t\t\t\t\t\tsetAddingBlock={ () => {\n\t\t\t\t\t\t\t\t\t\tsetAddingBlock( true );\n\t\t\t\t\t\t\t\t\t\tsetFocusAddBlockButton( false );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tsetAddingPage={ () => {\n\t\t\t\t\t\t\t\t\t\tsetAddingPage( true );\n\t\t\t\t\t\t\t\t\t\tsetFocusAddPageButton( false );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tcanAddPage={\n\t\t\t\t\t\t\t\t\t\tpermissions?.canCreate &&\n\t\t\t\t\t\t\t\t\t\ttype === 'page'\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tcanAddBlock={\n\t\t\t\t\t\t\t\t\t\tblockEditingMode === 'default'\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} }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ addingBlock && (\n\t\t\t\t<LinkUIBlockInserter\n\t\t\t\t\tclientId={ props.clientId }\n\t\t\t\t\tonBack={ () => {\n\t\t\t\t\t\tsetAddingBlock( false );\n\t\t\t\t\t\tsetFocusAddBlockButton( true );\n\t\t\t\t\t\tsetFocusAddPageButton( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonBlockInsert={ props?.onBlockInsert }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t{ addingPage && (\n\t\t\t\t<LinkUIPageCreator\n\t\t\t\t\tpostType={ postType }\n\t\t\t\t\tonBack={ () => {\n\t\t\t\t\t\tsetAddingPage( false );\n\t\t\t\t\t\tsetFocusAddPageButton( true );\n\t\t\t\t\t\tsetFocusAddBlockButton( false );\n\t\t\t\t\t} }\n\t\t\t\t\tonPageCreated={ handlePageCreated }\n\t\t\t\t\tinitialTitle={ link?.url || '' }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Popover>\n\t);\n}\n\nexport const LinkUI = forwardRef( UnforwardedLinkUI );\n\nconst LinkUITools = ( {\n\tsetAddingBlock,\n\tsetAddingPage,\n\tfocusAddBlockButton,\n\tfocusAddPageButton,\n\tcanAddPage,\n\tcanAddBlock,\n} ) => {\n\tconst blockInserterAriaRole = 'listbox';\n\tconst addBlockButtonRef = useRef();\n\tconst addPageButtonRef = useRef();\n\n\t// Focus the add block button when the popover is opened.\n\tuseEffect( () => {\n\t\tif ( focusAddBlockButton ) {\n\t\t\taddBlockButtonRef.current?.focus();\n\t\t}\n\t}, [ focusAddBlockButton ] );\n\n\t// Focus the add page button when the popover is opened.\n\tuseEffect( () => {\n\t\tif ( focusAddPageButton ) {\n\t\t\taddPageButtonRef.current?.focus();\n\t\t}\n\t}, [ focusAddPageButton ] );\n\n\t// Don't render anything if neither button should be shown\n\tif ( ! canAddPage && ! canAddBlock ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<VStack spacing={ 0 } className=\"link-ui-tools\">\n\t\t\t{ canAddPage && (\n\t\t\t\t<Button\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tref={ addPageButtonRef }\n\t\t\t\t\ticon={ plus }\n\t\t\t\t\tonClick={ ( e ) => {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\tsetAddingPage( true );\n\t\t\t\t\t} }\n\t\t\t\t\taria-haspopup={ blockInserterAriaRole }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Create page' ) }\n\t\t\t\t</Button>\n\t\t\t) }\n\t\t\t{ canAddBlock && (\n\t\t\t\t<Button\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\tref={ addBlockButtonRef }\n\t\t\t\t\ticon={ plus }\n\t\t\t\t\tonClick={ ( e ) => {\n\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\tsetAddingBlock( true );\n\t\t\t\t\t} }\n\t\t\t\t\taria-haspopup={ blockInserterAriaRole }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Add block' ) }\n\t\t\t\t</Button>\n\t\t\t) }\n\t\t</VStack>\n\t);\n};\n\nexport default LinkUITools;\n"],
|
|
5
|
+
"mappings": "AAsIK,SACC,KADD;AAnIL,SAAS,uBAAuB,iBAAiB;AACjD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA,wBAAwB;AAAA,OAClB;AACP,SAAS,UAAU;AACnB,SAAS,aAAa,2BAA2B;AACjD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,8BAA8B;AACvC,SAAS,YAAY;AACrB,SAAS,qBAAqB;AAK9B,SAAS,yBAAyB;AAClC,OAAO,yBAAyB;AAChC,SAAS,wBAAwB;AAU1B,SAAS,oBAAqB,MAAM,MAAO;AACjD,UAAS,MAAO;AAAA,IACf,KAAK;AAAA,IACL,KAAK;AACJ,aAAO,EAAE,MAAM,QAAQ,SAAS,KAAK;AAAA,IACtC,KAAK;AACJ,aAAO,EAAE,MAAM,QAAQ,SAAS,WAAW;AAAA,IAC5C,KAAK;AACJ,aAAO,EAAE,MAAM,QAAQ,SAAS,WAAW;AAAA,IAC5C,KAAK;AACJ,aAAO,EAAE,MAAM,cAAc;AAAA,IAC9B;AACC,UAAK,SAAS,YAAa;AAC1B,eAAO,EAAE,MAAM,QAAQ,SAAS,KAAK;AAAA,MACtC;AACA,UAAK,SAAS,aAAc;AAC3B,eAAO,EAAE,MAAM,QAAQ,SAAS,KAAK;AAAA,MACtC;AACA,aAAO;AAAA;AAAA;AAAA,QAGN,iCAAiC;AAAA,UAChC,MAAM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
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
TextareaControl
|
|
10
10
|
} from "@wordpress/components";
|
|
11
11
|
import { __, sprintf } from "@wordpress/i18n";
|
|
12
|
-
import { useRef } from "@wordpress/element";
|
|
12
|
+
import { useRef, useEffect, useState } 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,17 +46,34 @@ 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);
|
|
49
51
|
const inputId = useInstanceId(Controls, "link-input");
|
|
50
52
|
const helpTextId = `${inputId}__help`;
|
|
51
|
-
const
|
|
53
|
+
const [inputValue, setInputValue] = useState(url);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
setInputValue(url);
|
|
56
|
+
lastURLRef.current = url;
|
|
57
|
+
}, [url]);
|
|
58
|
+
const { hasUrlBinding, isBoundEntityAvailable, clearBinding } = useEntityBinding({
|
|
52
59
|
clientId,
|
|
53
60
|
attributes
|
|
54
61
|
});
|
|
55
62
|
const { updateBlockAttributes } = useDispatch(blockEditorStore);
|
|
56
|
-
const
|
|
63
|
+
const unsyncBoundLink = () => {
|
|
57
64
|
clearBinding();
|
|
58
|
-
updateBlockAttributes(clientId, {
|
|
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
|
+
});
|
|
59
70
|
};
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (!hasUrlBinding && shouldFocusURLInputRef.current) {
|
|
73
|
+
urlInputRef.current?.select();
|
|
74
|
+
}
|
|
75
|
+
shouldFocusURLInputRef.current = false;
|
|
76
|
+
}, [hasUrlBinding]);
|
|
60
77
|
return /* @__PURE__ */ jsxs(
|
|
61
78
|
ToolsPanel,
|
|
62
79
|
{
|
|
@@ -104,39 +121,54 @@ function Controls({ attributes, setAttributes, clientId }) {
|
|
|
104
121
|
children: /* @__PURE__ */ jsx(
|
|
105
122
|
InputControl,
|
|
106
123
|
{
|
|
124
|
+
ref: urlInputRef,
|
|
107
125
|
__nextHasNoMarginBottom: true,
|
|
108
126
|
__next40pxDefaultSize: true,
|
|
109
127
|
id: inputId,
|
|
110
128
|
label: __("Link"),
|
|
111
|
-
value:
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return;
|
|
129
|
+
value: (() => {
|
|
130
|
+
if (hasUrlBinding && !isBoundEntityAvailable) {
|
|
131
|
+
return "";
|
|
115
132
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
119
|
-
},
|
|
133
|
+
return inputValue ? safeDecodeURI(inputValue) : "";
|
|
134
|
+
})(),
|
|
120
135
|
autoComplete: "off",
|
|
121
136
|
type: "url",
|
|
122
137
|
disabled: hasUrlBinding,
|
|
138
|
+
"aria-invalid": hasUrlBinding && !isBoundEntityAvailable ? "true" : void 0,
|
|
139
|
+
"aria-describedby": helpTextId,
|
|
140
|
+
className: hasUrlBinding && !isBoundEntityAvailable ? "navigation-link-control__input-with-error-suffix" : void 0,
|
|
141
|
+
onChange: (newValue) => {
|
|
142
|
+
if (isBoundEntityAvailable) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
setInputValue(newValue);
|
|
146
|
+
},
|
|
123
147
|
onFocus: () => {
|
|
124
|
-
if (
|
|
148
|
+
if (isBoundEntityAvailable) {
|
|
125
149
|
return;
|
|
126
150
|
}
|
|
127
151
|
lastURLRef.current = url;
|
|
128
152
|
},
|
|
129
153
|
onBlur: () => {
|
|
130
|
-
if (
|
|
154
|
+
if (isBoundEntityAvailable) {
|
|
131
155
|
return;
|
|
132
156
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
157
|
+
const finalValue = !inputValue ? lastURLRef.current : inputValue;
|
|
158
|
+
setInputValue(finalValue);
|
|
159
|
+
updateAttributes({ url: finalValue }, setAttributes, {
|
|
160
|
+
...attributes,
|
|
161
|
+
url: lastURLRef.current
|
|
162
|
+
});
|
|
138
163
|
},
|
|
139
|
-
help: hasUrlBinding && /* @__PURE__ */ jsx(
|
|
164
|
+
help: hasUrlBinding && !isBoundEntityAvailable ? /* @__PURE__ */ jsx(
|
|
165
|
+
MissingEntityHelpText,
|
|
166
|
+
{
|
|
167
|
+
id: helpTextId,
|
|
168
|
+
type: attributes.type,
|
|
169
|
+
kind: attributes.kind
|
|
170
|
+
}
|
|
171
|
+
) : isBoundEntityAvailable && /* @__PURE__ */ jsx(
|
|
140
172
|
BindingHelpText,
|
|
141
173
|
{
|
|
142
174
|
type: attributes.type,
|
|
@@ -147,11 +179,15 @@ function Controls({ attributes, setAttributes, clientId }) {
|
|
|
147
179
|
Button,
|
|
148
180
|
{
|
|
149
181
|
icon: unlinkIcon,
|
|
150
|
-
onClick:
|
|
182
|
+
onClick: () => {
|
|
183
|
+
unsyncBoundLink();
|
|
184
|
+
shouldFocusURLInputRef.current = true;
|
|
185
|
+
},
|
|
151
186
|
"aria-describedby": helpTextId,
|
|
152
187
|
showTooltip: true,
|
|
153
188
|
label: __("Unsync and edit"),
|
|
154
|
-
__next40pxDefaultSize: true
|
|
189
|
+
__next40pxDefaultSize: true,
|
|
190
|
+
className: hasUrlBinding && !isBoundEntityAvailable ? "navigation-link-control__error-suffix-button" : void 0
|
|
155
191
|
}
|
|
156
192
|
)
|
|
157
193
|
}
|
|
@@ -236,6 +272,25 @@ function BindingHelpText({ type, kind }) {
|
|
|
236
272
|
entityType
|
|
237
273
|
);
|
|
238
274
|
}
|
|
275
|
+
function MissingEntityHelpText({ id, type, kind }) {
|
|
276
|
+
const entityType = getEntityTypeName(type, kind);
|
|
277
|
+
return /* @__PURE__ */ jsx(
|
|
278
|
+
"span",
|
|
279
|
+
{
|
|
280
|
+
id,
|
|
281
|
+
className: "navigation-link-control__error-text",
|
|
282
|
+
role: "alert",
|
|
283
|
+
"aria-live": "polite",
|
|
284
|
+
children: sprintf(
|
|
285
|
+
/* translators: %s is the entity type (e.g., "page", "post", "category") */
|
|
286
|
+
__(
|
|
287
|
+
"Synced %s is missing. Please update or remove this link."
|
|
288
|
+
),
|
|
289
|
+
entityType
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
);
|
|
293
|
+
}
|
|
239
294
|
export {
|
|
240
295
|
Controls
|
|
241
296
|
};
|
|
@@ -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 } 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": "
|
|
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, isBoundEntityAvailable, clearBinding } =\n\t\tuseEntityBinding( {\n\t\t\tclientId,\n\t\t\tattributes,\n\t\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// 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={ ( () => {\n\t\t\t\t\t\tif ( hasUrlBinding && ! isBoundEntityAvailable ) {\n\t\t\t\t\t\t\treturn '';\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn inputValue ? safeDecodeURI( inputValue ) : '';\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\taria-invalid={\n\t\t\t\t\t\thasUrlBinding && ! isBoundEntityAvailable\n\t\t\t\t\t\t\t? 'true'\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t\taria-describedby={ helpTextId }\n\t\t\t\t\tclassName={\n\t\t\t\t\t\thasUrlBinding && ! isBoundEntityAvailable\n\t\t\t\t\t\t\t? 'navigation-link-control__input-with-error-suffix'\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\tif ( isBoundEntityAvailable ) {\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 ( isBoundEntityAvailable ) {\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 ( isBoundEntityAvailable ) {\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 && ! isBoundEntityAvailable ? (\n\t\t\t\t\t\t\t<MissingEntityHelpText\n\t\t\t\t\t\t\t\tid={ helpTextId }\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\t\tisBoundEntityAvailable && (\n\t\t\t\t\t\t\t\t<BindingHelpText\n\t\t\t\t\t\t\t\t\ttype={ attributes.type }\n\t\t\t\t\t\t\t\t\tkind={ attributes.kind }\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\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\tclassName={\n\t\t\t\t\t\t\t\t\thasUrlBinding && ! isBoundEntityAvailable\n\t\t\t\t\t\t\t\t\t\t? 'navigation-link-control__error-suffix-button'\n\t\t\t\t\t\t\t\t\t\t: undefined\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/>\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\n/**\n * Component to display error help text for missing entity bindings.\n *\n * @param {Object} props - Component props\n * @param {string} props.id - ID for the help text element (for aria-describedby)\n * @param {string} props.type - The entity type\n * @param {string} props.kind - The entity kind\n * @return {JSX.Element} Error help text component\n */\nfunction MissingEntityHelpText( { id, type, kind } ) {\n\tconst entityType = getEntityTypeName( type, kind );\n\treturn (\n\t\t<span\n\t\t\tid={ id }\n\t\t\tclassName=\"navigation-link-control__error-text\"\n\t\t\trole=\"alert\"\n\t\t\taria-live=\"polite\"\n\t\t>\n\t\t\t{ sprintf(\n\t\t\t\t/* translators: %s is the entity type (e.g., \"page\", \"post\", \"category\") */\n\t\t\t\t__(\n\t\t\t\t\t'Synced %s is missing. Please update or remove this link.'\n\t\t\t\t),\n\t\t\t\tentityType\n\t\t\t) }\n\t\t</span>\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AA4HE,SAmBE,KAnBF;AAzHF;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,QAAQ,WAAW,gBAAgB;AAC5C,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,wBAAwB;AASjC,SAAS,kBAAmB,MAAM,MAAO;AACxC,MAAK,SAAS,aAAc;AAC3B,YAAS,MAAO;AAAA,MACf,KAAK;AACJ,eAAO,GAAI,MAAO;AAAA,MACnB,KAAK;AACJ,eAAO,GAAI,MAAO;AAAA,MACnB;AACC,eAAO,QAAQ,GAAI,MAAO;AAAA,IAC5B;AAAA,EACD;AACA,MAAK,SAAS,YAAa;AAC1B,YAAS,MAAO;AAAA,MACf,KAAK;AACJ,eAAO,GAAI,UAAW;AAAA,MACvB,KAAK;AACJ,eAAO,GAAI,KAAM;AAAA,MAClB;AACC,eAAO,QAAQ,GAAI,MAAO;AAAA,IAC5B;AAAA,EACD;AACA,SAAO,QAAQ,GAAI,MAAO;AAC3B;AAaO,SAAS,SAAU,EAAE,YAAY,eAAe,SAAS,GAAI;AACnE,QAAM,EAAE,OAAO,KAAK,aAAa,KAAK,cAAc,IAAI;AACxD,QAAM,aAAa,OAAQ,GAAI;AA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
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
useBlockBindingsUtils,
|
|
4
|
+
useBlockEditingMode
|
|
5
|
+
} from "@wordpress/block-editor";
|
|
6
|
+
import { useSelect } from "@wordpress/data";
|
|
7
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
3
8
|
function buildNavigationLinkEntityBinding(kind) {
|
|
4
9
|
if (kind === void 0) {
|
|
5
10
|
throw new Error(
|
|
@@ -23,10 +28,36 @@ function buildNavigationLinkEntityBinding(kind) {
|
|
|
23
28
|
}
|
|
24
29
|
function useEntityBinding({ clientId, attributes }) {
|
|
25
30
|
const { updateBlockBindings } = useBlockBindingsUtils(clientId);
|
|
26
|
-
const { metadata, id, kind } = attributes;
|
|
31
|
+
const { metadata, id, kind, type } = attributes;
|
|
32
|
+
const blockEditingMode = useBlockEditingMode();
|
|
27
33
|
const hasUrlBinding = !!metadata?.bindings?.url && !!id;
|
|
28
34
|
const expectedSource = kind === "post-type" ? "core/post-data" : "core/term-data";
|
|
29
35
|
const hasCorrectBinding = hasUrlBinding && metadata?.bindings?.url?.source === expectedSource;
|
|
36
|
+
const isBoundEntityAvailable = useSelect(
|
|
37
|
+
(select) => {
|
|
38
|
+
if (!hasCorrectBinding || !id) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const isPostType = kind === "post-type";
|
|
42
|
+
const isTaxonomy = kind === "taxonomy";
|
|
43
|
+
if (!isPostType && !isTaxonomy) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (blockEditingMode === "disabled") {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
const { getEntityRecord, hasFinishedResolution } = select(coreStore);
|
|
50
|
+
const entityType = isTaxonomy ? "taxonomy" : "postType";
|
|
51
|
+
const entityRecord = getEntityRecord(entityType, type, id);
|
|
52
|
+
const hasResolved = hasFinishedResolution("getEntityRecord", [
|
|
53
|
+
entityType,
|
|
54
|
+
type,
|
|
55
|
+
id
|
|
56
|
+
]);
|
|
57
|
+
return hasResolved ? entityRecord !== void 0 : true;
|
|
58
|
+
},
|
|
59
|
+
[kind, type, id, hasCorrectBinding, blockEditingMode]
|
|
60
|
+
);
|
|
30
61
|
const clearBinding = useCallback(() => {
|
|
31
62
|
if (hasUrlBinding) {
|
|
32
63
|
updateBlockBindings({ url: void 0 });
|
|
@@ -48,10 +79,11 @@ function useEntityBinding({ clientId, attributes }) {
|
|
|
48
79
|
);
|
|
49
80
|
}
|
|
50
81
|
},
|
|
51
|
-
[updateBlockBindings, kind
|
|
82
|
+
[updateBlockBindings, kind]
|
|
52
83
|
);
|
|
53
84
|
return {
|
|
54
85
|
hasUrlBinding: hasCorrectBinding,
|
|
86
|
+
isBoundEntityAvailable,
|
|
55
87
|
clearBinding,
|
|
56
88
|
createBinding
|
|
57
89
|
};
|
|
@@ -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 {
|
|
5
|
-
"mappings": "AAGA,SAAS,mBAAmB;AAC5B,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport {\n\tuseBlockBindingsUtils,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\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, type } = attributes;\n\tconst blockEditingMode = useBlockEditingMode();\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\t// Check if the bound entity is available (not deleted).\n\tconst isBoundEntityAvailable = useSelect(\n\t\t( select ) => {\n\t\t\t// First check: metadata/binding must exist\n\t\t\tif ( ! hasCorrectBinding || ! id ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst isPostType = kind === 'post-type';\n\t\t\tconst isTaxonomy = kind === 'taxonomy';\n\n\t\t\t// Only check entity availability for post types and taxonomies.\n\t\t\tif ( ! isPostType && ! isTaxonomy ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\t// Skip check in disabled contexts to avoid unnecessary requests.\n\t\t\tif ( blockEditingMode === 'disabled' ) {\n\t\t\t\treturn true; // Assume available in disabled contexts.\n\t\t\t}\n\n\t\t\t// Second check: entity must exist\n\t\t\tconst { getEntityRecord, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\n\t\t\t// Use the correct entity type based on kind.\n\t\t\tconst entityType = isTaxonomy ? 'taxonomy' : 'postType';\n\t\t\tconst entityRecord = getEntityRecord( entityType, type, id );\n\t\t\tconst hasResolved = hasFinishedResolution( 'getEntityRecord', [\n\t\t\t\tentityType,\n\t\t\t\ttype,\n\t\t\t\tid,\n\t\t\t] );\n\n\t\t\t// If resolution has finished and entityRecord is undefined, the entity was deleted.\n\t\t\t// Return true if entity exists, false if deleted.\n\t\t\treturn hasResolved ? entityRecord !== undefined : true;\n\t\t},\n\t\t[ kind, type, id, hasCorrectBinding, blockEditingMode ]\n\t);\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 ]\n\t);\n\n\treturn {\n\t\thasUrlBinding: hasCorrectBinding,\n\t\tisBoundEntityAvailable,\n\t\tclearBinding,\n\t\tcreateBinding,\n\t};\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,mBAAmB;AAC5B;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,iBAAiB;AAC1B,SAAS,SAAS,iBAAiB;AAa5B,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,MAAM,KAAK,IAAI;AACrC,QAAM,mBAAmB,oBAAoB;AAE7C,QAAM,gBAAgB,CAAC,CAAE,UAAU,UAAU,OAAO,CAAC,CAAE;AACvD,QAAM,iBACL,SAAS,cAAc,mBAAmB;AAC3C,QAAM,oBACL,iBAAiB,UAAU,UAAU,KAAK,WAAW;AAGtD,QAAM,yBAAyB;AAAA,IAC9B,CAAE,WAAY;AAEb,UAAK,CAAE,qBAAqB,CAAE,IAAK;AAClC,eAAO;AAAA,MACR;AAEA,YAAM,aAAa,SAAS;AAC5B,YAAM,aAAa,SAAS;AAG5B,UAAK,CAAE,cAAc,CAAE,YAAa;AACnC,eAAO;AAAA,MACR;AAGA,UAAK,qBAAqB,YAAa;AACtC,eAAO;AAAA,MACR;AAGA,YAAM,EAAE,iBAAiB,sBAAsB,IAC9C,OAAQ,SAAU;AAGnB,YAAM,aAAa,aAAa,aAAa;AAC7C,YAAM,eAAe,gBAAiB,YAAY,MAAM,EAAG;AAC3D,YAAM,cAAc,sBAAuB,mBAAmB;AAAA,QAC7D;AAAA,QACA;AAAA,QACA;AAAA,MACD,CAAE;AAIF,aAAO,cAAc,iBAAiB,SAAY;AAAA,IACnD;AAAA,IACA,CAAE,MAAM,MAAM,IAAI,mBAAmB,gBAAiB;AAAA,EACvD;AAEA,QAAM,eAAe,YAAa,MAAM;AACvC,QAAK,eAAgB;AACpB,0BAAqB,EAAE,KAAK,OAAU,CAAE;AAAA,IACzC;AAAA,EACD,GAAG,CAAE,qBAAqB,eAAe,UAAU,EAAG,CAAE;AAExD,QAAM,gBAAgB;AAAA,IACrB,CAAE,sBAAuB;AAGxB,YAAM,YAAY,mBAAmB,QAAQ;AAG7C,UAAK,CAAE,WAAY;AAClB;AAAA,MACD;AAEA,UAAI;AACH,cAAM,UAAU,iCAAkC,SAAU;AAC5D,4BAAqB,OAAQ;AAAA,MAC9B,SAAU,OAAQ;AAEjB,gBAAQ;AAAA,UACP;AAAA,UACA,MAAM;AAAA,QACP;AAAA,MAED;AAAA,IACD;AAAA,IACA,CAAE,qBAAqB,IAAK;AAAA,EAC7B;AAEA,SAAO;AAAA,IACN,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,6 +6,7 @@ import edit from "./edit";
|
|
|
6
6
|
import metadata from "./block.json";
|
|
7
7
|
import save from "./save";
|
|
8
8
|
import transforms from "./transforms";
|
|
9
|
+
import variations from "./variations";
|
|
9
10
|
const { name } = metadata;
|
|
10
11
|
const settings = {
|
|
11
12
|
icon,
|
|
@@ -37,7 +38,8 @@ const settings = {
|
|
|
37
38
|
};
|
|
38
39
|
},
|
|
39
40
|
edit,
|
|
40
|
-
save
|
|
41
|
+
save,
|
|
42
|
+
variations
|
|
41
43
|
};
|
|
42
44
|
const init = () => initBlock({ name, metadata, settings });
|
|
43
45
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/paragraph/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { paragraph as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tcontent: __(\n\t\t\t\t'In a village of La Mancha, the name of which I have no desire to call to mind, there lived not long since one of those gentlemen that keep a lance in the lance-rack, an old buckler, a lean hack, and a greyhound for coursing.'\n\t\t\t),\n\t\t},\n\t},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst customName = attributes?.metadata?.name;\n\n\t\tif ( context === 'list-view' && customName ) {\n\t\t\treturn customName;\n\t\t}\n\n\t\tif ( context === 'accessibility' ) {\n\t\t\tif ( customName ) {\n\t\t\t\treturn customName;\n\t\t\t}\n\n\t\t\tconst { content } = attributes;\n\t\t\treturn ! content || content.length === 0 ? __( 'Empty' ) : content;\n\t\t}\n\t},\n\ttransforms,\n\tdeprecated,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\tcontent:\n\t\t\t\t( attributes.content || '' ) +\n\t\t\t\t( attributesToMerge.content || '' ),\n\t\t};\n\t},\n\tedit,\n\tsave,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,UAAU;AACnB,SAAS,aAAa,YAAY;AAKlC,OAAO,eAAe;AACtB,OAAO,gBAAgB;AACvB,OAAO,UAAU;AACjB,OAAO,cAAc;AACrB,OAAO,UAAU;AACjB,OAAO,gBAAgB;AAEvB,MAAM,EAAE,KAAK,IAAI;AAIV,MAAM,WAAW;AAAA,EACvB;AAAA,EACA,SAAS;AAAA,IACR,YAAY;AAAA,MACX,SAAS;AAAA,QACR;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EACA,oBAAqB,YAAY,EAAE,QAAQ,GAAI;AAC9C,UAAM,aAAa,YAAY,UAAU;AAEzC,QAAK,YAAY,eAAe,YAAa;AAC5C,aAAO;AAAA,IACR;AAEA,QAAK,YAAY,iBAAkB;AAClC,UAAK,YAAa;AACjB,eAAO;AAAA,MACR;AAEA,YAAM,EAAE,QAAQ,IAAI;AACpB,aAAO,CAAE,WAAW,QAAQ,WAAW,IAAI,GAAI,OAAQ,IAAI;AAAA,IAC5D;AAAA,EACD;AAAA,EACA;AAAA,EACA;AAAA,EACA,MAAO,YAAY,mBAAoB;AACtC,WAAO;AAAA,MACN,UACG,WAAW,WAAW,OACtB,kBAAkB,WAAW;AAAA,IACjC;AAAA,EACD;AAAA,EACA;AAAA,EACA;AACD;AAEO,MAAM,OAAO,MAAM,UAAW,EAAE,MAAM,UAAU,SAAS,CAAE;",
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { paragraph as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport initBlock from '../utils/init-block';\nimport deprecated from './deprecated';\nimport edit from './edit';\nimport metadata from './block.json';\nimport save from './save';\nimport transforms from './transforms';\nimport variations from './variations';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\texample: {\n\t\tattributes: {\n\t\t\tcontent: __(\n\t\t\t\t'In a village of La Mancha, the name of which I have no desire to call to mind, there lived not long since one of those gentlemen that keep a lance in the lance-rack, an old buckler, a lean hack, and a greyhound for coursing.'\n\t\t\t),\n\t\t},\n\t},\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst customName = attributes?.metadata?.name;\n\n\t\tif ( context === 'list-view' && customName ) {\n\t\t\treturn customName;\n\t\t}\n\n\t\tif ( context === 'accessibility' ) {\n\t\t\tif ( customName ) {\n\t\t\t\treturn customName;\n\t\t\t}\n\n\t\t\tconst { content } = attributes;\n\t\t\treturn ! content || content.length === 0 ? __( 'Empty' ) : content;\n\t\t}\n\t},\n\ttransforms,\n\tdeprecated,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\tcontent:\n\t\t\t\t( attributes.content || '' ) +\n\t\t\t\t( attributesToMerge.content || '' ),\n\t\t};\n\t},\n\tedit,\n\tsave,\n\tvariations,\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,UAAU;AACnB,SAAS,aAAa,YAAY;AAKlC,OAAO,eAAe;AACtB,OAAO,gBAAgB;AACvB,OAAO,UAAU;AACjB,OAAO,cAAc;AACrB,OAAO,UAAU;AACjB,OAAO,gBAAgB;AACvB,OAAO,gBAAgB;AAEvB,MAAM,EAAE,KAAK,IAAI;AAIV,MAAM,WAAW;AAAA,EACvB;AAAA,EACA,SAAS;AAAA,IACR,YAAY;AAAA,MACX,SAAS;AAAA,QACR;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EACA,oBAAqB,YAAY,EAAE,QAAQ,GAAI;AAC9C,UAAM,aAAa,YAAY,UAAU;AAEzC,QAAK,YAAY,eAAe,YAAa;AAC5C,aAAO;AAAA,IACR;AAEA,QAAK,YAAY,iBAAkB;AAClC,UAAK,YAAa;AACjB,eAAO;AAAA,MACR;AAEA,YAAM,EAAE,QAAQ,IAAI;AACpB,aAAO,CAAE,WAAW,QAAQ,WAAW,IAAI,GAAI,OAAQ,IAAI;AAAA,IAC5D;AAAA,EACD;AAAA,EACA;AAAA,EACA;AAAA,EACA,MAAO,YAAY,mBAAoB;AACtC,WAAO;AAAA,MACN,UACG,WAAW,WAAW,OACtB,kBAAkB,WAAW;AAAA,IACjC;AAAA,EACD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEO,MAAM,OAAO,MAAM,UAAW,EAAE,MAAM,UAAU,SAAS,CAAE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { __ } from "@wordpress/i18n";
|
|
3
|
+
import { Path, SVG } from "@wordpress/primitives";
|
|
4
|
+
import { paragraph } from "@wordpress/icons";
|
|
5
|
+
const variations = [
|
|
6
|
+
{
|
|
7
|
+
name: "paragraph",
|
|
8
|
+
title: __("Paragraph"),
|
|
9
|
+
description: __(
|
|
10
|
+
"Start with the basic building block of all narrative."
|
|
11
|
+
),
|
|
12
|
+
isDefault: true,
|
|
13
|
+
scope: ["block", "inserter", "transform"],
|
|
14
|
+
attributes: { fitText: void 0 },
|
|
15
|
+
icon: paragraph
|
|
16
|
+
},
|
|
17
|
+
// There is a hardcoded workaround in packages/block-editor/src/store/selectors.js
|
|
18
|
+
// to make Stretchy variations appear as the last of their sections in the inserter.
|
|
19
|
+
{
|
|
20
|
+
name: "stretchy-paragraph",
|
|
21
|
+
title: __("Stretchy Paragraph"),
|
|
22
|
+
description: __("Paragraph that resizes to fit its container."),
|
|
23
|
+
icon: /* @__PURE__ */ jsx(SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx(Path, { d: "M3 9c0 2.8 2.2 5 5 5v-.2V20h1.5V5.5H12V20h1.5V5.5h3V4H8C5.2 4 3 6.2 3 9Zm16.2-.2v1.5h2.2L17.7 14l1.1 1.1 3.7-3.7v2.2H24V8.8h-4.8Z" }) }),
|
|
24
|
+
attributes: {
|
|
25
|
+
fitText: true
|
|
26
|
+
},
|
|
27
|
+
scope: ["inserter", "transform"],
|
|
28
|
+
isActive: (blockAttributes) => blockAttributes.fitText === true
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
var variations_default = variations;
|
|
32
|
+
export {
|
|
33
|
+
variations_default as default
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=variations.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/paragraph/variations.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Path, SVG } from '@wordpress/primitives';\nimport { paragraph } from '@wordpress/icons';\n\nconst variations = [\n\t{\n\t\tname: 'paragraph',\n\t\ttitle: __( 'Paragraph' ),\n\t\tdescription: __(\n\t\t\t'Start with the basic building block of all narrative.'\n\t\t),\n\t\tisDefault: true,\n\t\tscope: [ 'block', 'inserter', 'transform' ],\n\t\tattributes: { fitText: undefined },\n\t\ticon: paragraph,\n\t},\n\t// There is a hardcoded workaround in packages/block-editor/src/store/selectors.js\n\t// to make Stretchy variations appear as the last of their sections in the inserter.\n\t{\n\t\tname: 'stretchy-paragraph',\n\t\ttitle: __( 'Stretchy Paragraph' ),\n\t\tdescription: __( 'Paragraph that resizes to fit its container.' ),\n\t\ticon: (\n\t\t\t<SVG xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">\n\t\t\t\t<Path d=\"M3 9c0 2.8 2.2 5 5 5v-.2V20h1.5V5.5H12V20h1.5V5.5h3V4H8C5.2 4 3 6.2 3 9Zm16.2-.2v1.5h2.2L17.7 14l1.1 1.1 3.7-3.7v2.2H24V8.8h-4.8Z\" />\n\t\t\t</SVG>\n\t\t),\n\t\tattributes: {\n\t\t\tfitText: true,\n\t\t},\n\t\tscope: [ 'inserter', 'transform' ],\n\t\tisActive: ( blockAttributes ) => blockAttributes.fitText === true,\n\t},\n];\n\nexport default variations;\n"],
|
|
5
|
+
"mappings": "AA2BI;AAxBJ,SAAS,UAAU;AACnB,SAAS,MAAM,WAAW;AAC1B,SAAS,iBAAiB;AAE1B,MAAM,aAAa;AAAA,EAClB;AAAA,IACC,MAAM;AAAA,IACN,OAAO,GAAI,WAAY;AAAA,IACvB,aAAa;AAAA,MACZ;AAAA,IACD;AAAA,IACA,WAAW;AAAA,IACX,OAAO,CAAE,SAAS,YAAY,WAAY;AAAA,IAC1C,YAAY,EAAE,SAAS,OAAU;AAAA,IACjC,MAAM;AAAA,EACP;AAAA;AAAA;AAAA,EAGA;AAAA,IACC,MAAM;AAAA,IACN,OAAO,GAAI,oBAAqB;AAAA,IAChC,aAAa,GAAI,8CAA+C;AAAA,IAChE,MACC,oBAAC,OAAI,OAAM,8BAA6B,SAAQ,aAC/C,8BAAC,QAAK,GAAE,qIAAoI,GAC7I;AAAA,IAED,YAAY;AAAA,MACX,SAAS;AAAA,IACV;AAAA,IACA,OAAO,CAAE,YAAY,WAAY;AAAA,IACjC,UAAU,CAAE,oBAAqB,gBAAgB,YAAY;AAAA,EAC9D;AACD;AAEA,IAAO,qBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
.wp-block-accordion-heading.wp-block-accordion-heading {
|
|
2
|
+
min-width: 100%;
|
|
3
|
+
margin: 0;
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
.wp-block-accordion-heading__toggle {
|
|
2
7
|
font-family: inherit;
|
|
3
8
|
font-size: inherit;
|
|
@@ -8,21 +13,32 @@
|
|
|
8
13
|
text-decoration: inherit;
|
|
9
14
|
word-spacing: inherit;
|
|
10
15
|
font-style: inherit;
|
|
11
|
-
background: none;
|
|
12
16
|
border: none;
|
|
13
|
-
color: inherit;
|
|
14
17
|
padding: var(--wp--preset--spacing--20, 1em) 0;
|
|
15
18
|
cursor: pointer;
|
|
16
19
|
overflow: hidden;
|
|
17
20
|
display: flex;
|
|
18
21
|
align-items: center;
|
|
19
22
|
text-align: inherit;
|
|
20
|
-
position: relative;
|
|
21
23
|
width: 100%;
|
|
24
|
+
background-color: inherit !important;
|
|
25
|
+
color: inherit !important;
|
|
22
26
|
}
|
|
23
27
|
.wp-block-accordion-heading__toggle:not(:focus-visible) {
|
|
24
28
|
outline: none;
|
|
25
29
|
}
|
|
30
|
+
.wp-block-accordion-heading__toggle:hover, .wp-block-accordion-heading__toggle:focus {
|
|
31
|
+
text-decoration: none;
|
|
32
|
+
background-color: inherit !important;
|
|
33
|
+
box-shadow: none;
|
|
34
|
+
color: inherit;
|
|
35
|
+
border: none;
|
|
36
|
+
padding: var(--wp--preset--spacing--20, 1em) 0;
|
|
37
|
+
}
|
|
38
|
+
.wp-block-accordion-heading__toggle:focus-visible {
|
|
39
|
+
outline: auto;
|
|
40
|
+
outline-offset: 0;
|
|
41
|
+
}
|
|
26
42
|
.wp-block-accordion-heading__toggle:hover .wp-block-accordion-heading__toggle-title {
|
|
27
43
|
text-decoration: underline;
|
|
28
44
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
.wp-block-accordion-heading.wp-block-accordion-heading {
|
|
2
|
+
min-width: 100%;
|
|
3
|
+
margin: 0;
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
.wp-block-accordion-heading__toggle {
|
|
2
7
|
font-family: inherit;
|
|
3
8
|
font-size: inherit;
|
|
@@ -8,21 +13,32 @@
|
|
|
8
13
|
text-decoration: inherit;
|
|
9
14
|
word-spacing: inherit;
|
|
10
15
|
font-style: inherit;
|
|
11
|
-
background: none;
|
|
12
16
|
border: none;
|
|
13
|
-
color: inherit;
|
|
14
17
|
padding: var(--wp--preset--spacing--20, 1em) 0;
|
|
15
18
|
cursor: pointer;
|
|
16
19
|
overflow: hidden;
|
|
17
20
|
display: flex;
|
|
18
21
|
align-items: center;
|
|
19
22
|
text-align: inherit;
|
|
20
|
-
position: relative;
|
|
21
23
|
width: 100%;
|
|
24
|
+
background-color: inherit !important;
|
|
25
|
+
color: inherit !important;
|
|
22
26
|
}
|
|
23
27
|
.wp-block-accordion-heading__toggle:not(:focus-visible) {
|
|
24
28
|
outline: none;
|
|
25
29
|
}
|
|
30
|
+
.wp-block-accordion-heading__toggle:hover, .wp-block-accordion-heading__toggle:focus {
|
|
31
|
+
text-decoration: none;
|
|
32
|
+
background-color: inherit !important;
|
|
33
|
+
box-shadow: none;
|
|
34
|
+
color: inherit;
|
|
35
|
+
border: none;
|
|
36
|
+
padding: var(--wp--preset--spacing--20, 1em) 0;
|
|
37
|
+
}
|
|
38
|
+
.wp-block-accordion-heading__toggle:focus-visible {
|
|
39
|
+
outline: auto;
|
|
40
|
+
outline-offset: 0;
|
|
41
|
+
}
|
|
26
42
|
.wp-block-accordion-heading__toggle:hover .wp-block-accordion-heading__toggle-title {
|
|
27
43
|
text-decoration: underline;
|
|
28
44
|
}
|