sckatik/moonshine-editorjs

MoonShine 的 EditorJs 块编辑器

安装: 99

依赖: 0

建议: 0

安全: 0

星标: 5

关注者: 1

分支: 0

开放性问题: 0

语言:JavaScript

1.0.2 2024-06-11 09:28 UTC

This package is auto-updated.

Last update: 2024-09-11 09:58:45 UTC


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;