@wordpress/editor 14.32.1-next.ff1cebbba.0 → 14.33.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/bindings/api.js +2 -2
- package/build/bindings/api.js.map +3 -3
- package/build/bindings/post-data.js +50 -13
- package/build/bindings/post-data.js.map +3 -3
- package/build/bindings/term-data.js +165 -0
- package/build/bindings/term-data.js.map +7 -0
- package/build/components/collab-sidebar/add-comment.js +11 -15
- package/build/components/collab-sidebar/add-comment.js.map +2 -2
- package/build/components/collab-sidebar/comment-menu-item.js +1 -1
- package/build/components/collab-sidebar/comment-menu-item.js.map +2 -2
- package/build/components/collab-sidebar/comments.js +89 -67
- package/build/components/collab-sidebar/comments.js.map +2 -2
- package/build/components/collab-sidebar/constants.js +3 -0
- package/build/components/collab-sidebar/constants.js.map +2 -2
- package/build/components/collab-sidebar/hooks.js +13 -6
- package/build/components/collab-sidebar/hooks.js.map +2 -2
- package/build/components/collab-sidebar/index.js +28 -15
- package/build/components/collab-sidebar/index.js.map +3 -3
- package/build/components/post-fields/index.js +3 -25
- package/build/components/post-fields/index.js.map +2 -2
- package/build/components/post-template/create-new-template-modal.js +2 -1
- package/build/components/post-template/create-new-template-modal.js.map +2 -2
- package/build/components/provider/index.js +3 -2
- package/build/components/provider/index.js.map +2 -2
- package/build/components/provider/use-hide-blocks-from-inserter.js +4 -26
- package/build/components/provider/use-hide-blocks-from-inserter.js.map +3 -3
- package/build/store/actions.js +12 -11
- package/build/store/actions.js.map +2 -2
- package/build-module/bindings/api.js +2 -2
- package/build-module/bindings/api.js.map +2 -2
- package/build-module/bindings/post-data.js +50 -13
- package/build-module/bindings/post-data.js.map +2 -2
- package/build-module/bindings/term-data.js +145 -0
- package/build-module/bindings/term-data.js.map +7 -0
- package/build-module/components/collab-sidebar/add-comment.js +12 -16
- package/build-module/components/collab-sidebar/add-comment.js.map +2 -2
- package/build-module/components/collab-sidebar/comment-menu-item.js +1 -1
- package/build-module/components/collab-sidebar/comment-menu-item.js.map +2 -2
- package/build-module/components/collab-sidebar/comments.js +89 -67
- package/build-module/components/collab-sidebar/comments.js.map +2 -2
- package/build-module/components/collab-sidebar/constants.js +2 -0
- package/build-module/components/collab-sidebar/constants.js.map +2 -2
- package/build-module/components/collab-sidebar/hooks.js +13 -6
- package/build-module/components/collab-sidebar/hooks.js.map +2 -2
- package/build-module/components/collab-sidebar/index.js +33 -16
- package/build-module/components/collab-sidebar/index.js.map +2 -2
- package/build-module/components/post-fields/index.js +4 -26
- package/build-module/components/post-fields/index.js.map +2 -2
- package/build-module/components/post-template/create-new-template-modal.js +2 -1
- package/build-module/components/post-template/create-new-template-modal.js.map +2 -2
- package/build-module/components/provider/index.js +3 -2
- package/build-module/components/provider/index.js.map +2 -2
- package/build-module/components/provider/use-hide-blocks-from-inserter.js +4 -26
- package/build-module/components/provider/use-hide-blocks-from-inserter.js.map +2 -2
- package/build-module/store/actions.js +12 -11
- package/build-module/store/actions.js.map +2 -2
- package/build-style/style-rtl.css +1 -0
- package/build-style/style.css +1 -0
- package/build-types/bindings/post-data.d.ts +7 -4
- package/build-types/bindings/term-data.d.ts +42 -0
- package/build-types/bindings/term-data.d.ts.map +1 -0
- package/build-types/components/collab-sidebar/add-comment.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/comments.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/constants.d.ts +1 -0
- package/build-types/components/collab-sidebar/constants.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/hooks.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/index.d.ts.map +1 -1
- package/build-types/components/post-fields/index.d.ts +1 -5
- package/build-types/components/post-fields/index.d.ts.map +1 -1
- package/build-types/components/post-template/create-new-template-modal.d.ts.map +1 -1
- package/build-types/components/provider/index.d.ts.map +1 -1
- package/build-types/components/provider/use-hide-blocks-from-inserter.d.ts.map +1 -1
- package/build-types/store/actions.d.ts.map +1 -1
- package/package.json +38 -38
- package/src/bindings/api.js +2 -2
- package/src/bindings/post-data.js +80 -17
- package/src/bindings/term-data.js +224 -0
- package/src/components/collab-sidebar/add-comment.js +12 -23
- package/src/components/collab-sidebar/comment-menu-item.js +1 -1
- package/src/components/collab-sidebar/comments.js +111 -63
- package/src/components/collab-sidebar/constants.js +1 -0
- package/src/components/collab-sidebar/hooks.js +16 -9
- package/src/components/collab-sidebar/index.js +66 -49
- package/src/components/collab-sidebar/style.scss +1 -0
- package/src/components/post-fields/index.ts +5 -42
- package/src/components/post-template/create-new-template-modal.js +1 -0
- package/src/components/provider/index.js +5 -2
- package/src/components/provider/use-hide-blocks-from-inserter.js +6 -37
- package/src/store/actions.js +15 -17
- package/tsconfig.tsbuildinfo +1 -1
- package/build/bindings/entity.js +0 -78
- package/build/bindings/entity.js.map +0 -7
- package/build-module/bindings/entity.js +0 -58
- package/build-module/bindings/entity.js.map +0 -7
- package/build-types/bindings/entity.d.ts +0 -16
- package/build-types/bindings/entity.d.ts.map +0 -1
- package/src/bindings/entity.js +0 -89
package/CHANGELOG.md
CHANGED
package/build/bindings/api.js
CHANGED
|
@@ -35,12 +35,12 @@ var import_blocks = require("@wordpress/blocks");
|
|
|
35
35
|
var import_pattern_overrides = __toESM(require("./pattern-overrides"));
|
|
36
36
|
var import_post_data = __toESM(require("./post-data"));
|
|
37
37
|
var import_post_meta = __toESM(require("./post-meta"));
|
|
38
|
-
var
|
|
38
|
+
var import_term_data = __toESM(require("./term-data"));
|
|
39
39
|
function registerCoreBlockBindingsSources() {
|
|
40
40
|
(0, import_blocks.registerBlockBindingsSource)(import_pattern_overrides.default);
|
|
41
41
|
(0, import_blocks.registerBlockBindingsSource)(import_post_data.default);
|
|
42
42
|
(0, import_blocks.registerBlockBindingsSource)(import_post_meta.default);
|
|
43
|
-
(0, import_blocks.registerBlockBindingsSource)(
|
|
43
|
+
(0, import_blocks.registerBlockBindingsSource)(import_term_data.default);
|
|
44
44
|
}
|
|
45
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
46
46
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/bindings/api.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { registerBlockBindingsSource } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport patternOverrides from './pattern-overrides';\nimport postData from './post-data';\nimport postMeta from './post-meta';\nimport
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA4C;AAK5C,+BAA6B;AAC7B,uBAAqB;AACrB,uBAAqB;AACrB,
|
|
6
|
-
"names": ["patternOverrides", "postData", "postMeta", "
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { registerBlockBindingsSource } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport patternOverrides from './pattern-overrides';\nimport postData from './post-data';\nimport postMeta from './post-meta';\nimport termData from './term-data';\n\n/**\n * Function to register core block bindings sources provided by the editor.\n *\n * @example\n * ```js\n * import { registerCoreBlockBindingsSources } from '@wordpress/editor';\n *\n * registerCoreBlockBindingsSources();\n * ```\n */\nexport function registerCoreBlockBindingsSources() {\n\tregisterBlockBindingsSource( patternOverrides );\n\tregisterBlockBindingsSource( postData );\n\tregisterBlockBindingsSource( postMeta );\n\tregisterBlockBindingsSource( termData );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA4C;AAK5C,+BAA6B;AAC7B,uBAAqB;AACrB,uBAAqB;AACrB,uBAAqB;AAYd,SAAS,mCAAmC;AAClD,iDAA6B,yBAAAA,OAAiB;AAC9C,iDAA6B,iBAAAC,OAAS;AACtC,iDAA6B,iBAAAC,OAAS;AACtC,iDAA6B,iBAAAC,OAAS;AACvC;",
|
|
6
|
+
"names": ["patternOverrides", "postData", "postMeta", "termData"]
|
|
7
7
|
}
|
|
@@ -23,14 +23,31 @@ __export(post_data_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(post_data_exports);
|
|
24
24
|
var import_i18n = require("@wordpress/i18n");
|
|
25
25
|
var import_core_data = require("@wordpress/core-data");
|
|
26
|
-
|
|
26
|
+
var import_block_editor = require("@wordpress/block-editor");
|
|
27
|
+
const NAVIGATION_BLOCK_TYPES = [
|
|
28
|
+
"core/navigation-link",
|
|
29
|
+
"core/navigation-submenu"
|
|
30
|
+
];
|
|
31
|
+
function getPostDataFields(select, context, clientId) {
|
|
27
32
|
const { getEditedEntityRecord } = select(import_core_data.store);
|
|
33
|
+
const { getBlockAttributes, getBlockName } = select(import_block_editor.store);
|
|
28
34
|
let entityDataValues, dataFields;
|
|
29
|
-
|
|
35
|
+
const blockName = getBlockName?.(clientId);
|
|
36
|
+
const isNavigationBlock = NAVIGATION_BLOCK_TYPES.includes(blockName);
|
|
37
|
+
let postId, postType;
|
|
38
|
+
if (isNavigationBlock) {
|
|
39
|
+
const blockAttributes = getBlockAttributes?.(clientId);
|
|
40
|
+
postId = blockAttributes?.id;
|
|
41
|
+
postType = blockAttributes?.type;
|
|
42
|
+
} else {
|
|
43
|
+
postId = context?.postId;
|
|
44
|
+
postType = context?.postType;
|
|
45
|
+
}
|
|
46
|
+
if (postType && postId) {
|
|
30
47
|
entityDataValues = getEditedEntityRecord(
|
|
31
48
|
"postType",
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
postType,
|
|
50
|
+
postId
|
|
34
51
|
);
|
|
35
52
|
dataFields = {
|
|
36
53
|
date: {
|
|
@@ -42,6 +59,11 @@ function getPostDataFields(select, context) {
|
|
|
42
59
|
label: (0, import_i18n.__)("Post Modified Date"),
|
|
43
60
|
value: entityDataValues?.modified,
|
|
44
61
|
type: "string"
|
|
62
|
+
},
|
|
63
|
+
link: {
|
|
64
|
+
label: (0, import_i18n.__)("Post Link"),
|
|
65
|
+
value: entityDataValues?.link,
|
|
66
|
+
type: "string"
|
|
45
67
|
}
|
|
46
68
|
};
|
|
47
69
|
}
|
|
@@ -52,20 +74,25 @@ function getPostDataFields(select, context) {
|
|
|
52
74
|
}
|
|
53
75
|
var post_data_default = {
|
|
54
76
|
name: "core/post-data",
|
|
55
|
-
getValues({ select, context, bindings }) {
|
|
56
|
-
const dataFields = getPostDataFields(select, context);
|
|
77
|
+
getValues({ select, context, bindings, clientId }) {
|
|
78
|
+
const dataFields = getPostDataFields(select, context, clientId);
|
|
57
79
|
const newValues = {};
|
|
58
80
|
for (const [attributeName, source] of Object.entries(bindings)) {
|
|
59
|
-
const fieldKey = source.args.key;
|
|
81
|
+
const fieldKey = globalThis.IS_GUTENBERG_PLUGIN ? source.args.field || source.args.key : source.args.field;
|
|
60
82
|
const { value: fieldValue, label: fieldLabel } = dataFields?.[fieldKey] || {};
|
|
61
83
|
newValues[attributeName] = fieldValue ?? fieldLabel ?? fieldKey;
|
|
62
84
|
}
|
|
63
85
|
return newValues;
|
|
64
86
|
},
|
|
65
|
-
setValues({ dispatch, context, bindings }) {
|
|
87
|
+
setValues({ dispatch, context, bindings, clientId, select }) {
|
|
88
|
+
const { getBlockName } = select(import_block_editor.store);
|
|
89
|
+
const blockName = getBlockName?.(clientId);
|
|
90
|
+
if (NAVIGATION_BLOCK_TYPES.includes(blockName)) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
66
93
|
const newData = {};
|
|
67
94
|
Object.values(bindings).forEach(({ args, newValue }) => {
|
|
68
|
-
newData[args.
|
|
95
|
+
newData[args.field] = newValue;
|
|
69
96
|
});
|
|
70
97
|
dispatch(import_core_data.store).editEntityRecord(
|
|
71
98
|
"postType",
|
|
@@ -75,13 +102,19 @@ var post_data_default = {
|
|
|
75
102
|
);
|
|
76
103
|
},
|
|
77
104
|
canUserEditValue({ select, context, args }) {
|
|
105
|
+
const { getBlockName, getSelectedBlockClientId } = select(import_block_editor.store);
|
|
106
|
+
const clientId = getSelectedBlockClientId();
|
|
107
|
+
const blockName = getBlockName?.(clientId);
|
|
108
|
+
if (NAVIGATION_BLOCK_TYPES.includes(blockName)) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
78
111
|
if (context?.query || context?.queryId) {
|
|
79
112
|
return false;
|
|
80
113
|
}
|
|
81
114
|
if (!context?.postType) {
|
|
82
115
|
return false;
|
|
83
116
|
}
|
|
84
|
-
const fieldValue = getPostDataFields(select, context)?.[args.
|
|
117
|
+
const fieldValue = getPostDataFields(select, context, void 0)?.[args.field]?.value;
|
|
85
118
|
if (fieldValue === void 0) {
|
|
86
119
|
return false;
|
|
87
120
|
}
|
|
@@ -96,19 +129,23 @@ var post_data_default = {
|
|
|
96
129
|
return true;
|
|
97
130
|
},
|
|
98
131
|
getFieldsList({ select, context }) {
|
|
99
|
-
|
|
132
|
+
const clientId = select(import_block_editor.store).getSelectedBlockClientId();
|
|
133
|
+
return getPostDataFields(select, context, clientId);
|
|
100
134
|
},
|
|
101
135
|
editorUI({ select, context }) {
|
|
102
|
-
const selectedBlock = select(
|
|
136
|
+
const selectedBlock = select(import_block_editor.store).getSelectedBlock();
|
|
103
137
|
if (selectedBlock?.name !== "core/post-date") {
|
|
104
138
|
return {};
|
|
105
139
|
}
|
|
140
|
+
if (NAVIGATION_BLOCK_TYPES.includes(selectedBlock?.name)) {
|
|
141
|
+
return {};
|
|
142
|
+
}
|
|
106
143
|
const postDataFields = Object.entries(
|
|
107
144
|
getPostDataFields(select, context) || {}
|
|
108
145
|
).map(([key, field]) => ({
|
|
109
146
|
label: field.label,
|
|
110
147
|
args: {
|
|
111
|
-
key
|
|
148
|
+
field: key
|
|
112
149
|
},
|
|
113
150
|
type: field.type
|
|
114
151
|
}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/bindings/post-data.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { store as coreDataStore } from '@wordpress/core-data';\n\n/**\n * Gets a list of post data fields with their values and labels\n * to be consumed in the needed callbacks.\n * If the value is not available based on context, like in templates,\n * it falls back to the default value, label, or key.\n *\n * @param {Object} select
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,uBAAuC;
|
|
6
|
-
"names": ["coreDataStore"]
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n// Navigation block types that use special handling for backwards compatibility\nconst NAVIGATION_BLOCK_TYPES = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n];\n\n/**\n * Gets a list of post data fields with their values and labels\n * to be consumed in the needed callbacks.\n * If the value is not available based on context, like in templates,\n * it falls back to the default value, label, or key.\n *\n * @param {Object} select The select function from the data store.\n * @param {Object} context The context provided.\n * @param {string} clientId The block client ID used to read attributes.\n * @return {Object} List of post data fields with their value and label.\n *\n * @example\n * ```js\n * {\n * field_1_key: {\n * label: 'Field 1 Label',\n * value: 'Field 1 Value',\n * },\n * field_2_key: {\n * label: 'Field 2 Label',\n * value: 'Field 2 Value',\n * },\n * ...\n * }\n * ```\n */\nfunction getPostDataFields( select, context, clientId ) {\n\tconst { getEditedEntityRecord } = select( coreDataStore );\n\tconst { getBlockAttributes, getBlockName } = select( blockEditorStore );\n\n\tlet entityDataValues, dataFields;\n\n\t/*\n\t * BACKWARDS COMPATIBILITY: Hardcoded exception for navigation blocks.\n\t * Required for WordPress 6.9+ navigation blocks. DO NOT REMOVE.\n\t */\n\tconst blockName = getBlockName?.( clientId );\n\tconst isNavigationBlock = NAVIGATION_BLOCK_TYPES.includes( blockName );\n\n\tlet postId, postType;\n\n\tif ( isNavigationBlock ) {\n\t\t// Navigation blocks: read from block attributes\n\t\tconst blockAttributes = getBlockAttributes?.( clientId );\n\t\tpostId = blockAttributes?.id;\n\t\tpostType = blockAttributes?.type;\n\t} else {\n\t\t// All other blocks: use context\n\t\tpostId = context?.postId;\n\t\tpostType = context?.postType;\n\t}\n\n\t// Try to get the current entity data values using resolved identifiers.\n\tif ( postType && postId ) {\n\t\tentityDataValues = getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\tpostType,\n\t\t\tpostId\n\t\t);\n\t\tdataFields = {\n\t\t\tdate: {\n\t\t\t\tlabel: __( 'Post Date' ),\n\t\t\t\tvalue: entityDataValues?.date,\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tmodified: {\n\t\t\t\tlabel: __( 'Post Modified Date' ),\n\t\t\t\tvalue: entityDataValues?.modified,\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tlink: {\n\t\t\t\tlabel: __( 'Post Link' ),\n\t\t\t\tvalue: entityDataValues?.link,\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t};\n\t}\n\n\tif ( ! Object.keys( dataFields || {} ).length ) {\n\t\treturn null;\n\t}\n\n\treturn dataFields;\n}\n\n/**\n * @type {WPBlockBindingsSource}\n */\nexport default {\n\tname: 'core/post-data',\n\tgetValues( { select, context, bindings, clientId } ) {\n\t\tconst dataFields = getPostDataFields( select, context, clientId );\n\n\t\tconst newValues = {};\n\t\tfor ( const [ attributeName, source ] of Object.entries( bindings ) ) {\n\t\t\t// Use the value, the field label, or the field key.\n\t\t\tconst fieldKey = globalThis.IS_GUTENBERG_PLUGIN\n\t\t\t\t? source.args.field || source.args.key\n\t\t\t\t: source.args.field;\n\t\t\tconst { value: fieldValue, label: fieldLabel } =\n\t\t\t\tdataFields?.[ fieldKey ] || {};\n\t\t\tnewValues[ attributeName ] = fieldValue ?? fieldLabel ?? fieldKey;\n\t\t}\n\t\treturn newValues;\n\t},\n\tsetValues( { dispatch, context, bindings, clientId, select } ) {\n\t\tconst { getBlockName } = select( blockEditorStore );\n\n\t\tconst blockName = getBlockName?.( clientId );\n\n\t\t// Navigaton block types are read-only.\n\t\t// See https://github.com/WordPress/gutenberg/pull/72165.\n\t\tif ( NAVIGATION_BLOCK_TYPES.includes( blockName ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tconst newData = {};\n\t\tObject.values( bindings ).forEach( ( { args, newValue } ) => {\n\t\t\tnewData[ args.field ] = newValue;\n\t\t} );\n\n\t\tdispatch( coreDataStore ).editEntityRecord(\n\t\t\t'postType',\n\t\t\tcontext?.postType,\n\t\t\tcontext?.postId,\n\t\t\tnewData\n\t\t);\n\t},\n\tcanUserEditValue( { select, context, args } ) {\n\t\tconst { getBlockName, getSelectedBlockClientId } =\n\t\t\tselect( blockEditorStore );\n\t\tconst clientId = getSelectedBlockClientId();\n\t\tconst blockName = getBlockName?.( clientId );\n\n\t\t// Navigaton block types are read-only.\n\t\t// See https://github.com/WordPress/gutenberg/pull/72165.\n\t\tif ( NAVIGATION_BLOCK_TYPES.includes( blockName ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Lock editing in query loop.\n\t\tif ( context?.query || context?.queryId ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Lock editing when `postType` is not defined.\n\t\tif ( ! context?.postType ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst fieldValue = getPostDataFields( select, context, undefined )?.[\n\t\t\targs.field\n\t\t]?.value;\n\t\t// Empty string or `false` could be a valid value, so we need to check if the field value is undefined.\n\t\tif ( fieldValue === undefined ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Check that the user has the capability to edit post data.\n\t\tconst canUserEdit = select( coreDataStore ).canUser( 'update', {\n\t\t\tkind: 'postType',\n\t\t\tname: context?.postType,\n\t\t\tid: context?.postId,\n\t\t} );\n\t\tif ( ! canUserEdit ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t},\n\tgetFieldsList( { select, context } ) {\n\t\tconst clientId = select( blockEditorStore ).getSelectedBlockClientId();\n\t\t// Deprecated, will be removed after 6.9.\n\t\treturn getPostDataFields( select, context, clientId );\n\t},\n\teditorUI( { select, context } ) {\n\t\tconst selectedBlock = select( blockEditorStore ).getSelectedBlock();\n\t\tif ( selectedBlock?.name !== 'core/post-date' ) {\n\t\t\treturn {};\n\t\t}\n\t\t// Exit early for navigation blocks (read-only)\n\t\tif ( NAVIGATION_BLOCK_TYPES.includes( selectedBlock?.name ) ) {\n\t\t\treturn {};\n\t\t}\n\t\tconst postDataFields = Object.entries(\n\t\t\tgetPostDataFields( select, context ) || {}\n\t\t).map( ( [ key, field ] ) => ( {\n\t\t\tlabel: field.label,\n\t\t\targs: {\n\t\t\t\tfield: key,\n\t\t\t},\n\t\t\ttype: field.type,\n\t\t} ) );\n\t\t/*\n\t\t * We need to define the data as [{ label: string, value: any, type: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#type-validation }]\n\t\t */\n\t\treturn {\n\t\t\tmode: 'dropdown',\n\t\t\tdata: postDataFields,\n\t\t};\n\t},\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,uBAAuC;AACvC,0BAA0C;AAG1C,MAAM,yBAAyB;AAAA,EAC9B;AAAA,EACA;AACD;AA4BA,SAAS,kBAAmB,QAAQ,SAAS,UAAW;AACvD,QAAM,EAAE,sBAAsB,IAAI,OAAQ,iBAAAA,KAAc;AACxD,QAAM,EAAE,oBAAoB,aAAa,IAAI,OAAQ,oBAAAC,KAAiB;AAEtE,MAAI,kBAAkB;AAMtB,QAAM,YAAY,eAAgB,QAAS;AAC3C,QAAM,oBAAoB,uBAAuB,SAAU,SAAU;AAErE,MAAI,QAAQ;AAEZ,MAAK,mBAAoB;AAExB,UAAM,kBAAkB,qBAAsB,QAAS;AACvD,aAAS,iBAAiB;AAC1B,eAAW,iBAAiB;AAAA,EAC7B,OAAO;AAEN,aAAS,SAAS;AAClB,eAAW,SAAS;AAAA,EACrB;AAGA,MAAK,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AAO,CAAC;AAAA,IACT;AACA,UAAM,iBAAiB,OAAO;AAAA,MAC7B,kBAAmB,QAAQ,OAAQ,KAAK,CAAC;AAAA,IAC1C,EAAE,IAAK,CAAE,CAAE,KAAK,KAAM,OAAS;AAAA,MAC9B,OAAO,MAAM;AAAA,MACb,MAAM;AAAA,QACL,OAAO;AAAA,MACR;AAAA,MACA,MAAM,MAAM;AAAA,IACb,EAAI;AAIJ,WAAO;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,IACP;AAAA,EACD;AACD;",
|
|
6
|
+
"names": ["coreDataStore", "blockEditorStore"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var term_data_exports = {};
|
|
20
|
+
__export(term_data_exports, {
|
|
21
|
+
default: () => term_data_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(term_data_exports);
|
|
24
|
+
var import_i18n = require("@wordpress/i18n");
|
|
25
|
+
var import_core_data = require("@wordpress/core-data");
|
|
26
|
+
var import_block_editor = require("@wordpress/block-editor");
|
|
27
|
+
const NAVIGATION_BLOCK_TYPES = [
|
|
28
|
+
"core/navigation-link",
|
|
29
|
+
"core/navigation-submenu"
|
|
30
|
+
];
|
|
31
|
+
function createDataFields(termDataValues, idValue) {
|
|
32
|
+
return {
|
|
33
|
+
id: {
|
|
34
|
+
label: (0, import_i18n.__)("Term ID"),
|
|
35
|
+
value: idValue,
|
|
36
|
+
type: "string"
|
|
37
|
+
},
|
|
38
|
+
name: {
|
|
39
|
+
label: (0, import_i18n.__)("Name"),
|
|
40
|
+
value: termDataValues?.name,
|
|
41
|
+
type: "string"
|
|
42
|
+
},
|
|
43
|
+
slug: {
|
|
44
|
+
label: (0, import_i18n.__)("Slug"),
|
|
45
|
+
value: termDataValues?.slug,
|
|
46
|
+
type: "string"
|
|
47
|
+
},
|
|
48
|
+
link: {
|
|
49
|
+
label: (0, import_i18n.__)("Link"),
|
|
50
|
+
value: termDataValues?.link,
|
|
51
|
+
type: "string"
|
|
52
|
+
},
|
|
53
|
+
description: {
|
|
54
|
+
label: (0, import_i18n.__)("Description"),
|
|
55
|
+
value: termDataValues?.description,
|
|
56
|
+
type: "string"
|
|
57
|
+
},
|
|
58
|
+
parent: {
|
|
59
|
+
label: (0, import_i18n.__)("Parent ID"),
|
|
60
|
+
value: termDataValues?.parent,
|
|
61
|
+
type: "string"
|
|
62
|
+
},
|
|
63
|
+
count: {
|
|
64
|
+
label: (0, import_i18n.__)("Count"),
|
|
65
|
+
value: `(${termDataValues?.count ?? 0})`,
|
|
66
|
+
type: "string"
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function getTermDataFields(select, context, clientId) {
|
|
71
|
+
const { getEntityRecord } = select(import_core_data.store);
|
|
72
|
+
const { getBlockAttributes, getBlockName } = select(import_block_editor.store);
|
|
73
|
+
let termDataValues, dataFields;
|
|
74
|
+
const blockName = getBlockName?.(clientId);
|
|
75
|
+
const isNavigationBlock = NAVIGATION_BLOCK_TYPES.includes(blockName);
|
|
76
|
+
let termId, taxonomy;
|
|
77
|
+
if (isNavigationBlock) {
|
|
78
|
+
const blockAttributes = getBlockAttributes?.(clientId);
|
|
79
|
+
termId = blockAttributes?.id;
|
|
80
|
+
const typeFromAttributes = blockAttributes?.type;
|
|
81
|
+
taxonomy = typeFromAttributes === "tag" ? "post_tag" : typeFromAttributes;
|
|
82
|
+
} else {
|
|
83
|
+
termId = context?.termId;
|
|
84
|
+
taxonomy = context?.taxonomy;
|
|
85
|
+
}
|
|
86
|
+
if (taxonomy && termId) {
|
|
87
|
+
termDataValues = getEntityRecord("taxonomy", taxonomy, termId);
|
|
88
|
+
if (!termDataValues && context?.termData) {
|
|
89
|
+
termDataValues = context.termData;
|
|
90
|
+
}
|
|
91
|
+
if (termDataValues) {
|
|
92
|
+
dataFields = createDataFields(termDataValues, termId);
|
|
93
|
+
}
|
|
94
|
+
} else if (context?.termData) {
|
|
95
|
+
termDataValues = context.termData;
|
|
96
|
+
dataFields = createDataFields(
|
|
97
|
+
termDataValues,
|
|
98
|
+
termDataValues?.term_id
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
if (!dataFields || !Object.keys(dataFields).length) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
return dataFields;
|
|
105
|
+
}
|
|
106
|
+
var term_data_default = {
|
|
107
|
+
name: "core/term-data",
|
|
108
|
+
usesContext: ["taxonomy", "termId", "termData"],
|
|
109
|
+
getValues({ select, context, bindings, clientId }) {
|
|
110
|
+
const dataFields = getTermDataFields(select, context, clientId);
|
|
111
|
+
const newValues = {};
|
|
112
|
+
for (const [attributeName, source] of Object.entries(bindings)) {
|
|
113
|
+
const fieldKey = source.args.field;
|
|
114
|
+
const { value: fieldValue, label: fieldLabel } = dataFields?.[fieldKey] || {};
|
|
115
|
+
newValues[attributeName] = fieldValue ?? fieldLabel ?? fieldKey;
|
|
116
|
+
}
|
|
117
|
+
return newValues;
|
|
118
|
+
},
|
|
119
|
+
// eslint-disable-next-line no-unused-vars
|
|
120
|
+
setValues({ dispatch, context, bindings }) {
|
|
121
|
+
return false;
|
|
122
|
+
},
|
|
123
|
+
canUserEditValue({ select, context, args }) {
|
|
124
|
+
const { getBlockName, getSelectedBlockClientId } = select(import_block_editor.store);
|
|
125
|
+
const clientId = getSelectedBlockClientId();
|
|
126
|
+
const blockName = getBlockName?.(clientId);
|
|
127
|
+
if (NAVIGATION_BLOCK_TYPES.includes(blockName)) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
if (context?.termQuery) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
if (!context?.taxonomy || !context?.termId) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
const fieldValue = getTermDataFields(select, context, void 0)?.[args.field]?.value;
|
|
137
|
+
if (fieldValue === void 0) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
return false;
|
|
141
|
+
},
|
|
142
|
+
getFieldsList({ select, context }) {
|
|
143
|
+
return getTermDataFields(select, context);
|
|
144
|
+
},
|
|
145
|
+
editorUI({ select, context }) {
|
|
146
|
+
const selectedBlock = select(import_block_editor.store).getSelectedBlock();
|
|
147
|
+
if (NAVIGATION_BLOCK_TYPES.includes(selectedBlock?.name)) {
|
|
148
|
+
return {};
|
|
149
|
+
}
|
|
150
|
+
const termDataFields = Object.entries(
|
|
151
|
+
getTermDataFields(select, context) || {}
|
|
152
|
+
).map(([key, field]) => ({
|
|
153
|
+
label: field.label,
|
|
154
|
+
type: field.type,
|
|
155
|
+
args: {
|
|
156
|
+
field: key
|
|
157
|
+
}
|
|
158
|
+
}));
|
|
159
|
+
return {
|
|
160
|
+
mode: "dropdown",
|
|
161
|
+
data: termDataFields
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=term-data.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/bindings/term-data.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n// Navigation block types that use special handling for backwards compatibility\nconst NAVIGATION_BLOCK_TYPES = [\n\t'core/navigation-link',\n\t'core/navigation-submenu',\n];\n\n/**\n * Creates the data fields object with the given term data values and ID value.\n *\n * @param {Object} termDataValues The term data values.\n * @param {string|number} idValue The ID value to use.\n * @return {Object} The data fields object.\n */\nfunction createDataFields( termDataValues, idValue ) {\n\treturn {\n\t\tid: {\n\t\t\tlabel: __( 'Term ID' ),\n\t\t\tvalue: idValue,\n\t\t\ttype: 'string',\n\t\t},\n\t\tname: {\n\t\t\tlabel: __( 'Name' ),\n\t\t\tvalue: termDataValues?.name,\n\t\t\ttype: 'string',\n\t\t},\n\t\tslug: {\n\t\t\tlabel: __( 'Slug' ),\n\t\t\tvalue: termDataValues?.slug,\n\t\t\ttype: 'string',\n\t\t},\n\t\tlink: {\n\t\t\tlabel: __( 'Link' ),\n\t\t\tvalue: termDataValues?.link,\n\t\t\ttype: 'string',\n\t\t},\n\t\tdescription: {\n\t\t\tlabel: __( 'Description' ),\n\t\t\tvalue: termDataValues?.description,\n\t\t\ttype: 'string',\n\t\t},\n\t\tparent: {\n\t\t\tlabel: __( 'Parent ID' ),\n\t\t\tvalue: termDataValues?.parent,\n\t\t\ttype: 'string',\n\t\t},\n\t\tcount: {\n\t\t\tlabel: __( 'Count' ),\n\t\t\tvalue: `(${ termDataValues?.count ?? 0 })`,\n\t\t\ttype: 'string',\n\t\t},\n\t};\n}\n\n/**\n * Gets a list of term data fields with their values and labels\n * to be consumed in the needed callbacks.\n * If the value is not available based on context, like in templates,\n * it falls back to the default value, label, or key.\n *\n * @param {Object} select The select function from the data store.\n * @param {Object} context The context provided.\n * @param {string} clientId The block client ID used to read attributes.\n * @return {Object} List of term data fields with their value and label.\n *\n * @example\n * ```js\n * {\n * name: {\n * label: 'Term Name',\n * value: 'Category Name',\n * },\n * count: {\n * label: 'Term Count',\n * value: 5,\n * },\n * ...\n * }\n * ```\n */\nfunction getTermDataFields( select, context, clientId ) {\n\tconst { getEntityRecord } = select( coreDataStore );\n\tconst { getBlockAttributes, getBlockName } = select( blockEditorStore );\n\n\tlet termDataValues, dataFields;\n\n\t/*\n\t * BACKWARDS COMPATIBILITY: Hardcoded exception for navigation blocks.\n\t * Required for WordPress 6.9+ navigation blocks. DO NOT REMOVE.\n\t */\n\tconst blockName = getBlockName?.( clientId );\n\tconst isNavigationBlock = NAVIGATION_BLOCK_TYPES.includes( blockName );\n\n\tlet termId, taxonomy;\n\n\tif ( isNavigationBlock ) {\n\t\t// Navigation blocks: read from block attributes\n\t\tconst blockAttributes = getBlockAttributes?.( clientId );\n\t\ttermId = blockAttributes?.id;\n\t\tconst typeFromAttributes = blockAttributes?.type;\n\t\ttaxonomy =\n\t\t\ttypeFromAttributes === 'tag' ? 'post_tag' : typeFromAttributes;\n\t} else {\n\t\t// All other blocks: use context\n\t\ttermId = context?.termId;\n\t\ttaxonomy = context?.taxonomy;\n\t}\n\n\tif ( taxonomy && termId ) {\n\t\ttermDataValues = getEntityRecord( 'taxonomy', taxonomy, termId );\n\n\t\tif ( ! termDataValues && context?.termData ) {\n\t\t\ttermDataValues = context.termData;\n\t\t}\n\n\t\tif ( termDataValues ) {\n\t\t\tdataFields = createDataFields( termDataValues, termId );\n\t\t}\n\t} else if ( context?.termData ) {\n\t\ttermDataValues = context.termData;\n\t\tdataFields = createDataFields(\n\t\t\ttermDataValues,\n\t\t\ttermDataValues?.term_id\n\t\t);\n\t}\n\n\tif ( ! dataFields || ! Object.keys( dataFields ).length ) {\n\t\treturn null;\n\t}\n\n\treturn dataFields;\n}\n\n/**\n * @type {WPBlockBindingsSource}\n */\nexport default {\n\tname: 'core/term-data',\n\tusesContext: [ 'taxonomy', 'termId', 'termData' ],\n\tgetValues( { select, context, bindings, clientId } ) {\n\t\tconst dataFields = getTermDataFields( select, context, clientId );\n\n\t\tconst newValues = {};\n\t\tfor ( const [ attributeName, source ] of Object.entries( bindings ) ) {\n\t\t\t// Use the value, the field label, or the field key.\n\t\t\tconst fieldKey = source.args.field;\n\t\t\tconst { value: fieldValue, label: fieldLabel } =\n\t\t\t\tdataFields?.[ fieldKey ] || {};\n\t\t\tnewValues[ attributeName ] = fieldValue ?? fieldLabel ?? fieldKey;\n\t\t}\n\t\treturn newValues;\n\t},\n\t// eslint-disable-next-line no-unused-vars\n\tsetValues( { dispatch, context, bindings } ) {\n\t\t// Terms are typically not editable through block bindings in most contexts.\n\t\treturn false;\n\t},\n\tcanUserEditValue( { select, context, args } ) {\n\t\tconst { getBlockName, getSelectedBlockClientId } =\n\t\t\tselect( blockEditorStore );\n\n\t\tconst clientId = getSelectedBlockClientId();\n\t\tconst blockName = getBlockName?.( clientId );\n\n\t\t// Navigaton block types are read-only.\n\t\t// See https://github.com/WordPress/gutenberg/pull/72165.\n\t\tif ( NAVIGATION_BLOCK_TYPES.includes( blockName ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Terms are typically read-only when displayed.\n\t\tif ( context?.termQuery ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Lock editing when `taxonomy` or `termId` is not defined.\n\t\tif ( ! context?.taxonomy || ! context?.termId ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst fieldValue = getTermDataFields( select, context, undefined )?.[\n\t\t\targs.field\n\t\t]?.value;\n\t\t// Empty string or `false` could be a valid value, so we need to check if the field value is undefined.\n\t\tif ( fieldValue === undefined ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn false;\n\t},\n\tgetFieldsList( { select, context } ) {\n\t\t// Deprecated, will be removed after 6.9.\n\t\treturn getTermDataFields( select, context );\n\t},\n\teditorUI( { select, context } ) {\n\t\tconst selectedBlock = select( blockEditorStore ).getSelectedBlock();\n\t\t// Exit early for navigation blocks (read-only)\n\t\tif ( NAVIGATION_BLOCK_TYPES.includes( selectedBlock?.name ) ) {\n\t\t\treturn {};\n\t\t}\n\t\tconst termDataFields = Object.entries(\n\t\t\tgetTermDataFields( select, context ) || {}\n\t\t).map( ( [ key, field ] ) => ( {\n\t\t\tlabel: field.label,\n\t\t\ttype: field.type,\n\t\t\targs: {\n\t\t\t\tfield: key,\n\t\t\t},\n\t\t} ) );\n\t\t/*\n\t\t * We need to define the data as [{ label: string, value: any, type: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-attributes/#type-validation }]\n\t\t */\n\t\treturn {\n\t\t\tmode: 'dropdown',\n\t\t\tdata: termDataFields,\n\t\t};\n\t},\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,uBAAuC;AACvC,0BAA0C;AAG1C,MAAM,yBAAyB;AAAA,EAC9B;AAAA,EACA;AACD;AASA,SAAS,iBAAkB,gBAAgB,SAAU;AACpD,SAAO;AAAA,IACN,IAAI;AAAA,MACH,WAAO,gBAAI,SAAU;AAAA,MACrB,OAAO;AAAA,MACP,MAAM;AAAA,IACP;AAAA,IACA,MAAM;AAAA,MACL,WAAO,gBAAI,MAAO;AAAA,MAClB,OAAO,gBAAgB;AAAA,MACvB,MAAM;AAAA,IACP;AAAA,IACA,MAAM;AAAA,MACL,WAAO,gBAAI,MAAO;AAAA,MAClB,OAAO,gBAAgB;AAAA,MACvB,MAAM;AAAA,IACP;AAAA,IACA,MAAM;AAAA,MACL,WAAO,gBAAI,MAAO;AAAA,MAClB,OAAO,gBAAgB;AAAA,MACvB,MAAM;AAAA,IACP;AAAA,IACA,aAAa;AAAA,MACZ,WAAO,gBAAI,aAAc;AAAA,MACzB,OAAO,gBAAgB;AAAA,MACvB,MAAM;AAAA,IACP;AAAA,IACA,QAAQ;AAAA,MACP,WAAO,gBAAI,WAAY;AAAA,MACvB,OAAO,gBA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CAAE,CAAE,KAAK,KAAM,OAAS;AAAA,MAC9B,OAAO,MAAM;AAAA,MACb,MAAM,MAAM;AAAA,MACZ,MAAM;AAAA,QACL,OAAO;AAAA,MACR;AAAA,IACD,EAAI;AAIJ,WAAO;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,IACP;AAAA,EACD;AACD;",
|
|
6
|
+
"names": ["coreDataStore", "blockEditorStore"]
|
|
7
|
+
}
|
|
@@ -36,7 +36,6 @@ var import_i18n = require("@wordpress/i18n");
|
|
|
36
36
|
var import_data = require("@wordpress/data");
|
|
37
37
|
var import_components = require("@wordpress/components");
|
|
38
38
|
var import_block_editor = require("@wordpress/block-editor");
|
|
39
|
-
var import_blocks = require("@wordpress/blocks");
|
|
40
39
|
var import_lock_unlock = require("../../lock-unlock");
|
|
41
40
|
var import_comment_author_info = __toESM(require("./comment-author-info"));
|
|
42
41
|
var import_comment_form = __toESM(require("./comment-form"));
|
|
@@ -48,20 +47,16 @@ function AddComment({
|
|
|
48
47
|
setShowCommentBoard,
|
|
49
48
|
commentSidebarRef
|
|
50
49
|
}) {
|
|
51
|
-
const { clientId, blockCommentId
|
|
52
|
-
(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
[]
|
|
62
|
-
);
|
|
50
|
+
const { clientId, blockCommentId } = (0, import_data.useSelect)((select) => {
|
|
51
|
+
const { getSelectedBlock } = select(import_block_editor.store);
|
|
52
|
+
const selectedBlock = getSelectedBlock();
|
|
53
|
+
return {
|
|
54
|
+
clientId: selectedBlock?.clientId,
|
|
55
|
+
blockCommentId: selectedBlock?.attributes?.metadata?.noteId
|
|
56
|
+
};
|
|
57
|
+
}, []);
|
|
63
58
|
const blockElement = useBlockElement(clientId);
|
|
64
|
-
if (!showCommentBoard || !clientId || void 0 !== blockCommentId
|
|
59
|
+
if (!showCommentBoard || !clientId || void 0 !== blockCommentId) {
|
|
65
60
|
return null;
|
|
66
61
|
}
|
|
67
62
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
@@ -79,12 +74,13 @@ function AddComment({
|
|
|
79
74
|
onSubmit: async (inputComment) => {
|
|
80
75
|
const { id } = await onSubmit({ content: inputComment });
|
|
81
76
|
(0, import_utils.focusCommentThread)(id, commentSidebarRef.current);
|
|
77
|
+
setShowCommentBoard(false);
|
|
82
78
|
},
|
|
83
79
|
onCancel: () => {
|
|
84
80
|
setShowCommentBoard(false);
|
|
85
81
|
blockElement?.focus();
|
|
86
82
|
},
|
|
87
|
-
submitButtonText: (0, import_i18n.
|
|
83
|
+
submitButtonText: (0, import_i18n.__)("Add note"),
|
|
88
84
|
labelText: (0, import_i18n.__)("New Note")
|
|
89
85
|
}
|
|
90
86
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/collab-sidebar/add-comment.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport {\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport {\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport CommentAuthorInfo from './comment-author-info';\nimport CommentForm from './comment-form';\nimport { focusCommentThread } from './utils';\n\nconst { useBlockElement } = unlock( blockEditorPrivateApis );\n\nexport function AddComment( {\n\tonSubmit,\n\tshowCommentBoard,\n\tsetShowCommentBoard,\n\tcommentSidebarRef,\n} ) {\n\tconst { clientId, blockCommentId } = useSelect( ( select ) => {\n\t\tconst { getSelectedBlock } = select( blockEditorStore );\n\t\tconst selectedBlock = getSelectedBlock();\n\t\treturn {\n\t\t\tclientId: selectedBlock?.clientId,\n\t\t\tblockCommentId: selectedBlock?.attributes?.metadata?.noteId,\n\t\t};\n\t}, [] );\n\tconst blockElement = useBlockElement( clientId );\n\n\tif ( ! showCommentBoard || ! clientId || undefined !== blockCommentId ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<VStack\n\t\t\tclassName=\"editor-collab-sidebar-panel__thread is-selected\"\n\t\t\tspacing=\"3\"\n\t\t\ttabIndex={ 0 }\n\t\t\trole=\"listitem\"\n\t\t>\n\t\t\t<HStack alignment=\"left\" spacing=\"3\">\n\t\t\t\t<CommentAuthorInfo />\n\t\t\t</HStack>\n\t\t\t<CommentForm\n\t\t\t\tonSubmit={ async ( inputComment ) => {\n\t\t\t\t\tconst { id } = await onSubmit( { content: inputComment } );\n\t\t\t\t\tfocusCommentThread( id, commentSidebarRef.current );\n\t\t\t\t\tsetShowCommentBoard( false );\n\t\t\t\t} }\n\t\t\t\tonCancel={ () => {\n\t\t\t\t\tsetShowCommentBoard( false );\n\t\t\t\t\tblockElement?.focus();\n\t\t\t\t} }\n\t\t\t\tsubmitButtonText={ __( 'Add note' ) }\n\t\t\t\tlabelText={ __( 'New Note' ) }\n\t\t\t/>\n\t\t</VStack>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA6CE;AA1CF,kBAAmB;AACnB,kBAA0B;AAC1B,wBAGO;AACP,0BAGO;AAKP,yBAAuB;AACvB,iCAA8B;AAC9B,0BAAwB;AACxB,mBAAmC;AAEnC,MAAM,EAAE,gBAAgB,QAAI,2BAAQ,oBAAAA,WAAuB;AAEpD,SAAS,WAAY;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,EAAE,UAAU,eAAe,QAAI,uBAAW,CAAE,WAAY;AAC7D,UAAM,EAAE,iBAAiB,IAAI,OAAQ,oBAAAC,KAAiB;AACtD,UAAM,gBAAgB,iBAAiB;AACvC,WAAO;AAAA,MACN,UAAU,eAAe;AAAA,MACzB,gBAAgB,eAAe,YAAY,UAAU;AAAA,IACtD;AAAA,EACD,GAAG,CAAC,CAAE;AACN,QAAM,eAAe,gBAAiB,QAAS;AAE/C,MAAK,CAAE,oBAAoB,CAAE,YAAY,WAAc,gBAAiB;AACvE,WAAO;AAAA,EACR;AAEA,SACC;AAAA,IAAC,kBAAAC;AAAA,IAAA;AAAA,MACA,WAAU;AAAA,MACV,SAAQ;AAAA,MACR,UAAW;AAAA,MACX,MAAK;AAAA,MAEL;AAAA,oDAAC,kBAAAC,sBAAA,EAAO,WAAU,QAAO,SAAQ,KAChC,sDAAC,2BAAAC,SAAA,EAAkB,GACpB;AAAA,QACA;AAAA,UAAC,oBAAAC;AAAA,UAAA;AAAA,YACA,UAAW,OAAQ,iBAAkB;AACpC,oBAAM,EAAE,GAAG,IAAI,MAAM,SAAU,EAAE,SAAS,aAAa,CAAE;AACzD,mDAAoB,IAAI,kBAAkB,OAAQ;AAClD,kCAAqB,KAAM;AAAA,YAC5B;AAAA,YACA,UAAW,MAAM;AAChB,kCAAqB,KAAM;AAC3B,4BAAc,MAAM;AAAA,YACrB;AAAA,YACA,sBAAmB,gBAAI,UAAW;AAAA,YAClC,eAAY,gBAAI,UAAW;AAAA;AAAA,QAC5B;AAAA;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": ["blockEditorPrivateApis", "blockEditorStore", "VStack", "HStack", "CommentAuthorInfo", "CommentForm"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/collab-sidebar/comment-menu-item.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { comment as commentIcon } from '@wordpress/icons';\n\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\nconst { CommentIconSlotFill } = unlock( blockEditorPrivateApis );\n\nconst AddCommentMenuItem = ( { onClick } ) => {\n\treturn (\n\t\t<CommentIconSlotFill.Fill>\n\t\t\t{ ( { onClose } ) => (\n\t\t\t\t<MenuItem\n\t\t\t\t\ticon={ commentIcon }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tonClick();\n\t\t\t\t\t\tonClose();\n\t\t\t\t\t} }\n\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t>\n\t\t\t\t\t{ __( '
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBI;AAjBJ,wBAAyB;AACzB,kBAAmB;AACnB,mBAAuC;AAEvC,0BAAsD;AAKtD,yBAAuB;AAEvB,MAAM,EAAE,oBAAoB,QAAI,2BAAQ,oBAAAA,WAAuB;AAE/D,MAAM,qBAAqB,CAAE,EAAE,QAAQ,MAAO;AAC7C,SACC,4CAAC,oBAAoB,MAApB,EACE,WAAE,EAAE,QAAQ,MACb;AAAA,IAAC;AAAA;AAAA,MACA,MAAO,aAAAC;AAAA,MACP,SAAU,MAAM;AACf,gBAAQ;AACR,gBAAQ;AAAA,MACT;AAAA,MACA,iBAAc;AAAA,MAEZ,8BAAI,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { comment as commentIcon } from '@wordpress/icons';\n\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\nconst { CommentIconSlotFill } = unlock( blockEditorPrivateApis );\n\nconst AddCommentMenuItem = ( { onClick } ) => {\n\treturn (\n\t\t<CommentIconSlotFill.Fill>\n\t\t\t{ ( { onClose } ) => (\n\t\t\t\t<MenuItem\n\t\t\t\t\ticon={ commentIcon }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tonClick();\n\t\t\t\t\t\tonClose();\n\t\t\t\t\t} }\n\t\t\t\t\taria-haspopup=\"dialog\"\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Add note' ) }\n\t\t\t\t</MenuItem>\n\t\t\t) }\n\t\t</CommentIconSlotFill.Fill>\n\t);\n};\n\nexport default AddCommentMenuItem;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBI;AAjBJ,wBAAyB;AACzB,kBAAmB;AACnB,mBAAuC;AAEvC,0BAAsD;AAKtD,yBAAuB;AAEvB,MAAM,EAAE,oBAAoB,QAAI,2BAAQ,oBAAAA,WAAuB;AAE/D,MAAM,qBAAqB,CAAE,EAAE,QAAQ,MAAO;AAC7C,SACC,4CAAC,oBAAoB,MAApB,EACE,WAAE,EAAE,QAAQ,MACb;AAAA,IAAC;AAAA;AAAA,MACA,MAAO,aAAAC;AAAA,MACP,SAAU,MAAM;AACf,gBAAQ;AACR,gBAAQ;AAAA,MACT;AAAA,MACA,iBAAc;AAAA,MAEZ,8BAAI,UAAW;AAAA;AAAA,EAClB,GAEF;AAEF;AAEA,IAAO,4BAAQ;",
|
|
6
6
|
"names": ["blockEditorPrivateApis", "commentIcon"]
|
|
7
7
|
}
|