Update to AlpineJS 3.x

This commit is contained in:
Christopher C. Wells 2021-07-12 21:02:27 -07:00
parent 636f9ff864
commit feb6cce3a4
19 changed files with 3279 additions and 13754 deletions

16909
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -10,22 +10,21 @@
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --config=node_modules/laravel-mix/setup/webpack.config.js" "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --config=node_modules/laravel-mix/setup/webpack.config.js"
}, },
"devDependencies": { "devDependencies": {
"@tailwindcss/forms": "^0.3.2", "@tailwindcss/forms": "^0.3.3",
"@tailwindcss/typography": "^0.4.1", "@tailwindcss/typography": "^0.4.1",
"alpinejs": "^2.8.2", "alpinejs": "^3.2.1",
"autoprefixer": "^10.2.6", "autoprefixer": "^10.3.1",
"axios": "^0.21.1", "axios": "^0.21.1",
"cross-env": "^7.0", "cross-env": "^7.0",
"laravel-mix": "^6.0.19", "laravel-mix": "^6.0.25",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"postcss-import": "^14.0.2", "postcss-import": "^14.0.2",
"quill": "^1.3.7", "quill": "^1.3.7",
"resolve-url-loader": "^4.0.0", "resolve-url-loader": "^4.0.0",
"tailwindcss": "^2.1.2", "tailwindcss": "^2.2.4",
"vue-template-compiler": "^2.6.12" "vue-template-compiler": "^2.6.14"
}, },
"dependencies": { "dependencies": {
"@shopify/draggable": "^1.0.0-beta.12", "@shopify/draggable": "^1.0.0-beta.12"
"alpine-magic-helpers": "^1.2.2"
} }
} }

2
public/css/app.css vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
public/js/app.js vendored

File diff suppressed because one or more lines are too long

2
public/js/quill.js vendored

File diff suppressed because one or more lines are too long

3
resources/js/app.js vendored
View File

@ -1,4 +1 @@
require('./bootstrap'); require('./bootstrap');
require('alpine-magic-helpers');
require('alpinejs');

View File

@ -1,28 +1,11 @@
// Load Lodash.
window._ = require('lodash'); window._ = require('lodash');
/** // Load Axios.
* We'll load the axios HTTP library which allows us to easily issue requests
* to our Laravel back-end. This library automatically handles sending the
* CSRF token as a header based on the value of the "XSRF" token cookie.
*/
window.axios = require('axios'); window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
/** // Load AlpineJS.
* Echo exposes an expressive API for subscribing to channels and listening import Alpine from 'alpinejs';
* for events that are broadcast by Laravel. Echo and event broadcasting window.Alpine = Alpine;
* allows your team to easily build robust real-time web applications. Alpine.start();
*/
// import Echo from 'laravel-echo';
// window.Pusher = require('pusher-js');
// window.Echo = new Echo({
// broadcaster: 'pusher',
// key: process.env.MIX_PUSHER_APP_KEY,
// cluster: process.env.MIX_PUSHER_APP_CLUSTER,
// forceTLS: true
// });

View File

@ -21,7 +21,7 @@ switch ($width) {
} }
@endphp @endphp
<div class="relative" x-data="{ open: false }" @click.away="open = false" @close.stop="open = false"> <div class="relative" x-data="{ open: false }" @click.outside="open = false" @close.stop="open = false">
<div @click="open = ! open"> <div @click="open = ! open">
{{ $trigger }} {{ $trigger }}
</div> </div>

View File

@ -20,11 +20,11 @@
autocapitalize="none" autocapitalize="none"
inputmode="search" inputmode="search"
x-ref="ingredients_name" x-ref="ingredients_name"
x-spread="search" /> x-bind="search" />
</div> </div>
<div x-show="searching" x-cloak> <div x-show="searching" x-cloak>
<div class="absolute border-2 border-gray-500 border-b-0 bg-white" <div class="absolute border-2 border-gray-500 border-b-0 bg-white"
x-spread="ingredient"> x-bind="ingredient">
<template x-for="result in results" :key="result.id"> <template x-for="result in results" :key="result.id">
<div class="p-1 border-b-2 border-gray-500 hover:bg-yellow-300 cursor-pointer" x-bind:data-id="result.id"> <div class="p-1 border-b-2 border-gray-500 hover:bg-yellow-300 cursor-pointer" x-bind:data-id="result.id">
<div class="pointer-events-none"> <div class="pointer-events-none">

