F
Filamentβ€’15mo ago
Faab007NL

Filament GrapesJS - Plugin Development

Getting help with plugin development
59 Replies
Patrick Boivin
Patrick Boivinβ€’15mo ago
Hey @faab007nl
Faab007NL
Faab007NLOPβ€’15mo ago
GitHub
GitHub - faab007nl/filament-grapesjs
Contribute to faab007nl/filament-grapesjs development by creating an account on GitHub.
Faab007NL
Faab007NLOPβ€’15mo ago
Hay @Patrick Boivin I already made 2 function that can load and store the data from grapejs this.editor.on('load', async function (e) { and this.editor.on('storage:store', async function(e) {
Patrick Boivin
Patrick Boivinβ€’15mo ago
Ok cool, so on('load') loads the field data into Grapes, and the other one should put it back into the form field?
Faab007NL
Faab007NLOPβ€’15mo ago
Yea on('load') is called when grape loads and then await storageManager.store(newData); sets the data. and on('storage:store' sis called when the save btn is pressed (or also when autosaving think. Not tested that yet). When i get the editor data that is used in await storageManager.store(newData); and the html code that is used on the page itself.
Patrick Boivin
Patrick Boivinβ€’15mo ago
Ok, what is the "save" button in this case? (I don't really know how Grapes work)
Faab007NL
Faab007NLOPβ€’15mo ago
Look for className: 'fa fa-save', Or i just send a screen πŸ™‚
Faab007NL
Faab007NLOPβ€’15mo ago
And will probalby move the Toastifty to the actual upload function when thats done. For a more correct error / success msg.
Patrick Boivin
Patrick Boivinβ€’15mo ago
Ah ok, so this is a "save" button related to Grapes. Does it also save the Filament Form when you click it?
Faab007NL
Faab007NLOPβ€’15mo ago
Yes. It does not. The page should not reload or something.
Patrick Boivin
Patrick Boivinβ€’15mo ago
When you click this button, what happens? Do you exit Grapes or just stay in the editor? Oh I see, it's up to you, right? It will fire the storage:store event?
Faab007NL
Faab007NLOPβ€’15mo ago
Clicking the save btn will store to local storage using code from grape (still need to find a solution to that so it does not do that) And it will fire the storage:store event Normally you would have a load and store url/endpoint in grape but I don't wanna use that. And I couldn't get a custom storage working. So I decided to use localstorage and just overwrite the data on load.
Patrick Boivin
Patrick Boivinβ€’15mo ago
Hum, ok. I think the local storage can be a problem for later, not too important at this point.
Faab007NL
Faab007NLOPβ€’15mo ago
Yea thought that too. Ofcourse wanna do it the right way. Also tried setting storage type to none but that does not trigger the event
Patrick Boivin
Patrick Boivinβ€’15mo ago
Ok, so I think as a first step, I would probably try to get the data stored in the DB. So you start with an empty Grapes editor, add some block to it, click Save, and then you should have something stored somewhere in the DB. Does that sound right?
Faab007NL
Faab007NLOPβ€’15mo ago
Yea
Patrick Boivin
Patrick Boivinβ€’15mo ago
What tool do you use to inspect your DB. Do you have something like TablePlus?
Faab007NL
Faab007NLOPβ€’15mo ago
Heidi
Patrick Boivin
Patrick Boivinβ€’15mo ago
Ok perfect So what's your next step?
Faab007NL
Faab007NLOPβ€’15mo ago
Get the data to php How do i do that?
Patrick Boivin
Patrick Boivinβ€’15mo ago
I'm looking at grapesjs.blade.php and I see state: $wire.entangle('{{ $getStatePath() }}').defer, did you set this up?
Faab007NL
Faab007NLOPβ€’15mo ago
Yea copied from other plugin
Patrick Boivin
Patrick Boivinβ€’15mo ago
This is basically what you need... when you write to this.state in Alpine, this should keep the value in sync on the Livewire side. That's what entangle does.
Faab007NL
Faab007NLOPβ€’15mo ago
self.state is undefined
Patrick Boivin
Patrick Boivinβ€’15mo ago
Should be defined... that's the next thing to debug
Faab007NL
Faab007NLOPβ€’15mo ago
And i also think storage:store is called by await storageManager.store(newData); So also need to fix that. Maybe put a timeout on the save code.
Patrick Boivin
Patrick Boivinβ€’15mo ago
Sometimes you need timeouts but I think you should see if you can get it to work without. At first.
Faab007NL
Faab007NLOPβ€’15mo ago
Yea Oke added timeout for now. How do i debug the self.state? this.state is also undefined Do you have a good example that i can use?
Patrick Boivin
Patrick Boivinβ€’15mo ago
One plugin I've studied that really helped me is this one: https://github.com/awcodes/filament-tiptap-editor
GitHub
GitHub - awcodes/filament-tiptap-editor: A Rich Text Editor plugin ...
A Rich Text Editor plugin for Filament Forms. Contribute to awcodes/filament-tiptap-editor development by creating an account on GitHub.
Patrick Boivin
Patrick Boivinβ€’15mo ago
It's a big-ish plugin, so not really simple, but it's a good example of how to integrate a custom field with a complex JS library.
Faab007NL
Faab007NLOPβ€’15mo ago
Do i need to wrap the html in a x-dynamic-component element?
Patrick Boivin
Patrick Boivinβ€’15mo ago
No, I don't think you need that
Faab007NL
Faab007NLOPβ€’15mo ago
export default function tiptap({? https://cloud.faab007.nl/s/3HNXG3cQQpikRi9/preview
Faab007NL
Faab007NLOPβ€’15mo ago
Thats not Alpine.data('grapesjs' Are you available for vc?
Patrick Boivin
Patrick Boivinβ€’15mo ago
Sorry, not possible for me
Faab007NL
Faab007NLOPβ€’15mo ago
Do you know someone else who might?
Patrick Boivin
Patrick Boivinβ€’15mo ago
Not sure, maybe @Leandro Ferreira would be available for consulting.
LeandroFerreira
LeandroFerreiraβ€’15mo ago
Hey, thank you for tagging me, but I'm a bit busy these days and unavailable at the moment. Maybe next month. Thanks
awcodes
awcodesβ€’15mo ago
This is an alpine component. It’s bundled with esbuild to turn it into a module that can be used to load it with async alpine when the field is rendered on the page. You can find more info about that on https://filamentphp.com/docs/3.x/support/assets#asynchronous-alpinejs-components
Faab007NL
Faab007NLOPβ€’15mo ago
I created the component but i get an error> Alpine component with ID [filament-grapesjs-component] not found for package [app]. I followed the steps in that page. (Pushed to GH) @awcodes Are you able to help me in vc?
awcodes
awcodesβ€’15mo ago
i don't have time to VC sorry
Faab007NL
Faab007NLOPβ€’15mo ago
Does someone have time to help me?
wyChoong
wyChoongβ€’15mo ago
Build the assets and publish it artisan filament:assets
Faab007NL
Faab007NLOPβ€’15mo ago
Already did that. Doesn't work
awcodes
awcodesβ€’15mo ago
Looking at your repo, you’re not building the alpine component in a way that makes it a module. Nor are you registering it in Filament as an async alpine component. Start by following the documentation that I linked to at least get your alpine component working.
Faab007NL
Faab007NLOPβ€’15mo ago
I didn't push to gh yet. But I did follow the steps from the docs u send. I'll push later. Then u can see the changes
wyChoong
wyChoongβ€’15mo ago
is your alpine component works already? if its not its best you develop it in line with x-data before you move into a .js file which you need to build and publish
Faab007NL
Faab007NLOPβ€’15mo ago
Pushed
awcodes
awcodesβ€’15mo ago
ax-load-src="{{ \Filament\Support\Facades\FilamentAsset::getAlpineComponentSrc('filament-grapesjs-component', 'ekremogul/filament-grapesjs') }}" you're not including the plugin namespace when you load the script with ax-load-src
Faab007NL
Faab007NLOPβ€’15mo ago
Will try that later today
Faab007NL
Faab007NLOPβ€’15mo ago
Fixed that issue. Thx. Now got this. https://cloud.faab007.nl/s/kbqX7kZ5tKR83Bp/preview
toeknee
toekneeβ€’15mo ago
That's because you are passing in a closure but trying to render it as a string
Faab007NL
Faab007NLOPβ€’15mo ago
Oke. But the code is from the docs. . So did i do something wrong somewhere else?
wyChoong
wyChoongβ€’15mo ago
I would recommend you to dig around Filament's view files especially those components integrating with js libs, like select/choicejs, fileupload/filepond, to understand how it works its very hard for others to help you on what you don't understand
Faab007NL
Faab007NLOPβ€’15mo ago
Already looked at another plugin (https://github.com/awcodes/filament-tiptap-editor). It helped a little bit. But not enough
awcodes
awcodesβ€’15mo ago
try $getStatePath() instead of $statepath in your entangle also, when you copy paste stuff, don't do it blindly, understand what it is doing. πŸ™‚
Faab007NL
Faab007NLOPβ€’15mo ago
That works. Wdym i like copy pasting stuff. πŸ™‚ It loads without errors now. But this.state is still null
Want results from more Discord servers?
Add your server