forked from mirror/misskey
a6a91fec3a
* add: safeFloatParserを追加
* fix: 欠けていた型を追加
* refactor: pageBlockTypesをjson-schemaに移植
* refactor: components/global内の型エラーが出ている箇所を修正
* lint: fix null check style
* refactor: fix type error
* refactor: fix some type errors
* fix: 翻訳が抜けていた箇所を修正
* refactor: getJsonSchemaで正しいスキーマが返されるように修正
* fix: MkChartの型エラーとbytesオプションが機能していない問題を修正
* fix(misskey-js): `drive`->`folderUpdated`のpayloadの型が間違っていたのを修正
* refactor: fix some type errors
* change: Captcha読み込み中の文言をLoadingに変更
* refactor(backend/misskey-js): MainEventの型を改善
* refactor: chartjs-plugin-gradientが二重でpluginに登録されていたのを修正
* update: misskey-js.api.md
* refactor: fix some type errors
* fix: backendのtypecheckが落ちていたのを修正
* update: misskey-js.api.md
* add: json-schemaのnoteにpollの型定義を追加
* refactor: noteのjson-schemaの型を改善
* refactor: MkPoll
* refactor: fix some type errors
* change: UserLiteにisLockedを持たせるように
* fix: notificationスキーマにroleが含まれていないのを修正
* Revert "change: UserLiteにisLockedを持たせるように"
This reverts commit 1bb0c8e7a9
.
* fix: フォロー通知から鍵垢へのフォローを行うと処理中のまま止まってしまう問題を修正
* refactor: noteスキーマのvisibilityにenumを追加
* change: deepCloneのCloneableTypeにundefinedを追加
* refactor: fix some type errors
* refactor: `allowEmpty: false`を使用していた箇所を`minLength: 1`に置き換え
* enhance: API 'retension' のresponseの型を追加
* fix: Chart関連のtooltipが正しい位置に表示されない問題を修正
* refactor: fix some type errors
* fix: 型情報が不足していたのを修正
* enhance: announcementスキーマにenumを追加
* enhance: ロールポリシーの型定義をRoleServiceからjson-schemaに移植
* refactor: policiesを`ref: RolePolicies`に統一
* fix: API `meta` のレスポンスの型にpoliciesが含まれていないのを修正
* refactor: fix some type errors
* fix: backendのlintが落ちているのを修正
* fix: MkFoldableSectionの開閉時のanimationが適用されていない問題を修正
* fix: backendのtypecheckが落ちているのを修正
* update: run build-misskey-js-with-types
* fix: MkDialogのmount時に文字数制限の判定が行われない問題を修正
* update: CHANGELOG.md
* refactor: MkUserSelectDialogの型を改善
* fix: deepCloneでundefinedはcloneしないように (#9207)
* change: frontendのcloneをbackend側にも反映
* update: CHANGELOG.md
* fix: RoleServiceからPackを通して型RolePoliciesに依存させないように
* Update packages/frontend/src/scripts/get-note-summary.ts
* revert RoleService.ts changes
* change: optional chaining -> non-null assertion
* remove: unused import
* fix: propsで渡されたuserがUserLiteの場合に意図しない動作になってしまうのを修正
* change: fix null check style
* refactor: fix type error
* change: fix null check style
* Update packages/frontend/src/components/MkDrive.vue
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
* refactor: css moduleでglobalを使わないように
* refactor: roleのiconUrlは必ず存在するものとして扱うように
* enhance: MenuButtonのactiveにcomputedを受け付けられるように
* Update packages/frontend/src/components/MkNotePreview.vue
* Update MkWindow.vue
* refactor: notification.noteは必ず存在するものとして扱うように
* Update packages/frontend/src/components/MkNotification.vue
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
* fix: MkSignupDialogでdoneのemit時にresを含んでいなかったのを修正
* Update packages/frontend/src/scripts/clone.ts
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
* refactor: 不要な返り値の型を削除
* refactor: 不要なnullチェックを削除
* update: misskey-js-autogen
* update: clone.ts
* refactor
* Update MkNotification.vue
* Update MkNotification.vue
* ✌️
* Update MkNotification.vue
* Update MkNotification.vue
* Update MkNotification.vue
* Update MkNotifications.vue
* Update MkUserSetupDialog.Profile.vue
* Update MkUserCardMini.vue
* ✌️
* Update MkMenu.vue
---------
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
251 lines
6.7 KiB
Vue
251 lines
6.7 KiB
Vue
<!--
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
-->
|
|
|
|
<template>
|
|
<MkModal ref="modal" :preferType="'dialog'" :zPriority="'high'" @click="done(true)" @closed="emit('closed')">
|
|
<div :class="$style.root">
|
|
<div v-if="icon" :class="$style.icon">
|
|
<i :class="icon"></i>
|
|
</div>
|
|
<div
|
|
v-else-if="!input && !select"
|
|
:class="[$style.icon, {
|
|
[$style.type_success]: type === 'success',
|
|
[$style.type_error]: type === 'error',
|
|
[$style.type_warning]: type === 'warning',
|
|
[$style.type_info]: type === 'info',
|
|
}]"
|
|
>
|
|
<i v-if="type === 'success'" :class="$style.iconInner" class="ti ti-check"></i>
|
|
<i v-else-if="type === 'error'" :class="$style.iconInner" class="ti ti-circle-x"></i>
|
|
<i v-else-if="type === 'warning'" :class="$style.iconInner" class="ti ti-alert-triangle"></i>
|
|
<i v-else-if="type === 'info'" :class="$style.iconInner" class="ti ti-info-circle"></i>
|
|
<i v-else-if="type === 'question'" :class="$style.iconInner" class="ti ti-help-circle"></i>
|
|
<MkLoading v-else-if="type === 'waiting'" :class="$style.iconInner" :em="true"/>
|
|
</div>
|
|
<header v-if="title" :class="$style.title"><Mfm :text="title"/></header>
|
|
<div v-if="text" :class="$style.text"><Mfm :text="text"/></div>
|
|
<MkInput v-if="input" v-model="inputValue" autofocus :type="input.type || 'text'" :placeholder="input.placeholder || undefined" :autocomplete="input.autocomplete" @keydown="onInputKeydown">
|
|
<template v-if="input.type === 'password'" #prefix><i class="ti ti-lock"></i></template>
|
|
<template #caption>
|
|
<span v-if="okButtonDisabledReason === 'charactersExceeded'" v-text="i18n.tsx._dialog.charactersExceeded({ current: (inputValue as string)?.length ?? 0, max: input.maxLength ?? 'NaN' })"/>
|
|
<span v-else-if="okButtonDisabledReason === 'charactersBelow'" v-text="i18n.tsx._dialog.charactersBelow({ current: (inputValue as string)?.length ?? 0, min: input.minLength ?? 'NaN' })"/>
|
|
</template>
|
|
</MkInput>
|
|
<MkSelect v-if="select" v-model="selectedValue" autofocus>
|
|
<template v-if="select.items">
|
|
<option v-for="item in select.items" :value="item.value">{{ item.text }}</option>
|
|
</template>
|
|
<template v-else>
|
|
<optgroup v-for="groupedItem in select.groupedItems" :label="groupedItem.label">
|
|
<option v-for="item in groupedItem.items" :value="item.value">{{ item.text }}</option>
|
|
</optgroup>
|
|
</template>
|
|
</MkSelect>
|
|
<div v-if="(showOkButton || showCancelButton) && !actions" :class="$style.buttons">
|
|
<MkButton v-if="showOkButton" data-cy-modal-dialog-ok inline primary rounded :autofocus="!input && !select" :disabled="okButtonDisabledReason" @click="ok">{{ okText ?? ((showCancelButton || input || select) ? i18n.ts.ok : i18n.ts.gotIt) }}</MkButton>
|
|
<MkButton v-if="showCancelButton || input || select" data-cy-modal-dialog-cancel inline rounded @click="cancel">{{ cancelText ?? i18n.ts.cancel }}</MkButton>
|
|
</div>
|
|
<div v-if="actions" :class="$style.buttons">
|
|
<MkButton v-for="action in actions" :key="action.text" inline rounded :primary="action.primary" :danger="action.danger" @click="() => { action.callback(); modal?.close(); }">{{ action.text }}</MkButton>
|
|
</div>
|
|
</div>
|
|
</MkModal>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { onBeforeUnmount, onMounted, ref, shallowRef, computed } from 'vue';
|
|
import MkModal from '@/components/MkModal.vue';
|
|
import MkButton from '@/components/MkButton.vue';
|
|
import MkInput from '@/components/MkInput.vue';
|
|
import MkSelect from '@/components/MkSelect.vue';
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
type Input = {
|
|
type: 'text' | 'number' | 'password' | 'email' | 'url' | 'date' | 'time' | 'search' | 'datetime-local';
|
|
placeholder?: string | null;
|
|
autocomplete?: string;
|
|
default: string | number | null;
|
|
minLength?: number;
|
|
maxLength?: number;
|
|
};
|
|
|
|
type Select = {
|
|
items: {
|
|
value: string;
|
|
text: string;
|
|
}[];
|
|
groupedItems: {
|
|
label: string;
|
|
items: {
|
|
value: string;
|
|
text: string;
|
|
}[];
|
|
}[];
|
|
default: string | null;
|
|
};
|
|
|
|
const props = withDefaults(defineProps<{
|
|
type?: 'success' | 'error' | 'warning' | 'info' | 'question' | 'waiting';
|
|
title: string;
|
|
text?: string;
|
|
input?: Input;
|
|
select?: Select;
|
|
icon?: string;
|
|
actions?: {
|
|
text: string;
|
|
primary?: boolean,
|
|
danger?: boolean,
|
|
callback: (...args: any[]) => void;
|
|
}[];
|
|
showOkButton?: boolean;
|
|
showCancelButton?: boolean;
|
|
cancelableByBgClick?: boolean;
|
|
okText?: string;
|
|
cancelText?: string;
|
|
}>(), {
|
|
type: 'info',
|
|
showOkButton: true,
|
|
showCancelButton: false,
|
|
cancelableByBgClick: true,
|
|
});
|
|
|
|
const emit = defineEmits<{
|
|
(ev: 'done', v: { canceled: boolean; result: any }): void;
|
|
(ev: 'closed'): void;
|
|
}>();
|
|
|
|
const modal = shallowRef<InstanceType<typeof MkModal>>();
|
|
|
|
const inputValue = ref<string | number | null>(props.input?.default ?? null);
|
|
const selectedValue = ref(props.select?.default ?? null);
|
|
|
|
const okButtonDisabledReason = computed<null | 'charactersExceeded' | 'charactersBelow'>(() => {
|
|
if (props.input) {
|
|
if (props.input.minLength) {
|
|
if (inputValue.value == null || (inputValue.value as string).length < props.input.minLength) {
|
|
return 'charactersBelow';
|
|
}
|
|
}
|
|
if (props.input.maxLength) {
|
|
if (inputValue.value && (inputValue.value as string).length > props.input.maxLength) {
|
|
return 'charactersExceeded';
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
});
|
|
|
|
function done(canceled: boolean, result?) {
|
|
emit('done', { canceled, result });
|
|
modal.value?.close();
|
|
}
|
|
|
|
async function ok() {
|
|
if (!props.showOkButton) return;
|
|
|
|
const result =
|
|
props.input ? inputValue.value :
|
|
props.select ? selectedValue.value :
|
|
true;
|
|
done(false, result);
|
|
}
|
|
|
|
function cancel() {
|
|
done(true);
|
|
}
|
|
|
|
/*
|
|
function onBgClick() {
|
|
if (props.cancelableByBgClick) cancel();
|
|
}
|
|
*/
|
|
function onKeydown(evt: KeyboardEvent) {
|
|
if (evt.key === 'Escape') cancel();
|
|
}
|
|
|
|
function onInputKeydown(evt: KeyboardEvent) {
|
|
if (evt.key === 'Enter') {
|
|
evt.preventDefault();
|
|
evt.stopPropagation();
|
|
ok();
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
document.addEventListener('keydown', onKeydown);
|
|
});
|
|
|
|
onBeforeUnmount(() => {
|
|
document.removeEventListener('keydown', onKeydown);
|
|
});
|
|
</script>
|
|
|
|
<style lang="scss" module>
|
|
.root {
|
|
position: relative;
|
|
margin: auto;
|
|
padding: 32px;
|
|
min-width: 320px;
|
|
max-width: 480px;
|
|
box-sizing: border-box;
|
|
text-align: center;
|
|
background: var(--panel);
|
|
border-radius: 16px;
|
|
}
|
|
|
|
.icon {
|
|
font-size: 24px;
|
|
|
|
& + .title {
|
|
margin-top: 8px;
|
|
}
|
|
}
|
|
|
|
.iconInner {
|
|
display: block;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.type_info {
|
|
color: #55c4dd;
|
|
}
|
|
|
|
.type_success {
|
|
color: var(--success);
|
|
}
|
|
|
|
.type_error {
|
|
color: var(--error);
|
|
}
|
|
|
|
.type_warning {
|
|
color: var(--warn);
|
|
}
|
|
|
|
.title {
|
|
margin: 0 0 8px 0;
|
|
font-weight: bold;
|
|
font-size: 1.1em;
|
|
|
|
& + .text {
|
|
margin-top: 8px;
|
|
}
|
|
}
|
|
|
|
.text {
|
|
margin: 16px 0 0 0;
|
|
}
|
|
|
|
.buttons {
|
|
margin-top: 16px;
|
|
display: flex;
|
|
gap: 8px;
|
|
flex-wrap: wrap;
|
|
justify-content: center;
|
|
}
|
|
</style>
|