View File

@ -1,4 +1,4 @@
<div x-data="searchView()" x-init="loadMore()"> <div x-data="searchView">
<div class="flex flex-col space-y-4 md:flex-row md:space-x-4 md:space-y-0"> <div class="flex flex-col space-y-4 md:flex-row md:space-x-4 md:space-y-0">
<nav class="md:w-1/4"> <nav class="md:w-1/4">
<x-inputs.input name="search" <x-inputs.input name="search"
@ -41,7 +41,7 @@
class="bg-blue-800 hover:bg-blue-700 active:bg-blue-900 focus:border-blue-900 ring-blue-300" class="bg-blue-800 hover:bg-blue-700 active:bg-blue-900 focus:border-blue-900 ring-blue-300"
x-show="morePages" x-show="morePages"
x-cloak x-cloak
@click.prevent="loadMore()"> @click.prevent="loadMore">
Load more Load more
</x-inputs.button> </x-inputs.button>
</section> </section>
@ -51,8 +51,8 @@
@once @once
@push('scripts') @push('scripts')
<script type="text/javascript"> <script type="text/javascript">
let searchView = () => { document.addEventListener('alpine:init', () => {
return { Alpine.data('searchView', () => ({
results: [], results: [],
number: 1, number: 1,
size: 12, size: 12,
@ -60,6 +60,9 @@
searchTerm: null, searchTerm: null,
searching: false, searching: false,
filterTags: [], filterTags: [],
init() {
this.loadMore();
},
resetPagination() { resetPagination() {
this.number = 1; this.number = 1;
this.morePages = false; this.morePages = false;
@ -109,8 +112,8 @@
} }
this.loadMore(); this.loadMore();
} }
} }))
} })
</script> </script>
@endpush @endpush
@endonce @endonce

View File

@ -1,5 +1,5 @@
<div x-data data-tags="{{ $defaultTags ?? '[]' }}"> <div x-data data-tags="{{ $defaultTags ?? '[]' }}">
<div x-data="tagSelect()" x-init="init('parentEl')" @click.away="clearSearch()" @keydown.escape="clearSearch()"> <div x-data="tagSelect()" @click.outside="clearSearch()" @keydown.escape="clearSearch()">
<div class="relative" @keydown.enter.prevent="addTag(searchTerm)"> <div class="relative" @keydown.enter.prevent="addTag(searchTerm)">
<x-inputs.input type="hidden" <x-inputs.input type="hidden"
name="tags" name="tags"

View File

@ -10,7 +10,7 @@
</x-slot> </x-slot>
<x-search-view :route="route('api:v1:foods.index')" :tags="$tags"> <x-search-view :route="route('api:v1:foods.index')" :tags="$tags">
<x-slot name="results"> <x-slot name="results">
<template x-for="food in results" :key="food"> <template x-for="food in results" :key="food.slug">
<article class="p-1 border-2 border-black font-sans"> <article class="p-1 border-2 border-black font-sans">
<h1 class="text-2xl lowercase font-extrabold leading-none"> <h1 class="text-2xl lowercase font-extrabold leading-none">
<a x-bind:href="food.showUrl" <a x-bind:href="food.showUrl"

View File

@ -10,14 +10,14 @@
</x-slot> </x-slot>
<form method="POST" action="{{ route('journal-entries.store') }}"> <form method="POST" action="{{ route('journal-entries.store') }}">
@csrf @csrf
<div x-data x-init="initJournalEntries($el);" class="space-y-4"> <div x-data x-ref="root" x-init="initJournalEntries($refs.root)" class="space-y-4">
@foreach($ingredients as $ingredient) @foreach($ingredients as $ingredient)
@include('journal-entries.partials.entry-item-input', $ingredient) @include('journal-entries.partials.entry-item-input', $ingredient)
@endforeach @endforeach
<div class="journal-entry-template hidden"> <div class="journal-entry-template hidden">
@include('journal-entries.partials.entry-item-input', ['default_date' => $default_date]) @include('journal-entries.partials.entry-item-input', ['default_date' => $default_date])
</div> </div>
<x-inputs.icon-green type="button" class="add-entry-item" x-on:click="addEntryNode($el);"> <x-inputs.icon-green type="button" class="add-entry-item" x-on:click="addEntryNode($refs.root);">
<svg class="h-10 w-10 pointer-events-none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"> <svg class="h-10 w-10 pointer-events-none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-11a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V7z" clip-rule="evenodd" /> <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-11a1 1 0 10-2 0v2H7a1 1 0 100 2h2v2a1 1 0 102 0v-2h2a1 1 0 100-2h-2V7z" clip-rule="evenodd" />
</svg> </svg>
@ -27,7 +27,7 @@
<x-inputs.input type="checkbox" name="group_entries" class="h-5 w-5" value="1" /> <x-inputs.input type="checkbox" name="group_entries" class="h-5 w-5" value="1" />
<span class="ml-2">Group entries by day and meal</span> <span class="ml-2">Group entries by day and meal</span>
</x-inputs.label> </x-inputs.label>
<x-inputs.button x-on:click="removeTemplate($el);">Add entries</x-inputs.button> <x-inputs.button x-on:click="removeTemplate($refs.root);">Add entries</x-inputs.button>
</div> </div>
</div> </div>
</form> </form>

