From 516ac75b85f944dd06f7beea5bb3c70bb1bda322 Mon Sep 17 00:00:00 2001 From: danharrin Date: Fri, 14 Oct 2022 10:35:16 +0000 Subject: [PATCH] chore: fix code style --- bin/build.js | 10 +-- .../resources/js/components/color-picker.js | 15 ++-- .../js/components/date-time-picker.js | 24 ++---- .../resources/js/components/file-upload.js | 28 ++----- .../resources/js/components/key-value.js | 2 +- .../js/components/markdown-editor.js | 2 +- .../forms/resources/js/components/select.js | 78 +++++++------------ .../resources/js/components/tags-input.js | 2 +- packages/forms/src/FormsServiceProvider.php | 1 - packages/support/src/Assets/AssetManager.php | 2 - 10 files changed, 60 insertions(+), 104 deletions(-) diff --git a/bin/build.js b/bin/build.js index 0de3a8ef0a..9742bcf5fc 100644 --- a/bin/build.js +++ b/bin/build.js @@ -1,11 +1,7 @@ const esbuild = require('esbuild') const shouldWatch = process.argv.includes('--watch') -const packages = [ - 'forms', - 'notifications', - 'support', -] +const packages = ['forms', 'notifications', 'support'] packages.forEach((package) => { esbuild @@ -47,7 +43,9 @@ formComponents.forEach((component) => { ? `'production'` : `'development'`, }, - entryPoints: [`packages/forms/resources/js/components/${component}.js`], + entryPoints: [ + `packages/forms/resources/js/components/${component}.js`, + ], outfile: `packages/forms/dist/components/${component}.js`, bundle: true, platform: 'neutral', diff --git a/packages/forms/resources/js/components/color-picker.js b/packages/forms/resources/js/components/color-picker.js index 0437b22fd3..44cfcf58f4 100644 --- a/packages/forms/resources/js/components/color-picker.js +++ b/packages/forms/resources/js/components/color-picker.js @@ -3,7 +3,11 @@ import 'vanilla-colorful/hsl-string-color-picker' import 'vanilla-colorful/rgb-string-color-picker' import 'vanilla-colorful/rgba-string-color-picker' -export default function colorPickerFormComponent({ isAutofocused, isDisabled, state }) { +export default function colorPickerFormComponent({ + isAutofocused, + isDisabled, + state, +}) { return { state, @@ -20,12 +24,9 @@ export default function colorPickerFormComponent({ isAutofocused, isDisabled, st this.setState(event.target.value) }) - this.$refs.panel.addEventListener( - 'color-changed', - (event) => { - this.setState(event.detail.value) - }, - ) + this.$refs.panel.addEventListener('color-changed', (event) => { + this.setState(event.detail.value) + }) }, togglePanelVisibility: function () { diff --git a/packages/forms/resources/js/components/date-time-picker.js b/packages/forms/resources/js/components/date-time-picker.js index ee5f54aa14..b9d0670fce 100644 --- a/packages/forms/resources/js/components/date-time-picker.js +++ b/packages/forms/resources/js/components/date-time-picker.js @@ -57,10 +57,7 @@ export default function dateTimePickerFormComponent({ this.getSelectedDate() ?? dayjs().tz(timezone).hour(0).minute(0).second(0) - if ( - this.getMaxDate() !== null && - date.isAfter(this.getMaxDate()) - ) { + if (this.getMaxDate() !== null && date.isAfter(this.getMaxDate())) { date = null } else if ( this.getMinDate() !== null && @@ -90,9 +87,7 @@ export default function dateTimePickerFormComponent({ return } - this.focusedDate = this.focusedDate.month( - this.focusedMonth, - ) + this.focusedDate = this.focusedDate.month(this.focusedMonth) }) this.$watch('focusedYear', () => { @@ -100,10 +95,7 @@ export default function dateTimePickerFormComponent({ this.focusedYear = this.focusedYear.substring(0, 4) } - if ( - !this.focusedYear || - this.focusedYear?.length !== 4 - ) { + if (!this.focusedYear || this.focusedYear?.length !== 4) { return } @@ -433,9 +425,7 @@ export default function dateTimePickerFormComponent({ this.emptyDaysInFocusedMonth = Array.from( { - length: this.focusedDate - .date(8 - firstDayOfWeek) - .day(), + length: this.focusedDate.date(8 - firstDayOfWeek).day(), }, (_, i) => i + 1, ) @@ -449,9 +439,9 @@ export default function dateTimePickerFormComponent({ }, setFocusedDay: function (day) { - this.focusedDate = ( - this.focusedDate ?? dayjs().tz(timezone) - ).date(day) + this.focusedDate = (this.focusedDate ?? dayjs().tz(timezone)).date( + day, + ) }, setState: function (date) { diff --git a/packages/forms/resources/js/components/file-upload.js b/packages/forms/resources/js/components/file-upload.js index c78a4df7d2..345e421c96 100644 --- a/packages/forms/resources/js/components/file-upload.js +++ b/packages/forms/resources/js/components/file-upload.js @@ -81,20 +81,16 @@ export default function fileUploadFormComponent({ imageResizeTargetHeight, imageResizeTargetWidth, imageResizeMode, - itemInsertLocation: shouldAppendFiles - ? 'after' - : 'before', + itemInsertLocation: shouldAppendFiles ? 'after' : 'before', ...(placeholder && { labelIdle: placeholder }), maxFileSize: maxSize, minFileSize: minSize, styleButtonProcessItemPosition: uploadButtonPosition, - styleButtonRemoveItemPosition: - removeUploadedFileButtonPosition, + styleButtonRemoveItemPosition: removeUploadedFileButtonPosition, styleLoadIndicatorPosition: loadingIndicatorPosition, stylePanelAspectRatio: panelAspectRatio, stylePanelLayout: panelLayout, - styleProgressIndicatorPosition: - uploadProgressIndicatorPosition, + styleProgressIndicatorPosition: uploadProgressIndicatorPosition, server: { load: async (source, load) => { let response = await fetch(source) @@ -121,9 +117,7 @@ export default function fileUploadFormComponent({ ).replace(/[018]/g, (c) => ( c ^ - (crypto.getRandomValues( - new Uint8Array(1), - )[0] & + (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4))) ).toString(16), ) @@ -141,8 +135,7 @@ export default function fileUploadFormComponent({ ) }, remove: async (source, load) => { - let fileKey = - this.uploadedFileUrlIndex[source] ?? null + let fileKey = this.uploadedFileUrlIndex[source] ?? null if (!fileKey) { return @@ -189,8 +182,7 @@ export default function fileUploadFormComponent({ .map((file) => file.source instanceof File ? file.serverId - : this.uploadedFileUrlIndex[file.source] ?? - null, + : this.uploadedFileUrlIndex[file.source] ?? null, ) // file.serverId is null for a file that is not yet uploaded .filter((fileKey) => fileKey) @@ -264,9 +256,7 @@ export default function fileUploadFormComponent({ this.fileKeyIndex = uploadedFileUrls ?? {} - this.uploadedFileUrlIndex = Object.entries( - this.fileKeyIndex, - ) + this.uploadedFileUrlIndex = Object.entries(this.fileKeyIndex) .filter((value) => value) .reduce((obj, [key, value]) => { obj[value] = key @@ -280,9 +270,7 @@ export default function fileUploadFormComponent({ let files = [] - for (const uploadedFileUrl of Object.values( - this.fileKeyIndex, - )) { + for (const uploadedFileUrl of Object.values(this.fileKeyIndex)) { if (!uploadedFileUrl) { continue } diff --git a/packages/forms/resources/js/components/key-value.js b/packages/forms/resources/js/components/key-value.js index af20c0d79c..973082eba3 100644 --- a/packages/forms/resources/js/components/key-value.js +++ b/packages/forms/resources/js/components/key-value.js @@ -1,4 +1,4 @@ -export default function keyValueFormComponent ({ state }) { +export default function keyValueFormComponent({ state }) { return { state, diff --git a/packages/forms/resources/js/components/markdown-editor.js b/packages/forms/resources/js/components/markdown-editor.js index 8818ee8aea..22590fa8e1 100644 --- a/packages/forms/resources/js/components/markdown-editor.js +++ b/packages/forms/resources/js/components/markdown-editor.js @@ -4,7 +4,7 @@ import DOMPurify from 'dompurify' import { marked } from 'marked' import { highlight } from 'mdhl' -export default function markdownEditorFormComponent ({ state, tab }) { +export default function markdownEditorFormComponent({ state, tab }) { return { attachment: null, diff --git a/packages/forms/resources/js/components/select.js b/packages/forms/resources/js/components/select.js index 44a4380f85..92c3fe4616 100644 --- a/packages/forms/resources/js/components/select.js +++ b/packages/forms/resources/js/components/select.js @@ -57,9 +57,7 @@ export default function selectFormComponent({ await this.refreshChoices({ withInitialOptions: true }) if (![null, undefined, ''].includes(this.state)) { - this.select.setChoiceByValue( - this.formatState(this.state), - ) + this.select.setChoiceByValue(this.formatState(this.state)) } this.refreshPlaceholder() @@ -81,45 +79,39 @@ export default function selectFormComponent({ }) if (hasDynamicOptions) { - this.$refs.input.addEventListener( - 'showDropdown', - async () => { - this.select.clearChoices() - await this.select.setChoices([ - { - label: loadingMessage, - value: '', - disabled: true, - }, - ]) + this.$refs.input.addEventListener('showDropdown', async () => { + this.select.clearChoices() + await this.select.setChoices([ + { + label: loadingMessage, + value: '', + disabled: true, + }, + ]) - await this.refreshChoices() - }, - ) + await this.refreshChoices() + }) } if (hasDynamicSearchResults) { - this.$refs.input.addEventListener( - 'search', - async (event) => { - let search = event.detail.value?.trim() + this.$refs.input.addEventListener('search', async (event) => { + let search = event.detail.value?.trim() - if ([null, undefined, ''].includes(search)) { - return - } + if ([null, undefined, ''].includes(search)) { + return + } - this.isSearching = true + this.isSearching = true - this.select.clearChoices() - await this.select.setChoices([ - { - label: searchingMessage, - value: '', - disabled: true, - }, - ]) - }, - ) + this.select.clearChoices() + await this.select.setChoices([ + { + label: searchingMessage, + value: '', + disabled: true, + }, + ]) + }) this.$refs.input.addEventListener( 'search', @@ -149,9 +141,7 @@ export default function selectFormComponent({ this.setChoices(choices) if (![null, undefined, ''].includes(this.state)) { - this.select.setChoiceByValue( - this.formatState(this.state), - ) + this.select.setChoiceByValue(this.formatState(this.state)) } }) }, @@ -177,11 +167,7 @@ export default function selectFormComponent({ return options } - if ( - search !== '' && - search !== null && - search !== undefined - ) { + if (search !== '' && search !== null && search !== undefined) { return await getSearchResultsUsing(search) } @@ -226,11 +212,7 @@ export default function selectFormComponent({ ) if (isMultiple) { - if ( - state.every((value) => - existingOptionValues.has(value), - ) - ) { + if (state.every((value) => existingOptionValues.has(value))) { return {} } diff --git a/packages/forms/resources/js/components/tags-input.js b/packages/forms/resources/js/components/tags-input.js index 1c98092921..0ee384a5fc 100644 --- a/packages/forms/resources/js/components/tags-input.js +++ b/packages/forms/resources/js/components/tags-input.js @@ -1,4 +1,4 @@ -export default function tagsInputFormComponent ({ state }) { +export default function tagsInputFormComponent({ state }) { return { newTag: '', diff --git a/packages/forms/src/FormsServiceProvider.php b/packages/forms/src/FormsServiceProvider.php index f18d97ba46..175dbf9aa9 100644 --- a/packages/forms/src/FormsServiceProvider.php +++ b/packages/forms/src/FormsServiceProvider.php @@ -4,7 +4,6 @@ namespace Filament\Forms; use Filament\Forms\Testing\TestsForms; use Filament\Support\Assets\AlpineComponent; -use Filament\Support\Assets\Js; use Filament\Support\Facades\Asset; use Illuminate\Filesystem\Filesystem; use Livewire\Testing\TestableLivewire; diff --git a/packages/support/src/Assets/AssetManager.php b/packages/support/src/Assets/AssetManager.php index 275890e435..8739fcbb85 100644 --- a/packages/support/src/Assets/AssetManager.php +++ b/packages/support/src/Assets/AssetManager.php @@ -2,8 +2,6 @@ namespace Filament\Support\Assets; -use Illuminate\Contracts\Support\Htmlable; -use Illuminate\Contracts\View\View; use Illuminate\Support\Arr; class AssetManager