Skip to content

Commit

Permalink
Only load htmlhint-kses if we require it
Browse files Browse the repository at this point in the history
`htmlhint-kses` is only needed for users who don't have the
`unfiltered_html` capability. We can determine this by checking for the
presense of `wp.codeEditor.defaultSettingshtmlhint.kses`.
  • Loading branch information
noisysocks committed Jan 22, 2018
1 parent decd912 commit 87714ec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
28 changes: 18 additions & 10 deletions components/code-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import withLazyDependencies from '../higher-order/with-lazy-dependencies';
*/
const { UP, DOWN } = keycodes;

class CodeEditor extends Component {
export class CodeEditor extends Component {
constructor() {
super( ...arguments );

Expand Down Expand Up @@ -108,14 +108,22 @@ class CodeEditor extends Component {
}

export default withLazyDependencies( {
scripts: [
'wp-codemirror',
'code-editor',
'htmlhint',
'csslint',
'jshint',
// TODO: Gotta check if user can unfiltered_html
...( true ? [ 'htmlhint-kses' ] : [] ),
],
scripts() {
const scripts = [
'wp-codemirror',
'code-editor',
'htmlhint',
'csslint',
'jshint',
];

// Don't load htmlhint-kses unless we need it
if ( window._wpGutenbergCodeEditorSettings.htmlhint.kses ) {
scripts.push( 'htmlhint-kses' );
}

return scripts;
},

styles: [ 'wp-codemirror', 'code-editor' ],
} )( CodeEditor );
2 changes: 1 addition & 1 deletion components/code-editor/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { set, noop } from 'lodash';
/**
* Internal dependencies
*/
import CodeEditor from '../';
import { CodeEditor } from '../';

describe( 'CodeEditor', () => {
it( 'should render without an error', () => {
Expand Down
8 changes: 8 additions & 0 deletions components/higher-order/with-lazy-dependencies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ function loadStyle( url ) {
}

function loadDependencies( scripts, styles ) {
if ( typeof scripts === 'function' ) {
scripts = scripts();
}

if ( typeof styles === 'function' ) {
styles = styles();
}

const promises = [];

if ( scripts && scripts.length > 0 ) {
Expand Down

0 comments on commit 87714ec

Please sign in to comment.