From bc9a8283c66d7588f931d4b802f7ab1fa7aa3226 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 13 Nov 2017 18:05:35 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=AA=E3=82=93=E3=81=8B=E3=82=82=E3=81=86?= =?UTF-8?q?=E3=82=81=E3=81=A3=E3=81=A1=E3=82=83=E5=A4=89=E3=81=88=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 7 +++- src/web/app/auth/{script.js => script.ts} | 0 src/web/app/auth/tags/{index.js => index.ts} | 0 src/web/app/ch/{router.js => router.ts} | 4 +-- src/web/app/ch/{script.js => script.ts} | 0 src/web/app/ch/tags/channel.tag | 4 +-- src/web/app/ch/tags/{index.js => index.ts} | 0 src/web/app/common/mixins/{api.js => api.ts} | 2 +- src/web/app/common/mixins/{i.js => i.ts} | 2 +- src/web/app/common/mixins/index.js | 13 -------- src/web/app/common/mixins/index.ts | 14 ++++++++ src/web/app/common/scripts/{api.js => api.ts} | 4 +-- .../{bytes-to-size.js => bytes-to-size.ts} | 4 +-- .../{channel-stream.js => channel-stream.ts} | 0 ...heck-for-update.js => check-for-update.ts} | 4 ++- .../common/scripts/{config.js => config.ts} | 0 .../scripts/{contains.js => contains.ts} | 0 ...y-to-clipboard.js => copy-to-clipboard.ts} | 0 .../{date-stringify.js => date-stringify.ts} | 0 src/web/app/common/scripts/{gcd.js => gcd.ts} | 0 .../common/scripts/{get-kao.js => get-kao.ts} | 2 +- .../{home-stream.js => home-stream.ts} | 4 +-- .../scripts/{is-promise.js => is-promise.ts} | 0 .../common/scripts/{loading.js => loading.ts} | 0 ...essaging-stream.js => messaging-stream.ts} | 2 +- .../common/scripts/server-stream-manager.ts | 31 ++--------------- .../{server-stream.js => server-stream.ts} | 0 .../common/scripts/{signout.js => signout.ts} | 0 src/web/app/common/scripts/stream-manager.ts | 33 +++++++++++++++++++ .../common/scripts/{stream.js => stream.ts} | 31 +++++++++-------- .../{text-compiler.js => text-compiler.ts} | 4 +-- .../app/common/tags/{index.js => index.ts} | 0 src/web/app/common/tags/messaging/message.tag | 2 +- .../app/desktop/mixins/{index.js => index.ts} | 0 .../{user-preview.js => user-preview.ts} | 2 +- .../desktop/mixins/{widget.js => widget.ts} | 2 +- src/web/app/desktop/{router.js => router.ts} | 6 ++-- src/web/app/desktop/{script.js => script.ts} | 8 ++--- .../{autocomplete.js => autocomplete.ts} | 26 ++++++++------- .../desktop/scripts/{dialog.js => dialog.ts} | 4 +-- .../{fuck-ad-block.js => fuck-ad-block.ts} | 2 ++ .../{input-dialog.js => input-dialog.ts} | 2 +- ...eption.js => not-implemented-exception.ts} | 0 .../desktop/scripts/{notify.js => notify.ts} | 2 +- ...{password-dialog.js => password-dialog.ts} | 2 +- .../{update-avatar.js => update-avatar.ts} | 8 ++--- .../{update-banner.js => update-banner.ts} | 8 ++--- .../desktop/tags/autocomplete-suggestion.tag | 2 +- src/web/app/desktop/tags/drive/browser.tag | 4 +-- src/web/app/desktop/tags/drive/folder.tag | 2 +- src/web/app/desktop/tags/drive/nav-folder.tag | 2 +- .../app/desktop/tags/{index.js => index.ts} | 0 src/web/app/desktop/tags/post-detail-sub.tag | 2 +- src/web/app/desktop/tags/post-detail.tag | 2 +- src/web/app/desktop/tags/post-form.tag | 6 ++-- src/web/app/desktop/tags/sub-post-content.tag | 2 +- src/web/app/desktop/tags/timeline.tag | 2 +- src/web/app/dev/{router.js => router.ts} | 4 +-- src/web/app/dev/{script.js => script.ts} | 0 src/web/app/dev/tags/{index.js => index.ts} | 0 src/web/app/{init.js => init.ts} | 28 +++------------- src/web/app/mobile/{router.js => router.ts} | 6 ++-- src/web/app/mobile/{script.js => script.ts} | 0 .../{open-post-form.js => open-post-form.ts} | 0 .../scripts/{ui-event.js => ui-event.ts} | 0 src/web/app/mobile/tags/drive.tag | 2 +- .../app/mobile/tags/{index.js => index.ts} | 0 src/web/app/mobile/tags/post-detail.tag | 2 +- src/web/app/mobile/tags/post-form.tag | 4 +-- src/web/app/mobile/tags/sub-post-content.tag | 2 +- src/web/app/mobile/tags/timeline.tag | 2 +- src/web/app/stats/{script.js => script.ts} | 0 src/web/app/stats/tags/{index.js => index.ts} | 0 src/web/app/status/{script.js => script.ts} | 0 .../app/status/tags/{index.js => index.ts} | 0 tslint.json | 1 + webpack/webpack.config.ts | 21 +++++++----- 77 files changed, 170 insertions(+), 165 deletions(-) rename src/web/app/auth/{script.js => script.ts} (100%) rename src/web/app/auth/tags/{index.js => index.ts} (100%) rename src/web/app/ch/{router.js => router.ts} (92%) rename src/web/app/ch/{script.js => script.ts} (100%) rename src/web/app/ch/tags/{index.js => index.ts} (100%) rename src/web/app/common/mixins/{api.js => api.ts} (82%) rename src/web/app/common/mixins/{i.js => i.ts} (91%) delete mode 100644 src/web/app/common/mixins/index.js create mode 100644 src/web/app/common/mixins/index.ts rename src/web/app/common/scripts/{api.js => api.ts} (88%) rename src/web/app/common/scripts/{bytes-to-size.js => bytes-to-size.ts} (58%) rename src/web/app/common/scripts/{channel-stream.js => channel-stream.ts} (100%) rename src/web/app/common/scripts/{check-for-update.js => check-for-update.ts} (91%) rename src/web/app/common/scripts/{config.js => config.ts} (100%) rename src/web/app/common/scripts/{contains.js => contains.ts} (100%) rename src/web/app/common/scripts/{copy-to-clipboard.js => copy-to-clipboard.ts} (100%) rename src/web/app/common/scripts/{date-stringify.js => date-stringify.ts} (100%) rename src/web/app/common/scripts/{gcd.js => gcd.ts} (100%) rename src/web/app/common/scripts/{get-kao.js => get-kao.ts} (65%) rename src/web/app/common/scripts/{home-stream.js => home-stream.ts} (83%) rename src/web/app/common/scripts/{is-promise.js => is-promise.ts} (100%) rename src/web/app/common/scripts/{loading.js => loading.ts} (100%) rename src/web/app/common/scripts/{messaging-stream.js => messaging-stream.ts} (87%) rename src/web/app/common/scripts/{server-stream.js => server-stream.ts} (100%) rename src/web/app/common/scripts/{signout.js => signout.ts} (100%) create mode 100644 src/web/app/common/scripts/stream-manager.ts rename src/web/app/common/scripts/{stream.js => stream.ts} (83%) rename src/web/app/common/scripts/{text-compiler.js => text-compiler.ts} (94%) rename src/web/app/common/tags/{index.js => index.ts} (100%) rename src/web/app/desktop/mixins/{index.js => index.ts} (100%) rename src/web/app/desktop/mixins/{user-preview.js => user-preview.ts} (95%) rename src/web/app/desktop/mixins/{widget.js => widget.ts} (95%) rename src/web/app/desktop/{router.js => router.ts} (96%) rename src/web/app/desktop/{script.js => script.ts} (87%) rename src/web/app/desktop/scripts/{autocomplete.js => autocomplete.ts} (86%) rename src/web/app/desktop/scripts/{dialog.js => dialog.ts} (77%) rename src/web/app/desktop/scripts/{fuck-ad-block.js => fuck-ad-block.ts} (94%) rename src/web/app/desktop/scripts/{input-dialog.js => input-dialog.ts} (88%) rename src/web/app/desktop/scripts/{not-implemented-exception.js => not-implemented-exception.ts} (100%) rename src/web/app/desktop/scripts/{notify.js => notify.ts} (83%) rename src/web/app/desktop/scripts/{password-dialog.js => password-dialog.ts} (86%) rename src/web/app/desktop/scripts/{update-avatar.js => update-avatar.ts} (82%) rename src/web/app/desktop/scripts/{update-banner.js => update-banner.ts} (82%) rename src/web/app/desktop/tags/{index.js => index.ts} (100%) rename src/web/app/dev/{router.js => router.ts} (94%) rename src/web/app/dev/{script.js => script.ts} (100%) rename src/web/app/dev/tags/{index.js => index.ts} (100%) rename src/web/app/{init.js => init.ts} (81%) rename src/web/app/mobile/{router.js => router.ts} (97%) rename src/web/app/mobile/{script.js => script.ts} (100%) rename src/web/app/mobile/scripts/{open-post-form.js => open-post-form.ts} (100%) rename src/web/app/mobile/scripts/{ui-event.js => ui-event.ts} (100%) rename src/web/app/mobile/tags/{index.js => index.ts} (100%) rename src/web/app/stats/{script.js => script.ts} (100%) rename src/web/app/stats/tags/{index.js => index.ts} (100%) rename src/web/app/status/{script.js => script.ts} (100%) rename src/web/app/status/tags/{index.js => index.ts} (100%) diff --git a/package.json b/package.json index 2861fd9f0..879f4af92 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,9 @@ "@types/ms": "0.7.30", "@types/multer": "1.3.5", "@types/node": "8.0.49", + "@types/page": "1.5.32", + "@types/proxy-addr": "2.0.0", + "@types/seedrandom": "2.4.27", "@types/ratelimiter": "2.1.28", "@types/redis": "2.8.1", "@types/request": "2.0.7", @@ -92,8 +95,8 @@ "webpack": "3.8.1" }, "dependencies": { - "@prezzemolo/zip": "0.0.3", "@prezzemolo/rap": "0.1.2", + "@prezzemolo/zip": "0.0.3", "accesses": "2.5.0", "animejs": "2.2.0", "autwh": "0.0.1", @@ -131,6 +134,7 @@ "page": "1.7.1", "pictograph": "2.0.4", "prominence": "0.2.0", + "proxy-addr": "^2.0.2", "pug": "2.0.0-rc.4", "ratelimiter": "3.0.3", "recaptcha-promise": "0.1.3", @@ -141,6 +145,7 @@ "riot": "3.7.4", "rndstr": "1.0.0", "s-age": "1.1.0", + "seedrandom": "^2.4.3", "serve-favicon": "2.4.5", "sortablejs": "1.7.0", "summaly": "2.0.3", diff --git a/src/web/app/auth/script.js b/src/web/app/auth/script.ts similarity index 100% rename from src/web/app/auth/script.js rename to src/web/app/auth/script.ts diff --git a/src/web/app/auth/tags/index.js b/src/web/app/auth/tags/index.ts similarity index 100% rename from src/web/app/auth/tags/index.js rename to src/web/app/auth/tags/index.ts diff --git a/src/web/app/ch/router.js b/src/web/app/ch/router.ts similarity index 92% rename from src/web/app/ch/router.js rename to src/web/app/ch/router.ts index 424158f40..fe014d4e3 100644 --- a/src/web/app/ch/router.js +++ b/src/web/app/ch/router.ts @@ -1,5 +1,5 @@ import * as riot from 'riot'; -const route = require('page'); +import * as route from 'page'; let page = null; export default me => { @@ -22,7 +22,7 @@ export default me => { } // EXEC - route(); + (route as any)(); }; function mount(content) { diff --git a/src/web/app/ch/script.js b/src/web/app/ch/script.ts similarity index 100% rename from src/web/app/ch/script.js rename to src/web/app/ch/script.ts diff --git a/src/web/app/ch/tags/channel.tag b/src/web/app/ch/tags/channel.tag index 4ae62e7b3..48c5c705d 100644 --- a/src/web/app/ch/tags/channel.tag +++ b/src/web/app/ch/tags/channel.tag @@ -343,7 +343,7 @@ }; this.changeFile = () => { - this.refs.file.files.forEach(this.upload); + Array.from(this.refs.file.files).forEach(this.upload); }; this.selectFile = () => { @@ -367,7 +367,7 @@ }; this.onpaste = e => { - e.clipboardData.items.forEach(item => { + Array.from(e.clipboardData.items).forEach(item => { if (item.kind == 'file') { this.upload(item.getAsFile()); } diff --git a/src/web/app/ch/tags/index.js b/src/web/app/ch/tags/index.ts similarity index 100% rename from src/web/app/ch/tags/index.js rename to src/web/app/ch/tags/index.ts diff --git a/src/web/app/common/mixins/api.js b/src/web/app/common/mixins/api.ts similarity index 82% rename from src/web/app/common/mixins/api.js rename to src/web/app/common/mixins/api.ts index 42d96db55..9726caf51 100644 --- a/src/web/app/common/mixins/api.js +++ b/src/web/app/common/mixins/api.ts @@ -2,7 +2,7 @@ import * as riot from 'riot'; import api from '../scripts/api'; export default me => { - riot.mixin('api', { + (riot as any).mixin('api', { api: api.bind(null, me ? me.token : null) }); }; diff --git a/src/web/app/common/mixins/i.js b/src/web/app/common/mixins/i.ts similarity index 91% rename from src/web/app/common/mixins/i.js rename to src/web/app/common/mixins/i.ts index 522514776..0879d02d3 100644 --- a/src/web/app/common/mixins/i.js +++ b/src/web/app/common/mixins/i.ts @@ -1,7 +1,7 @@ import * as riot from 'riot'; export default me => { - riot.mixin('i', { + (riot as any).mixin('i', { init: function() { this.I = me; this.SIGNIN = me != null; diff --git a/src/web/app/common/mixins/index.js b/src/web/app/common/mixins/index.js deleted file mode 100644 index 19e0690d7..000000000 --- a/src/web/app/common/mixins/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import * as riot from 'riot'; - -import activateMe from './i'; -import activateApi from './api'; - -export default (me, stream, serverStreamManager) => { - activateMe(me); - activateApi(me); - - riot.mixin('stream', { stream }); - - riot.mixin('server-stream', { serverStream: serverStreamManager }); -}; diff --git a/src/web/app/common/mixins/index.ts b/src/web/app/common/mixins/index.ts new file mode 100644 index 000000000..45427fb9d --- /dev/null +++ b/src/web/app/common/mixins/index.ts @@ -0,0 +1,14 @@ +import * as riot from 'riot'; + +import activateMe from './i'; +import activateApi from './api'; +import ServerStreamManager from '../scripts/server-stream-manager'; + +export default (me, stream) => { + activateMe(me); + activateApi(me); + + (riot as any).mixin('stream', { stream }); + + (riot as any).mixin('server-stream', { serverStream: new ServerStreamManager() }); +}; diff --git a/src/web/app/common/scripts/api.js b/src/web/app/common/scripts/api.ts similarity index 88% rename from src/web/app/common/scripts/api.js rename to src/web/app/common/scripts/api.ts index 4855f736c..2a9d78e87 100644 --- a/src/web/app/common/scripts/api.js +++ b/src/web/app/common/scripts/api.ts @@ -14,7 +14,7 @@ let pending = 0; * @param {any} [data={}] Data * @return {Promise} Response */ -export default (i, endpoint, data = {}) => { +export default (i, endpoint, data = {}): Promise => { if (++pending === 1) { spinner = document.createElement('div'); spinner.setAttribute('id', 'wait'); @@ -22,7 +22,7 @@ export default (i, endpoint, data = {}) => { } // Append the credential - if (i != null) data.i = typeof i === 'object' ? i.token : i; + if (i != null) (data as any).i = typeof i === 'object' ? i.token : i; return new Promise((resolve, reject) => { // Send request diff --git a/src/web/app/common/scripts/bytes-to-size.js b/src/web/app/common/scripts/bytes-to-size.ts similarity index 58% rename from src/web/app/common/scripts/bytes-to-size.js rename to src/web/app/common/scripts/bytes-to-size.ts index af0268dbd..1d2b1e7ce 100644 --- a/src/web/app/common/scripts/bytes-to-size.js +++ b/src/web/app/common/scripts/bytes-to-size.ts @@ -1,6 +1,6 @@ export default (bytes, digits = 0) => { - var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; if (bytes == 0) return '0Byte'; - var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); + const i = Math.floor(Math.log(bytes) / Math.log(1024)); return (bytes / Math.pow(1024, i)).toFixed(digits).replace(/\.0+$/, '') + sizes[i]; }; diff --git a/src/web/app/common/scripts/channel-stream.js b/src/web/app/common/scripts/channel-stream.ts similarity index 100% rename from src/web/app/common/scripts/channel-stream.js rename to src/web/app/common/scripts/channel-stream.ts diff --git a/src/web/app/common/scripts/check-for-update.js b/src/web/app/common/scripts/check-for-update.ts similarity index 91% rename from src/web/app/common/scripts/check-for-update.js rename to src/web/app/common/scripts/check-for-update.ts index 7cb7839d2..99d8b5d05 100644 --- a/src/web/app/common/scripts/check-for-update.js +++ b/src/web/app/common/scripts/check-for-update.ts @@ -1,5 +1,7 @@ import CONFIG from './config'; +declare var VERSION: string; + export default function() { fetch(CONFIG.apiUrl + '/meta', { method: 'POST' @@ -11,4 +13,4 @@ export default function() { } }); }); -}; +} diff --git a/src/web/app/common/scripts/config.js b/src/web/app/common/scripts/config.ts similarity index 100% rename from src/web/app/common/scripts/config.js rename to src/web/app/common/scripts/config.ts diff --git a/src/web/app/common/scripts/contains.js b/src/web/app/common/scripts/contains.ts similarity index 100% rename from src/web/app/common/scripts/contains.js rename to src/web/app/common/scripts/contains.ts diff --git a/src/web/app/common/scripts/copy-to-clipboard.js b/src/web/app/common/scripts/copy-to-clipboard.ts similarity index 100% rename from src/web/app/common/scripts/copy-to-clipboard.js rename to src/web/app/common/scripts/copy-to-clipboard.ts diff --git a/src/web/app/common/scripts/date-stringify.js b/src/web/app/common/scripts/date-stringify.ts similarity index 100% rename from src/web/app/common/scripts/date-stringify.js rename to src/web/app/common/scripts/date-stringify.ts diff --git a/src/web/app/common/scripts/gcd.js b/src/web/app/common/scripts/gcd.ts similarity index 100% rename from src/web/app/common/scripts/gcd.js rename to src/web/app/common/scripts/gcd.ts diff --git a/src/web/app/common/scripts/get-kao.js b/src/web/app/common/scripts/get-kao.ts similarity index 65% rename from src/web/app/common/scripts/get-kao.js rename to src/web/app/common/scripts/get-kao.ts index 0b77ee285..2168c5be8 100644 --- a/src/web/app/common/scripts/get-kao.js +++ b/src/web/app/common/scripts/get-kao.ts @@ -1,5 +1,5 @@ export default () => [ '(=^・・^=)', 'v(‘ω’)v', - '🐡( '-' 🐡 )フグパンチ!!!!' + '🐡( \'-\' 🐡 )フグパンチ!!!!' ][Math.floor(Math.random() * 3)]; diff --git a/src/web/app/common/scripts/home-stream.js b/src/web/app/common/scripts/home-stream.ts similarity index 83% rename from src/web/app/common/scripts/home-stream.js rename to src/web/app/common/scripts/home-stream.ts index de9ceb3b5..c549f2b93 100644 --- a/src/web/app/common/scripts/home-stream.js +++ b/src/web/app/common/scripts/home-stream.ts @@ -17,9 +17,9 @@ class Connection extends Stream { this.send({ type: 'alive' }); }, 1000 * 60); - this.on('i_updated', me.update); + (this as any).on('i_updated', me.update); - this.on('my_token_regenerated', () => { + (this as any).on('my_token_regenerated', () => { alert('%i18n:common.my-token-regenerated%'); signout(); }); diff --git a/src/web/app/common/scripts/is-promise.js b/src/web/app/common/scripts/is-promise.ts similarity index 100% rename from src/web/app/common/scripts/is-promise.js rename to src/web/app/common/scripts/is-promise.ts diff --git a/src/web/app/common/scripts/loading.js b/src/web/app/common/scripts/loading.ts similarity index 100% rename from src/web/app/common/scripts/loading.js rename to src/web/app/common/scripts/loading.ts diff --git a/src/web/app/common/scripts/messaging-stream.js b/src/web/app/common/scripts/messaging-stream.ts similarity index 87% rename from src/web/app/common/scripts/messaging-stream.js rename to src/web/app/common/scripts/messaging-stream.ts index 261525d5f..63830f7b1 100644 --- a/src/web/app/common/scripts/messaging-stream.js +++ b/src/web/app/common/scripts/messaging-stream.ts @@ -12,7 +12,7 @@ class Connection extends Stream { otherparty }); - this.on('_connected_', () => { + (this as any).on('_connected_', () => { this.send({ i: me.token }); diff --git a/src/web/app/common/scripts/server-stream-manager.ts b/src/web/app/common/scripts/server-stream-manager.ts index 54333c8cf..a170daebb 100644 --- a/src/web/app/common/scripts/server-stream-manager.ts +++ b/src/web/app/common/scripts/server-stream-manager.ts @@ -1,14 +1,7 @@ +import StreamManager from './stream-manager'; import Connection from './server-stream'; -import * as uuid from 'uuid'; - -export default class ServerStreamManager { - private connection = null; - - /** - * コネクションを必要としているユーザー - */ - private users = []; +export default class ServerStreamManager extends StreamManager { public getConnection() { if (this.connection == null) { this.connection = new Connection(); @@ -16,24 +9,4 @@ export default class ServerStreamManager { return this.connection; } - - public use() { - // ユーザーID生成 - const userId = uuid(); - - this.users.push(userId); - - return userId; - } - - public dispose(userId) { - this.users = this.users.filter(id => id != userId); - - // 誰もコネクションの利用者がいなくなったら - if (this.users.length == 0) { - // コネクションを切断する - this.connection.close(); - this.connection = null; - } - } } diff --git a/src/web/app/common/scripts/server-stream.js b/src/web/app/common/scripts/server-stream.ts similarity index 100% rename from src/web/app/common/scripts/server-stream.js rename to src/web/app/common/scripts/server-stream.ts diff --git a/src/web/app/common/scripts/signout.js b/src/web/app/common/scripts/signout.ts similarity index 100% rename from src/web/app/common/scripts/signout.js rename to src/web/app/common/scripts/signout.ts diff --git a/src/web/app/common/scripts/stream-manager.ts b/src/web/app/common/scripts/stream-manager.ts new file mode 100644 index 000000000..4eaf0f9a4 --- /dev/null +++ b/src/web/app/common/scripts/stream-manager.ts @@ -0,0 +1,33 @@ +import * as uuid from 'uuid'; +import Connection from './stream'; + +export default abstract class StreamManager { + protected connection: T = null; + + /** + * コネクションを必要としているユーザー + */ + private users = []; + + public abstract getConnection(): T; + + public use() { + // ユーザーID生成 + const userId = uuid(); + + this.users.push(userId); + + return userId; + } + + public dispose(userId) { + this.users = this.users.filter(id => id != userId); + + // 誰もコネクションの利用者がいなくなったら + if (this.users.length == 0) { + // コネクションを切断する + this.connection.close(); + this.connection = null; + } + } +} diff --git a/src/web/app/common/scripts/stream.js b/src/web/app/common/scripts/stream.ts similarity index 83% rename from src/web/app/common/scripts/stream.js rename to src/web/app/common/scripts/stream.ts index a03b7bf20..959524687 100644 --- a/src/web/app/common/scripts/stream.js +++ b/src/web/app/common/scripts/stream.ts @@ -8,7 +8,11 @@ import CONFIG from './config'; * Misskey stream connection */ class Connection { - constructor(endpoint, params) { + private state: string; + private buffer: any[]; + private socket: ReconnectingWebsocket; + + constructor(endpoint, params?) { // BIND ----------------------------------- this.onOpen = this.onOpen.bind(this); this.onClose = this.onClose.bind(this); @@ -37,11 +41,10 @@ class Connection { /** * Callback of when open connection - * @private */ - onOpen() { + private onOpen() { this.state = 'connected'; - this.trigger('_connected_'); + (this as any).trigger('_connected_'); // バッファーを処理 const _buffer = [].concat(this.buffer); // Shallow copy @@ -53,45 +56,41 @@ class Connection { /** * Callback of when close connection - * @private */ - onClose() { + private onClose() { this.state = 'reconnecting'; - this.trigger('_closed_'); + (this as any).trigger('_closed_'); } /** * Callback of when received a message from connection - * @private */ - onMessage(message) { + private onMessage(message) { try { const msg = JSON.parse(message.data); - if (msg.type) this.trigger(msg.type, msg.body); - } catch(e) { + if (msg.type) (this as any).trigger(msg.type, msg.body); + } catch (e) { // noop } } /** * Send a message to connection - * @public */ - send(message) { + public send(message) { // まだ接続が確立されていなかったらバッファリングして次に接続した時に送信する if (this.state != 'connected') { this.buffer.push(message); return; - }; + } this.socket.send(JSON.stringify(message)); } /** * Close this connection - * @public */ - close() { + public close() { this.socket.removeEventListener('open', this.onOpen); this.socket.removeEventListener('message', this.onMessage); } diff --git a/src/web/app/common/scripts/text-compiler.js b/src/web/app/common/scripts/text-compiler.ts similarity index 94% rename from src/web/app/common/scripts/text-compiler.js rename to src/web/app/common/scripts/text-compiler.ts index 0a9b8022d..8c65d6a06 100644 --- a/src/web/app/common/scripts/text-compiler.js +++ b/src/web/app/common/scripts/text-compiler.ts @@ -1,5 +1,5 @@ import * as riot from 'riot'; -const pictograph = require('pictograph'); +import * as pictograph from 'pictograph'; import CONFIG from './config'; const escape = text => @@ -12,7 +12,7 @@ export default (tokens, shouldBreak) => { shouldBreak = true; } - const me = riot.mixin('i').me; + const me = (riot as any).mixin('i').me; let text = tokens.map(token => { switch (token.type) { diff --git a/src/web/app/common/tags/index.js b/src/web/app/common/tags/index.ts similarity index 100% rename from src/web/app/common/tags/index.js rename to src/web/app/common/tags/index.ts diff --git a/src/web/app/common/tags/messaging/message.tag b/src/web/app/common/tags/messaging/message.tag index d6db9070e..ea1ea2310 100644 --- a/src/web/app/common/tags/messaging/message.tag +++ b/src/web/app/common/tags/messaging/message.tag @@ -219,7 +219,7 @@ this.refs.text.innerHTML = compile(tokens); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); diff --git a/src/web/app/desktop/mixins/index.js b/src/web/app/desktop/mixins/index.ts similarity index 100% rename from src/web/app/desktop/mixins/index.js rename to src/web/app/desktop/mixins/index.ts diff --git a/src/web/app/desktop/mixins/user-preview.js b/src/web/app/desktop/mixins/user-preview.ts similarity index 95% rename from src/web/app/desktop/mixins/user-preview.js rename to src/web/app/desktop/mixins/user-preview.ts index 3f483beb3..614de72be 100644 --- a/src/web/app/desktop/mixins/user-preview.js +++ b/src/web/app/desktop/mixins/user-preview.ts @@ -52,7 +52,7 @@ function attach(el) { clearTimeout(showTimer); hideTimer = setTimeout(close, 500); }); - tag = riot.mount(document.body.appendChild(preview), { + tag = (riot as any).mount(document.body.appendChild(preview), { user: user })[0]; }; diff --git a/src/web/app/desktop/mixins/widget.js b/src/web/app/desktop/mixins/widget.ts similarity index 95% rename from src/web/app/desktop/mixins/widget.js rename to src/web/app/desktop/mixins/widget.ts index cb04295fc..04131cd8f 100644 --- a/src/web/app/desktop/mixins/widget.js +++ b/src/web/app/desktop/mixins/widget.ts @@ -3,7 +3,7 @@ import * as riot from 'riot'; // ミックスインにオプションを渡せないのアレ // SEE: https://github.com/riot/riot/issues/2434 -riot.mixin('widget', { +(riot as any).mixin('widget', { init: function() { this.mixin('i'); this.mixin('api'); diff --git a/src/web/app/desktop/router.js b/src/web/app/desktop/router.ts similarity index 96% rename from src/web/app/desktop/router.js rename to src/web/app/desktop/router.ts index 4675b967d..a74299b28 100644 --- a/src/web/app/desktop/router.js +++ b/src/web/app/desktop/router.ts @@ -3,7 +3,7 @@ */ import * as riot from 'riot'; -const route = require('page'); +import * as route from 'page'; let page = null; export default me => { @@ -83,12 +83,12 @@ export default me => { mount(document.createElement('mk-not-found')); } - riot.mixin('page', { + (riot as any).mixin('page', { page: route }); // EXEC - route(); + (route as any)(); }; function mount(content) { diff --git a/src/web/app/desktop/script.js b/src/web/app/desktop/script.ts similarity index 87% rename from src/web/app/desktop/script.js rename to src/web/app/desktop/script.ts index 46a7fce70..a0453865e 100644 --- a/src/web/app/desktop/script.js +++ b/src/web/app/desktop/script.ts @@ -11,7 +11,7 @@ import * as riot from 'riot'; import init from '../init'; import route from './router'; import fuckAdBlock from './scripts/fuck-ad-block'; -import getPostSummary from '../../../common/get-post-summary.ts'; +import getPostSummary from '../../../common/get-post-summary'; /** * init @@ -27,11 +27,11 @@ init(async (me, stream) => { */ if ('Notification' in window) { // 許可を得ていなかったらリクエスト - if (Notification.permission == 'default') { + if ((Notification as any).permission == 'default') { await Notification.requestPermission(); } - if (Notification.permission == 'granted') { + if ((Notification as any).permission == 'granted') { registerNotifications(stream); } } @@ -82,7 +82,7 @@ function registerNotifications(stream) { }); n.onclick = () => { n.close(); - riot.mount(document.body.appendChild(document.createElement('mk-messaging-room-window')), { + (riot as any).mount(document.body.appendChild(document.createElement('mk-messaging-room-window')), { user: message.user }); }; diff --git a/src/web/app/desktop/scripts/autocomplete.js b/src/web/app/desktop/scripts/autocomplete.ts similarity index 86% rename from src/web/app/desktop/scripts/autocomplete.js rename to src/web/app/desktop/scripts/autocomplete.ts index 8ca516e2a..9df7aae08 100644 --- a/src/web/app/desktop/scripts/autocomplete.js +++ b/src/web/app/desktop/scripts/autocomplete.ts @@ -1,10 +1,12 @@ -const getCaretCoordinates = require('textarea-caret'); +import getCaretCoordinates = require('textarea-caret'); import * as riot from 'riot'; /** * オートコンプリートを管理するクラス。 */ class Autocomplete { + private suggestion: any; + private textarea: any; /** * 対象のテキストエリアを与えてインスタンスを初期化します。 @@ -23,22 +25,22 @@ class Autocomplete { /** * このインスタンスにあるテキストエリアの入力のキャプチャを開始します。 */ - attach() { + public attach() { this.textarea.addEventListener('input', this.onInput); } /** * このインスタンスにあるテキストエリアの入力のキャプチャを解除します。 */ - detach() { + public detach() { this.textarea.removeEventListener('input', this.onInput); this.close(); } /** - * [Private] テキスト入力時 + * テキスト入力時 */ - onInput() { + private onInput() { this.close(); const caret = this.textarea.selectionStart; @@ -56,9 +58,9 @@ class Autocomplete { } /** - * [Private] サジェストを提示します。 + * サジェストを提示します。 */ - open(type, q) { + private open(type, q) { // 既に開いているサジェストは閉じる this.close(); @@ -81,7 +83,7 @@ class Autocomplete { const el = document.body.appendChild(tag); // マウント - this.suggestion = riot.mount(el, { + this.suggestion = (riot as any).mount(el, { textarea: this.textarea, complete: this.complete, close: this.close, @@ -91,9 +93,9 @@ class Autocomplete { } /** - * [Private] サジェストを閉じます。 + * サジェストを閉じます。 */ - close() { + private close() { if (this.suggestion == null) return; this.suggestion.unmount(); @@ -103,9 +105,9 @@ class Autocomplete { } /** - * [Private] オートコンプリートする + * オートコンプリートする */ - complete(user) { + private complete(user) { this.close(); const value = user.username; diff --git a/src/web/app/desktop/scripts/dialog.js b/src/web/app/desktop/scripts/dialog.ts similarity index 77% rename from src/web/app/desktop/scripts/dialog.js rename to src/web/app/desktop/scripts/dialog.ts index c502d3fcb..816ba4b5f 100644 --- a/src/web/app/desktop/scripts/dialog.js +++ b/src/web/app/desktop/scripts/dialog.ts @@ -1,9 +1,9 @@ import * as riot from 'riot'; -export default (title, text, buttons, canThrough, onThrough) => { +export default (title, text, buttons, canThrough?, onThrough?) => { const dialog = document.body.appendChild(document.createElement('mk-dialog')); const controller = riot.observable(); - riot.mount(dialog, { + (riot as any).mount(dialog, { controller: controller, title: title, text: text, diff --git a/src/web/app/desktop/scripts/fuck-ad-block.js b/src/web/app/desktop/scripts/fuck-ad-block.ts similarity index 94% rename from src/web/app/desktop/scripts/fuck-ad-block.js rename to src/web/app/desktop/scripts/fuck-ad-block.ts index ccfc43ce6..3307ba2f3 100644 --- a/src/web/app/desktop/scripts/fuck-ad-block.js +++ b/src/web/app/desktop/scripts/fuck-ad-block.ts @@ -1,6 +1,8 @@ require('fuckadblock'); import dialog from './dialog'; +declare var fuckAdBlock: any; + export default () => { if (fuckAdBlock === undefined) { adBlockDetected(); diff --git a/src/web/app/desktop/scripts/input-dialog.js b/src/web/app/desktop/scripts/input-dialog.ts similarity index 88% rename from src/web/app/desktop/scripts/input-dialog.js rename to src/web/app/desktop/scripts/input-dialog.ts index 954fabfb6..b06d011c6 100644 --- a/src/web/app/desktop/scripts/input-dialog.js +++ b/src/web/app/desktop/scripts/input-dialog.ts @@ -2,7 +2,7 @@ import * as riot from 'riot'; export default (title, placeholder, defaultValue, onOk, onCancel) => { const dialog = document.body.appendChild(document.createElement('mk-input-dialog')); - return riot.mount(dialog, { + return (riot as any).mount(dialog, { title: title, placeholder: placeholder, 'default': defaultValue, diff --git a/src/web/app/desktop/scripts/not-implemented-exception.js b/src/web/app/desktop/scripts/not-implemented-exception.ts similarity index 100% rename from src/web/app/desktop/scripts/not-implemented-exception.js rename to src/web/app/desktop/scripts/not-implemented-exception.ts diff --git a/src/web/app/desktop/scripts/notify.js b/src/web/app/desktop/scripts/notify.ts similarity index 83% rename from src/web/app/desktop/scripts/notify.js rename to src/web/app/desktop/scripts/notify.ts index e58a8e4d3..2e6cbdeed 100644 --- a/src/web/app/desktop/scripts/notify.js +++ b/src/web/app/desktop/scripts/notify.ts @@ -2,7 +2,7 @@ import * as riot from 'riot'; export default message => { const notification = document.body.appendChild(document.createElement('mk-ui-notification')); - riot.mount(notification, { + (riot as any).mount(notification, { message: message }); }; diff --git a/src/web/app/desktop/scripts/password-dialog.js b/src/web/app/desktop/scripts/password-dialog.ts similarity index 86% rename from src/web/app/desktop/scripts/password-dialog.js rename to src/web/app/desktop/scripts/password-dialog.ts index 2bdc93e42..39d7f3db7 100644 --- a/src/web/app/desktop/scripts/password-dialog.js +++ b/src/web/app/desktop/scripts/password-dialog.ts @@ -2,7 +2,7 @@ import * as riot from 'riot'; export default (title, onOk, onCancel) => { const dialog = document.body.appendChild(document.createElement('mk-input-dialog')); - return riot.mount(dialog, { + return (riot as any).mount(dialog, { title: title, type: 'password', onOk: onOk, diff --git a/src/web/app/desktop/scripts/update-avatar.js b/src/web/app/desktop/scripts/update-avatar.ts similarity index 82% rename from src/web/app/desktop/scripts/update-avatar.js rename to src/web/app/desktop/scripts/update-avatar.ts index 165c90567..5fd7f2d3d 100644 --- a/src/web/app/desktop/scripts/update-avatar.js +++ b/src/web/app/desktop/scripts/update-avatar.ts @@ -5,7 +5,7 @@ import api from '../../common/scripts/api'; export default (I, cb, file = null) => { const fileSelected = file => { - const cropper = riot.mount(document.body.appendChild(document.createElement('mk-crop-window')), { + const cropper = (riot as any).mount(document.body.appendChild(document.createElement('mk-crop-window')), { file: file, title: 'アバターとして表示する部分を選択', aspectRatio: 1 / 1 @@ -37,7 +37,7 @@ export default (I, cb, file = null) => { }; const upload = (data, folder) => { - const progress = riot.mount(document.body.appendChild(document.createElement('mk-progress-dialog')), { + const progress = (riot as any).mount(document.body.appendChild(document.createElement('mk-progress-dialog')), { title: '新しいアバターをアップロードしています' })[0]; @@ -46,7 +46,7 @@ export default (I, cb, file = null) => { const xhr = new XMLHttpRequest(); xhr.open('POST', CONFIG.apiUrl + '/drive/files/create', true); xhr.onload = e => { - const file = JSON.parse(e.target.response); + const file = JSON.parse((e.target as any).response); progress.close(); set(file); }; @@ -75,7 +75,7 @@ export default (I, cb, file = null) => { if (file) { fileSelected(file); } else { - const browser = riot.mount(document.body.appendChild(document.createElement('mk-select-file-from-drive-window')), { + const browser = (riot as any).mount(document.body.appendChild(document.createElement('mk-select-file-from-drive-window')), { multiple: false, title: 'アバターにする画像を選択' })[0]; diff --git a/src/web/app/desktop/scripts/update-banner.js b/src/web/app/desktop/scripts/update-banner.ts similarity index 82% rename from src/web/app/desktop/scripts/update-banner.js rename to src/web/app/desktop/scripts/update-banner.ts index d83b2bf1b..23a671c44 100644 --- a/src/web/app/desktop/scripts/update-banner.js +++ b/src/web/app/desktop/scripts/update-banner.ts @@ -5,7 +5,7 @@ import api from '../../common/scripts/api'; export default (I, cb, file = null) => { const fileSelected = file => { - const cropper = riot.mount(document.body.appendChild(document.createElement('mk-crop-window')), { + const cropper = (riot as any).mount(document.body.appendChild(document.createElement('mk-crop-window')), { file: file, title: 'バナーとして表示する部分を選択', aspectRatio: 16 / 9 @@ -37,7 +37,7 @@ export default (I, cb, file = null) => { }; const upload = (data, folder) => { - const progress = riot.mount(document.body.appendChild(document.createElement('mk-progress-dialog')), { + const progress = (riot as any).mount(document.body.appendChild(document.createElement('mk-progress-dialog')), { title: '新しいバナーをアップロードしています' })[0]; @@ -46,7 +46,7 @@ export default (I, cb, file = null) => { const xhr = new XMLHttpRequest(); xhr.open('POST', CONFIG.apiUrl + '/drive/files/create', true); xhr.onload = e => { - const file = JSON.parse(e.target.response); + const file = JSON.parse((e.target as any).response); progress.close(); set(file); }; @@ -75,7 +75,7 @@ export default (I, cb, file = null) => { if (file) { fileSelected(file); } else { - const browser = riot.mount(document.body.appendChild(document.createElement('mk-select-file-from-drive-window')), { + const browser = (riot as any).mount(document.body.appendChild(document.createElement('mk-select-file-from-drive-window')), { multiple: false, title: 'バナーにする画像を選択' })[0]; diff --git a/src/web/app/desktop/tags/autocomplete-suggestion.tag b/src/web/app/desktop/tags/autocomplete-suggestion.tag index b93636040..731160669 100644 --- a/src/web/app/desktop/tags/autocomplete-suggestion.tag +++ b/src/web/app/desktop/tags/autocomplete-suggestion.tag @@ -177,7 +177,7 @@ }; this.applySelect = () => { - this.refs.users.children.forEach(el => { + Array.from(this.refs.users.children).forEach(el => { el.removeAttribute('data-selected'); }); diff --git a/src/web/app/desktop/tags/drive/browser.tag b/src/web/app/desktop/tags/drive/browser.tag index be16a782d..18e27f24b 100644 --- a/src/web/app/desktop/tags/drive/browser.tag +++ b/src/web/app/desktop/tags/drive/browser.tag @@ -408,7 +408,7 @@ // ドロップされてきたものがファイルだったら if (e.dataTransfer.files.length > 0) { - e.dataTransfer.files.forEach(file => { + Array.from(e.dataTransfer.files).forEach(file => { this.upload(file, this.folder); }); return false; @@ -510,7 +510,7 @@ }; this.changeFileInput = () => { - this.refs.fileInput.files.forEach(file => { + Array.from(this.refs.fileInput.files).forEach(file => { this.upload(file, this.folder); }); }; diff --git a/src/web/app/desktop/tags/drive/folder.tag b/src/web/app/desktop/tags/drive/folder.tag index e03c4e353..1c361c8e4 100644 --- a/src/web/app/desktop/tags/drive/folder.tag +++ b/src/web/app/desktop/tags/drive/folder.tag @@ -109,7 +109,7 @@ // ファイルだったら if (e.dataTransfer.files.length > 0) { - e.dataTransfer.files.forEach(file => { + Array.from(e.dataTransfer.files).forEach(file => { this.browser.upload(file, this.folder); }); return false; diff --git a/src/web/app/desktop/tags/drive/nav-folder.tag b/src/web/app/desktop/tags/drive/nav-folder.tag index c89d9edc1..0a9421353 100644 --- a/src/web/app/desktop/tags/drive/nav-folder.tag +++ b/src/web/app/desktop/tags/drive/nav-folder.tag @@ -55,7 +55,7 @@ // ファイルだったら if (e.dataTransfer.files.length > 0) { - e.dataTransfer.files.forEach(file => { + Array.from(e.dataTransfer.files).forEach(file => { this.browser.upload(file, this.folder); }); return false; diff --git a/src/web/app/desktop/tags/index.js b/src/web/app/desktop/tags/index.ts similarity index 100% rename from src/web/app/desktop/tags/index.js rename to src/web/app/desktop/tags/index.ts diff --git a/src/web/app/desktop/tags/post-detail-sub.tag b/src/web/app/desktop/tags/post-detail-sub.tag index 8a0ada5f2..e22386df9 100644 --- a/src/web/app/desktop/tags/post-detail-sub.tag +++ b/src/web/app/desktop/tags/post-detail-sub.tag @@ -129,7 +129,7 @@ this.refs.text.innerHTML = compile(tokens); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); } diff --git a/src/web/app/desktop/tags/post-detail.tag b/src/web/app/desktop/tags/post-detail.tag index ce7f81e32..1a0eefe13 100644 --- a/src/web/app/desktop/tags/post-detail.tag +++ b/src/web/app/desktop/tags/post-detail.tag @@ -273,7 +273,7 @@ this.refs.text.innerHTML = compile(tokens); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); diff --git a/src/web/app/desktop/tags/post-form.tag b/src/web/app/desktop/tags/post-form.tag index 5041078be..e49beeedb 100644 --- a/src/web/app/desktop/tags/post-form.tag +++ b/src/web/app/desktop/tags/post-form.tag @@ -405,7 +405,7 @@ // ファイルだったら if (e.dataTransfer.files.length > 0) { - e.dataTransfer.files.forEach(this.upload); + Array.from(e.dataTransfer.files).forEach(this.upload); } }; @@ -414,7 +414,7 @@ }; this.onpaste = e => { - e.clipboardData.items.forEach(item => { + Array.from(e.clipboardData.items).forEach(item => { if (item.kind == 'file') { this.upload(item.getAsFile()); } @@ -435,7 +435,7 @@ }; this.changeFile = () => { - this.refs.file.files.forEach(this.upload); + Array.from(this.refs.file.files).forEach(this.upload); }; this.upload = file => { diff --git a/src/web/app/desktop/tags/sub-post-content.tag b/src/web/app/desktop/tags/sub-post-content.tag index c75ae2911..86269fdbe 100644 --- a/src/web/app/desktop/tags/sub-post-content.tag +++ b/src/web/app/desktop/tags/sub-post-content.tag @@ -45,7 +45,7 @@ const tokens = this.post.ast; this.refs.text.innerHTML = compile(tokens, false); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); } diff --git a/src/web/app/desktop/tags/timeline.tag b/src/web/app/desktop/tags/timeline.tag index 44f3d5d8e..5e3b883b4 100644 --- a/src/web/app/desktop/tags/timeline.tag +++ b/src/web/app/desktop/tags/timeline.tag @@ -498,7 +498,7 @@ this.refs.text.innerHTML = this.refs.text.innerHTML.replace('

', compile(tokens)); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); diff --git a/src/web/app/dev/router.js b/src/web/app/dev/router.ts similarity index 94% rename from src/web/app/dev/router.js rename to src/web/app/dev/router.ts index 7fde30fa5..532ec23c7 100644 --- a/src/web/app/dev/router.js +++ b/src/web/app/dev/router.ts @@ -1,5 +1,5 @@ import * as riot from 'riot'; -const route = require('page'); +import * as route from 'page'; let page = null; export default me => { @@ -32,7 +32,7 @@ export default me => { } // EXEC - route(); + (route as any)(); }; function mount(content) { diff --git a/src/web/app/dev/script.js b/src/web/app/dev/script.ts similarity index 100% rename from src/web/app/dev/script.js rename to src/web/app/dev/script.ts diff --git a/src/web/app/dev/tags/index.js b/src/web/app/dev/tags/index.ts similarity index 100% rename from src/web/app/dev/tags/index.js rename to src/web/app/dev/tags/index.ts diff --git a/src/web/app/init.js b/src/web/app/init.ts similarity index 81% rename from src/web/app/init.js rename to src/web/app/init.ts index d3817fe97..e68a7c915 100644 --- a/src/web/app/init.js +++ b/src/web/app/init.ts @@ -2,14 +2,13 @@ * App initializer */ -'use strict'; +declare var VERSION: string; +declare var LANG: string; import * as riot from 'riot'; -import api from './common/scripts/api'; import signout from './common/scripts/signout'; import checkForUpdate from './common/scripts/check-for-update'; import Connection from './common/scripts/home-stream'; -import ServerStreamManager from './common/scripts/server-stream-manager.ts'; import Progress from './common/scripts/loading'; import mixin from './common/mixins'; import CONFIG from './common/scripts/config'; @@ -37,21 +36,7 @@ console.info(`Misskey v${VERSION} (葵 aoi)`); document.domain = CONFIG.host; // Set global configuration -riot.mixin({ CONFIG }); - -// ↓ NodeList、HTMLCollection、FileList、DataTransferItemListで forEach を使えるようにする -if (NodeList.prototype.forEach === undefined) { - NodeList.prototype.forEach = Array.prototype.forEach; -} -if (HTMLCollection.prototype.forEach === undefined) { - HTMLCollection.prototype.forEach = Array.prototype.forEach; -} -if (FileList.prototype.forEach === undefined) { - FileList.prototype.forEach = Array.prototype.forEach; -} -if (window.DataTransferItemList && DataTransferItemList.prototype.forEach === undefined) { - DataTransferItemList.prototype.forEach = Array.prototype.forEach; -} +(riot as any).mixin({ CONFIG }); // iOSでプライベートモードだとlocalStorageが使えないので既存のメソッドを上書きする try { @@ -72,7 +57,7 @@ setTimeout(checkForUpdate, 3000); // ユーザーをフェッチしてコールバックする export default callback => { // Get cached account data - let cachedMe = JSON.parse(localStorage.getItem('me')); + const cachedMe = JSON.parse(localStorage.getItem('me')); if (cachedMe) { fetched(cachedMe); @@ -112,11 +97,8 @@ export default callback => { // Init home stream connection const stream = me ? new Connection(me) : null; - // Init server stream connection manager - const serverStreamManager = new ServerStreamManager(); - // ミックスイン初期化 - mixin(me, stream, serverStreamManager); + mixin(me, stream); // ローディング画面クリア const ini = document.getElementById('ini'); diff --git a/src/web/app/mobile/router.js b/src/web/app/mobile/router.ts similarity index 97% rename from src/web/app/mobile/router.js rename to src/web/app/mobile/router.ts index 01eb3c814..7fae9db54 100644 --- a/src/web/app/mobile/router.js +++ b/src/web/app/mobile/router.ts @@ -3,7 +3,7 @@ */ import * as riot from 'riot'; -const route = require('page'); +import * as route from 'page'; let page = null; export default me => { @@ -131,12 +131,12 @@ export default me => { mount(document.createElement('mk-not-found')); } - riot.mixin('page', { + (riot as any).mixin('page', { page: route }); // EXEC - route(); + (route as any)(); }; function mount(content) { diff --git a/src/web/app/mobile/script.js b/src/web/app/mobile/script.ts similarity index 100% rename from src/web/app/mobile/script.js rename to src/web/app/mobile/script.ts diff --git a/src/web/app/mobile/scripts/open-post-form.js b/src/web/app/mobile/scripts/open-post-form.ts similarity index 100% rename from src/web/app/mobile/scripts/open-post-form.js rename to src/web/app/mobile/scripts/open-post-form.ts diff --git a/src/web/app/mobile/scripts/ui-event.js b/src/web/app/mobile/scripts/ui-event.ts similarity index 100% rename from src/web/app/mobile/scripts/ui-event.js rename to src/web/app/mobile/scripts/ui-event.ts diff --git a/src/web/app/mobile/tags/drive.tag b/src/web/app/mobile/tags/drive.tag index 6929c50ab..870a451ac 100644 --- a/src/web/app/mobile/tags/drive.tag +++ b/src/web/app/mobile/tags/drive.tag @@ -561,7 +561,7 @@ }; this.changeLocalFile = () => { - this.refs.file.files.forEach(f => this.refs.uploader.upload(f, this.folder)); + Array.from(this.refs.file.files).forEach(f => this.refs.uploader.upload(f, this.folder)); }; diff --git a/src/web/app/mobile/tags/index.js b/src/web/app/mobile/tags/index.ts similarity index 100% rename from src/web/app/mobile/tags/index.js rename to src/web/app/mobile/tags/index.ts diff --git a/src/web/app/mobile/tags/post-detail.tag b/src/web/app/mobile/tags/post-detail.tag index 8a3210103..28071a5ca 100644 --- a/src/web/app/mobile/tags/post-detail.tag +++ b/src/web/app/mobile/tags/post-detail.tag @@ -285,7 +285,7 @@ this.refs.text.innerHTML = compile(tokens); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); diff --git a/src/web/app/mobile/tags/post-form.tag b/src/web/app/mobile/tags/post-form.tag index d7d382c9e..2912bfdfa 100644 --- a/src/web/app/mobile/tags/post-form.tag +++ b/src/web/app/mobile/tags/post-form.tag @@ -207,7 +207,7 @@ }; this.onpaste = e => { - e.clipboardData.items.forEach(item => { + Array.from(e.clipboardData.items).forEach(item => { if (item.kind == 'file') { this.upload(item.getAsFile()); } @@ -228,7 +228,7 @@ }; this.changeFile = () => { - this.refs.file.files.forEach(this.upload); + Array.from(this.refs.file.files).forEach(this.upload); }; this.upload = file => { diff --git a/src/web/app/mobile/tags/sub-post-content.tag b/src/web/app/mobile/tags/sub-post-content.tag index e32e24518..c14233d3b 100644 --- a/src/web/app/mobile/tags/sub-post-content.tag +++ b/src/web/app/mobile/tags/sub-post-content.tag @@ -37,7 +37,7 @@ const tokens = this.post.ast; this.refs.text.innerHTML = compile(tokens, false); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); } diff --git a/src/web/app/mobile/tags/timeline.tag b/src/web/app/mobile/tags/timeline.tag index f9ec2cca6..52f6f27ea 100644 --- a/src/web/app/mobile/tags/timeline.tag +++ b/src/web/app/mobile/tags/timeline.tag @@ -538,7 +538,7 @@ this.refs.text.innerHTML = this.refs.text.innerHTML.replace('

', compile(tokens)); - this.refs.text.children.forEach(e => { + Array.from(this.refs.text.children).forEach(e => { if (e.tagName == 'MK-URL') riot.mount(e); }); diff --git a/src/web/app/stats/script.js b/src/web/app/stats/script.ts similarity index 100% rename from src/web/app/stats/script.js rename to src/web/app/stats/script.ts diff --git a/src/web/app/stats/tags/index.js b/src/web/app/stats/tags/index.ts similarity index 100% rename from src/web/app/stats/tags/index.js rename to src/web/app/stats/tags/index.ts diff --git a/src/web/app/status/script.js b/src/web/app/status/script.ts similarity index 100% rename from src/web/app/status/script.js rename to src/web/app/status/script.ts diff --git a/src/web/app/status/tags/index.js b/src/web/app/status/tags/index.ts similarity index 100% rename from src/web/app/status/tags/index.js rename to src/web/app/status/tags/index.ts diff --git a/tslint.json b/tslint.json index 1c4457951..d3f96000b 100644 --- a/tslint.json +++ b/tslint.json @@ -13,6 +13,7 @@ "object-literal-sort-keys": false, "curly": false, "no-console": [false], + "no-empty":false, "ordered-imports": [false], "arrow-parens": false, "object-literal-shorthand": false, diff --git a/webpack/webpack.config.ts b/webpack/webpack.config.ts index 97782a410..f2bcf48f3 100644 --- a/webpack/webpack.config.ts +++ b/webpack/webpack.config.ts @@ -14,13 +14,13 @@ module.exports = langs.map(([lang, locale]) => { // Entries const entry = { - desktop: './src/web/app/desktop/script.js', - mobile: './src/web/app/mobile/script.js', - ch: './src/web/app/ch/script.js', - stats: './src/web/app/stats/script.js', - status: './src/web/app/status/script.js', - dev: './src/web/app/dev/script.js', - auth: './src/web/app/auth/script.js' + desktop: './src/web/app/desktop/script.ts', + mobile: './src/web/app/mobile/script.ts', + ch: './src/web/app/ch/script.ts', + stats: './src/web/app/stats/script.ts', + status: './src/web/app/status/script.ts', + dev: './src/web/app/dev/script.ts', + auth: './src/web/app/auth/script.ts' }; const output = { @@ -33,6 +33,11 @@ module.exports = langs.map(([lang, locale]) => { entry, module: module_(lang, locale), plugins: plugins(version, lang), - output + output, + resolve: { + extensions: [ + '.js', '.ts' + ] + } }; });