From 0eee0519ed51d3b9fd0f38a24c766fcfe6024ce0 Mon Sep 17 00:00:00 2001 From: NGPixel Date: Mon, 17 Apr 2023 06:53:07 +0000 Subject: [PATCH] feat: insert asset in editor --- ux/.eslintrc.js | 3 +- ux/package-lock.json | 4 ++- ux/package.json | 1 + ux/quasar.config.js | 1 + ux/src/boot/eventbus.js | 12 ++++++++ ux/src/components/EditorMarkdown.vue | 30 +++++++++++++++--- ux/src/components/EditorWysiwyg.vue | 4 +-- ux/src/components/FileManager.vue | 46 +++++++++++++++++++++++----- ux/src/components/HeaderNav.vue | 7 ++++- ux/src/components/PageNewMenu.vue | 2 +- ux/src/i18n/locales/en.json | 2 ++ ux/src/layouts/MainLayout.vue | 2 +- ux/src/stores/site.js | 9 ++++++ 13 files changed, 103 insertions(+), 20 deletions(-) create mode 100644 ux/src/boot/eventbus.js diff --git a/ux/.eslintrc.js b/ux/.eslintrc.js index e6f432a8..8f6e513f 100644 --- a/ux/.eslintrc.js +++ b/ux/.eslintrc.js @@ -43,7 +43,8 @@ module.exports = { __QUASAR_SSR_CLIENT__: 'readonly', __QUASAR_SSR_PWA__: 'readonly', process: 'readonly', - APOLLO_CLIENT: 'readonly' + APOLLO_CLIENT: 'readonly', + EVENT_BUS: 'readonly' }, // add your custom rules here diff --git a/ux/package-lock.json b/ux/package-lock.json index f223d639..9daff899 100644 --- a/ux/package-lock.json +++ b/ux/package-lock.json @@ -67,6 +67,7 @@ "markdown-it-sub": "1.0.0", "markdown-it-sup": "1.0.0", "markdown-it-task-lists": "2.1.1", + "mitt": "3.0.0", "pako": "2.1.0", "pinia": "2.0.33", "prosemirror-commands": "1.5.1", @@ -5575,7 +5576,8 @@ }, "node_modules/mitt": { "version": "3.0.0", - "license": "MIT" + "resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.0.tgz", + "integrity": "sha512-7dX2/10ITVyqh4aOSVI9gdape+t9l2/8QxHrFmUXu4EEUpdlxl6RudZUPZoc+zuY2hk1j7XxVroIVIan/pD/SQ==" }, "node_modules/ms": { "version": "2.1.3", diff --git a/ux/package.json b/ux/package.json index b3f3ca07..a2cd327c 100644 --- a/ux/package.json +++ b/ux/package.json @@ -72,6 +72,7 @@ "markdown-it-sub": "1.0.0", "markdown-it-sup": "1.0.0", "markdown-it-task-lists": "2.1.1", + "mitt": "3.0.0", "pako": "2.1.0", "pinia": "2.0.33", "prosemirror-commands": "1.5.1", diff --git a/ux/quasar.config.js b/ux/quasar.config.js index 600fdfa7..c8e14045 100644 --- a/ux/quasar.config.js +++ b/ux/quasar.config.js @@ -38,6 +38,7 @@ module.exports = configure(function (/* ctx */) { boot: [ 'apollo', 'components', + 'eventbus', 'i18n' ], diff --git a/ux/src/boot/eventbus.js b/ux/src/boot/eventbus.js new file mode 100644 index 00000000..68b50847 --- /dev/null +++ b/ux/src/boot/eventbus.js @@ -0,0 +1,12 @@ +import { boot } from 'quasar/wrappers' +import mitt from 'mitt' + +export default boot(({ app }) => { + const emitter = mitt() + + if (import.meta.env.SSR) { + global.EVENT_BUS = emitter + } else { + window.EVENT_BUS = emitter + } +}) diff --git a/ux/src/components/EditorMarkdown.vue b/ux/src/components/EditorMarkdown.vue index a343921d..7dca53ca 100644 --- a/ux/src/components/EditorMarkdown.vue +++ b/ux/src/components/EditorMarkdown.vue @@ -233,7 +233,7 @@ diff --git a/ux/src/components/PageNewMenu.vue b/ux/src/components/PageNewMenu.vue index 7b0f4ae8..98dddc58 100644 --- a/ux/src/components/PageNewMenu.vue +++ b/ux/src/components/PageNewMenu.vue @@ -116,7 +116,7 @@ function create (editor) { } function openFileManager () { - siteStore.overlay = 'FileManager' + siteStore.openFileManager() } function newFolder () { diff --git a/ux/src/i18n/locales/en.json b/ux/src/i18n/locales/en.json index 0c90f9c2..e1f864ff 100644 --- a/ux/src/i18n/locales/en.json +++ b/ux/src/i18n/locales/en.json @@ -1164,6 +1164,7 @@ "common.actions.commit": "Commit", "common.actions.confirm": "Confirm", "common.actions.copy": "Copy", + "common.actions.copyURL": "Copy URL", "common.actions.create": "Create", "common.actions.deactivate": "Deactivate", "common.actions.delete": "Delete", @@ -1198,6 +1199,7 @@ "common.actions.select": "Select", "common.actions.update": "Update", "common.actions.upload": "Upload", + "common.actions.view": "View", "common.clipboard.failure": "Failed to copy to clipboard.", "common.clipboard.success": "Copied to clipboard successfully.", "common.clipboard.uuid": "Copy UUID to clipboard.", diff --git a/ux/src/layouts/MainLayout.vue b/ux/src/layouts/MainLayout.vue index 4f6dcb8f..7c96b169 100644 --- a/ux/src/layouts/MainLayout.vue +++ b/ux/src/layouts/MainLayout.vue @@ -149,7 +149,7 @@ const isSidebarShown = computed(() => { // METHODS function openFileManager () { - siteStore.overlay = 'FileManager' + siteStore.openFileManager() } diff --git a/ux/src/stores/site.js b/ux/src/stores/site.js index 25b62b9e..4d3be806 100644 --- a/ux/src/stores/site.js +++ b/ux/src/stores/site.js @@ -25,6 +25,7 @@ export const useSiteStore = defineStore('site', { showSideNav: true, showSidebar: true, overlay: null, + overlayOpts: {}, features: { ratingsMode: 'off', reasonForChange: 'required', @@ -70,6 +71,14 @@ export const useSiteStore = defineStore('site', { overlayIsShown: (state) => Boolean(state.overlay) }, actions: { + openFileManager (opts) { + this.$patch({ + overlay: 'FileManager', + overlayOpts: { + insertMode: opts?.insertMode ?? false + } + }) + }, async loadSite (hostname) { try { const resp = await APOLLO_CLIENT.query({