pref: Optimize client imports (#9506)

* pref: Optimize client imports

* split api?

* fix

* ✌️

* no vue split?

* Revert "no vue split?"

This reverts commit 27ccec971e2925184a58da65c3472655def2617c.

* function => const

* ✌️

* Revert "function => const"

This reverts commit 34f2feb224f65cc4fca090b29450adb00e85c2c5.

* function api
This commit is contained in:
tamaina 2023-01-17 17:36:18 +09:00 committed by GitHub
parent 424919ffd0
commit d456308653
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 17 deletions

View file

@ -1,5 +1,7 @@
// TODO: なんでもかんでもos.tsに突っ込むのやめたいのでよしなに分割する
import { pendingApiRequestsCount, api, apiGet } from '@/scripts/api';
export { pendingApiRequestsCount, api, apiGet };
import { Component, markRaw, Ref, ref, defineAsyncComponent } from 'vue';
import { EventEmitter } from 'eventemitter3';
import insertTextAtCursor from 'insert-text-at-cursor';
@ -7,9 +9,14 @@ import * as Misskey from 'misskey-js';
import { i18n } from './i18n';
import MkPostFormDialog from '@/components/MkPostFormDialog.vue';
import MkWaitingDialog from '@/components/MkWaitingDialog.vue';
import MkPageWindow from '@/components/MkPageWindow.vue'
import MkToast from '@/components/MkToast.vue';
import MkDialog from '@/components/MkDialog.vue';
import MkEmojiPickerDialog from '@/components/MkEmojiPickerDialog.vue';
import MkEmojiPickerWindow from '@/components/MkEmojiPickerWindow.vue';
import MkPopupMenu from '@/components/MkPopupMenu.vue';
import MkContextMenu from '@/components/MkContextMenu.vue';
import { MenuItem } from '@/types/menu';
import { pendingApiRequestsCount, api, apiGet } from '@/scripts/api';
export { pendingApiRequestsCount, api, apiGet };
export const apiWithDialog = ((
endpoint: string,
@ -124,7 +131,7 @@ export async function popup(component: Component, props: Record<string, any>, ev
}
export function pageWindow(path: string) {
popup(defineAsyncComponent(() => import('@/components/MkPageWindow.vue')), {
popup(MkPageWindow, {
initialPath: path,
}, {}, 'closed');
}
@ -136,7 +143,7 @@ export function modalPageWindow(path: string) {
}
export function toast(message: string) {
popup(defineAsyncComponent(() => import('@/components/MkToast.vue')), {
popup(MkToast, {
message,
}, {}, 'closed');
}
@ -147,7 +154,7 @@ export function alert(props: {
text?: string | null;
}): Promise<void> {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkDialog.vue')), props, {
popup(MkDialog, props, {
done: result => {
resolve();
},
@ -161,7 +168,7 @@ export function confirm(props: {
text?: string | null;
}): Promise<{ canceled: boolean }> {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkDialog.vue')), {
popup(MkDialog, {
...props,
showCancelButton: true,
}, {
@ -182,7 +189,7 @@ export function inputText(props: {
canceled: false; result: string;
}> {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkDialog.vue')), {
popup(MkDialog, {
title: props.title,
text: props.text,
input: {
@ -207,7 +214,7 @@ export function inputNumber(props: {
canceled: false; result: number;
}> {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkDialog.vue')), {
popup(MkDialog, {
title: props.title,
text: props.text,
input: {
@ -232,7 +239,7 @@ export function inputDate(props: {
canceled: false; result: Date;
}> {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkDialog.vue')), {
popup(MkDialog, {
title: props.title,
text: props.text,
input: {
@ -269,7 +276,7 @@ export function select<C = any>(props: {
canceled: false; result: C;
}> {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkDialog.vue')), {
popup(MkDialog, {
title: props.title,
text: props.text,
select: {
@ -291,7 +298,7 @@ export function success() {
window.setTimeout(() => {
showing.value = false;
}, 1000);
popup(defineAsyncComponent(() => import('@/components/MkWaitingDialog.vue')), {
popup(MkWaitingDialog, {
success: true,
showing: showing,
}, {
@ -303,7 +310,7 @@ export function success() {
export function waiting() {
return new Promise((resolve, reject) => {
const showing = ref(true);
popup(defineAsyncComponent(() => import('@/components/MkWaitingDialog.vue')), {
popup(MkWaitingDialog, {
success: false,
showing: showing,
}, {
@ -366,7 +373,7 @@ export async function selectDriveFolder(multiple: boolean) {
export async function pickEmoji(src: HTMLElement | null, opts) {
return new Promise((resolve, reject) => {
popup(defineAsyncComponent(() => import('@/components/MkEmojiPickerDialog.vue')), {
popup(MkEmojiPickerDialog, {
src,
...opts,
}, {
@ -431,7 +438,7 @@ export async function openEmojiPicker(src?: HTMLElement, opts, initialTextarea:
characterData: false,
});
openingEmojiPicker = await popup(defineAsyncComponent(() => import('@/components/MkEmojiPickerWindow.vue')), {
openingEmojiPicker = await popup(MkEmojiPickerWindow, {
src,
...opts,
}, {
@ -454,7 +461,7 @@ export function popupMenu(items: MenuItem[] | Ref<MenuItem[]>, src?: HTMLElement
}) {
return new Promise((resolve, reject) => {
let dispose;
popup(defineAsyncComponent(() => import('@/components/MkPopupMenu.vue')), {
popup(MkPopupMenu, {
items,
src,
width: options?.width,
@ -478,7 +485,7 @@ export function contextMenu(items: MenuItem[] | Ref<MenuItem[]>, ev: MouseEvent)
ev.preventDefault();
return new Promise((resolve, reject) => {
let dispose;
popup(defineAsyncComponent(() => import('@/components/MkContextMenu.vue')), {
popup(MkContextMenu, {
items,
ev,
}, {

View file

@ -97,6 +97,7 @@ export default defineConfig(({ command, mode }) => {
output: {
manualChunks: {
vue: ['vue'],
photoswipe: ['photoswipe', 'photoswipe/lightbox', 'photoswipe/style.css'],
},
},
},