π A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Vue awesomedashboarddockerhomelabhomepagemitnodejsorganizationproductivitypwaself-hostedstartpagevue
β¨ Builds toast plugin, updates usage across app
Alicia Sykeseb3d7208822a
diff --git a/docs/credits.md b/docs/credits.mdindex 3d505477..ae2712b6 100644--- a/docs/credits.md+++ b/docs/credits.md@@ -41,7 +41,6 @@ At it's core, the application uses [**Vue.js**](https://github.com/vuejs/vue), a- [`vue-material-tabs`](https://github.com/jairoblatt/vue-material-tabs) - Tab view component by @jairoblatt `MIT`- [`VJsoneditor`](https://github.com/yansenlei/VJsoneditor) - Interactive JSON editor component by @yansenlei `MIT`- Forked from [`JsonEditor`](https://github.com/josdejong/jsoneditor) by @josdejong `Apache-2.0 License`-- [`vue-toasted`](https://github.com/shakee93/vue-toasted) - Toast notification component by @shakee93 `MIT`- [`vue-swatches`](https://github.com/saintplay/vue-swatches) - Color palete picker by @saintplay `MIT`diff --git a/src/components/Configuration/CloudBackupRestore.vue b/src/components/Configuration/CloudBackupRestore.vueindex 9126dc48..07afb26a 100644--- a/src/components/Configuration/CloudBackupRestore.vue+++ b/src/components/Configuration/CloudBackupRestore.vue@@ -191,12 +191,12 @@ export default {/* If the server returns a warning, then show to user and log it */showErrorMsg(errorMsg) {WarningInfoHandler(errorMsg, InfoKeys.CLOUD_BACKUP);- this.$toasted.show(errorMsg, { className: 'toast-error' });+ this.$toast.error(errorMsg);},/* When server returns success message, then show to user and log it */showSuccessMsg(msg) {InfoHandler(msg, InfoKeys.CLOUD_BACKUP);- this.$toasted.show(msg, { className: 'toast-success' });+ this.$toast.success(msg);},/* Call to hash function, to hash the users chosen/ entered password */makeHash(pass) {diff --git a/src/components/Configuration/ConfigContainer.vue b/src/components/Configuration/ConfigContainer.vueindex 9f0f3368..38e7cb0b 100644--- a/src/components/Configuration/ConfigContainer.vue+++ b/src/components/Configuration/ConfigContainer.vue@@ -192,7 +192,7 @@ export default {const isTheUserSure = confirm(msg); // eslint-disable-line no-alert, no-restricted-globalsif (isTheUserSure) {localStorage.clear();- this.$toasted.show(this.$t('config.data-cleared-msg'));+ this.$toast(this.$t('config.data-cleared-msg'));this.$store.dispatch(StoreKeys.INITIALIZE_CONFIG);}},diff --git a/src/components/Configuration/CustomCss.vue b/src/components/Configuration/CustomCss.vueindex 9448d2fa..393015b8 100644--- a/src/components/Configuration/CustomCss.vue+++ b/src/components/Configuration/CustomCss.vue@@ -83,7 +83,7 @@ export default {},/* Show success toast and lot update */showSuccessMsg() {- this.$toasted.show('Changes saved successfully');+ this.$toast('Changes saved successfully');},},};diff --git a/src/components/Configuration/EditSiteMeta.vue b/src/components/Configuration/EditSiteMeta.vueindex a372e9b6..8c110fc6 100644--- a/src/components/Configuration/EditSiteMeta.vue+++ b/src/components/Configuration/EditSiteMeta.vue@@ -64,7 +64,7 @@ export default {pageInfo.navLinks = this.formElements.navLinks.filter(link => (link.title !== ''));}localStorage.setItem(localStorageKeys.PAGE_INFO, JSON.stringify(pageInfo));- this.$toasted.show('Changes saved successfully');+ this.$toast('Changes saved successfully');setTimeout(() => { location.reload(); }, 1500); // eslint-disable-line no-restricted-globals},addNavLinkRow() {diff --git a/src/components/Configuration/JsonEditor.vue b/src/components/Configuration/JsonEditor.vueindex 02ad36e7..1de89e5c 100644--- a/src/components/Configuration/JsonEditor.vue+++ b/src/components/Configuration/JsonEditor.vue@@ -136,7 +136,7 @@ export default {} else if (this.saveMode === 'file') {this.writeToDisk();} else {- this.$toasted.show(this.$t('config-editor.error-msg-save-mode'));+ this.$toast.error(this.$t('config-editor.error-msg-save-mode'));}},/* Applies changes to the local state, begins edit mode and closes modal */@@ -194,7 +194,7 @@ export default {},/* Shows toast message */showToast(message, success) {- this.$toasted.show(message, { className: `toast-${success ? 'success' : 'error'}` });+ this.$toast[success ? 'success' : 'error'](message);},},};diff --git a/src/components/Configuration/RebuildApp.vue b/src/components/Configuration/RebuildApp.vueindex 697cb0fe..0850f9e4 100644--- a/src/components/Configuration/RebuildApp.vue+++ b/src/components/Configuration/RebuildApp.vue@@ -108,10 +108,10 @@ export default {this.message = message;this.error = error;}- this.$toasted.show(- (this.success- ? `β ${this.$t('app-rebuild.success-msg')}` : `β ${this.$t('app-rebuild.fail-msg')}`),- { className: `toast-${this.success ? 'success' : 'error'}` },+ this.$toast[this.success ? 'success' : 'error'](+ this.success+ ? `β ${this.$t('app-rebuild.success-msg')}`+ : `β ${this.$t('app-rebuild.fail-msg')}`,);},refreshPage() {diff --git a/src/components/InteractiveEditor/EditAppConfig.vue b/src/components/InteractiveEditor/EditAppConfig.vueindex bb0376e5..2311fdae 100644--- a/src/components/InteractiveEditor/EditAppConfig.vue+++ b/src/components/InteractiveEditor/EditAppConfig.vue@@ -61,7 +61,7 @@ export default {this.cancelEditing();} catch (e) {ErrorHandler('Failed to save app config', e);- this.$toasted.show('Error saving changes, check the logs', { className: 'toast-error' });+ this.$toast.error('Error saving changes, check the logs');}},cancelEditing() { this.$modal.hide(this.modalName); },diff --git a/src/components/InteractiveEditor/EditItem.vue b/src/components/InteractiveEditor/EditItem.vueindex a03fa972..81c1fd0f 100644--- a/src/components/InteractiveEditor/EditItem.vue+++ b/src/components/InteractiveEditor/EditItem.vue@@ -207,10 +207,7 @@ export default {const structured = {};this.formData.forEach((row) => { structured[row.name] = row.value; });if (!structured.title) { // Missing title, show error and don't proceed- this.$toasted.show(- this.$t('interactive-editor.edit-item.missing-title-err'),- { className: 'toast-error' },- );+ this.$toast.error(this.$t('interactive-editor.edit-item.missing-title-err'));return;}try {@@ -228,7 +225,7 @@ export default {this.closeModal();} catch (e) {ErrorHandler('Failed to save item', e);- this.$toasted.show('Error saving item. See Logs.', { className: 'toast-error' });+ this.$toast.error('Error saving item. See Logs.');}},/* Some fields require a bit of extra processing before they're saved */diff --git a/src/components/InteractiveEditor/EditModeSaveMenu.vue b/src/components/InteractiveEditor/EditModeSaveMenu.vueindex c5768d11..812c3f3a 100644--- a/src/components/InteractiveEditor/EditModeSaveMenu.vue+++ b/src/components/InteractiveEditor/EditModeSaveMenu.vue@@ -162,7 +162,7 @@ export default {return { content };},showToast(message, success) {- this.$toasted.show(message, { className: `toast-${success ? 'success' : 'error'}` });+ this.$toast[success ? 'success' : 'error'](message);},saveLocally() {const msg = this.$t('interactive-editor.menu.save-locally-warning');diff --git a/src/components/InteractiveEditor/EditMultiPages.vue b/src/components/InteractiveEditor/EditMultiPages.vueindex a00c7819..dbd2ce0a 100644--- a/src/components/InteractiveEditor/EditMultiPages.vue+++ b/src/components/InteractiveEditor/EditMultiPages.vue@@ -76,7 +76,7 @@ export default {this.cancelEditing();} catch (e) {ErrorHandler('Failed to save pages list', e);- this.$toasted.show('Error saving changes. See Logs.', { className: 'toast-error' });+ this.$toast.error('Error saving changes. See Logs.');}},cancelEditing() { this.$modal.hide(this.modalName); },diff --git a/src/components/InteractiveEditor/EditPageInfo.vue b/src/components/InteractiveEditor/EditPageInfo.vueindex 72b26884..69799783 100644--- a/src/components/InteractiveEditor/EditPageInfo.vue+++ b/src/components/InteractiveEditor/EditPageInfo.vue@@ -50,7 +50,7 @@ export default {this.cancelEditing();} catch (e) {ErrorHandler('Failed to save page info', e);- this.$toasted.show('Error saving changes. See Logs.', { className: 'toast-error' });+ this.$toast.error('Error saving changes. See Logs.');}},cancelEditing() { this.$modal.hide(this.modalName); },diff --git a/src/components/InteractiveEditor/EditSection.vue b/src/components/InteractiveEditor/EditSection.vueindex cfd0272d..ff85c9bd 100644--- a/src/components/InteractiveEditor/EditSection.vue+++ b/src/components/InteractiveEditor/EditSection.vue@@ -94,7 +94,7 @@ export default {this.$emit('closeEditSection');} catch (e) {ErrorHandler('Failed to save section', e);- this.$toasted.show('Error saving changes. See Logs.', { className: 'toast-error' });+ this.$toast.error('Error saving changes. See Logs.');}},},diff --git a/src/components/InteractiveEditor/ExportConfigMenu.vue b/src/components/InteractiveEditor/ExportConfigMenu.vueindex 9365c5df..84f2ac62 100644--- a/src/components/InteractiveEditor/ExportConfigMenu.vue+++ b/src/components/InteractiveEditor/ExportConfigMenu.vue@@ -95,10 +95,10 @@ export default {const config = this.convertJsonToYaml();if (navigator.clipboard) {navigator.clipboard.writeText(config);- this.$toasted.show(this.$t('config.data-copied-msg'));+ this.$toast(this.$t('config.data-copied-msg'));} else {ErrorHandler('Clipboard access requires HTTPS. See: https://bit.ly/3N5WuAA');- this.$toasted.show('Unable to copy, see log', { className: 'toast-error' });+ this.$toast.error('Unable to copy, see log');}InfoHandler('Config copied to clipboard', InfoKeys.EDITOR);},diff --git a/src/components/InteractiveEditor/MoveItemTo.vue b/src/components/InteractiveEditor/MoveItemTo.vueindex ab9bca0a..026a598c 100644--- a/src/components/InteractiveEditor/MoveItemTo.vue+++ b/src/components/InteractiveEditor/MoveItemTo.vue@@ -117,7 +117,7 @@ export default {this.close();} catch (e) {ErrorHandler(`Failed to ${this.operation} item`, e);- this.$toasted.show('Error. See Logs.', { className: 'toast-error' });+ this.$toast.error('Error. See Logs.');}},close() {diff --git a/src/components/Settings/AuthButtons.vue b/src/components/Settings/AuthButtons.vueindex 0a349fe8..ef22a2ca 100644--- a/src/components/Settings/AuthButtons.vue+++ b/src/components/Settings/AuthButtons.vue@@ -59,21 +59,21 @@ export default {methods: {logout() {registerLogout();- this.$toasted.show(this.$t('login.logout-message'));+ this.$toast(this.$t('login.logout-message'));setTimeout(() => {router.push({ path: '/login' });}, 500);},oidcLogout() {const oidc = getOidcAuth();- this.$toasted.show(this.$t('login.logout-message'));+ this.$toast(this.$t('login.logout-message'));setTimeout(() => {oidc.logout();}, 500);},keycloakLogout() {const keycloak = getKeycloakAuth();- this.$toasted.show(this.$t('login.logout-message'));+ this.$toast(this.$t('login.logout-message'));setTimeout(() => {keycloak.logout();}, 500);diff --git a/src/components/Settings/CustomThemeMaker.vue b/src/components/Settings/CustomThemeMaker.vueindex 02622a8a..ac7cdf33 100644--- a/src/components/Settings/CustomThemeMaker.vue+++ b/src/components/Settings/CustomThemeMaker.vue@@ -90,7 +90,7 @@ export default {priorSettings[this.themeToEdit] = this.customColors;localStorage.setItem(localStorageKeys.CUSTOM_COLORS, JSON.stringify(priorSettings));this.$store.commit(StoreKeys.SET_CUSTOM_COLORS, priorSettings);- this.$toasted.show(this.$t('theme-maker.saved-toast', { theme: this.themeToEdit }));+ this.$toast(this.$t('theme-maker.saved-toast', { theme: this.themeToEdit }));this.$emit('closeThemeConfigurator');},/* Itterates over available variables, removing them from the DOM */@@ -110,7 +110,7 @@ export default {delete priorSettings[this.themeToEdit];localStorage.setItem(localStorageKeys.CUSTOM_COLORS, JSON.stringify(priorSettings));this.resetUnsavedColors();- this.$toasted.show(this.$t('theme-maker.reset-toast', { theme: this.themeToEdit }));+ this.$toast(this.$t('theme-maker.reset-toast', { theme: this.themeToEdit }));},/* Generates CSS for the currently applied variables, and copys to users clipboard */exportToClipboard() {@@ -120,7 +120,7 @@ export default {clipboardText += (`--${customVar}: ${this.customColors[customVar]};\n`);});navigator.clipboard.writeText(clipboardText);- this.$toasted.show(this.$t('theme-maker.copied-toast', { theme: themeName }));+ this.$toast(this.$t('theme-maker.copied-toast', { theme: themeName }));},/* Returns a JSON object, with the variable name as key, and color as value */makeInitialData(variableArray) {diff --git a/src/components/Settings/LanguageSwitcher.vue b/src/components/Settings/LanguageSwitcher.vueindex 1ccb9bd5..8a243fe5 100644--- a/src/components/Settings/LanguageSwitcher.vue+++ b/src/components/Settings/LanguageSwitcher.vue@@ -94,10 +94,10 @@ export default {this.savedLanguage = selectedLanguage;const successMsg = `${selectedLanguage.flag} `+ `${this.$t('language-switcher.success-msg')} ${selectedLanguage.name}`;- this.$toasted.show(successMsg, { className: 'toast-success' });+ this.$toast.success(successMsg);this.$modal.hide(this.modalName);} else {- this.$toasted.show('Unable to update language', { className: 'toast-error' });+ this.$toast.error('Unable to update language');ErrorHandler('Unable to apply language');}},diff --git a/src/components/Settings/LocalConfigWarning.vue b/src/components/Settings/LocalConfigWarning.vueindex 9c265df7..e3cef3b5 100644--- a/src/components/Settings/LocalConfigWarning.vue+++ b/src/components/Settings/LocalConfigWarning.vue@@ -54,7 +54,7 @@ export default {const isTheUserSure = confirm(msg); // eslint-disable-line no-alert, no-restricted-globalsif (isTheUserSure) {localStorage.clear();- this.$toasted.show(this.$t('config.data-cleared-msg'));+ this.$toast(this.$t('config.data-cleared-msg'));this.$store.dispatch(StoreKeys.INITIALIZE_CONFIG);this.shouldHide = true;}diff --git a/src/components/Widgets/AnonAddy.vue b/src/components/Widgets/AnonAddy.vueindex bb5c6242..2c0ab82a 100644--- a/src/components/Widgets/AnonAddy.vue+++ b/src/components/Widgets/AnonAddy.vue@@ -182,7 +182,7 @@ export default {},copyToClipboard(text) {navigator.clipboard.writeText(text);- this.$toasted.show('Email address copied to clipboard');+ this.$toast('Email address copied to clipboard');},fetchData() {this.makeRequest(this.endpoint, this.headers).then(this.processData);@@ -239,7 +239,7 @@ export default {},toggleAlias(state, id) {if (this.disableControls) {- this.$toasted.show('Error, controls disabled', { className: 'toast-error' });+ this.$toast.error('Error, controls disabled');} else {const method = state ? 'POST' : 'DELETE';const path = state ? 'active-aliases' : `active-aliases/${id}`;@@ -247,7 +247,7 @@ export default {const endpoint = `${this.hostname}/api/${this.apiVersion}/${path}`;this.makeRequest(endpoint, this.headers, method, body).then(() => {const successMsg = `Alias successfully ${state ? 'enabled' : 'disabled'}`;- this.$toasted.show(successMsg, { className: 'toast-success' });+ this.$toast.success(successMsg);});}},diff --git a/src/main.js b/src/main.jsindex 9b8660fd..4cc17bcb 100644--- a/src/main.js+++ b/src/main.js@@ -23,6 +23,7 @@ import { initHeaderAuth, isHeaderAuthEnabled } from '@/utils/HeaderAuth';import { initOidcAuth, isOidcEnabled } from '@/utils/OidcAuth';import Keys from '@/utils/StoreMutations';import ErrorHandler from '@/utils/ErrorHandler';+import Toast from '@/utils/Toast';import '@/utils/patchResizeObserver';// Setup i18n translations@@ -42,31 +43,13 @@ app.use(router);app.use(i18n);app.use(VModal);app.use(JsonViewer);+app.use(Toast);// Register global components and directivesapp.component('v-select', VSelect);app.directive('clickOutside', clickOutside);app.directive('tooltip', tooltip);-// Lightweight $toasted shim (replaces vue-toasted)-/* eslint-disable object-property-newline */-app.config.globalProperties.$toasted = {- show(msg, opts = {}) {- const el = document.createElement('div');- el.className = `toast-message ${opts.className || ''}`.trim();- el.textContent = msg;- el.style.cssText = 'position:fixed;bottom:1rem;left:50%;transform:translateX(-50%);'- + 'padding:0.5rem 1rem;border-radius:4px;z-index:9999;'- + 'background:var(--background-darker,#333);color:var(--primary,#fff);'- + 'box-shadow:0 2px 8px rgba(0,0,0,0.3);transition:opacity 0.3s;';- document.body.appendChild(el);- const duration = opts.duration || 2500;- setTimeout(() => { el.style.opacity = '0'; }, duration);- setTimeout(() => { el.remove(); }, duration + 300);- },-};-/* eslint-enable object-property-newline */-app.config.errorHandler = (err, instance, info) => {ErrorHandler(`Vue error in ${info}`, err);};diff --git a/src/mixins/ItemMixin.js b/src/mixins/ItemMixin.jsindex 4fdfc744..deb418b4 100644--- a/src/mixins/ItemMixin.js+++ b/src/mixins/ItemMixin.js@@ -218,13 +218,10 @@ export default {copyToClipboard(content) {if (navigator.clipboard) {navigator.clipboard.writeText(content);- this.$toasted.show(- this.$t('context-menus.item.copied-toast'),- { className: 'toast-success' },- );+ this.$toast.success(this.$t('context-menus.item.copied-toast'));} else {ErrorHandler('Clipboard access requires HTTPS. See: https://bit.ly/3N5WuAA');- this.$toasted.show('Unable to copy, see log', { className: 'toast-error' });+ this.$toast.error('Unable to copy, see log');}},/* Used for smart-sort when sorting items by most used apps */diff --git a/src/styles/color-palette.scss b/src/styles/color-palette.scssindex d7c38787..1bf1d221 100644--- a/src/styles/color-palette.scss+++ b/src/styles/color-palette.scss@@ -6,6 +6,8 @@--background: #0b1021; // Page background--background-darker: #05070e; // Used for navigation bar, footer and fills+ --primary-transparent-60: color-mix(in srgb, var(--primary), transparent 60%);+/* Action Colors */--info: #04e4f4;--success: #20e253;@@ -37,7 +39,7 @@* all variables are optional, since they inherit initial values from above** Using specific variables makes overriding for custom themes really easy */--heading-text-color: var(--primary);- // Nav-bar links+ // Nav-bar links--nav-link-text-color: var(--primary);--nav-link-background-color: #607d8b33;--nav-link-text-color-hover: var(--primary);diff --git a/src/styles/global-styles.scss b/src/styles/global-styles.scssindex f5143ef3..ab2353df 100644--- a/src/styles/global-styles.scss+++ b/src/styles/global-styles.scss@@ -55,25 +55,6 @@ button svg, a svg {background: #00000080;}-/* Overiding styles for the global toast component */-.toast-message {- background: var(--toast-background) !important;- color: var(--toast-color) !important;- border: 1px solid var(--toast-color) !important;- border-radius: var(--curve-factor) !important;- font-size: 1.25rem !important;-}-.toast-error {- background: var(--danger) !important;- color: var(--white) !important;- font-size: 1.25rem !important;-}-.toast-success {- background: var(--success) !important;- color: var(--white) !important;- font-size: 1.25rem !important;-}-/* v-select, dropdown styles */.v-select {.vs__dropdown-toggle {diff --git a/src/utils/Toast.js b/src/utils/Toast.jsnew file mode 100644index 00000000..7cfe554f--- /dev/null+++ b/src/utils/Toast.js@@ -0,0 +1,249 @@+/**+ * Dashy's $toast plugin, for action/toast notifications+ *+ * Usage: registered globally as `$toast` β no import needed in components.+ * this.$toast('Saved'); // neutral info toast+ * this.$toast.success('Saved successfully');+ * this.$toast.error('Something broke', { duration: 0 }); // 0 = sticky+ * this.$toast.show(msg, { type, duration, dismissible, action, html });+ *+ * Options:+ * type 'info' | 'success' | 'error' | 'warning' (default 'info')+ * duration ms before auto-dismiss; 0 = sticky (default 3000)+ * dismissible show close button (default false)+ * action { text, onClick } (default none)+ * html render content as sanitized HTML (default false)+ * className extra class(es) on the toast+ * onClose callback when toast is removed+ *+ * Returns { id, dismiss } from show() so callers can dismiss programmatically.+ */+import DOMPurify from 'dompurify';++const DEFAULTS = { type: 'info', duration: 3000, dismissible: false };+const MAX_STACK = 5;+const TRANSITION_MS = 200;+const CONTAINER_ID = 'dashy-toasts';++let idCounter = 0;+let stylesInjected = false;+let containerEl = null;+const toasts = new Map();++function injectStyles() {+ if (stylesInjected) return;+ stylesInjected = true;+ const style = document.createElement('style');+ style.id = 'dashy-toast-styles';+ style.textContent = `+ #${CONTAINER_ID} {+ position: fixed;+ bottom: 1rem;+ left: 50%;+ z-index: 99;+ display: flex;+ flex-direction: column-reverse;+ gap: 0.5rem;+ width: max-content;+ max-width: min(90vw, 32rem);+ pointer-events: none;+ transform: translateX(-50%);+ }+ .dashy-toast {+ display: flex;+ align-items: center;+ gap: 0.75rem;+ padding: 0.6rem 0.9rem;+ border: 1px solid var(--toast-color);+ border-radius: var(--curve-factor);+ background: var(--toast-background);+ color: var(--toast-color);+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);+ line-height: 1.3;+ pointer-events: auto;+ opacity: 0;+ transform: translateY(1rem);+ transition: opacity ${TRANSITION_MS}ms ease, transform ${TRANSITION_MS}ms ease;+ }+ .dashy-toast.is-visible {+ opacity: 1;+ transform: translateY(0);+ }+ .dashy-toast.is-leaving {+ opacity: 0;+ }+ .dashy-toast--success {+ background: var(--success);+ border-color: transparent;+ color: #fff;+ }+ .dashy-toast--error {+ background: var(--danger);+ border-color: transparent;+ color: #fff;+ }+ .dashy-toast--warning {+ background: var(--warning);+ border-color: transparent;+ color: #fff;+ }+ .dashy-toast__msg {+ flex: 1;+ min-width: 0;+ overflow-wrap: break-word;+ }+ .dashy-toast__action,+ .dashy-toast__close {+ background: transparent;+ color: inherit;+ font: inherit;+ cursor: pointer;+ }+ .dashy-toast__action {+ padding: 0.2rem 0.6rem;+ border: 1px solid currentColor;+ border-radius: 2px;+ }+ .dashy-toast__close {+ padding: 0 0.25rem;+ border: 0;+ font-size: 1.25rem;+ line-height: 1;+ opacity: 0.7;+ }+ .dashy-toast__action:hover,+ .dashy-toast__action:focus-visible {+ background: rgba(255, 255, 255, 0.15);+ }+ .dashy-toast__close:hover,+ .dashy-toast__close:focus-visible {+ opacity: 1;+ }+ @media (max-width: 600px) {+ #${CONTAINER_ID} {+ left: 0.5rem;+ right: 0.5rem;+ width: auto;+ max-width: none;+ transform: none;+ }+ }+ @media (prefers-reduced-motion: reduce) {+ .dashy-toast {+ transition: opacity ${TRANSITION_MS}ms ease; transform: none !important;+ }+ }+ `;+ document.head.appendChild(style);+}++function ensureContainer() {+ if (containerEl?.isConnected) return containerEl;+ containerEl = document.createElement('div');+ containerEl.id = CONTAINER_ID;+ containerEl.setAttribute('role', 'region');+ containerEl.setAttribute('aria-label', 'Notifications');+ document.body.appendChild(containerEl);+ return containerEl;+}++function dismiss(id) {+ const t = toasts.get(id);+ if (!t) return;+ clearTimeout(t.timer);+ toasts.delete(id);+ t.el.classList.add('is-leaving');+ t.el.classList.remove('is-visible');+ setTimeout(() => {+ t.el.remove();+ if (containerEl && !containerEl.children.length) {+ containerEl.remove();+ containerEl = null;+ }+ t.onClose?.();+ }, TRANSITION_MS);+}++function clear() { [...toasts.keys()].forEach(dismiss); }++function show(message, opts = {}) {+ if (message == null || message === '') return { id: null, dismiss: () => {} };+ injectStyles();+ const container = ensureContainer();++ // Evict oldest if stack full+ if (toasts.size >= MAX_STACK) dismiss(toasts.keys().next().value);++ const cfg = { ...DEFAULTS, ...opts };+ const id = ++idCounter;+ const isError = cfg.type === 'error';++ const el = document.createElement('div');+ el.className = `dashy-toast dashy-toast--${cfg.type}`;+ if (cfg.className) el.classList.add(...String(cfg.className).split(/\s+/).filter(Boolean));+ el.setAttribute('role', isError ? 'alert' : 'status');+ el.setAttribute('aria-live', isError ? 'assertive' : 'polite');+ el.setAttribute('aria-atomic', 'true');++ const msg = document.createElement('div');+ msg.className = 'dashy-toast__msg';+ if (cfg.html) msg.innerHTML = DOMPurify.sanitize(String(message));+ else msg.textContent = String(message);+ el.appendChild(msg);++ if (cfg.action?.text) {+ const btn = document.createElement('button');+ btn.type = 'button';+ btn.className = 'dashy-toast__action';+ btn.textContent = cfg.action.text;+ btn.addEventListener('click', () => { cfg.action.onClick?.(); dismiss(id); });+ el.appendChild(btn);+ }++ const needsClose = cfg.dismissible || cfg.duration === 0;+ if (needsClose) {+ const close = document.createElement('button');+ close.type = 'button';+ close.className = 'dashy-toast__close';+ close.setAttribute('aria-label', 'Close notification');+ close.innerHTML = '×';+ close.addEventListener('click', () => dismiss(id));+ el.appendChild(close);+ }++ container.appendChild(el);+ requestAnimationFrame(() => el.classList.add('is-visible'));++ const entry = { el, timer: null, onClose: cfg.onClose };+ toasts.set(id, entry);++ if (cfg.duration > 0) {+ const start = () => { entry.timer = setTimeout(() => dismiss(id), cfg.duration); };+ start();+ el.addEventListener('mouseenter', () => clearTimeout(entry.timer));+ el.addEventListener('mouseleave', start);+ el.addEventListener('focusin', () => clearTimeout(entry.timer));+ el.addEventListener('focusout', start);+ }++ return { id, dismiss: () => dismiss(id) };+}++// Callable API: $toast(msg) + helpers+const toast = (msg, opts) => show(msg, opts);+toast.show = show;+toast.success = (msg, opts) => show(msg, { ...opts, type: 'success' });+toast.error = (msg, opts) => show(msg, { ...opts, type: 'error' });+toast.info = (msg, opts) => show(msg, { ...opts, type: 'info' });+toast.warning = (msg, opts) => show(msg, { ...opts, type: 'warning' });+toast.dismiss = dismiss;+toast.clear = clear;++export { toast };+export function useToast() { return toast; }++export default {+ install(app) {+ app.config.globalProperties.$toast = toast;+ },+};diff --git a/src/utils/defaults.js b/src/utils/defaults.jsindex 882479b0..279866d1 100644--- a/src/utils/defaults.js+++ b/src/utils/defaults.js@@ -173,14 +173,6 @@ const defaults = {splashScreenTime: 1000,/* Page meta-data, rendered in the header of each view */metaTagData: [{ name: 'description', content: "A simple static homepage for you're server" }],- /* Default option for Toast messages */- toastedOptions: {- position: 'bottom-center',- duration: 2500,- keepOnHover: true,- className: 'toast-message',- iconPack: 'fontawesome',- },/* Server location of the Backup & Sync cloud function */backupEndpoint: 'https://sync-service.dashy.to',/* Available services for fetching favicon icon for user apps */@@ -373,7 +365,6 @@ export const {topLevelConfKeys,splashScreenTime,metaTagData,- toastedOptions,backupEndpoint,faviconApiEndpoints,iconCdns,diff --git a/src/views/Login.vue b/src/views/Login.vueindex 4fce9fce..29b6541f 100644--- a/src/views/Login.vue+++ b/src/views/Login.vue@@ -168,11 +168,11 @@ export default {guestLogin() {const isAllowed = this.isGuestAccessEnabled;if (isAllowed) {- this.$toasted.show(this.$t('login.logged-in-guest'), { className: 'toast-success' });+ this.$toast.success(this.$t('login.logged-in-guest'));InfoHandler('Logged in as Guest', InfoKeys.AUTH);this.goHome();} else {- this.$toasted.show(this.$t('login.error-guest-access'), { className: 'toast-error' });+ this.$toast.error(this.$t('login.error-guest-access'));WarningInfoHandler('Guest Access Not Allowed', InfoKeys.AUTH);}},diff --git a/src/views/Workspace.vue b/src/views/Workspace.vueindex 2599c500..48049d4a 100644--- a/src/views/Workspace.vue+++ b/src/views/Workspace.vue@@ -55,10 +55,10 @@ export default {} else if (options.target === 'clipboard') {if (navigator.clipboard) {navigator.clipboard.writeText(options.url);- this.$toasted.show(this.$t('context-menus.item.copied-toast'), { className: 'toast-success' });+ this.$toast.success(this.$t('context-menus.item.copied-toast'));} else {ErrorHandler('Clipboard access requires HTTPS. See: https://bit.ly/3N5WuAA');- this.$toasted.show('Unable to copy, see log', { className: 'toast-error' });+ this.$toast.error('Unable to copy, see log');}return;} else {diff --git a/tests/components/item.test.js b/tests/components/item.test.jsindex 71ea855a..8166b3d1 100644--- a/tests/components/item.test.js+++ b/tests/components/item.test.js@@ -61,7 +61,10 @@ function mountItem(overrides = {}) {},mocks: {$modal: { show: vi.fn(), hide: vi.fn() },- $toasted: { show: vi.fn() },+ $toast: Object.assign(vi.fn(), {+ show: vi.fn(), success: vi.fn(), error: vi.fn(), info: vi.fn(), warning: vi.fn(),+ dismiss: vi.fn(), clear: vi.fn(),+ }),$t: (key) => key,...(overrides.mocks || {}),},@@ -591,7 +594,7 @@ describe('Methods: copyToClipboard', () => {const { wrapper } = mountItem();wrapper.vm.copyToClipboard('hello');expect(clipboardSpy).toHaveBeenCalledWith('hello');- expect(wrapper.vm.$toasted.show).toHaveBeenCalled();+ expect(wrapper.vm.$toast.success).toHaveBeenCalled();});it('shows error when clipboard unavailable', async () => {@@ -602,10 +605,7 @@ describe('Methods: copyToClipboard', () => {const { wrapper } = mountItem();wrapper.vm.copyToClipboard('hello');expect(ErrorHandler).toHaveBeenCalled();- expect(wrapper.vm.$toasted.show).toHaveBeenCalledWith(- 'Unable to copy, see log',- expect.objectContaining({ className: 'toast-error' }),- );+ expect(wrapper.vm.$toast.error).toHaveBeenCalledWith('Unable to copy, see log');});});