advoor / nova-editor-js
A Laravel Nova field bringing EditorJs magic to Nova.
Installs: 106 183
Dependents: 4
Suggesters: 0
Security: 0
Stars: 92
Watchers: 7
Forks: 53
Open Issues: 14
Requires
- php: ^8.2
- ext-exif: *
- ext-json: *
- codex-team/editor.js: *
- guzzlehttp/guzzle: ^7.0
- illuminate/events: ^10.0 || ^11.0
- illuminate/support: ^10.0 || ^11.0
- laravel/nova: ^4.0
- spatie/image: ^3.0
Requires (Dev)
- laravel/pint: ^1.15
- orchestra/testbench: ^8.0 || ^9.0
- php-parallel-lint/php-parallel-lint: ^1.3
- dev-master
- v4.0.0
- v3.3.0
- v3.2.1
- v3.2.0
- v3.1.0
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- 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-dependabot/npm_and_yarn/webpack-5.76.1
- dev-dependabot/composer/symfony/http-kernel-6.2.6
- dev-dependabot/npm_and_yarn/json5-1.0.2
- dev-dependabot/npm_and_yarn/loader-utils-1.4.2
- dev-image-service
- dev-feature/fix-unit-tests
- dev-feature/custom-blocks
This package is auto-updated.
Last update: 2024-12-22 10:34:47 UTC
README
A Laravel Nova implementation of Editor.js by @advoor.
Installation
Install via composer:
composer require advoor/nova-editor-js
Publish the config file
php artisan vendor:publish --provider="Advoor\NovaEditorJs\FieldServiceProvider"
Version Compatibility
Laravel Nova 4.x isn't backwards compatible with 3.x, so we had to make a version split. Please use the below table to find which versions are suitable for your installation.
Note that we really pushed the PHP version up. If you're staying on new versions of Laravel and Nova, we're expecting your PHP version to match that behaviour.
Upgrade
See the upgrade guide.
Usage
To add EditorJS to your application, you'll need to modify your Nova resource. For ease-of-use we also recommend to update your models, but that's optional.
Updating your Nova resource
This package exposes a NovaEditorJsField
that takes care of displaying the HTML contents
and providing the user with the EditorJS field.
To use it, simply import the field,
use Advoor\NovaEditorJs\NovaEditorJsField;
use it in your fields array,
return [ // … NovaEditorJsField::make('about'), ];
And boom, you've got yourself a fancy editor.
Updating your models (optional)
For ease-of-use, we recommend you add the NovaEditorJsCast
to the $casts
on your models.
This will map the value to a NovaEditorJsData
model, which can be returned in Blade (rendering HTML), or sent
via API calls (rendering JSON, unless you call toHtml
on it or cast it to a string).
use Advoor\NovaEditorJs\NovaEditorJsCast; class User extends Model { protected $casts = [ 'about' => NovaEditorJsCast::class, ]; }
Since the NovaEditorJsData
model is an Htmlable
, Blade will recognize it as
safe HTML. This means you don't have to use Blade "unescaped statements".
<article> <h1>About {{ $user->name }}</h1> {{ $user->about }} </article>
Rendering HTML without model changes
You can also use the NovaEditorJs
facade to render HTML from stored data.
NovaEditorJs::generateHtmlOutput($user->about);
The return value of generateHtmlOutput
is an HtmlString
, which is treated as
safe by Blade. This means you don't have to use Blade "unescaped statements".
<article> <h1>About {{ $user->name }}</h1> {{ NovaEditorJs::generateHtmlOutput($user->about) }} </article>
Customizing
You can configure the editor settings and what tools the Editor should use, by
updating the editorSettings
and toolSettings
property in the config file
respectively.
From the config, you can define the following editor settings:
placeholder
(docs) - The placeholder to show in an empty editordefaultBlock
(docs) - The block that's used by defaultautofocus
(docs) - If the editor should auto-focus, only use if you never have multiple editors on a page and after considering the accessibility implicationsrtl
(docs) - Set to true to enable right-to-left mode, for languages like Arabic and Hebrew
Furthermore, you can customize the tools the editor should use. The following tools are enabled by default:
You can customize the views for each component, by changing the view in resources/views/vendor/nova-editor-js/
.
† The Embeds tool is triggered by pasting URLs to embeddable content. It does not have an entry in the "Add" menu.
Registering custom components
Please refer to the extending Nova EditorJS guide on instructions on how to register custom components.