@wordpress/block-library 9.30.1-next.6870dfe5b.0 → 9.30.1-next.836ecdcae.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/navigation-link/link-ui.js +82 -34
- package/build/navigation-link/link-ui.js.map +1 -1
- package/build/navigation-link/page-creator.js +18 -12
- package/build/navigation-link/page-creator.js.map +1 -1
- package/build-module/navigation-link/link-ui.js +85 -37
- package/build-module/navigation-link/link-ui.js.map +1 -1
- package/build-module/navigation-link/page-creator.js +19 -12
- package/build-module/navigation-link/page-creator.js.map +1 -1
- package/package.json +35 -35
- package/src/navigation-link/link-ui.js +95 -32
- package/src/navigation-link/page-creator.js +20 -13
- package/build/navigation-link/block-inserter.js +0 -69
- package/build/navigation-link/block-inserter.js.map +0 -1
- package/build/navigation-link/dialog-wrapper.js +0 -80
- package/build/navigation-link/dialog-wrapper.js.map +0 -1
- package/build-module/navigation-link/block-inserter.js +0 -61
- package/build-module/navigation-link/block-inserter.js.map +0 -1
- package/build-module/navigation-link/dialog-wrapper.js +0 -75
- package/build-module/navigation-link/dialog-wrapper.js.map +0 -1
- package/src/navigation-link/block-inserter.js +0 -65
- package/src/navigation-link/dialog-wrapper.js +0 -74
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -12,10 +11,11 @@ var _i18n = require("@wordpress/i18n");
|
|
|
12
11
|
var _blockEditor = require("@wordpress/block-editor");
|
|
13
12
|
var _element = require("@wordpress/element");
|
|
14
13
|
var _coreData = require("@wordpress/core-data");
|
|
14
|
+
var _data = require("@wordpress/data");
|
|
15
15
|
var _icons = require("@wordpress/icons");
|
|
16
16
|
var _compose = require("@wordpress/compose");
|
|
17
|
+
var _lockUnlock = require("../lock-unlock");
|
|
17
18
|
var _pageCreator = require("./page-creator");
|
|
18
|
-
var _blockInserter = _interopRequireDefault(require("./block-inserter"));
|
|
19
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
20
|
/**
|
|
21
21
|
* WordPress dependencies
|
|
@@ -25,6 +25,10 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
25
25
|
* Internal dependencies
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
+
const {
|
|
29
|
+
PrivateQuickInserter: QuickInserter
|
|
30
|
+
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
31
|
+
|
|
28
32
|
/**
|
|
29
33
|
* Given the Link block's type attribute, return the query params to give to
|
|
30
34
|
* /wp/v2/search.
|
|
@@ -79,6 +83,61 @@ function getSuggestionsQuery(type, kind) {
|
|
|
79
83
|
};
|
|
80
84
|
}
|
|
81
85
|
}
|
|
86
|
+
function LinkUIBlockInserter({
|
|
87
|
+
clientId,
|
|
88
|
+
onBack,
|
|
89
|
+
onBlockInsert
|
|
90
|
+
}) {
|
|
91
|
+
const {
|
|
92
|
+
rootBlockClientId
|
|
93
|
+
} = (0, _data.useSelect)(select => {
|
|
94
|
+
const {
|
|
95
|
+
getBlockRootClientId
|
|
96
|
+
} = select(_blockEditor.store);
|
|
97
|
+
return {
|
|
98
|
+
rootBlockClientId: getBlockRootClientId(clientId)
|
|
99
|
+
};
|
|
100
|
+
}, [clientId]);
|
|
101
|
+
const focusOnMountRef = (0, _compose.useFocusOnMount)('firstElement');
|
|
102
|
+
const dialogTitleId = (0, _compose.useInstanceId)(_blockEditor.LinkControl, `link-ui-block-inserter__title`);
|
|
103
|
+
const dialogDescriptionId = (0, _compose.useInstanceId)(_blockEditor.LinkControl, `link-ui-block-inserter__description`);
|
|
104
|
+
if (!clientId) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
108
|
+
className: "link-ui-block-inserter",
|
|
109
|
+
role: "dialog",
|
|
110
|
+
"aria-labelledby": dialogTitleId,
|
|
111
|
+
"aria-describedby": dialogDescriptionId,
|
|
112
|
+
ref: focusOnMountRef,
|
|
113
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.VisuallyHidden, {
|
|
114
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
|
|
115
|
+
id: dialogTitleId,
|
|
116
|
+
children: (0, _i18n.__)('Add block')
|
|
117
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
118
|
+
id: dialogDescriptionId,
|
|
119
|
+
children: (0, _i18n.__)('Choose a block to add to your Navigation.')
|
|
120
|
+
})]
|
|
121
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
122
|
+
className: "link-ui-block-inserter__back",
|
|
123
|
+
icon: (0, _i18n.isRTL)() ? _icons.chevronRightSmall : _icons.chevronLeftSmall,
|
|
124
|
+
onClick: e => {
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
onBack();
|
|
127
|
+
},
|
|
128
|
+
size: "small",
|
|
129
|
+
children: (0, _i18n.__)('Back')
|
|
130
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(QuickInserter, {
|
|
131
|
+
rootClientId: rootBlockClientId,
|
|
132
|
+
clientId: clientId,
|
|
133
|
+
isAppender: false,
|
|
134
|
+
prioritizePatterns: false,
|
|
135
|
+
selectBlockOnInsert: !onBlockInsert,
|
|
136
|
+
onSelect: onBlockInsert ? onBlockInsert : undefined,
|
|
137
|
+
hasSearch: false
|
|
138
|
+
})]
|
|
139
|
+
});
|
|
140
|
+
}
|
|
82
141
|
function UnforwardedLinkUI(props, ref) {
|
|
83
142
|
const {
|
|
84
143
|
label,
|
|
@@ -110,8 +169,8 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
110
169
|
// Return to main Link UI
|
|
111
170
|
setAddingPage(false);
|
|
112
171
|
};
|
|
113
|
-
const dialogTitleId = (0, _compose.useInstanceId)(LinkUI,
|
|
114
|
-
const dialogDescriptionId = (0, _compose.useInstanceId)(LinkUI,
|
|
172
|
+
const dialogTitleId = (0, _compose.useInstanceId)(LinkUI, `link-ui-link-control__title`);
|
|
173
|
+
const dialogDescriptionId = (0, _compose.useInstanceId)(LinkUI, `link-ui-link-control__description`);
|
|
115
174
|
const blockEditingMode = (0, _blockEditor.useBlockEditingMode)();
|
|
116
175
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Popover, {
|
|
117
176
|
ref: ref,
|
|
@@ -143,28 +202,22 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
143
202
|
onChange: props.onChange,
|
|
144
203
|
onRemove: props.onRemove,
|
|
145
204
|
onCancel: props.onCancel,
|
|
146
|
-
renderControlBottom: () => {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
setFocusAddPageButton(false);
|
|
161
|
-
},
|
|
162
|
-
canAddPage: permissions?.canCreate && type === 'page',
|
|
163
|
-
canAddBlock: blockEditingMode === 'default'
|
|
164
|
-
});
|
|
165
|
-
}
|
|
205
|
+
renderControlBottom: () => !link?.url?.length && /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkUITools, {
|
|
206
|
+
focusAddBlockButton: focusAddBlockButton,
|
|
207
|
+
focusAddPageButton: focusAddPageButton,
|
|
208
|
+
setAddingBlock: () => {
|
|
209
|
+
setAddingBlock(true);
|
|
210
|
+
setFocusAddBlockButton(false);
|
|
211
|
+
},
|
|
212
|
+
setAddingPage: () => {
|
|
213
|
+
setAddingPage(true);
|
|
214
|
+
setFocusAddPageButton(false);
|
|
215
|
+
},
|
|
216
|
+
canCreatePage: permissions.canCreate,
|
|
217
|
+
blockEditingMode: blockEditingMode
|
|
218
|
+
})
|
|
166
219
|
})]
|
|
167
|
-
}), addingBlock && /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
220
|
+
}), addingBlock && /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkUIBlockInserter, {
|
|
168
221
|
clientId: props.clientId,
|
|
169
222
|
onBack: () => {
|
|
170
223
|
setAddingBlock(false);
|
|
@@ -190,8 +243,8 @@ const LinkUITools = ({
|
|
|
190
243
|
setAddingPage,
|
|
191
244
|
focusAddBlockButton,
|
|
192
245
|
focusAddPageButton,
|
|
193
|
-
|
|
194
|
-
|
|
246
|
+
canCreatePage,
|
|
247
|
+
blockEditingMode
|
|
195
248
|
}) => {
|
|
196
249
|
const blockInserterAriaRole = 'listbox';
|
|
197
250
|
const addBlockButtonRef = (0, _element.useRef)();
|
|
@@ -210,15 +263,10 @@ const LinkUITools = ({
|
|
|
210
263
|
addPageButtonRef.current?.focus();
|
|
211
264
|
}
|
|
212
265
|
}, [focusAddPageButton]);
|
|
213
|
-
|
|
214
|
-
// Don't render anything if neither button should be shown
|
|
215
|
-
if (!canAddPage && !canAddBlock) {
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
218
266
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
219
267
|
spacing: 0,
|
|
220
268
|
className: "link-ui-tools",
|
|
221
|
-
children: [
|
|
269
|
+
children: [canCreatePage && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
222
270
|
__next40pxDefaultSize: true,
|
|
223
271
|
ref: addPageButtonRef,
|
|
224
272
|
icon: _icons.plus,
|
|
@@ -228,7 +276,7 @@ const LinkUITools = ({
|
|
|
228
276
|
},
|
|
229
277
|
"aria-haspopup": blockInserterAriaRole,
|
|
230
278
|
children: (0, _i18n.__)('Create page')
|
|
231
|
-
}),
|
|
279
|
+
}), blockEditingMode === 'default' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
232
280
|
__next40pxDefaultSize: true,
|
|
233
281
|
ref: addBlockButtonRef,
|
|
234
282
|
icon: _icons.plus,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_dom","require","_components","_i18n","_blockEditor","_element","_coreData","_icons","_compose","_pageCreator","_blockInserter","_interopRequireDefault","_jsxRuntime","getSuggestionsQuery","type","kind","subtype","initialSuggestionsSearchOptions","perPage","UnforwardedLinkUI","props","ref","label","url","opensInNewTab","link","postType","addingBlock","setAddingBlock","useState","addingPage","setAddingPage","focusAddBlockButton","setFocusAddBlockButton","focusAddPageButton","setFocusAddPageButton","permissions","useResourcePermissions","name","useMemo","title","stripHTML","handlePageCreated","pageLink","onChange","dialogTitleId","useInstanceId","LinkUI","dialogDescriptionId","blockEditingMode","useBlockEditingMode","jsxs","Popover","placement","onClose","anchor","shift","children","role","VisuallyHidden","jsx","id","__","LinkControl","hasTextControl","hasRichPreviews","value","showInitialSuggestions","withCreateSuggestion","noDirectEntry","noURLSuggestion","suggestionsQuery","onRemove","onCancel","renderControlBottom","length","LinkUITools","canAddPage","canCreate","canAddBlock","default","clientId","onBack","onBlockInsert","LinkUIPageCreator","onPageCreated","initialTitle","exports","forwardRef","blockInserterAriaRole","addBlockButtonRef","useRef","addPageButtonRef","useEffect","current","focus","__experimentalVStack","spacing","className","Button","__next40pxDefaultSize","icon","plus","onClick","e","preventDefault","_default"],"sources":["@wordpress/block-library/src/navigation-link/link-ui.js"],"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 } = props.link;\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// 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} ),\n\t\t[ label, opensInNewTab, url ]\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\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"],"mappings":";;;;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAMA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAOA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,QAAA,GAAAP,OAAA;AAKA,IAAAQ,YAAA,GAAAR,OAAA;AACA,IAAAS,cAAA,GAAAC,sBAAA,CAAAV,OAAA;AAAmD,IAAAW,WAAA,GAAAX,OAAA;AA3BnD;AACA;AACA;;AAqBA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASY,mBAAmBA,CAAEC,IAAI,EAAEC,IAAI,EAAG;EACjD,QAASD,IAAI;IACZ,KAAK,MAAM;IACX,KAAK,MAAM;MACV,OAAO;QAAEA,IAAI,EAAE,MAAM;QAAEE,OAAO,EAAEF;MAAK,CAAC;IACvC,KAAK,UAAU;MACd,OAAO;QAAEA,IAAI,EAAE,MAAM;QAAEE,OAAO,EAAE;MAAW,CAAC;IAC7C,KAAK,KAAK;MACT,OAAO;QAAEF,IAAI,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U,IAAI,CAAEE,WAAW,EAAG;IACpC,OAAO,IAAI;EACZ;EAEA,oBACC,IAAAnE,WAAA,CAAAuC,IAAA,EAACjD,WAAA,CAAA8F,oBAAM;IAACC,OAAO,EAAG,CAAG;IAACC,SAAS,EAAC,eAAe;IAAAzC,QAAA,GAC5CoB,UAAU,iBACX,IAAAjE,WAAA,CAAAgD,GAAA,EAAC1D,WAAA,CAAAiG,MAAM;MACNC,qBAAqB;MACrB/E,GAAG,EAAGuE,gBAAkB;MACxBS,IAAI,EAAGC,WAAM;MACbC,OAAO,EAAKC,CAAC,IAAM;QAClBA,CAAC,CAACC,cAAc,CAAC,CAAC;QAClB1E,aAAa,CAAE,IAAK,CAAC;MACtB,CAAG;MACH,iBAAgB0D,qBAAuB;MAAAhC,QAAA,EAErC,IAAAK,QAAE,EAAE,aAAc;IAAC,CACd,CACR,EACCiB,WAAW,iBACZ,IAAAnE,WAAA,CAAAgD,GAAA,EAAC1D,WAAA,CAAAiG,MAAM;MACNC,qBAAqB;MACrB/E,GAAG,EAAGqE,iBAAmB;MACzBW,IAAI,EAAGC,WAAM;MACbC,OAAO,EAAKC,CAAC,IAAM;QAClBA,CAAC,CAACC,cAAc,CAAC,CAAC;QAClB7E,cAAc,CAAE,IAAK,CAAC;MACvB,CAAG;MACH,iBAAgB6D,qBAAuB;MAAAhC,QAAA,EAErC,IAAAK,QAAE,EAAE,WAAY;IAAC,CACZ,CACR;EAAA,CACM,CAAC;AAEX,CAAC;AAAC,IAAA4C,QAAA,GAAAnB,OAAA,CAAAP,OAAA,GAEaJ,WAAW","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_dom","require","_components","_i18n","_blockEditor","_element","_coreData","_data","_icons","_compose","_lockUnlock","_pageCreator","_jsxRuntime","PrivateQuickInserter","QuickInserter","unlock","blockEditorPrivateApis","getSuggestionsQuery","type","kind","subtype","initialSuggestionsSearchOptions","perPage","LinkUIBlockInserter","clientId","onBack","onBlockInsert","rootBlockClientId","useSelect","select","getBlockRootClientId","blockEditorStore","focusOnMountRef","useFocusOnMount","dialogTitleId","useInstanceId","LinkControl","dialogDescriptionId","jsxs","className","role","ref","children","VisuallyHidden","jsx","id","__","Button","icon","isRTL","chevronRightSmall","chevronLeftSmall","onClick","e","preventDefault","size","rootClientId","isAppender","prioritizePatterns","selectBlockOnInsert","onSelect","undefined","hasSearch","UnforwardedLinkUI","props","label","url","opensInNewTab","link","postType","addingBlock","setAddingBlock","useState","addingPage","setAddingPage","focusAddBlockButton","setFocusAddBlockButton","focusAddPageButton","setFocusAddPageButton","permissions","useResourcePermissions","name","useMemo","title","stripHTML","handlePageCreated","pageLink","onChange","LinkUI","blockEditingMode","useBlockEditingMode","Popover","placement","onClose","anchor","shift","hasTextControl","hasRichPreviews","value","showInitialSuggestions","withCreateSuggestion","noDirectEntry","noURLSuggestion","suggestionsQuery","onRemove","onCancel","renderControlBottom","length","LinkUITools","canCreatePage","canCreate","LinkUIPageCreator","onPageCreated","initialTitle","exports","forwardRef","blockInserterAriaRole","addBlockButtonRef","useRef","addPageButtonRef","useEffect","current","focus","__experimentalVStack","spacing","__next40pxDefaultSize","plus","_default","default"],"sources":["@wordpress/block-library/src/navigation-link/link-ui.js"],"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 { __, isRTL } from '@wordpress/i18n';\nimport {\n\tLinkControl,\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n\tuseBlockEditingMode,\n} 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 { useSelect } from '@wordpress/data';\nimport { chevronLeftSmall, chevronRightSmall, plus } from '@wordpress/icons';\nimport { useInstanceId, useFocusOnMount } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../lock-unlock';\nimport { LinkUIPageCreator } from './page-creator';\n\nconst { PrivateQuickInserter: QuickInserter } = unlock(\n\tblockEditorPrivateApis\n);\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 LinkUIBlockInserter( { clientId, onBack, onBlockInsert } ) {\n\tconst { rootBlockClientId } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockRootClientId } = select( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\trootBlockClientId: getBlockRootClientId( clientId ),\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst focusOnMountRef = useFocusOnMount( 'firstElement' );\n\n\tconst dialogTitleId = useInstanceId(\n\t\tLinkControl,\n\t\t`link-ui-block-inserter__title`\n\t);\n\tconst dialogDescriptionId = useInstanceId(\n\t\tLinkControl,\n\t\t`link-ui-block-inserter__description`\n\t);\n\n\tif ( ! clientId ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"link-ui-block-inserter\"\n\t\t\trole=\"dialog\"\n\t\t\taria-labelledby={ dialogTitleId }\n\t\t\taria-describedby={ dialogDescriptionId }\n\t\t\tref={ focusOnMountRef }\n\t\t>\n\t\t\t<VisuallyHidden>\n\t\t\t\t<h2 id={ dialogTitleId }>{ __( 'Add block' ) }</h2>\n\n\t\t\t\t<p id={ dialogDescriptionId }>\n\t\t\t\t\t{ __( 'Choose a block to add to your Navigation.' ) }\n\t\t\t\t</p>\n\t\t\t</VisuallyHidden>\n\n\t\t\t<Button\n\t\t\t\tclassName=\"link-ui-block-inserter__back\"\n\t\t\t\ticon={ isRTL() ? chevronRightSmall : chevronLeftSmall }\n\t\t\t\tonClick={ ( e ) => {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\tonBack();\n\t\t\t\t} }\n\t\t\t\tsize=\"small\"\n\t\t\t>\n\t\t\t\t{ __( 'Back' ) }\n\t\t\t</Button>\n\n\t\t\t<QuickInserter\n\t\t\t\trootClientId={ rootBlockClientId }\n\t\t\t\tclientId={ clientId }\n\t\t\t\tisAppender={ false }\n\t\t\t\tprioritizePatterns={ false }\n\t\t\t\tselectBlockOnInsert={ ! onBlockInsert }\n\t\t\t\tonSelect={ onBlockInsert ? onBlockInsert : undefined }\n\t\t\t\thasSearch={ false }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nfunction UnforwardedLinkUI( props, ref ) {\n\tconst { label, url, opensInNewTab, type, kind } = props.link;\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// 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} ),\n\t\t[ label, opensInNewTab, url ]\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\trenderControlBottom={ () =>\n\t\t\t\t\t\t\t! link?.url?.length && (\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\tcanCreatePage={ permissions.canCreate }\n\t\t\t\t\t\t\t\t\tblockEditingMode={ blockEditingMode }\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\tcanCreatePage,\n\tblockEditingMode,\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\treturn (\n\t\t<VStack spacing={ 0 } className=\"link-ui-tools\">\n\t\t\t{ canCreatePage && (\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{ blockEditingMode === 'default' && (\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"],"mappings":";;;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAMA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAMA,IAAAI,QAAA,GAAAJ,OAAA;AAOA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,QAAA,GAAAR,OAAA;AAKA,IAAAS,WAAA,GAAAT,OAAA;AACA,IAAAU,YAAA,GAAAV,OAAA;AAAmD,IAAAW,WAAA,GAAAX,OAAA;AAjCnD;AACA;AACA;;AA2BA;AACA;AACA;;AAIA,MAAM;EAAEY,oBAAoB,EAAEC;AAAc,CAAC,GAAG,IAAAC,kBAAM,EACrDC,wBACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,mBAAmBA,CAAEC,IAAI,EAAEC,IAAI,EAAG;EACjD,QAASD,IAAI;IACZ,KAAK,MAAM;IACX,KAAK,MAAM;MACV,OAAO;QAAEA,IAAI,EAAE,MAAM;QAAEE,OAAO,EAAEF;MAAK,CAAC;IACvC,KAAK,UAAU;MACd,OAAO;QAAEA,IAAI,EAAE,MAAM;QAAEE,OAAO,EAAE;MAAW,CAAC;IAC7C,KAAK,KAAK;MACT,OAAO;QAAEF,IAAI,EAAE,MAAM;QAAEE,OAAO,EAAE;MAAW,CAAC;IAC7C,KAAK,aAAa;MACjB,OAAO;QAAEF,IAA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AC;AAEX,CAAC;AAAC,IAAAiF,QAAA,GAAAb,OAAA,CAAAc,OAAA,GAEapB,WAAW","ignoreList":[]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -11,16 +10,13 @@ var _data = require("@wordpress/data");
|
|
|
11
10
|
var _coreData = require("@wordpress/core-data");
|
|
12
11
|
var _htmlEntities = require("@wordpress/html-entities");
|
|
13
12
|
var _element = require("@wordpress/element");
|
|
14
|
-
var
|
|
13
|
+
var _icons = require("@wordpress/icons");
|
|
14
|
+
var _compose = require("@wordpress/compose");
|
|
15
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
16
|
/**
|
|
17
17
|
* WordPress dependencies
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
/**
|
|
21
|
-
* Internal dependencies
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
20
|
/**
|
|
25
21
|
* Component for creating new pages within the Navigation Link UI.
|
|
26
22
|
*
|
|
@@ -39,6 +35,9 @@ function LinkUIPageCreator({
|
|
|
39
35
|
const [title, setTitle] = (0, _element.useState)(initialTitle);
|
|
40
36
|
const [shouldPublish, setShouldPublish] = (0, _element.useState)(false);
|
|
41
37
|
|
|
38
|
+
// Focus the first element when the component mounts
|
|
39
|
+
const focusOnMountRef = (0, _compose.useFocusOnMount)('firstElement');
|
|
40
|
+
|
|
42
41
|
// Check if the title is valid for submission
|
|
43
42
|
const isTitleValid = title.trim().length > 0;
|
|
44
43
|
|
|
@@ -81,12 +80,19 @@ function LinkUIPageCreator({
|
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
const isSubmitDisabled = isSaving || !isTitleValid;
|
|
84
|
-
return /*#__PURE__*/(0, _jsxRuntime.
|
|
83
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
85
84
|
className: "link-ui-page-creator",
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
ref: focusOnMountRef,
|
|
86
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
87
|
+
className: "link-ui-page-creator__back",
|
|
88
|
+
icon: (0, _i18n.isRTL)() ? _icons.chevronRightSmall : _icons.chevronLeftSmall,
|
|
89
|
+
onClick: e => {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
onBack();
|
|
92
|
+
},
|
|
93
|
+
size: "small",
|
|
94
|
+
children: (0, _i18n.__)('Back')
|
|
95
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalVStack, {
|
|
90
96
|
className: "link-ui-page-creator__inner",
|
|
91
97
|
spacing: 4,
|
|
92
98
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("form", {
|
|
@@ -131,7 +137,7 @@ function LinkUIPageCreator({
|
|
|
131
137
|
})]
|
|
132
138
|
})
|
|
133
139
|
})
|
|
134
|
-
})
|
|
140
|
+
})]
|
|
135
141
|
});
|
|
136
142
|
}
|
|
137
143
|
//# sourceMappingURL=page-creator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_i18n","_data","_coreData","_htmlEntities","_element","
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_data","_coreData","_htmlEntities","_element","_icons","_compose","_jsxRuntime","LinkUIPageCreator","postType","onBack","onPageCreated","initialTitle","title","setTitle","useState","shouldPublish","setShouldPublish","focusOnMountRef","useFocusOnMount","isTitleValid","trim","length","lastError","isSaving","useSelect","select","coreStore","getLastEntitySaveError","isSavingEntityRecord","saveEntityRecord","useDispatch","createPage","event","preventDefault","savedRecord","status","throwOnError","pageLink","id","type","decodeEntities","rendered","url","link","kind","error","isSubmitDisabled","jsxs","className","ref","children","jsx","Button","icon","isRTL","chevronRightSmall","chevronLeftSmall","onClick","e","size","__","__experimentalVStack","spacing","onSubmit","TextControl","__next40pxDefaultSize","__nextHasNoMarginBottom","label","onChange","placeholder","value","CheckboxControl","help","checked","Notice","isDismissible","message","__experimentalHStack","justify","variant","disabled","accessibleWhenDisabled","isBusy"],"sources":["@wordpress/block-library/src/navigation-link/page-creator.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tTextControl,\n\tNotice,\n\tCheckboxControl,\n\t__experimentalVStack as VStack,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport { __, isRTL } from '@wordpress/i18n';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useState } from '@wordpress/element';\nimport { chevronLeftSmall, chevronRightSmall } from '@wordpress/icons';\nimport { useFocusOnMount } from '@wordpress/compose';\n\n/**\n * Component for creating new pages within the Navigation Link UI.\n *\n * @param {Object} props Component props.\n * @param {string} props.postType The post type to create.\n * @param {Function} props.onBack Callback when user wants to go back.\n * @param {Function} props.onPageCreated Callback when page is successfully created.\n * @param {string} [props.initialTitle] Initial title to pre-fill the form.\n */\nexport function LinkUIPageCreator( {\n\tpostType,\n\tonBack,\n\tonPageCreated,\n\tinitialTitle = '',\n} ) {\n\tconst [ title, setTitle ] = useState( initialTitle );\n\tconst [ shouldPublish, setShouldPublish ] = useState( false );\n\n\t// Focus the first element when the component mounts\n\tconst focusOnMountRef = useFocusOnMount( 'firstElement' );\n\n\t// Check if the title is valid for submission\n\tconst isTitleValid = title.trim().length > 0;\n\n\t// Get the last created entity record (without ID) to track creation state\n\tconst { lastError, isSaving } = useSelect(\n\t\t( select ) => ( {\n\t\t\tlastError: select( coreStore ).getLastEntitySaveError(\n\t\t\t\t'postType',\n\t\t\t\tpostType\n\t\t\t),\n\t\t\tisSaving: select( coreStore ).isSavingEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType\n\t\t\t),\n\t\t} ),\n\t\t[ postType ]\n\t);\n\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\n\tasync function createPage( event ) {\n\t\tevent.preventDefault();\n\t\tif ( isSaving || ! isTitleValid ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst savedRecord = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tpostType,\n\t\t\t\t{\n\t\t\t\t\ttitle,\n\t\t\t\t\tstatus: shouldPublish ? 'publish' : 'draft',\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\tif ( savedRecord ) {\n\t\t\t\t// Create the page link object from the saved record\n\t\t\t\tconst pageLink = {\n\t\t\t\t\tid: savedRecord.id,\n\t\t\t\t\ttype: postType,\n\t\t\t\t\ttitle: decodeEntities( savedRecord.title.rendered ),\n\t\t\t\t\turl: savedRecord.link,\n\t\t\t\t\tkind: 'post-type',\n\t\t\t\t};\n\n\t\t\t\tonPageCreated( pageLink );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\t// Error handling is done via the data store selectors\n\t\t}\n\t}\n\n\tconst isSubmitDisabled = isSaving || ! isTitleValid;\n\n\treturn (\n\t\t<div className=\"link-ui-page-creator\" ref={ focusOnMountRef }>\n\t\t\t<Button\n\t\t\t\tclassName=\"link-ui-page-creator__back\"\n\t\t\t\ticon={ isRTL() ? chevronRightSmall : chevronLeftSmall }\n\t\t\t\tonClick={ ( e ) => {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\tonBack();\n\t\t\t\t} }\n\t\t\t\tsize=\"small\"\n\t\t\t>\n\t\t\t\t{ __( 'Back' ) }\n\t\t\t</Button>\n\n\t\t\t<VStack className=\"link-ui-page-creator__inner\" spacing={ 4 }>\n\t\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t\t<VStack spacing={ 4 }>\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ __( 'Title' ) }\n\t\t\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\t\t\tplaceholder={ __( 'No title' ) }\n\t\t\t\t\t\t\tvalue={ title }\n\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t<CheckboxControl\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ __( 'Publish immediately' ) }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'If unchecked, the page will be created as a draft.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tchecked={ shouldPublish }\n\t\t\t\t\t\t\tonChange={ setShouldPublish }\n\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t{ lastError && (\n\t\t\t\t\t\t\t<Notice status=\"error\" isDismissible={ false }>\n\t\t\t\t\t\t\t\t{ lastError.message }\n\t\t\t\t\t\t\t</Notice>\n\t\t\t\t\t\t) }\n\n\t\t\t\t\t\t<HStack spacing={ 2 } justify=\"flex-end\">\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\tonClick={ onBack }\n\t\t\t\t\t\t\t\tdisabled={ isSaving }\n\t\t\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\t\tisBusy={ isSaving }\n\t\t\t\t\t\t\t\taria-disabled={ isSubmitDisabled }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Create page' ) }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t</HStack>\n\t\t\t\t\t</VStack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C,UAAU;cAClBtB,OAAO,EAAGhD,MAAQ;cAClBuE,QAAQ,EAAGzD,QAAU;cACrB0D,sBAAsB;cAAA/B,QAAA,EAEpB,IAAAU,QAAE,EAAE,QAAS;YAAC,CACT,CAAC,eACT,IAAAtD,WAAA,CAAA6C,GAAA,EAACtD,WAAA,CAAAuD,MAAM;cACNa,qBAAqB;cACrBc,OAAO,EAAC,SAAS;cACjBxC,IAAI,EAAC,QAAQ;cACb2C,MAAM,EAAG3D,QAAU;cACnB,iBAAgBuB,gBAAkB;cAAAI,QAAA,EAEhC,IAAAU,QAAE,EAAE,aAAc;YAAC,CACd,CAAC;UAAA,CACF,CAAC;QAAA,CACF;MAAC,CACJ;IAAC,CACA,CAAC;EAAA,CACL,CAAC;AAER","ignoreList":[]}
|
|
@@ -3,18 +3,23 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
|
|
5
5
|
import { Popover, Button, VisuallyHidden, __experimentalVStack as VStack } from '@wordpress/components';
|
|
6
|
-
import { __ } from '@wordpress/i18n';
|
|
7
|
-
import { LinkControl, useBlockEditingMode } from '@wordpress/block-editor';
|
|
6
|
+
import { __, isRTL } from '@wordpress/i18n';
|
|
7
|
+
import { LinkControl, store as blockEditorStore, privateApis as blockEditorPrivateApis, useBlockEditingMode } from '@wordpress/block-editor';
|
|
8
8
|
import { useMemo, useState, useRef, useEffect, forwardRef } from '@wordpress/element';
|
|
9
9
|
import { useResourcePermissions } from '@wordpress/core-data';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { useSelect } from '@wordpress/data';
|
|
11
|
+
import { chevronLeftSmall, chevronRightSmall, plus } from '@wordpress/icons';
|
|
12
|
+
import { useInstanceId, useFocusOnMount } from '@wordpress/compose';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Internal dependencies
|
|
15
16
|
*/
|
|
17
|
+
import { unlock } from '../lock-unlock';
|
|
16
18
|
import { LinkUIPageCreator } from './page-creator';
|
|
17
|
-
import
|
|
19
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
const {
|
|
21
|
+
PrivateQuickInserter: QuickInserter
|
|
22
|
+
} = unlock(blockEditorPrivateApis);
|
|
18
23
|
|
|
19
24
|
/**
|
|
20
25
|
* Given the Link block's type attribute, return the query params to give to
|
|
@@ -24,7 +29,6 @@ import LinkUIBlockInserter from './block-inserter';
|
|
|
24
29
|
* @param {string} kind Link block's entity of kind (post-type|taxonomy)
|
|
25
30
|
* @return {{ type?: string, subtype?: string }} Search query params.
|
|
26
31
|
*/
|
|
27
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
28
32
|
export function getSuggestionsQuery(type, kind) {
|
|
29
33
|
switch (type) {
|
|
30
34
|
case 'post':
|
|
@@ -71,6 +75,61 @@ export function getSuggestionsQuery(type, kind) {
|
|
|
71
75
|
};
|
|
72
76
|
}
|
|
73
77
|
}
|
|
78
|
+
function LinkUIBlockInserter({
|
|
79
|
+
clientId,
|
|
80
|
+
onBack,
|
|
81
|
+
onBlockInsert
|
|
82
|
+
}) {
|
|
83
|
+
const {
|
|
84
|
+
rootBlockClientId
|
|
85
|
+
} = useSelect(select => {
|
|
86
|
+
const {
|
|
87
|
+
getBlockRootClientId
|
|
88
|
+
} = select(blockEditorStore);
|
|
89
|
+
return {
|
|
90
|
+
rootBlockClientId: getBlockRootClientId(clientId)
|
|
91
|
+
};
|
|
92
|
+
}, [clientId]);
|
|
93
|
+
const focusOnMountRef = useFocusOnMount('firstElement');
|
|
94
|
+
const dialogTitleId = useInstanceId(LinkControl, `link-ui-block-inserter__title`);
|
|
95
|
+
const dialogDescriptionId = useInstanceId(LinkControl, `link-ui-block-inserter__description`);
|
|
96
|
+
if (!clientId) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
100
|
+
className: "link-ui-block-inserter",
|
|
101
|
+
role: "dialog",
|
|
102
|
+
"aria-labelledby": dialogTitleId,
|
|
103
|
+
"aria-describedby": dialogDescriptionId,
|
|
104
|
+
ref: focusOnMountRef,
|
|
105
|
+
children: [/*#__PURE__*/_jsxs(VisuallyHidden, {
|
|
106
|
+
children: [/*#__PURE__*/_jsx("h2", {
|
|
107
|
+
id: dialogTitleId,
|
|
108
|
+
children: __('Add block')
|
|
109
|
+
}), /*#__PURE__*/_jsx("p", {
|
|
110
|
+
id: dialogDescriptionId,
|
|
111
|
+
children: __('Choose a block to add to your Navigation.')
|
|
112
|
+
})]
|
|
113
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
114
|
+
className: "link-ui-block-inserter__back",
|
|
115
|
+
icon: isRTL() ? chevronRightSmall : chevronLeftSmall,
|
|
116
|
+
onClick: e => {
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
onBack();
|
|
119
|
+
},
|
|
120
|
+
size: "small",
|
|
121
|
+
children: __('Back')
|
|
122
|
+
}), /*#__PURE__*/_jsx(QuickInserter, {
|
|
123
|
+
rootClientId: rootBlockClientId,
|
|
124
|
+
clientId: clientId,
|
|
125
|
+
isAppender: false,
|
|
126
|
+
prioritizePatterns: false,
|
|
127
|
+
selectBlockOnInsert: !onBlockInsert,
|
|
128
|
+
onSelect: onBlockInsert ? onBlockInsert : undefined,
|
|
129
|
+
hasSearch: false
|
|
130
|
+
})]
|
|
131
|
+
});
|
|
132
|
+
}
|
|
74
133
|
function UnforwardedLinkUI(props, ref) {
|
|
75
134
|
const {
|
|
76
135
|
label,
|
|
@@ -102,8 +161,8 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
102
161
|
// Return to main Link UI
|
|
103
162
|
setAddingPage(false);
|
|
104
163
|
};
|
|
105
|
-
const dialogTitleId = useInstanceId(LinkUI,
|
|
106
|
-
const dialogDescriptionId = useInstanceId(LinkUI,
|
|
164
|
+
const dialogTitleId = useInstanceId(LinkUI, `link-ui-link-control__title`);
|
|
165
|
+
const dialogDescriptionId = useInstanceId(LinkUI, `link-ui-link-control__description`);
|
|
107
166
|
const blockEditingMode = useBlockEditingMode();
|
|
108
167
|
return /*#__PURE__*/_jsxs(Popover, {
|
|
109
168
|
ref: ref,
|
|
@@ -135,26 +194,20 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
135
194
|
onChange: props.onChange,
|
|
136
195
|
onRemove: props.onRemove,
|
|
137
196
|
onCancel: props.onCancel,
|
|
138
|
-
renderControlBottom: () => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
setFocusAddPageButton(false);
|
|
153
|
-
},
|
|
154
|
-
canAddPage: permissions?.canCreate && type === 'page',
|
|
155
|
-
canAddBlock: blockEditingMode === 'default'
|
|
156
|
-
});
|
|
157
|
-
}
|
|
197
|
+
renderControlBottom: () => !link?.url?.length && /*#__PURE__*/_jsx(LinkUITools, {
|
|
198
|
+
focusAddBlockButton: focusAddBlockButton,
|
|
199
|
+
focusAddPageButton: focusAddPageButton,
|
|
200
|
+
setAddingBlock: () => {
|
|
201
|
+
setAddingBlock(true);
|
|
202
|
+
setFocusAddBlockButton(false);
|
|
203
|
+
},
|
|
204
|
+
setAddingPage: () => {
|
|
205
|
+
setAddingPage(true);
|
|
206
|
+
setFocusAddPageButton(false);
|
|
207
|
+
},
|
|
208
|
+
canCreatePage: permissions.canCreate,
|
|
209
|
+
blockEditingMode: blockEditingMode
|
|
210
|
+
})
|
|
158
211
|
})]
|
|
159
212
|
}), addingBlock && /*#__PURE__*/_jsx(LinkUIBlockInserter, {
|
|
160
213
|
clientId: props.clientId,
|
|
@@ -182,8 +235,8 @@ const LinkUITools = ({
|
|
|
182
235
|
setAddingPage,
|
|
183
236
|
focusAddBlockButton,
|
|
184
237
|
focusAddPageButton,
|
|
185
|
-
|
|
186
|
-
|
|
238
|
+
canCreatePage,
|
|
239
|
+
blockEditingMode
|
|
187
240
|
}) => {
|
|
188
241
|
const blockInserterAriaRole = 'listbox';
|
|
189
242
|
const addBlockButtonRef = useRef();
|
|
@@ -202,15 +255,10 @@ const LinkUITools = ({
|
|
|
202
255
|
addPageButtonRef.current?.focus();
|
|
203
256
|
}
|
|
204
257
|
}, [focusAddPageButton]);
|
|
205
|
-
|
|
206
|
-
// Don't render anything if neither button should be shown
|
|
207
|
-
if (!canAddPage && !canAddBlock) {
|
|
208
|
-
return null;
|
|
209
|
-
}
|
|
210
258
|
return /*#__PURE__*/_jsxs(VStack, {
|
|
211
259
|
spacing: 0,
|
|
212
260
|
className: "link-ui-tools",
|
|
213
|
-
children: [
|
|
261
|
+
children: [canCreatePage && /*#__PURE__*/_jsx(Button, {
|
|
214
262
|
__next40pxDefaultSize: true,
|
|
215
263
|
ref: addPageButtonRef,
|
|
216
264
|
icon: plus,
|
|
@@ -220,7 +268,7 @@ const LinkUITools = ({
|
|
|
220
268
|
},
|
|
221
269
|
"aria-haspopup": blockInserterAriaRole,
|
|
222
270
|
children: __('Create page')
|
|
223
|
-
}),
|
|
271
|
+
}), blockEditingMode === 'default' && /*#__PURE__*/_jsx(Button, {
|
|
224
272
|
__next40pxDefaultSize: true,
|
|
225
273
|
ref: addBlockButtonRef,
|
|
226
274
|
icon: plus,
|