2021-02-27 05:08:34 +01:00
|
|
|
|
// TODO: なんでもかんでもos.tsに突っ込むのやめたいのでよしなに分割する
|
|
|
|
|
|
2024-03-28 17:26:52 +01:00
|
|
|
|
import { EventEmitter } from "eventemitter3";
|
|
|
|
|
import { type entities, api as firefishApi } from "firefish-js";
|
|
|
|
|
import insertTextAtCursor from "insert-text-at-cursor";
|
|
|
|
|
import type { Component, Ref } from "vue";
|
|
|
|
|
import { defineAsyncComponent, markRaw, ref } from "vue";
|
|
|
|
|
import { i18n } from "./i18n";
|
2024-03-30 17:30:50 +01:00
|
|
|
|
import MkDialog from "@/components/MkDialog.vue";
|
|
|
|
|
import MkPostFormDialog from "@/components/MkPostFormDialog.vue";
|
|
|
|
|
import MkToast from "@/components/MkToast.vue";
|
|
|
|
|
import MkWaitingDialog from "@/components/MkWaitingDialog.vue";
|
|
|
|
|
import { apiUrl, url } from "@/config";
|
|
|
|
|
import { me } from "@/me";
|
|
|
|
|
import type { MenuItem } from "@/types/menu";
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
|
|
|
|
export const pendingApiRequestsCount = ref(0);
|
|
|
|
|
|
2024-02-12 16:40:46 +01:00
|
|
|
|
const apiClient = new firefishApi.APIClient({
|
2021-05-27 10:15:08 +02:00
|
|
|
|
origin: url,
|
|
|
|
|
});
|
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
|
export const api = ((
|
|
|
|
|
endpoint: string,
|
|
|
|
|
data: Record<string, any> = {},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
token?: string | null | undefined,
|
2023-10-22 10:44:32 +02:00
|
|
|
|
useToken = true,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
) => {
|
2020-10-17 13:12:00 +02:00
|
|
|
|
pendingApiRequestsCount.value++;
|
|
|
|
|
|
|
|
|
|
const onFinally = () => {
|
|
|
|
|
pendingApiRequestsCount.value--;
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-07 03:06:45 +01:00
|
|
|
|
const authorizationToken = token ?? me?.token ?? undefined;
|
2023-01-13 05:40:33 +01:00
|
|
|
|
const authorization = authorizationToken
|
|
|
|
|
? `Bearer ${authorizationToken}`
|
|
|
|
|
: undefined;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
2022-07-19 00:49:40 +02:00
|
|
|
|
const promise = new Promise((resolve, reject) => {
|
2023-09-02 01:27:33 +02:00
|
|
|
|
fetch(endpoint.includes("://") ? endpoint : `${apiUrl}/${endpoint}`, {
|
2023-06-24 06:22:44 +02:00
|
|
|
|
method: "POST",
|
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
|
credentials: "omit",
|
|
|
|
|
cache: "no-cache",
|
2023-10-02 09:43:48 +02:00
|
|
|
|
headers: authorization && useToken ? { authorization } : {},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
})
|
2023-01-13 05:40:33 +01:00
|
|
|
|
.then(async (res) => {
|
|
|
|
|
const body = res.status === 204 ? null : await res.json();
|
|
|
|
|
|
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
resolve(body);
|
|
|
|
|
} else if (res.status === 204) {
|
|
|
|
|
resolve();
|
|
|
|
|
} else {
|
|
|
|
|
reject(body.error);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(reject);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
promise.then(onFinally, onFinally);
|
|
|
|
|
|
|
|
|
|
return promise;
|
2021-05-27 10:15:08 +02:00
|
|
|
|
}) as typeof apiClient.request;
|
2022-06-25 11:26:31 +02:00
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
|
export const apiGet = ((
|
|
|
|
|
endpoint: string,
|
|
|
|
|
data: Record<string, any> = {},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
token?: string | null | undefined,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
) => {
|
2022-06-25 11:26:31 +02:00
|
|
|
|
pendingApiRequestsCount.value++;
|
|
|
|
|
|
|
|
|
|
const onFinally = () => {
|
|
|
|
|
pendingApiRequestsCount.value--;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const query = new URLSearchParams(data);
|
|
|
|
|
|
2024-03-07 03:06:45 +01:00
|
|
|
|
const authorizationToken = token ?? me?.token ?? undefined;
|
2023-01-13 05:40:33 +01:00
|
|
|
|
const authorization = authorizationToken
|
|
|
|
|
? `Bearer ${authorizationToken}`
|
|
|
|
|
: undefined;
|
2022-07-19 00:49:40 +02:00
|
|
|
|
|
2022-06-25 11:26:31 +02:00
|
|
|
|
const promise = new Promise((resolve, reject) => {
|
|
|
|
|
// Send request
|
|
|
|
|
fetch(`${apiUrl}/${endpoint}?${query}`, {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
method: "GET",
|
|
|
|
|
credentials: "omit",
|
|
|
|
|
cache: "default",
|
2022-07-20 18:40:23 +02:00
|
|
|
|
headers: authorization ? { authorization } : {},
|
2023-01-13 05:40:33 +01:00
|
|
|
|
})
|
|
|
|
|
.then(async (res) => {
|
|
|
|
|
const body = res.status === 204 ? null : await res.json();
|
|
|
|
|
|
|
|
|
|
if (res.status === 200) {
|
|
|
|
|
resolve(body);
|
|
|
|
|
} else if (res.status === 204) {
|
|
|
|
|
resolve();
|
|
|
|
|
} else {
|
|
|
|
|
reject(body.error);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(reject);
|
2022-06-25 11:26:31 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
promise.then(onFinally, onFinally);
|
|
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
|
}) as typeof apiClient.request;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
2021-05-27 10:15:08 +02:00
|
|
|
|
export const apiWithDialog = ((
|
2020-10-18 03:11:34 +02:00
|
|
|
|
endpoint: string,
|
|
|
|
|
data: Record<string, any> = {},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
token?: string | null | undefined,
|
2021-05-27 10:15:08 +02:00
|
|
|
|
) => {
|
2020-10-18 03:11:34 +02:00
|
|
|
|
const promise = api(endpoint, data, token);
|
2022-05-26 15:53:09 +02:00
|
|
|
|
promiseDialog(promise, null, (err) => {
|
2021-11-18 15:36:04 +01:00
|
|
|
|
alert({
|
2023-01-13 05:40:33 +01:00
|
|
|
|
type: "error",
|
|
|
|
|
text: err.message + "\n" + (err as any).id,
|
2020-10-18 03:21:02 +02:00
|
|
|
|
});
|
|
|
|
|
});
|
2020-10-18 03:11:34 +02:00
|
|
|
|
|
|
|
|
|
return promise;
|
2021-05-27 10:15:08 +02:00
|
|
|
|
}) as typeof api;
|
2020-10-18 03:11:34 +02:00
|
|
|
|
|
|
|
|
|
export function promiseDialog<T extends Promise<any>>(
|
|
|
|
|
promise: T,
|
2021-01-03 15:58:24 +01:00
|
|
|
|
onSuccess?: ((res: any) => void) | null,
|
2022-05-26 15:53:09 +02:00
|
|
|
|
onFailure?: ((err: Error) => void) | null,
|
2023-06-24 06:22:44 +02:00
|
|
|
|
text?: string,
|
2020-10-18 03:11:34 +02:00
|
|
|
|
): T {
|
2020-10-17 13:12:00 +02:00
|
|
|
|
const showing = ref(true);
|
2020-10-18 03:11:34 +02:00
|
|
|
|
const success = ref(false);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
|
promise
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (onSuccess) {
|
2020-10-17 13:12:00 +02:00
|
|
|
|
showing.value = false;
|
2023-01-13 05:40:33 +01:00
|
|
|
|
onSuccess(res);
|
|
|
|
|
} else {
|
|
|
|
|
success.value = true;
|
|
|
|
|
window.setTimeout(() => {
|
|
|
|
|
showing.value = false;
|
|
|
|
|
}, 1000);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
showing.value = false;
|
|
|
|
|
if (onFailure) {
|
|
|
|
|
onFailure(err);
|
|
|
|
|
} else {
|
|
|
|
|
alert({
|
|
|
|
|
type: "error",
|
|
|
|
|
text: err,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
2020-10-19 12:29:04 +02:00
|
|
|
|
// NOTE: dynamic importすると挙動がおかしくなる(showingの変更が伝播しない)
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
|
|
|
|
MkWaitingDialog,
|
|
|
|
|
{
|
2023-09-02 01:27:33 +02:00
|
|
|
|
success,
|
|
|
|
|
showing,
|
|
|
|
|
text,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
},
|
|
|
|
|
{},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-01 05:38:48 +01:00
|
|
|
|
let popupIdCount = 0;
|
2023-01-13 05:40:33 +01:00
|
|
|
|
export const popups = ref([]) as Ref<
|
|
|
|
|
{
|
|
|
|
|
id: any;
|
|
|
|
|
component: any;
|
|
|
|
|
props: Record<string, any>;
|
|
|
|
|
}[]
|
|
|
|
|
>;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
2021-12-18 04:12:47 +01:00
|
|
|
|
const zIndexes = {
|
|
|
|
|
low: 1000000,
|
|
|
|
|
middle: 2000000,
|
|
|
|
|
high: 3000000,
|
|
|
|
|
};
|
2023-01-13 05:40:33 +01:00
|
|
|
|
export function claimZIndex(
|
2023-06-24 06:22:44 +02:00
|
|
|
|
priority: "low" | "middle" | "high" = "low",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
): number {
|
2021-12-18 04:12:47 +01:00
|
|
|
|
zIndexes[priority] += 100;
|
|
|
|
|
return zIndexes[priority];
|
2021-12-10 10:20:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-15 22:19:33 +02:00
|
|
|
|
let uniqueId = 0;
|
|
|
|
|
export function getUniqueId(): string {
|
2023-05-17 05:31:13 +02:00
|
|
|
|
return uniqueId++ + "";
|
2023-05-15 22:19:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
|
export async function popup(
|
|
|
|
|
component: Component,
|
|
|
|
|
props: Record<string, any>,
|
|
|
|
|
events = {},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
disposeEvent?: string,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
) {
|
2020-10-17 13:12:00 +02:00
|
|
|
|
markRaw(component);
|
|
|
|
|
|
2020-11-01 05:38:48 +01:00
|
|
|
|
const id = ++popupIdCount;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
const dispose = () => {
|
|
|
|
|
// このsetTimeoutが無いと挙動がおかしくなる(autocompleteが閉じなくなる)。Vueのバグ?
|
2022-01-16 02:14:14 +01:00
|
|
|
|
window.setTimeout(() => {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popups.value = popups.value.filter((popup) => popup.id !== id);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
}, 0);
|
|
|
|
|
};
|
|
|
|
|
const state = {
|
|
|
|
|
component,
|
|
|
|
|
props,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
events: disposeEvent
|
|
|
|
|
? {
|
|
|
|
|
...events,
|
|
|
|
|
[disposeEvent]: dispose,
|
2024-03-28 06:25:33 +01:00
|
|
|
|
}
|
2023-01-13 05:40:33 +01:00
|
|
|
|
: events,
|
2020-10-17 13:12:00 +02:00
|
|
|
|
id,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
popups.value.push(state);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
dispose,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-03 02:06:19 +01:00
|
|
|
|
export function pageWindow(path: string) {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkPageWindow.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
initialPath: path,
|
|
|
|
|
},
|
|
|
|
|
{},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-11 14:09:35 +02:00
|
|
|
|
export function modalPageWindow(path: string) {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkModalPageWindow.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
initialPath: path,
|
|
|
|
|
},
|
|
|
|
|
{},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2021-04-11 14:09:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-28 12:07:37 +01:00
|
|
|
|
export function toast(message: string) {
|
2023-02-19 04:48:25 +01:00
|
|
|
|
popup(
|
|
|
|
|
MkToast,
|
|
|
|
|
{
|
|
|
|
|
message,
|
|
|
|
|
},
|
|
|
|
|
{},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-02-19 04:48:25 +01:00
|
|
|
|
);
|
2021-11-28 12:07:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-18 10:45:58 +01:00
|
|
|
|
export function alert(props: {
|
2023-02-19 04:48:25 +01:00
|
|
|
|
type?: "error" | "info" | "success" | "warning" | "waiting" | "question";
|
2021-08-22 06:16:23 +02:00
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
2023-09-27 09:46:43 +02:00
|
|
|
|
isPlaintext?: boolean;
|
2021-11-18 10:45:58 +01:00
|
|
|
|
}): Promise<void> {
|
2020-10-17 13:12:00 +02:00
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-06-02 23:52:44 +02:00
|
|
|
|
if (props.text == null && props.type === "error") {
|
2023-06-03 00:45:05 +02:00
|
|
|
|
props.text = i18n.ts.somethingHappened;
|
2023-06-02 23:52:44 +02:00
|
|
|
|
}
|
2023-02-19 04:48:25 +01:00
|
|
|
|
popup(
|
|
|
|
|
MkDialog,
|
|
|
|
|
props,
|
|
|
|
|
{
|
|
|
|
|
done: (result) => {
|
|
|
|
|
resolve();
|
|
|
|
|
},
|
2021-11-18 10:45:58 +01:00
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-02-19 04:48:25 +01:00
|
|
|
|
);
|
2021-11-18 10:45:58 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function confirm(props: {
|
2023-02-19 04:48:25 +01:00
|
|
|
|
type: "error" | "info" | "success" | "warning" | "waiting" | "question";
|
2021-11-18 10:45:58 +01:00
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
2023-02-19 01:28:50 +01:00
|
|
|
|
okText?: string;
|
|
|
|
|
cancelText?: string;
|
2023-09-27 09:46:43 +02:00
|
|
|
|
isPlaintext?: boolean;
|
2021-11-18 10:45:58 +01:00
|
|
|
|
}): Promise<{ canceled: boolean }> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-02-19 04:48:25 +01:00
|
|
|
|
popup(
|
|
|
|
|
MkDialog,
|
|
|
|
|
{
|
|
|
|
|
...props,
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
done: (result) => {
|
2023-09-02 01:27:33 +02:00
|
|
|
|
resolve(result || { canceled: true });
|
2023-02-19 04:48:25 +01:00
|
|
|
|
},
|
2023-01-13 05:40:33 +01:00
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-02-19 04:48:25 +01:00
|
|
|
|
);
|
2021-11-18 10:45:58 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-26 07:44:38 +02:00
|
|
|
|
export function yesno(props: {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
type: "error" | "info" | "success" | "warning" | "waiting" | "question";
|
2022-10-26 07:44:38 +02:00
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
2023-09-27 09:46:43 +02:00
|
|
|
|
isPlaintext?: boolean;
|
2022-10-26 07:44:38 +02:00
|
|
|
|
}): Promise<{ canceled: boolean }> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkDialog.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
...props,
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
isYesNo: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
done: (result) => {
|
2023-09-02 01:27:33 +02:00
|
|
|
|
resolve(result || { canceled: true });
|
2023-01-13 05:40:33 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2022-10-26 07:44:38 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-18 10:45:58 +01:00
|
|
|
|
export function inputText(props: {
|
2023-06-08 19:01:51 +02:00
|
|
|
|
type?: "text" | "email" | "password" | "url" | "search";
|
2021-11-18 10:45:58 +01:00
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
|
|
|
|
placeholder?: string | null;
|
2023-06-16 01:12:32 +02:00
|
|
|
|
autocomplete?: string;
|
2021-11-18 10:45:58 +01:00
|
|
|
|
default?: string | null;
|
2023-06-16 01:12:32 +02:00
|
|
|
|
minLength?: number;
|
|
|
|
|
maxLength?: number;
|
2023-01-13 05:40:33 +01:00
|
|
|
|
}): Promise<
|
|
|
|
|
| { canceled: true; result: undefined }
|
|
|
|
|
| {
|
|
|
|
|
canceled: false;
|
|
|
|
|
result: string;
|
|
|
|
|
}
|
|
|
|
|
> {
|
2021-11-18 10:45:58 +01:00
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-06-16 01:12:32 +02:00
|
|
|
|
MkDialog,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
title: props.title,
|
|
|
|
|
text: props.text,
|
|
|
|
|
input: {
|
|
|
|
|
type: props.type,
|
|
|
|
|
placeholder: props.placeholder,
|
2023-06-16 01:12:32 +02:00
|
|
|
|
autocomplete: props.autocomplete,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
default: props.default,
|
2023-06-16 01:12:32 +02:00
|
|
|
|
minLength: props.minLength,
|
|
|
|
|
maxLength: props.maxLength,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
done: (result) => {
|
2023-09-02 01:27:33 +02:00
|
|
|
|
resolve(result || { canceled: true });
|
2023-01-13 05:40:33 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2021-11-18 10:45:58 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-19 08:22:28 +01:00
|
|
|
|
export function inputParagraph(props: {
|
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
|
|
|
|
placeholder?: string | null;
|
|
|
|
|
default?: string | null;
|
|
|
|
|
}): Promise<
|
|
|
|
|
| { canceled: true; result: undefined }
|
|
|
|
|
| {
|
|
|
|
|
canceled: false;
|
|
|
|
|
result: string;
|
|
|
|
|
}
|
|
|
|
|
> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkDialog.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-03-19 08:22:28 +01:00
|
|
|
|
{
|
|
|
|
|
title: props.title,
|
|
|
|
|
text: props.text,
|
|
|
|
|
input: {
|
|
|
|
|
type: "paragraph",
|
|
|
|
|
placeholder: props.placeholder,
|
|
|
|
|
default: props.default,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
done: (result) => {
|
2023-09-02 01:27:33 +02:00
|
|
|
|
resolve(result || { canceled: true });
|
2023-03-19 08:22:28 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-03-19 08:22:28 +01:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-18 10:45:58 +01:00
|
|
|
|
export function inputNumber(props: {
|
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
|
|
|
|
placeholder?: string | null;
|
|
|
|
|
default?: number | null;
|
2023-06-16 01:12:32 +02:00
|
|
|
|
autocomplete?: string;
|
2023-01-13 05:40:33 +01:00
|
|
|
|
}): Promise<
|
|
|
|
|
| { canceled: true; result: undefined }
|
|
|
|
|
| {
|
|
|
|
|
canceled: false;
|
|
|
|
|
result: number;
|
|
|
|
|
}
|
|
|
|
|
> {
|
2021-11-18 10:45:58 +01:00
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkDialog.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
title: props.title,
|
|
|
|
|
text: props.text,
|
|
|
|
|
input: {
|
|
|
|
|
type: "number",
|
|
|
|
|
placeholder: props.placeholder,
|
2023-06-16 01:12:32 +02:00
|
|
|
|
autocomplete: props.autocomplete,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
default: props.default,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
done: (result) => {
|
2023-09-02 01:27:33 +02:00
|
|
|
|
resolve(result || { canceled: true });
|
2023-01-13 05:40:33 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2021-11-18 10:45:58 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function inputDate(props: {
|
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
|
|
|
|
placeholder?: string | null;
|
|
|
|
|
default?: Date | null;
|
2023-01-13 05:40:33 +01:00
|
|
|
|
}): Promise<
|
|
|
|
|
| { canceled: true; result: undefined }
|
|
|
|
|
| {
|
|
|
|
|
canceled: false;
|
|
|
|
|
result: Date;
|
|
|
|
|
}
|
|
|
|
|
> {
|
2021-11-18 10:45:58 +01:00
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-06-16 01:12:32 +02:00
|
|
|
|
MkDialog,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
title: props.title,
|
|
|
|
|
text: props.text,
|
|
|
|
|
input: {
|
|
|
|
|
type: "date",
|
|
|
|
|
placeholder: props.placeholder,
|
|
|
|
|
default: props.default,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
done: (result) => {
|
|
|
|
|
resolve(
|
2023-06-16 01:12:32 +02:00
|
|
|
|
result
|
|
|
|
|
? {
|
|
|
|
|
result: new Date(result.result),
|
|
|
|
|
canceled: false,
|
2024-03-28 06:25:33 +01:00
|
|
|
|
}
|
2023-06-24 06:22:44 +02:00
|
|
|
|
: { canceled: true },
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2021-11-18 10:45:58 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
|
export function select<C = any>(
|
|
|
|
|
props: {
|
|
|
|
|
title?: string | null;
|
|
|
|
|
text?: string | null;
|
|
|
|
|
default?: string | null;
|
|
|
|
|
} & (
|
|
|
|
|
| {
|
|
|
|
|
items: {
|
|
|
|
|
value: C;
|
|
|
|
|
text: string;
|
|
|
|
|
}[];
|
|
|
|
|
}
|
|
|
|
|
| {
|
|
|
|
|
groupedItems: {
|
|
|
|
|
label: string;
|
|
|
|
|
items: {
|
|
|
|
|
value: C;
|
|
|
|
|
text: string;
|
|
|
|
|
}[];
|
|
|
|
|
}[];
|
|
|
|
|
}
|
2023-06-24 06:22:44 +02:00
|
|
|
|
),
|
2023-01-13 05:40:33 +01:00
|
|
|
|
): Promise<
|
|
|
|
|
| { canceled: true; result: undefined }
|
|
|
|
|
| {
|
|
|
|
|
canceled: false;
|
|
|
|
|
result: C;
|
|
|
|
|
}
|
|
|
|
|
> {
|
2021-11-18 10:45:58 +01:00
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-06-16 01:12:32 +02:00
|
|
|
|
MkDialog,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
title: props.title,
|
|
|
|
|
text: props.text,
|
|
|
|
|
select: {
|
|
|
|
|
items: props.items,
|
|
|
|
|
groupedItems: props.groupedItems,
|
|
|
|
|
default: props.default,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
done: (result) => {
|
2023-09-02 01:27:33 +02:00
|
|
|
|
resolve(result || { canceled: true });
|
2023-01-13 05:40:33 +01:00
|
|
|
|
},
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-16 01:12:32 +02:00
|
|
|
|
export function success(): Promise<void> {
|
2020-10-17 13:12:00 +02:00
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const showing = ref(true);
|
2022-01-16 02:14:14 +01:00
|
|
|
|
window.setTimeout(() => {
|
2020-10-17 13:12:00 +02:00
|
|
|
|
showing.value = false;
|
|
|
|
|
}, 1000);
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-06-16 01:12:32 +02:00
|
|
|
|
MkWaitingDialog,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
success: true,
|
2023-09-02 01:27:33 +02:00
|
|
|
|
showing,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
done: () => resolve(),
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-16 01:12:32 +02:00
|
|
|
|
export function waiting(): Promise<void> {
|
2020-10-17 13:12:00 +02:00
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const showing = ref(true);
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-06-16 01:12:32 +02:00
|
|
|
|
MkWaitingDialog,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
success: false,
|
2023-09-02 01:27:33 +02:00
|
|
|
|
showing,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
done: () => resolve(),
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function form(title, form) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkFormDialog.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{ title, form },
|
|
|
|
|
{
|
|
|
|
|
done: (result) => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
},
|
2020-10-17 13:12:00 +02:00
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function selectUser() {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkUserSelectDialog.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
ok: (user) => {
|
|
|
|
|
resolve(user);
|
|
|
|
|
},
|
2020-10-17 13:12:00 +02:00
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 04:53:46 +02:00
|
|
|
|
export async function selectLocalUser() {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
popup(
|
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkUserSelectLocalDialog.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
ok: (user) => {
|
|
|
|
|
resolve(user);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"closed",
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-12 16:40:46 +01:00
|
|
|
|
export async function selectInstance(): Promise<entities.Instance> {
|
2023-02-12 02:20:17 +01:00
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkInstanceSelectDialog.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-02-12 02:20:17 +01:00
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
ok: (instance) => {
|
|
|
|
|
resolve(instance);
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-02-12 02:20:17 +01:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
|
export async function selectDriveFile(multiple: boolean) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkDriveSelectDialog.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
type: "file",
|
|
|
|
|
multiple,
|
2020-10-17 13:12:00 +02:00
|
|
|
|
},
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
done: (files) => {
|
|
|
|
|
if (files) {
|
|
|
|
|
resolve(multiple ? files : files[0]);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function selectDriveFolder(multiple: boolean) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkDriveSelectDialog.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
type: "folder",
|
|
|
|
|
multiple,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
done: (folders) => {
|
|
|
|
|
if (folders) {
|
|
|
|
|
resolve(multiple ? folders : folders[0]);
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-10-17 13:12:00 +02:00
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-28 04:20:42 +01:00
|
|
|
|
export async function pickEmoji(src: HTMLElement | null, opts) {
|
2020-10-17 13:12:00 +02:00
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkEmojiPickerDialog.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
src,
|
|
|
|
|
...opts,
|
2020-10-17 13:12:00 +02:00
|
|
|
|
},
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
done: (emoji) => {
|
|
|
|
|
resolve(emoji);
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
|
export async function cropImage(
|
2024-02-12 16:40:46 +01:00
|
|
|
|
image: entities.DriveFile,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
options: {
|
|
|
|
|
aspectRatio: number;
|
2023-06-24 06:22:44 +02:00
|
|
|
|
},
|
2024-02-12 16:40:46 +01:00
|
|
|
|
): Promise<entities.DriveFile> {
|
2022-06-11 08:45:44 +02:00
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkCropperDialog.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
file: image,
|
|
|
|
|
aspectRatio: options.aspectRatio,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
ok: (x) => {
|
|
|
|
|
resolve(x);
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
"closed",
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2022-06-11 08:45:44 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
|
type AwaitType<T> = T extends Promise<infer U>
|
|
|
|
|
? U
|
|
|
|
|
: T extends (...args: any[]) => Promise<infer V>
|
2024-03-28 06:25:33 +01:00
|
|
|
|
? V
|
|
|
|
|
: T;
|
2024-03-30 17:30:50 +01:00
|
|
|
|
let openingEmojiPicker: AwaitType<ReturnType<typeof popup>> | null = null;
|
|
|
|
|
let activeTextarea: HTMLTextAreaElement | HTMLInputElement | null = null;
|
2023-01-13 05:40:33 +01:00
|
|
|
|
export async function openEmojiPicker(
|
|
|
|
|
src?: HTMLElement,
|
|
|
|
|
opts,
|
2023-06-24 06:22:44 +02:00
|
|
|
|
initialTextarea: typeof activeTextarea,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
) {
|
2021-02-27 05:08:34 +01:00
|
|
|
|
if (openingEmojiPicker) return;
|
|
|
|
|
|
|
|
|
|
activeTextarea = initialTextarea;
|
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
|
const textareas = document.querySelectorAll("textarea, input");
|
2021-02-27 05:08:34 +01:00
|
|
|
|
for (const textarea of Array.from(textareas)) {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
textarea.addEventListener("focus", () => {
|
2021-02-27 05:08:34 +01:00
|
|
|
|
activeTextarea = textarea;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
|
const observer = new MutationObserver((records) => {
|
2021-02-27 05:08:34 +01:00
|
|
|
|
for (const record of records) {
|
2023-01-13 05:40:33 +01:00
|
|
|
|
for (const node of Array.from(record.addedNodes).filter(
|
2023-06-24 06:22:44 +02:00
|
|
|
|
(node) => node instanceof HTMLElement,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
) as HTMLElement[]) {
|
2023-04-02 09:07:48 +02:00
|
|
|
|
const textareas = node.querySelectorAll("textarea, input");
|
2023-01-13 05:40:33 +01:00
|
|
|
|
for (const textarea of Array.from(textareas).filter(
|
2023-06-24 06:22:44 +02:00
|
|
|
|
(textarea) => textarea.dataset.preventEmojiInsert == null,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
)) {
|
2023-06-24 06:22:44 +02:00
|
|
|
|
if (document.activeElement === textarea) activeTextarea = textarea;
|
2023-01-13 05:40:33 +01:00
|
|
|
|
textarea.addEventListener("focus", () => {
|
2021-02-27 05:16:59 +01:00
|
|
|
|
activeTextarea = textarea;
|
|
|
|
|
});
|
2021-02-27 05:08:34 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
observer.observe(document.body, {
|
|
|
|
|
childList: true,
|
|
|
|
|
subtree: true,
|
|
|
|
|
attributes: false,
|
|
|
|
|
characterData: false,
|
|
|
|
|
});
|
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
|
openingEmojiPicker = await popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkEmojiPickerDialog.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
src,
|
|
|
|
|
...opts,
|
2022-11-07 05:17:59 +01:00
|
|
|
|
},
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
chosen: (emoji) => {
|
|
|
|
|
insertTextAtCursor(activeTextarea, emoji);
|
|
|
|
|
},
|
|
|
|
|
done: (emoji) => {
|
|
|
|
|
insertTextAtCursor(activeTextarea, emoji);
|
|
|
|
|
},
|
|
|
|
|
closed: () => {
|
|
|
|
|
openingEmojiPicker!.dispose();
|
|
|
|
|
openingEmojiPicker = null;
|
|
|
|
|
observer.disconnect();
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
},
|
2023-01-13 05:40:33 +01:00
|
|
|
|
);
|
2021-02-27 05:08:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
|
export function popupMenu(
|
|
|
|
|
items: MenuItem[] | Ref<MenuItem[]>,
|
|
|
|
|
src?: HTMLElement,
|
|
|
|
|
options?: {
|
|
|
|
|
align?: string;
|
|
|
|
|
width?: number;
|
|
|
|
|
viaKeyboard?: boolean;
|
2023-06-08 19:01:51 +02:00
|
|
|
|
noReturnFocus?: boolean;
|
2023-06-24 06:22:44 +02:00
|
|
|
|
},
|
2023-01-13 05:40:33 +01:00
|
|
|
|
) {
|
2024-04-04 12:48:23 +02:00
|
|
|
|
return new Promise<void>((resolve, _reject) => {
|
|
|
|
|
let dispose: () => void;
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkPopupMenu.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
items,
|
|
|
|
|
src,
|
|
|
|
|
width: options?.width,
|
|
|
|
|
align: options?.align,
|
|
|
|
|
viaKeyboard: options?.viaKeyboard,
|
2023-06-08 19:01:51 +02:00
|
|
|
|
noReturnFocus: options?.noReturnFocus,
|
2020-10-17 13:12:00 +02:00
|
|
|
|
},
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
closed: () => {
|
|
|
|
|
resolve();
|
|
|
|
|
dispose();
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
},
|
2023-01-13 05:40:33 +01:00
|
|
|
|
).then((res) => {
|
2020-11-03 08:21:28 +01:00
|
|
|
|
dispose = res.dispose;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
|
export function contextMenu(
|
|
|
|
|
items: MenuItem[] | Ref<MenuItem[]>,
|
2023-06-24 06:22:44 +02:00
|
|
|
|
ev: MouseEvent,
|
2023-01-13 05:40:33 +01:00
|
|
|
|
) {
|
2020-10-17 13:12:00 +02:00
|
|
|
|
ev.preventDefault();
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2020-11-03 07:22:55 +01:00
|
|
|
|
let dispose;
|
2023-01-13 05:40:33 +01:00
|
|
|
|
popup(
|
2023-05-17 05:31:13 +02:00
|
|
|
|
defineAsyncComponent({
|
|
|
|
|
loader: () => import("@/components/MkContextMenu.vue"),
|
|
|
|
|
loadingComponent: MkWaitingDialog,
|
|
|
|
|
delay: 1000,
|
|
|
|
|
}),
|
2023-01-13 05:40:33 +01:00
|
|
|
|
{
|
|
|
|
|
items,
|
|
|
|
|
ev,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
closed: () => {
|
|
|
|
|
resolve();
|
|
|
|
|
dispose();
|
|
|
|
|
},
|
2023-06-24 06:22:44 +02:00
|
|
|
|
},
|
2023-01-13 05:40:33 +01:00
|
|
|
|
).then((res) => {
|
2020-11-03 08:21:28 +01:00
|
|
|
|
dispose = res.dispose;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 14:09:40 +01:00
|
|
|
|
export function post(props: Record<string, any> = {}) {
|
2020-10-17 13:12:00 +02:00
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
// NOTE: MkPostFormDialogをdynamic importするとiOSでテキストエリアに自動フォーカスできない
|
2020-10-19 07:46:32 +02:00
|
|
|
|
// NOTE: ただ、dynamic importしない場合、MkPostFormDialogインスタンスが使いまわされ、
|
|
|
|
|
// Vueが渡されたコンポーネントに内部的に__propsというプロパティを生やす影響で、
|
|
|
|
|
// 複数のpost formを開いたときに場合によってはエラーになる
|
|
|
|
|
// もちろん複数のpost formを開けること自体Misskeyサイドのバグなのだが
|
2020-11-03 07:22:55 +01:00
|
|
|
|
let dispose;
|
|
|
|
|
popup(MkPostFormDialog, props, {
|
2020-10-17 13:12:00 +02:00
|
|
|
|
closed: () => {
|
|
|
|
|
resolve();
|
|
|
|
|
dispose();
|
|
|
|
|
},
|
2023-01-13 05:40:33 +01:00
|
|
|
|
}).then((res) => {
|
2020-11-03 08:21:28 +01:00
|
|
|
|
dispose = res.dispose;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const deckGlobalEvents = new EventEmitter();
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
export function checkExistence(fileData: ArrayBuffer): Promise<any> {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const data = new FormData();
|
|
|
|
|
data.append('md5', getMD5(fileData));
|
|
|
|
|
|
|
|
|
|
os.api('drive/files/find-by-hash', {
|
|
|
|
|
md5: getMD5(fileData)
|
|
|
|
|
}).then(resp => {
|
|
|
|
|
resolve(resp.length > 0 ? resp[0] : null);
|
|
|
|
|
});
|
|
|
|
|
});
|
2023-09-02 01:27:33 +02:00
|
|
|
|
} */
|