sckatik / moonshine-editorjs
MoonShine 的 EditorJs 块编辑器
1.0.2
2024-06-11 09:28 UTC
Requires
- php: ^8.2
- ext-curl: *
- ext-dom: *
- ext-fileinfo: *
- ext-json: *
- codex-team/editor.js: *
- guzzlehttp/guzzle: ^7.0
- illuminate/events: ^10.0 || ^11.0
- spatie/image: ^3.0
Requires (Dev)
- brianium/paratest: ^6.8
- mockery/mockery: ^1.4.4
- orchestra/testbench: ^4.0|^5.0|^6.0|^7.0|^8.0
- phpstan/phpstan: ^1.4.7
- phpunit/phpunit: ^9.5.8
Conflicts
- moonshine/moonshine: <1.52
README
演示
您可以在这里尝试演示
安装
通过 composer 安装
composer require sckatik/moonshine-editorjs
发布配置文件
php artisan vendor:publish --tag="moonshine-editorjs-config"
发布资源,确保不发布它们编辑器将无法工作
php artisan vendor:publish --tag="moonshine-editorjs-assets"
可选地,如果您想更改从编辑器Js输出的字段的外观,可以发布视图
php artisan vendor:publish --tag="moonshine-editorjs"
您还可以在 editorJs 中连接必要的组件或您自己的组件。
在视图字段/editorJs.blade.php中删除以下行
{{ Vite::useHotFile('vendor/moonshine-editorjs/moonshine-editorjs.hot')
->useBuildDirectory("vendor/moonshine-editorjs")
->withEntryPoints(['resources/css/field.css', 'resources/js/field.js']) }}
并将您的 js 与一组其组件 EditorJs 相连接
配置
您可以在配置文件 config/moonshine-editor-js.php 的配置块 - toolSettings 中禁用或启用编辑器中的必要块
在配置文件 config/moonshine-editor-js.php 的配置块 - renderSettings 中,您可以从 EditorJs 数据中自定义渲染规则
使用方法
将文本类型的字段添加到数据库中,以输出 EditorJs 的数据,请使用以下方法
use App\Models\Post; use Sckatik\MoonshineEditorJs\Facades\RenderEditorJs; $post = Post::find(1); echo RenderEditorJs::render($post->body);
定义访问器
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Sckatik\MoonshineEditorJs\Facades\RenderEditorJs; class Post extends Model { public function getBodyAttribute() { return RenderEditorJs::render($this->attributes['body']); } } $post = Post::find(1); echo $post->body;