advoor / nova-editor-js

Editor JS field for Laravel Nova
92 stars 54 forks source link

Allow tools to be set per-field #81

Open johnpuddephatt opened 2 years ago

johnpuddephatt commented 2 years ago

This allows tool config to be set on an individual field, which is very useful when Editor.js is being used in multiple places within Nova and different tools are desired in each place.

roelofr commented 1 year ago

This seems like a good start, but the config you'd have to enter for your Nova fields gets enormous with it, as you'd have to repeat all fields' settings.

Maybe we could add a withTools(string[] $tools): self method, that uses Arr::only to slice out the tools that should be enabled from the global config.

This would mean you can define your per-tool settings in your config, and then per-field set which tools are available with their config-based settings.

Let me know what you think.

johnpuddephatt commented 1 year ago

The problem with the Arr::only approach is that while you can then choose which tools are enabled you can't have different tool configs on different fields (e.g. different fields might require different image sizes)

I agree the settings could/would be big, but couldn't this be easy to mitigate by the developer adding their tool config to the nova-editor-js config file? e.g. if I added:

"myCustomToolSettings" => [ .... ]

to config/nova-editor-js.php, I could then use the tools() method proposed in this PR like so:

->tools(config('nova-editor-js.myCustomToolSettings')

I could then reuse these configs. So I might have a "simple" config that just enables the headings plugin, and I might have an "advanced" config that enables everything. And my nova resource files stay nice and compact.

(Looking back on this I do think the method should probably be ->toolSettings() not ->tools() for consistency)