diff --git a/src/app/Mounter.ts b/src/app/Mounter.ts
deleted file mode 100644
index 8e6c273d..00000000
--- a/src/app/Mounter.ts
+++ /dev/null
@@ -1,70 +0,0 @@
-import { ModelPath } from '@mcschema/core'
-import { hexId } from './Utils'
-
-type Registry = {
- [id: string]: (el: Element) => void
-}
-
-export interface Mounter {
- register(callback: (el: Element) => void): string
- registerEvent(type: string, callback: (el: Element) => void): string
- registerChange(callback: (el: Element) => void): string
- registerClick(callback: (el: Element) => void): string
- mount(el: Element): void
-}
-
-export class Mounter implements Mounter {
- registry: Registry = {}
-
- /**
- * Registers a callback and gives an ID
- * @param callback function that is called when the element is mounted
- * @returns the ID that should be applied to the data-id attribute
- */
- register(callback: (el: Element) => void): string {
- const id = hexId()
- this.registry[id] = callback
- return id
- }
-
- /**
- * Registers an event and gives an ID
- * @param type event type
- * @param callback function that is called when the event is fired
- * @returns the ID that should be applied to the data-id attribute
- */
- registerEvent(type: string, callback: (el: Element) => void): string {
- return this.register(el => {
- el.addEventListener(type, evt => {
- callback(el)
- evt.stopPropagation()
- })
- })
- }
-
- /**
- * Registers a change event and gives an ID
- * @param callback function that is called when the event is fired
- * @returns the ID that should be applied to the data-id attribute
- */
- registerChange(callback: (el: Element) => void): string {
- return this.registerEvent('change', callback)
- }
-
- /**
- * Registers a click event and gives an ID
- * @param callback function that is called when the event is fired
- * @returns the ID that should be applied to the data-id attribute
- */
- registerClick(callback: (el: Element) => void): string {
- return this.registerEvent('click', callback)
- }
-
- mount(el: Element): void {
- for (const id in this.registry) {
- const element = el.querySelector(`[data-id="${id}"]`)
- if (element !== null) this.registry[id](element)
- }
- this.registry = {}
- }
-}
diff --git a/src/app/components/panels/TreePanel.ts b/src/app/components/panels/TreePanel.ts
index 12e95f30..ffc9bcfd 100644
--- a/src/app/components/panels/TreePanel.ts
+++ b/src/app/components/panels/TreePanel.ts
@@ -3,7 +3,6 @@ import { App, checkVersion, Previews } from '../../App';
import { Tracker } from '../../Tracker'
import { toggleMenu, View } from '../../views/View';
import { Octicon } from '../Octicon';
-import { Mounter } from '../../Mounter';
import { renderHtml } from '../../hooks/renderHtml';
import config from '../../../config.json'
import { BiomeNoisePreview } from '../../preview/BiomeNoisePreview';
@@ -39,11 +38,10 @@ const treeViewObserver = (el: Element) => {
}
export const TreePanel = (view: View, model: DataModel) => {
- const mounter = new Mounter()
const getContent = () => {
if (App.loaded.get()) {
const path = new ModelPath(model)
- const rendered = model.schema.hook(renderHtml, path, model.data, mounter)
+ const rendered = model.schema.hook(renderHtml, path, model.data, view)
const category = model.schema.category(path)
if (rendered[1]) {
return `
@@ -56,9 +54,8 @@ export const TreePanel = (view: View, model: DataModel) => {
return '
'
}
const mountContent = (el: Element) => {
- el.innerHTML = getContent()
+ view.mount(el, getContent(), false)
treeViewObserver(el)
- mounter.mount(el)
}
const tree = view.register(el => {
App.loaded.watchRun((value) => {
diff --git a/src/app/hooks/renderHtml.ts b/src/app/hooks/renderHtml.ts
index 33cc61b1..50a56db9 100644
--- a/src/app/hooks/renderHtml.ts
+++ b/src/app/hooks/renderHtml.ts
@@ -1,6 +1,6 @@
import { Hook, ModelPath, Path, StringHookParams, ValidationOption, EnumOption, INode, DataModel, MapNode, StringNode } from '@mcschema/core'
import { locale, segmentedLocale } from '../Locales'
-import { Mounter } from '../Mounter'
+import { Mounter } from '../views/View'
import { hexId, htmlEncode } from '../Utils'
import { suffixInjector } from './suffixInjector'
@@ -22,10 +22,10 @@ export const renderHtml: Hook<[any, Mounter], [string, string, string]> = {
},
boolean({ node }, path, value, mounter) {
- const onFalse = mounter.registerClick(el => {
+ const onFalse = mounter.onClick(el => {
path.model.set(path, node.optional() && value === false ? undefined : false)
})
- const onTrue = mounter.registerClick(el => {
+ const onTrue = mounter.onClick(el => {
path.model.set(path, node.optional() && value === true ? undefined : true)
})
return ['', `