fix: harden CHRNX editor lifecycle
This commit is contained in:
12 files changed
+512
-95
No files matched your search
@@ -13,6 +13,14 @@
|
||||
{ name: 'chrnx_show', restBase: 'show', title: 'Show' },
|
||||
];
|
||||
|
||||
function getTranslator( wp ) {
|
||||
return wp.i18n && typeof wp.i18n.__ === 'function'
|
||||
? wp.i18n.__
|
||||
: function ( text ) {
|
||||
return text;
|
||||
};
|
||||
}
|
||||
|
||||
function orderTerms( terms ) {
|
||||
if ( ! Array.isArray( terms ) ) {
|
||||
return [];
|
||||
@@ -57,15 +65,12 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
const editor = wp.data.select( 'core/editor' );
|
||||
if (
|
||||
! editor ||
|
||||
typeof editor.getCurrentPostType !== 'function' ||
|
||||
typeof editor.getEditedPostAttribute !== 'function' ||
|
||||
editor.getCurrentPostType() !== 'post'
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
const __ = getTranslator( wp );
|
||||
const titles = {
|
||||
chrnx_topic: __( 'Topic', 'chrnx' ),
|
||||
chrnx_language: __( 'Language', 'chrnx' ),
|
||||
chrnx_show: __( 'Show', 'chrnx' ),
|
||||
};
|
||||
|
||||
const panelDispatch = wp.data.dispatch( 'core/edit-post' );
|
||||
if ( panelDispatch && typeof panelDispatch.removeEditorPanel === 'function' ) {
|
||||
@@ -98,7 +103,7 @@
|
||||
return {
|
||||
selected: currentEditor.getEditedPostAttribute( taxonomy.restBase ),
|
||||
terms: core.getEntityRecords( 'taxonomy', taxonomy.name, {
|
||||
per_page: -1,
|
||||
per_page: 100,
|
||||
orderby: 'name',
|
||||
order: 'asc',
|
||||
} ),
|
||||
@@ -118,7 +123,7 @@
|
||||
}
|
||||
|
||||
const selected = editorState.taxonomies[ index ].selected;
|
||||
const options = [ { label: 'Not set', value: '' } ].concat(
|
||||
const options = [ { label: __( 'Not set', 'chrnx' ), value: '' } ].concat(
|
||||
terms.map( function ( term ) {
|
||||
return { label: term.name, value: String( term.id ) };
|
||||
} ),
|
||||
@@ -129,10 +134,10 @@
|
||||
{
|
||||
key: taxonomy.name,
|
||||
name: 'chrnx-' + taxonomy.restBase,
|
||||
title: taxonomy.title,
|
||||
title: titles[ taxonomy.name ],
|
||||
},
|
||||
wp.element.createElement( wp.components.RadioControl, {
|
||||
label: taxonomy.title,
|
||||
label: titles[ taxonomy.name ],
|
||||
selected: Array.isArray( selected ) && selected.length ? String( selected[ 0 ] ) : '',
|
||||
options,
|
||||
onChange( value ) {
|
||||
|
||||
Reference in new issue
Block a user