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

View File

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