Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.x] Upgrade VueJS to version 3 #666

Merged
merged 14 commits into from
Feb 15, 2021
9 changes: 4 additions & 5 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,15 @@ protected function installInertiaStack()
$this->updateNodePackages(function ($packages) {
return [
'@inertiajs/inertia' => '^0.8.2',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth bumping this to 0.8.4, given the recent axios vulnerability (see here).

Suggested change
'@inertiajs/inertia' => '^0.8.2',
'@inertiajs/inertia' => '^0.8.4',

'@inertiajs/inertia-vue' => '^0.5.4',
'@inertiajs/inertia-vue3' => '^0.3.5',
'@tailwindcss/forms' => '^0.2.1',
'@tailwindcss/typography' => '^0.3.0',
'portal-vue' => '^2.1.7',
'postcss-import' => '^12.0.1',
'tailwindcss' => '^2.0.1',
'autoprefixer' => '^10.0.2',
'vue' => '^2.5.17',
'vue-loader' => '^15.9.6',
'vue-template-compiler' => '^2.6.10',
'vue' => '^3.0.5',
'@vue/compiler-sfc' => '^3.0.5',
'vue-loader' => '^16.1.2',
] + $packages;
});

Expand Down
42 changes: 19 additions & 23 deletions stubs/inertia/resources/js/Jetstream/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,28 @@
</template>

