Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@
"author": "Automattic",
"license": "GPL-2.0-or-later",
"devDependencies": {
"@babel/core": "^7.21.0",
"@babel/core": "^7.21.3",
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@types/eslint": "^8.21.1",
"@wordpress/babel-preset-default": "^7.12.0",
"@wordpress/prettier-config": "^2.11.0",
"@wordpress/scripts": "^25.5.1",
"@types/eslint": "^8.21.3",
"@wordpress/babel-preset-default": "^7.13.0",
"@wordpress/prettier-config": "^2.12.0",
"@wordpress/scripts": "^26.0.0",
"babel-plugin-emotion": "^11.0.0",
"babel-plugin-inline-json-import": "^0.3.2",
"eslint": "^8.35.0",
"eslint": "^8.36.0",
"eslint-config-wpcalypso": "^6.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-wpcalypso": "^7.0.0",
"onchange": "^7.1.0",
"precss": "^4.0.0",
"release-it": "^15.8.0",
"release-it": "^15.9.3",
"remove-files-webpack-plugin": "^1.5.0"
},
"dependencies": {
Expand Down
24 changes: 17 additions & 7 deletions src/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function setLoaded( container ) {
}

function createContainer( textarea, existingContainer ) {
if ( existingContainer && !existingContainer.contains( textarea ) ) {
if ( existingContainer && ! existingContainer.contains( textarea ) ) {
return existingContainer;
}

Expand All @@ -47,20 +47,25 @@ function createContainer( textarea, existingContainer ) {
return container;
}

function createEditorContainer( container, textarea, settings ) {
function createEditorContainer( container, textarea, settings, form ) {
if ( settings?.editor?.hasUploadPermissions ) {
// Connect the media uploader if it's enabled
settings.editor.mediaUpload = mediaUpload;
addFilter( 'editor.MediaUpload', 'blocks-everywhere/media-upload', () => MediaUpload );
} else {
settings.editor.mediaUpload = ( { onError } ) => {
onError( __( 'File uploading is disabled. Please use an image block and an external image URL.', 'blocks-everywhere' ) );
onError(
__(
'File uploading is disabled. Please use an image block and an external image URL.',
'blocks-everywhere'
)
);
};
}

render(
<IsolatedBlockEditor
settings={ settings }
settings={ { ...settings, editor: { ...settings.editor, currentEditor: { container, form } } } }
onSaveContent={ ( content ) => saveBlocks( textarea, content ) }
onLoad={ ( parser ) => ( textarea && textarea.nodeName === 'TEXTAREA' ? parser( textarea.value ) : [] ) }
onError={ () => document.location.reload() }
Expand All @@ -85,7 +90,11 @@ function insulateForm( container ) {
ev.preventDefault();
}
} );

return form;
}

return null;
}

export default function createEditor( node ) {
Expand All @@ -99,6 +108,7 @@ export default function createEditor( node ) {
container = createContainer( node, document.querySelector( wpBlocksEverywhere.container ) );
}

insulateForm( container );
createEditorContainer( container, node, wpBlocksEverywhere );
}
const form = insulateForm( container );

createEditorContainer( container, node, wpBlocksEverywhere, form );
}
Loading