@wordpress/editor 14.35.2-next.dc3f6d3c1.0 → 14.36.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 +1 -1
- package/build/bindings/post-data.js +15 -15
- package/build/bindings/post-data.js.map +2 -2
- package/build/bindings/term-data.js +97 -95
- package/build/bindings/term-data.js.map +2 -2
- package/build/components/collab-sidebar/comments.js +12 -4
- package/build/components/collab-sidebar/comments.js.map +2 -2
- package/build/components/collab-sidebar/hooks.js +9 -1
- package/build/components/collab-sidebar/hooks.js.map +2 -2
- package/build/components/global-styles/index.js +1 -1
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/post-schedule/panel.js +1 -7
- package/build/components/post-schedule/panel.js.map +2 -2
- package/build/components/post-status/index.js +1 -7
- package/build/components/post-status/index.js.map +2 -2
- package/build/components/post-template/block-theme.js +1 -1
- package/build/components/post-template/block-theme.js.map +2 -2
- package/build/components/post-template/hooks.js +1 -1
- package/build/components/post-template/hooks.js.map +2 -2
- package/build/components/provider/index.js +3 -1
- package/build/components/provider/index.js.map +2 -2
- package/build/components/visual-editor/index.js +1 -7
- package/build/components/visual-editor/index.js.map +2 -2
- package/build/components/visual-editor/use-edit-content-only-section-exit.js +5 -6
- package/build/components/visual-editor/use-edit-content-only-section-exit.js.map +2 -2
- package/build/dataviews/store/private-actions.js +5 -1
- package/build/dataviews/store/private-actions.js.map +2 -2
- package/build/hooks/template-part-navigation-edit-button.js +8 -11
- package/build/hooks/template-part-navigation-edit-button.js.map +3 -3
- package/build/store/actions.js +1 -1
- package/build/store/actions.js.map +2 -2
- package/build/store/constants.js +8 -0
- package/build/store/constants.js.map +2 -2
- package/build-module/bindings/post-data.js +15 -15
- package/build-module/bindings/post-data.js.map +2 -2
- package/build-module/bindings/term-data.js +93 -95
- package/build-module/bindings/term-data.js.map +2 -2
- package/build-module/components/collab-sidebar/comments.js +12 -4
- package/build-module/components/collab-sidebar/comments.js.map +2 -2
- package/build-module/components/collab-sidebar/hooks.js +9 -1
- package/build-module/components/collab-sidebar/hooks.js.map +2 -2
- package/build-module/components/global-styles/index.js +1 -1
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/post-schedule/panel.js +1 -12
- package/build-module/components/post-schedule/panel.js.map +2 -2
- package/build-module/components/post-status/index.js +1 -12
- package/build-module/components/post-status/index.js.map +2 -2
- package/build-module/components/post-template/block-theme.js +1 -1
- package/build-module/components/post-template/block-theme.js.map +2 -2
- package/build-module/components/post-template/hooks.js +1 -1
- package/build-module/components/post-template/hooks.js.map +2 -2
- package/build-module/components/provider/index.js +3 -1
- package/build-module/components/provider/index.js.map +2 -2
- package/build-module/components/visual-editor/index.js +2 -7
- package/build-module/components/visual-editor/index.js.map +2 -2
- package/build-module/components/visual-editor/use-edit-content-only-section-exit.js +5 -6
- package/build-module/components/visual-editor/use-edit-content-only-section-exit.js.map +2 -2
- package/build-module/dataviews/store/private-actions.js +5 -1
- package/build-module/dataviews/store/private-actions.js.map +2 -2
- package/build-module/hooks/template-part-navigation-edit-button.js +10 -17
- package/build-module/hooks/template-part-navigation-edit-button.js.map +2 -2
- package/build-module/store/actions.js +1 -1
- package/build-module/store/actions.js.map +2 -2
- package/build-module/store/constants.js +7 -0
- package/build-module/store/constants.js.map +2 -2
- package/build-style/style-rtl.css +263 -27
- package/build-style/style.css +263 -27
- package/build-types/bindings/post-data.d.ts +2 -1
- package/build-types/bindings/term-data.d.ts +86 -8
- package/build-types/bindings/term-data.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/comments.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/hooks.d.ts.map +1 -1
- package/build-types/components/post-schedule/panel.d.ts.map +1 -1
- package/build-types/components/post-status/index.d.ts.map +1 -1
- package/build-types/components/post-template/block-theme.d.ts.map +1 -1
- package/build-types/components/provider/index.d.ts.map +1 -1
- package/build-types/components/visual-editor/index.d.ts.map +1 -1
- package/build-types/components/visual-editor/use-edit-content-only-section-exit.d.ts.map +1 -1
- package/build-types/dataviews/store/private-actions.d.ts +5 -0
- package/build-types/dataviews/store/private-actions.d.ts.map +1 -1
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/store/constants.d.ts +1 -0
- package/build-types/store/constants.d.ts.map +1 -1
- package/package.json +40 -40
- package/src/bindings/post-data.js +21 -20
- package/src/bindings/term-data.js +124 -151
- package/src/bindings/test/post-data.js +31 -20
- package/src/bindings/test/term-data.js +406 -0
- package/src/components/collab-sidebar/comments.js +24 -16
- package/src/components/collab-sidebar/hooks.js +12 -1
- package/src/components/global-styles/index.js +1 -1
- package/src/components/post-schedule/panel.js +1 -13
- package/src/components/post-status/index.js +1 -13
- package/src/components/post-template/block-theme.js +4 -1
- package/src/components/post-template/hooks.js +1 -1
- package/src/components/provider/index.js +7 -2
- package/src/components/visual-editor/index.js +1 -6
- package/src/components/visual-editor/use-edit-content-only-section-exit.js +9 -10
- package/src/dataviews/store/private-actions.ts +17 -1
- package/src/hooks/template-part-navigation-edit-button.js +4 -15
- package/src/store/actions.js +2 -0
- package/src/store/constants.ts +6 -0
- package/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/editor",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.36.0",
|
|
4
4
|
"description": "Enhanced block editor for WordPress posts.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -53,44 +53,44 @@
|
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@floating-ui/react-dom": "2.0.8",
|
|
56
|
-
"@wordpress/a11y": "^4.
|
|
57
|
-
"@wordpress/api-fetch": "^7.
|
|
58
|
-
"@wordpress/base-styles": "^6.
|
|
59
|
-
"@wordpress/blob": "^4.
|
|
60
|
-
"@wordpress/block-editor": "^15.
|
|
61
|
-
"@wordpress/blocks": "^15.
|
|
62
|
-
"@wordpress/commands": "^1.
|
|
63
|
-
"@wordpress/components": "^30.
|
|
64
|
-
"@wordpress/compose": "^7.
|
|
65
|
-
"@wordpress/core-data": "^7.
|
|
66
|
-
"@wordpress/data": "^10.
|
|
67
|
-
"@wordpress/dataviews": "^
|
|
68
|
-
"@wordpress/date": "^5.
|
|
69
|
-
"@wordpress/deprecated": "^4.
|
|
70
|
-
"@wordpress/dom": "^4.
|
|
71
|
-
"@wordpress/element": "^6.
|
|
72
|
-
"@wordpress/fields": "^0.
|
|
73
|
-
"@wordpress/global-styles-engine": "^1.
|
|
74
|
-
"@wordpress/global-styles-ui": "^1.
|
|
75
|
-
"@wordpress/hooks": "^4.
|
|
76
|
-
"@wordpress/html-entities": "^4.
|
|
77
|
-
"@wordpress/i18n": "^6.
|
|
78
|
-
"@wordpress/icons": "^11.
|
|
79
|
-
"@wordpress/interface": "^9.
|
|
80
|
-
"@wordpress/keyboard-shortcuts": "^5.
|
|
81
|
-
"@wordpress/keycodes": "^4.
|
|
82
|
-
"@wordpress/media-utils": "^5.
|
|
83
|
-
"@wordpress/notices": "^5.
|
|
84
|
-
"@wordpress/patterns": "^2.
|
|
85
|
-
"@wordpress/plugins": "^7.
|
|
86
|
-
"@wordpress/preferences": "^4.
|
|
87
|
-
"@wordpress/private-apis": "^1.
|
|
88
|
-
"@wordpress/reusable-blocks": "^5.
|
|
89
|
-
"@wordpress/rich-text": "^7.
|
|
90
|
-
"@wordpress/server-side-render": "^6.
|
|
91
|
-
"@wordpress/url": "^4.
|
|
92
|
-
"@wordpress/warning": "^3.
|
|
93
|
-
"@wordpress/wordcount": "^4.
|
|
56
|
+
"@wordpress/a11y": "^4.36.0",
|
|
57
|
+
"@wordpress/api-fetch": "^7.36.0",
|
|
58
|
+
"@wordpress/base-styles": "^6.12.0",
|
|
59
|
+
"@wordpress/blob": "^4.36.0",
|
|
60
|
+
"@wordpress/block-editor": "^15.9.0",
|
|
61
|
+
"@wordpress/blocks": "^15.9.0",
|
|
62
|
+
"@wordpress/commands": "^1.36.0",
|
|
63
|
+
"@wordpress/components": "^30.9.0",
|
|
64
|
+
"@wordpress/compose": "^7.36.0",
|
|
65
|
+
"@wordpress/core-data": "^7.36.0",
|
|
66
|
+
"@wordpress/data": "^10.36.0",
|
|
67
|
+
"@wordpress/dataviews": "^11.0.0",
|
|
68
|
+
"@wordpress/date": "^5.36.0",
|
|
69
|
+
"@wordpress/deprecated": "^4.36.0",
|
|
70
|
+
"@wordpress/dom": "^4.36.0",
|
|
71
|
+
"@wordpress/element": "^6.36.0",
|
|
72
|
+
"@wordpress/fields": "^0.28.0",
|
|
73
|
+
"@wordpress/global-styles-engine": "^1.3.0",
|
|
74
|
+
"@wordpress/global-styles-ui": "^1.3.0",
|
|
75
|
+
"@wordpress/hooks": "^4.36.0",
|
|
76
|
+
"@wordpress/html-entities": "^4.36.0",
|
|
77
|
+
"@wordpress/i18n": "^6.9.0",
|
|
78
|
+
"@wordpress/icons": "^11.3.0",
|
|
79
|
+
"@wordpress/interface": "^9.21.0",
|
|
80
|
+
"@wordpress/keyboard-shortcuts": "^5.36.0",
|
|
81
|
+
"@wordpress/keycodes": "^4.36.0",
|
|
82
|
+
"@wordpress/media-utils": "^5.36.0",
|
|
83
|
+
"@wordpress/notices": "^5.36.0",
|
|
84
|
+
"@wordpress/patterns": "^2.36.0",
|
|
85
|
+
"@wordpress/plugins": "^7.36.0",
|
|
86
|
+
"@wordpress/preferences": "^4.36.0",
|
|
87
|
+
"@wordpress/private-apis": "^1.36.0",
|
|
88
|
+
"@wordpress/reusable-blocks": "^5.36.0",
|
|
89
|
+
"@wordpress/rich-text": "^7.36.0",
|
|
90
|
+
"@wordpress/server-side-render": "^6.12.0",
|
|
91
|
+
"@wordpress/url": "^4.36.0",
|
|
92
|
+
"@wordpress/warning": "^3.36.0",
|
|
93
|
+
"@wordpress/wordcount": "^4.36.0",
|
|
94
94
|
"change-case": "^4.1.2",
|
|
95
95
|
"client-zip": "^2.4.5",
|
|
96
96
|
"clsx": "^2.1.1",
|
|
@@ -108,5 +108,5 @@
|
|
|
108
108
|
"publishConfig": {
|
|
109
109
|
"access": "public"
|
|
110
110
|
},
|
|
111
|
-
"gitHead": "
|
|
111
|
+
"gitHead": "b35cf1a2dce04665e99fd6b9c2891c0b336361b9"
|
|
112
112
|
}
|
|
@@ -35,23 +35,19 @@ const postDataFields = [
|
|
|
35
35
|
export default {
|
|
36
36
|
name: 'core/post-data',
|
|
37
37
|
getValues( { select, context, bindings, clientId } ) {
|
|
38
|
-
const allowedFields = postDataFields.map(
|
|
39
|
-
( field ) => field.args.field
|
|
40
|
-
);
|
|
41
|
-
|
|
42
38
|
/*
|
|
43
39
|
* BACKWARDS COMPATIBILITY: Hardcoded exception for navigation blocks.
|
|
44
40
|
* Required for WordPress 6.9+ navigation blocks. DO NOT REMOVE.
|
|
45
41
|
*/
|
|
46
42
|
const { getBlockAttributes, getBlockName } = select( blockEditorStore );
|
|
47
|
-
const blockName = getBlockName
|
|
43
|
+
const blockName = getBlockName( clientId );
|
|
48
44
|
const isNavigationBlock = NAVIGATION_BLOCK_TYPES.includes( blockName );
|
|
49
45
|
|
|
50
46
|
let postId, postType;
|
|
51
47
|
|
|
52
48
|
if ( isNavigationBlock ) {
|
|
53
49
|
// Navigation blocks: read from block attributes
|
|
54
|
-
const blockAttributes = getBlockAttributes
|
|
50
|
+
const blockAttributes = getBlockAttributes( clientId );
|
|
55
51
|
postId = blockAttributes?.id;
|
|
56
52
|
postType = blockAttributes?.type;
|
|
57
53
|
} else {
|
|
@@ -69,23 +65,28 @@ export default {
|
|
|
69
65
|
|
|
70
66
|
const newValues = {};
|
|
71
67
|
for ( const [ attributeName, binding ] of Object.entries( bindings ) ) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
const postDataField = postDataFields.find(
|
|
69
|
+
( field ) => field.args.field === binding.args.field
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
if ( ! postDataField ) {
|
|
73
|
+
// If the field is unknown, return the field name.
|
|
74
|
+
newValues[ attributeName ] = binding.args.field;
|
|
75
|
+
} else if ( ! entityDataValues ) {
|
|
76
|
+
// If the entity data does not exist, return the field label.
|
|
77
|
+
newValues[ attributeName ] = postDataField.label;
|
|
78
|
+
} else {
|
|
79
|
+
// If the entity data exists, return the entity value.
|
|
80
|
+
newValues[ attributeName ] =
|
|
81
|
+
entityDataValues[ binding.args.field ];
|
|
75
82
|
}
|
|
76
|
-
|
|
77
|
-
newValues[ attributeName ] =
|
|
78
|
-
entityDataValues?.[ binding.args.field ] ??
|
|
79
|
-
postDataFields.find(
|
|
80
|
-
( field ) => field.args.field === binding.args.field
|
|
81
|
-
).label;
|
|
82
83
|
}
|
|
83
84
|
return newValues;
|
|
84
85
|
},
|
|
85
86
|
setValues( { dispatch, context, bindings, clientId, select } ) {
|
|
86
87
|
const { getBlockName } = select( blockEditorStore );
|
|
87
88
|
|
|
88
|
-
const blockName = getBlockName
|
|
89
|
+
const blockName = getBlockName( clientId );
|
|
89
90
|
|
|
90
91
|
// Navigaton block types are read-only.
|
|
91
92
|
// See https://github.com/WordPress/gutenberg/pull/72165.
|
|
@@ -108,7 +109,7 @@ export default {
|
|
|
108
109
|
const { getBlockName, getSelectedBlockClientId } =
|
|
109
110
|
select( blockEditorStore );
|
|
110
111
|
const clientId = getSelectedBlockClientId();
|
|
111
|
-
const blockName = getBlockName
|
|
112
|
+
const blockName = getBlockName( clientId );
|
|
112
113
|
|
|
113
114
|
// Navigaton block types are read-only.
|
|
114
115
|
// See https://github.com/WordPress/gutenberg/pull/72165.
|
|
@@ -138,13 +139,13 @@ export default {
|
|
|
138
139
|
|
|
139
140
|
return true;
|
|
140
141
|
},
|
|
141
|
-
getFieldsList( { select } ) {
|
|
142
|
+
getFieldsList( { context, select } ) {
|
|
142
143
|
const selectedBlock = select( blockEditorStore ).getSelectedBlock();
|
|
143
144
|
if ( selectedBlock?.name !== 'core/post-date' ) {
|
|
144
145
|
return [];
|
|
145
146
|
}
|
|
146
|
-
|
|
147
|
-
if (
|
|
147
|
+
|
|
148
|
+
if ( ! context || ! context.postId || ! context.postType ) {
|
|
148
149
|
return [];
|
|
149
150
|
}
|
|
150
151
|
|
|
@@ -11,131 +11,43 @@ const NAVIGATION_BLOCK_TYPES = [
|
|
|
11
11
|
'core/navigation-submenu',
|
|
12
12
|
];
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
}
|
|
14
|
+
export const termDataFields = [
|
|
15
|
+
{
|
|
16
|
+
label: __( 'Term ID' ),
|
|
17
|
+
args: { field: 'id' },
|
|
18
|
+
type: 'string',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
label: __( 'Name' ),
|
|
22
|
+
args: { field: 'name' },
|
|
23
|
+
type: 'string',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
label: __( 'Slug' ),
|
|
27
|
+
args: { field: 'slug' },
|
|
28
|
+
type: 'string',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
label: __( 'Link' ),
|
|
32
|
+
args: { field: 'link' },
|
|
33
|
+
type: 'string',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
label: __( 'Description' ),
|
|
37
|
+
args: { field: 'description' },
|
|
38
|
+
type: 'string',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
label: __( 'Parent ID' ),
|
|
42
|
+
args: { field: 'parent' },
|
|
43
|
+
type: 'string',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
label: __( 'Count' ),
|
|
47
|
+
args: { field: 'count' },
|
|
48
|
+
type: 'string',
|
|
49
|
+
},
|
|
50
|
+
];
|
|
139
51
|
|
|
140
52
|
/**
|
|
141
53
|
* @type {WPBlockBindingsSource}
|
|
@@ -144,15 +56,67 @@ export default {
|
|
|
144
56
|
name: 'core/term-data',
|
|
145
57
|
usesContext: [ 'taxonomy', 'termId', 'termData' ],
|
|
146
58
|
getValues( { select, context, bindings, clientId } ) {
|
|
147
|
-
const
|
|
59
|
+
const { getEntityRecord } = select( coreDataStore );
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
* BACKWARDS COMPATIBILITY: Hardcoded exception for navigation blocks.
|
|
63
|
+
* Required for WordPress 6.9+ navigation blocks. DO NOT REMOVE.
|
|
64
|
+
*/
|
|
65
|
+
const { getBlockAttributes, getBlockName } = select( blockEditorStore );
|
|
66
|
+
const blockName = getBlockName( clientId );
|
|
67
|
+
const isNavigationBlock = NAVIGATION_BLOCK_TYPES.includes( blockName );
|
|
68
|
+
|
|
69
|
+
let termDataValues;
|
|
70
|
+
|
|
71
|
+
if ( isNavigationBlock ) {
|
|
72
|
+
// Navigation blocks: read from block attributes
|
|
73
|
+
const blockAttributes = getBlockAttributes( clientId );
|
|
74
|
+
const typeFromAttributes = blockAttributes?.type;
|
|
75
|
+
const taxonomy =
|
|
76
|
+
typeFromAttributes === 'tag' ? 'post_tag' : typeFromAttributes;
|
|
77
|
+
termDataValues = getEntityRecord(
|
|
78
|
+
'taxonomy',
|
|
79
|
+
taxonomy,
|
|
80
|
+
blockAttributes?.id
|
|
81
|
+
);
|
|
82
|
+
} else if ( context.termId && context.taxonomy ) {
|
|
83
|
+
// All other blocks: use context
|
|
84
|
+
termDataValues = getEntityRecord(
|
|
85
|
+
'taxonomy',
|
|
86
|
+
context.taxonomy,
|
|
87
|
+
context.termId
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Fall back to context termData if available.
|
|
92
|
+
if ( ! termDataValues && context?.termData && ! isNavigationBlock ) {
|
|
93
|
+
termDataValues = context.termData;
|
|
94
|
+
}
|
|
148
95
|
|
|
149
96
|
const newValues = {};
|
|
150
|
-
for ( const [ attributeName,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
97
|
+
for ( const [ attributeName, binding ] of Object.entries( bindings ) ) {
|
|
98
|
+
const termDataField = termDataFields.find(
|
|
99
|
+
( field ) => field.args.field === binding.args.field
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
if ( ! termDataField ) {
|
|
103
|
+
// If the field is unknown, return the field name.
|
|
104
|
+
newValues[ attributeName ] = binding.args.field;
|
|
105
|
+
} else if (
|
|
106
|
+
! termDataValues ||
|
|
107
|
+
termDataValues[ binding.args.field ] === undefined
|
|
108
|
+
) {
|
|
109
|
+
// If the term data does not exist, return the field label.
|
|
110
|
+
newValues[ attributeName ] = termDataField.label;
|
|
111
|
+
} else if ( binding.args.field === 'count' ) {
|
|
112
|
+
// Return the term count value in parentheses.
|
|
113
|
+
newValues[ attributeName ] =
|
|
114
|
+
'(' + termDataValues[ binding.args.field ] + ')';
|
|
115
|
+
} else {
|
|
116
|
+
// If the term data exists, return the term data value.
|
|
117
|
+
newValues[ attributeName ] =
|
|
118
|
+
termDataValues[ binding.args.field ];
|
|
119
|
+
}
|
|
156
120
|
}
|
|
157
121
|
return newValues;
|
|
158
122
|
},
|
|
@@ -161,12 +125,12 @@ export default {
|
|
|
161
125
|
// Terms are typically not editable through block bindings in most contexts.
|
|
162
126
|
return false;
|
|
163
127
|
},
|
|
164
|
-
canUserEditValue( { select, context
|
|
128
|
+
canUserEditValue( { select, context } ) {
|
|
165
129
|
const { getBlockName, getSelectedBlockClientId } =
|
|
166
130
|
select( blockEditorStore );
|
|
167
131
|
|
|
168
132
|
const clientId = getSelectedBlockClientId();
|
|
169
|
-
const blockName = getBlockName
|
|
133
|
+
const blockName = getBlockName( clientId );
|
|
170
134
|
|
|
171
135
|
// Navigaton block types are read-only.
|
|
172
136
|
// See https://github.com/WordPress/gutenberg/pull/72165.
|
|
@@ -184,26 +148,35 @@ export default {
|
|
|
184
148
|
return false;
|
|
185
149
|
}
|
|
186
150
|
|
|
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
151
|
return false;
|
|
196
152
|
},
|
|
197
|
-
getFieldsList( {
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
153
|
+
getFieldsList( { context, select } ) {
|
|
154
|
+
const { getBlockAttributes, getBlockName, getSelectedBlockClientId } =
|
|
155
|
+
select( blockEditorStore );
|
|
156
|
+
const clientId = getSelectedBlockClientId();
|
|
157
|
+
const blockName = getBlockName( clientId );
|
|
158
|
+
|
|
159
|
+
if ( NAVIGATION_BLOCK_TYPES.includes( blockName ) ) {
|
|
160
|
+
// Navigation blocks: read from block attributes
|
|
161
|
+
const blockAttributes = getBlockAttributes( clientId );
|
|
162
|
+
if (
|
|
163
|
+
! blockAttributes ||
|
|
164
|
+
! blockAttributes.id ||
|
|
165
|
+
! blockAttributes.type
|
|
166
|
+
) {
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
169
|
+
return termDataFields;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if ( ! context ) {
|
|
201
173
|
return [];
|
|
202
174
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
175
|
+
|
|
176
|
+
if ( ( context.taxonomy && context.termId ) || context.termData ) {
|
|
177
|
+
return termDataFields;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return [];
|
|
208
181
|
},
|
|
209
182
|
};
|
|
@@ -32,12 +32,12 @@ describe( 'post-data bindings', () => {
|
|
|
32
32
|
link: 'https://example.com/post',
|
|
33
33
|
unknown: 'Unknown field value',
|
|
34
34
|
}
|
|
35
|
-
:
|
|
35
|
+
: false,
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
38
|
} );
|
|
39
39
|
|
|
40
|
-
it( 'should return entity field values when they exist', () => {
|
|
40
|
+
it( 'should return entity field values when they exist, and field name for unknown fields', () => {
|
|
41
41
|
const values = postDataBindings.getValues( {
|
|
42
42
|
select,
|
|
43
43
|
context: { postId: 123, postType: 'post' },
|
|
@@ -54,6 +54,10 @@ describe( 'post-data bindings', () => {
|
|
|
54
54
|
source: 'core/post-date',
|
|
55
55
|
args: { field: 'link' },
|
|
56
56
|
},
|
|
57
|
+
content: {
|
|
58
|
+
source: 'core/post-date',
|
|
59
|
+
args: { field: 'unknown' },
|
|
60
|
+
},
|
|
57
61
|
},
|
|
58
62
|
clientId: '123abc456',
|
|
59
63
|
} );
|
|
@@ -62,10 +66,11 @@ describe( 'post-data bindings', () => {
|
|
|
62
66
|
datetime: '2024-03-02 00:00:00',
|
|
63
67
|
modified: '2025-06-07 00:00:00',
|
|
64
68
|
url: 'https://example.com/post',
|
|
69
|
+
content: 'unknown',
|
|
65
70
|
} );
|
|
66
71
|
} );
|
|
67
72
|
|
|
68
|
-
it( 'should fall back to field labels when entity value does not exist', () => {
|
|
73
|
+
it( 'should fall back to field labels when entity value does not exist, and to field name for unknown fields', () => {
|
|
69
74
|
const values = postDataBindings.getValues( {
|
|
70
75
|
select,
|
|
71
76
|
context: { postId: 456, postType: 'post' },
|
|
@@ -82,6 +87,10 @@ describe( 'post-data bindings', () => {
|
|
|
82
87
|
source: 'core/post-date',
|
|
83
88
|
args: { field: 'link' },
|
|
84
89
|
},
|
|
90
|
+
content: {
|
|
91
|
+
source: 'core/post-date',
|
|
92
|
+
args: { field: 'unknown' },
|
|
93
|
+
},
|
|
85
94
|
},
|
|
86
95
|
clientId: '123abc456',
|
|
87
96
|
} );
|
|
@@ -90,24 +99,9 @@ describe( 'post-data bindings', () => {
|
|
|
90
99
|
datetime: 'Post Date',
|
|
91
100
|
modified: 'Post Modified Date',
|
|
92
101
|
url: 'Post Link',
|
|
102
|
+
content: 'unknown',
|
|
93
103
|
} );
|
|
94
104
|
} );
|
|
95
|
-
|
|
96
|
-
it( 'should return empty object for unknown fields', () => {
|
|
97
|
-
const values = postDataBindings.getValues( {
|
|
98
|
-
select,
|
|
99
|
-
context: { postId: 123, postType: 'post' },
|
|
100
|
-
bindings: {
|
|
101
|
-
content: {
|
|
102
|
-
source: 'core/post-date',
|
|
103
|
-
args: { field: 'unknown' },
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
clientId: '123abc456',
|
|
107
|
-
} );
|
|
108
|
-
|
|
109
|
-
expect( values.content ).toEqual( {} );
|
|
110
|
-
} );
|
|
111
105
|
} );
|
|
112
106
|
|
|
113
107
|
describe( 'for navigation blocks using block attributes', () => {
|
|
@@ -152,7 +146,7 @@ describe( 'post-data bindings', () => {
|
|
|
152
146
|
} );
|
|
153
147
|
|
|
154
148
|
describe( 'getFieldsList', () => {
|
|
155
|
-
it( 'should return the list of available post data fields when the Date block is selected', () => {
|
|
149
|
+
it( 'should return the list of available post data fields when the Date block is selected, and postId and postType are provided via context', () => {
|
|
156
150
|
const select = () => ( {
|
|
157
151
|
getSelectedBlock: () => ( {
|
|
158
152
|
name: 'core/post-date',
|
|
@@ -160,6 +154,7 @@ describe( 'post-data bindings', () => {
|
|
|
160
154
|
} );
|
|
161
155
|
|
|
162
156
|
const fields = postDataBindings.getFieldsList( {
|
|
157
|
+
context: { postId: 123, postType: 'post' },
|
|
163
158
|
select,
|
|
164
159
|
} );
|
|
165
160
|
|
|
@@ -182,6 +177,21 @@ describe( 'post-data bindings', () => {
|
|
|
182
177
|
] );
|
|
183
178
|
} );
|
|
184
179
|
|
|
180
|
+
it( 'should return an empty array when the Date block is selected but no postId context is provided', () => {
|
|
181
|
+
const select = () => ( {
|
|
182
|
+
getSelectedBlock: () => ( {
|
|
183
|
+
name: 'core/post-date',
|
|
184
|
+
} ),
|
|
185
|
+
} );
|
|
186
|
+
|
|
187
|
+
const fields = postDataBindings.getFieldsList( {
|
|
188
|
+
context: { postType: 'post' },
|
|
189
|
+
select,
|
|
190
|
+
} );
|
|
191
|
+
|
|
192
|
+
expect( fields ).toEqual( [] );
|
|
193
|
+
} );
|
|
194
|
+
|
|
185
195
|
it( 'should return an empty array when any other block than the Date block is selected', () => {
|
|
186
196
|
const select = () => ( {
|
|
187
197
|
getSelectedBlock: () => ( {
|
|
@@ -190,6 +200,7 @@ describe( 'post-data bindings', () => {
|
|
|
190
200
|
} );
|
|
191
201
|
|
|
192
202
|
const fields = postDataBindings.getFieldsList( {
|
|
203
|
+
context: { postId: 123, postType: 'post' },
|
|
193
204
|
select,
|
|
194
205
|
} );
|
|
195
206
|
|