fix: harden CHRNX editor lifecycle

This commit is contained in:
chrnx committed 2026-08-11 15:06:50 -05:00
1 parent a5b94123a8
commit 835fb74ebf
12 files changed
+512 -95

No files matched your search

+20 -16
View File
@@ -7,13 +7,25 @@
} )( function () {
'use strict';
const maxParticipants = 50;
const maxParticipantLength = 100;
function getTranslator( wp ) {
return wp.i18n && typeof wp.i18n.__ === 'function'
? wp.i18n.__
: function ( text ) {
return text;
};
}
function participantsFromText( value ) {
return String( value || '' )
.split( /\r?\n/ )
.map( function ( name ) {
return name.trim();
return Array.from( name.trim() ).slice( 0, maxParticipantLength ).join( '' );
} )
.filter( Boolean );
.filter( Boolean )
.slice( 0, maxParticipants );
}
function participantsToText( value ) {
@@ -53,15 +65,7 @@
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 );
function PodcastPanel() {
const editorState = wp.data.useSelect( function ( select ) {
@@ -107,9 +111,9 @@
return wp.element.createElement(
wp.editPost.PluginDocumentSettingPanel,
{ name: 'chrnx-podcast', title: 'Podcast episode' },
{ name: 'chrnx-podcast', title: __( 'Podcast episode', 'chrnx' ) },
wp.element.createElement( wp.components.TextControl, {
label: 'Episode number',
label: __( 'Episode number', 'chrnx' ),
type: 'number',
min: 0,
value: meta.chrnx_episode_number ?? '',
@@ -122,21 +126,21 @@
},
} ),
wp.element.createElement( wp.components.TextControl, {
label: 'Duration',
label: __( 'Duration', 'chrnx' ),
value: meta.chrnx_episode_duration || '',
onChange( value ) {
setMeta( 'chrnx_episode_duration', value );
},
} ),
wp.element.createElement( wp.components.TextareaControl, {
label: 'Participants (one per line)',
label: __( 'Participants (one per line)', 'chrnx' ),
value: participantsToText( meta.chrnx_episode_participants ),
onChange( value ) {
setMeta( 'chrnx_episode_participants', participantsFromText( value ) );
},
} ),
wp.element.createElement( wp.components.TextControl, {
label: 'Canonical episode URL',
label: __( 'Canonical episode URL', 'chrnx' ),
type: 'url',
value: meta.canonical_episode_url || '',
onChange( value ) {