From 2e2d0dd6f6c05b7f82a52522f8d7816719e18d9c Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Sun, 29 Apr 2018 01:57:09 +0100 Subject: [PATCH] Make some Vue components available to plugins, add highlight.js module and some tidying --- client/src/modules/pluginapi.js | 36 ++++++------------- client/src/modules/pluginmanager.js | 10 +++--- client/src/modules/webpackmodules.js | 1 + client/src/styles/index.scss | 2 +- client/src/ui/bdui.js | 23 +++--------- client/src/ui/commoncomponents.js | 8 +++++ client/src/ui/components/BdSettings.vue | 3 +- client/src/ui/components/bd/ContentAuthor.vue | 9 +---- client/src/ui/components/common/index.js | 5 +++ client/src/ui/reflection.js | 2 +- package.json | 4 +-- 11 files changed, 40 insertions(+), 63 deletions(-) create mode 100644 client/src/ui/commoncomponents.js diff --git a/client/src/modules/pluginapi.js b/client/src/modules/pluginapi.js index 5b25797b..884936c9 100644 --- a/client/src/modules/pluginapi.js +++ b/client/src/modules/pluginapi.js @@ -11,6 +11,7 @@ import { EmoteModule } from 'builtin'; import { SettingsSet, SettingsCategory, Setting, SettingsScheme } from 'structs'; import { BdMenu, Modals, DOM, Reflection } from 'ui'; +import * as CommonComponents from 'commoncomponents'; import { Utils, Filters, ClientLogger as Logger, ClientIPC, AsyncEventEmitter } from 'common'; import Settings from './settings'; import ExtModuleManager from './extmodulemanager'; @@ -58,6 +59,13 @@ export default class PluginApi { get AsyncEventEmitter() { return AsyncEventEmitter } get EventsWrapper() { return EventsWrapper } + get CommonComponents() { return CommonComponents } + get Filters() { return Filters } + get Discord() { return DiscordApi } + get DiscordApi() { return DiscordApi } + get ReactComponents() { return ReactComponents } + get Reflection() { return Reflection } + /** * Logger */ @@ -431,37 +439,13 @@ export default class PluginApi { getModuleByProperties: this.getWebpackModuleByProperties.bind(this), getModuleByPrototypeFields: this.getWebpackModuleByPrototypeFields.bind(this), getModulesByProperties: this.getWebpackModulesByProperties.bind(this), - getModulesByPrototypeFields: this.getWebpackModulesByPrototypeFields.bind(this) + getModulesByPrototypeFields: this.getWebpackModulesByPrototypeFields.bind(this), + KnownModules: WebpackModules.KnownModules }, 'require', { get: () => this.webpackRequire }); } - /** - * Filters - */ - - get Filters() { return Filters } - - /** - * DiscordApi - */ - - get Discord() { return DiscordApi } - get DiscordApi() { return DiscordApi } - - /** - * ReactComponents - */ - - get ReactComponents() { return ReactComponents } - - /** - * Reflection - */ - - get Reflection() { return Reflection } - /** * Patcher */ diff --git a/client/src/modules/pluginmanager.js b/client/src/modules/pluginmanager.js index 181335a0..4f227840 100644 --- a/client/src/modules/pluginmanager.js +++ b/client/src/modules/pluginmanager.js @@ -8,15 +8,15 @@ * LICENSE file in the root directory of this source tree. */ +import { Events, Permissions } from 'modules'; +import { Modals } from 'ui'; +import { ErrorEvent } from 'structs'; +import { ClientLogger as Logger } from 'common'; import ContentManager from './contentmanager'; import ExtModuleManager from './extmodulemanager'; import Plugin from './plugin'; import PluginApi from './pluginapi'; import Vendor from './vendor'; -import { ClientLogger as Logger } from 'common'; -import { Events, Permissions } from 'modules'; -import { Modals } from 'ui'; -import { ErrorEvent } from 'structs'; export default class extends ContentManager { @@ -85,7 +85,7 @@ export default class extends ContentManager { } } - const deps = []; + const deps = {}; if (dependencies) { for (const [key, value] of Object.entries(dependencies)) { const extModule = ExtModuleManager.findModule(key); diff --git a/client/src/modules/webpackmodules.js b/client/src/modules/webpackmodules.js index a9493f83..15c79088 100644 --- a/client/src/modules/webpackmodules.js +++ b/client/src/modules/webpackmodules.js @@ -139,6 +139,7 @@ const KnownModules = { Strings: Filters.byProperties(["TEXT", "TEXTAREA_PLACEHOLDER"]), StringFormats: Filters.byProperties(['a', 'z']), StringUtils: Filters.byProperties(["toASCII"]), + hljs: Filters.byProperties(['highlight', 'highlightBlock']), /* URLs and Utils */ URLParser: Filters.byProperties(['Url', 'parse']), diff --git a/client/src/styles/index.scss b/client/src/styles/index.scss index a5a02b66..1bce97fa 100644 --- a/client/src/styles/index.scss +++ b/client/src/styles/index.scss @@ -1 +1 @@ -@import './partials/index.scss'; \ No newline at end of file +@import './partials/index.scss'; diff --git a/client/src/ui/bdui.js b/client/src/ui/bdui.js index df3ff80a..d50104cc 100644 --- a/client/src/ui/bdui.js +++ b/client/src/ui/bdui.js @@ -34,28 +34,13 @@ export default class { remote.BrowserWindow.getFocusedWindow().webContents.on('did-navigate-in-page', (e, url, isMainFrame) => { const { currentGuild, currentChannel } = DiscordApi; - if (!this.pathCache.server) { + if (!this.pathCache.server) Events.emit('server-switch', { server: currentGuild, channel: currentChannel }); - this.pathCache.server = currentGuild; - this.pathCache.channel = currentChannel; - return; - } - - if (!this.pathCache.channel) { + else if (!this.pathCache.channel) Events.emit('channel-switch', currentChannel); - this.pathCache.server = currentGuild; - this.pathCache.channel = currentChannel; - return; - } - - if (currentGuild && currentGuild.id && this.pathCache.server && this.pathCache.server.id !== currentGuild.id) { + else if (currentGuild && currentGuild.id && this.pathCache.server && this.pathCache.server.id !== currentGuild.id) Events.emit('server-switch', { server: currentGuild, channel: currentChannel }); - this.pathCache.server = currentGuild; - this.pathCache.channel = currentChannel; - return; - } - - if (currentChannel && currentChannel.id && this.pathCache.channel && this.pathCache.channel.id !== currentChannel.id) + else if (currentChannel && currentChannel.id && this.pathCache.channel && this.pathCache.channel.id !== currentChannel.id) Events.emit('channel-switch', currentChannel); this.pathCache.server = currentGuild; diff --git a/client/src/ui/commoncomponents.js b/client/src/ui/commoncomponents.js new file mode 100644 index 00000000..74bc8ce8 --- /dev/null +++ b/client/src/ui/commoncomponents.js @@ -0,0 +1,8 @@ +export * from './components/common'; + +export { default as SettingsPanel } from './components/bd/SettingsPanel.vue'; +export { default as Setting } from './components/bd/setting/Setting.vue'; +export { default as Card } from './components/bd/Card.vue'; +export { default as ContentAuthor } from './components/bd/ContentAuthor.vue'; +export { default as BdBadge } from './components/bd/BdBadge.vue'; +export { default as BdMessageBadge } from './components/bd/BdMessageBadge.vue'; diff --git a/client/src/ui/components/BdSettings.vue b/client/src/ui/components/BdSettings.vue index 5f09d7d6..8c9c1794 100644 --- a/client/src/ui/components/BdSettings.vue +++ b/client/src/ui/components/BdSettings.vue @@ -101,7 +101,8 @@ methods: { itemOnClick(id) { if (this.animating || id === this.activeIndex) return; - if (this.activeIndex >= 0) this.sidebarItems.find(item => item.id === this.activeIndex).active = false; + const activeItem = this.sidebarItems.find(item => item.id === this.activeIndex); + if (activeItem) activeItem.active = false; this.sidebarItems.find(item => item.id === id).active = true; this.animating = true; this.lastActiveIndex = this.activeIndex; diff --git a/client/src/ui/components/bd/ContentAuthor.vue b/client/src/ui/components/bd/ContentAuthor.vue index 639e520c..0b35da54 100644 --- a/client/src/ui/components/bd/ContentAuthor.vue +++ b/client/src/ui/components/bd/ContentAuthor.vue @@ -10,12 +10,6 @@