Merge branch 'notification-read-api' into swn

This commit is contained in:
tamaina 2021-12-11 00:57:22 +09:00
commit b4954fe7c2
635 changed files with 4867 additions and 4789 deletions

View file

@ -1 +0,0 @@
export const isDeviceTouch = 'maxTouchPoints' in navigator && navigator.maxTouchPoints > 0;

View file

@ -1,8 +1,9 @@
import * as os from '@/os';
import { i18n } from '@/i18n';
import { defaultStore } from '@/store';
import { DriveFile } from 'misskey-js/built/entities';
export function selectFile(src: any, label: string | null, multiple = false) {
function select(src: any, label: string | null, multiple: boolean): Promise<DriveFile | DriveFile[]> {
return new Promise((res, rej) => {
const chooseFileFromPc = () => {
const input = document.createElement('input');
@ -86,3 +87,11 @@ export function selectFile(src: any, label: string | null, multiple = false) {
}], src);
});
}
export function selectFile(src: any, label: string | null = null): Promise<DriveFile> {
return select(src, label, false) as Promise<DriveFile>;
}
export function selectFiles(src: any, label: string | null = null): Promise<DriveFile[]> {
return select(src, label, true) as Promise<DriveFile[]>;
}

View file

@ -0,0 +1,19 @@
const isTouchSupported = 'maxTouchPoints' in navigator && navigator.maxTouchPoints > 0;
export let isTouchUsing = false;
export let isScreenTouching = false;
if (isTouchSupported) {
window.addEventListener('touchstart', () => {
// maxTouchPointsなどでの判定だけだと、「タッチ機能付きディスプレイを使っているがマウスでしか操作しない」場合にも
// タッチで使っていると判定されてしまうため、実際に一度でもタッチされたらtrueにする
isTouchUsing = true;
isScreenTouching = true;
}, { passive: true });
window.addEventListener('touchend', () => {
isScreenTouching = false;
}, { passive: true });
}

View file

@ -1,9 +1,16 @@
import { isScreenTouching } from '@/os';
import { Ref, ref } from 'vue';
import { isDeviceTouch } from './is-device-touch';
import { Ref, ref, watch } from 'vue';
export function useTooltip(onShow: (showing: Ref<boolean>) => void) {
export function useTooltip(
elRef: Ref<HTMLElement | { $el: HTMLElement } | null | undefined>,
onShow: (showing: Ref<boolean>) => void,
): void {
let isHovering = false;
// iOS(Androidも)では、要素をタップした直後に(おせっかいで)mouseoverイベントを発火させたりするため、それを無視するためのフラグ
// 無視しないと、画面に触れてないのにツールチップが出たりし、ユーザビリティが損なわれる
// TODO: 一度でもタップすると二度とマウスでツールチップ出せなくなるのをどうにかする 定期的にfalseに戻すとか...
let shouldIgnoreMouseover = false;
let timeoutId: number;
let changeShowingState: (() => void) | null;
@ -12,10 +19,6 @@ export function useTooltip(onShow: (showing: Ref<boolean>) => void) {
close();
if (!isHovering) return;
// iOS(Androidも)では、要素をタップした直後に(おせっかいで)mouseoverイベントを発火させたりするため、その対策
// これが無いと、画面に触れてないのにツールチップが出たりしてしまう
if (isDeviceTouch && !isScreenTouching) return;
const showing = ref(true);
onShow(showing);
changeShowingState = () => {
@ -32,6 +35,7 @@ export function useTooltip(onShow: (showing: Ref<boolean>) => void) {
const onMouseover = () => {
if (isHovering) return;
if (shouldIgnoreMouseover) return;
isHovering = true;
timeoutId = window.setTimeout(open, 300);
};
@ -43,8 +47,31 @@ export function useTooltip(onShow: (showing: Ref<boolean>) => void) {
close();
};
return {
onMouseover,
onMouseleave,
const onTouchstart = () => {
shouldIgnoreMouseover = true;
if (isHovering) return;
isHovering = true;
timeoutId = window.setTimeout(open, 300);
};
const onTouchend = () => {
if (!isHovering) return;
isHovering = false;
window.clearTimeout(timeoutId);
close();
};
const stop = watch(elRef, () => {
if (elRef.value) {
stop();
const el = elRef.value instanceof Element ? elRef.value : elRef.value.$el;
el.addEventListener('mouseover', onMouseover, { passive: true });
el.addEventListener('mouseleave', onMouseleave, { passive: true });
el.addEventListener('touchstart', onTouchstart, { passive: true });
el.addEventListener('touchend', onTouchend, { passive: true });
}
}, {
immediate: true,
flush: 'post',
});
}