@wordpress/block-library 9.29.1-next.f34ab90e9.0 → 9.30.1-next.6870dfe5b.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/CHANGELOG.md +2 -0
- package/build/accordion/edit.js +18 -1
- package/build/accordion/edit.js.map +1 -1
- package/build/accordion/index.js +0 -3
- package/build/accordion/index.js.map +1 -1
- package/build/accordion-content/edit.js +8 -8
- package/build/accordion-content/edit.js.map +1 -1
- package/build/accordion-content/index.js +2 -5
- package/build/accordion-content/index.js.map +1 -1
- package/build/accordion-header/index.js +0 -4
- package/build/accordion-header/index.js.map +1 -1
- package/build/accordion-panel/edit.js +5 -30
- package/build/accordion-panel/edit.js.map +1 -1
- package/build/accordion-panel/index.js +2 -5
- package/build/accordion-panel/index.js.map +1 -1
- package/build/accordion-panel/save.js +3 -29
- package/build/accordion-panel/save.js.map +1 -1
- package/build/audio/edit.js +3 -1
- package/build/audio/edit.js.map +1 -1
- package/build/gallery/index.js +2 -1
- package/build/gallery/index.js.map +1 -1
- package/build/group/variations.js +0 -12
- package/build/group/variations.js.map +1 -1
- package/build/image/image.js +1 -1
- package/build/image/image.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/block-inserter.js +69 -0
- package/build/navigation-link/block-inserter.js.map +1 -0
- package/build/navigation-link/dialog-wrapper.js +80 -0
- package/build/navigation-link/dialog-wrapper.js.map +1 -0
- package/build/navigation-link/link-ui.js +80 -116
- package/build/navigation-link/link-ui.js.map +1 -1
- package/build/navigation-link/page-creator.js +137 -0
- package/build/navigation-link/page-creator.js.map +1 -0
- package/build/query/edit/index.js.map +1 -1
- package/build/query/edit/query-content.js +7 -6
- package/build/query/edit/query-content.js.map +1 -1
- package/build/query/edit/query-placeholder.js +30 -9
- package/build/query/edit/query-placeholder.js.map +1 -1
- package/build/query/edit/query-toolbar.js +4 -2
- package/build/query/edit/query-toolbar.js.map +1 -1
- package/build/search/edit.js +22 -14
- package/build/search/edit.js.map +1 -1
- package/build/template-part/edit/placeholder.js +2 -1
- package/build/template-part/edit/placeholder.js.map +1 -1
- package/build/video/edit.js +3 -1
- package/build/video/edit.js.map +1 -1
- package/build-module/accordion/edit.js +20 -3
- package/build-module/accordion/edit.js.map +1 -1
- package/build-module/accordion/index.js +0 -3
- package/build-module/accordion/index.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 -5
- package/build-module/accordion-content/index.js.map +1 -1
- package/build-module/accordion-header/index.js +0 -4
- package/build-module/accordion-header/index.js.map +1 -1
- package/build-module/accordion-panel/edit.js +6 -29
- package/build-module/accordion-panel/edit.js.map +1 -1
- package/build-module/accordion-panel/index.js +2 -5
- package/build-module/accordion-panel/index.js.map +1 -1
- package/build-module/accordion-panel/save.js +4 -28
- package/build-module/accordion-panel/save.js.map +1 -1
- package/build-module/audio/edit.js +4 -2
- package/build-module/audio/edit.js.map +1 -1
- package/build-module/gallery/index.js +2 -1
- package/build-module/gallery/index.js.map +1 -1
- package/build-module/group/variations.js +0 -12
- package/build-module/group/variations.js.map +1 -1
- package/build-module/image/image.js +1 -1
- package/build-module/image/image.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/block-inserter.js +61 -0
- package/build-module/navigation-link/block-inserter.js.map +1 -0
- package/build-module/navigation-link/dialog-wrapper.js +75 -0
- package/build-module/navigation-link/dialog-wrapper.js.map +1 -0
- package/build-module/navigation-link/link-ui.js +85 -121
- package/build-module/navigation-link/link-ui.js.map +1 -1
- package/build-module/navigation-link/page-creator.js +130 -0
- package/build-module/navigation-link/page-creator.js.map +1 -0
- package/build-module/query/edit/index.js.map +1 -1
- package/build-module/query/edit/query-content.js +8 -7
- package/build-module/query/edit/query-content.js.map +1 -1
- package/build-module/query/edit/query-placeholder.js +30 -10
- package/build-module/query/edit/query-placeholder.js.map +1 -1
- package/build-module/query/edit/query-toolbar.js +4 -2
- package/build-module/query/edit/query-toolbar.js.map +1 -1
- package/build-module/search/edit.js +22 -14
- package/build-module/search/edit.js.map +1 -1
- package/build-module/template-part/edit/placeholder.js +2 -1
- package/build-module/template-part/edit/placeholder.js.map +1 -1
- package/build-module/video/edit.js +4 -2
- package/build-module/video/edit.js.map +1 -1
- package/build-style/accordion/style-rtl.css +8 -18
- package/build-style/accordion/style.css +8 -18
- package/build-style/editor-rtl.css +18 -0
- package/build-style/editor.css +18 -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/query/editor-rtl.css +4 -0
- package/build-style/query/editor.css +4 -0
- package/build-style/search/style-rtl.css +11 -12
- package/build-style/search/style.css +11 -12
- package/build-style/style-rtl.css +32 -40
- package/build-style/style.css +32 -40
- package/package.json +35 -35
- package/src/accordion/block.json +0 -3
- package/src/accordion/edit.js +20 -0
- package/src/accordion/style.scss +12 -21
- package/src/accordion-content/block.json +2 -4
- package/src/accordion-content/edit.js +21 -27
- package/src/accordion-content/index.js +0 -1
- package/src/accordion-header/block.json +0 -3
- package/src/accordion-header/index.js +0 -1
- package/src/accordion-panel/block.json +2 -4
- package/src/accordion-panel/edit.js +11 -51
- package/src/accordion-panel/index.js +0 -1
- package/src/accordion-panel/save.js +4 -45
- package/src/audio/edit.js +6 -1
- package/src/cover/test/edit.js +1 -5
- package/src/form-input/style.scss +3 -2
- package/src/gallery/block.json +2 -1
- package/src/gallery/index.php +1 -1
- package/src/gallery/test/helpers.native.js +3 -3
- package/src/group/variations.js +0 -12
- package/src/image/image.js +2 -1
- 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/block-inserter.js +65 -0
- package/src/navigation-link/dialog-wrapper.js +74 -0
- package/src/navigation-link/editor.scss +17 -0
- package/src/navigation-link/link-ui.js +108 -158
- package/src/navigation-link/page-creator.js +157 -0
- package/src/navigation-link/style.scss +1 -1
- package/src/post-comments-form/style.scss +11 -11
- package/src/post-date/index.php +2 -1
- package/src/query/edit/index.js +1 -0
- package/src/query/edit/query-content.js +8 -4
- package/src/query/edit/query-placeholder.js +47 -17
- package/src/query/edit/query-toolbar.js +10 -2
- package/src/query/editor.scss +6 -1
- package/src/search/edit.js +44 -13
- package/src/search/index.php +16 -2
- package/src/search/style.scss +15 -16
- package/src/template-part/edit/placeholder.js +2 -1
- package/src/video/edit.js +6 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _components = require("@wordpress/components");
|
|
8
|
+
var _i18n = require("@wordpress/i18n");
|
|
9
|
+
var _icons = require("@wordpress/icons");
|
|
10
|
+
var _compose = require("@wordpress/compose");
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
/**
|
|
13
|
+
* WordPress dependencies
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Shared BackButton component for consistent navigation across LinkUI sub-components.
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} props Component props.
|
|
20
|
+
* @param {string} props.className CSS class name for the button.
|
|
21
|
+
* @param {Function} props.onBack Callback when user wants to go back.
|
|
22
|
+
*/function BackButton({
|
|
23
|
+
className,
|
|
24
|
+
onBack
|
|
25
|
+
}) {
|
|
26
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
27
|
+
className: className,
|
|
28
|
+
icon: (0, _i18n.isRTL)() ? _icons.chevronRightSmall : _icons.chevronLeftSmall,
|
|
29
|
+
onClick: e => {
|
|
30
|
+
e.preventDefault();
|
|
31
|
+
onBack();
|
|
32
|
+
},
|
|
33
|
+
size: "small",
|
|
34
|
+
children: (0, _i18n.__)('Back')
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Shared DialogWrapper component for consistent dialog structure across LinkUI sub-components.
|
|
40
|
+
*
|
|
41
|
+
* @param {Object} props Component props.
|
|
42
|
+
* @param {string} props.className CSS class name for the dialog container.
|
|
43
|
+
* @param {string} props.title Dialog title for accessibility.
|
|
44
|
+
* @param {string} props.description Dialog description for accessibility.
|
|
45
|
+
* @param {Function} props.onBack Callback when user wants to go back.
|
|
46
|
+
* @param {Object} props.children Child components to render inside the dialog.
|
|
47
|
+
*/
|
|
48
|
+
function DialogWrapper({
|
|
49
|
+
className,
|
|
50
|
+
title,
|
|
51
|
+
description,
|
|
52
|
+
onBack,
|
|
53
|
+
children
|
|
54
|
+
}) {
|
|
55
|
+
const dialogTitleId = (0, _compose.useInstanceId)(DialogWrapper, 'link-ui-dialog-title');
|
|
56
|
+
const dialogDescriptionId = (0, _compose.useInstanceId)(DialogWrapper, 'link-ui-dialog-description');
|
|
57
|
+
const focusOnMountRef = (0, _compose.useFocusOnMount)('firstElement');
|
|
58
|
+
const backButtonClassName = `${className}__back`;
|
|
59
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
60
|
+
className: className,
|
|
61
|
+
role: "dialog",
|
|
62
|
+
"aria-labelledby": dialogTitleId,
|
|
63
|
+
"aria-describedby": dialogDescriptionId,
|
|
64
|
+
ref: focusOnMountRef,
|
|
65
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.VisuallyHidden, {
|
|
66
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
|
|
67
|
+
id: dialogTitleId,
|
|
68
|
+
children: title
|
|
69
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
70
|
+
id: dialogDescriptionId,
|
|
71
|
+
children: description
|
|
72
|
+
})]
|
|
73
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(BackButton, {
|
|
74
|
+
className: backButtonClassName,
|
|
75
|
+
onBack: onBack
|
|
76
|
+
}), children]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
var _default = exports.default = DialogWrapper;
|
|
80
|
+
//# sourceMappingURL=dialog-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_icons","_compose","_jsxRuntime","BackButton","className","onBack","jsx","Button","icon","isRTL","chevronRightSmall","chevronLeftSmall","onClick","e","preventDefault","size","children","__","DialogWrapper","title","description","dialogTitleId","useInstanceId","dialogDescriptionId","focusOnMountRef","useFocusOnMount","backButtonClassName","jsxs","role","ref","VisuallyHidden","id","_default","exports","default"],"sources":["@wordpress/block-library/src/navigation-link/dialog-wrapper.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Button, VisuallyHidden } from '@wordpress/components';\nimport { __, isRTL } from '@wordpress/i18n';\nimport { chevronLeftSmall, chevronRightSmall } from '@wordpress/icons';\nimport { useInstanceId, useFocusOnMount } from '@wordpress/compose';\n\n/**\n * Shared BackButton component for consistent navigation across LinkUI sub-components.\n *\n * @param {Object} props Component props.\n * @param {string} props.className CSS class name for the button.\n * @param {Function} props.onBack Callback when user wants to go back.\n */\nfunction BackButton( { className, onBack } ) {\n\treturn (\n\t\t<Button\n\t\t\tclassName={ className }\n\t\t\ticon={ isRTL() ? chevronRightSmall : chevronLeftSmall }\n\t\t\tonClick={ ( e ) => {\n\t\t\t\te.preventDefault();\n\t\t\t\tonBack();\n\t\t\t} }\n\t\t\tsize=\"small\"\n\t\t>\n\t\t\t{ __( 'Back' ) }\n\t\t</Button>\n\t);\n}\n\n/**\n * Shared DialogWrapper component for consistent dialog structure across LinkUI sub-components.\n *\n * @param {Object} props Component props.\n * @param {string} props.className CSS class name for the dialog container.\n * @param {string} props.title Dialog title for accessibility.\n * @param {string} props.description Dialog description for accessibility.\n * @param {Function} props.onBack Callback when user wants to go back.\n * @param {Object} props.children Child components to render inside the dialog.\n */\nfunction DialogWrapper( { className, title, description, onBack, children } ) {\n\tconst dialogTitleId = useInstanceId(\n\t\tDialogWrapper,\n\t\t'link-ui-dialog-title'\n\t);\n\tconst dialogDescriptionId = useInstanceId(\n\t\tDialogWrapper,\n\t\t'link-ui-dialog-description'\n\t);\n\tconst focusOnMountRef = useFocusOnMount( 'firstElement' );\n\tconst backButtonClassName = `${ className }__back`;\n\n\treturn (\n\t\t<div\n\t\t\tclassName={ className }\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 }>{ title }</h2>\n\t\t\t\t<p id={ dialogDescriptionId }>{ description }</p>\n\t\t\t</VisuallyHidden>\n\n\t\t\t<BackButton className={ backButtonClassName } onBack={ onBack } />\n\n\t\t\t{ children }\n\t\t</div>\n\t);\n}\n\nexport default DialogW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AR,QAAA,gBAEvB,IAAAd,WAAA,CAAAyB,IAAA,EAAC9B,WAAA,CAAAiC,cAAc;MAAAd,QAAA,gBACd,IAAAd,WAAA,CAAAI,GAAA;QAAIyB,EAAE,EAAGV,aAAe;QAAAL,QAAA,EAAGG;MAAK,CAAM,CAAC,eACvC,IAAAjB,WAAA,CAAAI,GAAA;QAAGyB,EAAE,EAAGR,mBAAqB;QAAAP,QAAA,EAAGI;MAAW,CAAK,CAAC;IAAA,CAClC,CAAC,eAEjB,IAAAlB,WAAA,CAAAI,GAAA,EAACH,UAAU;MAACC,SAAS,EAAGsB,mBAAqB;MAACrB,MAAM,EAAGA;IAAQ,CAAE,CAAC,EAEhEW,QAAQ;EAAA,CACN,CAAC;AAER;AAAC,IAAAgB,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEchB,aAAa","ignoreList":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
@@ -11,11 +12,10 @@ var _i18n = require("@wordpress/i18n");
|
|
|
11
12
|
var _blockEditor = require("@wordpress/block-editor");
|
|
12
13
|
var _element = require("@wordpress/element");
|
|
13
14
|
var _coreData = require("@wordpress/core-data");
|
|
14
|
-
var _htmlEntities = require("@wordpress/html-entities");
|
|
15
|
-
var _data = require("@wordpress/data");
|
|
16
15
|
var _icons = require("@wordpress/icons");
|
|
17
16
|
var _compose = require("@wordpress/compose");
|
|
18
|
-
var
|
|
17
|
+
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,10 +25,6 @@ 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
|
-
|
|
32
28
|
/**
|
|
33
29
|
* Given the Link block's type attribute, return the query params to give to
|
|
34
30
|
* /wp/v2/search.
|
|
@@ -83,59 +79,6 @@ function getSuggestionsQuery(type, kind) {
|
|
|
83
79
|
};
|
|
84
80
|
}
|
|
85
81
|
}
|
|
86
|
-
function LinkUIBlockInserter({
|
|
87
|
-
clientId,
|
|
88
|
-
onBack
|
|
89
|
-
}) {
|
|
90
|
-
const {
|
|
91
|
-
rootBlockClientId
|
|
92
|
-
} = (0, _data.useSelect)(select => {
|
|
93
|
-
const {
|
|
94
|
-
getBlockRootClientId
|
|
95
|
-
} = select(_blockEditor.store);
|
|
96
|
-
return {
|
|
97
|
-
rootBlockClientId: getBlockRootClientId(clientId)
|
|
98
|
-
};
|
|
99
|
-
}, [clientId]);
|
|
100
|
-
const focusOnMountRef = (0, _compose.useFocusOnMount)('firstElement');
|
|
101
|
-
const dialogTitleId = (0, _compose.useInstanceId)(_blockEditor.LinkControl, `link-ui-block-inserter__title`);
|
|
102
|
-
const dialogDescriptionId = (0, _compose.useInstanceId)(_blockEditor.LinkControl, `link-ui-block-inserter__description`);
|
|
103
|
-
if (!clientId) {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
107
|
-
className: "link-ui-block-inserter",
|
|
108
|
-
role: "dialog",
|
|
109
|
-
"aria-labelledby": dialogTitleId,
|
|
110
|
-
"aria-describedby": dialogDescriptionId,
|
|
111
|
-
ref: focusOnMountRef,
|
|
112
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.VisuallyHidden, {
|
|
113
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
|
|
114
|
-
id: dialogTitleId,
|
|
115
|
-
children: (0, _i18n.__)('Add block')
|
|
116
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
117
|
-
id: dialogDescriptionId,
|
|
118
|
-
children: (0, _i18n.__)('Choose a block to add to your Navigation.')
|
|
119
|
-
})]
|
|
120
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
121
|
-
className: "link-ui-block-inserter__back",
|
|
122
|
-
icon: (0, _i18n.isRTL)() ? _icons.chevronRightSmall : _icons.chevronLeftSmall,
|
|
123
|
-
onClick: e => {
|
|
124
|
-
e.preventDefault();
|
|
125
|
-
onBack();
|
|
126
|
-
},
|
|
127
|
-
size: "small",
|
|
128
|
-
children: (0, _i18n.__)('Back')
|
|
129
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(QuickInserter, {
|
|
130
|
-
rootClientId: rootBlockClientId,
|
|
131
|
-
clientId: clientId,
|
|
132
|
-
isAppender: false,
|
|
133
|
-
prioritizePatterns: false,
|
|
134
|
-
selectBlockOnInsert: true,
|
|
135
|
-
hasSearch: false
|
|
136
|
-
})]
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
82
|
function UnforwardedLinkUI(props, ref) {
|
|
140
83
|
const {
|
|
141
84
|
label,
|
|
@@ -146,37 +89,13 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
146
89
|
} = props.link;
|
|
147
90
|
const postType = type || 'page';
|
|
148
91
|
const [addingBlock, setAddingBlock] = (0, _element.useState)(false);
|
|
92
|
+
const [addingPage, setAddingPage] = (0, _element.useState)(false);
|
|
149
93
|
const [focusAddBlockButton, setFocusAddBlockButton] = (0, _element.useState)(false);
|
|
150
|
-
const
|
|
151
|
-
saveEntityRecord
|
|
152
|
-
} = (0, _data.useDispatch)(_coreData.store);
|
|
94
|
+
const [focusAddPageButton, setFocusAddPageButton] = (0, _element.useState)(false);
|
|
153
95
|
const permissions = (0, _coreData.useResourcePermissions)({
|
|
154
96
|
kind: 'postType',
|
|
155
97
|
name: postType
|
|
156
98
|
});
|
|
157
|
-
async function handleCreate(pageTitle) {
|
|
158
|
-
const page = await saveEntityRecord('postType', postType, {
|
|
159
|
-
title: pageTitle,
|
|
160
|
-
status: 'draft'
|
|
161
|
-
});
|
|
162
|
-
return {
|
|
163
|
-
id: page.id,
|
|
164
|
-
type: postType,
|
|
165
|
-
// Make `title` property consistent with that in `fetchLinkSuggestions` where the `rendered` title (containing HTML entities)
|
|
166
|
-
// is also being decoded. By being consistent in both locations we avoid having to branch in the rendering output code.
|
|
167
|
-
// Ideally in the future we will update both APIs to utilise the "raw" form of the title which is better suited to edit contexts.
|
|
168
|
-
// e.g.
|
|
169
|
-
// - title.raw = "Yes & No"
|
|
170
|
-
// - title.rendered = "Yes & No"
|
|
171
|
-
// - decodeEntities( title.rendered ) = "Yes & No"
|
|
172
|
-
// See:
|
|
173
|
-
// - https://github.com/WordPress/gutenberg/pull/41063
|
|
174
|
-
// - https://github.com/WordPress/gutenberg/blob/a1e1fdc0e6278457e9f4fc0b31ac6d2095f5450b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js#L212-L218
|
|
175
|
-
title: (0, _htmlEntities.decodeEntities)(page.title.rendered),
|
|
176
|
-
url: page.link,
|
|
177
|
-
kind: 'post-type'
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
99
|
|
|
181
100
|
// Memoize link value to avoid overriding the LinkControl's internal state.
|
|
182
101
|
// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.
|
|
@@ -185,15 +104,22 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
185
104
|
opensInNewTab,
|
|
186
105
|
title: label && (0, _dom.__unstableStripHTML)(label)
|
|
187
106
|
}), [label, opensInNewTab, url]);
|
|
188
|
-
const
|
|
189
|
-
|
|
107
|
+
const handlePageCreated = pageLink => {
|
|
108
|
+
// Set the new page as the current link
|
|
109
|
+
props.onChange(pageLink);
|
|
110
|
+
// Return to main Link UI
|
|
111
|
+
setAddingPage(false);
|
|
112
|
+
};
|
|
113
|
+
const dialogTitleId = (0, _compose.useInstanceId)(LinkUI, 'link-ui-link-control__title');
|
|
114
|
+
const dialogDescriptionId = (0, _compose.useInstanceId)(LinkUI, 'link-ui-link-control__description');
|
|
115
|
+
const blockEditingMode = (0, _blockEditor.useBlockEditingMode)();
|
|
190
116
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Popover, {
|
|
191
117
|
ref: ref,
|
|
192
118
|
placement: "bottom",
|
|
193
119
|
onClose: props.onClose,
|
|
194
120
|
anchor: props.anchor,
|
|
195
121
|
shift: true,
|
|
196
|
-
children: [!addingBlock && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
122
|
+
children: [!addingBlock && !addingPage && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
197
123
|
role: "dialog",
|
|
198
124
|
"aria-labelledby": dialogTitleId,
|
|
199
125
|
"aria-describedby": dialogDescriptionId,
|
|
@@ -210,51 +136,66 @@ function UnforwardedLinkUI(props, ref) {
|
|
|
210
136
|
hasRichPreviews: true,
|
|
211
137
|
value: link,
|
|
212
138
|
showInitialSuggestions: true,
|
|
213
|
-
withCreateSuggestion:
|
|
214
|
-
createSuggestion: handleCreate,
|
|
215
|
-
createSuggestionButtonText: searchTerm => {
|
|
216
|
-
let format;
|
|
217
|
-
if (type === 'post') {
|
|
218
|
-
/* translators: %s: search term. */
|
|
219
|
-
format = (0, _i18n.__)('Create draft post: <mark>%s</mark>');
|
|
220
|
-
} else {
|
|
221
|
-
/* translators: %s: search term. */
|
|
222
|
-
format = (0, _i18n.__)('Create draft page: <mark>%s</mark>');
|
|
223
|
-
}
|
|
224
|
-
return (0, _element.createInterpolateElement)((0, _i18n.sprintf)(format, searchTerm), {
|
|
225
|
-
mark: /*#__PURE__*/(0, _jsxRuntime.jsx)("mark", {})
|
|
226
|
-
});
|
|
227
|
-
},
|
|
139
|
+
withCreateSuggestion: false,
|
|
228
140
|
noDirectEntry: !!type,
|
|
229
141
|
noURLSuggestion: !!type,
|
|
230
142
|
suggestionsQuery: getSuggestionsQuery(type, kind),
|
|
231
143
|
onChange: props.onChange,
|
|
232
144
|
onRemove: props.onRemove,
|
|
233
145
|
onCancel: props.onCancel,
|
|
234
|
-
renderControlBottom: () =>
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
setFocusAddBlockButton(false);
|
|
146
|
+
renderControlBottom: () => {
|
|
147
|
+
// Don't show the tools when there is submitted link (preview state).
|
|
148
|
+
if (link?.url?.length) {
|
|
149
|
+
return null;
|
|
239
150
|
}
|
|
240
|
-
|
|
151
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkUITools, {
|
|
152
|
+
focusAddBlockButton: focusAddBlockButton,
|
|
153
|
+
focusAddPageButton: focusAddPageButton,
|
|
154
|
+
setAddingBlock: () => {
|
|
155
|
+
setAddingBlock(true);
|
|
156
|
+
setFocusAddBlockButton(false);
|
|
157
|
+
},
|
|
158
|
+
setAddingPage: () => {
|
|
159
|
+
setAddingPage(true);
|
|
160
|
+
setFocusAddPageButton(false);
|
|
161
|
+
},
|
|
162
|
+
canAddPage: permissions?.canCreate && type === 'page',
|
|
163
|
+
canAddBlock: blockEditingMode === 'default'
|
|
164
|
+
});
|
|
165
|
+
}
|
|
241
166
|
})]
|
|
242
|
-
}), addingBlock && /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
167
|
+
}), addingBlock && /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockInserter.default, {
|
|
243
168
|
clientId: props.clientId,
|
|
244
169
|
onBack: () => {
|
|
245
170
|
setAddingBlock(false);
|
|
246
171
|
setFocusAddBlockButton(true);
|
|
247
|
-
|
|
172
|
+
setFocusAddPageButton(false);
|
|
173
|
+
},
|
|
174
|
+
onBlockInsert: props?.onBlockInsert
|
|
175
|
+
}), addingPage && /*#__PURE__*/(0, _jsxRuntime.jsx)(_pageCreator.LinkUIPageCreator, {
|
|
176
|
+
postType: postType,
|
|
177
|
+
onBack: () => {
|
|
178
|
+
setAddingPage(false);
|
|
179
|
+
setFocusAddPageButton(true);
|
|
180
|
+
setFocusAddBlockButton(false);
|
|
181
|
+
},
|
|
182
|
+
onPageCreated: handlePageCreated,
|
|
183
|
+
initialTitle: link?.url || ''
|
|
248
184
|
})]
|
|
249
185
|
});
|
|
250
186
|
}
|
|
251
187
|
const LinkUI = exports.LinkUI = (0, _element.forwardRef)(UnforwardedLinkUI);
|
|
252
188
|
const LinkUITools = ({
|
|
253
189
|
setAddingBlock,
|
|
254
|
-
|
|
190
|
+
setAddingPage,
|
|
191
|
+
focusAddBlockButton,
|
|
192
|
+
focusAddPageButton,
|
|
193
|
+
canAddPage,
|
|
194
|
+
canAddBlock
|
|
255
195
|
}) => {
|
|
256
196
|
const blockInserterAriaRole = 'listbox';
|
|
257
197
|
const addBlockButtonRef = (0, _element.useRef)();
|
|
198
|
+
const addPageButtonRef = (0, _element.useRef)();
|
|
258
199
|
|
|
259
200
|
// Focus the add block button when the popover is opened.
|
|
260
201
|
(0, _element.useEffect)(() => {
|
|
@@ -262,9 +203,32 @@ const LinkUITools = ({
|
|
|
262
203
|
addBlockButtonRef.current?.focus();
|
|
263
204
|
}
|
|
264
205
|
}, [focusAddBlockButton]);
|
|
265
|
-
|
|
206
|
+
|
|
207
|
+
// Focus the add page button when the popover is opened.
|
|
208
|
+
(0, _element.useEffect)(() => {
|
|
209
|
+
if (focusAddPageButton) {
|
|
210
|
+
addPageButtonRef.current?.focus();
|
|
211
|
+
}
|
|
212
|
+
}, [focusAddPageButton]);
|
|
213
|
+
|
|
214
|
+
// Don't render anything if neither button should be shown
|
|
215
|
+
if (!canAddPage && !canAddBlock) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
219
|
+
spacing: 0,
|
|
266
220
|
className: "link-ui-tools",
|
|
267
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
221
|
+
children: [canAddPage && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
222
|
+
__next40pxDefaultSize: true,
|
|
223
|
+
ref: addPageButtonRef,
|
|
224
|
+
icon: _icons.plus,
|
|
225
|
+
onClick: e => {
|
|
226
|
+
e.preventDefault();
|
|
227
|
+
setAddingPage(true);
|
|
228
|
+
},
|
|
229
|
+
"aria-haspopup": blockInserterAriaRole,
|
|
230
|
+
children: (0, _i18n.__)('Create page')
|
|
231
|
+
}), canAddBlock && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
268
232
|
__next40pxDefaultSize: true,
|
|
269
233
|
ref: addBlockButtonRef,
|
|
270
234
|
icon: _icons.plus,
|
|
@@ -274,7 +238,7 @@ const LinkUITools = ({
|
|
|
274
238
|
},
|
|
275
239
|
"aria-haspopup": blockInserterAriaRole,
|
|
276
240
|
children: (0, _i18n.__)('Add block')
|
|
277
|
-
})
|
|
241
|
+
})]
|
|
278
242
|
});
|
|
279
243
|
};
|
|
280
244
|
var _default = exports.default = LinkUITools;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_dom","require","_components","_i18n","_blockEditor","_element","_coreData","_htmlEntities","_data","_icons","_compose","_lockUnlock","_jsxRuntime","PrivateQuickInserter","QuickInserter","unlock","blockEditorPrivateApis","getSuggestionsQuery","type","kind","subtype","initialSuggestionsSearchOptions","perPage","LinkUIBlockInserter","clientId","onBack","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","hasSearch","UnforwardedLinkUI","props","label","url","opensInNewTab","link","postType","addingBlock","setAddingBlock","useState","focusAddBlockButton","setFocusAddBlockButton","saveEntityRecord","useDispatch","coreStore","permissions","useResourcePermissions","name","handleCreate","pageTitle","page","title","status","decodeEntities","rendered","useMemo","stripHTML","LinkUI","Popover","placement","onClose","anchor","shift","hasTextControl","hasRichPreviews","value","showInitialSuggestions","withCreateSuggestion","canCreate","createSuggestion","createSuggestionButtonText","searchTerm","format","createInterpolateElement","sprintf","mark","noDirectEntry","noURLSuggestion","suggestionsQuery","onChange","onRemove","onCancel","renderControlBottom","length","LinkUITools","exports","forwardRef","blockInserterAriaRole","addBlockButtonRef","useRef","useEffect","current","focus","__experimentalVStack","__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 { __, sprintf, isRTL } from '@wordpress/i18n';\nimport {\n\tLinkControl,\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\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\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\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":";;;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAMA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAKA,IAAAI,QAAA,GAAAJ,OAAA;AAQA,I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+
{"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,EAAE,MAAM;QAAEE,OAAO,EAAE;MAAW,CAAC;IAC7C,KAAK,aAAa;MACjB,OA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,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":[]}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.LinkUIPageCreator = LinkUIPageCreator;
|
|
8
|
+
var _components = require("@wordpress/components");
|
|
9
|
+
var _i18n = require("@wordpress/i18n");
|
|
10
|
+
var _data = require("@wordpress/data");
|
|
11
|
+
var _coreData = require("@wordpress/core-data");
|
|
12
|
+
var _htmlEntities = require("@wordpress/html-entities");
|
|
13
|
+
var _element = require("@wordpress/element");
|
|
14
|
+
var _dialogWrapper = _interopRequireDefault(require("./dialog-wrapper"));
|
|
15
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Component for creating new pages within the Navigation Link UI.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} props Component props.
|
|
28
|
+
* @param {string} props.postType The post type to create.
|
|
29
|
+
* @param {Function} props.onBack Callback when user wants to go back.
|
|
30
|
+
* @param {Function} props.onPageCreated Callback when page is successfully created.
|
|
31
|
+
* @param {string} [props.initialTitle] Initial title to pre-fill the form.
|
|
32
|
+
*/
|
|
33
|
+
function LinkUIPageCreator({
|
|
34
|
+
postType,
|
|
35
|
+
onBack,
|
|
36
|
+
onPageCreated,
|
|
37
|
+
initialTitle = ''
|
|
38
|
+
}) {
|
|
39
|
+
const [title, setTitle] = (0, _element.useState)(initialTitle);
|
|
40
|
+
const [shouldPublish, setShouldPublish] = (0, _element.useState)(false);
|
|
41
|
+
|
|
42
|
+
// Check if the title is valid for submission
|
|
43
|
+
const isTitleValid = title.trim().length > 0;
|
|
44
|
+
|
|
45
|
+
// Get the last created entity record (without ID) to track creation state
|
|
46
|
+
const {
|
|
47
|
+
lastError,
|
|
48
|
+
isSaving
|
|
49
|
+
} = (0, _data.useSelect)(select => ({
|
|
50
|
+
lastError: select(_coreData.store).getLastEntitySaveError('postType', postType),
|
|
51
|
+
isSaving: select(_coreData.store).isSavingEntityRecord('postType', postType)
|
|
52
|
+
}), [postType]);
|
|
53
|
+
const {
|
|
54
|
+
saveEntityRecord
|
|
55
|
+
} = (0, _data.useDispatch)(_coreData.store);
|
|
56
|
+
async function createPage(event) {
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
if (isSaving || !isTitleValid) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const savedRecord = await saveEntityRecord('postType', postType, {
|
|
63
|
+
title,
|
|
64
|
+
status: shouldPublish ? 'publish' : 'draft'
|
|
65
|
+
}, {
|
|
66
|
+
throwOnError: true
|
|
67
|
+
});
|
|
68
|
+
if (savedRecord) {
|
|
69
|
+
// Create the page link object from the saved record
|
|
70
|
+
const pageLink = {
|
|
71
|
+
id: savedRecord.id,
|
|
72
|
+
type: postType,
|
|
73
|
+
title: (0, _htmlEntities.decodeEntities)(savedRecord.title.rendered),
|
|
74
|
+
url: savedRecord.link,
|
|
75
|
+
kind: 'post-type'
|
|
76
|
+
};
|
|
77
|
+
onPageCreated(pageLink);
|
|
78
|
+
}
|
|
79
|
+
} catch (error) {
|
|
80
|
+
// Error handling is done via the data store selectors
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const isSubmitDisabled = isSaving || !isTitleValid;
|
|
84
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_dialogWrapper.default, {
|
|
85
|
+
className: "link-ui-page-creator",
|
|
86
|
+
title: (0, _i18n.__)('Create page'),
|
|
87
|
+
description: (0, _i18n.__)('Create a new page to add to your Navigation.'),
|
|
88
|
+
onBack: onBack,
|
|
89
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalVStack, {
|
|
90
|
+
className: "link-ui-page-creator__inner",
|
|
91
|
+
spacing: 4,
|
|
92
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("form", {
|
|
93
|
+
onSubmit: createPage,
|
|
94
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
95
|
+
spacing: 4,
|
|
96
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, {
|
|
97
|
+
__next40pxDefaultSize: true,
|
|
98
|
+
__nextHasNoMarginBottom: true,
|
|
99
|
+
label: (0, _i18n.__)('Title'),
|
|
100
|
+
onChange: setTitle,
|
|
101
|
+
placeholder: (0, _i18n.__)('No title'),
|
|
102
|
+
value: title
|
|
103
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.CheckboxControl, {
|
|
104
|
+
__nextHasNoMarginBottom: true,
|
|
105
|
+
label: (0, _i18n.__)('Publish immediately'),
|
|
106
|
+
help: (0, _i18n.__)('If unchecked, the page will be created as a draft.'),
|
|
107
|
+
checked: shouldPublish,
|
|
108
|
+
onChange: setShouldPublish
|
|
109
|
+
}), lastError && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Notice, {
|
|
110
|
+
status: "error",
|
|
111
|
+
isDismissible: false,
|
|
112
|
+
children: lastError.message
|
|
113
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
114
|
+
spacing: 2,
|
|
115
|
+
justify: "flex-end",
|
|
116
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
117
|
+
__next40pxDefaultSize: true,
|
|
118
|
+
variant: "tertiary",
|
|
119
|
+
onClick: onBack,
|
|
120
|
+
disabled: isSaving,
|
|
121
|
+
accessibleWhenDisabled: true,
|
|
122
|
+
children: (0, _i18n.__)('Cancel')
|
|
123
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
124
|
+
__next40pxDefaultSize: true,
|
|
125
|
+
variant: "primary",
|
|
126
|
+
type: "submit",
|
|
127
|
+
isBusy: isSaving,
|
|
128
|
+
"aria-disabled": isSubmitDisabled,
|
|
129
|
+
children: (0, _i18n.__)('Create page')
|
|
130
|
+
})]
|
|
131
|
+
})]
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=page-creator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_data","_coreData","_htmlEntities","_element","_dialogWrapper","_interopRequireDefault","_jsxRuntime","LinkUIPageCreator","postType","onBack","onPageCreated","initialTitle","title","setTitle","useState","shouldPublish","setShouldPublish","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","jsx","default","className","__","description","children","__experimentalVStack","spacing","onSubmit","jsxs","TextControl","__next40pxDefaultSize","__nextHasNoMarginBottom","label","onChange","placeholder","value","CheckboxControl","help","checked","Notice","isDismissible","message","__experimentalHStack","justify","Button","variant","onClick","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 { __ } 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';\n\n/**\n * Internal dependencies\n */\nimport DialogWrapper from './dialog-wrapper';\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// 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<DialogWrapper\n\t\t\tclassName=\"link-ui-page-creator\"\n\t\t\ttitle={ __( 'Create page' ) }\n\t\t\tdescription={ __( 'Create a new page to add to your Navigation.' ) }\n\t\t\tonBack={ onBack }\n\t\t>\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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,EAAChD,WAAA,CAAAyE,MAAM;cACNd,qBAAqB;cACrBe,OAAO,EAAC,SAAS;cACjBlC,IAAI,EAAC,QAAQ;cACbsC,MAAM,EAAGtD,QAAU;cACnB,iBAAgBuB,gBAAkB;cAAAM,QAAA,EAEhC,IAAAF,QAAE,EAAE,aAAc;YAAC,CACd,CAAC;UAAA,CACF,CAAC;QAAA,CACF;MAAC,CACJ;IAAC,CACA;EAAC,CACK,CAAC;AAElB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_element","_blockEditor","_queryContent","_interopRequireDefault","_queryPlaceholder","_patternSelection","_jsxRuntime","QueryEdit","props","clientId","attributes","isPatternSelectionModalOpen","setIsPatternSelectionModalOpen","useState","hasInnerBlocks","useSelect","select","blockEditorStore","getBlocks","length","Component","QueryContent","QueryPlaceholder","jsxs","Fragment","children","jsx","openPatternSelectionModal","PatternSelectionModal","_default","exports","default"],"sources":["@wordpress/block-library/src/query/edit/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport QueryContent from './query-content';\nimport QueryPlaceholder from './query-placeholder';\nimport { PatternSelectionModal } from './pattern-selection';\n\nconst QueryEdit = ( props ) => {\n\tconst { clientId, attributes } = props;\n\tconst [ isPatternSelectionModalOpen, setIsPatternSelectionModalOpen ] =\n\t\tuseState( false );\n\tconst hasInnerBlocks = useSelect(\n\t\t( select ) =>\n\t\t\t!! select( blockEditorStore ).getBlocks( clientId ).length,\n\t\t[ clientId ]\n\t);\n\tconst Component = hasInnerBlocks ? QueryContent : QueryPlaceholder;\n\treturn (\n\t\t<>\n\t\t\t<Component\n\t\t\t\t{ ...props }\n\t\t\t\topenPatternSelectionModal={ () =>\n\t\t\t\t\tsetIsPatternSelectionModalOpen( true )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t{ isPatternSelectionModalOpen && (\n\t\t\t\t<PatternSelectionModal\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetIsPatternSelectionModalOpen={\n\t\t\t\t\t\tsetIsPatternSelectionModalOpen\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n};\n\nexport default QueryEdit;\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAKA,IAAAG,aAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAD,sBAAA,CAAAJ,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAA4D,IAAAO,WAAA,GAAAP,OAAA;AAZ5D;AACA;AACA;;AAKA;AACA;AACA;;AAKA,MAAMQ,SAAS,GAAKC,KAAK,IAAM;EAC9B,MAAM;IAAEC,QAAQ;IAAEC;EAAW,CAAC,GAAGF,KAAK;EACtC,MAAM,CAAEG,2BAA2B,EAAEC,8BAA8B,CAAE,GACpE,IAAAC,iBAAQ,EAAE,KAAM,CAAC;EAClB,MAAMC,cAAc,GAAG,IAAAC,eAAS,EAC7BC,MAAM,IACP,CAAC,CAAEA,MAAM,CAAEC,kBAAiB,CAAC,CAACC,SAAS,CAAET,QAAS,CAAC,CAACU,MAAM,EAC3D,CAAEV,QAAQ,CACX,CAAC;EACD,MAAMW,SAAS,GAAGN,cAAc,GAAGO,qBAAY,GAAGC,yBAAgB;
|
|
1
|
+
{"version":3,"names":["_data","require","_element","_blockEditor","_queryContent","_interopRequireDefault","_queryPlaceholder","_patternSelection","_jsxRuntime","QueryEdit","props","clientId","attributes","isPatternSelectionModalOpen","setIsPatternSelectionModalOpen","useState","hasInnerBlocks","useSelect","select","blockEditorStore","getBlocks","length","Component","QueryContent","QueryPlaceholder","jsxs","Fragment","children","jsx","openPatternSelectionModal","PatternSelectionModal","_default","exports","default"],"sources":["@wordpress/block-library/src/query/edit/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport QueryContent from './query-content';\nimport QueryPlaceholder from './query-placeholder';\nimport { PatternSelectionModal } from './pattern-selection';\n\nconst QueryEdit = ( props ) => {\n\tconst { clientId, attributes } = props;\n\tconst [ isPatternSelectionModalOpen, setIsPatternSelectionModalOpen ] =\n\t\tuseState( false );\n\tconst hasInnerBlocks = useSelect(\n\t\t( select ) =>\n\t\t\t!! select( blockEditorStore ).getBlocks( clientId ).length,\n\t\t[ clientId ]\n\t);\n\tconst Component = hasInnerBlocks ? QueryContent : QueryPlaceholder;\n\n\treturn (\n\t\t<>\n\t\t\t<Component\n\t\t\t\t{ ...props }\n\t\t\t\topenPatternSelectionModal={ () =>\n\t\t\t\t\tsetIsPatternSelectionModalOpen( true )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t{ isPatternSelectionModalOpen && (\n\t\t\t\t<PatternSelectionModal\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetIsPatternSelectionModalOpen={\n\t\t\t\t\t\tsetIsPatternSelectionModalOpen\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n};\n\nexport default QueryEdit;\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAKA,IAAAG,aAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAD,sBAAA,CAAAJ,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAA4D,IAAAO,WAAA,GAAAP,OAAA;AAZ5D;AACA;AACA;;AAKA;AACA;AACA;;AAKA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