View File

@ -14,12 +14,12 @@
</a> </a>
</div> </div>
<div class="text-base text-gray-500"> <div class="text-base text-gray-500">
<form x-data method="GET" action="{{ route('journal-entries.index') }}"> <form x-data x-ref="root" method="GET" action="{{ route('journal-entries.index') }}">
<x-inputs.input name="date" <x-inputs.input name="date"
type="date" type="date"
class="border-0 shadow-none p-0 text-center" class="border-0 shadow-none p-0 text-center"
:value="$date->toDateString()" :value="$date->toDateString()"
x-on:change="$el.submit();" x-on:change="$refs.root.submit();"
required /> required />
</form> </form>
</div> </div>

View File

@ -35,9 +35,9 @@
<x-dropdown-link :href="route('users.index')">Manage Users</x-dropdown-link> <x-dropdown-link :href="route('users.index')">Manage Users</x-dropdown-link>
@endcan @endcan
<hr /> <hr />
<form method="POST" action="{{ route('logout') }}" x-data> <form method="POST" action="{{ route('logout') }}" x-data x-ref="root">
@csrf @csrf
<x-dropdown-link :href="route('logout')" @click.prevent="$el.closest('form').submit();">Logout</x-dropdown-link> <x-dropdown-link :href="route('logout')" @click.prevent="$refs.root.closest('form').submit();">Logout</x-dropdown-link>
</form> </form>
</div> </div>
</x-slot> </x-slot>

View File

