generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from tanthammar/lazy-load-assets
Lazy load assets
- Loading branch information
Showing
2 changed files
with
62 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,65 @@ | ||
<x-filament-forms::field-wrapper | ||
:id="$getId()" | ||
:label="$getLabel()" | ||
:label-sr-only="$isLabelHidden()" | ||
:helper-text="$getHelperText()" | ||
:hint="$getHint()" | ||
:hint-icon="$getHintIcon()" | ||
:required="$isRequired()" | ||
:state-path="$getStatePath()" | ||
:id="$getId()" | ||
:label="$getLabel()" | ||
:label-sr-only="$isLabelHidden()" | ||
:helper-text="$getHelperText()" | ||
:hint="$getHint()" | ||
:hint-icon="$getHintIcon()" | ||
:required="$isRequired()" | ||
:state-path="$getStatePath()" | ||
> | ||
<div class="w-full" x-data="{ | ||
<div class="w-full" | ||
x-load-css="[@js(\Filament\Support\Facades\FilamentAsset::getStyleHref('invaders-filament-jsoneditor', package: 'invaders/jsoneditor'))]" | ||
data-js-before="app.js" | ||
x-load-js="[@js(\Filament\Support\Facades\FilamentAsset::getScriptSrc('invaders-filament-jsoneditor', package: 'invaders/jsoneditor'))]" | ||
data-dispatch="jsoneditor-loaded" | ||
x-on:jsoneditor-loaded-js.window="start" | ||
x-data="{ | ||
state: $wire.entangle('{{ $getStatePath() }}'), | ||
}" | ||
x-init="$nextTick(() => { | ||
const options = { | ||
modes: {{ $getModes() }}, | ||
history: true, | ||
onChange: function(){ | ||
}, | ||
onChangeJSON: function(json){ | ||
state=JSON.stringify(json); | ||
}, | ||
onChangeText: function(jsonString){ | ||
state=jsonString; | ||
}, | ||
onValidationError: function (errors) { | ||
errors.forEach((error) => { | ||
switch (error.type) { | ||
case 'validation': // schema validation error | ||
break; | ||
case 'error': // json parse error | ||
console.log(error.message); | ||
break; | ||
} | ||
}) | ||
} | ||
}; | ||
if(typeof json_editor !== 'undefined'){ | ||
json_editor = new JSONEditor($refs.editor, options); | ||
json_editor.set(state); | ||
} else { | ||
let json_editor = new JSONEditor($refs.editor, options); | ||
json_editor.set(state); | ||
editor: null, | ||
destroy() { | ||
this.editor = null; | ||
console.info('destroy'); | ||
}, | ||
start() { | ||
$nextTick(() => { | ||
if(this.editor !== null) { | ||
return; | ||
} | ||
const options = { | ||
modes: {{ $getModes() }}, | ||
history: true, | ||
onChange: () => { | ||
// onChange callback code if needed | ||
}, | ||
onChangeJSON: (json) => { | ||
this.state = JSON.stringify(json); | ||
}, | ||
onChangeText: (jsonString) => { | ||
this.state = jsonString; | ||
}, | ||
onValidationError: (errors) => { | ||
errors.forEach((error) => { | ||
switch (error.type) { | ||
case 'validation': // schema validation error | ||
// Handle schema validation error | ||
break; | ||
case 'error': // json parse error | ||
console.log(error.message); | ||
break; | ||
} | ||
}); | ||
} | ||
}; | ||
if(typeof JSONEditor !== 'undefined') { | ||
this.editor = new JSONEditor($refs.editor, options); | ||
Alpine.raw(this.editor).set(this.state); | ||
} | ||
}) | ||
} | ||
})" | ||
}" | ||
x-cloak | ||
wire:ignore> | ||
<div x-ref="editor" class="w-full ace_editor" | ||
style="min-height: 30vh;height:{{ $getHeight() }}px"></div> | ||
<div x-ref="editor" class="w-full ace_editor" style="min-height: 30vh;height:{{ $getHeight() }}px"></div> | ||
</div> | ||
</x-filament-forms::field-wrapper> | ||
|
||
</x-filament-forms::field-wrapper> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters