summaryrefslogtreecommitdiff
path: root/src/client/scripts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-10-16 19:55:44 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-10-16 19:55:44 +0900
commit8a1f3a4c0b5732d0f08f0788d93c5934de8960c8 (patch)
treebe6fbcf3a1bbd78306d91e19ef6f3e7023f41561 /src/client/scripts
parentMerge branch 'develop' (diff)
parent12.92.0 (diff)
downloadmisskey-8a1f3a4c0b5732d0f08f0788d93c5934de8960c8.tar.gz
misskey-8a1f3a4c0b5732d0f08f0788d93c5934de8960c8.tar.bz2
misskey-8a1f3a4c0b5732d0f08f0788d93c5934de8960c8.zip
Merge branch 'develop'
Diffstat (limited to 'src/client/scripts')
-rw-r--r--src/client/scripts/autocomplete.ts35
-rw-r--r--src/client/scripts/idb-proxy.ts5
-rw-r--r--src/client/scripts/physics.ts2
-rw-r--r--src/client/scripts/scroll.ts20
-rw-r--r--src/client/scripts/theme.ts7
5 files changed, 54 insertions, 15 deletions
diff --git a/src/client/scripts/autocomplete.ts b/src/client/scripts/autocomplete.ts
index 924d6a62ee..c0c33b2c7e 100644
--- a/src/client/scripts/autocomplete.ts
+++ b/src/client/scripts/autocomplete.ts
@@ -7,9 +7,9 @@ export class Autocomplete {
private suggestion: {
x: Ref<number>;
y: Ref<number>;
- q: Ref<string>;
+ q: Ref<string | null>;
close: Function;
- };
+ } | null;
private textarea: any;
private vm: any;
private currentType: string;
@@ -70,11 +70,13 @@ export class Autocomplete {
const mentionIndex = text.lastIndexOf('@');
const hashtagIndex = text.lastIndexOf('#');
const emojiIndex = text.lastIndexOf(':');
+ const mfmTagIndex = text.lastIndexOf('$');
const max = Math.max(
mentionIndex,
hashtagIndex,
- emojiIndex);
+ emojiIndex,
+ mfmTagIndex);
if (max == -1) {
this.close();
@@ -83,6 +85,7 @@ export class Autocomplete {
const isMention = mentionIndex != -1;
const isHashtag = hashtagIndex != -1;
+ const isMfmTag = mfmTagIndex != -1;
const isEmoji = emojiIndex != -1 && text.split(/:[a-z0-9_+\-]+:/).pop()!.includes(':');
let opened = false;
@@ -114,6 +117,14 @@ export class Autocomplete {
}
}
+ if (isMfmTag && !opened) {
+ const mfmTag = text.substr(mfmTagIndex + 1);
+ if (!mfmTag.includes(' ')) {
+ this.open('mfmTag', mfmTag.replace('[', ''));
+ opened = true;
+ }
+ }
+
if (!opened) {
this.close();
}
@@ -122,7 +133,7 @@ export class Autocomplete {
/**
* サジェストを提示します。
*/
- private async open(type: string, q: string) {
+ private async open(type: string, q: string | null) {
if (type != this.currentType) {
this.close();
}
@@ -244,6 +255,22 @@ export class Autocomplete {
const pos = trimmedBefore.length + value.length;
this.textarea.setSelectionRange(pos, pos);
});
+ } else if (type == 'mfmTag') {
+ const source = this.text;
+
+ const before = source.substr(0, caret);
+ const trimmedBefore = before.substring(0, before.lastIndexOf('$'));
+ const after = source.substr(caret);
+
+ // 挿入
+ this.text = `${trimmedBefore}$[${value} ]${after}`;
+
+ // キャレットを戻す
+ this.vm.$nextTick(() => {
+ this.textarea.focus();
+ const pos = trimmedBefore.length + (value.length + 3);
+ this.textarea.setSelectionRange(pos, pos);
+ });
}
}
}
diff --git a/src/client/scripts/idb-proxy.ts b/src/client/scripts/idb-proxy.ts
index 21c4dcff65..5f76ae30bb 100644
--- a/src/client/scripts/idb-proxy.ts
+++ b/src/client/scripts/idb-proxy.ts
@@ -4,7 +4,6 @@ import {
get as iget,
set as iset,
del as idel,
- createStore,
} from 'idb-keyval';
const fallbackName = (key: string) => `idbfallback::${key}`;
@@ -13,9 +12,9 @@ let idbAvailable = typeof window !== 'undefined' ? !!window.indexedDB : true;
if (idbAvailable) {
try {
- await createStore('keyval-store', 'keyval');
+ await iset('idb-test', 'test');
} catch (e) {
- console.error('idb open error', e);
+ console.error('idb error', e);
idbAvailable = false;
}
}
diff --git a/src/client/scripts/physics.ts b/src/client/scripts/physics.ts
index 8e971d5844..445b6296eb 100644
--- a/src/client/scripts/physics.ts
+++ b/src/client/scripts/physics.ts
@@ -79,7 +79,7 @@ export function physics(container: HTMLElement) {
objEl.offsetWidth,
objEl.offsetHeight,
{
- chamfer: { radius: parseInt(style.borderRadius, 10) },
+ chamfer: { radius: parseInt(style.borderRadius || '0', 10) },
restitution: 0.5
}
);
diff --git a/src/client/scripts/scroll.ts b/src/client/scripts/scroll.ts
index bc6d1530c5..621fe88105 100644
--- a/src/client/scripts/scroll.ts
+++ b/src/client/scripts/scroll.ts
@@ -1,3 +1,5 @@
+type ScrollBehavior = 'auto' | 'smooth' | 'instant';
+
export function getScrollContainer(el: Element | null): Element | null {
if (el == null || el.tagName === 'BODY') return null;
const overflow = window.getComputedStyle(el).getPropertyValue('overflow');
@@ -45,21 +47,25 @@ export function onScrollBottom(el: Element, cb) {
container.addEventListener('scroll', onScroll, { passive: true });
}
-export function scroll(el: Element, top: number) {
+export function scroll(el: Element, options: {
+ top?: number;
+ left?: number;
+ behavior?: ScrollBehavior;
+}) {
const container = getScrollContainer(el);
if (container == null) {
- window.scroll({ top: top, behavior: 'instant' });
+ window.scroll(options);
} else {
- container.scrollTop = top;
+ container.scroll(options);
}
}
-export function scrollToTop(el: Element) {
- scroll(el, 0);
+export function scrollToTop(el: Element, options: { behavior?: ScrollBehavior; } = {}) {
+ scroll(el, { top: 0, ...options });
}
-export function scrollToBottom(el: Element) {
- scroll(el, 99999); // TODO: ちゃんと計算する
+export function scrollToBottom(el: Element, options: { behavior?: ScrollBehavior; } = {}) {
+ scroll(el, { top: 99999, ...options }); // TODO: ちゃんと計算する
}
export function isBottom(el: Element, asobi = 0) {
diff --git a/src/client/scripts/theme.ts b/src/client/scripts/theme.ts
index 3fb5666a72..e79d54fa6d 100644
--- a/src/client/scripts/theme.ts
+++ b/src/client/scripts/theme.ts
@@ -1,3 +1,4 @@
+import { globalEvents } from '@client/events';
import * as tinycolor from 'tinycolor2';
export type Theme = {
@@ -24,6 +25,7 @@ export const builtinThemes = [
require('@client/themes/d-persimmon.json5'),
require('@client/themes/d-astro.json5'),
require('@client/themes/d-future.json5'),
+ require('@client/themes/d-botanical.json5'),
require('@client/themes/d-black.json5'),
] as Theme[];
@@ -62,6 +64,9 @@ export function applyTheme(theme: Theme, persist = true) {
if (persist) {
localStorage.setItem('theme', JSON.stringify(props));
}
+
+ // 色計算など再度行えるようにクライアント全体に通知
+ globalEvents.emit('themeChanged');
}
function compile(theme: Theme): Record<string, string> {
@@ -87,6 +92,8 @@ function compile(theme: Theme): Record<string, string> {
case 'darken': return color.darken(arg);
case 'lighten': return color.lighten(arg);
case 'alpha': return color.setAlpha(arg);
+ case 'hue': return color.spin(arg);
+ case 'saturate': return color.saturate(arg);
}
}