From 5b35be3f05d91ce0c2c11bbf75fc3f33dcb0069b Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Sun, 2 Mar 2025 14:19:38 -0500 Subject: [PATCH 1/5] Code split vue-toasted --- resources/js/bootstrap/statamic.js | 16 +---------- resources/js/components/Toasts.js | 43 ++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/resources/js/bootstrap/statamic.js b/resources/js/bootstrap/statamic.js index fc55ffca32..1e2f927637 100644 --- a/resources/js/bootstrap/statamic.js +++ b/resources/js/bootstrap/statamic.js @@ -16,9 +16,6 @@ import 'floating-vue/dist/style.css'; import VCalendar from 'v-calendar'; import 'v-calendar/style.css'; import Toasts from '../components/Toasts'; -import Toasted from '@hoppscotch/vue-toasted'; -import { useToasted } from '@hoppscotch/vue-toasted'; -import '@hoppscotch/vue-toasted/style.css'; import 'vue-final-modal/style.css'; import PortalVue from 'portal-vue'; import Keys from '../components/keys/Keys'; @@ -129,17 +126,6 @@ export default { this.$app.use(VueClickAway); this.$app.use(FloatingVue, { disposeTimeout: 30000, distance: 10 }); this.$app.use(VCalendar); - this.$app.use(Toasted, { - position: 'bottom-left', - duration: 3500, - theme: 'statamic', - action: { - text: '×', - onClick: (e, toastObject) => { - toastObject.goAway(0); - }, - }, - }); const portals = markRaw(new Portals()); @@ -164,7 +150,7 @@ export default { $portals: portals, $stacks: new Stacks(portals), $hooks: new Hooks(), - $toast: new Toasts(useToasted()), + $toast: new Toasts(this.$app), $bard: new Bard(), $reveal: new Reveal(), $echo: new Echo(), diff --git a/resources/js/components/Toasts.js b/resources/js/components/Toasts.js index aae10c1de4..832dbc8cb7 100644 --- a/resources/js/components/Toasts.js +++ b/resources/js/components/Toasts.js @@ -1,6 +1,9 @@ export default class Toasts { - constructor(toasted) { - this.toasted = toasted; + #app; + #plugin; + + constructor(app) { + this.#app = app; } registerInterceptor(axios) { @@ -35,8 +38,32 @@ export default class Toasts { return opts; } - success(message, opts) { - this.toasted.success( + async #toasted() { + return new Promise(async (resolve) => { + if (!this.#plugin) { + const { default: Toasted, useToasted } = await import('@hoppscotch/vue-toasted'); + import('@hoppscotch/vue-toasted/style.css'); + + this.#app.use(Toasted, { + position: 'bottom-left', + duration: 3500, + theme: 'statamic', + action: { + text: '×', + onClick: (e, toastObject) => { + toastObject.goAway(0); + }, + }, + }); + this.#plugin = useToasted(); + } + + resolve(this.#plugin); + }); + } + + async success(message, opts) { + (await this.#toasted()).success( message, this.#normalizeToastOptions({ iconPack: 'callback', @@ -50,8 +77,8 @@ export default class Toasts { ); } - info(message, opts) { - this.toasted.show( + async info(message, opts) { + (await this.#toasted()).show( message, this.#normalizeToastOptions({ iconPack: 'callback', @@ -65,8 +92,8 @@ export default class Toasts { ); } - error(message, opts) { - this.toasted.error( + async error(message, opts) { + (await this.#toasted()).error( message, this.#normalizeToastOptions({ iconPack: 'callback', From 9393670c7f32f68c816e70f857ef8cc55a752195 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Sun, 2 Mar 2025 14:36:44 -0500 Subject: [PATCH 2/5] Code split vue-final-modal --- resources/js/bootstrap/components.js | 7 +++++-- resources/js/bootstrap/statamic.js | 1 - resources/js/components/Modal.vue | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/resources/js/bootstrap/components.js b/resources/js/bootstrap/components.js index d2d5dbadeb..c988125856 100644 --- a/resources/js/bootstrap/components.js +++ b/resources/js/bootstrap/components.js @@ -52,7 +52,6 @@ import CreateEntryButton from '../components/entries/CreateEntryButton.vue'; import Popover from '../components/Popover.vue'; import Portal from '../components/portals/Portal.vue'; import PermissionTree from '../components/roles/PermissionTree.vue'; -import Modal from '../components/Modal.vue'; import ConfirmationModal from '../components/modals/ConfirmationModal.vue'; import FavoriteCreator from '../components/FavoriteCreator.vue'; import KeyboardShortcutsModal from '../components/modals/KeyboardShortcutsModal.vue'; @@ -62,6 +61,7 @@ import Stack from '../components/stacks/Stack.vue'; import StackTest from '../components/stacks/StackTest.vue'; import CodeBlock from '../components/CodeBlock.vue'; import BlueprintResetter from '../components/blueprints/BlueprintResetter.vue'; +import { defineAsyncComponent } from 'vue'; export default function registerGlobalComponents(app) { // Core @@ -136,7 +136,10 @@ export default function registerGlobalComponents(app) { app.component('role-permission-tree', PermissionTree); // Modals - app.component('modal', Modal); + app.component( + 'modal', + defineAsyncComponent(() => import('../components/Modal.vue')), + ); app.component('confirmation-modal', ConfirmationModal); app.component('favorite-creator', FavoriteCreator); app.component('keyboard-shortcuts-modal', KeyboardShortcutsModal); diff --git a/resources/js/bootstrap/statamic.js b/resources/js/bootstrap/statamic.js index 1e2f927637..2a8032442d 100644 --- a/resources/js/bootstrap/statamic.js +++ b/resources/js/bootstrap/statamic.js @@ -16,7 +16,6 @@ import 'floating-vue/dist/style.css'; import VCalendar from 'v-calendar'; import 'v-calendar/style.css'; import Toasts from '../components/Toasts'; -import 'vue-final-modal/style.css'; import PortalVue from 'portal-vue'; import Keys from '../components/keys/Keys'; import FieldActions from '../components/field-actions/FieldActions.js'; diff --git a/resources/js/components/Modal.vue b/resources/js/components/Modal.vue index 36635b7a86..4aac0143e1 100644 --- a/resources/js/components/Modal.vue +++ b/resources/js/components/Modal.vue @@ -11,6 +11,7 @@