Skip to content

Commit

Permalink
Handle plugin script partial
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine committed May 10, 2023
1 parent ee494fa commit 9829b12
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@


@if(config("sharp.extensions.activate_custom_fields", false))
@php
try {
$url = mix('/js/sharp-plugin.js');
} catch(\Exception $exception) {}
@endphp

@if($url ?? null)
<script src="{{ $url }}"></script>

@elseif($exception ?? null)
<script>
console.error(@json($exception->getMessage()));
</script>
@if($script = trim(view('sharp::partials.plugin-script')->render()))
{!! $script !!}
@else
<script defer src="{{ mix('/js/sharp-plugin.js') }}"></script>
@endif
@endif
17 changes: 9 additions & 8 deletions resources/views/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@
<x-sharp::extensions.injected-assets />

@include('sharp::partials.head')

<script defer src="{{ mix('manifest.js', '/vendor/sharp') }}"></script>
<script defer src="{{ mix('vendor.js', '/vendor/sharp') }}"></script>
<script defer src="{{ mix('client-api.js', '/vendor/sharp') }}"></script>

<x-sharp::extensions.custom-fields-script />

<script defer src="/vendor/sharp/lang.js?version={{ sharp_version() }}&locale={{ app()->getLocale() }}"></script>
<script defer src="{{ mix('sharp.js', '/vendor/sharp') }}"></script>
</head>
<body class="{{ $bodyClass ?? '' }}">
<x-sharp::alert.assets-outdated />

@yield('content')

<script src="{{ mix('manifest.js', '/vendor/sharp') }}"></script>
<script src="{{ mix('vendor.js', '/vendor/sharp') }}"></script>
<script src="{{ mix('client-api.js', '/vendor/sharp') }}"></script>

<x-sharp::extensions.custom-fields-script />

<script src="/vendor/sharp/lang.js?version={{ sharp_version() }}&locale={{ app()->getLocale() }}"></script>
<script src="{{ mix('sharp.js', '/vendor/sharp') }}"></script>
@stack('script')
</body>
</html>
2 changes: 2 additions & 0 deletions resources/views/partials/plugin-script.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

{{-- insert here your plugin script, e.g @vite('resources/js/sharp-plugin.js') --}}
1 change: 1 addition & 0 deletions src/SharpServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function boot()
$this->publishes([
__DIR__.'/../resources/views/components/file.blade.php' => resource_path('views/vendor/sharp/components/file.blade.php'),
__DIR__.'/../resources/views/components/image.blade.php' => resource_path('views/vendor/sharp/components/image.blade.php'),
__DIR__.'/../resources/views/partials/plugin-script.blade.php' => resource_path('views/vendor/sharp/partials/plugin-script.blade.php'),
], 'views');

Blade::componentNamespace('Code16\\Sharp\\View\\Components', 'sharp');
Expand Down

0 comments on commit 9829b12

Please sign in to comment.