From d3afdc574d85e55a406068822f32b3936c1169d6 Mon Sep 17 00:00:00 2001 From: cnouguier Date: Sun, 8 Dec 2024 22:59:42 +0100 Subject: [PATCH] wip: Refactor documents related components #904 --- core/client/components/document/KBrowser.vue | 4 ++-- core/client/document.js | 15 ++++++++------- core/client/index.js | 1 + 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/core/client/components/document/KBrowser.vue b/core/client/components/document/KBrowser.vue index 2888122c5..4ac715910 100644 --- a/core/client/components/document/KBrowser.vue +++ b/core/client/components/document/KBrowser.vue @@ -5,7 +5,6 @@ v-if="document" class="text-subtitle1" > - {{ document.name }} @@ -18,6 +17,7 @@ id="previous-button" icon="las la-angle-left" size="1rem" + color="white" :handler="previous" /> @@ -36,6 +36,7 @@ id="next-button" icon="las la-angle-right" size="1rem" + color="white" :handler="next" /> @@ -76,7 +77,6 @@ const hasNext = computed(() => { // Watch watch(() => [props.documents, props.default], async () => { - console.log('[DEBUG] Props changed') index.value = _.findIndex(props.documents, { name: props.default }) if (index.value > -1) await refresh() }, { immediate: true }) diff --git a/core/client/document.js b/core/client/document.js index 25b21010d..77a878087 100644 --- a/core/client/document.js +++ b/core/client/document.js @@ -7,8 +7,7 @@ import { i18n } from './i18n.js' export const Document = { initialize () { - this.options = _.get(config, 'document') - this.options = _.defaultsDeep(this.options, { + this.options = _.defaultsDeep(_.get(config, 'document'), { viewers: { htm: 'document/KHtml', html: 'document/KHtml', @@ -38,13 +37,15 @@ export const Document = { }) logger.debug('[KDK] Configuring documents with options:', this.options) }, - register (type, viewer) { - if (!_.isArray(type)) type = [type] - _.forEach(type, mimeType => { - _.set(this.options, `viewers.${mimeType}`, viewer) + register (types, viewer) { + if (!_.isArray(types)) types = [types] + _.forEach(types, type => { + _.set(this.options, `viewers.${type}`, viewer) }) }, - + hasViewer (type) { + return _.get(this.options, `viewers.${type}`) ? true: false + }, sanitizeHtml (html) { if (_.isNil(html)) return null return sanitize(html, this.options.htmlSanitizer) diff --git a/core/client/index.js b/core/client/index.js index 1615c8061..c470dd6d8 100644 --- a/core/client/index.js +++ b/core/client/index.js @@ -43,6 +43,7 @@ export { Units } export { Layout } export { Filter } export { Sorter } +export { Document } export { Exporter } export { Reader } export { services }