@wordpress/editor 14.32.1-next.ff1cebbba.0 → 14.33.1
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 +90 -68
- 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 +90 -68
- 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 +78 -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 +112 -64
- 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
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { __ } from '@wordpress/i18n';
|
|
5
5
|
import { store as coreDataStore } from '@wordpress/core-data';
|
|
6
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
7
|
+
|
|
8
|
+
// Navigation block types that use special handling for backwards compatibility
|
|
9
|
+
const NAVIGATION_BLOCK_TYPES = [
|
|
10
|
+
'core/navigation-link',
|
|
11
|
+
'core/navigation-submenu',
|
|
12
|
+
];
|
|
6
13
|
|
|
7
14
|
/**
|
|
8
15
|
* Gets a list of post data fields with their values and labels
|
|
@@ -10,8 +17,9 @@ import { store as coreDataStore } from '@wordpress/core-data';
|
|
|
10
17
|
* If the value is not available based on context, like in templates,
|
|
11
18
|
* it falls back to the default value, label, or key.
|
|
12
19
|
*
|
|
13
|
-
* @param {Object} select
|
|
14
|
-
* @param {Object} context
|
|
20
|
+
* @param {Object} select The select function from the data store.
|
|
21
|
+
* @param {Object} context The context provided.
|
|
22
|
+
* @param {string} clientId The block client ID used to read attributes.
|
|
15
23
|
* @return {Object} List of post data fields with their value and label.
|
|
16
24
|
*
|
|
17
25
|
* @example
|
|
@@ -29,16 +37,38 @@ import { store as coreDataStore } from '@wordpress/core-data';
|
|
|
29
37
|
* }
|
|
30
38
|
* ```
|
|
31
39
|
*/
|
|
32
|
-
function getPostDataFields( select, context ) {
|
|
40
|
+
function getPostDataFields( select, context, clientId ) {
|
|
33
41
|
const { getEditedEntityRecord } = select( coreDataStore );
|
|
42
|
+
const { getBlockAttributes, getBlockName } = select( blockEditorStore );
|
|
34
43
|
|
|
35
44
|
let entityDataValues, dataFields;
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
* BACKWARDS COMPATIBILITY: Hardcoded exception for navigation blocks.
|
|
48
|
+
* Required for WordPress 6.9+ navigation blocks. DO NOT REMOVE.
|
|
49
|
+
*/
|
|
50
|
+
const blockName = getBlockName?.( clientId );
|
|
51
|
+
const isNavigationBlock = NAVIGATION_BLOCK_TYPES.includes( blockName );
|
|
52
|
+
|
|
53
|
+
let postId, postType;
|
|
54
|
+
|
|
55
|
+
if ( isNavigationBlock ) {
|
|
56
|
+
// Navigation blocks: read from block attributes
|
|
57
|
+
const blockAttributes = getBlockAttributes?.( clientId );
|
|
58
|
+
postId = blockAttributes?.id;
|
|
59
|
+
postType = blockAttributes?.type;
|
|
60
|
+
} else {
|
|
61
|
+
// All other blocks: use context
|
|
62
|
+
postId = context?.postId;
|
|
63
|
+
postType = context?.postType;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Try to get the current entity data values using resolved identifiers.
|
|
67
|
+
if ( postType && postId ) {
|
|
38
68
|
entityDataValues = getEditedEntityRecord(
|
|
39
69
|
'postType',
|
|
40
|
-
|
|
41
|
-
|
|
70
|
+
postType,
|
|
71
|
+
postId
|
|
42
72
|
);
|
|
43
73
|
dataFields = {
|
|
44
74
|
date: {
|
|
@@ -51,6 +81,11 @@ function getPostDataFields( select, context ) {
|
|
|
51
81
|
value: entityDataValues?.modified,
|
|
52
82
|
type: 'string',
|
|
53
83
|
},
|
|
84
|
+
link: {
|
|
85
|
+
label: __( 'Post Link' ),
|
|
86
|
+
value: entityDataValues?.link,
|
|
87
|
+
type: 'string',
|
|
88
|
+
},
|
|
54
89
|
};
|
|
55
90
|
}
|
|
56
91
|
|
|
@@ -66,23 +101,32 @@ function getPostDataFields( select, context ) {
|
|
|
66
101
|
*/
|
|
67
102
|
export default {
|
|
68
103
|
name: 'core/post-data',
|
|
69
|
-
getValues( { select, context, bindings } ) {
|
|
70
|
-
const dataFields = getPostDataFields( select, context );
|
|
104
|
+
getValues( { select, context, bindings, clientId } ) {
|
|
105
|
+
const dataFields = getPostDataFields( select, context, clientId );
|
|
71
106
|
|
|
72
107
|
const newValues = {};
|
|
73
108
|
for ( const [ attributeName, source ] of Object.entries( bindings ) ) {
|
|
74
109
|
// Use the value, the field label, or the field key.
|
|
75
|
-
const fieldKey = source.args.
|
|
110
|
+
const fieldKey = source.args.field;
|
|
76
111
|
const { value: fieldValue, label: fieldLabel } =
|
|
77
112
|
dataFields?.[ fieldKey ] || {};
|
|
78
113
|
newValues[ attributeName ] = fieldValue ?? fieldLabel ?? fieldKey;
|
|
79
114
|
}
|
|
80
115
|
return newValues;
|
|
81
116
|
},
|
|
82
|
-
setValues( { dispatch, context, bindings } ) {
|
|
117
|
+
setValues( { dispatch, context, bindings, clientId, select } ) {
|
|
118
|
+
const { getBlockName } = select( blockEditorStore );
|
|
119
|
+
|
|
120
|
+
const blockName = getBlockName?.( clientId );
|
|
121
|
+
|
|
122
|
+
// Navigaton block types are read-only.
|
|
123
|
+
// See https://github.com/WordPress/gutenberg/pull/72165.
|
|
124
|
+
if ( NAVIGATION_BLOCK_TYPES.includes( blockName ) ) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
83
127
|
const newData = {};
|
|
84
128
|
Object.values( bindings ).forEach( ( { args, newValue } ) => {
|
|
85
|
-
newData[ args.
|
|
129
|
+
newData[ args.field ] = newValue;
|
|
86
130
|
} );
|
|
87
131
|
|
|
88
132
|
dispatch( coreDataStore ).editEntityRecord(
|
|
@@ -93,6 +137,17 @@ export default {
|
|
|
93
137
|
);
|
|
94
138
|
},
|
|
95
139
|
canUserEditValue( { select, context, args } ) {
|
|
140
|
+
const { getBlockName, getSelectedBlockClientId } =
|
|
141
|
+
select( blockEditorStore );
|
|
142
|
+
const clientId = getSelectedBlockClientId();
|
|
143
|
+
const blockName = getBlockName?.( clientId );
|
|
144
|
+
|
|
145
|
+
// Navigaton block types are read-only.
|
|
146
|
+
// See https://github.com/WordPress/gutenberg/pull/72165.
|
|
147
|
+
if ( NAVIGATION_BLOCK_TYPES.includes( blockName ) ) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
96
151
|
// Lock editing in query loop.
|
|
97
152
|
if ( context?.query || context?.queryId ) {
|
|
98
153
|
return false;
|
|
@@ -103,8 +158,9 @@ export default {
|
|
|
103
158
|
return false;
|
|
104
159
|
}
|
|
105
160
|
|
|
106
|
-
const fieldValue = getPostDataFields( select, context )?.[
|
|
107
|
-
|
|
161
|
+
const fieldValue = getPostDataFields( select, context, undefined )?.[
|
|
162
|
+
args.field
|
|
163
|
+
]?.value;
|
|
108
164
|
// Empty string or `false` could be a valid value, so we need to check if the field value is undefined.
|
|
109
165
|
if ( fieldValue === undefined ) {
|
|
110
166
|
return false;
|
|
@@ -123,20 +179,25 @@ export default {
|
|
|
123
179
|
return true;
|
|
124
180
|
},
|
|
125
181
|
getFieldsList( { select, context } ) {
|
|
182
|
+
const clientId = select( blockEditorStore ).getSelectedBlockClientId();
|
|
126
183
|
// Deprecated, will be removed after 6.9.
|
|
127
|
-
return getPostDataFields( select, context );
|
|
184
|
+
return getPostDataFields( select, context, clientId );
|
|
128
185
|
},
|
|
129
186
|
editorUI( { select, context } ) {
|
|
130
|
-
const selectedBlock = select(
|
|
187
|
+
const selectedBlock = select( blockEditorStore ).getSelectedBlock();
|
|
131
188
|
if ( selectedBlock?.name !== 'core/post-date' ) {
|
|
132
189
|
return {};
|
|
133
190
|
}
|
|
191
|
+
// Exit early for navigation blocks (read-only)
|
|
192
|
+
if ( NAVIGATION_BLOCK_TYPES.includes( selectedBlock?.name ) ) {
|
|
193
|
+
return {};
|
|
194
|
+
}
|
|
134
195
|
const postDataFields = Object.entries(
|
|
135
196
|
getPostDataFields( select, context ) || {}
|
|
136
197
|
).map( ( [ key, field ] ) => ( {
|
|
137
198
|
label: field.label,
|
|
138
199
|
args: {
|
|
139
|
-
key,
|
|
200
|
+
field: key,
|
|
140
201
|
},
|
|
141
202
|
type: field.type,
|
|
142
203
|
} ) );
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { store as coreDataStore } from '@wordpress/core-data';
|
|
6
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
7
|
+
|
|
8
|
+
// Navigation block types that use special handling for backwards compatibility
|
|
9
|
+
const NAVIGATION_BLOCK_TYPES = [
|
|
10
|
+
'core/navigation-link',
|
|
11
|
+
'core/navigation-submenu',
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates the data fields object with the given term data values and ID value.
|
|
16
|
+
*
|
|
17
|
+
* @param {Object} termDataValues The term data values.
|
|
18
|
+
* @param {string|number} idValue The ID value to use.
|
|
19
|
+
* @return {Object} The data fields object.
|
|
20
|
+
*/
|
|
21
|
+
function createDataFields( termDataValues, idValue ) {
|
|
22
|
+
return {
|
|
23
|
+
id: {
|
|
24
|
+
label: __( 'Term ID' ),
|
|
25
|
+
value: idValue,
|
|
26
|
+
type: 'string',
|
|
27
|
+
},
|
|
28
|
+
name: {
|
|
29
|
+
label: __( 'Name' ),
|
|
30
|
+
value: termDataValues?.name,
|
|
31
|
+
type: 'string',
|
|
32
|
+
},
|
|
33
|
+
slug: {
|
|
34
|
+
label: __( 'Slug' ),
|
|
35
|
+
value: termDataValues?.slug,
|
|
36
|
+
type: 'string',
|
|
37
|
+
},
|
|
38
|
+
link: {
|
|
39
|
+
label: __( 'Link' ),
|
|
40
|
+
value: termDataValues?.link,
|
|
41
|
+
type: 'string',
|
|
42
|
+
},
|
|
43
|
+
description: {
|
|
44
|
+
label: __( 'Description' ),
|
|
45
|
+
value: termDataValues?.description,
|
|
46
|
+
type: 'string',
|
|
47
|
+
},
|
|
48
|
+
parent: {
|
|
49
|
+
label: __( 'Parent ID' ),
|
|
50
|
+
value: termDataValues?.parent,
|
|
51
|
+
type: 'string',
|
|
52
|
+
},
|
|
53
|
+
count: {
|
|
54
|
+
label: __( 'Count' ),
|
|
55
|
+
value: `(${ termDataValues?.count ?? 0 })`,
|
|
56
|
+
type: 'string',
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Gets a list of term data fields with their values and labels
|
|
63
|
+
* to be consumed in the needed callbacks.
|
|
64
|
+
* If the value is not available based on context, like in templates,
|
|
65
|
+
* it falls back to the default value, label, or key.
|
|
66
|
+
*
|
|
67
|
+
* @param {Object} select The select function from the data store.
|
|
68
|
+
* @param {Object} context The context provided.
|
|
69
|
+
* @param {string} clientId The block client ID used to read attributes.
|
|
70
|
+
* @return {Object} List of term data fields with their value and label.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```js
|
|
74
|
+
* {
|
|
75
|
+
* name: {
|
|
76
|
+
* label: 'Term Name',
|
|
77
|
+
* value: 'Category Name',
|
|
78
|
+
* },
|
|
79
|
+
* count: {
|
|
80
|
+
* label: 'Term Count',
|
|
81
|
+
* value: 5,
|
|
82
|
+
* },
|
|
83
|
+
* ...
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
function getTermDataFields( select, context, clientId ) {
|
|
88
|
+
const { getEntityRecord } = select( coreDataStore );
|
|
89
|
+
const { getBlockAttributes, getBlockName } = select( blockEditorStore );
|
|
90
|
+
|
|
91
|
+
let termDataValues, dataFields;
|
|
92
|
+
|
|
93
|
+
/*
|
|
94
|
+
* BACKWARDS COMPATIBILITY: Hardcoded exception for navigation blocks.
|
|
95
|
+
* Required for WordPress 6.9+ navigation blocks. DO NOT REMOVE.
|
|
96
|
+
*/
|
|
97
|
+
const blockName = getBlockName?.( clientId );
|
|
98
|
+
const isNavigationBlock = NAVIGATION_BLOCK_TYPES.includes( blockName );
|
|
99
|
+
|
|
100
|
+
let termId, taxonomy;
|
|
101
|
+
|
|
102
|
+
if ( isNavigationBlock ) {
|
|
103
|
+
// Navigation blocks: read from block attributes
|
|
104
|
+
const blockAttributes = getBlockAttributes?.( clientId );
|
|
105
|
+
termId = blockAttributes?.id;
|
|
106
|
+
const typeFromAttributes = blockAttributes?.type;
|
|
107
|
+
taxonomy =
|
|
108
|
+
typeFromAttributes === 'tag' ? 'post_tag' : typeFromAttributes;
|
|
109
|
+
} else {
|
|
110
|
+
// All other blocks: use context
|
|
111
|
+
termId = context?.termId;
|
|
112
|
+
taxonomy = context?.taxonomy;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if ( taxonomy && termId ) {
|
|
116
|
+
termDataValues = getEntityRecord( 'taxonomy', taxonomy, termId );
|
|
117
|
+
|
|
118
|
+
if ( ! termDataValues && context?.termData ) {
|
|
119
|
+
termDataValues = context.termData;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if ( termDataValues ) {
|
|
123
|
+
dataFields = createDataFields( termDataValues, termId );
|
|
124
|
+
}
|
|
125
|
+
} else if ( context?.termData ) {
|
|
126
|
+
termDataValues = context.termData;
|
|
127
|
+
dataFields = createDataFields(
|
|
128
|
+
termDataValues,
|
|
129
|
+
termDataValues?.term_id
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if ( ! dataFields || ! Object.keys( dataFields ).length ) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return dataFields;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @type {WPBlockBindingsSource}
|
|
142
|
+
*/
|
|
143
|
+
export default {
|
|
144
|
+
name: 'core/term-data',
|
|
145
|
+
usesContext: [ 'taxonomy', 'termId', 'termData' ],
|
|
146
|
+
getValues( { select, context, bindings, clientId } ) {
|
|
147
|
+
const dataFields = getTermDataFields( select, context, clientId );
|
|
148
|
+
|
|
149
|
+
const newValues = {};
|
|
150
|
+
for ( const [ attributeName, source ] of Object.entries( bindings ) ) {
|
|
151
|
+
// Use the value, the field label, or the field key.
|
|
152
|
+
const fieldKey = source.args.field;
|
|
153
|
+
const { value: fieldValue, label: fieldLabel } =
|
|
154
|
+
dataFields?.[ fieldKey ] || {};
|
|
155
|
+
newValues[ attributeName ] = fieldValue ?? fieldLabel ?? fieldKey;
|
|
156
|
+
}
|
|
157
|
+
return newValues;
|
|
158
|
+
},
|
|
159
|
+
// eslint-disable-next-line no-unused-vars
|
|
160
|
+
setValues( { dispatch, context, bindings } ) {
|
|
161
|
+
// Terms are typically not editable through block bindings in most contexts.
|
|
162
|
+
return false;
|
|
163
|
+
},
|
|
164
|
+
canUserEditValue( { select, context, args } ) {
|
|
165
|
+
const { getBlockName, getSelectedBlockClientId } =
|
|
166
|
+
select( blockEditorStore );
|
|
167
|
+
|
|
168
|
+
const clientId = getSelectedBlockClientId();
|
|
169
|
+
const blockName = getBlockName?.( clientId );
|
|
170
|
+
|
|
171
|
+
// Navigaton block types are read-only.
|
|
172
|
+
// See https://github.com/WordPress/gutenberg/pull/72165.
|
|
173
|
+
if ( NAVIGATION_BLOCK_TYPES.includes( blockName ) ) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Terms are typically read-only when displayed.
|
|
178
|
+
if ( context?.termQuery ) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Lock editing when `taxonomy` or `termId` is not defined.
|
|
183
|
+
if ( ! context?.taxonomy || ! context?.termId ) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const fieldValue = getTermDataFields( select, context, undefined )?.[
|
|
188
|
+
args.field
|
|
189
|
+
]?.value;
|
|
190
|
+
// Empty string or `false` could be a valid value, so we need to check if the field value is undefined.
|
|
191
|
+
if ( fieldValue === undefined ) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return false;
|
|
196
|
+
},
|
|
197
|
+
getFieldsList( { select, context } ) {
|
|
198
|
+
// Deprecated, will be removed after 6.9.
|
|
199
|
+
return getTermDataFields( select, context );
|
|
200
|
+
},
|
|
201
|
+
editorUI( { select, context } ) {
|
|
202
|
+
const selectedBlock = select( blockEditorStore ).getSelectedBlock();
|
|
203
|
+
// Exit early for navigation blocks (read-only)
|
|
204
|
+
if ( NAVIGATION_BLOCK_TYPES.includes( selectedBlock?.name ) ) {
|
|
205
|
+
return {};
|
|
206
|
+
}
|
|
207
|
+
const termDataFields = Object.entries(
|
|
208
|
+
getTermDataFields( select, context ) || {}
|
|
209
|
+
).map( ( [ key, field ] ) => ( {
|
|
210
|
+
label: field.label,
|
|
211
|
+
type: field.type,
|
|
212
|
+
args: {
|
|
213
|
+
field: key,
|
|
214
|
+
},
|
|
215
|
+
} ) );
|
|
216
|
+
/*
|
|
217
|
+
* 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 }]
|
|
218
|
+
*/
|
|
219
|
+
return {
|
|
220
|
+
mode: 'dropdown',
|
|
221
|
+
data: termDataFields,
|
|
222
|
+
};
|
|
223
|
+
},
|
|
224
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { __
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
5
|
import { useSelect } from '@wordpress/data';
|
|
6
6
|
import {
|
|
7
7
|
__experimentalHStack as HStack,
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
store as blockEditorStore,
|
|
12
12
|
privateApis as blockEditorPrivateApis,
|
|
13
13
|
} from '@wordpress/block-editor';
|
|
14
|
-
import { isUnmodifiedDefaultBlock } from '@wordpress/blocks';
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* Internal dependencies
|
|
@@ -29,28 +28,17 @@ export function AddComment( {
|
|
|
29
28
|
setShowCommentBoard,
|
|
30
29
|
commentSidebarRef,
|
|
31
30
|
} ) {
|
|
32
|
-
const { clientId, blockCommentId
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
? isUnmodifiedDefaultBlock( selectedBlock )
|
|
41
|
-
: false,
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
[]
|
|
45
|
-
);
|
|
31
|
+
const { clientId, blockCommentId } = useSelect( ( select ) => {
|
|
32
|
+
const { getSelectedBlock } = select( blockEditorStore );
|
|
33
|
+
const selectedBlock = getSelectedBlock();
|
|
34
|
+
return {
|
|
35
|
+
clientId: selectedBlock?.clientId,
|
|
36
|
+
blockCommentId: selectedBlock?.attributes?.metadata?.noteId,
|
|
37
|
+
};
|
|
38
|
+
}, [] );
|
|
46
39
|
const blockElement = useBlockElement( clientId );
|
|
47
40
|
|
|
48
|
-
if (
|
|
49
|
-
! showCommentBoard ||
|
|
50
|
-
! clientId ||
|
|
51
|
-
undefined !== blockCommentId ||
|
|
52
|
-
isEmptyDefaultBlock
|
|
53
|
-
) {
|
|
41
|
+
if ( ! showCommentBoard || ! clientId || undefined !== blockCommentId ) {
|
|
54
42
|
return null;
|
|
55
43
|
}
|
|
56
44
|
|
|
@@ -68,12 +56,13 @@ export function AddComment( {
|
|
|
68
56
|
onSubmit={ async ( inputComment ) => {
|
|
69
57
|
const { id } = await onSubmit( { content: inputComment } );
|
|
70
58
|
focusCommentThread( id, commentSidebarRef.current );
|
|
59
|
+
setShowCommentBoard( false );
|
|
71
60
|
} }
|
|
72
61
|
onCancel={ () => {
|
|
73
62
|
setShowCommentBoard( false );
|
|
74
63
|
blockElement?.focus();
|
|
75
64
|
} }
|
|
76
|
-
submitButtonText={
|
|
65
|
+
submitButtonText={ __( 'Add note' ) }
|
|
77
66
|
labelText={ __( 'New Note' ) }
|
|
78
67
|
/>
|
|
79
68
|
</VStack>
|