π A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Vue awesomedashboarddockerhomelabhomepagemitnodejsorganizationproductivitypwaself-hostedstartpagevue
β Removes vue modal, implements our own
Alicia Sykes7f79c7275e32
diff --git a/package.json b/package.jsonindex 2b31683d..e6a53cac 100644--- a/package.json+++ b/package.json@@ -30,7 +30,6 @@"@codemirror/search": "^6.7.0","@codemirror/state": "^6.6.0","@codemirror/view": "^6.41.1",- "@febe95/vue-js-modal": "^3.2.0","@jsonforms/core": "^3.7.0","@jsonforms/vue": "^3.7.0","@jsonforms/vue-vanilla": "^3.7.0",diff --git a/src/assets/locales/en.json b/src/assets/locales/en.jsonindex 9598335d..f4bac6b9 100644--- a/src/assets/locales/en.json+++ b/src/assets/locales/en.json@@ -1,4 +1,7 @@{+ "general": {+ "close-modal": "Close dialog"+ },"home": {"no-results": "No Search Results","no-data": "No Data Configured",diff --git a/src/components/Modal.vue b/src/components/Modal.vuenew file mode 100644index 00000000..e48cfaf1--- /dev/null+++ b/src/components/Modal.vue@@ -0,0 +1,179 @@+<template>+ <teleport to="body">+ <div+ v-if="isOpen"+ ref="overlay"+ class="modal-overlay"+ @mousedown="onOverlayDown"+ @click="onOverlayClick"+ >+ <dialog+ ref="dlg"+ open+ role="dialog"+ aria-modal="true"+ :aria-label="$t('general.close-modal')"+ :class="['dashy-modal', classes, { resizable }]"+ :style="{ width, height }"+ >+ <div v-if="$slots['top-right']" class="modal-top-right">+ <slot name="top-right" />+ </div>+ <button+ v-else+ type="button"+ class="modal-close-mobile"+ :aria-label="$t('general.close-modal')"+ @click="close"+ >Γ</button>+ <div class="modal-body">+ <slot />+ </div>+ </dialog>+ </div>+ </teleport>+</template>++<script>+import { register, unregister } from '@/plugins/modal';+import ErrorHandler from '@/utils/logging/ErrorHandler';++const FOCUSABLE = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';++export default {+ name: 'Modal',+ props: {+ name: { type: String, required: true },+ width: { type: [String, Number], default: '50%' },+ height: { type: [String, Number], default: '80%' },+ resizable: { type: Boolean, default: true },+ classes: { type: String, default: '' },+ },+ emits: ['before-open', 'opened', 'closed'],+ data: () => ({ isOpen: false, mouseDownTarget: null, prevFocus: null }),+ mounted() {+ register(this.name, { open: this.open, close: this.close });+ },+ beforeUnmount() {+ unregister(this.name);+ if (this.isOpen) this.teardown();+ },+ methods: {+ open() {+ if (this.isOpen) return;+ try {+ this.prevFocus = document.activeElement;+ this.$emit('before-open');+ this.isOpen = true;+ document.addEventListener('keydown', this.onKeyDown);+ const root = document.getElementById('dashy');+ if (root) root.setAttribute('inert', '');+ this.$nextTick(() => {+ this.$refs.dlg?.querySelector(FOCUSABLE)?.focus();+ this.$emit('opened');+ });+ } catch (e) {+ ErrorHandler(`Failed to open modal '${this.name}'`, e);+ }+ },+ close() {+ if (!this.isOpen) return;+ this.teardown();+ this.$emit('closed');+ },+ teardown() {+ this.isOpen = false;+ document.removeEventListener('keydown', this.onKeyDown);+ document.getElementById('dashy')?.removeAttribute('inert');+ this.prevFocus?.focus?.();+ this.prevFocus = null;+ },+ onKeyDown(e) {+ if (e.key === 'Escape') this.close();+ },+ onOverlayDown(e) {+ this.mouseDownTarget = e.target;+ },+ onOverlayClick(e) {+ if (e.target !== this.$refs.overlay) return;+ if (this.mouseDownTarget !== this.$refs.overlay) return;+ this.close();+ },+ },+};+</script>++<style lang="scss">+@import '@/styles/media-queries.scss';++.modal-overlay {+ position: fixed;+ inset: 0;+ z-index: 50;+ display: flex;+ align-items: center;+ justify-content: center;+ background: #00000080;+}++dialog.dashy-modal {+ position: static;+ display: block;+ padding: 0;+ margin: 0;+ min-width: 350px;+ min-height: 200px;+ max-width: 95vw;+ max-height: 95vh;+ color: inherit;+ background: var(--background-darker);+ border: none;+ border-radius: var(--curve-factor);+ box-shadow: 0 40px 70px -2px hsl(0deg 0% 0% / 60%), 1px 1px 6px var(--primary);+ overflow: auto;++ &.resizable { resize: both; }++ .modal-body { height: 100%; }++ .modal-top-right {+ position: absolute;+ top: 0;+ right: 0;+ z-index: 2;+ }++ .modal-close-mobile {+ display: none;+ position: absolute;+ top: 0;+ right: 0;+ z-index: 3;+ width: 2.5rem;+ height: 2.5rem;+ padding: 0;+ font-size: 1.75rem;+ line-height: 1;+ color: var(--primary);+ background: transparent;+ border: none;+ cursor: pointer;+ &:hover, &:focus-visible {+ background: var(--primary);+ color: var(--background);+ outline: none;+ }+ }++ @include phone {+ width: 100vw !important;+ height: 100vh !important;+ min-width: 0;+ max-width: 100vw;+ max-height: 100vh;+ border-radius: 0;+ resize: none;+ .modal-close-mobile { display: inline-flex; align-items: center; justify-content: center; }+ }+}+</style>diff --git a/src/main.js b/src/main.jsindex a8d538f1..f61a5758 100644--- a/src/main.js+++ b/src/main.js@@ -3,11 +3,12 @@import { createApp } from 'vue';// Import component Vue plugins, used throughout the app-import VModal from '@febe95/vue-js-modal'; // Modal component (Vue 3 fork)import VSelect from 'vue-select'; // Select dropdown component// Import base Dashy components and utilsimport Dashy from '@/App.vue'; // Main Dashy Vue app+import Modal from '@/components/Modal.vue'; // In-house modal component+import VModal from '@/plugins/modal'; // $modal.show()/hide() pluginimport store from '@/store'; // Store, for local state managementimport router from '@/router'; // Router, for navigationimport serviceWorker from '@/utils/InitServiceWorker'; // Service worker initialization@@ -21,7 +22,6 @@ import { initOidcAuth, isOidcEnabled } from '@/utils/auth/OidcAuth';import Keys from '@/utils/StoreMutations';import ErrorHandler from '@/utils/logging/ErrorHandler';import Toast from '@/utils/Toast';-import '@/utils/patchResizeObserver';// Create the Vue 3 app instanceconst app = createApp(Dashy);@@ -34,6 +34,7 @@ app.use(VModal);app.use(Toast);// Register global components and directives+app.component('modal', Modal);app.component('v-select', VSelect);app.directive('clickOutside', clickOutside);app.directive('tooltip', tooltip);diff --git a/src/plugins/modal.js b/src/plugins/modal.jsnew file mode 100644index 00000000..9eed093f--- /dev/null+++ b/src/plugins/modal.js@@ -0,0 +1,30 @@+import ErrorHandler from '@/utils/logging/ErrorHandler';++const registry = new Map();++export function register(name, instance) {+ registry.set(name, instance);+}++export function unregister(name) {+ registry.delete(name);+}++export default {+ install(app) {+ app.config.globalProperties.$modal = {+ show(name) {+ const instance = registry.get(name);+ if (!instance) {+ ErrorHandler(`Modal '${name}' is not registered`);+ return;+ }+ instance.open();+ },+ hide(name) {+ const instance = registry.get(name);+ if (instance) instance.close();+ },+ };+ },+};diff --git a/src/store.js b/src/store.jsindex 37ea2de1..868f63cd 100644--- a/src/store.js+++ b/src/store.js@@ -1,4 +1,3 @@-import { createStore } from 'vuex';import { load as yamlLoad } from 'js-yaml';import request from '@/utils/request';@@ -245,7 +244,7 @@ const store = createStore({void state.authRevision; // Re-evaluate when auth state changesreturn getUserState();},-+getSectionByIndex: (state, getters) => (index) => {return getters.sections[index];},@@ -271,13 +270,13 @@ const store = createStore({},layout(state) {const scope = configScope(state.currentConfigInfo.confId);- const fromState = state.config?.appConfig?.layout || 'auto';+ const fromState = state.configSource?.appConfig?.layout || 'auto';if (state.editMode) return fromState;return localStorage.getItem(scope.LAYOUT) || fromState;},iconSize(state) {const scope = configScope(state.currentConfigInfo.confId);- const fromState = state.config?.appConfig?.iconSize || 'medium';+ const fromState = state.configSource?.appConfig?.iconSize || 'medium';if (state.editMode) return fromState;return localStorage.getItem(scope.ICON_SIZE) || fromState;},diff --git a/src/styles/global-styles.scss b/src/styles/global-styles.scssindex 0e26b4b8..2183f8f6 100644--- a/src/styles/global-styles.scss+++ b/src/styles/global-styles.scss@@ -38,28 +38,6 @@ button svg, a svg {vertical-align: middle;}-/* Overriding styles for the modal component */-.vm--modal, .dashy-modal {- box-shadow: 0 40px 70px -2px hsl(0deg 0% 0% / 60%), 1px 1px 6px var(--primary) !important;- min-width: 350px;- min-height: 200px;- background: var(--background-darker);- @include phone {- left: 0.5rem !important;- right: 0.5rem !important;- width: 95% !important;- top: 2rem !important;- }-}-.vm--overlay {- background: #00000080;-}--// Override the vue-js-modal default z-index: 9999. Because i hate z-index: 9999999.-.vm--container {- z-index: 8;-}-/* Small uppercase label above a form control */.options-label,.theme-label {diff --git a/src/utils/patchResizeObserver.js b/src/utils/patchResizeObserver.jsdeleted file mode 100644index 35a4773a..00000000--- a/src/utils/patchResizeObserver.js+++ /dev/null@@ -1,10 +0,0 @@-/* Patch `ResizeObserver.prototype.unobserve` to no-op on non-Element args.- * Works around @febe95/[email protected] passing a stale/null ref during- * component unmount. Safe to apply globally: `unobserve(null)` has no valid use. */-if (typeof ResizeObserver !== 'undefined') {- const original = ResizeObserver.prototype.unobserve;- ResizeObserver.prototype.unobserve = function unobserve(target) {- if (target instanceof Element) return original.call(this, target);- return undefined;- };-}diff --git a/yarn.lock b/yarn.lockindex cdf1eb11..35df12cd 100644--- a/yarn.lock+++ b/yarn.lock@@ -1082,14 +1082,6 @@"@eslint/core" "^1.2.1"levn "^0.4.1"-"@febe95/vue-js-modal@^3.2.0":- version "3.2.0"- resolved "https://registry.yarnpkg.com/@febe95/vue-js-modal/-/vue-js-modal-3.2.0.tgz#4d0bd064553ca11f647112a08bf31ed6ec43ad8a"- integrity sha512-RcJpSfwTXOyE6PnvnS/Cxh6k9ygTG1D4Juna1/8eAuWXXOR1WyOf9Vm0+hXEXhfaqsHnWru6AX3mjGGNwRCt7Q==- dependencies:- resize-observer-polyfill "^1.5.1"- tiny-emitter "^2.1.0"-"@humanfs/core@^0.19.2":version "0.19.2"resolved "https://registry.yarnpkg.com/@humanfs/core/-/core-0.19.2.tgz#a8272ca03b2acf492670222b2320b6c421bfde60"@@ -4512,11 +4504,6 @@ require-from-string@^2.0.2:resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909"integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==-resize-observer-polyfill@^1.5.1:- version "1.5.1"- resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"- integrity sha512-LwZrotdHOo12nQuZlHEmtuXdqGoOD0OhaxopaNFxWzInpEgaLWoVuAMbTzixuosCx2nEG58ngzW3vxdWoxIgdg==-resolve-pkg-maps@^1.0.0:version "1.0.0"resolved "https://registry.yarnpkg.com/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz#616b3dc2c57056b5588c31cdf4b3d64db133720f"@@ -5111,11 +5098,6 @@ terser@^5.17.4:commander "^2.20.0"source-map-support "~0.5.20"-tiny-emitter@^2.1.0:- version "2.1.0"- resolved "https://registry.yarnpkg.com/tiny-emitter/-/tiny-emitter-2.1.0.tgz#1d1a56edfc51c43e863cbb5382a72330e3555423"- integrity sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==-tinybench@^2.9.0:version "2.9.0"resolved "https://registry.yarnpkg.com/tinybench/-/tinybench-2.9.0.tgz#103c9f8ba6d7237a47ab6dd1dcff77251863426b"