GithubHelp home page GithubHelp logo

advoor / nova-editor-js Goto Github PK

View Code? Open in Web Editor NEW
91.0 7.0 52.0 880 KB

Editor JS field for Laravel Nova

Vue 4.24% JavaScript 12.92% PHP 73.14% HTML 1.76% Blade 3.30% CSS 4.65%
laravel laravel-nova-field laravel-nova

nova-editor-js's Introduction

Laravel Nova Editor JS Field

Latest Version on Github Total Downloads

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.

Package version Nova Version Laravel Version PHP version
4.x 4.x 10.x - 11.x 8.2+
3.x 4.x 8.x - 10.x 8.1+
2.x 2.x - 3.x 5.x - 8.x 5.6 - 7.4

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 editor
  • defaultBlock (docs) - The block that's used by default
  • autofocus (docs) - If the editor should auto-focus, only use if you never have multiple editors on a page and after considering the accessibility implications
  • rtl (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.

nova-editor-js's People

Contributors

advoor avatar anstap avatar bangnokia avatar harrk avatar lorado avatar pravk avatar reflow1319 avatar roelofr avatar rogierw avatar stickeerehan avatar techouse avatar thedeadcode avatar waelelsawy avatar woeler avatar xamthor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nova-editor-js's Issues

Laravel 11 Support

Is this package still maintained? Would it be possible to update in order to support Laravel 11?

 advoor/nova-editor-js dev-fix/read-header-tool-config requires illuminate/support ^8.0 || ^9.0 || ^10.0 -> satisfiable by illuminate/support[v8.0.0, ..., v8.83.27, v9.0.0, ..., v9.52.16, v10.0.0, ..., v10.48.4]

Error when saving the same content

@roelofr this might be related to this issue because it's trying to save [object Object] again.

What's happening is that when I have an empty EditorJS field in Nova and type some content and save it, everything works fine.

If I then edit the resource and hit save but don't edit the content, I get:

3140 Invalid JSON text: "Invalid value." at position 1 in value for column 'post.body'. (SQL: update `posts` set `body` = [object Object], ...)

If I change the EditorJS content and save it (even if it's just adding a dot), then it does actually works.

Laravel Vapor plans

I'm using this package in a Laravel application that I want to run on Laravel Vapor. Does this package support Vapor, or are there plans to support it?

Thanks for the great package!

Editor.js padding bottom

Great package & thank you. There is some styling issue with this editor:

image - gigantic padding bottom

It is possible, to fix this issue by setting global nova style to:

.codex-editor__redactor { padding-bottom: 30px !important; }

But this solution looks like a hack. There is more native solution here: codex-team/editor.js#724 but I don't know how to set config options in your package. It would be great if you could somehow implement this functionality.

Json Error when trying to use

I just added the package and initialised the field on my resource, however, i seem to be unable to use it. Not sure where to start looking for this problem.

SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse ()
at p.setInitialValue (nova-editor-js:1)
at p.mounted (nova-editor-js:1)
at Pt (vendor.js?id=65e95ff86f8b1a7dffe7:1)
at en (vendor.js?id=65e95ff86f8b1a7dffe7:1)
at Object.insert (vendor.js?id=65e95ff86f8b1a7dffe7:1)
at y (vendor.js?id=65e95ff86f8b1a7dffe7:1)
at p.patch (vendor.js?id=65e95ff86f8b1a7dffe7:1)
at p.t._update (vendor.js?id=65e95ff86f8b1a7dffe7:1)
at p.ln.before (vendor.js?id=65e95ff86f8b1a7dffe7:1)

Remove image when delete block

Hello, first, thank you for this amazing tool.

Image upload is working fine, but will be great to remove the image if a Image block is deleted.

A way to customize the storage disk will be useful also.

Thanks!

Something went wrong: Field `blocks` is missing

@roelofr thanks for the previous fixes with the attribute casting. After the upgrade however (I'm using the casting now), this is what's happening:

  • If I save in Nova, the editor in Nova stays blank as in it doesn't show the just saved content in the editor
  • The data is correctly saved however, because I can see it in the database
  • If I try to display the data in a view using {{ $post->body }} I get Something went wrong: Field blocks is missing while the database data I can clearly see the blocks in the stored data.

Make it translatable ?

Is this package works with Spatie Translatable ?

I was able to use it but as we store the json into another json, it's seem not to display the content on the nova index or show page. I can make some content and edit it but this is what I get when I try to see it in nova:

"Something went wrong: Field blocks is missing"

Any solution or fix ? Thx

Update spatie/image

Hey, thanks for updating the package to support nova 4 👏

Sadly I still can't use it in one of my projects, as it uses the newest spatie/image version..

Screenshot 2022-07-03 at 09 52 00

It would've been really nice if you could update the composer.json in order to fix that

Compatibility issue with Laravel 10

I'm updating my laravel 9 project to use Laravel 10, but I'm encountering an error related to compatibility. I believe there is a conflict between the requirements of package and Laravel 10. Can you please help me resolve this issue?

{
    "require": {
        "php": "^8.1.0",
        "advoor/nova-editor-js": "^3.0",
        "laravel/framework": "^10.0"
    }
}
Problem 1
    - Conclusion: don't install advoor/nova-editor-js v3.0.1 (conflict analysis result)
    - Conclusion: don't install advoor/nova-editor-js v3.0.5 (conflict analysis result)
    - Conclusion: don't install advoor/nova-editor-js v3.1.0 (conflict analysis result)
    - illuminate/support[v8.0.0, ..., v8.11.2] require php ^7.3 -> your php version (8.2.2) does not satisfy that requirement.
    - Root composer.json requires advoor/nova-editor-js ^3.0 -> satisfiable by advoor/nova-editor-js[v3.0.0, ..., v3.1.0].
    - Conclusion: don't install laravel/framework v10.0.1 (conflict analysis result)
    - Conclusion: don't install laravel/framework v10.0.2 (conflict analysis result)
    - Conclusion: don't install laravel/framework v10.0.3 (conflict analysis result)
    - Conclusion: don't install laravel/framework v10.0.0 (conflict analysis result)
    - advoor/nova-editor-js v3.0.0 requires illuminate/support ^8.0 || ^9.0 -> satisfiable by illuminate/support[v8.0.0, ..., 8.x-dev, v9.0.0-beta.1, ..., 9.x-dev].
    - Only one of these can be installed: illuminate/support[v5.0.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev, v9.0.0-beta.1, ..., 9.x-dev, v10.0.0, ..., 10.x-dev], laravel/framework[v10.0.0, ..., 10.x-dev]. laravel/framework replaces illuminate/support and thus cannot coexist with it.
    - Root composer.json requires laravel/framework ^10.0 -> satisfiable by laravel/framework[v10.0.0, ..., 10.x-dev].

Converting Header to Paragraph

Hi,

It looks like I'm able to convert Paragraph to Header, but not Header to Paragraph.

From the source code of header it looks like it should be possible:

Screen Shot 2021-07-01 at 17 54 40

Am I missing some configuration?

foreach() argument error

I'm getting foreach() argument must be of type array|object, string given when saving the Nova resource with the EditorJS field.

Happens on line 25 of NovaEditorJsData:

foreach ($attributes as $key => $value) {
  $this->attributes[$key] = $value;
}

Not sure if it's related but I'm using the NovaEditorJsCast on the model.

empty text field on DB

I have noticed that my db fields must contain an empty object "{}" in order for this to work.

So adding something like this:
NovaEditorJs::make('my_wonderful_content')

Where 'my_wonderful_conten' is an empty TEXT field on the DB

results in a console error:
Unexpected end of JSON input

Forked

@advoor I forked you here:
https://github.com/alloyking/nova-editor-js.

I don't actually know how pull requests work, nor if you even want changes I make.
But if you do I'm happy to help in anyway. My goal isn't to take over what you have here which I think is useful.

I made two hurried changes:

  1. Modified the css to make the editor field look more like the existing fields
  2. Handled the JSON parse error that shows in the console.

Thanks,
Alloyking

spatie/image ^3.0 Compatible

advoor/nova-editor-js v3.3.0 requires spatie/image ^1.7 || ^2.0 -> found spatie/image[1.7.0, ..., 1.11.0, 2.0.0, ..., 2.2.7] but the package is fixed to 3.3.4 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command

Add support for Block Tunes API?

Currently Block Tunes are not available when rendering content.

Tunes are stored separate to a block's data. Here's an example for an image with a tune called "blockWidthTune":

{
  "id":"4njDtOcDe2",
  "type":"image",
  "data":{
    "file":{
      "url":"/storage/images/tTVQFcY2KCNDXWHvKRX8VjdkOifWJK6aDdKQpqk8.jpg",
      "thumbnails": ["/storage/images/tTVQFcY2KCNDXWHvKRX8VjdkOifWJK6aDdKQpqk8_small.jpg"]
    },
    "caption":""
  },
  "tunes":{
    "blockWidthTune":"wide"
  }
}

In NovaEditorJsConverter.php, only the block data key gets passed to the view, e.g.

$this->addRender(
  "list",
  fn($block) => view("nova-editor-js::list", $block["data"])->render()
);

We cannot change to passing the data and tunes separately like ['data' => $block['data'], 'tunes' => $block['tunes']] without rewriting all the block views, so perhaps the best way to pass the tunes would be to merge them with the block data, like so:

$this->addRender(
    "list",
    fn($block) => view(
        "nova-editor-js::list",
        array_merge($block["data"], ["tunes" => $block["tunes"] ?? []])
    )->render()
);

To prevent collision with an existing data key with the name 'tunes', the key could perhaps be changed to "_tunes".

Happy to open a PR but wanted to seek input first!

Resize uploaded images

Hi, as I already mentioned - great work, thanks for the library!

I thought about possible improvements. Would it be possible to add support for spatie medialibrary? Resize/Multiple sizes of images would become so easy.

Alternatively some resize params would be nice, like in advanced image field

What do yo think?

Throw events when an image has been uploaded

Hello,

I currently have an app where the uploaded images need to be converted to the webp format. Currently I do this by observing my model, looping over the editor blocks and sending out jobs to convert the images from the block data. However, it would be nice if this package could thrown an event whenever an image has been successfully uploaded.

What do you think about this idea? I can implement it I think. Just wanted to get an opinion of the maintainer(s) first before I sink some time in it.

It would definitely make our codebase cleaner, and I'm sure other people can find a use for the events if they need to do some extra post-processing with images.

Cheers.

Border top when Editor is first element in panel

Hello, I have an issue with this Field on Details page. When other Fields are first in the Panel they don't have border-t and other border-related classes:

image

image

However when Nova JS Editor is the first element in the Panel it has this top border:

image

image

I found that those classes are added by Nova itself, but I cannot find why it is applied to Editor field.

generateHtmlOutput Renders encoded HTML entities

When using \Advoor\NovaEditorJs\NovaEditorJs::generateHtmlOutput it automatically encodes html entities in the returned HtmlString object returned:

image

Then when using blade to output this string it shows as html tags which is not what we want:

image

I had to use this work around to make it work:

{!! html_entity_decode(\Advoor\NovaEditorJs\NovaEditorJs::generateHtmlOutput($content->body_default)) !!}

This does not work also:

{{ \Advoor\NovaEditorJs\NovaEditorJs::generateHtmlOutput($content->body_default) }}

anchors not rendering

I'm using the NovaEditorJsCast on my modal. Everything is rendering as expected, except for anchor tags (<a href="..."></a>), those are displayed as plain text. Anything I'm missing? I'm using the regular {{ $post->body }} in my blade view.

SyntaxError: Unexpected token < in JSON at position 0

Hi, I receive the below error when using this on a resource. I've added:

protected $casts = [
    'content' => 'json'
];

to my model. But I still get this error. My database column type for 'content' is TEXT and not JSON as the server doesn't support JSON but that shouldn't make a difference as I'm using the casts property.

Any ideas?

The top level frontend message on the resource is:

Something went wrong: Wrong JSON format: Syntax error


SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse ()
at p.setInitialValue (nova-editor-js:1)
at p.mounted (nova-editor-js:1)
at Pt (vendor.js?id=abad729d86d183328118:1)
at en (vendor.js?id=abad729d86d183328118:1)
at Object.insert (vendor.js?id=abad729d86d183328118:1)
at y (vendor.js?id=abad729d86d183328118:1)
at p.patch (vendor.js?id=abad729d86d183328118:1)
at p.t._update (vendor.js?id=abad729d86d183328118:1)
at p.ln.before (vendor.js?id=abad729d86d183328118:1)

Can't extend the Editorjs

I've followed every step of the documentation under https://github.com/advoor/nova-editor-js#extending

But the plugin is still not appearing. I think the reason is because the javascript is rendered after the main editor-js scripts.

Here's the HTML part where the scripts are loaded.

<script>
   window.config = {...}
</script>

<!-- Scripts -->
<script src="/vendor/nova/manifest.js?id=2d315777967b6001bcf1"></script>
<script src="/vendor/nova/vendor.js?id=e2c07eb6c9b9faf610fc"></script>
<script src="/vendor/nova/app.js?id=1c7abbbe8cf05b9e2ece"></script>

<!-- Build Nova Instance -->
<script>
   window.Nova = new CreateNova(config)
</script>

<!-- Tool Scripts -->
<script src="/nova-api/scripts/nova-editor-js"></script>
<script src="/nova-api/scripts/editor-js-quote"></script>

<!-- Start Nova -->
<script>
   Nova.liftOff()
</script>

Not working with s3 disk

@advoor we are trying to implement this package in our nova dashboard. It works fine with local disk, but on s3 disk, it gives 500 error on image upload, and in network tab error is as follows on /nova-vendor/editor-js-field/upload/file call :

image

Extend in Vite

Referencing to EXTENDING.md

There is mentioned about webpack.mix.js, but Laravel is not delivered with Vite by default. So maybe it needs an update? 🤔

editor configuration

how can the editor object can be configured?
for example i want to change the placeholder ("tell your story") to another value

thanks,
nils

generateHtmlOutput breaks when sending pre-decoded data

I've made a model to work with the new editor, and since it needs array data, I've added the content property to the casts list in the model.

It looks something like this:

<?php

namespace App\Models;

use Advoor\NovaEditorJs\NovaEditorJs;
use Illuminate\Database\Eloquent\Model;

/**
 * A page
 */
class Page extends Model
{
    /**
     * @inheritDoc
     */
    protected $casts = [
        'content' => 'json',
    ];

    /**
     * Returns content HTML
     *
     * @return string|null
     */
    public function getContentHtmlAttribute(): ?string
    {
        return $this->content ? NovaEditorJs::generateHtmlOutput($this->content) : null;
    }
}

Problem is, when using this code, the NovaEditorJs::generateHtmlOutput will recieve an array, instead of a string (which the phpdocs aren't clear about).

Atribute casting

Hey guys,

Can't have the field with the content castable to array so it's sent to frontend as array, because nova field json.parse fails...

RTL Support

how we can have RTL support for this package?

i18n setting

Hello!
Is it possible to apply localization settings?
Editor js support i18n message on config file. Can i do it in nova-editor-js?

Nullable columns issue

When I make a nullable column, and don't change any content in NovaEditorJs field, it sends null to the backend, what is the behaviour I expect.

The problem is, when generateHtmlOutput() is used, it returns following error: "Something went wrong: JSON is empty". And it is pretty weird, when I don't enter any content, but on entity preview I such an error. It just feels broken.

So my suggestions are:

  • Either change generateHtmlOutput() method, and simply return empty string, if given value is null
  • OR change Fiel behaviour, so that already on initialisation value gets evaluated and generated as JSON. Output JSON will simply contain empty blocks array, something like this: {"time":1558480815671,"blocks":[],"version":"2.12.4"}

What do you think?

Error in nova 4 when attaching links that have image.

When attaching a link and viewing it I receive this error.

Something went wrong: Found extra param `imageUrl`

This seems to be a regression in #70 where the structure of the link json was changed, but the config validation was not updated to match, nor was the link.blade.php renderer.

<div class="editor-js-block">
    <div class="editor-js-link">
        <a href="{{ $link }}" class="editor-js-link-content">
            @if (!empty($meta['image']['url']))
                <div class="editor-js-link-image" style="background-image: url('{{ $meta['image']['url'] }}');"></div>
            @endif

            <h4>{{ $meta['title'] }}</h4>
            <p>
                {{ $meta['description'] }}
            </p>
            <p>
                <small>{{ $link }}</small>
            </p>
        </a>
    </div>
</div>

Edit header toolSettings levels

Hello,

Is it possible to edit the header tool levels ?
I want to disable H1 and I tried this but it's stil allowing H1 when editing :

'toolSettings' => [
        'header' => [
            'activated' => true,
            'placeholder' => 'Header',
	    'defaultLevel'=> 3,
	    'levels'=> [2, 3, 4, 5],
            'shortcut' => 'CMD+SHIFT+H'
        ],
        ...

Links in a list are not parsed

Hey,
I have a unsorted list with text on each line, all beginning with a link at the first word. But the links aren't parsed when generating HtmlOutput.. Also not in the show-modus in Nova.

Embed block doesn't show

In a vanilla installation the embed block does not show up in the drop down list, even though it's enabled in the config file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.