Refaktorisierte 'UI'-Funktionen zu statischen Methoden

This commit is contained in:
Developer 02
2024-06-18 19:01:40 +02:00
parent 39cc257466
commit 95958f2a1d
2 changed files with 11 additions and 12 deletions

View File

@@ -14,7 +14,6 @@ class App {
this.container = container ?? `#${this.constructor.name.toLowerCase()}`; this.container = container ?? `#${this.constructor.name.toLowerCase()}`;
this.envelopeKey = envelopeKey this.envelopeKey = envelopeKey
this.UI = new UI()
this.Network = new Network() this.Network = new Network()
this.Instance = null this.Instance = null
@@ -48,8 +47,8 @@ class App {
const arrayBuffer = this.documentBytes const arrayBuffer = this.documentBytes
// Load PSPDFKit // Load PSPDFKit
this.Instance = await this.UI.loadPSPDFKit(arrayBuffer, this.container, this.licenseKey, this.locale) this.Instance = await UI.loadPSPDFKit(arrayBuffer, this.container, this.licenseKey, this.locale)
this.UI.configurePSPDFKit(this.Instance, this.handleClick.bind(this)) UI.configurePSPDFKit(this.Instance, this.handleClick.bind(this))
this.Instance.addEventListener( this.Instance.addEventListener(
'annotations.load', 'annotations.load',

View File

@@ -1,5 +1,5 @@
class UI { class UI {
allowedToolbarItems = [ static allowedToolbarItems = [
'sidebar-thumbnails', 'sidebar-thumbnails',
'sidebar-document-ouline', 'sidebar-document-ouline',
'sidebar-bookmarks', 'sidebar-bookmarks',
@@ -14,7 +14,7 @@
// Load the PSPDFKit UI by setting a target element as the container to render in // Load the PSPDFKit UI by setting a target element as the container to render in
// and a arraybuffer which represents the document that should be displayed. // and a arraybuffer which represents the document that should be displayed.
loadPSPDFKit(arrayBuffer, container, licenseKey, locale) { static loadPSPDFKit(arrayBuffer, container, licenseKey, locale) {
return PSPDFKit.load({ return PSPDFKit.load({
locale: locale, locale: locale,
licenseKey: licenseKey, licenseKey: licenseKey,
@@ -45,30 +45,30 @@
}) })
} }
configurePSPDFKit(instance, handler) { static configurePSPDFKit(instance, handler) {
const toolbarItems = this.getToolbarItems(instance, handler) const toolbarItems = this.getToolbarItems(instance, handler)
instance.setToolbarItems(toolbarItems) instance.setToolbarItems(toolbarItems)
} }
annotationRenderer(data) { static annotationRenderer(data) {
// leave everything as is // leave everything as is
return null return null
} }
getToolbarItems(instance, handler) { static getToolbarItems(instance, handler) {
const customItems = this.getCustomItems(handler) const customItems = this.getCustomItems(handler)
const defaultItems = this.getDefaultItems(instance.toolbarItems) const defaultItems = this.getDefaultItems(instance.toolbarItems)
return defaultItems.concat(customItems) return defaultItems.concat(customItems)
} }
createElementFromHTML(html) { static createElementFromHTML(html) {
const el = document.createElement('div') const el = document.createElement('div')
el.innerHTML = html.trim() el.innerHTML = html.trim()
return el.firstChild return el.firstChild
} }
getCustomItems = function (callback) { static getCustomItems = function (callback) {
return [] return []
return [ return [
{ {
@@ -108,11 +108,11 @@
] ]
} }
getDefaultItems(items) { static getDefaultItems(items) {
return items.filter((item) => this.allowedToolbarItems.includes(item.type)) return items.filter((item) => this.allowedToolbarItems.includes(item.type))
} }
getPresets() { static getPresets() {
const annotationPresets = PSPDFKit.defaultAnnotationPresets const annotationPresets = PSPDFKit.defaultAnnotationPresets
annotationPresets.ink = { annotationPresets.ink = {
lineWidth: 10, lineWidth: 10,