-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom blocks #33
Custom blocks #33
Conversation
I'd really like some feedback on people who use this and want to add custom blocks. Does this seem like a good method to do this, or would you rather have a different solution? |
Nice work with this. I made progress without any tremendous effort at all. You have a call to default:
$htmlOutput .= view("nova-editor-js::{$block['type']}", $block['data'])->render(); The nova-editor-js views are already publishable, so adding extra ones for any additional plugins that are written or installed is no big ask. I chucked a basic quote template in that looked like this: <div class="editor-js-block">
<blockquote class="text-{{ $alignment }}">
{{ $text }}
</blockquote>
@if (!empty($caption))
<caption>{{ $caption }}</caption>
@endif
</div> The js I needed to be able to install the Quote plugin was pretty much as per your description: const Quote = require('@editorjs/quote');
if (!window.novaEditorjsFields) {
window.novaEditorjsFields = {}
}
if (!window.novaEditorjsFields.tools) {
window.novaEditorjsFields.tools = []
}
window.novaEditorjsFields.tools.push(tools => {
tools.quote = Quote
return tools
}) Plus the config it requires: 'quote' => [
'text' => [
'type' => 'string',
],
'caption' => [
'type' => 'string',
'required' => false,
],
'alignment' => [
'type' => 'string',
],
], You didn't provide an explanation for where I should be providing this JS... I stuffed it in this way in NovaServiceProvider, and added a new js output file into my webpack config, meh, works: Nova::$scripts['nova-custom-js'] = public_path('/js/nova.js'); I might be nova-noobing with the above js injection approach, tips appreciated if there's an easy way to improve on this. In terms of improving the experience for other NovaEditorJs users who want to add custom blocks, in lieu of any better ideas, I'd wrap up the const NovaEditor = require('nova-editor-js');
const Quote = require('@editorjs/quote');
NovaEditor.register(Quote); Alternatively, write something that scaffolds that js from php, so we don't have to touch it at all (perhaps that's hard, where would the plugin come from) – either way I'd say this is sufficiently usable. |
This solution might work, but the code that @TheDeadCode made is a lot cleaner and I'd recommend using that. Closing this. |
Added support for custom blocks, via pluggable methods.
Closes #19.
How to use
Usage is split two-way: showing the block and rendering the HTML.
To show the block
window.novaEditorjsFields.tools
To render the HTML
nova-editorjs-php.php
config. See editorjs-php.NovaEditorJs
Example
We want to register the
SimpleImage
block from the The firt plugin tutorial.To do