Skip to content

Commit 2cf3428

Browse files
committed
Make components CSP-compatible
1 parent c8a4b68 commit 2cf3428

File tree

6 files changed

+11
-48
lines changed

6 files changed

+11
-48
lines changed

stubs/resources/views/flux/input/clearable.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<flux:button
1313
:$attributes
1414
:size="$size === 'sm' || $size === 'xs' ? 'xs' : 'sm'"
15-
x-data
16-
x-on:click="let input = $el.closest('[data-flux-input]').querySelector('input'); input.value = ''; input.dispatchEvent(new Event('input', { bubbles: false })); input.dispatchEvent(new Event('change', { bubbles: false })); input.focus()"
15+
x-data="fluxInputClearable"
16+
x-on:click="clear()"
1717
tabindex="-1"
1818
aria-label="Clear input"
1919
data-flux-clear-button

stubs/resources/views/flux/input/copyable.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<flux:button
1313
:$attributes
1414
:size="$size === 'sm' || $size === 'xs' ? 'xs' : 'sm'"
15-
x-data="{ copied: false }"
16-
x-on:click="copied = ! copied; navigator.clipboard && navigator.clipboard.writeText($el.closest('[data-flux-input]').querySelector('input').value); setTimeout(() => copied = false, 2000)"
15+
x-data="fluxInputCopyable"
16+
x-on:click="copy()"
1717
x-bind:data-copyable-copied="copied"
1818
aria-label="{{ __('Copy to clipboard') }}"
1919
>

stubs/resources/views/flux/input/expandable.blade.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<flux:button
1313
:$attributes
1414
:size="$size === 'sm' || $size === 'xs' ? 'xs' : 'sm'"
15-
x-on:click="$el.closest('[data-flux-input]').querySelector('input').value = ''"
1615
>
1716
<flux:icon.chevron-down variant="micro" />
1817
</flux:button>

stubs/resources/views/flux/input/file.blade.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,16 @@
3232
data-flux-input-file
3333
wire:ignore
3434
tabindex="0"
35-
x-data {{-- This is here to "scope" the x-ref references inside this component from interfering with others outside... --}}
35+
x-data="fluxInputFile({ files: '{{ __('files') }}', noFile: '{{ __('No file chosen') }}' })"
3636
x-on:click.prevent.stop="$refs.input.click()"
3737
x-on:keydown.enter.prevent.stop="$refs.input.click()"
3838
x-on:keydown.space.prevent.stop
3939
x-on:keyup.space.prevent.stop="$refs.input.click()"
40-
x-on:change="$refs.name.textContent = $event.target.files[1] ? ($event.target.files.length + ' {!! __('files') !!}') : ($event.target.files[0]?.name || '{!! __('No file chosen') !!}')"
40+
x-on:change="updateLabel($event)"
4141
>
4242
<input
4343
x-ref="input"
4444
x-on:click.stop {{-- Without this, the parent element's click listener will ".prevent" the file input from being clicked... --}}
45-
{{-- This is here because clearing the input via .value = "" doesn't trigger a change event... --}}
46-
{{-- We need it to so that we can know to clear the selected file labels when the input is cleared... --}}
47-
x-init="Object.defineProperty($el, 'value', {
48-
...Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value'),
49-
set(value) {
50-
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set.call(this, value);
51-
52-
if(! value) this.dispatchEvent(new Event('change', { bubbles: true }))
53-
}
54-
})"
5545
type="file"
5646
class="sr-only"
5747
tabindex="-1"

stubs/resources/views/flux/input/viewable.blade.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,10 @@
1212
<flux:button
1313
:$attributes
1414
:size="$size === 'sm' || $size === 'xs' ? 'xs' : 'sm'"
15-
x-data="{ open: false }"
16-
x-on:click="open = ! open; $el.closest('[data-flux-input]').querySelector('input').setAttribute('type', open ? 'text' : 'password')"
15+
x-data="fluxInputViewable"
16+
x-on:click="toggle()"
1717
x-bind:data-viewable-open="open"
1818
aria-label="{{ __('Toggle password visibility') }}"
19-
20-
{{-- We need to make the input type "durable" (immune to Livewire morph manipulations): --}}
21-
x-init="
22-
let input = $el.closest('[data-flux-input]')?.querySelector('input');
23-
24-
if (! input) return;
25-
26-
let observer = new MutationObserver(() => {
27-
let type = open ? 'text' : 'password';
28-
if (input.getAttribute('type') === type) return;
29-
input.setAttribute('type', type)
30-
});
31-
32-
observer.observe(input, { attributes: true, attributeFilter: ['type'] });
33-
"
3419
>
3520
<flux:icon.eye-slash variant="micro" class="hidden [[data-viewable-open]>&]:block" />
3621
<flux:icon.eye variant="micro" class="block [[data-viewable-open]>&]:hidden" />

stubs/resources/views/flux/modal/index.blade.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,9 @@
9090
{{ $styleAttributes->class($classes) }}
9191
@if ($name) data-modal="{{ $name }}" @endif
9292
@if ($flyout) data-flux-flyout @endif
93-
x-data
94-
@isset($__livewire)
95-
x-on:modal-show.document="
96-
if ($event.detail.name === @js($name) && ($event.detail.scope === @js($__livewire->getId()))) $el.showModal();
97-
if ($event.detail.name === @js($name) && (! $event.detail.scope)) $el.showModal();
98-
"
99-
x-on:modal-close.document="
100-
if ($event.detail.name === @js($name) && ($event.detail.scope === @js($__livewire->getId()))) $el.close();
101-
if (! $event.detail.name || ($event.detail.name === @js($name) && (! $event.detail.scope))) $el.close();
102-
"
103-
@else
104-
x-on:modal-show.document="if ($event.detail.name === @js($name) && (! $event.detail.scope)) $el.showModal()"
105-
x-on:modal-close.document="if (! $event.detail.name || ($event.detail.name === @js($name) && (! $event.detail.scope))) $el.close()"
106-
@endif
93+
x-data="fluxModal(@js($name), @js($__livewire?->getId()))"
94+
x-on:modal-show.document="handleShow($event)"
95+
x-on:modal-close.document="handleClose($event)"
10796
>
10897
{{ $slot }}
10998

0 commit comments

Comments
 (0)