This commit is contained in:
syuilo 2020-09-13 23:22:17 +09:00
parent 5447ecb306
commit d6f9453c38
21 changed files with 68 additions and 37 deletions

View File

@ -210,6 +210,7 @@ export default defineComponent({
showMenu() { showMenu() {
os.menu({ os.menu({
items: this.getMenu(), items: this.getMenu(),
}, {
source: this.$refs.menu, source: this.$refs.menu,
}); });
}, },

View File

@ -108,6 +108,7 @@ export default defineComponent({
icon: faTrashAlt, icon: faTrashAlt,
action: this.deleteFile action: this.deleteFile
}], }],
}, {
source: ev.currentTarget || ev.target, source: ev.currentTarget || ev.target,
}); });
} }

View File

@ -468,9 +468,10 @@ export default defineComponent({
renote: this.appearNote, renote: this.appearNote,
}); });
} }
}] }],
source: this.$refs.renoteButton,
viaKeyboard viaKeyboard
}, {
source: this.$refs.renoteButton,
}); });
}, },
@ -684,8 +685,9 @@ export default defineComponent({
os.menu({ os.menu({
items: menu, items: menu,
source: this.$refs.menuButton,
viaKeyboard viaKeyboard
}, {
source: this.$refs.menuButton,
}).then(this.focus); }).then(this.focus);
}, },
@ -702,8 +704,9 @@ export default defineComponent({
this.isDeleted = true; this.isDeleted = true;
} }
}], }],
source: this.$refs.renoteTime,
viaKeyboard: viaKeyboard viaKeyboard: viaKeyboard
}, {
source: this.$refs.renoteTime,
}); });
}, },

View File

@ -94,7 +94,8 @@ export default defineComponent({
icon: faTimesCircle, icon: faTimesCircle,
action: () => { this.detachMedia(file.id) } action: () => { this.detachMedia(file.id) }
}], }],
source: ev.currentTarget || ev.target }, {
source: ev.currentTarget || ev.target,
}).then(() => this.menu = null); }).then(() => this.menu = null);
} }
} }

View File

@ -366,7 +366,8 @@ export default defineComponent({
icon: faLink, icon: faLink,
action: () => { this.chooseFileFromUrl() } action: () => { this.chooseFileFromUrl() }
}], }],
source: ev.currentTarget || ev.target }, {
source: ev.currentTarget || ev.target,
}); });
}, },
@ -625,6 +626,7 @@ export default defineComponent({
}); });
} }
})), })),
}, {
source: ev.currentTarget || ev.target, source: ev.currentTarget || ev.target,
}); });
} }

View File

@ -176,6 +176,7 @@ export default defineComponent({
align: 'left', align: 'left',
fixed: true, fixed: true,
width: 240, width: 240,
}, {
source: ev.currentTarget || ev.target, source: ev.currentTarget || ev.target,
}); });
}, },
@ -183,6 +184,7 @@ export default defineComponent({
align: 'left', align: 'left',
fixed: true, fixed: true,
width: 240, width: 240,
}, {
source: ev.currentTarget || ev.target, source: ev.currentTarget || ev.target,
}); });
}, },
@ -238,6 +240,7 @@ export default defineComponent({
align: 'left', align: 'left',
fixed: true, fixed: true,
width: 200, width: 200,
}, {
source: ev.currentTarget || ev.target, source: ev.currentTarget || ev.target,
}); });
}, },
@ -271,6 +274,7 @@ export default defineComponent({
align: 'left', align: 'left',
fixed: true, fixed: true,
width: 200, width: 200,
}, {
source: ev.currentTarget || ev.target, source: ev.currentTarget || ev.target,
}); });
}, },

View File

@ -113,13 +113,24 @@ export function modal(component: Component, props: Record<string, any>, events =
} }
export function dialog(props: Record<string, any>, opts?: { cancelableByBgClick: boolean; }) { export function dialog(props: Record<string, any>, opts?: { cancelableByBgClick: boolean; }) {
return modal(defineAsyncComponent(() => import('@/components/dialog.vue')), props, {}, { cancelableByBgClick: opts?.cancelableByBgClick }).then(result => { return new PCancelable((resolve, reject, onCancel) => {
const dialog = modal(defineAsyncComponent(() => import('@/components/dialog.vue')), props, {}, { cancelableByBgClick: opts?.cancelableByBgClick });
dialog.then(result => {
if (result) { if (result) {
return result; resolve(result);
} else { } else {
return { canceled: true }; resolve({ canceled: true });
} }
}); });
dialog.catch(reject);
onCancel.shouldReject = false;
onCancel(() => {
dialog.cancel();
});
});
} }
export function menu(props: Record<string, any>, opts?: { source: any; }) { export function menu(props: Record<string, any>, opts?: { source: any; }) {

View File

@ -111,7 +111,7 @@ export default defineComponent({
}, },
setBannerImage(e) { setBannerImage(e) {
selectFile(this, e.currentTarget || e.target, null, false).then(file => { selectFile(e.currentTarget || e.target, null, false).then(file => {
this.bannerId = file.id; this.bannerId = file.id;
}); });
}, },

View File

@ -70,7 +70,8 @@ export default defineComponent({
}], }],
fixed: true, fixed: true,
noCenter: true, noCenter: true,
source: ev.currentTarget || ev.target }, {
source: ev.currentTarget || ev.target,
}).then(() => { }).then(() => {
this.menuOpened = false; this.menuOpened = false;
}); });

