diff --git a/src/web/app/common/views/components/messaging-form.vue b/src/web/app/common/views/components/messaging-form.vue index bf4dd17baa..18d45790e4 100644 --- a/src/web/app/common/views/components/messaging-form.vue +++ b/src/web/app/common/views/components/messaging-form.vue @@ -62,7 +62,7 @@ export default Vue.extend({ send() { this.sending = true; - this.$root.$data.os.api('messaging/messages/create', { + (this as any).api('messaging/messages/create', { user_id: this.user.id, text: this.text }).then(message => { diff --git a/src/web/app/common/views/components/messaging-message.vue b/src/web/app/common/views/components/messaging-message.vue index b1afe7a690..6f44332aff 100644 --- a/src/web/app/common/views/components/messaging-message.vue +++ b/src/web/app/common/views/components/messaging-message.vue @@ -8,7 +8,7 @@

%i18n:common.tags.mk-messaging-message.is-read%

- +
image
@@ -30,7 +30,7 @@ export default Vue.extend({ props: ['message'], computed: { isMe(): boolean { - return this.message.user_id == this.$root.$data.os.i.id; + return this.message.user_id == (this as any).os.i.id; }, urls(): string[] { if (this.message.ast) { diff --git a/src/web/app/common/views/components/messaging-room.vue b/src/web/app/common/views/components/messaging-room.vue index 838e1e2653..978610d7ff 100644 --- a/src/web/app/common/views/components/messaging-room.vue +++ b/src/web/app/common/views/components/messaging-room.vue @@ -48,7 +48,7 @@ export default Vue.extend({ }, mounted() { - this.connection = new MessagingStreamConnection(this.$root.$data.os.i, this.user.id); + this.connection = new MessagingStreamConnection((this as any).os.i, this.user.id); this.connection.on('message', this.onMessage); this.connection.on('read', this.onRead); @@ -72,7 +72,7 @@ export default Vue.extend({ return new Promise((resolve, reject) => { const max = this.existMoreMessages ? 20 : 10; - this.$root.$data.os.api('messaging/messages', { + (this as any).api('messaging/messages', { user_id: this.user.id, limit: max + 1, until_id: this.existMoreMessages ? this.messages[0].id : undefined @@ -99,7 +99,7 @@ export default Vue.extend({ const isBottom = this.isBottom(); this.messages.push(message); - if (message.user_id != this.$root.$data.os.i.id && !document.hidden) { + if (message.user_id != (this as any).os.i.id && !document.hidden) { this.connection.send({ type: 'read', id: message.id @@ -109,7 +109,7 @@ export default Vue.extend({ if (isBottom) { // Scroll to bottom this.scrollToBottom(); - } else if (message.user_id != this.$root.$data.os.i.id) { + } else if (message.user_id != (this as any).os.i.id) { // Notify this.notify('%i18n:common.tags.mk-messaging-room.new-message%'); } @@ -157,7 +157,7 @@ export default Vue.extend({ onVisibilitychange() { if (document.hidden) return; this.messages.forEach(message => { - if (message.user_id !== this.$root.$data.os.i.id && !message.is_read) { + if (message.user_id !== (this as any).os.i.id && !message.is_read) { this.connection.send({ type: 'read', id: message.id diff --git a/src/web/app/common/views/components/messaging.vue b/src/web/app/common/views/components/messaging.vue index f45f99b535..1b56382b08 100644 --- a/src/web/app/common/views/components/messaging.vue +++ b/src/web/app/common/views/components/messaging.vue @@ -71,13 +71,13 @@ export default Vue.extend({ }; }, mounted() { - this.connection = this.$root.$data.os.streams.messagingIndexStream.getConnection(); - this.connectionId = this.$root.$data.os.streams.messagingIndexStream.use(); + this.connection = (this as any).os.streams.messagingIndexStream.getConnection(); + this.connectionId = (this as any).os.streams.messagingIndexStream.use(); this.connection.on('message', this.onMessage); this.connection.on('read', this.onRead); - this.$root.$data.os.api('messaging/history').then(messages => { + (this as any).api('messaging/history').then(messages => { this.fetching = false; this.messages = messages; }); @@ -85,11 +85,11 @@ export default Vue.extend({ beforeDestroy() { this.connection.off('message', this.onMessage); this.connection.off('read', this.onRead); - this.$root.$data.os.stream.dispose(this.connectionId); + (this as any).os.stream.dispose(this.connectionId); }, methods: { isMe(message) { - return message.user_id == this.$root.$data.os.i.id; + return message.user_id == (this as any).os.i.id; }, onMessage(message) { this.messages = this.messages.filter(m => !( @@ -109,7 +109,7 @@ export default Vue.extend({ this.result = []; return; } - this.$root.$data.os.api('users/search', { + (this as any).api('users/search', { query: this.q, max: 5 }).then(users => { diff --git a/src/web/app/common/views/components/poll.vue b/src/web/app/common/views/components/poll.vue index 19ce557e73..d06c019dba 100644 --- a/src/web/app/common/views/components/poll.vue +++ b/src/web/app/common/views/components/poll.vue @@ -47,7 +47,7 @@ }, vote(id) { if (this.poll.choices.some(c => c.is_voted)) return; - this.$root.$data.os.api('posts/polls/vote', { + (this as any).api('posts/polls/vote', { post_id: this.post.id, choice: id }).then(() => { diff --git a/src/web/app/common/views/components/post-menu.vue b/src/web/app/common/views/components/post-menu.vue index 7a33360f60..e14d67fc8d 100644 --- a/src/web/app/common/views/components/post-menu.vue +++ b/src/web/app/common/views/components/post-menu.vue @@ -48,7 +48,7 @@ export default Vue.extend({ }, methods: { pin() { - this.$root.$data.os.api('i/pin', { + (this as any).api('i/pin', { post_id: this.post.id }).then(() => { this.$destroy(); diff --git a/src/web/app/common/views/components/reaction-picker.vue b/src/web/app/common/views/components/reaction-picker.vue index 0446d7b18e..f3731cd632 100644 --- a/src/web/app/common/views/components/reaction-picker.vue +++ b/src/web/app/common/views/components/reaction-picker.vue @@ -68,7 +68,7 @@ export default Vue.extend({ }, methods: { react(reaction) { - this.$root.$data.os.api('posts/reactions/create', { + (this as any).api('posts/reactions/create', { post_id: this.post.id, reaction: reaction }).then(() => { diff --git a/src/web/app/common/views/components/signin.vue b/src/web/app/common/views/components/signin.vue index 989c017054..31243e99a1 100644 --- a/src/web/app/common/views/components/signin.vue +++ b/src/web/app/common/views/components/signin.vue @@ -28,7 +28,7 @@ export default Vue.extend({ }, methods: { onUsernameChange() { - this.$root.$data.os.api('users/show', { + (this as any).api('users/show', { username: this.username }).then(user => { this.user = user; @@ -37,7 +37,7 @@ export default Vue.extend({ onSubmit() { this.signing = true; - this.$root.$data.os.api('signin', { + (this as any).api('signin', { username: this.username, password: this.password, token: this.user && this.user.two_factor_enabled ? this.token : undefined diff --git a/src/web/app/common/views/components/signup.vue b/src/web/app/common/views/components/signup.vue index 34d17ef0ea..1fdc49a181 100644 --- a/src/web/app/common/views/components/signup.vue +++ b/src/web/app/common/views/components/signup.vue @@ -88,7 +88,7 @@ export default Vue.extend({ this.usernameState = 'wait'; - this.$root.$data.os.api('username/available', { + (this as any).api('username/available', { username: this.username }).then(result => { this.usernameState = result.available ? 'ok' : 'unavailable'; @@ -115,12 +115,12 @@ export default Vue.extend({ this.passwordRetypeState = this.password == this.retypedPassword ? 'match' : 'not-match'; }, onSubmit() { - this.$root.$data.os.api('signup', { + (this as any).api('signup', { username: this.username, password: this.password, 'g-recaptcha-response': (window as any).grecaptcha.getResponse() }).then(() => { - this.$root.$data.os.api('signin', { + (this as any).api('signin', { username: this.username, password: this.password }).then(() => { diff --git a/src/web/app/common/views/components/stream-indicator.vue b/src/web/app/common/views/components/stream-indicator.vue index 00bd58c1f9..c1c0672e48 100644 --- a/src/web/app/common/views/components/stream-indicator.vue +++ b/src/web/app/common/views/components/stream-indicator.vue @@ -26,10 +26,10 @@ export default Vue.extend({ }; }, created() { - this.stream = this.$root.$data.os.stream.borrow(); + this.stream = (this as any).os.stream.borrow(); - this.$root.$data.os.stream.on('connected', this.onConnected); - this.$root.$data.os.stream.on('disconnected', this.onDisconnected); + (this as any).os.stream.on('connected', this.onConnected); + (this as any).os.stream.on('disconnected', this.onDisconnected); this.$nextTick(() => { if (this.stream.state == 'connected') { @@ -38,12 +38,12 @@ export default Vue.extend({ }); }, beforeDestroy() { - this.$root.$data.os.stream.off('connected', this.onConnected); - this.$root.$data.os.stream.off('disconnected', this.onDisconnected); + (this as any).os.stream.off('connected', this.onConnected); + (this as any).os.stream.off('disconnected', this.onDisconnected); }, methods: { onConnected() { - this.stream = this.$root.$data.os.stream.borrow(); + this.stream = (this as any).os.stream.borrow(); setTimeout(() => { anime({ diff --git a/src/web/app/common/views/components/uploader.vue b/src/web/app/common/views/components/uploader.vue index 21f92caabf..6367b69973 100644 --- a/src/web/app/common/views/components/uploader.vue +++ b/src/web/app/common/views/components/uploader.vue @@ -50,7 +50,7 @@ export default Vue.extend({ reader.readAsDataURL(file); const data = new FormData(); - data.append('i', this.$root.$data.os.i.token); + data.append('i', (this as any).os.i.token); data.append('file', file); if (folder) data.append('folder_id', folder); diff --git a/src/web/app/common/views/components/widgets/photo-stream.vue b/src/web/app/common/views/components/widgets/photo-stream.vue index afbdc2162c..4d6b660696 100644 --- a/src/web/app/common/views/components/widgets/photo-stream.vue +++ b/src/web/app/common/views/components/widgets/photo-stream.vue @@ -26,12 +26,12 @@ export default define({ }; }, mounted() { - this.connection = this.$root.$data.os.stream.getConnection(); - this.connectionId = this.$root.$data.os.stream.use(); + this.connection = (this as any).os.stream.getConnection(); + this.connectionId = (this as any).os.stream.use(); this.connection.on('drive_file_created', this.onDriveFileCreated); - this.$root.$data.os.api('drive/stream', { + (this as any).api('drive/stream', { type: 'image/*', limit: 9 }).then(images => { @@ -41,7 +41,7 @@ export default define({ }, beforeDestroy() { this.connection.off('drive_file_created', this.onDriveFileCreated); - this.$root.$data.os.stream.dispose(this.connectionId); + (this as any).os.stream.dispose(this.connectionId); }, methods: { onDriveFileCreated(file) { diff --git a/src/web/app/common/views/components/widgets/slideshow.vue b/src/web/app/common/views/components/widgets/slideshow.vue index c24e3003c4..a200aa061d 100644 --- a/src/web/app/common/views/components/widgets/slideshow.vue +++ b/src/web/app/common/views/components/widgets/slideshow.vue @@ -89,7 +89,7 @@ export default define({ fetch() { this.fetching = true; - this.$root.$data.os.api('drive/files', { + (this as any).api('drive/files', { folder_id: this.props.folder, type: 'image/*', limit: 100 @@ -102,7 +102,7 @@ export default define({ }); }, choose() { - this.$root.$data.api.chooseDriveFolder().then(folder => { + (this as any).apis.chooseDriveFolder().then(folder => { this.props.folder = folder ? folder.id : null; this.fetch(); }); diff --git a/src/web/app/desktop/-tags/drive/browser-window.tag b/src/web/app/desktop/-tags/drive/browser-window.tag deleted file mode 100644 index c9c7652521..0000000000 --- a/src/web/app/desktop/-tags/drive/browser-window.tag +++ /dev/null @@ -1,60 +0,0 @@ - - - -

{ parent.usage.toFixed(1) }% %i18n:desktop.tags.mk-drive-browser-window.used%

- %fa:cloud%%i18n:desktop.tags.mk-drive-browser-window.drive% -
- - - -
- - -
diff --git a/src/web/app/desktop/-tags/drive/file-contextmenu.tag b/src/web/app/desktop/-tags/drive/file-contextmenu.tag deleted file mode 100644 index 8776fcc029..0000000000 --- a/src/web/app/desktop/-tags/drive/file-contextmenu.tag +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - diff --git a/src/web/app/desktop/-tags/drive/folder-contextmenu.tag b/src/web/app/desktop/-tags/drive/folder-contextmenu.tag deleted file mode 100644 index a0146410f6..0000000000 --- a/src/web/app/desktop/-tags/drive/folder-contextmenu.tag +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - diff --git a/src/web/app/desktop/api/choose-drive-file.ts b/src/web/app/desktop/api/choose-drive-file.ts new file mode 100644 index 0000000000..e048441713 --- /dev/null +++ b/src/web/app/desktop/api/choose-drive-file.ts @@ -0,0 +1,18 @@ +import MkChooseFileFromDriveWindow from '../views/components/choose-file-from-drive-window.vue'; + +export default function(opts) { + return new Promise((res, rej) => { + const o = opts || {}; + const w = new MkChooseFileFromDriveWindow({ + propsData: { + title: o.title, + multiple: o.multiple, + initFolder: o.currentFolder + } + }).$mount(); + w.$once('selected', file => { + res(file); + }); + document.body.appendChild(w.$el); + }); +} diff --git a/src/web/app/desktop/api/choose-drive-folder.ts b/src/web/app/desktop/api/choose-drive-folder.ts index a5116f7bcd..9b33a20d9a 100644 --- a/src/web/app/desktop/api/choose-drive-folder.ts +++ b/src/web/app/desktop/api/choose-drive-folder.ts @@ -1,12 +1,12 @@ -import MkChooseFolderFromDriveWindow from '../../../common/views/components/choose-folder-from-drive-window.vue'; +import MkChooseFolderFromDriveWindow from '../views/components/choose-folder-from-drive-window.vue'; -export default function(this: any, opts) { +export default function(opts) { return new Promise((res, rej) => { const o = opts || {}; const w = new MkChooseFolderFromDriveWindow({ - parent: this, propsData: { - title: o.title + title: o.title, + initFolder: o.currentFolder } }).$mount(); w.$once('selected', folder => { diff --git a/src/web/app/desktop/api/contextmenu.ts b/src/web/app/desktop/api/contextmenu.ts new file mode 100644 index 0000000000..b70d7122d3 --- /dev/null +++ b/src/web/app/desktop/api/contextmenu.ts @@ -0,0 +1,16 @@ +import Ctx from '../views/components/context-menu.vue'; + +export default function(e, menu, opts?) { + const o = opts || {}; + const vm = new Ctx({ + propsData: { + menu, + x: e.pageX - window.pageXOffset, + y: e.pageY - window.pageYOffset, + } + }).$mount(); + vm.$once('closed', () => { + if (o.closed) o.closed(); + }); + document.body.appendChild(vm.$el); +} diff --git a/src/web/app/desktop/api/dialog.ts b/src/web/app/desktop/api/dialog.ts new file mode 100644 index 0000000000..07935485b0 --- /dev/null +++ b/src/web/app/desktop/api/dialog.ts @@ -0,0 +1,19 @@ +import Dialog from '../views/components/dialog.vue'; + +export default function(opts) { + return new Promise((res, rej) => { + const o = opts || {}; + const d = new Dialog({ + propsData: { + title: o.title, + text: o.text, + modal: o.modal, + buttons: o.actions + } + }).$mount(); + d.$once('clicked', id => { + res(id); + }); + document.body.appendChild(d.$el); + }); +} diff --git a/src/web/app/desktop/api/input.ts b/src/web/app/desktop/api/input.ts new file mode 100644 index 0000000000..a5ab07138a --- /dev/null +++ b/src/web/app/desktop/api/input.ts @@ -0,0 +1,19 @@ +import InputDialog from '../views/components/input-dialog.vue'; + +export default function(opts) { + return new Promise((res, rej) => { + const o = opts || {}; + const d = new InputDialog({ + propsData: { + title: o.title, + placeholder: o.placeholder, + default: o.default, + type: o.type || 'text' + } + }).$mount(); + d.$once('done', text => { + res(text); + }); + document.body.appendChild(d.$el); + }); +} diff --git a/src/web/app/desktop/script.ts b/src/web/app/desktop/script.ts index cd894170e2..cb7a53fb2b 100644 --- a/src/web/app/desktop/script.ts +++ b/src/web/app/desktop/script.ts @@ -11,6 +11,9 @@ import HomeStreamManager from '../common/scripts/streaming/home-stream-manager'; import composeNotification from '../common/scripts/compose-notification'; import chooseDriveFolder from './api/choose-drive-folder'; +import chooseDriveFile from './api/choose-drive-file'; +import dialog from './api/dialog'; +import input from './api/input'; import MkIndex from './views/pages/index.vue'; @@ -30,7 +33,10 @@ init(async (launch) => { require('./views/components'); const app = launch({ - chooseDriveFolder + chooseDriveFolder, + chooseDriveFile, + dialog, + input }); /** diff --git a/src/web/app/desktop/views/components/2fa-setting.vue b/src/web/app/desktop/views/components/2fa-setting.vue index 146d707e1c..8271cbbf36 100644 --- a/src/web/app/desktop/views/components/2fa-setting.vue +++ b/src/web/app/desktop/views/components/2fa-setting.vue @@ -36,7 +36,7 @@ export default Vue.extend({ methods: { register() { passwordDialog('%i18n:desktop.tags.mk-2fa-setting.enter-password%', password => { - this.$root.$data.os.api('i/2fa/register', { + (this as any).api('i/2fa/register', { password: password }).then(data => { this.data = data; @@ -46,21 +46,21 @@ export default Vue.extend({ unregister() { passwordDialog('%i18n:desktop.tags.mk-2fa-setting.enter-password%', password => { - this.$root.$data.os.api('i/2fa/unregister', { + (this as any).api('i/2fa/unregister', { password: password }).then(() => { notify('%i18n:desktop.tags.mk-2fa-setting.unregistered%'); - this.$root.$data.os.i.two_factor_enabled = false; + (this as any).os.i.two_factor_enabled = false; }); }); }, submit() { - this.$root.$data.os.api('i/2fa/done', { + (this as any).api('i/2fa/done', { token: this.token }).then(() => { notify('%i18n:desktop.tags.mk-2fa-setting.success%'); - this.$root.$data.os.i.two_factor_enabled = true; + (this as any).os.i.two_factor_enabled = true; }).catch(() => { notify('%i18n:desktop.tags.mk-2fa-setting.failed%'); }); diff --git a/src/web/app/desktop/views/components/api-setting.vue b/src/web/app/desktop/views/components/api-setting.vue index 78429064b9..08c5a0c512 100644 --- a/src/web/app/desktop/views/components/api-setting.vue +++ b/src/web/app/desktop/views/components/api-setting.vue @@ -1,6 +1,6 @@ @@ -28,10 +28,12 @@ + + + diff --git a/src/web/app/desktop/views/components/drive.vue b/src/web/app/desktop/views/components/drive.vue index 5d398dab98..2b33265e5d 100644 --- a/src/web/app/desktop/views/components/drive.vue +++ b/src/web/app/desktop/views/components/drive.vue @@ -2,17 +2,17 @@