Skip to content

Commit

Permalink
Improved Gutenberg & WP 5.0 compatibility. 3.2.1 tag
Browse files Browse the repository at this point in the history
  • Loading branch information
sybrew committed Dec 6, 2018
1 parent bedc10e commit f5c2feb
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 42 deletions.
4 changes: 2 additions & 2 deletions autodescription.php
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: The SEO Framework
* Plugin URI: https://theseoframework.com/
* Description: An automated, advanced, accessible, unbranded and extremely fast SEO solution for any WordPress website.
* Version: 3.2.0
* Version: 3.2.1
* Author: Sybre Waaijer
* Author URI: https://theseoframework.com/
* License: GPLv3
Expand Down Expand Up @@ -53,7 +53,7 @@
*
* @since 2.3.5
*/
define( 'THE_SEO_FRAMEWORK_VERSION', '3.2.0' );
define( 'THE_SEO_FRAMEWORK_VERSION', '3.2.1' );

/**
* The plugin Database version.
Expand Down
6 changes: 4 additions & 2 deletions inc/classes/admin-init.class.php
Expand Up @@ -208,7 +208,7 @@ public function enqueue_gutenberg_compat_scripts() {
[
'id' => 'tsf-gbc',
'type' => 'js',
'deps' => [ 'jquery', 'tsf' ],
'deps' => [ 'jquery', 'tsf', 'wp-editor', 'wp-data', 'lodash', 'react' ],
'autoload' => true,
'name' => 'tsf-gbc',
'base' => THE_SEO_FRAMEWORK_DIR_URL . 'lib/js/',
Expand Down Expand Up @@ -334,11 +334,13 @@ public function enqueue_primaryterm_scripts() {
'id' => 'tsf-pt-gb',
'name' => 'pt-gb',
];
$deps = [ 'jquery', 'tsf', 'wp-hooks', 'wp-element', 'wp-components', 'wp-url', 'wp-api-fetch', 'lodash', 'react' ];
} else {
$vars = [
'id' => 'tsf-pt',
'name' => 'pt',
];
$deps = [ 'jquery', 'tsf', 'tsf-tt' ];
}

//! PHP 5.4 compat: put in var.
Expand All @@ -347,7 +349,7 @@ public function enqueue_primaryterm_scripts() {
[
'id' => $vars['id'],
'type' => 'js',
'deps' => [ 'jquery', 'tsf', 'tsf-tt' ],
'deps' => $deps,
'autoload' => true,
'name' => $vars['name'],
'base' => THE_SEO_FRAMEWORK_DIR_URL . 'lib/js/',
Expand Down
47 changes: 13 additions & 34 deletions lib/js/pt-gb.js
Expand Up @@ -99,9 +99,7 @@ window.tsfPTGB = function( $ ) {
}
}
}
const handleDataInput = ( taxonomy, value ) => {
return setPrimaryTermID( taxonomy, value );
}
const handleDataInput = ( taxonomy, value ) => setPrimaryTermID( taxonomy, value );

// Hook data handles.
(()=>{
Expand Down Expand Up @@ -205,7 +203,6 @@ window.tsfPTGB = function( $ ) {
selectedTerms: this.props.terms,
loading: true,
} );
this.lockRef();

this.fetchRequest = apiFetch( {
path: addQueryArgs( `/wp/v2/${ taxonomy.rest_base }`, DEFAULT_QUERY ),
Expand All @@ -217,7 +214,7 @@ window.tsfPTGB = function( $ ) {
loading: false,
} );
this.dsAccess().set( 'availableTerms', terms );
this.updateRef();
this.forceUpdate();
},
( xhr ) => { // reject
if ( xhr.statusText === 'abort' ) {
Expand All @@ -227,44 +224,21 @@ window.tsfPTGB = function( $ ) {
this.setState( {
loading: false,
} );
this.updateRef();
this.forceUpdate();
}
);
}

lockRef() {
if ( this.tsRef && this.tsRef.current ) {
this.tsRef.current.props.disabled = true;
this.tsRef.current.forceUpdate();
}
}

updateRef() {
if ( this.tsRef && this.tsRef.current ) {
this.tsRef.current.props.options = this.getSelectOptions();
this.tsRef.current.props.disabled = false;
this.tsRef.current.forceUpdate();
}
}
}

class TermSelector extends PrimaryTermSelectorHandler {
constructor( props ) {
super( props );

this.onChange = this.onChange.bind( this );
this.tsRef = React.createRef();
}

getTermName( id ) {
let availableTerms = this.dsAccess().get( 'availableTerms' );
// if ( tsf.browseUnhappy ) {
// for ( let i in availableTerms ) {
// if ( availableTerms[ i ].id === id )
// return availableTerms[ i ] && availableTerms[ i ].name || '';
// }
// return '';
// }

let term = availableTerms.find( term => term.id === id );
return term && term.name || '';
Expand All @@ -276,10 +250,16 @@ window.tsfPTGB = function( $ ) {
} );
}

/* I'm good with React. */
onChange( value ) {
this.tsRef.current.props.value = handleDataInput( this.props.slug, value );
this.tsRef.current.forceUpdate();
this.setState( {
options: this.getSelectOptions(),
value: handleDataInput( this.props.slug, value )
} );
tsf.registerChange();
}

isDisabled() {
return !! this.state.loading;
}

render() {
Expand All @@ -292,8 +272,7 @@ window.tsfPTGB = function( $ ) {
className: 'tsf-pt-gb-selector',
onChange: this.onChange,
options: this.state.loading ? '' : this.getSelectOptions(),
disabled: this.state.loading,
ref: this.tsRef,
disabled: this.isDisabled(),
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/js/pt-gb.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/js/tt.js
Expand Up @@ -290,6 +290,9 @@ window.tsfTT = function( $ ) {

addBoundary( '#wpcontent' ); //! All pages, but Gutenberg destroys the boundaries..
addBoundary( '#editor' ); //! Gutenberg
// if ( tsfL10n && tsf.states && tsf.states.isGutenbergPage ) {
// addBoundary( '.edit-post-layout__metaboxes' ); //! TSF's postbox container... ideally.
// }
}

/**
Expand Down Expand Up @@ -482,7 +485,7 @@ window.tsfTT = function( $ ) {
* @return {undefined}
*/
load: function() {
$( document.body ).on( 'tsf-onload', _initToolTips );
$( document.body ).ready( _initToolTips );
}
}, {
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/js/tt.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f5c2feb

Please sign in to comment.