Merge pull request 'Added copy button and relevant logic' (#1516) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 17s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 17s
Reviewed-on: #1516
This commit was merged in pull request #1516.
This commit is contained in:
@@ -57,15 +57,9 @@ class SharedEditor extends Page
|
||||
}
|
||||
}
|
||||
|
||||
public function clearContent(): void
|
||||
public function copyContent(): void
|
||||
{
|
||||
SharedClipBoard::where('id', 1)->update([
|
||||
'content' => '',
|
||||
]);
|
||||
|
||||
$this->content = '';
|
||||
|
||||
$this->lastSyncedContent = '';
|
||||
$this->dispatch('copy-to-clipboard', content: $this->content);
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
|
||||
@@ -58,12 +58,11 @@
|
||||
|
||||
{{-- Clear Button --}}
|
||||
<x-filament::button
|
||||
color="danger"
|
||||
icon="heroicon-o-trash"
|
||||
wire:click="clearContent"
|
||||
wire:confirm="Are you sure you want to clear the shared clipboard?"
|
||||
color="info"
|
||||
icon="heroicon-o-clipboard"
|
||||
wire:click="copyContent"
|
||||
>
|
||||
Clear Content
|
||||
Copy To ClipBoard
|
||||
</x-filament::button>
|
||||
|
||||
</div>
|
||||
@@ -99,4 +98,43 @@
|
||||
|
||||
</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>
|
||||
|
||||
Reference in New Issue
Block a user