View File

@ -192,7 +192,8 @@ export default defineComponent({
}, antennaItems.length > 0 ? null : undefined, ...antennaItems, listItems.length > 0 ? null : undefined, ...listItems, channelItems.length > 0 ? null : undefined, ...channelItems], }, antennaItems.length > 0 ? null : undefined, ...antennaItems, listItems.length > 0 ? null : undefined, ...listItems, channelItems.length > 0 ? null : undefined, ...channelItems],
fixed: true, fixed: true,
noCenter: true, noCenter: true,
source: ev.currentTarget || ev.target }, {
source: ev.currentTarget || ev.target,
}).then(() => { }).then(() => {
this.menuOpened = false; this.menuOpened = false;
}); });

View File

@ -127,7 +127,7 @@ export default defineComponent({
methods: { methods: {
async add(e) { async add(e) {
const files = await selectFile(this, e.currentTarget || e.target, null, true); const files = await selectFile(e.currentTarget || e.target, null, true);
const dialog = os.dialog({ const dialog = os.dialog({
type: 'waiting', type: 'waiting',

View File

@ -127,6 +127,7 @@ export default defineComponent({
action: () => { this.startGroup() } action: () => { this.startGroup() }
}], }],
noCenter: true, noCenter: true,
}, {
source: ev.currentTarget || ev.target, source: ev.currentTarget || ev.target,
}); });
}, },

View File

@ -158,7 +158,7 @@ export default defineComponent({
}, },
chooseFile(e) { chooseFile(e) {
selectFile(this, e.currentTarget || e.target, this.$t('selectFile'), false).then(file => { selectFile(e.currentTarget || e.target, this.$t('selectFile'), false).then(file => {
this.file = file; this.file = file;
}); });
}, },

View File

@ -120,7 +120,7 @@ export default defineComponent({
methods: { methods: {
changeAvatar(e) { changeAvatar(e) {
selectFile(this, e.currentTarget || e.target, this.$t('avatar')).then(file => { selectFile(e.currentTarget || e.target, this.$t('avatar')).then(file => {
os.api('i/update', { os.api('i/update', {
avatarId: file.id, avatarId: file.id,
}); });
@ -128,7 +128,7 @@ export default defineComponent({
}, },
changeBanner(e) { changeBanner(e) {
selectFile(this, e.currentTarget || e.target, this.$t('banner')).then(file => { selectFile(e.currentTarget || e.target, this.$t('banner')).then(file => {
os.api('i/update', { os.api('i/update', {
bannerId: file.id, bannerId: file.id,
}); });

View File

@ -188,7 +188,7 @@ export default defineComponent({
methods: { methods: {
setWallpaper(e) { setWallpaper(e) {
selectFile(this, e.currentTarget || e.target, null, false).then(file => { selectFile(e.currentTarget || e.target, null, false).then(file => {
this.wallpaper = file.url; this.wallpaper = file.url;
}); });
}, },

View File

@ -224,7 +224,7 @@ export default defineComponent({
}, },
chooseImage(key, e) { chooseImage(key, e) {
selectFile(this, e.currentTarget || e.target, null, false).then(file => { selectFile(e.currentTarget || e.target, null, false).then(file => {
room.updateProp(key, `/proxy/?${urlQuery({ url: file.thumbnailUrl })}`); room.updateProp(key, `/proxy/?${urlQuery({ url: file.thumbnailUrl })}`);
this.$refs.preview.selected(room.getSelectedObject()); this.$refs.preview.selected(room.getSelectedObject());
this.changed = true; this.changed = true;

View File

@ -279,6 +279,7 @@ export default defineComponent({
type: 'refConst', key: '', type: 'refConst', key: '',
}), }),
},], },],
}, {
source: e.currentTarget || e.target, source: e.currentTarget || e.target,
}); });
}); });

View File

@ -1,4 +1,4 @@
export function selectDriveFile($root: any, multiple) { export function selectDriveFile(multiple) {
return new Promise((res, rej) => { return new Promise((res, rej) => {
import('@/components/drive-window.vue').then(dialog => { import('@/components/drive-window.vue').then(dialog => {
const w = $root.new(dialog, { const w = $root.new(dialog, {

View File

@ -1,4 +1,4 @@
export function selectDriveFolder($root: any, multiple) { export function selectDriveFolder(multiple) {
return new Promise((res, rej) => { return new Promise((res, rej) => {
import('@/components/drive-window.vue').then(dialog => { import('@/components/drive-window.vue').then(dialog => {
const w = $root.new(dialog, { const w = $root.new(dialog, {

View File

@ -1,18 +1,20 @@
import { faUpload, faCloud } from '@fortawesome/free-solid-svg-icons'; import { faUpload, faCloud } from '@fortawesome/free-solid-svg-icons';
import { selectDriveFile } from './select-drive-file'; import { selectDriveFile } from './select-drive-file';
import { apiUrl } from '@/config'; import { apiUrl } from '@/config';
import { store } from '@/store';
import * as os from '@/os';
import { locale } from '@/i18n';
// TODO: component引数は消せる(各種操作がstoreに移動し、かつstoreが複数ファイルで共有されるようになったため) export function selectFile(src: any, label: string | null, multiple = false) {
export function selectFile(component: any, src: any, label: string | null, multiple = false) {
return new Promise((res, rej) => { return new Promise((res, rej) => {
const chooseFileFromPc = () => { const chooseFileFromPc = () => {
const input = document.createElement('input'); const input = document.createElement('input');
input.type = 'file'; input.type = 'file';
input.multiple = multiple; input.multiple = multiple;
input.onchange = () => { input.onchange = () => {
const dialog = component.os.dialog({ const dialog = os.dialog({
type: 'waiting', type: 'waiting',
text: component.$t('uploading') + '...', text: locale['uploading'] + '...',
showOkButton: false, showOkButton: false,
showCancelButton: false, showCancelButton: false,
cancelableByBgClick: false cancelableByBgClick: false
@ -21,7 +23,7 @@ export function selectFile(component: any, src: any, label: string | null, multi
const promises = Array.from(input.files).map(file => new Promise((ok, err) => { const promises = Array.from(input.files).map(file => new Promise((ok, err) => {
const data = new FormData(); const data = new FormData();
data.append('file', file); data.append('file', file);
data.append('i', component.$store.state.i.token); data.append('i', store.state.i.token);
fetch(apiUrl + '/drive/files/create', { fetch(apiUrl + '/drive/files/create', {
method: 'POST', method: 'POST',
@ -35,12 +37,12 @@ export function selectFile(component: any, src: any, label: string | null, multi
Promise.all(promises).then(driveFiles => { Promise.all(promises).then(driveFiles => {
res(multiple ? driveFiles : driveFiles[0]); res(multiple ? driveFiles : driveFiles[0]);
}).catch(e => { }).catch(e => {
component.os.dialog({ os.dialog({
type: 'error', type: 'error',
text: e text: e
}); });
}).finally(() => { }).finally(() => {
dialog.close(); dialog.cancel();
}); });
// 一応廃棄 // 一応廃棄
@ -55,7 +57,7 @@ export function selectFile(component: any, src: any, label: string | null, multi
}; };
const chooseFileFromDrive = () => { const chooseFileFromDrive = () => {
selectDriveFile(component.$root, multiple).then(files => { selectDriveFile(multiple).then(files => {
res(files); res(files);
}); });
}; };
@ -65,24 +67,25 @@ export function selectFile(component: any, src: any, label: string | null, multi
}; };
component.os.menu({ os.menu({
items: [label ? { items: [label ? {
text: label, text: label,
type: 'label' type: 'label'
} : undefined, { } : undefined, {
text: component.$t('upload'), text: locale['upload'],
icon: faUpload, icon: faUpload,
action: chooseFileFromPc action: chooseFileFromPc
}, { }, {
text: component.$t('fromDrive'), text: locale['fromDrive'],
icon: faCloud, icon: faCloud,
action: chooseFileFromDrive action: chooseFileFromDrive
}, /*{ }, /*{
text: component.$t('fromUrl'), text: locale('fromUrl'),
icon: faLink, icon: faLink,
action: chooseFileFromUrl action: chooseFileFromUrl
}*/], }*/],
source: src }, {
source: src,
}); });
}); });
} }

View File

@ -108,7 +108,8 @@ export default defineComponent({
action: () => { this.setSrc('global') } action: () => { this.setSrc('global') }
}, antennaItems.length > 0 ? null : undefined, ...antennaItems, listItems.length > 0 ? null : undefined, ...listItems], }, antennaItems.length > 0 ? null : undefined, ...antennaItems, listItems.length > 0 ? null : undefined, ...listItems],
noCenter: true, noCenter: true,
source: ev.currentTarget || ev.target }, {
source: ev.currentTarget || ev.target,
}).then(() => { }).then(() => {
this.menuOpened = false; this.menuOpened = false;
}); });