Skip to content

Commit

Permalink
wip: Refactor documents related components #904
Browse files Browse the repository at this point in the history
  • Loading branch information
cnouguier committed Dec 8, 2024
1 parent a09b074 commit d3afdc5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions core/client/components/document/KBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
v-if="document"
class="text-subtitle1"
>

{{ document.name }}
</div>
</div>
Expand All @@ -18,6 +17,7 @@
id="previous-button"
icon="las la-angle-left"
size="1rem"
color="white"
:handler="previous"
/>
</div>
Expand All @@ -36,6 +36,7 @@
id="next-button"
icon="las la-angle-right"
size="1rem"
color="white"
:handler="next"
/>
</div>
Expand Down Expand Up @@ -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 })
Expand Down
15 changes: 8 additions & 7 deletions core/client/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions core/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export { Units }
export { Layout }
export { Filter }
export { Sorter }
export { Document }
export { Exporter }
export { Reader }
export { services }
Expand Down

0 comments on commit d3afdc5

Please sign in to comment.