everzel / nova-editor-js
A Laravel Nova field bringing EditorJs magic to Nova.
Requires
- php: >=7.1.0
- ext-exif: *
- ext-json: *
- codex-team/editor.js: *
- laravel/nova: ^2.0 || ^3.0
- spatie/image: ^1.7
Requires (Dev)
- orchestra/testbench: ^3.8
- dev-master
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.0.1
- v1.0.0
- v0.6.6
- v0.6.5
- v0.6.4
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6
- v0.5.1
- v0.5.0
- v0.4.0
- v0.3.0
- v0.2.0
- 0.0.1
- dev-feature/fix-unit-tests
- dev-feature/custom-blocks
- dev-updates
- dev-link-fix
- dev-editor-configs
- dev-prevent-keyboard-conflicts
- dev-update-dependencies
- dev-spatie-image
This package is not auto-updated.
Last update: 2024-11-04 05:45:42 UTC
README
Installation
Install via composer:
composer require everzel/nova-editor-js
Publish the config file
php artisan vendor:publish --provider="Everzel\NovaEditorJs\FieldServiceProvider"
Upgrade
If upgrading from v0.4.0, re-publish the config file!
Usage:
Add this use
statement to the top of the your nova resource file:
use Everzel\NovaEditorJs\NovaEditorJs;
Use the field as below:
NovaEditorJs::make('FieldName');
And boom!
You can configure what tools the Editor should use in the config file along with some other settings so make sure to have a look :)
You can use the built in function to generate the response for the frontend:
NovaEditorJs::generateHtmlOutput($user->about);
Each 'block' has it's own view which can be overwritten in resources/views/vendor/nova-editor-js/
Tools included
- https://github.com/editor-js/header
- https://github.com/editor-js/image
- https://github.com/editor-js/code
- https://github.com/editor-js/link
- https://github.com/editor-js/list
- https://github.com/editor-js/inline-code
- https://github.com/editor-js/checklist
- https://github.com/editor-js/marker
- https://github.com/editor-js/embed
- https://github.com/editor-js/delimiter
- https://github.com/editor-js/table
- https://github.com/editor-js/raw
Extending
For the purpose of this section, we will use editor-js/warning
as an example of extensibility.
There are two steps to extending the editor. The first consists of creating a JavaScript file and passing it onto Nova.
The second step allows you to create a blade view file and pass it to the field to allow your block to render in the Nova show
page.
Creating the Javascript file
resources/js/editor-js-plugins/warning.js
/* * The editorConfig variable is used by you to add your tools, * or any additional configuration you might want to add to the editor. * * The fieldConfig variable is the VueJS field exposed to you. You may * fetch any value that is contained in your laravel config file from there. */ NovaEditorJS.booting(function (editorConfig, fieldConfig) { if (fieldConfig.toolSettings.warning.activated === true) { editorConfig.tools.warning = { class: require('@editorjs/warning'), shortcut: fieldConfig.toolSettings.warning.shortcut, config: { titlePlaceholder: fieldConfig.toolSettings.warning.titlePlaceholder, messagePlaceholder: fieldConfig.toolSettings.warning.messagePlaceholder, }, } } });
webpack.mix.js
const mix = require('laravel-mix'); mix.js('resources/js/editor-js-plugins/warning.js', 'public/js/editor-js-plugins/warning.js');
app/Providers/NovaServiceProvider.php
// ... public function boot() { parent::boot(); Nova::serving(function () { Nova::script('editor-js-warning', public_path('js/editor-js-plugins/warning.js')); }); } // ...
config/nova-editor-js.php
return [ // ... 'toolSettings' => [ 'warning' => [ 'activated' => true, 'titlePlaceholder' => 'Title', 'messagePlaceholder' => 'Message', 'shortcut' => 'CMD+SHIFT+L' ], ] // ... ];
Creating the blade view file
resources/views/editorjs/warning.blade.php
CSS classes taken from here.
<div class="editor-js-block"> <div class="cdx-warning"> <h3 class="cdx-warning__title">{{ $title }}</h3> <p class="cdx-warning__message">{{ $message }}</p> </div> </div>
app/Providers/NovaServiceProvider.php
use Everzel\NovaEditorJs\NovaEditorJs; // ... public function boot() { parent::boot(); NovaEditorJs::addRender('warning', function($block) { return view('editorjs.warning', $block['data'])->render(); }); // ... } // ...
That's it for extending the Nova EditorJS package!