@wordpress/block-library 9.30.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/accordion-content/edit.js +8 -8
- package/build/accordion-content/edit.js.map +1 -1
- package/build/accordion-content/index.js +2 -1
- package/build/accordion-content/index.js.map +1 -1
- package/build/accordion-panel/index.js +2 -1
- package/build/accordion-panel/index.js.map +1 -1
- package/build/navigation/constants.js +5 -1
- package/build/navigation/constants.js.map +1 -1
- package/build/navigation/edit/index.js +45 -1
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/leaf-more-menu.js +0 -1
- package/build/navigation/edit/leaf-more-menu.js.map +1 -1
- package/build/navigation/edit/menu-inspector-controls.js +40 -5
- package/build/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build/navigation-link/link-ui.js +64 -56
- package/build/navigation-link/link-ui.js.map +1 -1
- package/build/navigation-link/page-creator.js +143 -0
- package/build/navigation-link/page-creator.js.map +1 -0
- package/build/search/edit.js +22 -14
- package/build/search/edit.js.map +1 -1
- package/build-module/accordion-content/edit.js +8 -8
- package/build-module/accordion-content/edit.js.map +1 -1
- package/build-module/accordion-content/index.js +2 -1
- package/build-module/accordion-content/index.js.map +1 -1
- package/build-module/accordion-panel/index.js +2 -1
- package/build-module/accordion-panel/index.js.map +1 -1
- package/build-module/navigation/constants.js +5 -1
- package/build-module/navigation/constants.js.map +1 -1
- package/build-module/navigation/edit/index.js +50 -4
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/leaf-more-menu.js +0 -1
- package/build-module/navigation/edit/leaf-more-menu.js.map +1 -1
- package/build-module/navigation/edit/menu-inspector-controls.js +40 -5
- package/build-module/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build-module/navigation-link/link-ui.js +68 -60
- package/build-module/navigation-link/link-ui.js.map +1 -1
- package/build-module/navigation-link/page-creator.js +137 -0
- package/build-module/navigation-link/page-creator.js.map +1 -0
- package/build-module/search/edit.js +22 -14
- package/build-module/search/edit.js.map +1 -1
- package/build-style/accordion/style-rtl.css +5 -6
- package/build-style/accordion/style.css +5 -6
- package/build-style/editor-rtl.css +14 -0
- package/build-style/editor.css +14 -0
- package/build-style/form-input/style-rtl.css +4 -3
- package/build-style/form-input/style.css +4 -3
- package/build-style/navigation-link/editor-rtl.css +14 -0
- package/build-style/navigation-link/editor.css +14 -0
- package/build-style/navigation-link/style-rtl.css +1 -1
- package/build-style/navigation-link/style.css +1 -1
- package/build-style/post-comments-form/style-rtl.css +8 -5
- package/build-style/post-comments-form/style.css +8 -5
- package/build-style/search/style-rtl.css +11 -12
- package/build-style/search/style.css +11 -12
- package/build-style/style-rtl.css +29 -27
- package/build-style/style.css +29 -27
- package/package.json +35 -35
- package/src/accordion/style.scss +6 -6
- package/src/accordion-content/block.json +2 -1
- package/src/accordion-content/edit.js +21 -27
- package/src/accordion-panel/block.json +2 -1
- package/src/cover/test/edit.js +1 -5
- package/src/form-input/style.scss +3 -2
- package/src/navigation/constants.js +4 -0
- package/src/navigation/edit/index.js +50 -1
- package/src/navigation/edit/leaf-more-menu.js +0 -1
- package/src/navigation/edit/menu-inspector-controls.js +40 -5
- package/src/navigation-link/editor.scss +17 -0
- package/src/navigation-link/link-ui.js +88 -81
- package/src/navigation-link/page-creator.js +164 -0
- package/src/navigation-link/style.scss +1 -1
- package/src/post-comments-form/style.scss +11 -11
- package/src/search/edit.js +44 -13
- package/src/search/index.php +16 -2
- package/src/search/style.scss +15 -16
|
@@ -3,12 +3,11 @@
|
|
|
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 { __,
|
|
6
|
+
import { __, isRTL } from '@wordpress/i18n';
|
|
7
7
|
import { LinkControl, store as blockEditorStore, privateApis as blockEditorPrivateApis, useBlockEditingMode } from '@wordpress/block-editor';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
8
|
+
import { useMemo, useState, useRef, useEffect, forwardRef } from '@wordpress/element';
|
|
9
|
+
import { useResourcePermissions } from '@wordpress/core-data';
|
|
10
|
+
import { useSelect } from '@wordpress/data';
|
|
12
11
|
import { chevronLeftSmall, chevronRightSmall, plus } from '@wordpress/icons';
|
|
13
12
|
import { useInstanceId, useFocusOnMount } from '@wordpress/compose';
|
|
14
13
|
|
|
@@ -16,6 +15,7 @@ import { useInstanceId, useFocusOnMount } from '@wordpress/compose';
|
|
|
16
15
|
* Internal dependencies
|
|
17
16
|
*/
|
|
18
17
|
import { unlock } from '../lock-unlock';
|
|
18
|
+
import { LinkUIPageCreator } from './page-creator';
|
|
19
19
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
20
|
const {
|
|
21
21
|
PrivateQuickInserter: QuickInserter
|
|
@@ -77,7 +77,8 @@ export function getSuggestionsQuery(type, kind) {
|
|
|
77
77
|
}
|
|
78
78
|
function LinkUIBlockInserter({
|
|
79
79
|
clientId,
|
|
80
|
-
onBack
|
|
80
|
+
onBack,
|
|
81
|
+
onBlockInsert
|
|
81
82
|
}) {
|
|
82
83
|
const {
|
|
83
84
|
rootBlockClientId
|
|
@@ -123,7 +124,8 @@ function LinkUIBlockInserter({
|
|
|
123
124
|
clientId: clientId,
|
|
124
125
|
isAppender: false,
|
|
125
126
|
prioritizePatterns: false,
|
|
126
|
-
selectBlockOnInsert:
|
|
127
|
+
selectBlockOnInsert: !onBlockInsert,
|
|
128
|
+
onSelect: onBlockInsert ? onBlockInsert : undefined,
|
|
127
129
|
hasSearch: false
|
|
128
130
|
})]
|
|
129
131
|
});
|
|
@@ -138,42 +140,14 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
138
140
|
} = props.link;
|
|
139
141
|
const postType = type || 'page';
|
|
140
142
|
const [addingBlock, setAddingBlock] = useState(false);
|
|
143
|
+
const [addingPage, setAddingPage] = useState(false);
|
|
141
144
|
const [focusAddBlockButton, setFocusAddBlockButton] = useState(false);
|
|
142
|
-
const
|
|
143
|
-
saveEntityRecord
|
|
144
|
-
} = useDispatch(coreStore);
|
|
145
|
+
const [focusAddPageButton, setFocusAddPageButton] = useState(false);
|
|
145
146
|
const permissions = useResourcePermissions({
|
|
146
147
|
kind: 'postType',
|
|
147
148
|
name: postType
|
|
148
149
|
});
|
|
149
150
|
|
|
150
|
-
// Check if we're in contentOnly mode
|
|
151
|
-
const blockEditingMode = useBlockEditingMode();
|
|
152
|
-
const isDefaultBlockEditingMode = blockEditingMode === 'default';
|
|
153
|
-
async function handleCreate(pageTitle) {
|
|
154
|
-
const page = await saveEntityRecord('postType', postType, {
|
|
155
|
-
title: pageTitle,
|
|
156
|
-
status: 'draft'
|
|
157
|
-
});
|
|
158
|
-
return {
|
|
159
|
-
id: page.id,
|
|
160
|
-
type: postType,
|
|
161
|
-
// Make `title` property consistent with that in `fetchLinkSuggestions` where the `rendered` title (containing HTML entities)
|
|
162
|
-
// is also being decoded. By being consistent in both locations we avoid having to branch in the rendering output code.
|
|
163
|
-
// Ideally in the future we will update both APIs to utilise the "raw" form of the title which is better suited to edit contexts.
|
|
164
|
-
// e.g.
|
|
165
|
-
// - title.raw = "Yes & No"
|
|
166
|
-
// - title.rendered = "Yes & No"
|
|
167
|
-
// - decodeEntities( title.rendered ) = "Yes & No"
|
|
168
|
-
// See:
|
|
169
|
-
// - https://github.com/WordPress/gutenberg/pull/41063
|
|
170
|
-
// - https://github.com/WordPress/gutenberg/blob/a1e1fdc0e6278457e9f4fc0b31ac6d2095f5450b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js#L212-L218
|
|
171
|
-
title: decodeEntities(page.title.rendered),
|
|
172
|
-
url: page.link,
|
|
173
|
-
kind: 'post-type'
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
151
|
// Memoize link value to avoid overriding the LinkControl's internal state.
|
|
178
152
|
// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.
|
|
179
153
|
const link = useMemo(() => ({
|
|
@@ -181,15 +155,22 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
181
155
|
opensInNewTab,
|
|
182
156
|
title: label && stripHTML(label)
|
|
183
157
|
}), [label, opensInNewTab, url]);
|
|
158
|
+
const handlePageCreated = pageLink => {
|
|
159
|
+
// Set the new page as the current link
|
|
160
|
+
props.onChange(pageLink);
|
|
161
|
+
// Return to main Link UI
|
|
162
|
+
setAddingPage(false);
|
|
163
|
+
};
|
|
184
164
|
const dialogTitleId = useInstanceId(LinkUI, `link-ui-link-control__title`);
|
|
185
165
|
const dialogDescriptionId = useInstanceId(LinkUI, `link-ui-link-control__description`);
|
|
166
|
+
const blockEditingMode = useBlockEditingMode();
|
|
186
167
|
return /*#__PURE__*/_jsxs(Popover, {
|
|
187
168
|
ref: ref,
|
|
188
169
|
placement: "bottom",
|
|
189
170
|
onClose: props.onClose,
|
|
190
171
|
anchor: props.anchor,
|
|
191
172
|
shift: true,
|
|
192
|
-
children: [!addingBlock && /*#__PURE__*/_jsxs("div", {
|
|
173
|
+
children: [!addingBlock && !addingPage && /*#__PURE__*/_jsxs("div", {
|
|
193
174
|
role: "dialog",
|
|
194
175
|
"aria-labelledby": dialogTitleId,
|
|
195
176
|
"aria-describedby": dialogDescriptionId,
|
|
@@ -206,33 +187,26 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
206
187
|
hasRichPreviews: true,
|
|
207
188
|
value: link,
|
|
208
189
|
showInitialSuggestions: true,
|
|
209
|
-
withCreateSuggestion:
|
|
210
|
-
createSuggestion: handleCreate,
|
|
211
|
-
createSuggestionButtonText: searchTerm => {
|
|
212
|
-
let format;
|
|
213
|
-
if (type === 'post') {
|
|
214
|
-
/* translators: %s: search term. */
|
|
215
|
-
format = __('Create draft post: <mark>%s</mark>');
|
|
216
|
-
} else {
|
|
217
|
-
/* translators: %s: search term. */
|
|
218
|
-
format = __('Create draft page: <mark>%s</mark>');
|
|
219
|
-
}
|
|
220
|
-
return createInterpolateElement(sprintf(format, searchTerm), {
|
|
221
|
-
mark: /*#__PURE__*/_jsx("mark", {})
|
|
222
|
-
});
|
|
223
|
-
},
|
|
190
|
+
withCreateSuggestion: false,
|
|
224
191
|
noDirectEntry: !!type,
|
|
225
192
|
noURLSuggestion: !!type,
|
|
226
193
|
suggestionsQuery: getSuggestionsQuery(type, kind),
|
|
227
194
|
onChange: props.onChange,
|
|
228
195
|
onRemove: props.onRemove,
|
|
229
196
|
onCancel: props.onCancel,
|
|
230
|
-
renderControlBottom: () => !link?.url?.length &&
|
|
197
|
+
renderControlBottom: () => !link?.url?.length && /*#__PURE__*/_jsx(LinkUITools, {
|
|
231
198
|
focusAddBlockButton: focusAddBlockButton,
|
|
199
|
+
focusAddPageButton: focusAddPageButton,
|
|
232
200
|
setAddingBlock: () => {
|
|
233
201
|
setAddingBlock(true);
|
|
234
202
|
setFocusAddBlockButton(false);
|
|
235
|
-
}
|
|
203
|
+
},
|
|
204
|
+
setAddingPage: () => {
|
|
205
|
+
setAddingPage(true);
|
|
206
|
+
setFocusAddPageButton(false);
|
|
207
|
+
},
|
|
208
|
+
canCreatePage: permissions.canCreate,
|
|
209
|
+
blockEditingMode: blockEditingMode
|
|
236
210
|
})
|
|
237
211
|
})]
|
|
238
212
|
}), addingBlock && /*#__PURE__*/_jsx(LinkUIBlockInserter, {
|
|
@@ -240,17 +214,33 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
240
214
|
onBack: () => {
|
|
241
215
|
setAddingBlock(false);
|
|
242
216
|
setFocusAddBlockButton(true);
|
|
243
|
-
|
|
217
|
+
setFocusAddPageButton(false);
|
|
218
|
+
},
|
|
219
|
+
onBlockInsert: props?.onBlockInsert
|
|
220
|
+
}), addingPage && /*#__PURE__*/_jsx(LinkUIPageCreator, {
|
|
221
|
+
postType: postType,
|
|
222
|
+
onBack: () => {
|
|
223
|
+
setAddingPage(false);
|
|
224
|
+
setFocusAddPageButton(true);
|
|
225
|
+
setFocusAddBlockButton(false);
|
|
226
|
+
},
|
|
227
|
+
onPageCreated: handlePageCreated,
|
|
228
|
+
initialTitle: link?.url || ''
|
|
244
229
|
})]
|
|
245
230
|
});
|
|
246
231
|
}
|
|
247
232
|
export const LinkUI = forwardRef(UnforwardedLinkUI);
|
|
248
233
|
const LinkUITools = ({
|
|
249
234
|
setAddingBlock,
|
|
250
|
-
|
|
235
|
+
setAddingPage,
|
|
236
|
+
focusAddBlockButton,
|
|
237
|
+
focusAddPageButton,
|
|
238
|
+
canCreatePage,
|
|
239
|
+
blockEditingMode
|
|
251
240
|
}) => {
|
|
252
241
|
const blockInserterAriaRole = 'listbox';
|
|
253
242
|
const addBlockButtonRef = useRef();
|
|
243
|
+
const addPageButtonRef = useRef();
|
|
254
244
|
|
|
255
245
|
// Focus the add block button when the popover is opened.
|
|
256
246
|
useEffect(() => {
|
|
@@ -258,9 +248,27 @@ const LinkUITools = ({
|
|
|
258
248
|
addBlockButtonRef.current?.focus();
|
|
259
249
|
}
|
|
260
250
|
}, [focusAddBlockButton]);
|
|
261
|
-
|
|
251
|
+
|
|
252
|
+
// Focus the add page button when the popover is opened.
|
|
253
|
+
useEffect(() => {
|
|
254
|
+
if (focusAddPageButton) {
|
|
255
|
+
addPageButtonRef.current?.focus();
|
|
256
|
+
}
|
|
257
|
+
}, [focusAddPageButton]);
|
|
258
|
+
return /*#__PURE__*/_jsxs(VStack, {
|
|
259
|
+
spacing: 0,
|
|
262
260
|
className: "link-ui-tools",
|
|
263
|
-
children: /*#__PURE__*/_jsx(Button, {
|
|
261
|
+
children: [canCreatePage && /*#__PURE__*/_jsx(Button, {
|
|
262
|
+
__next40pxDefaultSize: true,
|
|
263
|
+
ref: addPageButtonRef,
|
|
264
|
+
icon: plus,
|
|
265
|
+
onClick: e => {
|
|
266
|
+
e.preventDefault();
|
|
267
|
+
setAddingPage(true);
|
|
268
|
+
},
|
|
269
|
+
"aria-haspopup": blockInserterAriaRole,
|
|
270
|
+
children: __('Create page')
|
|
271
|
+
}), blockEditingMode === 'default' && /*#__PURE__*/_jsx(Button, {
|
|
264
272
|
__next40pxDefaultSize: true,
|
|
265
273
|
ref: addBlockButtonRef,
|
|
266
274
|
icon: plus,
|
|
@@ -270,7 +278,7 @@ const LinkUITools = ({
|
|
|
270
278
|
},
|
|
271
279
|
"aria-haspopup": blockInserterAriaRole,
|
|
272
280
|
children: __('Add block')
|
|
273
|
-
})
|
|
281
|
+
})]
|
|
274
282
|
});
|
|
275
283
|
};
|
|
276
284
|
export default LinkUITools;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__unstableStripHTML","stripHTML","Popover","Button","VisuallyHidden","__experimentalVStack","VStack","__","sprintf","isRTL","LinkControl","store","blockEditorStore","privateApis","blockEditorPrivateApis","useBlockEditingMode","createInterpolateElement","useMemo","useState","useRef","useEffect","forwardRef","coreStore","useResourcePermissions","decodeEntities","useSelect","useDispatch","chevronLeftSmall","chevronRightSmall","plus","useInstanceId","useFocusOnMount","unlock","jsx","_jsx","jsxs","_jsxs","PrivateQuickInserter","QuickInserter","getSuggestionsQuery","type","kind","subtype","initialSuggestionsSearchOptions","perPage","LinkUIBlockInserter","clientId","onBack","rootBlockClientId","select","getBlockRootClientId","focusOnMountRef","dialogTitleId","dialogDescriptionId","className","role","ref","children","id","icon","onClick","e","preventDefault","size","rootClientId","isAppender","prioritizePatterns","selectBlockOnInsert","hasSearch","UnforwardedLinkUI","props","label","url","opensInNewTab","link","postType","addingBlock","setAddingBlock","focusAddBlockButton","setFocusAddBlockButton","saveEntityRecord","permissions","name","blockEditingMode","isDefaultBlockEditingMode","handleCreate","pageTitle","page","title","status","rendered","LinkUI","placement","onClose","anchor","shift","hasTextControl","hasRichPreviews","value","showInitialSuggestions","withCreateSuggestion","canCreate","createSuggestion","createSuggestionButtonText","searchTerm","format","mark","noDirectEntry","noURLSuggestion","suggestionsQuery","onChange","onRemove","onCancel","renderControlBottom","length","LinkUITools","blockInserterAriaRole","addBlockButtonRef","current","focus","__next40pxDefaultSize"],"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 { __, sprintf, isRTL } from '@wordpress/i18n';\nimport {\n\tLinkControl,\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n\tuseBlockEditingMode,\n} from '@wordpress/block-editor';\nimport {\n\tcreateInterpolateElement,\n\tuseMemo,\n\tuseState,\n\tuseRef,\n\tuseEffect,\n\tforwardRef,\n} from '@wordpress/element';\nimport {\n\tstore as coreStore,\n\tuseResourcePermissions,\n} from '@wordpress/core-data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useSelect, useDispatch } 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';\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 } ) {\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\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 [ focusAddBlockButton, setFocusAddBlockButton ] = useState( false );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst permissions = useResourcePermissions( {\n\t\tkind: 'postType',\n\t\tname: postType,\n\t} );\n\n\t// Check if we're in contentOnly mode\n\tconst blockEditingMode = useBlockEditingMode();\n\tconst isDefaultBlockEditingMode = blockEditingMode === 'default';\n\n\tasync function handleCreate( pageTitle ) {\n\t\tconst page = await saveEntityRecord( 'postType', postType, {\n\t\t\ttitle: pageTitle,\n\t\t\tstatus: 'draft',\n\t\t} );\n\n\t\treturn {\n\t\t\tid: page.id,\n\t\t\ttype: postType,\n\t\t\t// Make `title` property consistent with that in `fetchLinkSuggestions` where the `rendered` title (containing HTML entities)\n\t\t\t// is also being decoded. By being consistent in both locations we avoid having to branch in the rendering output code.\n\t\t\t// Ideally in the future we will update both APIs to utilise the \"raw\" form of the title which is better suited to edit contexts.\n\t\t\t// e.g.\n\t\t\t// - title.raw = \"Yes & No\"\n\t\t\t// - title.rendered = \"Yes & No\"\n\t\t\t// - decodeEntities( title.rendered ) = \"Yes & No\"\n\t\t\t// See:\n\t\t\t// - https://github.com/WordPress/gutenberg/pull/41063\n\t\t\t// - https://github.com/WordPress/gutenberg/blob/a1e1fdc0e6278457e9f4fc0b31ac6d2095f5450b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js#L212-L218\n\t\t\ttitle: decodeEntities( page.title.rendered ),\n\t\t\turl: page.link,\n\t\t\tkind: 'post-type',\n\t\t};\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 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\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 && (\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={ permissions.canCreate }\n\t\t\t\t\t\tcreateSuggestion={ handleCreate }\n\t\t\t\t\t\tcreateSuggestionButtonText={ ( searchTerm ) => {\n\t\t\t\t\t\t\tlet format;\n\n\t\t\t\t\t\t\tif ( type === 'post' ) {\n\t\t\t\t\t\t\t\t/* translators: %s: search term. */\n\t\t\t\t\t\t\t\tformat = __(\n\t\t\t\t\t\t\t\t\t'Create draft post: <mark>%s</mark>'\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t/* translators: %s: search term. */\n\t\t\t\t\t\t\t\tformat = __(\n\t\t\t\t\t\t\t\t\t'Create draft page: <mark>%s</mark>'\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn createInterpolateElement(\n\t\t\t\t\t\t\t\tsprintf( format, searchTerm ),\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tmark: <mark />,\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\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\tisDefaultBlockEditingMode && (\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\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/>\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} }\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 = ( { setAddingBlock, focusAddBlockButton } ) => {\n\tconst blockInserterAriaRole = 'listbox';\n\tconst addBlockButtonRef = 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\treturn (\n\t\t<VStack className=\"link-ui-tools\">\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tref={ addBlockButtonRef }\n\t\t\t\ticon={ plus }\n\t\t\t\tonClick={ ( e ) => {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\tsetAddingBlock( true );\n\t\t\t\t} }\n\t\t\t\taria-haspopup={ blockInserterAriaRole }\n\t\t\t>\n\t\t\t\t{ __( 'Add block' ) }\n\t\t\t</Button>\n\t\t</VStack>\n\t);\n};\n\nexport default LinkUITools;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,mBAAmB,IAAIC,SAAS,QAAQ,gBAAgB;AACjE,SACCC,OAAO,EACPC,MAAM,EACNC,cAAc,EACdC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAC9B,SAASC,EAAE,EAAEC,OAAO,EAAEC,KAAK,QAAQ,iBAAiB;AACpD,SACCC,WAAW,EACXC,KAAK,IAAIC,gBAAgB,EACzBC,WAAW,IAAIC,sBAAsB,EACrCC,mBAAmB,QACb,yBAAyB;AAChC,SACCC,wBAAwB,EACxBC,OAAO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E,IAAK,CAAC;MAC/B;IAAG,CACH,CACD;EAAA,CACO,CAAC;AAEZ;AAEA,OAAO,MAAMY,MAAM,GAAGtE,UAAU,CAAEgD,iBAAkB,CAAC;AAErD,MAAM8C,WAAW,GAAGA,CAAE;EAAEtC,cAAc;EAAEC;AAAoB,CAAC,KAAM;EAClE,MAAMsC,qBAAqB,GAAG,SAAS;EACvC,MAAMC,iBAAiB,GAAGlG,MAAM,CAAC,CAAC;;EAElC;EACAC,SAAS,CAAE,MAAM;IAChB,IAAK0D,mBAAmB,EAAG;MAC1BuC,iBAAiB,CAACC,OAAO,EAAEC,KAAK,CAAC,CAAC;IACnC;EACD,CAAC,EAAE,CAAEzC,mBAAmB,CAAG,CAAC;EAE5B,oBACC5C,IAAA,CAAC5B,MAAM;IAACgD,SAAS,EAAC,eAAe;IAAAG,QAAA,eAChCvB,IAAA,CAAC/B,MAAM;MACNqH,qBAAqB;MACrBhE,GAAG,EAAG6D,iBAAmB;MACzB1D,IAAI,EAAG9B,IAAM;MACb+B,OAAO,EAAKC,CAAC,IAAM;QAClBA,CAAC,CAACC,cAAc,CAAC,CAAC;QAClBe,cAAc,CAAE,IAAK,CAAC;MACvB,CAAG;MACH,iBAAgBuC,qBAAuB;MAAA3D,QAAA,EAErClD,EAAE,CAAE,WAAY;IAAC,CACZ;EAAC,CACF,CAAC;AAEX,CAAC;AAED,eAAe4G,WAAW","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["__unstableStripHTML","stripHTML","Popover","Button","VisuallyHidden","__experimentalVStack","VStack","__","isRTL","LinkControl","store","blockEditorStore","privateApis","blockEditorPrivateApis","useBlockEditingMode","useMemo","useState","useRef","useEffect","forwardRef","useResourcePermissions","useSelect","chevronLeftSmall","chevronRightSmall","plus","useInstanceId","useFocusOnMount","unlock","LinkUIPageCreator","jsx","_jsx","jsxs","_jsxs","PrivateQuickInserter","QuickInserter","getSuggestionsQuery","type","kind","subtype","initialSuggestionsSearchOptions","perPage","LinkUIBlockInserter","clientId","onBack","onBlockInsert","rootBlockClientId","select","getBlockRootClientId","focusOnMountRef","dialogTitleId","dialogDescriptionId","className","role","ref","children","id","icon","onClick","e","preventDefault","size","rootClientId","isAppender","prioritizePatterns","selectBlockOnInsert","onSelect","undefined","hasSearch","UnforwardedLinkUI","props","label","url","opensInNewTab","link","postType","addingBlock","setAddingBlock","addingPage","setAddingPage","focusAddBlockButton","setFocusAddBlockButton","focusAddPageButton","setFocusAddPageButton","permissions","name","title","handlePageCreated","pageLink","onChange","LinkUI","blockEditingMode","placement","onClose","anchor","shift","hasTextControl","hasRichPreviews","value","showInitialSuggestions","withCreateSuggestion","noDirectEntry","noURLSuggestion","suggestionsQuery","onRemove","onCancel","renderControlBottom","length","LinkUITools","canCreatePage","canCreate","onPageCreated","initialTitle","blockInserterAriaRole","addBlockButtonRef","addPageButtonRef","current","focus","spacing","__next40pxDefaultSize"],"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={ blockInserterAria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SAAS,EAAC,eAAe;IAAAG,QAAA,GAC5CsD,aAAa,iBACd9E,IAAA,CAAC3B,MAAM;MACNmH,qBAAqB;MACrBjE,GAAG,EAAG6D,gBAAkB;MACxB1D,IAAI,EAAGhC,IAAM;MACbiC,OAAO,EAAKC,CAAC,IAAM;QAClBA,CAAC,CAACC,cAAc,CAAC,CAAC;QAClBmB,aAAa,CAAE,IAAK,CAAC;MACtB,CAAG;MACH,iBAAgBkC,qBAAuB;MAAA1D,QAAA,EAErC/C,EAAE,CAAE,aAAc;IAAC,CACd,CACR,EACCmF,gBAAgB,KAAK,SAAS,iBAC/B5D,IAAA,CAAC3B,MAAM;MACNmH,qBAAqB;MACrBjE,GAAG,EAAG4D,iBAAmB;MACzBzD,IAAI,EAAGhC,IAAM;MACbiC,OAAO,EAAKC,CAAC,IAAM;QAClBA,CAAC,CAACC,cAAc,CAAC,CAAC;QAClBiB,cAAc,CAAE,IAAK,CAAC;MACvB,CAAG;MACH,iBAAgBoC,qBAAuB;MAAA1D,QAAA,EAErC/C,EAAE,CAAE,WAAY;IAAC,CACZ,CACR;EAAA,CACM,CAAC;AAEX,CAAC;AAED,eAAeoG,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Button, TextControl, Notice, CheckboxControl, __experimentalVStack as VStack, __experimentalHStack as HStack } from '@wordpress/components';
|
|
5
|
+
import { __, isRTL } from '@wordpress/i18n';
|
|
6
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
7
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
8
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
9
|
+
import { useState } from '@wordpress/element';
|
|
10
|
+
import { chevronLeftSmall, chevronRightSmall } from '@wordpress/icons';
|
|
11
|
+
import { useFocusOnMount } from '@wordpress/compose';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Component for creating new pages within the Navigation Link UI.
|
|
15
|
+
*
|
|
16
|
+
* @param {Object} props Component props.
|
|
17
|
+
* @param {string} props.postType The post type to create.
|
|
18
|
+
* @param {Function} props.onBack Callback when user wants to go back.
|
|
19
|
+
* @param {Function} props.onPageCreated Callback when page is successfully created.
|
|
20
|
+
* @param {string} [props.initialTitle] Initial title to pre-fill the form.
|
|
21
|
+
*/
|
|
22
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
23
|
+
export function LinkUIPageCreator({
|
|
24
|
+
postType,
|
|
25
|
+
onBack,
|
|
26
|
+
onPageCreated,
|
|
27
|
+
initialTitle = ''
|
|
28
|
+
}) {
|
|
29
|
+
const [title, setTitle] = useState(initialTitle);
|
|
30
|
+
const [shouldPublish, setShouldPublish] = useState(false);
|
|
31
|
+
|
|
32
|
+
// Focus the first element when the component mounts
|
|
33
|
+
const focusOnMountRef = useFocusOnMount('firstElement');
|
|
34
|
+
|
|
35
|
+
// Check if the title is valid for submission
|
|
36
|
+
const isTitleValid = title.trim().length > 0;
|
|
37
|
+
|
|
38
|
+
// Get the last created entity record (without ID) to track creation state
|
|
39
|
+
const {
|
|
40
|
+
lastError,
|
|
41
|
+
isSaving
|
|
42
|
+
} = useSelect(select => ({
|
|
43
|
+
lastError: select(coreStore).getLastEntitySaveError('postType', postType),
|
|
44
|
+
isSaving: select(coreStore).isSavingEntityRecord('postType', postType)
|
|
45
|
+
}), [postType]);
|
|
46
|
+
const {
|
|
47
|
+
saveEntityRecord
|
|
48
|
+
} = useDispatch(coreStore);
|
|
49
|
+
async function createPage(event) {
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
if (isSaving || !isTitleValid) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const savedRecord = await saveEntityRecord('postType', postType, {
|
|
56
|
+
title,
|
|
57
|
+
status: shouldPublish ? 'publish' : 'draft'
|
|
58
|
+
}, {
|
|
59
|
+
throwOnError: true
|
|
60
|
+
});
|
|
61
|
+
if (savedRecord) {
|
|
62
|
+
// Create the page link object from the saved record
|
|
63
|
+
const pageLink = {
|
|
64
|
+
id: savedRecord.id,
|
|
65
|
+
type: postType,
|
|
66
|
+
title: decodeEntities(savedRecord.title.rendered),
|
|
67
|
+
url: savedRecord.link,
|
|
68
|
+
kind: 'post-type'
|
|
69
|
+
};
|
|
70
|
+
onPageCreated(pageLink);
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
// Error handling is done via the data store selectors
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const isSubmitDisabled = isSaving || !isTitleValid;
|
|
77
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
78
|
+
className: "link-ui-page-creator",
|
|
79
|
+
ref: focusOnMountRef,
|
|
80
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
81
|
+
className: "link-ui-page-creator__back",
|
|
82
|
+
icon: isRTL() ? chevronRightSmall : chevronLeftSmall,
|
|
83
|
+
onClick: e => {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
onBack();
|
|
86
|
+
},
|
|
87
|
+
size: "small",
|
|
88
|
+
children: __('Back')
|
|
89
|
+
}), /*#__PURE__*/_jsx(VStack, {
|
|
90
|
+
className: "link-ui-page-creator__inner",
|
|
91
|
+
spacing: 4,
|
|
92
|
+
children: /*#__PURE__*/_jsx("form", {
|
|
93
|
+
onSubmit: createPage,
|
|
94
|
+
children: /*#__PURE__*/_jsxs(VStack, {
|
|
95
|
+
spacing: 4,
|
|
96
|
+
children: [/*#__PURE__*/_jsx(TextControl, {
|
|
97
|
+
__next40pxDefaultSize: true,
|
|
98
|
+
__nextHasNoMarginBottom: true,
|
|
99
|
+
label: __('Title'),
|
|
100
|
+
onChange: setTitle,
|
|
101
|
+
placeholder: __('No title'),
|
|
102
|
+
value: title
|
|
103
|
+
}), /*#__PURE__*/_jsx(CheckboxControl, {
|
|
104
|
+
__nextHasNoMarginBottom: true,
|
|
105
|
+
label: __('Publish immediately'),
|
|
106
|
+
help: __('If unchecked, the page will be created as a draft.'),
|
|
107
|
+
checked: shouldPublish,
|
|
108
|
+
onChange: setShouldPublish
|
|
109
|
+
}), lastError && /*#__PURE__*/_jsx(Notice, {
|
|
110
|
+
status: "error",
|
|
111
|
+
isDismissible: false,
|
|
112
|
+
children: lastError.message
|
|
113
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
114
|
+
spacing: 2,
|
|
115
|
+
justify: "flex-end",
|
|
116
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
117
|
+
__next40pxDefaultSize: true,
|
|
118
|
+
variant: "tertiary",
|
|
119
|
+
onClick: onBack,
|
|
120
|
+
disabled: isSaving,
|
|
121
|
+
accessibleWhenDisabled: true,
|
|
122
|
+
children: __('Cancel')
|
|
123
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
124
|
+
__next40pxDefaultSize: true,
|
|
125
|
+
variant: "primary",
|
|
126
|
+
type: "submit",
|
|
127
|
+
isBusy: isSaving,
|
|
128
|
+
"aria-disabled": isSubmitDisabled,
|
|
129
|
+
children: __('Create page')
|
|
130
|
+
})]
|
|
131
|
+
})]
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
})]
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=page-creator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Button","TextControl","Notice","CheckboxControl","__experimentalVStack","VStack","__experimentalHStack","HStack","__","isRTL","useSelect","useDispatch","store","coreStore","decodeEntities","useState","chevronLeftSmall","chevronRightSmall","useFocusOnMount","jsx","_jsx","jsxs","_jsxs","LinkUIPageCreator","postType","onBack","onPageCreated","initialTitle","title","setTitle","shouldPublish","setShouldPublish","focusOnMountRef","isTitleValid","trim","length","lastError","isSaving","select","getLastEntitySaveError","isSavingEntityRecord","saveEntityRecord","createPage","event","preventDefault","savedRecord","status","throwOnError","pageLink","id","type","rendered","url","link","kind","error","isSubmitDisabled","className","ref","children","icon","onClick","e","size","spacing","onSubmit","__next40pxDefaultSize","__nextHasNoMarginBottom","label","onChange","placeholder","value","help","checked","isDismissible","message","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>\n\t\t\t\t</form>\n\t\t\t</VStack>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3B,IAAI,EAAC,QAAQ;cACb8B,MAAM,EAAG3C,QAAU;cACnB,iBAAgBmB,gBAAkB;cAAAG,QAAA,EAEhCnD,EAAE,CAAE,aAAc;YAAC,CACd,CAAC;UAAA,CACF,CAAC;QAAA,CACF;MAAC,CACJ;IAAC,CACA,CAAC;EAAA,CACL,CAAC;AAER","ignoreList":[]}
|
|
@@ -155,7 +155,11 @@ export default function SearchEdit({
|
|
|
155
155
|
const textFieldClasses = clsx('wp-block-search__input', isButtonPositionInside ? undefined : borderProps.className, typographyProps.className);
|
|
156
156
|
const textFieldStyles = {
|
|
157
157
|
...(isButtonPositionInside ? {
|
|
158
|
-
borderRadius
|
|
158
|
+
borderRadius: borderProps.style?.borderRadius,
|
|
159
|
+
borderTopLeftRadius: borderProps.style?.borderTopLeftRadius,
|
|
160
|
+
borderTopRightRadius: borderProps.style?.borderTopRightRadius,
|
|
161
|
+
borderBottomLeftRadius: borderProps.style?.borderBottomLeftRadius,
|
|
162
|
+
borderBottomRightRadius: borderProps.style?.borderBottomRightRadius
|
|
159
163
|
} : borderProps.style),
|
|
160
164
|
...typographyProps.style,
|
|
161
165
|
textDecoration: undefined
|
|
@@ -184,7 +188,11 @@ export default function SearchEdit({
|
|
|
184
188
|
...colorProps.style,
|
|
185
189
|
...typographyProps.style,
|
|
186
190
|
...(isButtonPositionInside ? {
|
|
187
|
-
borderRadius
|
|
191
|
+
borderRadius: borderProps.style?.borderRadius,
|
|
192
|
+
borderTopLeftRadius: borderProps.style?.borderTopLeftRadius,
|
|
193
|
+
borderTopRightRadius: borderProps.style?.borderTopRightRadius,
|
|
194
|
+
borderBottomLeftRadius: borderProps.style?.borderBottomLeftRadius,
|
|
195
|
+
borderBottomRightRadius: borderProps.style?.borderBottomRightRadius
|
|
188
196
|
} : borderProps.style)
|
|
189
197
|
};
|
|
190
198
|
const handleButtonClick = () => {
|
|
@@ -353,7 +361,8 @@ export default function SearchEdit({
|
|
|
353
361
|
})
|
|
354
362
|
})
|
|
355
363
|
});
|
|
356
|
-
const
|
|
364
|
+
const isNonZeroBorderRadius = radius => radius !== undefined && parseInt(radius, 10) !== 0;
|
|
365
|
+
const padBorderRadius = radius => isNonZeroBorderRadius(radius) ? `calc(${radius} + ${DEFAULT_INNER_PADDING})` : undefined;
|
|
357
366
|
const getWrapperStyles = () => {
|
|
358
367
|
const styles = isButtonPositionInside ? borderProps.style : {
|
|
359
368
|
borderRadius: borderProps.style?.borderRadius,
|
|
@@ -362,8 +371,7 @@ export default function SearchEdit({
|
|
|
362
371
|
borderBottomLeftRadius: borderProps.style?.borderBottomLeftRadius,
|
|
363
372
|
borderBottomRightRadius: borderProps.style?.borderBottomRightRadius
|
|
364
373
|
};
|
|
365
|
-
|
|
366
|
-
if (isButtonPositionInside && isNonZeroBorderRadius) {
|
|
374
|
+
if (isButtonPositionInside) {
|
|
367
375
|
// We have button inside wrapper and a border radius value to apply.
|
|
368
376
|
// Add default padding so we don't get "fat" corners.
|
|
369
377
|
//
|
|
@@ -373,17 +381,17 @@ export default function SearchEdit({
|
|
|
373
381
|
if (typeof borderRadius === 'object') {
|
|
374
382
|
// Individual corner border radii present.
|
|
375
383
|
const {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
} =
|
|
384
|
+
borderTopLeftRadius,
|
|
385
|
+
borderTopRightRadius,
|
|
386
|
+
borderBottomLeftRadius,
|
|
387
|
+
borderBottomRightRadius
|
|
388
|
+
} = borderProps.style;
|
|
381
389
|
return {
|
|
382
390
|
...styles,
|
|
383
|
-
borderTopLeftRadius: padBorderRadius(
|
|
384
|
-
borderTopRightRadius: padBorderRadius(
|
|
385
|
-
borderBottomLeftRadius: padBorderRadius(
|
|
386
|
-
borderBottomRightRadius: padBorderRadius(
|
|
391
|
+
borderTopLeftRadius: padBorderRadius(borderTopLeftRadius),
|
|
392
|
+
borderTopRightRadius: padBorderRadius(borderTopRightRadius),
|
|
393
|
+
borderBottomLeftRadius: padBorderRadius(borderBottomLeftRadius),
|
|
394
|
+
borderBottomRightRadius: padBorderRadius(borderBottomRightRadius)
|
|
387
395
|
};
|
|
388
396
|
}
|
|
389
397
|
|