This commit is contained in:
syuilo 2020-09-05 19:38:57 +09:00
parent 5f3f9e2f8f
commit cb965feab4
14 changed files with 122 additions and 146 deletions

View File

@ -132,7 +132,7 @@
"double-ended-queue": "2.1.0-0",
"escape-regexp": "0.0.1",
"eslint": "7.4.0",
"eslint-plugin-vue": "6.2.2",
"eslint-plugin-vue": "7.0.0-beta.3",
"eventemitter3": "4.0.4",
"feed": "4.2.1",
"fibers": "5.0.0",

View File

@ -9,6 +9,7 @@ import MkFormula from './formula.vue';
import MkCode from './code.vue';
import MkGoogle from './google.vue';
import { host } from '../config';
import { RouterLink } from 'vue-router';
export default defineComponent({
props: {
@ -71,17 +72,13 @@ export default defineComponent({
case 'italic': {
return h('i', {
attrs: {
style: 'font-style: oblique;'
},
style: 'font-style: oblique;'
}, genEl(token.children));
}
case 'big': {
return h('strong', {
attrs: {
style: `display: inline-block; font-size: 150%;`
},
style: `display: inline-block; font-size: 150%;`,
directives: [this.$store.state.device.animatedMfm ? {
name: 'animate-css',
value: { classes: 'tada', iteration: 'infinite' }
@ -99,17 +96,13 @@ export default defineComponent({
case 'center': {
return [h('div', {
attrs: {
style: 'text-align:center;'
}
style: 'text-align:center;'
}, genEl(token.children))];
}
case 'motion': {
return h('span', {
attrs: {
style: 'display: inline-block;'
},
style: 'display: inline-block;',
directives: [this.$store.state.device.animatedMfm ? {
name: 'animate-css',
value: { classes: 'rubberBand', iteration: 'infinite' }
@ -125,95 +118,75 @@ export default defineComponent({
const style = this.$store.state.device.animatedMfm
? `animation: spin 1.5s linear infinite; animation-direction: ${direction};` : '';
return h('span', {
attrs: {
style: 'display: inline-block;' + style
},
style: 'display: inline-block;' + style
}, genEl(token.children));
}
case 'jump': {
return h('span', {
attrs: {
style: this.$store.state.device.animatedMfm ? 'display: inline-block; animation: jump 0.75s linear infinite;' : 'display: inline-block;'
},
style: this.$store.state.device.animatedMfm ? 'display: inline-block; animation: jump 0.75s linear infinite;' : 'display: inline-block;'
}, genEl(token.children));
}
case 'flip': {
return h('span', {
attrs: {
style: 'display: inline-block; transform: scaleX(-1);'
},
style: 'display: inline-block; transform: scaleX(-1);'
}, genEl(token.children));
}
case 'url': {
return [h(MkUrl, {
key: Math.random(),
props: {
url: token.node.props.url,
rel: 'nofollow noopener',
},
url: token.node.props.url,
rel: 'nofollow noopener',
})];
}
case 'link': {
return [h(MkLink, {
key: Math.random(),
props: {
url: token.node.props.url,
rel: 'nofollow noopener',
},
url: token.node.props.url,
rel: 'nofollow noopener',
}, genEl(token.children))];
}
case 'mention': {
return [h(MkMention, {
key: Math.random(),
props: {
host: (token.node.props.host == null && this.author && this.author.host != null ? this.author.host : token.node.props.host) || host,
username: token.node.props.username
}
host: (token.node.props.host == null && this.author && this.author.host != null ? this.author.host : token.node.props.host) || host,
username: token.node.props.username
})];
}
case 'hashtag': {
return [h('router-link', {
return [h(RouterLink, {
key: Math.random(),
attrs: {
to: this.isNote ? `/tags/${encodeURIComponent(token.node.props.hashtag)}` : `/explore/tags/${encodeURIComponent(token.node.props.hashtag)}`,
style: 'color:var(--hashtag);'
}
to: this.isNote ? `/tags/${encodeURIComponent(token.node.props.hashtag)}` : `/explore/tags/${encodeURIComponent(token.node.props.hashtag)}`,
style: 'color:var(--hashtag);'
}, `#${token.node.props.hashtag}`)];
}
case 'blockCode': {
return [h(MkCode, {
key: Math.random(),
props: {
code: token.node.props.code,
lang: token.node.props.lang,
}
code: token.node.props.code,
lang: token.node.props.lang,
})];
}
case 'inlineCode': {
return [h(MkCode, {
key: Math.random(),
props: {
code: token.node.props.code,
lang: token.node.props.lang,
inline: true
}
code: token.node.props.code,
lang: token.node.props.lang,
inline: true
})];
}
case 'quote': {
if (this.shouldBreak) {
return [h('div', {
attrs: {
class: 'quote'
}
class: 'quote'
}, genEl(token.children))];
} else {
return [h('span', {
@ -226,57 +199,45 @@ export default defineComponent({
case 'title': {
return [h('div', {
attrs: {
class: 'title'
}
class: 'title'
}, genEl(token.children))];
}
case 'emoji': {
return [h('mk-emoji', {
key: Math.random(),
attrs: {
emoji: token.node.props.emoji,
name: token.node.props.name
},
props: {
customEmojis: this.customEmojis,
normal: this.plain
}
emoji: token.node.props.emoji,
name: token.node.props.name,
customEmojis: this.customEmojis,
normal: this.plain
})];
}
case 'mathInline': {
return [h(MkFormula, {
key: Math.random(),
props: {
formula: token.node.props.formula,
block: false
}
formula: token.node.props.formula,
block: false
})];
}
case 'mathBlock': {
return [h(MkFormula, {
key: Math.random(),
props: {
formula: token.node.props.formula,
block: true
}
formula: token.node.props.formula,
block: true
})];
}
case 'search': {
return [h(MkGoogle, {
key: Math.random(),
props: {
q: token.node.props.query
}
q: token.node.props.query
})];
}
default: {
console.log('unknown ast type:', token.node.type);
console.log('unrecognized ast type:', token.node.type);
return [];
}

View File

@ -19,14 +19,14 @@
</template>
<script lang="ts">
import Vue, { PropType } from 'vue';
import { defineComponent, PropType } from 'vue';
import XWindow from './window.vue';
import MkSwitch from './ui/switch.vue';
import MkInfo from './ui/info.vue';
import MkButton from './ui/button.vue';
import { notificationTypes } from '../../types';
export default Vue.extend({
export default defineComponent({
components: {
XWindow,
MkSwitch,

View File

@ -66,6 +66,7 @@ import XReactionIcon from './reaction-icon.vue';
import MkFollowButton from './follow-button.vue';
import notePage from '../filters/note';
import { userPage } from '../filters/user';
import { locale } from '../i18n';
export default defineComponent({
components: {
@ -89,7 +90,7 @@ export default defineComponent({
},
data() {
return {
getNoteSummary: (text: string) => noteSummary(text, this.$root.i18n.messages[this.$root.i18n.locale]),
getNoteSummary: (text: string) => noteSummary(text, locale),
followRequestDone: false,
groupInviteDone: false,
connection: null,

View File

@ -1,14 +1,14 @@
<template>
<div class="ulveipgl">
<transition :name="$store.state.device.animation ? 'form-fade' : ''" appear @after-leave="$emit('closed');">
<div class="bg _modalBg" ref="bg" v-if="show" @click="close()"></div>
<div class="ulveipgl" :style="{ pointerEvents: closing ? 'none' : 'auto' }">
<transition :name="$store.state.device.animation ? 'form-fade' : ''" appear @after-leave="$store.commit('setPostForm', null)">
<div class="bg _modalBg" ref="bg" v-if="!closing" @click="close()"></div>
</transition>
<div class="main" ref="main" @click.self="close()" @keydown="onKeydown">
<transition :name="$store.state.device.animation ? 'form' : ''" appear
@after-leave="destroyDom"
>
<x-post-form ref="form"
v-if="show"
v-if="!closing"
:reply="reply"
:renote="renote"
:mention="mention"
@ -18,7 +18,8 @@
:instant="instant"
@posted="onPosted"
@cancel="onCanceled"
style="border-radius: var(--radius);"/>
style="border-radius: var(--radius);"
/>
</transition>
</div>
</div>
@ -67,7 +68,7 @@ export default defineComponent({
data() {
return {
show: true
closing: false
};
},
@ -77,9 +78,7 @@ export default defineComponent({
},
close() {
this.show = false;
(this.$refs.bg as any).style.pointerEvents = 'none';
(this.$refs.main as any).style.pointerEvents = 'none';
this.closing = true;
},
onPosted() {

View File

@ -193,6 +193,7 @@ export default defineComponent({
id,
v,
focused,
invalid,
changed,
filled,
inputEl,

View File

@ -295,7 +295,7 @@ export default defineComponent({
},
post() {
this.$root.post();
this.$store.commit('setPostForm', {});
},
search() {

View File

@ -12,5 +12,5 @@ export default function(app: App) {
app.directive('user-preview', userPreview);
app.directive('size', size);
//app.directive('particle', particle);
//app.directive('tooltip', tooltip);
app.directive('tooltip', tooltip);
}

View File

@ -1,3 +1,4 @@
import { Directive } from 'vue';
import MkTooltip from '../components/ui/tooltip.vue';
import { isDeviceTouch } from '../scripts/is-device-touch';
@ -5,7 +6,7 @@ const start = isDeviceTouch ? 'touchstart' : 'mouseover';
const end = isDeviceTouch ? 'touchend' : 'mouseleave';
export default {
bind(el: HTMLElement, binding, vn) {
mounted(el: HTMLElement, binding, vn) {
const self = (el as any)._tooltipDirective_ = {} as any;
self.text = binding.value as string;
@ -55,8 +56,8 @@ export default {
});
},
unbind(el, binding, vn) {
unmounted(el, binding, vn) {
const self = el._tooltipDirective_;
clearInterval(self.checkTimer);
},
};
} as Directive;

37
src/client/i18n.ts Normal file
View File

@ -0,0 +1,37 @@
import { createI18n } from 'vue-i18n';
import { clientDb, get, count } from './db';
import { setI18nContexts } from './scripts/set-i18n-contexts';
import { version, langs, getLocale } from './config';
let _lang = localStorage.getItem('lang');
if (_lang == null) {
if (langs.map(x => x[0]).includes(navigator.language)) {
_lang = navigator.language;
} else {
_lang = langs.map(x => x[0]).find(x => x.split('-')[0] == navigator.language);
if (_lang == null) {
// Fallback
_lang = 'en-US';
}
}
localStorage.setItem('lang', _lang);
}
export const lang = _lang;
export const locale = await count(clientDb.i18n).then(async n => {
if (n === 0) return await setI18nContexts(_lang, version);
if ((await get('_version_', clientDb.i18n) !== version)) return await setI18nContexts(_lang, version, true);
return await getLocale();
});
export const i18n = createI18n({
legacy: true,
sync: false,
locale: _lang,
messages: { [_lang]: locale }
});

View File

@ -5,7 +5,6 @@
import { createApp } from 'vue';
import VueMeta from 'vue-meta';
import VAnimateCss from 'v-animate-css';
import { createI18n } from 'vue-i18n';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { AiScript } from '@syuilo/aiscript';
import { deserialize } from '@syuilo/aiscript/built/serializer';
@ -16,14 +15,13 @@ import Stream from './scripts/stream';
import widgets from './widgets';
import directives from './directives';
import components from './components';
import { version, langs, getLocale, apiUrl } from './config';
import { version, apiUrl } from './config';
import { store } from './store';
import { router } from './router';
import { applyTheme, lightTheme } from './scripts/theme';
import { isDeviceDarkmode } from './scripts/is-device-darkmode';
import { clientDb, get, count } from './db';
import { setI18nContexts } from './scripts/set-i18n-contexts';
import { createPluginEnv } from './scripts/aiscript/api';
import { i18n, lang } from './i18n';
console.info(`Misskey v${version}`);
@ -41,25 +39,6 @@ window.addEventListener('resize', () => {
});
//#endregion
//#region Detect the user language
let lang = localStorage.getItem('lang');
if (lang == null) {
if (langs.map(x => x[0]).includes(navigator.language)) {
lang = navigator.language;
} else {
lang = langs.map(x => x[0]).find(x => x.split('-')[0] == navigator.language);
if (lang == null) {
// Fallback
lang = 'en-US';
}
}
localStorage.setItem('lang', lang);
}
//#endregion
// Detect the user agent
const ua = navigator.userAgent.toLowerCase();
const isMobile = /mobile|iphone|ipad|android/.test(ua);
@ -151,28 +130,11 @@ const app = createApp(Root, {
app.use(store);
app.use(router);
app.use(i18n);
app.use(VueHotkey);
app.use(VAnimateCss);
app.component('fa', FontAwesomeIcon);
//#region Init i18n
const locale = await count(clientDb.i18n).then(async n => {
if (n === 0) return await setI18nContexts(lang, version);
if ((await get('_version_', clientDb.i18n) !== version)) return await setI18nContexts(lang, version, true);
return await getLocale();
});
const i18n = createI18n({
legacy: true,
sync: false,
locale: lang,
messages: { [lang]: locale }
});
app.use(i18n);
//#endregion
widgets(app);
directives(app);
components(app);

View File

@ -2,8 +2,7 @@
<DeckUI v-if="deckmode"/>
<DefaultUI v-else/>
<XPostFormDialog v-if="$store.state.postForm" v-bind="$store.state.postForm"
@done="onDialogDone" @closed="onDialogClosed"/>
<XPostFormDialog v-if="$store.state.postForm" v-bind="$store.state.postForm"/>
<XDialog v-if="dialog" v-bind="dialog" :key="dialog.id"/>
</template>
@ -19,6 +18,7 @@ export default defineComponent({
DefaultUI,
DeckUI,
XDialog: defineAsyncComponent(() => import('./components/dialog.vue')),
XPostFormDialog: defineAsyncComponent(() => import('./components/post-form-dialog.vue')),
},
metaInfo: {

View File

@ -115,6 +115,7 @@ export const store = createStore({
text: string;
result: any;
}[],
postForm: null,
fullView: false,
// Plugin
@ -276,6 +277,11 @@ export const store = createStore({
state.dialogs = state.dialogs.filter(d => d.id !== dialogId);
},
setPostForm(state, postForm) {
if (state.postForm != null && postForm != null) return;
state.postForm = postForm;
},
setFullView(state, v) {
state.fullView = v;
},

View File

@ -3509,14 +3509,15 @@ escodegen@^1.14.1:
optionalDependencies:
source-map "~0.6.1"
eslint-plugin-vue@6.2.2:
version "6.2.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-vue/-/eslint-plugin-vue-6.2.2.tgz#27fecd9a3a24789b0f111ecdd540a9e56198e0fe"
integrity sha512-Nhc+oVAHm0uz/PkJAWscwIT4ijTrK5fqNqz9QB1D35SbbuMG1uB6Yr5AJpvPSWg+WOw7nYNswerYh0kOk64gqQ==
eslint-plugin-vue@7.0.0-beta.3:
version "7.0.0-beta.3"
resolved "https://registry.yarnpkg.com/eslint-plugin-vue/-/eslint-plugin-vue-7.0.0-beta.3.tgz#37a4fedf46db74cdb3be268390b4541eb7a810b7"
integrity sha512-/p23IRPN9gFNN7dzesrctt06Kvs9E3VRB8BGIAPSEaQNk5yhlKUzntPARjUpsTWW+DQg0mqglZptfkUJK4+4EQ==
dependencies:
eslint-utils "^2.1.0"
natural-compare "^1.4.0"
semver "^5.6.0"
vue-eslint-parser "^7.0.0"
semver "^7.3.2"
vue-eslint-parser "^7.1.0"
eslint-scope@^5.0.0:
version "5.0.0"
@ -3541,6 +3542,13 @@ eslint-utils@^2.0.0:
dependencies:
eslint-visitor-keys "^1.1.0"
eslint-utils@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-2.1.0.tgz#d2de5e03424e707dc10c74068ddedae708741b27"
integrity sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==
dependencies:
eslint-visitor-keys "^1.1.0"
eslint-visitor-keys@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2"
@ -3593,7 +3601,7 @@ eslint@7.4.0:
text-table "^0.2.0"
v8-compile-cache "^2.0.3"
espree@^6.1.2:
espree@^6.2.1:
version "6.2.1"
resolved "https://registry.yarnpkg.com/espree/-/espree-6.2.1.tgz#77fc72e1fd744a2052c20f38a5b575832e82734a"
integrity sha512-ysCxRQY3WaXJz9tdbWOwuWr5Y/XrPTGX9Kiz3yoUXwW0VZ4w30HTkQLaGx/+ttFjF8i+ACbArnB4ce68a9m5hw==
@ -10083,15 +10091,15 @@ vue-cropperjs@4.1.0:
dependencies:
cropperjs "^1.5.6"
vue-eslint-parser@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/vue-eslint-parser/-/vue-eslint-parser-7.0.0.tgz#a4ed2669f87179dedd06afdd8736acbb3a3864d6"
integrity sha512-yR0dLxsTT7JfD2YQo9BhnQ6bUTLsZouuzt9SKRP7XNaZJV459gvlsJo4vT2nhZ/2dH9j3c53bIx9dnqU2prM9g==
vue-eslint-parser@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/vue-eslint-parser/-/vue-eslint-parser-7.1.0.tgz#9cdbcc823e656b087507a1911732b867ac101e83"
integrity sha512-Kr21uPfthDc63nDl27AGQEhtt9VrZ9nkYk/NTftJ2ws9XiJwzJJCnCr3AITQ2jpRMA0XPGDECxYH8E027qMK9Q==
dependencies:
debug "^4.1.1"
eslint-scope "^5.0.0"
eslint-visitor-keys "^1.1.0"
espree "^6.1.2"
espree "^6.2.1"
esquery "^1.0.1"
lodash "^4.17.15"