@ -4,7 +4,7 @@
<x-slot name="header"> <x-slot name="header">
<h1 class="font-semibold text-xl text-gray-800 leading-tight">{{ $title }}</h1> <h1 class="font-semibold text-xl text-gray-800 leading-tight">{{ $title }}</h1>
</x-slot> </x-slot>
<form x-data method="POST" enctype="multipart/form-data" action="{{ ($recipe->exists ? route('recipes.update', $recipe) : route('recipes.store')) }}"> <form x-data x-ref="root" method="POST" enctype="multipart/form-data" action="{{ ($recipe->exists ? route('recipes.update', $recipe) : route('recipes.store')) }}">
@if ($recipe->exists)@method('put')@endif @if ($recipe->exists)@method('put')@endif
@csrf @csrf
<div class="flex flex-col space-y-4 md:flex-row md:space-x-4 md:space-y-0"> <div class="flex flex-col space-y-4 md:flex-row md:space-x-4 md:space-y-0">
@ -114,7 +114,7 @@
<!-- Ingredients --> <!-- Ingredients -->
<h3 class="mt-6 mb-2 font-extrabold text-lg">Ingredients</h3> <h3 class="mt-6 mb-2 font-extrabold text-lg">Ingredients</h3>
<div x-data class="ingredients space-y-4"> <div x-data x-ref="ingredients" class="ingredients space-y-4">
@forelse($ingredients_list->sortBy('weight') as $item) @forelse($ingredients_list->sortBy('weight') as $item)
@if($item['type'] === 'ingredient') @if($item['type'] === 'ingredient')
@include('recipes.partials.ingredient-input', $item) @include('recipes.partials.ingredient-input', $item)
@ -134,19 +134,19 @@
</div> </div>
<x-inputs.button type="button" <x-inputs.button type="button"
class="bg-green-800 hover:bg-green-700 active:bg-green-900 focus:border-green-900 ring-green-300" class="bg-green-800 hover:bg-green-700 active:bg-green-900 focus:border-green-900 ring-green-300"
x-on:click="addNodeFromTemplate($el, 'ingredient');"> x-on:click="addNodeFromTemplate($refs.ingredients, 'ingredient');">
Add Ingredient Add Ingredient
</x-inputs.button> </x-inputs.button>
<x-inputs.button type="button" <x-inputs.button type="button"
class="bg-blue-800 hover:bg-blue-700 active:bg-blue-900 focus:border-blue-900 ring-blue-300" class="bg-blue-800 hover:bg-blue-700 active:bg-blue-900 focus:border-blue-900 ring-blue-300"
x-on:click="addNodeFromTemplate($el, 'separator');"> x-on:click="addNodeFromTemplate($refs.ingredients, 'separator');">
Add Separator Add Separator
</x-inputs.button> </x-inputs.button>
</div> </div>
<!-- Steps --> <!-- Steps -->
<h3 class="mt-6 mb-2 font-extrabold text-lg">Steps</h3> <h3 class="mt-6 mb-2 font-extrabold text-lg">Steps</h3>
<div x-data class="steps"> <div x-data x-ref="steps" class="steps">
@forelse($steps as $step) @forelse($steps as $step)
@include('recipes.partials.step-input', $step) @include('recipes.partials.step-input', $step)
@empty @empty
@ -159,13 +159,13 @@
</div> </div>
<x-inputs.button type="button" <x-inputs.button type="button"
class="bg-green-800 hover:bg-green-700 active:bg-green-900 focus:border-green-900 ring-green-300" class="bg-green-800 hover:bg-green-700 active:bg-green-900 focus:border-green-900 ring-green-300"
x-on:click="addNodeFromTemplate($el, 'step');"> x-on:click="addNodeFromTemplate($refs.steps, 'step');">
Add Step Add Step
</x-inputs.button> </x-inputs.button>
</div> </div>
<div class="flex items-center justify-end mt-4"> <div class="flex items-center justify-end mt-4">
<x-inputs.button x-on:click="prepareForm($el);" class="ml-3"> <x-inputs.button x-on:click="prepareForm($refs.root);" class="ml-3">
{{ ($recipe->exists ? 'Save' : 'Add') }} {{ ($recipe->exists ? 'Save' : 'Add') }}
</x-inputs.button> </x-inputs.button>
</div> </div>

View File

@ -10,7 +10,7 @@
</x-slot> </x-slot>
<x-search-view :route="route('api:v1:recipes.index')" :tags="$tags"> <x-search-view :route="route('api:v1:recipes.index')" :tags="$tags">
<x-slot name="results"> <x-slot name="results">
<template x-for="recipe in results" :key="recipe"> <template x-for="recipe in results" :key="recipe.slug">
<article class="p-1 border-2 border-black font-sans"> <article class="p-1 border-2 border-black font-sans">
<h1 class="text-2xl font-extrabold"> <h1 class="text-2xl font-extrabold">
<a x-bind:href="recipe.showUrl" <a x-bind:href="recipe.showUrl"

View File

@ -9,7 +9,7 @@
</h1> </h1>
</x-slot> </x-slot>
<div class="flex flex-col-reverse justify-between md:flex-row md:space-x-4"> <div class="flex flex-col-reverse justify-between md:flex-row md:space-x-4">
<div class="flex-1" x-data="{showNutrientsSummary: false}"> <div class="flex-1" x-data="{ showNutrientsSummary: false }">
@if($recipe->time_total > 0) @if($recipe->time_total > 0)
<section class="flex justify-between mb-2 p-2 bg-gray-100 rounded max-w-3xl"> <section class="flex justify-between mb-2 p-2 bg-gray-100 rounded max-w-3xl">
<div> <div>
@ -31,7 +31,7 @@
{!! $recipe->description !!} {!! $recipe->description !!}
</section> </section>
@endif @endif
<section x-data="{showNutrientsSummary: false}"> <section x-data="{ showNutrientsSummary: false }">
<h1 class="mb-2 font-bold text-2xl"> <h1 class="mb-2 font-bold text-2xl">
Ingredients Ingredients
<span class="text-sm text-gray-500 hover:text-gray-700 hover:border-gray-300 font-normal cursor-pointer" <span class="text-sm text-gray-500 hover:text-gray-700 hover:border-gray-300 font-normal cursor-pointer"