<script>
export default {
model: {
prop: "checked",
event: "change",
},
export default {
emits: ['update:checked'],

props: {
checked: {
type: [Array, Boolean],
default: false,
},
value: {
default: null,
},
props: {
checked: {
type: [Array, Boolean],
default: false,
},
value: {
default: null,
},
},

computed: {
proxyChecked: {
get() {
return this.checked;
},
set(val) {
this.$emit("change", val);
},
computed: {
proxyChecked: {
get() {
return this.checked;
},
set(val) {
this.$emit("update:checked", val);
},
},
}
},
}
</script>

2 changes: 2 additions & 0 deletions stubs/inertia/resources/js/Jetstream/ConfirmationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import Modal from './Modal'

export default {
emits: ['close'],

components: {
Modal,
},
Expand Down
2 changes: 2 additions & 0 deletions stubs/inertia/resources/js/Jetstream/ConfirmsPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import JetSecondaryButton from './SecondaryButton'

export default {
emits: ['confirmed'],

props: {
title: {
default: 'Confirm Password',
Expand Down
2 changes: 2 additions & 0 deletions stubs/inertia/resources/js/Jetstream/DialogModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import Modal from './Modal'

export default {
emits: ['close'],

components: {
Modal,
},
Expand Down
4 changes: 0 additions & 4 deletions stubs/inertia/resources/js/Jetstream/Dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@
}
}

this.$once('hook:destroyed', () => {
document.removeEventListener('keydown', closeOnEscape)
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So where does this get removed now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops totally forgot about that, I will add it tommorow, this hook removed at first because the depreciation of $once function
but this willbe moved in the beforeUnmount lifecycle hook without the $once function

document.addEventListener('keydown', closeOnEscape)
},

Expand Down
2 changes: 2 additions & 0 deletions stubs/inertia/resources/js/Jetstream/FormSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import JetSectionTitle from './SectionTitle'

export default {
emits: ['submitted'],

components: {
JetSectionTitle,
},
Expand Down
6 changes: 4 additions & 2 deletions stubs/inertia/resources/js/Jetstream/Input.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<template>
<input class="border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm" :value="value" @input="$emit('input', $event.target.value)" ref="input">
<input class="border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm" :value="modelValue" @input="$emit('update:modelValue', $event.target.value)" ref="input">
</template>

<script>
export default {
props: ['value'],
props: ['modelValue'],

emits: ['update:modelValue'],

methods: {
focus() {
Expand Down
10 changes: 4 additions & 6 deletions stubs/inertia/resources/js/Jetstream/Modal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<portal to="modal">
<Teleport to="#modal">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested this, but do you really need the <div id="modal"></div>? I think you can just do to="body". Also, I'm pretty sure even Vue uses the lowercase version of <teleport> in their docs, so that might be more idiomatic.

Suggested change
<Teleport to="#modal">
<teleport to="body">

<transition leave-active-class="duration-200">
<div v-show="show" class="fixed inset-0 overflow-y-auto px-4 py-6 sm:px-0 z-50">
<transition enter-active-class="ease-out duration-300"
Expand All @@ -25,11 +25,13 @@
</transition>
</div>
</transition>
</portal>
</Teleport>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</Teleport>
</teleport>

</template>

<script>
export default {
emits: ['close'],

props: {
show: {
default: false
Expand Down Expand Up @@ -71,10 +73,6 @@
}

document.addEventListener('keydown', closeOnEscape)

this.$once('hook:destroyed', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However we solve this in the Dropdown.vue component, needs to also be done here.

document.removeEventListener('keydown', closeOnEscape)
})
},

computed: {
Expand Down
12 changes: 4 additions & 8 deletions stubs/inertia/resources/js/Layouts/AppLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
Switch Teams
</div>

<template v-for="team in $page.props.user.all_teams">
<form @submit.prevent="switchToTeam(team)" :key="team.id">
<template v-for="team in $page.props.user.all_teams" :key="team.id">
<form @submit.prevent="switchToTeam(team)">
<jet-dropdown-link as="button">
<div class="flex items-center">
<svg v-if="team.id == $page.props.user.current_team_id" class="mr-2 h-5 w-5 text-green-400" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" stroke="currentColor" viewBox="0 0 24 24"><path d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
Expand Down Expand Up @@ -198,8 +198,8 @@
Switch Teams
</div>

<template v-for="team in $page.props.user.all_teams">
<form @submit.prevent="switchToTeam(team)" :key="team.id">
<template v-for="team in $page.props.user.all_teams" :key="team.id">
<form @submit.prevent="switchToTeam(team)">
<jet-responsive-nav-link as="button">
<div class="flex items-center">
<svg v-if="team.id == $page.props.user.current_team_id" class="mr-2 h-5 w-5 text-green-400" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" stroke="currentColor" viewBox="0 0 24 24"><path d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
Expand All @@ -225,10 +225,6 @@
<main>
<slot></slot>
</main>

<!-- Modal Portal -->
<portal-target name="modal" multiple>
</portal-target>
</div>
</div>
</template>
Expand Down
4 changes: 2 additions & 2 deletions stubs/inertia/resources/js/Pages/API/ApiTokenManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div class="mt-2 grid grid-cols-1 md:grid-cols-2 gap-4">
<div v-for="permission in availablePermissions" :key="permission">
<label class="flex items-center">
<jet-checkbox :value="permission" v-model="createApiTokenForm.permissions"/>
<jet-checkbox :value="permission" v-model:checked="createApiTokenForm.permissions"/>
<span class="ml-2 text-sm text-gray-600">{{ permission }}</span>
</label>
</div>
Expand Down Expand Up @@ -122,7 +122,7 @@
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div v-for="permission in availablePermissions" :key="permission">
<label class="flex items-center">
<jet-checkbox :value="permission" v-model="updateApiTokenForm.permissions"/>
<jet-checkbox :value="permission" v-model:checked="updateApiTokenForm.permissions"/>
<span class="ml-2 text-sm text-gray-600">{{ permission }}</span>
</label>
</div>
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia/resources/js/Pages/Auth/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<div class="block mt-4">
<label class="flex items-center">
<jet-checkbox name="remember" v-model="form.remember" />
<jet-checkbox name="remember" v-model:checked="form.remember" />
<span class="ml-2 text-sm text-gray-600">Remember me</span>
</label>
</div>
Expand Down
2 changes: 1 addition & 1 deletion stubs/inertia/resources/js/Pages/Auth/Register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div class="mt-4" v-if="$page.props.jetstream.hasTermsAndPrivacyPolicyFeature">
<jet-label for="terms">
<div class="flex items-center">
<jet-checkbox name="terms" id="terms" v-model="form.terms" />
<jet-checkbox name="terms" id="terms" v-model:checked="form.terms"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space.

Suggested change
<jet-checkbox name="terms" id="terms" v-model:checked="form.terms"/>
<jet-checkbox name="terms" id="terms" v-model:checked="form.terms" />


<div class="ml-2">
I agree to the <a target="_blank" :href="route('terms.show')" class="underline text-sm text-gray-600 hover:text-gray-900">Terms of Service</a> and <a target="_blank" :href="route('policy.show')" class="underline text-sm text-gray-600 hover:text-gray-900">Privacy Policy</a>
Expand Down
26 changes: 11 additions & 15 deletions stubs/inertia/resources/js/app.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
require('./bootstrap');

// Import modules...
import Vue from 'vue';
import { App as InertiaApp, plugin as InertiaPlugin } from '@inertiajs/inertia-vue';
import PortalVue from 'portal-vue';
import { createApp, h } from 'vue';
import { App as InertiaApp, plugin as InertiaPlugin } from '@inertiajs/inertia-vue3';

Vue.mixin({ methods: { route } });
Vue.use(InertiaPlugin);
Vue.use(PortalVue);
const el = document.getElementById('app');

const app = document.getElementById('app');

new Vue({
render: (h) =>
createApp({
render: () =>
h(InertiaApp, {
props: {
initialPage: JSON.parse(app.dataset.page),
resolveComponent: (name) => require(`./Pages/${name}`).default,
},
initialPage: JSON.parse(el.dataset.page),
resolveComponent: (name) => require(`./Pages/${name}`).default,
}),
}).$mount(app);
})
.mixin({ methods: { route } })
.use(InertiaPlugin)
.mount(el);
3 changes: 3 additions & 0 deletions stubs/inertia/resources/views/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
</head>
<body class="font-sans antialiased">
@inertia

<!-- Modal Teleport -->
<div id="modal"></div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required, as per comment above.

Suggested change
<!-- Modal Teleport -->
<div id="modal"></div>

</body>
</html>