定制 marshmallow/nova-tinymce 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

marshmallow/nova-tinymce

Composer 安装命令:

composer require marshmallow/nova-tinymce

包简介

This Nova package allow you to use TinyMCE editor for text areas.You can customize the editor options and... you can upload images to your server and put them rigth there on the text without leaving the text editor!

README 文档

README

alt text

Laravel Nova TinyMCE editor

Latest Version on Packagist Total Downloads

This Nova package allows you to use the TinyMCE editor for text areas. You can fully customize the editor options, define reusable styling, add custom buttons and variables, and optionally upload images straight into the editor.

Screenshot

Requirements

  • PHP ^8.0
  • Laravel Nova ^4.0 or ^5.0

Installation

Install the package via Composer:

composer require marshmallow/nova-tinymce

Publish the TinyMCE JavaScript, CSS, and skin assets to your public directory:

php artisan vendor:publish --provider="Marshmallow\Nova\TinyMCE\FieldServiceProvider" --tag="resources"

This publishes the assets to public/vendor/tinymce. Republish them after every package update so the editor assets stay in sync.

Publish the config file (optional)

Publish the config to override any of the default TinyMCE settings:

php artisan vendor:publish --provider="Marshmallow\Nova\TinyMCE\FieldServiceProvider" --tag="config"

Usage

Add the TinyMCE field to the fields array of your Nova resource. The field is hidden on the index view by default.

use Marshmallow\Nova\TinyMCE\TinyMCE;

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),
        TinyMCE::make(__('Content'), 'content'),
    ];
}

Set the height

The default height is defined in the nova-tinymce.php config file. Override it per field with the height() method:

TinyMCE::make('body')->height(300),

Add custom HTML (buttons)

Insert buttons or custom HTML with a single click using the buttons() method. The array key is the button label, the value is the HTML that gets inserted:

TinyMCE::make('body')->buttons([
    'Name button' => 'value of HTML',
    'Name button2' => '<p>More HTML</p>',
]),

Add variables

Insert variables with a single click using the variables() method:

TinyMCE::make('body')->variables([
    'name_var' => 'value_var',
]),

Set the toolbar

Override the toolbar string for a single field with the toolbar() method:

TinyMCE::make('body')->toolbar('undo redo | bold italic | link'),

Set the plugins

Override the active TinyMCE plugins for a single field with the plugins() method:

TinyMCE::make('body')->plugins(['lists', 'link', 'image', 'table']),

Pass any TinyMCE option

Pass any option supported by the TinyMCE JavaScript SDK through the options() method. The given options are merged on top of the defaults:

TinyMCE::make('body')->options([
    'height' => '980',
]),

See the full list of options in the TinyMCE configuration docs.

Add styling options per field

Add one or more entries to the field's style format ("Content type") selector at runtime with addStyle() and addStyles():

TinyMCE::make('body')->addStyle([
    'title' => 'Lead Paragraph',
    'block' => 'p',
    'classes' => 'lead',
]),

TinyMCE::make('body')->addStyles([
    ['title' => 'Lead Paragraph', 'block' => 'p', 'classes' => 'lead'],
    ['title' => 'Muted', 'inline' => 'span', 'classes' => 'text-muted'],
]),

Add custom styling for all fields

To add styling options available on every TinyMCE field, publish the config and add entries to the custom_items array. These appear in the editor's "Content type" selector:

'custom_items' => [
    // This adds a .lead class on the paragraph tag.
    [
        'title' => 'Lead Paragraph',
        'block' => 'p',
        'classes' => 'lead',
    ],
],

File manager support

The package ships a use_lfm config option to integrate with a Laravel file manager (set use_lfm to true and configure lfm_url). After installing your file manager, run the bundled command to drop in the package's file manager view override:

php artisan nova-tinymce:support-lfm

Configuration

The published config/nova-tinymce.php file exposes the defaults that are applied to every field. The most common keys:

Key Default Description
custom_items one Lead Paragraph entry Styling items shown in the "Content type" selector for every field.
license_key 'gpl' TinyMCE license key. Use 'gpl' for the self-hosted GPL build.
cloud_api_key null TinyMCE Cloud API key, or null for self-hosted.
height 350 Default editor height in pixels.
content_css oxide + custom.css Stylesheet(s) loaded inside the editor content area.
skin_url oxide skin path Path to the editor UI skin.
content_css_dark oxide-dark content css Content stylesheet used in dark mode.
skin_url_dark oxide-dark skin path UI skin used in dark mode.
plugins array of TinyMCE plugins Plugins enabled on every field.
menubar 'file edit view insert format tools table' The editor menu bar.
toolbar toolbar string The editor toolbar layout.
relative_urls false Whether URLs are converted to relative paths.
use_lfm false Enable Laravel file manager integration.
lfm_url 'filemanager' URL of the file manager.
use_dark true Enable dark-mode skins.
browser_spellcheck false Use the browser's native spell checker.
link_class_list preset button classes Class options offered when inserting a link.
table_class_list Default Class options for tables.
image_class_list Default Class options for images.
color_map preset palette The editor color picker palette.
formats [] Custom TinyMCE formats definitions.
extra_options [] Any additional raw TinyMCE options merged into every field.

See config/nova-tinymce.php for the complete list of available keys.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security

If you discover any security related issues, please email stef@marshmallow.dev instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see the License File for more information.

marshmallow/nova-tinymce 适用场景与选型建议

marshmallow/nova-tinymce 是一款 基于 CSS 开发的 Composer 扩展包,目前已累计 21.95k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2020 年 05 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「editor」 「nova」 「laravel」 「tiny」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 marshmallow/nova-tinymce 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 marshmallow/nova-tinymce 我们能提供哪些服务?
定制开发 / 二次开发

基于 marshmallow/nova-tinymce 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 21.95k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 25
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 1
  • 开发语言: CSS

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-05