The EditableMarkdown component has been updated to remove direct download functionality. Instead, it now emits a Livewire event when the content is saved, allowing other components to listen for this event and handle the save and download operations.
-
Removed download-related functionality from the
EditableMarkdowncomponent:- Removed properties:
$showDownloadModaland$downloadFilename - Removed methods:
toggleDownloadModal()anddownload() - Removed UI elements: Download buttons and the download modal
- Removed properties:
-
Added a Save button in display mode that calls the
save()method, which emits themarkdownSavedevent with the content.
If you're using the EditableMarkdown component within another Livewire component, you can listen for the save event like this:
<?php
namespace App\Livewire;
use Livewire\Component;
class ParentComponent extends Component
{
public function handleMarkdownSaved($content)
{
// Handle the saved markdown content
// For example, save it to a file or database
// To download the content as a file:
return response()->streamDownload(function () use ($content) {
echo $content;
}, 'markdown.md');
}
public function render()
{
return view('livewire.parent-component');
}
}In your Blade template:
<div>
<livewire:editable-markdown save-event="markdownSaved" />
<script>
document.addEventListener('livewire:initialized', () => {
@this.on('markdownSaved', (event) => {
// You can also handle the event in JavaScript
console.log('Markdown saved:', event.content);
});
});
</script>
</div>If you're using the EditableMarkdown component directly in a Blade view, you can listen for the event using Alpine.js:
<div x-data="{
handleMarkdownSaved(content) {
// Handle the saved markdown content
console.log('Markdown saved:', content);
// For example, you could trigger a download using JavaScript:
const blob = new Blob([content], { type: 'text/markdown' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'markdown.md';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
}">
<livewire:editable-markdown save-event="markdownSaved" />
<script>
document.addEventListener('livewire:initialized', () => {
Livewire.on('markdownSaved', (content) => {
Alpine.evaluate(document.querySelector('[x-data]'), 'handleMarkdownSaved', content);
});
});
</script>
</div>If you need to handle the save event in a controller, you can create a dedicated Livewire component that wraps the EditableMarkdown component and handles the save event:
<?php
namespace App\Livewire;
use Livewire\Component;
class MarkdownEditor extends Component
{
public function downloadMarkdown($content)
{
// Handle the saved markdown content
// For example, save it to a file or database
// To download the content as a file:
return response()->streamDownload(function () use ($content) {
echo $content;
}, 'markdown.md');
}
public function render()
{
return view('livewire.markdown-editor');
}
}In your Blade template:
<div>
<livewire:editable-markdown save-event="markdownSaved" />
<script>
document.addEventListener('livewire:initialized', () => {
Livewire.on('markdownSaved', (event) => {
@this.downloadMarkdown(event.content);
});
});
</script>
</div>You can customize the event name by passing the save-event parameter to the EditableMarkdown component:
<livewire:editable-markdown save-event="customEventName" />Then listen for this custom event name instead of the default markdownSaved.