Added copy button and relevant logic #1516
@@ -57,15 +57,9 @@ class SharedEditor extends Page
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clearContent(): void
|
public function copyContent(): void
|
||||||
{
|
{
|
||||||
SharedClipBoard::where('id', 1)->update([
|
$this->dispatch('copy-to-clipboard', content: $this->content);
|
||||||
'content' => '',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->content = '';
|
|
||||||
|
|
||||||
$this->lastSyncedContent = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function canAccess(): bool
|
public static function canAccess(): bool
|
||||||
|
|||||||
@@ -58,12 +58,11 @@
|
|||||||
|
|
||||||
{{-- Clear Button --}}
|
{{-- Clear Button --}}
|
||||||
<x-filament::button
|
<x-filament::button
|
||||||
color="danger"
|
color="info"
|
||||||
icon="heroicon-o-trash"
|
icon="heroicon-o-clipboard"
|
||||||
wire:click="clearContent"
|
wire:click="copyContent"
|
||||||
wire:confirm="Are you sure you want to clear the shared clipboard?"
|
|
||||||
>
|
>
|
||||||
Clear Content
|
Copy To ClipBoard
|
||||||
</x-filament::button>
|
</x-filament::button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -99,4 +98,43 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@script
|
||||||
|
<script>
|
||||||
|
$wire.on('copy-to-clipboard', (event) => {
|
||||||
|
|
||||||
|
const content = event.content;
|
||||||
|
|
||||||
|
const textarea = document.createElement('textarea');
|
||||||
|
|
||||||
|
textarea.value = content;
|
||||||
|
textarea.style.position = 'fixed';
|
||||||
|
textarea.style.left = '-9999px';
|
||||||
|
textarea.style.top = '0';
|
||||||
|
|
||||||
|
document.body.appendChild(textarea);
|
||||||
|
|
||||||
|
textarea.focus();
|
||||||
|
textarea.select();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const successful = document.execCommand('copy');
|
||||||
|
|
||||||
|
if (successful) {
|
||||||
|
new FilamentNotification()
|
||||||
|
.title('Content copied successfully!')
|
||||||
|
.success()
|
||||||
|
.send();
|
||||||
|
} else {
|
||||||
|
throw new Error('Copy command failed');
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Clipboard copy failed:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body.removeChild(textarea);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endscript
|
||||||
|
|
||||||
</x-filament-panels::page>
|
</x-filament-panels::page>
|
||||||
|
|||||||
Reference in New Issue
Block a user