joelwmale/livewire-quill

轻松将支持图片的 QuillJS 添加到任何 Laravel Livewire 组件中。

3.0.0 2024-09-03 07:55 UTC

README

Latest Version on Packagist GitHub Tests Action Status Total Downloads License

此包为您的应用程序添加了一个易于使用的 Livewire 组件,该组件会为您创建并主要管理 Quill 编辑器。

它支持图片上传,无需您做任何工作。

本包的 v2.0 版本仅支持 Livewire v3.x。如果您仍在使用 Livewire 2.x,请使用本包的 v1.0 版本。

安装

您可以通过 composer 安装此包

composer require joelwmale/livewire-quill

配置(可选)

安装完包后,您可以可选地发布配置以更改任何默认设置

php artisan vendor:publish --tag=livewire-quill:config

这是已发布配置文件的内容

return [
    /*
     * The base folder to store the images in
     */
    'storage_folder' => env('LIVEWIRE_QUILL_STORAGE_FOLDER', 'images'),

    /*
     * Should the images be stored publically or not
     */
    'store_publically' => env('LIVEWIRE_QUILL_STORE_PUBLICALLY', true),

    /*
     * Should the images be deleted from the server once deleted in the editor
     * or retained for future use (note: the package will never re-use the same image)
     */
    'clean_up_deleted_images' => env('LIVEWIRE_QUILL_CLEAN_UP_DELETED_IMAGES', true),
];

用法

在 Livewire 组件中这样使用它

@livewire('livewire-quill', [
    'quillId' => 'customQuillId',
    'data' => $content,
    'classes' => 'bg-white',
    'toolbar' => [
        [
            [
                'header' => [1, 2, 3, 4, 5, 6, false],
            ],
        ],
        ['bold', 'italic', 'underline'],
        [
            [
                'list' => 'ordered',
            ],
            [
                'list' => 'bullet',
            ],
        ],
        ['link'],
        ['image'],
    ],
])

在您的 Livewire 组件中,添加以下内容

use Joelwmale\LivewireQuill\Traits\HasQuillEditor;

class SomeLivewireComponent extends Component
{
    use HasQuillEditor;

    public function contentChanged($editorId, $content)
    {
        // $editorId is the id use when you initiated the livewire component
        // $content is the raw text editor content

        // save to the local variable...
        $this->content = $content;
    }
}

参数

QuillId

使用此 ID 创建一个 div,这允许在同一个页面上轻松使用多个 Quill 实例。

数据

这是文本编辑器的初始值(即:文本编辑器的先前保存版本)

您希望添加到基础编辑器类的任何自定义类。

注意:对于任何定制,我们建议使用 CSS 进行更改。您可以通过引用 #quillId 变量来编辑特定的 Quill 实例。

工具栏

一个数组,用于管理和创建 Quill 使用的工具栏

测试

composer test

致谢

许可

版权 © Joel Male

Livewire Quill 是开源软件,许可协议为 MIT 许可