mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Fix pushonce directive and image previews for file field.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
@extends('filament::layouts.field-group')
|
||||
|
||||
@pushonce('head')
|
||||
@pushonce('head:flatpickr-css')
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
|
||||
@endpushonce
|
||||
|
||||
@pushonce('js')
|
||||
@pushonce('js:flatpickr')
|
||||
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
|
||||
@endpushonce
|
||||
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
@extends('filament::layouts.field-group')
|
||||
|
||||
@pushonce('head')
|
||||
@pushonce('head:filepond-css')
|
||||
<link rel="stylesheet" href="https://unpkg.com/filepond/dist/filepond.css">
|
||||
@endpushonce
|
||||
|
||||
@pushonce('js')
|
||||
@pushonce('js:livewire-sortable')
|
||||
<script src="https://cdn.jsdelivr.net/gh/livewire/sortable@v0.x.x/dist/livewire-sortable.js"></script>
|
||||
@endpushonce
|
||||
|
||||
@pushonce('js:filepond')
|
||||
<script src="https://unpkg.com/filepond/dist/filepond.js"></script>
|
||||
@endpushonce
|
||||
|
||||
@@ -14,6 +18,9 @@
|
||||
x-data
|
||||
x-init="
|
||||
FilePond.setOptions({
|
||||
@isset($field->extraAttributes['placeholder'])
|
||||
labelIdle: '{{ $field->extraAttributes['placeholder'] }}',
|
||||
@endisset
|
||||
allowMultiple: {{ isset($field->extraAttributes['multiple']) ? 'true' : 'false' }},
|
||||
server: {
|
||||
process:(fieldName, file, metadata, load, error, progress, abort, transfer, options) => {
|
||||
@@ -49,7 +56,7 @@
|
||||
@endif
|
||||
>
|
||||
<div class="col-span-1 p-2 bg-white shadow-sm rounded border border-gray-300 flex items-center space-x-2 @if ($field->sortMethod) cursor-move @endif">
|
||||
@if (exif_imagetype(Filament::storage()->path($file)))
|
||||
@if (Filament::isImage($file))
|
||||
<x-filament::modal class="flex-shrink-0 flex">
|
||||
<x-filament-image :src="$file" alt="{{ $file }}" :manipulations="[ 'w' => 48, 'h' => 48, 'fit' => 'crop' ]" width="48px" height="48px" loading="lazy" class="w-12 h-12 rounded" />
|
||||
<x-slot name="content">
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
@extends('filament::layouts.field-group')
|
||||
|
||||
@pushonce('js:livewire-sortable')
|
||||
<script src="https://cdn.jsdelivr.net/gh/livewire/sortable@v0.x.x/dist/livewire-sortable.js"></script>
|
||||
@endpushonce
|
||||
|
||||
@section('field')
|
||||
<div class="space-y-4">
|
||||
<x-filament::select
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
@extends('filament::layouts.field-group')
|
||||
|
||||
@pushonce('head')
|
||||
@pushonce('head:trix-css')
|
||||
<link rel="stylesheet" href="https://www.unpkg.com/trix@1.3.1/dist/trix.css">
|
||||
@endpushonce
|
||||
|
||||
@pushonce('js')
|
||||
@pushonce('js:trix')
|
||||
<script src="https://www.unpkg.com/trix@1.3.1/dist/trix.js"></script>
|
||||
<script>
|
||||
Trix.config.blockAttributes.heading = {
|
||||
|
||||
@@ -16,9 +16,11 @@ class BladeDirectives
|
||||
|
||||
public static function pushOnce($expression): string
|
||||
{
|
||||
$var = '$__env->{"__pushonce_" . md5(__FILE__ . ":" . __LINE__)}';
|
||||
|
||||
return "<?php if(!isset({$var})): {$var} = true; \$__env->startPush({$expression}); ?>";
|
||||
[$pushName, $pushSub] = explode(':', trim(substr($expression, 1, -1)));
|
||||
|
||||
$key = '__pushonce_'.str_replace('-', '_', $pushName).'_'.str_replace('-', '_', $pushSub);
|
||||
|
||||
return "<?php if(! isset(\$__env->{$key})): \$__env->{$key} = 1; \$__env->startPush('{$pushName}'); ?>";
|
||||
}
|
||||
|
||||
public static function endPushOnce(): string
|
||||
|
||||
+16
-6
@@ -101,10 +101,6 @@ class Filament
|
||||
$asset = $this->getAsset($key);
|
||||
$publishedAsset = $this->getPublicAsset($key);
|
||||
|
||||
$additionalAssets = '
|
||||
<script src="https://cdn.jsdelivr.net/gh/livewire/sortable@v0.x.x/dist/livewire-sortable.js"></script>
|
||||
';
|
||||
|
||||
if ($publishedAsset) {
|
||||
$assetWarning = ($publishedAsset !== $asset) ?
|
||||
'<script>console.warn("Filament: The published javascript assets are out of date.\n");</script>' : null;
|
||||
@@ -113,7 +109,6 @@ class Filament
|
||||
<!-- Filament Published Scripts -->
|
||||
{$assetWarning}
|
||||
<script src=\"/vendor/filament{$publishedAsset}\" data-turbolinks-eval=\"false\"></script>
|
||||
{$additionalAssets}
|
||||
");
|
||||
}
|
||||
|
||||
@@ -122,7 +117,6 @@ class Filament
|
||||
return new HtmlString("
|
||||
<!-- Filament Scripts -->
|
||||
<script src=\"".route('filament.assets.js', $jsInfo)."\" data-turbolinks-eval=\"false\"></script>
|
||||
{$additionalAssets}
|
||||
");
|
||||
}
|
||||
|
||||
@@ -234,4 +228,20 @@ class Filament
|
||||
$urlBuilder = UrlBuilderFactory::create('', config('app.key'));
|
||||
return route('filament.image', ['path' => ltrim($urlBuilder->getUrl($path, $manipulations), '/')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if an asset is a valid image based on approved MIME Types.
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isImage($file)
|
||||
{
|
||||
return in_array($this->storage()->getMimeType($file), [
|
||||
'image/jpeg',
|
||||
'image/png',
|
||||
'image/gif',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user