@wordpress/block-library 7.3.2 → 7.3.3
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/comment-template/hooks.js +11 -3
- package/build/comment-template/hooks.js.map +1 -1
- package/build/comments-pagination/edit.js +18 -1
- package/build/comments-pagination/edit.js.map +1 -1
- package/build/comments-query-loop/edit.js +2 -2
- package/build/comments-query-loop/edit.js.map +1 -1
- package/build/comments-title/edit.js +149 -0
- package/build/comments-title/edit.js.map +1 -0
- package/build/comments-title/index.js +101 -0
- package/build/comments-title/index.js.map +1 -0
- package/build/index.js +4 -2
- package/build/index.js.map +1 -1
- package/build/navigation/edit/index.js +17 -1
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/navigation-menu-selector.js +7 -2
- package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build/post-comments/edit.js +141 -35
- package/build/post-comments/edit.js.map +1 -1
- package/build/post-comments/index.js +2 -1
- package/build/post-comments/index.js.map +1 -1
- package/build/post-comments-form/edit.js +22 -1
- package/build/post-comments-form/edit.js.map +1 -1
- package/build/post-comments-form/index.js +1 -0
- package/build/post-comments-form/index.js.map +1 -1
- package/build/query-no-results/edit.js +1 -1
- package/build/query-no-results/edit.js.map +1 -1
- package/build-module/comment-template/hooks.js +11 -3
- package/build-module/comment-template/hooks.js.map +1 -1
- package/build-module/comments-pagination/edit.js +19 -2
- package/build-module/comments-pagination/edit.js.map +1 -1
- package/build-module/comments-query-loop/edit.js +2 -2
- package/build-module/comments-query-loop/edit.js.map +1 -1
- package/build-module/comments-title/edit.js +133 -0
- package/build-module/comments-title/edit.js.map +1 -0
- package/build-module/comments-title/index.js +88 -0
- package/build-module/comments-title/index.js.map +1 -0
- package/build-module/index.js +3 -2
- package/build-module/index.js.map +1 -1
- package/build-module/navigation/edit/index.js +17 -1
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/navigation-menu-selector.js +6 -2
- package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build-module/post-comments/edit.js +143 -38
- package/build-module/post-comments/edit.js.map +1 -1
- package/build-module/post-comments/index.js +2 -1
- package/build-module/post-comments/index.js.map +1 -1
- package/build-module/post-comments-form/edit.js +21 -1
- package/build-module/post-comments-form/edit.js.map +1 -1
- package/build-module/post-comments-form/index.js +1 -0
- package/build-module/post-comments-form/index.js.map +1 -1
- package/build-module/query-no-results/edit.js +1 -1
- package/build-module/query-no-results/edit.js.map +1 -1
- package/build-style/comments-title/editor-rtl.css +79 -0
- package/build-style/comments-title/editor.css +79 -0
- package/build-style/editor-rtl.css +12 -0
- package/build-style/editor.css +12 -0
- package/build-style/post-comments/editor-rtl.css +79 -0
- package/build-style/post-comments/editor.css +79 -0
- package/build-style/post-comments/style-rtl.css +1 -3
- package/build-style/post-comments/style.css +1 -3
- package/build-style/post-comments-form/editor-rtl.css +79 -0
- package/build-style/post-comments-form/editor.css +79 -0
- package/build-style/post-comments-form/style-rtl.css +9 -0
- package/build-style/post-comments-form/style.css +9 -0
- package/build-style/style-rtl.css +10 -3
- package/build-style/style.css +10 -3
- package/package.json +9 -9
- package/src/comment-edit-link/index.php +1 -4
- package/src/comment-reply-link/index.php +1 -4
- package/src/comment-template/hooks.js +13 -1
- package/src/comment-template/index.php +13 -4
- package/src/comments-pagination/edit.js +23 -0
- package/src/comments-query-loop/edit.js +2 -0
- package/src/comments-title/block.json +70 -0
- package/src/comments-title/edit.js +197 -0
- package/src/comments-title/editor.scss +4 -0
- package/src/comments-title/index.js +18 -0
- package/src/comments-title/index.php +68 -0
- package/src/editor.scss +3 -0
- package/src/index.js +4 -1
- package/src/navigation/edit/index.js +24 -0
- package/src/navigation/edit/navigation-menu-selector.js +15 -9
- package/src/post-comments/block.json +2 -1
- package/src/post-comments/edit.js +204 -44
- package/src/post-comments/editor.scss +3 -0
- package/src/post-comments/style.scss +1 -5
- package/src/post-comments-form/block.json +1 -0
- package/src/post-comments-form/edit.js +39 -2
- package/src/post-comments-form/editor.scss +3 -0
- package/src/post-comments-form/style.scss +11 -0
- package/src/query-no-results/edit.js +1 -1
|
@@ -17,6 +17,8 @@ var _coreData = require("@wordpress/core-data");
|
|
|
17
17
|
|
|
18
18
|
var _i18n = require("@wordpress/i18n");
|
|
19
19
|
|
|
20
|
+
var _compose = require("@wordpress/compose");
|
|
21
|
+
|
|
20
22
|
/**
|
|
21
23
|
* External dependencies
|
|
22
24
|
*/
|
|
@@ -44,6 +46,8 @@ function PostCommentsFormEdit(_ref) {
|
|
|
44
46
|
})
|
|
45
47
|
});
|
|
46
48
|
const isInSiteEditor = postType === undefined || postId === undefined;
|
|
49
|
+
const disabledFormRef = (0, _compose.__experimentalUseDisabled)();
|
|
50
|
+
const instanceId = (0, _compose.useInstanceId)(PostCommentsFormEdit);
|
|
47
51
|
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_blockEditor.BlockControls, {
|
|
48
52
|
group: "block"
|
|
49
53
|
}, (0, _element.createElement)(_blockEditor.AlignmentControl, {
|
|
@@ -55,6 +59,23 @@ function PostCommentsFormEdit(_ref) {
|
|
|
55
59
|
}
|
|
56
60
|
})), (0, _element.createElement)("div", blockProps, !commentStatus && !isInSiteEditor && (0, _element.createElement)(_blockEditor.Warning, null, (0, _i18n.__)('Post Comments Form block: comments are not enabled for this post type.')), 'open' !== commentStatus && !isInSiteEditor && (0, _element.createElement)(_blockEditor.Warning, null, (0, _i18n.sprintf)(
|
|
57
61
|
/* translators: 1: Post type (i.e. "post", "page") */
|
|
58
|
-
(0, _i18n.__)('Post Comments Form block: comments to this %s are not allowed.'), postType)), ('open' === commentStatus || isInSiteEditor) && (0, _i18n.__)('
|
|
62
|
+
(0, _i18n.__)('Post Comments Form block: comments to this %s are not allowed.'), postType)), ('open' === commentStatus || isInSiteEditor) && (0, _element.createElement)("div", null, (0, _element.createElement)("h3", null, (0, _i18n.__)('Leave a Reply')), (0, _element.createElement)("form", {
|
|
63
|
+
noValidate: true,
|
|
64
|
+
className: "comment-form",
|
|
65
|
+
ref: disabledFormRef
|
|
66
|
+
}, (0, _element.createElement)("p", null, (0, _element.createElement)("label", {
|
|
67
|
+
htmlFor: `comment-${instanceId}`
|
|
68
|
+
}, (0, _i18n.__)('Comment')), (0, _element.createElement)("textarea", {
|
|
69
|
+
id: `comment-${instanceId}`,
|
|
70
|
+
name: "comment",
|
|
71
|
+
cols: "45",
|
|
72
|
+
rows: "8"
|
|
73
|
+
})), (0, _element.createElement)("p", null, (0, _element.createElement)("input", {
|
|
74
|
+
name: "submit",
|
|
75
|
+
className: "submit wp-block-button__link",
|
|
76
|
+
label: (0, _i18n.__)('Post Comment'),
|
|
77
|
+
value: (0, _i18n.__)('Post Comment'),
|
|
78
|
+
readOnly: true
|
|
79
|
+
}))))));
|
|
59
80
|
}
|
|
60
81
|
//# sourceMappingURL=edit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/post-comments-form/edit.js"],"names":["PostCommentsFormEdit","attributes","context","setAttributes","textAlign","postId","postType","commentStatus","blockProps","className","isInSiteEditor","undefined","nextAlign"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AAMA;;AACA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/post-comments-form/edit.js"],"names":["PostCommentsFormEdit","attributes","context","setAttributes","textAlign","postId","postType","commentStatus","blockProps","className","isInSiteEditor","undefined","disabledFormRef","instanceId","nextAlign"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AAMA;;AACA;;AACA;;AAhBA;AACA;AACA;;AAGA;AACA;AACA;AAce,SAASA,oBAAT,OAIX;AAAA,MAJ0C;AAC7CC,IAAAA,UAD6C;AAE7CC,IAAAA,OAF6C;AAG7CC,IAAAA;AAH6C,GAI1C;AACH,QAAM;AAAEC,IAAAA;AAAF,MAAgBH,UAAtB;AACA,QAAM;AAAEI,IAAAA,MAAF;AAAUC,IAAAA;AAAV,MAAuBJ,OAA7B;AACA,QAAM,CAAE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C;AAJN,IAJD,CALD,EAgBC,uCACC;AACC,IAAA,IAAI,EAAC,QADN;AAEC,IAAA,SAAS,EAAC,8BAFX;AAGC,IAAA,KAAK,EAAG,cAAI,cAAJ,CAHT;AAIC,IAAA,KAAK,EAAG,cAAI,cAAJ,CAJT;AAKC,IAAA,QAAQ;AALT,IADD,CAhBD,CAFD,CAtBF,CATD,CADD;AAiEA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tAlignmentControl,\n\tBlockControls,\n\tWarning,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport { useEntityProp } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\t__experimentalUseDisabled as useDisabled,\n\tuseInstanceId,\n} from '@wordpress/compose';\n\nexport default function PostCommentsFormEdit( {\n\tattributes,\n\tcontext,\n\tsetAttributes,\n} ) {\n\tconst { textAlign } = attributes;\n\tconst { postId, postType } = context;\n\tconst [ commentStatus ] = useEntityProp(\n\t\t'postType',\n\t\tpostType,\n\t\t'comment_status',\n\t\tpostId\n\t);\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t} );\n\n\tconst isInSiteEditor = postType === undefined || postId === undefined;\n\n\tconst disabledFormRef = useDisabled();\n\n\tconst instanceId = useInstanceId( PostCommentsFormEdit );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t<AlignmentControl\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( nextAlign ) => {\n\t\t\t\t\t\tsetAttributes( { textAlign: nextAlign } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ ! commentStatus && ! isInSiteEditor && (\n\t\t\t\t\t<Warning>\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Post Comments Form block: comments are not enabled for this post type.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Warning>\n\t\t\t\t) }\n\n\t\t\t\t{ 'open' !== commentStatus && ! isInSiteEditor && (\n\t\t\t\t\t<Warning>\n\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t/* translators: 1: Post type (i.e. \"post\", \"page\") */\n\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t'Post Comments Form block: comments to this %s are not allowed.'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tpostType\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Warning>\n\t\t\t\t) }\n\n\t\t\t\t{ ( 'open' === commentStatus || isInSiteEditor ) && (\n\t\t\t\t\t<div>\n\t\t\t\t\t\t<h3>{ __( 'Leave a Reply' ) }</h3>\n\t\t\t\t\t\t<form\n\t\t\t\t\t\t\tnoValidate\n\t\t\t\t\t\t\tclassName=\"comment-form\"\n\t\t\t\t\t\t\tref={ disabledFormRef }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t\t<label htmlFor={ `comment-${ instanceId }` }>\n\t\t\t\t\t\t\t\t\t{ __( 'Comment' ) }\n\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t\t<textarea\n\t\t\t\t\t\t\t\t\tid={ `comment-${ instanceId }` }\n\t\t\t\t\t\t\t\t\tname=\"comment\"\n\t\t\t\t\t\t\t\t\tcols=\"45\"\n\t\t\t\t\t\t\t\t\trows=\"8\"\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t<p>\n\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\tname=\"submit\"\n\t\t\t\t\t\t\t\t\tclassName=\"submit wp-block-button__link\"\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Post Comment' ) }\n\t\t\t\t\t\t\t\t\tvalue={ __( 'Post Comment' ) }\n\t\t\t\t\t\t\t\t\treadOnly\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t</form>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/post-comments-form/index.js"],"names":["name","metadata","settings","icon","edit"],"mappings":";;;;;;;;;AAGA;;AAMA;;AATA;AACA;AACA;;AAGA;AACA;AACA
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/post-comments-form/index.js"],"names":["name","metadata","settings","icon","edit"],"mappings":";;;;;;;;;AAGA;;AAMA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM;AAAEA,EAAAA;AAAF,IAAWC,QAAjB;;AAGO,MAAMC,QAAQ,GAAG;AACvBC,EAAAA,IAAI,EAAJA,uBADuB;AAEvBC,EAAAA,IAAI,EAAJA;AAFuB,CAAjB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { postCommentsForm as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n};\n"]}
|
|
@@ -15,7 +15,7 @@ var _i18n = require("@wordpress/i18n");
|
|
|
15
15
|
* WordPress dependencies
|
|
16
16
|
*/
|
|
17
17
|
const TEMPLATE = [['core/paragraph', {
|
|
18
|
-
placeholder: (0, _i18n.__)('Add
|
|
18
|
+
placeholder: (0, _i18n.__)('Add text or blocks that will display when the query returns no results.')
|
|
19
19
|
}]];
|
|
20
20
|
|
|
21
21
|
function QueryNoResultsEdit() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/query-no-results/edit.js"],"names":["TEMPLATE","placeholder","QueryNoResultsEdit","blockProps","innerBlocksProps","template"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;AAIA,MAAMA,QAAQ,GAAG,CAChB,CACC,gBADD,EAEC;AACCC,EAAAA,WAAW,EAAE,cACZ,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/query-no-results/edit.js"],"names":["TEMPLATE","placeholder","QueryNoResultsEdit","blockProps","innerBlocksProps","template"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;AAIA,MAAMA,QAAQ,GAAG,CAChB,CACC,gBADD,EAEC;AACCC,EAAAA,WAAW,EAAE,cACZ,yEADY;AADd,CAFD,CADgB,CAAjB;;AAWe,SAASC,kBAAT,GAA8B;AAC5C,QAAMC,UAAU,GAAG,iCAAnB;AACA,QAAMC,gBAAgB,GAAG,sCAAqBD,UAArB,EAAiC;AACzDE,IAAAA,QAAQ,EAAEL;AAD+C,GAAjC,CAAzB;AAGA,SACC,qDACC,mCAAUI,gBAAV,CADD,CADD;AAKA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\n\nconst TEMPLATE = [\n\t[\n\t\t'core/paragraph',\n\t\t{\n\t\t\tplaceholder: __(\n\t\t\t\t'Add text or blocks that will display when the query returns no results.'\n\t\t\t),\n\t\t},\n\t],\n];\n\nexport default function QueryNoResultsEdit() {\n\tconst blockProps = useBlockProps();\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: TEMPLATE,\n\t} );\n\treturn (\n\t\t<>\n\t\t\t<div { ...innerBlocksProps } />\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -5,7 +5,9 @@ import { useState, useEffect, useMemo } from '@wordpress/element';
|
|
|
5
5
|
import { useSelect } from '@wordpress/data';
|
|
6
6
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
7
7
|
import { addQueryArgs } from '@wordpress/url';
|
|
8
|
-
import apiFetch from '@wordpress/api-fetch';
|
|
8
|
+
import apiFetch from '@wordpress/api-fetch'; // This is limited by WP REST API
|
|
9
|
+
|
|
10
|
+
const MAX_COMMENTS_PER_PAGE = 100;
|
|
9
11
|
/**
|
|
10
12
|
* Return an object with the query args needed to fetch the default page of
|
|
11
13
|
* comments.
|
|
@@ -31,7 +33,8 @@ export const useCommentQueryArgs = _ref => {
|
|
|
31
33
|
}; // Get the Discussion settings that may be needed to query the comments.
|
|
32
34
|
|
|
33
35
|
const {
|
|
34
|
-
|
|
36
|
+
pageComments,
|
|
37
|
+
commentsPerPage,
|
|
35
38
|
defaultCommentsPage: defaultPage
|
|
36
39
|
} = useSelect(select => {
|
|
37
40
|
const {
|
|
@@ -41,7 +44,12 @@ export const useCommentQueryArgs = _ref => {
|
|
|
41
44
|
__experimentalDiscussionSettings
|
|
42
45
|
} = getSettings();
|
|
43
46
|
return __experimentalDiscussionSettings;
|
|
44
|
-
}); //
|
|
47
|
+
}); // WP REST API doesn't allow fetching more than max items limit set per single page of data.
|
|
48
|
+
// As for the editor performance is more important than completeness of data and fetching only the
|
|
49
|
+
// max allowed for single page should be enough for the purpose of design and laying out the page.
|
|
50
|
+
// Fetching over the limit would return an error here but would work with backend query.
|
|
51
|
+
|
|
52
|
+
const perPage = pageComments ? Math.min(commentsPerPage, MAX_COMMENTS_PER_PAGE) : MAX_COMMENTS_PER_PAGE; // Get the number of the default page.
|
|
45
53
|
|
|
46
54
|
const page = useDefaultPageIndex({
|
|
47
55
|
defaultPage,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/comment-template/hooks.js"],"names":["useState","useEffect","useMemo","useSelect","store","blockEditorStore","addQueryArgs","apiFetch","useCommentQueryArgs","postId","queryArgs","status","order","context","parent","_embed","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/comment-template/hooks.js"],"names":["useState","useEffect","useMemo","useSelect","store","blockEditorStore","addQueryArgs","apiFetch","MAX_COMMENTS_PER_PAGE","useCommentQueryArgs","postId","queryArgs","status","order","context","parent","_embed","pageComments","commentsPerPage","defaultCommentsPage","defaultPage","select","getSettings","__experimentalDiscussionSettings","perPage","Math","min","page","useDefaultPageIndex","post","per_page","defaultPages","setDefaultPages","key","path","_fields","method","parse","then","res","pages","parseInt","headers","get","useCommentTree","topLevelComments","commentTree","map","id","_embedded","children","commentId","child"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,SAAnB,EAA8BC,OAA9B,QAA6C,oBAA7C;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,yBAA1C;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,OAAOC,QAAP,MAAqB,sBAArB,C,CAEA;;AACA,MAAMC,qBAAqB,GAAG,GAA9B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,mBAAmB,GAAG,QAAkB;AAAA,MAAhB;AAAEC,IAAAA;AAAF,GAAgB;AACpD;AACA,QAAMC,SAAS,GAAG;AACjBC,IAAAA,MAAM,EAAE,SADS;AAEjBC,IAAAA,KAAK,EAAE,KAFU;AAGjBC,IAAAA,OAAO,EAAE,OAHQ;AAIjBC,IAAAA,MAAM,EAAE,CAJS;AAKjBC,IAAAA,MAAM,EAAE;AALS,GAAlB,CAFoD,CAUpD;;AACA,QAAM;AACLC,IAAAA,YADK;AAELC,IAAAA,eAFK;AAGLC,IAAAA,mBAAmB,EAAEC;AAHhB,MAIFjB,SAAS,CAAIkB,MAAF,IAAc;AAC5B,UAAM;AAAEC,MAAAA;AAAF,QAAkBD,MAAM,CAAEhB,gBAAF,CAA9B;AACA,UAAM;AAAEkB,MAAAA;AAAF,QAAuCD,WAAW,EAAxD;AACA,WAAOC,gCAAP;AACA,GAJY,CAJb,CAXoD,CAqBpD;AACA;AACA;AACA;;AACA,QAAMC,OAAO,GAAGP,YAAY,GACzBQ,IAAI,CAACC,GAAL,CAAUR,e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AhBM","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useEffect, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\n\n// This is limited by WP REST API\nconst MAX_COMMENTS_PER_PAGE = 100;\n\n/**\n * Return an object with the query args needed to fetch the default page of\n * comments.\n *\n * @param {Object} props Hook props.\n * @param {number} props.postId ID of the post that contains the comments.\n * discussion settings.\n *\n * @return {Object} Query args to retrieve the comments.\n */\nexport const useCommentQueryArgs = ( { postId } ) => {\n\t// Initialize the query args that are not going to change.\n\tconst queryArgs = {\n\t\tstatus: 'approve',\n\t\torder: 'asc',\n\t\tcontext: 'embed',\n\t\tparent: 0,\n\t\t_embed: 'children',\n\t};\n\n\t// Get the Discussion settings that may be needed to query the comments.\n\tconst {\n\t\tpageComments,\n\t\tcommentsPerPage,\n\t\tdefaultCommentsPage: defaultPage,\n\t} = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst { __experimentalDiscussionSettings } = getSettings();\n\t\treturn __experimentalDiscussionSettings;\n\t} );\n\n\t// WP REST API doesn't allow fetching more than max items limit set per single page of data.\n\t// As for the editor performance is more important than completeness of data and fetching only the\n\t// max allowed for single page should be enough for the purpose of design and laying out the page.\n\t// Fetching over the limit would return an error here but would work with backend query.\n\tconst perPage = pageComments\n\t\t? Math.min( commentsPerPage, MAX_COMMENTS_PER_PAGE )\n\t\t: MAX_COMMENTS_PER_PAGE;\n\n\t// Get the number of the default page.\n\tconst page = useDefaultPageIndex( {\n\t\tdefaultPage,\n\t\tpostId,\n\t\tperPage,\n\t\tqueryArgs,\n\t} );\n\n\t// Merge, memoize and return all query arguments, unless the default page's\n\t// number is not known yet.\n\treturn useMemo( () => {\n\t\treturn page\n\t\t\t? {\n\t\t\t\t\t...queryArgs,\n\t\t\t\t\tpost: postId,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\tpage,\n\t\t\t }\n\t\t\t: null;\n\t}, [ postId, perPage, page ] );\n};\n\n/**\n * Return the index of the default page, depending on whether `defaultPage` is\n * `newest` or `oldest`. In the first case, the only way to know the page's\n * index is by using the `X-WP-TotalPages` header, which forces to make an\n * additional request.\n *\n * @param {Object} props Hook props.\n * @param {string} props.defaultPage Page shown by default (newest/oldest).\n * @param {number} props.postId ID of the post that contains the comments.\n * @param {number} props.perPage The number of comments included per page.\n * @param {Object} props.queryArgs Other query args.\n *\n * @return {number} Index of the default comments page.\n */\nconst useDefaultPageIndex = ( { defaultPage, postId, perPage, queryArgs } ) => {\n\t// Store the default page indices.\n\tconst [ defaultPages, setDefaultPages ] = useState( {} );\n\tconst key = `${ postId }_${ perPage }`;\n\tconst page = defaultPages[ key ] || 0;\n\n\tuseEffect( () => {\n\t\t// Do nothing if the page is already known or not the newest page.\n\t\tif ( page || defaultPage !== 'newest' ) {\n\t\t\treturn;\n\t\t}\n\t\t// We need to fetch comments to know the index. Use HEAD and limit\n\t\t// fields just to ID, to make this call as light as possible.\n\t\tapiFetch( {\n\t\t\tpath: addQueryArgs( '/wp/v2/comments', {\n\t\t\t\t...queryArgs,\n\t\t\t\tpost: postId,\n\t\t\t\tper_page: perPage,\n\t\t\t\t_fields: 'id',\n\t\t\t} ),\n\t\t\tmethod: 'HEAD',\n\t\t\tparse: false,\n\t\t} ).then( ( res ) => {\n\t\t\tconst pages = parseInt( res.headers.get( 'X-WP-TotalPages' ) );\n\t\t\tsetDefaultPages( {\n\t\t\t\t...defaultPages,\n\t\t\t\t[ key ]: pages <= 1 ? 1 : pages, // If there are 0 pages, it means that there are no comments, but there is no 0th page.\n\t\t\t} );\n\t\t} );\n\t}, [ defaultPage, postId, perPage, setDefaultPages ] );\n\n\t// The oldest one is always the first one.\n\treturn defaultPage === 'newest' ? page : 1;\n};\n\n/**\n * Generate a tree structure of comment IDs from a list of comment entities. The\n * children of each comment are obtained from `_embedded`.\n *\n * @typedef {{ commentId: number, children: CommentNode }} CommentNode\n *\n * @param {Object[]} topLevelComments List of comment entities.\n * @return {{ commentTree: CommentNode[]}} Tree of comment IDs.\n */\nexport const useCommentTree = ( topLevelComments ) => {\n\tconst commentTree = useMemo(\n\t\t() =>\n\t\t\ttopLevelComments?.map( ( { id, _embedded } ) => {\n\t\t\t\tconst [ children ] = _embedded?.children || [ [] ];\n\t\t\t\treturn {\n\t\t\t\t\tcommentId: id,\n\t\t\t\t\tchildren: children.map( ( child ) => ( {\n\t\t\t\t\t\tcommentId: child.id,\n\t\t\t\t\t} ) ),\n\t\t\t\t};\n\t\t\t} ),\n\t\t[ topLevelComments ]\n\t);\n\n\treturn commentTree;\n};\n"]}
|
|
@@ -4,7 +4,7 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
4
4
|
* WordPress dependencies
|
|
5
5
|
*/
|
|
6
6
|
import { __ } from '@wordpress/i18n';
|
|
7
|
-
import { InspectorControls, useBlockProps, useInnerBlocksProps, store as blockEditorStore } from '@wordpress/block-editor';
|
|
7
|
+
import { InspectorControls, useBlockProps, useInnerBlocksProps, store as blockEditorStore, Warning } from '@wordpress/block-editor';
|
|
8
8
|
import { useSelect } from '@wordpress/data';
|
|
9
9
|
import { getBlockSupport } from '@wordpress/blocks';
|
|
10
10
|
import { PanelBody } from '@wordpress/components';
|
|
@@ -51,7 +51,24 @@ export default function QueryPaginationEdit(_ref) {
|
|
|
51
51
|
template: TEMPLATE,
|
|
52
52
|
allowedBlocks: ['core/comments-pagination-previous', 'core/comments-pagination-numbers', 'core/comments-pagination-next'],
|
|
53
53
|
__experimentalLayout: usedLayout
|
|
54
|
-
});
|
|
54
|
+
}); // Get the Discussion settings
|
|
55
|
+
|
|
56
|
+
const pageComments = useSelect(select => {
|
|
57
|
+
const {
|
|
58
|
+
getSettings
|
|
59
|
+
} = select(blockEditorStore);
|
|
60
|
+
const {
|
|
61
|
+
__experimentalDiscussionSettings
|
|
62
|
+
} = getSettings();
|
|
63
|
+
return __experimentalDiscussionSettings === null || __experimentalDiscussionSettings === void 0 ? void 0 : __experimentalDiscussionSettings.pageComments;
|
|
64
|
+
}, []); // If paging comments is not enabled in the Discussion Settings then hide the pagination
|
|
65
|
+
// controls. We don't want to remove them from the template so that when the user enables
|
|
66
|
+
// paging comments, the controls will be visible.
|
|
67
|
+
|
|
68
|
+
if (!pageComments) {
|
|
69
|
+
return createElement(Warning, null, __('Comments Pagination block: paging comments is disabled in the Discussion Settings'));
|
|
70
|
+
}
|
|
71
|
+
|
|
55
72
|
return createElement(Fragment, null, hasNextPreviousBlocks && createElement(InspectorControls, null, createElement(PanelBody, {
|
|
56
73
|
title: __('Settings')
|
|
57
74
|
}, createElement(CommentsPaginationArrowControls, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/comments-pagination/edit.js"],"names":["__","InspectorControls","useBlockProps","useInnerBlocksProps","store","blockEditorStore","useSelect","getBlockSupport","PanelBody","CommentsPaginationArrowControls","TEMPLATE","getDefaultBlockLayout","blockTypeOrName","layoutBlockSupportConfig","default","QueryPaginationEdit","attributes","paginationArrow","layout","setAttributes","clientId","name","usedLayout","hasNextPreviousBlocks","select","getBlocks","innerBlocks","find","innerBlock","includes","blockProps","innerBlocksProps","template","allowedBlocks","__experimentalLayout","value"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SACCC,iBADD,EAECC,aAFD,EAGCC,mBAHD,EAICC,KAAK,IAAIC,gBAJV,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/comments-pagination/edit.js"],"names":["__","InspectorControls","useBlockProps","useInnerBlocksProps","store","blockEditorStore","Warning","useSelect","getBlockSupport","PanelBody","CommentsPaginationArrowControls","TEMPLATE","getDefaultBlockLayout","blockTypeOrName","layoutBlockSupportConfig","default","QueryPaginationEdit","attributes","paginationArrow","layout","setAttributes","clientId","name","usedLayout","hasNextPreviousBlocks","select","getBlocks","innerBlocks","find","innerBlock","includes","blockProps","innerBlocksProps","template","allowedBlocks","__experimentalLayout","pageComments","getSettings","__experimentalDiscussionSettings","value"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SACCC,iBADD,EAECC,aAFD,EAGCC,mBAHD,EAICC,KAAK,IAAIC,gBAJV,EAKCC,OALD,QAMO,yBANP;AAOA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,eAAT,QAAgC,mBAAhC;AACA,SAASC,SAAT,QAA0B,uBAA1B;AAEA;AACA;AACA;;AACA,SAASC,+BAAT,QAAgD,sCAAhD;AAEA,MAAMC,QAAQ,GAAG,CAChB,CAAE,mCAAF,CADgB,EAEhB,CAAE,kCAAF,CAFgB,EAGhB,CAAE,+BAAF,CAHgB,CAAjB;;AAMA,MAAMC,qBAAqB,GAAKC,eAAF,IAAuB;AACpD,QAAMC,wBAAwB,GAAGN,eAAe,CAC/CK,eAD+C,EAE/C,sBAF+C,CAAhD;AAIA,SAAOC,wBAAP,aAAOA,wBAAP,uBAAOA,wBAAwB,CAAEC,OAAjC;AACA,CAND;;AAQA,eAAe,SAASC,mBAAT,OAKX;AAAA,MALyC;AAC5CC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,eAAF;AAAmBC,MAAAA;AAAnB,KADgC;AAE5CC,IAAAA,aAF4C;AAG5CC,IAAAA,QAH4C;AAI5CC,IAAAA;AAJ4C,GAKzC;AACH,QAAMC,UAAU,GAAGJ,MAAM,IAAIP,qBAAqB,CAAEU,IAAF,CAAlD;AACA,QAAME,qBAAqB,GAAGjB,SAAS,CAAIkB,MAAF,IAAc;AACtD,UAAM;AAAEC,MAAAA;AAAF,QAAgBD,MAAM,CAAEpB,gBAAF,CAA5B;AACA,UAAMsB,WAAW,GAAGD,SAAS,CAAEL,QAAF,CAA7B;AACA;AACF;AACA;AACA;AACA;;AACE,WAAOM,WAAP,aAAOA,WAAP,uBAAOA,WAAW,CAAEC,IAAb,CAAqBC,UAA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InspectorControls,\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n\tWarning,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport { PanelBody } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { CommentsPaginationArrowControls } from './comments-pagination-arrow-controls';\n\nconst TEMPLATE = [\n\t[ 'core/comments-pagination-previous' ],\n\t[ 'core/comments-pagination-numbers' ],\n\t[ 'core/comments-pagination-next' ],\n];\n\nconst getDefaultBlockLayout = ( blockTypeOrName ) => {\n\tconst layoutBlockSupportConfig = getBlockSupport(\n\t\tblockTypeOrName,\n\t\t'__experimentalLayout'\n\t);\n\treturn layoutBlockSupportConfig?.default;\n};\n\nexport default function QueryPaginationEdit( {\n\tattributes: { paginationArrow, layout },\n\tsetAttributes,\n\tclientId,\n\tname,\n} ) {\n\tconst usedLayout = layout || getDefaultBlockLayout( name );\n\tconst hasNextPreviousBlocks = useSelect( ( select ) => {\n\t\tconst { getBlocks } = select( blockEditorStore );\n\t\tconst innerBlocks = getBlocks( clientId );\n\t\t/**\n\t\t * Show the `paginationArrow` control only if a\n\t\t * Comments Pagination Next or Comments Pagination Previous\n\t\t * block exists.\n\t\t */\n\t\treturn innerBlocks?.find( ( innerBlock ) => {\n\t\t\treturn [\n\t\t\t\t'core/comments-pagination-previous',\n\t\t\t\t'core/comments-pagination-next',\n\t\t\t].includes( innerBlock.name );\n\t\t} );\n\t}, [] );\n\n\tconst blockProps = useBlockProps();\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: TEMPLATE,\n\t\tallowedBlocks: [\n\t\t\t'core/comments-pagination-previous',\n\t\t\t'core/comments-pagination-numbers',\n\t\t\t'core/comments-pagination-next',\n\t\t],\n\t\t__experimentalLayout: usedLayout,\n\t} );\n\n\t// Get the Discussion settings\n\tconst pageComments = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst { __experimentalDiscussionSettings } = getSettings();\n\t\treturn __experimentalDiscussionSettings?.pageComments;\n\t}, [] );\n\n\t// If paging comments is not enabled in the Discussion Settings then hide the pagination\n\t// controls. We don't want to remove them from the template so that when the user enables\n\t// paging comments, the controls will be visible.\n\tif ( ! pageComments ) {\n\t\treturn (\n\t\t\t<Warning>\n\t\t\t\t{ __(\n\t\t\t\t\t'Comments Pagination block: paging comments is disabled in the Discussion Settings'\n\t\t\t\t) }\n\t\t\t</Warning>\n\t\t);\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ hasNextPreviousBlocks && (\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<PanelBody title={ __( 'Settings' ) }>\n\t\t\t\t\t\t<CommentsPaginationArrowControls\n\t\t\t\t\t\t\tvalue={ paginationArrow }\n\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\tsetAttributes( { paginationArrow: value } );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</PanelBody>\n\t\t\t\t</InspectorControls>\n\t\t\t) }\n\t\t\t<div { ...innerBlocksProps } />\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -9,7 +9,7 @@ import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import CommentsInspectorControls from './edit/comments-inspector-controls';
|
|
12
|
-
const TEMPLATE = [['core/comment-template', {}, [['core/columns', {}, [['core/column', {
|
|
12
|
+
const TEMPLATE = [['core/comments-title'], ['core/comment-template', {}, [['core/columns', {}, [['core/column', {
|
|
13
13
|
width: '40px'
|
|
14
14
|
}, [['core/avatar', {
|
|
15
15
|
size: 40,
|
|
@@ -30,7 +30,7 @@ const TEMPLATE = [['core/comment-template', {}, [['core/columns', {}, [['core/co
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
}, [['core/comment-date'], ['core/comment-edit-link']]], ['core/comment-content'], ['core/comment-reply-link']]]]]]], ['core/comments-pagination']];
|
|
33
|
+
}, [['core/comment-date'], ['core/comment-edit-link']]], ['core/comment-content'], ['core/comment-reply-link']]]]]]], ['core/comments-pagination'], ['core/post-comments-form']];
|
|
34
34
|
export default function CommentsQueryLoopEdit(_ref) {
|
|
35
35
|
let {
|
|
36
36
|
attributes,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/comments-query-loop/edit.js"],"names":["useBlockProps","useInnerBlocksProps","CommentsInspectorControls","TEMPLATE","width","size","style","border","radius","layout","type","spacing","margin","top","bottom","CommentsQueryLoopEdit","attributes","setAttributes","tagName","TagName","blockProps","innerBlocksProps","template"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,aAAT,EAAwBC,mBAAxB,QAAmD,yBAAnD;AAEA;AACA;AACA;;AACA,OAAOC,yBAAP,MAAsC,oCAAtC;AAEA,MAAMC,QAAQ,GAAG,CAChB,CACC,uBADD,EAEC,EAFD,EAGC,CACC,CACC,cADD,EAEC,EAFD,EAGC,CACC,CACC,aADD,EAEC;AAAEC,EAAAA,KAAK,EAAE;AAAT,CAFD,EAGC,CACC,CACC,aADD,EAEC;AACCC,EAAAA,IAAI,EAAE,EADP;AAECC,EAAAA,KAAK,EAAE;AACNC,IAAAA,MAAM,EAAE;AAAEC,MAAAA,MAAM,EAAE;AAAV;AADF;AAFR,CAFD,CADD,CAHD,CADD,EAgBC,CACC,aADD,EAEC,EAFD,EAGC,CACC,CAAE,0BAAF,CADD,EAEC,CACC,YADD,EAEC;AACCC,EAAAA,MAAM,EAAE;AAAEC,IAAAA,IAAI,EAAE;AAAR,GADT;AAECJ,EAAAA,KAAK,EAAE;AACNK,IAAAA,OAAO,EAAE;AACRC,MAAAA,MAAM,EAAE;AACPC,QAAAA,GAAG,EAAE,KADE;AAEPC,QAAAA,MAAM,EAAE;AAFD;AADA;AADH;AAFR,CAFD,EAaC,CACC,CAAE,mBAAF,CADD,EAEC,CAAE,wBAAF,CAFD,CAbD,CAFD,EAoBC,CAAE,sBAAF,CApBD,EAqBC,CAAE,yBAAF,CArBD,CAHD,CAhBD,CAHD,CADD,CAHD,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/comments-query-loop/edit.js"],"names":["useBlockProps","useInnerBlocksProps","CommentsInspectorControls","TEMPLATE","width","size","style","border","radius","layout","type","spacing","margin","top","bottom","CommentsQueryLoopEdit","attributes","setAttributes","tagName","TagName","blockProps","innerBlocksProps","template"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,aAAT,EAAwBC,mBAAxB,QAAmD,yBAAnD;AAEA;AACA;AACA;;AACA,OAAOC,yBAAP,MAAsC,oCAAtC;AAEA,MAAMC,QAAQ,GAAG,CAChB,CAAE,qBAAF,CADgB,EAEhB,CACC,uBADD,EAEC,EAFD,EAGC,CACC,CACC,cADD,EAEC,EAFD,EAGC,CACC,CACC,aADD,EAEC;AAAEC,EAAAA,KAAK,EAAE;AAAT,CAFD,EAGC,CACC,CACC,aADD,EAEC;AACCC,EAAAA,IAAI,EAAE,EADP;AAECC,EAAAA,KAAK,EAAE;AACNC,IAAAA,MAAM,EAAE;AAAEC,MAAAA,MAAM,EAAE;AAAV;AADF;AAFR,CAFD,CADD,CAHD,CADD,EAgBC,CACC,aADD,EAEC,EAFD,EAGC,CACC,CAAE,0BAAF,CADD,EAEC,CACC,YADD,EAEC;AACCC,EAAAA,MAAM,EAAE;AAAEC,IAAAA,IAAI,EAAE;AAAR,GADT;AAECJ,EAAAA,KAAK,EAAE;AACNK,IAAAA,OAAO,EAAE;AACRC,MAAAA,MAAM,EAAE;AACPC,QAAAA,GAAG,EAAE,KADE;AAEPC,QAAAA,MAAM,EAAE;AAFD;AADA;AADH;AAFR,CAFD,EAaC,CACC,CAAE,mBAAF,CADD,EAEC,CAAE,wBAAF,CAFD,CAbD,CAFD,EAoBC,CAAE,sBAAF,CApBD,EAqBC,CAAE,yBAAF,CArBD,CAHD,CAhBD,CAHD,CADD,CAHD,CAFgB,EAwDhB,CAAE,0BAAF,CAxDgB,EAyDhB,CAAE,yBAAF,CAzDgB,CAAjB;AA4DA,eAAe,SAASC,qBAAT,OAAgE;AAAA,MAAhC;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,GAAgC;AAC9E,QAAM;AAAEC,IAAAA,OAAO,EAAEC;AAAX,MAAuBH,UAA7B;AAEA,QAAMI,UAAU,GAAGpB,aAAa,EAAhC;AACA,QAAMqB,gBAAgB,GAAGpB,mBAAmB,CAAEmB,UAAF,EAAc;AACzDE,IAAAA,QAAQ,EAAEnB;AAD+C,GAAd,CAA5C;AAIA,SACC,8BACC,cAAC,yBAAD;AACC,IAAA,UAAU,EAAGa,UADd;AAEC,IAAA,aAAa,EAAGC;AAFjB,IADD,EAKC,cAAC,OAAD,EAAcI,gBAAd,CALD,CADD;AASA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport CommentsInspectorControls from './edit/comments-inspector-controls';\n\nconst TEMPLATE = [\n\t[ 'core/comments-title' ],\n\t[\n\t\t'core/comment-template',\n\t\t{},\n\t\t[\n\t\t\t[\n\t\t\t\t'core/columns',\n\t\t\t\t{},\n\t\t\t\t[\n\t\t\t\t\t[\n\t\t\t\t\t\t'core/column',\n\t\t\t\t\t\t{ width: '40px' },\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t'core/avatar',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tsize: 40,\n\t\t\t\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\t\t\t\tborder: { radius: '20px' },\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\t[\n\t\t\t\t\t\t'core/column',\n\t\t\t\t\t\t{},\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t[ 'core/comment-author-name' ],\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t'core/group',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tlayout: { type: 'flex' },\n\t\t\t\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\t\t\t\tspacing: {\n\t\t\t\t\t\t\t\t\t\t\tmargin: {\n\t\t\t\t\t\t\t\t\t\t\t\ttop: '0px',\n\t\t\t\t\t\t\t\t\t\t\t\tbottom: '0px',\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\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\t[\n\t\t\t\t\t\t\t\t\t[ 'core/comment-date' ],\n\t\t\t\t\t\t\t\t\t[ 'core/comment-edit-link' ],\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t[ 'core/comment-content' ],\n\t\t\t\t\t\t\t[ 'core/comment-reply-link' ],\n\t\t\t\t\t\t],\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t],\n\t\t],\n\t],\n\t[ 'core/comments-pagination' ],\n\t[ 'core/post-comments-form' ],\n];\n\nexport default function CommentsQueryLoopEdit( { attributes, setAttributes } ) {\n\tconst { tagName: TagName } = attributes;\n\n\tconst blockProps = useBlockProps();\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: TEMPLATE,\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<CommentsInspectorControls\n\t\t\t\tattributes={ attributes }\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t/>\n\t\t\t<TagName { ...innerBlocksProps } />\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import classnames from 'classnames';
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { AlignmentControl, BlockControls, useBlockProps, PlainText, InspectorControls } from '@wordpress/block-editor';
|
|
12
|
+
import { __ } from '@wordpress/i18n';
|
|
13
|
+
import { useEntityProp } from '@wordpress/core-data';
|
|
14
|
+
import { PanelBody, ToggleControl, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption } from '@wordpress/components';
|
|
15
|
+
import { useState, useEffect } from '@wordpress/element';
|
|
16
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
17
|
+
import { addQueryArgs } from '@wordpress/url';
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import HeadingLevelDropdown from '../heading/heading-level-dropdown';
|
|
23
|
+
export default function Edit(_ref) {
|
|
24
|
+
let {
|
|
25
|
+
attributes: {
|
|
26
|
+
textAlign,
|
|
27
|
+
singleCommentLabel,
|
|
28
|
+
multipleCommentsLabel,
|
|
29
|
+
showPostTitle,
|
|
30
|
+
showCommentsCount,
|
|
31
|
+
level
|
|
32
|
+
},
|
|
33
|
+
setAttributes,
|
|
34
|
+
context: {
|
|
35
|
+
postType,
|
|
36
|
+
postId
|
|
37
|
+
}
|
|
38
|
+
} = _ref;
|
|
39
|
+
const TagName = 'h' + level;
|
|
40
|
+
const [commentsCount, setCommentsCount] = useState();
|
|
41
|
+
const [editingMode, setEditingMode] = useState('plural');
|
|
42
|
+
const [rawTitle] = useEntityProp('postType', postType, 'title', postId);
|
|
43
|
+
const isSiteEditor = typeof postId === 'undefined';
|
|
44
|
+
const blockProps = useBlockProps({
|
|
45
|
+
className: classnames({
|
|
46
|
+
[`has-text-align-${textAlign}`]: textAlign
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (isSiteEditor) {
|
|
51
|
+
setCommentsCount(3);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const currentPostId = postId;
|
|
56
|
+
apiFetch({
|
|
57
|
+
path: addQueryArgs('/wp/v2/comments', {
|
|
58
|
+
post: postId,
|
|
59
|
+
_fields: 'id'
|
|
60
|
+
}),
|
|
61
|
+
method: 'HEAD',
|
|
62
|
+
parse: false
|
|
63
|
+
}).then(res => {
|
|
64
|
+
// Stale requests will have the `currentPostId` of an older closure.
|
|
65
|
+
if (currentPostId === postId) {
|
|
66
|
+
setCommentsCount(parseInt(res.headers.get('X-WP-Total')));
|
|
67
|
+
}
|
|
68
|
+
}).catch(() => {
|
|
69
|
+
setCommentsCount(0);
|
|
70
|
+
});
|
|
71
|
+
}, [postId]);
|
|
72
|
+
const blockControls = createElement(BlockControls, {
|
|
73
|
+
group: "block"
|
|
74
|
+
}, createElement(AlignmentControl, {
|
|
75
|
+
value: textAlign,
|
|
76
|
+
onChange: newAlign => setAttributes({
|
|
77
|
+
textAlign: newAlign
|
|
78
|
+
})
|
|
79
|
+
}), createElement(HeadingLevelDropdown, {
|
|
80
|
+
selectedLevel: level,
|
|
81
|
+
onChange: newLevel => setAttributes({
|
|
82
|
+
level: newLevel
|
|
83
|
+
})
|
|
84
|
+
}));
|
|
85
|
+
const inspectorControls = createElement(InspectorControls, null, createElement(PanelBody, {
|
|
86
|
+
title: __('Settings')
|
|
87
|
+
}, isSiteEditor && createElement(ToggleGroupControl, {
|
|
88
|
+
label: __('Editing mode'),
|
|
89
|
+
onChange: setEditingMode,
|
|
90
|
+
value: editingMode
|
|
91
|
+
}, createElement(ToggleGroupControlOption, {
|
|
92
|
+
label: __('Singular'),
|
|
93
|
+
value: "singular"
|
|
94
|
+
}), createElement(ToggleGroupControlOption, {
|
|
95
|
+
label: __('Plural'),
|
|
96
|
+
value: "plural"
|
|
97
|
+
})), createElement(ToggleControl, {
|
|
98
|
+
label: __('Show post title'),
|
|
99
|
+
checked: showPostTitle,
|
|
100
|
+
onChange: value => setAttributes({
|
|
101
|
+
showPostTitle: value
|
|
102
|
+
})
|
|
103
|
+
}), createElement(ToggleControl, {
|
|
104
|
+
label: __('Show comments count'),
|
|
105
|
+
checked: showCommentsCount,
|
|
106
|
+
onChange: value => setAttributes({
|
|
107
|
+
showCommentsCount: value
|
|
108
|
+
})
|
|
109
|
+
})));
|
|
110
|
+
const postTitle = isSiteEditor ? __('"Post Title"') : `"${rawTitle}"`;
|
|
111
|
+
const singlePlaceholder = showPostTitle ? __('One response to ') : __('One response');
|
|
112
|
+
const multiplePlaceholder = showPostTitle ? __('Responses to ') : __('Responses');
|
|
113
|
+
return createElement(Fragment, null, blockControls, inspectorControls, createElement(TagName, blockProps, editingMode === 'singular' || commentsCount === 1 ? createElement(Fragment, null, createElement(PlainText, {
|
|
114
|
+
__experimentalVersion: 2,
|
|
115
|
+
tagName: "span",
|
|
116
|
+
"aria-label": singlePlaceholder,
|
|
117
|
+
placeholder: singlePlaceholder,
|
|
118
|
+
value: singleCommentLabel,
|
|
119
|
+
onChange: newLabel => setAttributes({
|
|
120
|
+
singleCommentLabel: newLabel
|
|
121
|
+
})
|
|
122
|
+
}), showPostTitle ? postTitle : null) : createElement(Fragment, null, showCommentsCount ? commentsCount : null, createElement(PlainText, {
|
|
123
|
+
__experimentalVersion: 2,
|
|
124
|
+
tagName: "span",
|
|
125
|
+
"aria-label": showCommentsCount ? ` ${multiplePlaceholder}` : multiplePlaceholder,
|
|
126
|
+
placeholder: showCommentsCount ? ` ${multiplePlaceholder}` : multiplePlaceholder,
|
|
127
|
+
value: multipleCommentsLabel,
|
|
128
|
+
onChange: newLabel => setAttributes({
|
|
129
|
+
multipleCommentsLabel: newLabel
|
|
130
|
+
})
|
|
131
|
+
}), showPostTitle ? postTitle : null)));
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/comments-title/edit.js"],"names":["classnames","AlignmentControl","BlockControls","useBlockProps","PlainText","InspectorControls","__","useEntityProp","PanelBody","ToggleControl","__experimentalToggleGroupControl","ToggleGroupControl","__experimentalToggleGroupControlOption","ToggleGroupControlOption","useState","useEffect","apiFetch","addQueryArgs","HeadingLevelDropdown","Edit","attributes","textAlign","singleCommentLabel","multipleCommentsLabel","showPostTitle","showCommentsCount","level","setAttributes","context","postType","postId","TagName","commentsCount","setCommentsCount","editingMode","setEditingMode","rawTitle","isSiteEditor","blockProps","className","currentPostId","path","post","_fields","method","parse","then","res","parseInt","headers","get","catch","blockControls","newAlign","newLevel","inspectorControls","value","postTitle","singlePlaceholder","multiplePlaceholder","newLabel"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SACCC,gBADD,EAECC,aAFD,EAGCC,aAHD,EAICC,SAJD,EAKCC,iBALD,QAMO,yBANP;AAOA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,aAAT,QAA8B,sBAA9B;AACA,SACCC,SADD,EAECC,aAFD,EAGCC,gCAAgC,IAAIC,kBAHrC,EAICC,sCAAsC,IAAIC,wBAJ3C,QAKO,uBALP;AAMA,SAASC,QAAT,EAAmBC,SAAnB,QAAoC,oBAApC;AACA,OAAOC,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AAEA;AACA;AACA;;AACA,OAAOC,oBAAP,MAAiC,mCAAjC;AAEA,eAAe,SAASC,IAAT,OAWX;AAAA,MAX0B;AAC7BC,IAAAA,UAAU,EAAE;AACXC,MAAAA,SADW;AAEXC,MAAAA,kBAFW;AAGXC,MAAAA,qBAHW;AAIXC,MAAAA,aAJW;AAKXC,MAAAA,iBALW;AAMXC,MAAAA;AANW,KADiB;AAS7BC,IAAAA,aAT6B;AAU7BC,IAAAA,OAAO,EAAE;AAAEC,MAAAA,QAAF;AAAYC,MAAAA;AAAZ;AAVoB,GAW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,CADD;AAkDA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tAlignmentControl,\n\tBlockControls,\n\tuseBlockProps,\n\tPlainText,\n\tInspectorControls,\n} from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\nimport { useEntityProp } from '@wordpress/core-data';\nimport {\n\tPanelBody,\n\tToggleControl,\n\t__experimentalToggleGroupControl as ToggleGroupControl,\n\t__experimentalToggleGroupControlOption as ToggleGroupControlOption,\n} from '@wordpress/components';\nimport { useState, useEffect } from '@wordpress/element';\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport HeadingLevelDropdown from '../heading/heading-level-dropdown';\n\nexport default function Edit( {\n\tattributes: {\n\t\ttextAlign,\n\t\tsingleCommentLabel,\n\t\tmultipleCommentsLabel,\n\t\tshowPostTitle,\n\t\tshowCommentsCount,\n\t\tlevel,\n\t},\n\tsetAttributes,\n\tcontext: { postType, postId },\n} ) {\n\tconst TagName = 'h' + level;\n\tconst [ commentsCount, setCommentsCount ] = useState();\n\tconst [ editingMode, setEditingMode ] = useState( 'plural' );\n\tconst [ rawTitle ] = useEntityProp( 'postType', postType, 'title', postId );\n\tconst isSiteEditor = typeof postId === 'undefined';\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t} );\n\n\tuseEffect( () => {\n\t\tif ( isSiteEditor ) {\n\t\t\tsetCommentsCount( 3 );\n\t\t\treturn;\n\t\t}\n\t\tconst currentPostId = postId;\n\t\tapiFetch( {\n\t\t\tpath: addQueryArgs( '/wp/v2/comments', {\n\t\t\t\tpost: postId,\n\t\t\t\t_fields: 'id',\n\t\t\t} ),\n\t\t\tmethod: 'HEAD',\n\t\t\tparse: false,\n\t\t} )\n\t\t\t.then( ( res ) => {\n\t\t\t\t// Stale requests will have the `currentPostId` of an older closure.\n\t\t\t\tif ( currentPostId === postId ) {\n\t\t\t\t\tsetCommentsCount(\n\t\t\t\t\t\tparseInt( res.headers.get( 'X-WP-Total' ) )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( () => {\n\t\t\t\tsetCommentsCount( 0 );\n\t\t\t} );\n\t}, [ postId ] );\n\n\tconst blockControls = (\n\t\t<BlockControls group=\"block\">\n\t\t\t<AlignmentControl\n\t\t\t\tvalue={ textAlign }\n\t\t\t\tonChange={ ( newAlign ) =>\n\t\t\t\t\tsetAttributes( { textAlign: newAlign } )\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<HeadingLevelDropdown\n\t\t\t\tselectedLevel={ level }\n\t\t\t\tonChange={ ( newLevel ) =>\n\t\t\t\t\tsetAttributes( { level: newLevel } )\n\t\t\t\t}\n\t\t\t/>\n\t\t</BlockControls>\n\t);\n\n\tconst inspectorControls = (\n\t\t<InspectorControls>\n\t\t\t<PanelBody title={ __( 'Settings' ) }>\n\t\t\t\t{ isSiteEditor && (\n\t\t\t\t\t<ToggleGroupControl\n\t\t\t\t\t\tlabel={ __( 'Editing mode' ) }\n\t\t\t\t\t\tonChange={ setEditingMode }\n\t\t\t\t\t\tvalue={ editingMode }\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tlabel={ __( 'Singular' ) }\n\t\t\t\t\t\t\tvalue=\"singular\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<ToggleGroupControlOption\n\t\t\t\t\t\t\tlabel={ __( 'Plural' ) }\n\t\t\t\t\t\t\tvalue=\"plural\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToggleGroupControl>\n\t\t\t\t) }\n\t\t\t\t<ToggleControl\n\t\t\t\t\tlabel={ __( 'Show post title' ) }\n\t\t\t\t\tchecked={ showPostTitle }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { showPostTitle: value } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<ToggleControl\n\t\t\t\t\tlabel={ __( 'Show comments count' ) }\n\t\t\t\t\tchecked={ showCommentsCount }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { showCommentsCount: value } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n\n\tconst postTitle = isSiteEditor ? __( '\"Post Title\"' ) : `\"${ rawTitle }\"`;\n\n\tconst singlePlaceholder = showPostTitle\n\t\t? __( 'One response to ' )\n\t\t: __( 'One response' );\n\n\tconst multiplePlaceholder = showPostTitle\n\t\t? __( 'Responses to ' )\n\t\t: __( 'Responses' );\n\n\treturn (\n\t\t<>\n\t\t\t{ blockControls }\n\t\t\t{ inspectorControls }\n\t\t\t<TagName { ...blockProps }>\n\t\t\t\t{ editingMode === 'singular' || commentsCount === 1 ? (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<PlainText\n\t\t\t\t\t\t\t__experimentalVersion={ 2 }\n\t\t\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\t\t\taria-label={ singlePlaceholder }\n\t\t\t\t\t\t\tplaceholder={ singlePlaceholder }\n\t\t\t\t\t\t\tvalue={ singleCommentLabel }\n\t\t\t\t\t\t\tonChange={ ( newLabel ) =>\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tsingleCommentLabel: newLabel,\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\t{ showPostTitle ? postTitle : null }\n\t\t\t\t\t</>\n\t\t\t\t) : (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ showCommentsCount ? commentsCount : null }\n\t\t\t\t\t\t<PlainText\n\t\t\t\t\t\t\t__experimentalVersion={ 2 }\n\t\t\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\t\t\taria-label={\n\t\t\t\t\t\t\t\tshowCommentsCount\n\t\t\t\t\t\t\t\t\t? ` ${ multiplePlaceholder }`\n\t\t\t\t\t\t\t\t\t: multiplePlaceholder\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tplaceholder={\n\t\t\t\t\t\t\t\tshowCommentsCount\n\t\t\t\t\t\t\t\t\t? ` ${ multiplePlaceholder }`\n\t\t\t\t\t\t\t\t\t: multiplePlaceholder\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tvalue={ multipleCommentsLabel }\n\t\t\t\t\t\t\tonChange={ ( newLabel ) =>\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tmultipleCommentsLabel: newLabel,\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\t{ showPostTitle ? postTitle : null }\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</TagName>\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { commentTitle as icon } from '@wordpress/icons';
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const metadata = {
|
|
10
|
+
$schema: "https://schemas.wp.org/trunk/block.json",
|
|
11
|
+
apiVersion: 2,
|
|
12
|
+
name: "core/comments-title",
|
|
13
|
+
title: "Comments Title",
|
|
14
|
+
category: "theme",
|
|
15
|
+
ancestor: ["core/comments-query-loop"],
|
|
16
|
+
description: "Displays a title with the number of comments",
|
|
17
|
+
textdomain: "default",
|
|
18
|
+
usesContext: ["postId", "postType"],
|
|
19
|
+
attributes: {
|
|
20
|
+
textAlign: {
|
|
21
|
+
type: "string"
|
|
22
|
+
},
|
|
23
|
+
singleCommentLabel: {
|
|
24
|
+
type: "string"
|
|
25
|
+
},
|
|
26
|
+
multipleCommentsLabel: {
|
|
27
|
+
type: "string"
|
|
28
|
+
},
|
|
29
|
+
showPostTitle: {
|
|
30
|
+
type: "boolean",
|
|
31
|
+
"default": true
|
|
32
|
+
},
|
|
33
|
+
showCommentsCount: {
|
|
34
|
+
type: "boolean",
|
|
35
|
+
"default": true
|
|
36
|
+
},
|
|
37
|
+
level: {
|
|
38
|
+
type: "number",
|
|
39
|
+
"default": 2
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
supports: {
|
|
43
|
+
anchor: false,
|
|
44
|
+
align: true,
|
|
45
|
+
html: false,
|
|
46
|
+
__experimentalBorder: {
|
|
47
|
+
radius: true,
|
|
48
|
+
color: true,
|
|
49
|
+
width: true,
|
|
50
|
+
style: true
|
|
51
|
+
},
|
|
52
|
+
color: {
|
|
53
|
+
gradients: true,
|
|
54
|
+
__experimentalDefaultControls: {
|
|
55
|
+
background: true,
|
|
56
|
+
text: true
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
spacing: {
|
|
60
|
+
margin: true,
|
|
61
|
+
padding: true
|
|
62
|
+
},
|
|
63
|
+
typography: {
|
|
64
|
+
fontSize: true,
|
|
65
|
+
lineHeight: true,
|
|
66
|
+
__experimentalFontStyle: true,
|
|
67
|
+
__experimentalFontWeight: true,
|
|
68
|
+
__experimentalFontFamily: true,
|
|
69
|
+
__experimentalTextTransform: true,
|
|
70
|
+
__experimentalDefaultControls: {
|
|
71
|
+
fontSize: true,
|
|
72
|
+
__experimentalFontFamily: true,
|
|
73
|
+
__experimentalFontStyle: true,
|
|
74
|
+
__experimentalFontWeight: true
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
import edit from './edit';
|
|
80
|
+
const {
|
|
81
|
+
name
|
|
82
|
+
} = metadata;
|
|
83
|
+
export { metadata, name };
|
|
84
|
+
export const settings = {
|
|
85
|
+
icon,
|
|
86
|
+
edit
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/comments-title/index.js"],"names":["commentTitle","icon","edit","name","metadata","settings"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAY,IAAIC,IAAzB,QAAqC,kBAArC;AAEA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAOC,IAAP,MAAiB,QAAjB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAWC,QAAjB;AACA,SAASA,QAAT,EAAmBD,IAAnB;AAEA,OAAO,MAAME,QAAQ,GAAG;AACvBJ,EAAAA,IADuB;AAEvBC,EAAAA;AAFuB,CAAjB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { commentTitle as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport metadata from './block.json';\nimport edit from './edit';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n};\n"]}
|
package/build-module/index.js
CHANGED
|
@@ -29,6 +29,7 @@ import * as commentsQueryLoop from './comments-query-loop';
|
|
|
29
29
|
import * as commentsPagination from './comments-pagination';
|
|
30
30
|
import * as commentsPaginationNext from './comments-pagination-next';
|
|
31
31
|
import * as commentsPaginationNumbers from './comments-pagination-numbers';
|
|
32
|
+
import * as commentsTitle from './comments-title';
|
|
32
33
|
import * as cover from './cover';
|
|
33
34
|
import * as embed from './embed';
|
|
34
35
|
import * as file from './file';
|
|
@@ -139,7 +140,7 @@ paragraph, image, heading, gallery, list, quote, // Register all remaining core
|
|
|
139
140
|
archives, audio, button, buttons, calendar, categories, window.wp && window.wp.oldEditor ? classic : null, // Only add the classic block in WP Context.
|
|
140
141
|
code, column, columns, cover, embed, file, group, html, latestComments, latestPosts, mediaText, missing, more, nextpage, pageList, pattern, preformatted, pullquote, reusableBlock, rss, search, separator, shortcode, socialLink, socialLinks, spacer, table, // tableOfContents,
|
|
141
142
|
tagCloud, textColumns, verse, video, // theme blocks
|
|
142
|
-
navigation, navigationLink, navigationSubmenu, siteLogo, siteTitle, siteTagline, query, templatePart, avatar, postTitle, postExcerpt, postFeaturedImage, postContent, postAuthor, postDate, postTerms, postNavigationLink, postTemplate, queryPagination, queryPaginationNext, queryPaginationNumbers, queryPaginationPrevious, queryNoResults, readMore, commentAuthorName, commentContent, commentDate, commentEditLink, commentReplyLink, commentTemplate, commentsQueryLoop, commentsPagination, commentsPaginationNext, commentsPaginationNumbers, commentsPaginationPrevious, postComments, homeLink, logInOut, termDescription, queryTitle, postAuthorBiography];
|
|
143
|
+
navigation, navigationLink, navigationSubmenu, siteLogo, siteTitle, siteTagline, query, templatePart, avatar, postTitle, postExcerpt, postFeaturedImage, postContent, postAuthor, postDate, postTerms, postNavigationLink, postTemplate, queryPagination, queryPaginationNext, queryPaginationNumbers, queryPaginationPrevious, queryNoResults, readMore, commentAuthorName, commentContent, commentDate, commentEditLink, commentReplyLink, commentTemplate, commentsTitle, commentsQueryLoop, commentsPagination, commentsPaginationNext, commentsPaginationNumbers, commentsPaginationPrevious, postComments, postCommentsForm, homeLink, logInOut, termDescription, queryTitle, postAuthorBiography];
|
|
143
144
|
/**
|
|
144
145
|
* Function to register core blocks provided by the block editor.
|
|
145
146
|
*
|
|
@@ -183,6 +184,6 @@ export const __experimentalRegisterExperimentalCoreBlocks = process.env.IS_GUTEN
|
|
|
183
184
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
184
185
|
[// Experimental blocks.
|
|
185
186
|
postAuthorName, ...(window.__experimentalEnableListBlockV2 ? [listItem] : []), // Full Site Editing blocks.
|
|
186
|
-
...(enableFSEBlocks ? [commentAuthorAvatar, navigationArea, postComment, postCommentsCount,
|
|
187
|
+
...(enableFSEBlocks ? [commentAuthorAvatar, navigationArea, postComment, postCommentsCount, postCommentsLink] : [])].forEach(registerBlock);
|
|
187
188
|
} : undefined;
|
|
188
189
|
//# sourceMappingURL=index.js.map
|