awcodes / filament-tiptap-editor

A Rich Text Editor plugin for Filament Forms.
MIT License
290 stars 79 forks source link

feat: Add update-editor-content event handler #129

Closed pboivin closed 1 year ago

pboivin commented 1 year ago

I'm working on integrating Filament Tiptap Editor with the new Builder Preview feature of Peek.

I found a small issue when trying to manually update the Tiptap state path in my Page component. Here's a quick screen capture of the issue : https://github.com/awcodes/filament-tiptap-editor/assets/7805679/b6821860-bda3-4d6b-8c18-8313fa5f1c58

The state is correctly modified and saved but the UI does not reflect the changes.

This PR adds an event handler to force the Tiptap UI to refresh after updating the state path. Here's how I'm currently using it from a Page action :

    // ...

    $this->data[$fieldName] = $editorData[$fieldName];

    $this->dispatchBrowserEvent('update-editor-content', [
        'statePath' => "data.{$fieldName}",
        'content' => $editorData[$fieldName],
    ]);