From be7ec90b500ac68e053f2b58feb085247ef95817 Mon Sep 17 00:00:00 2001 From: Petri Hienonen Date: Tue, 4 Nov 2025 17:07:24 +0200 Subject: Refactor application to use couchbase --- app/dom.js | 920 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 467 insertions(+), 453 deletions(-) (limited to 'app/dom.js') diff --git a/app/dom.js b/app/dom.js index 5f94132..ab43570 100644 --- a/app/dom.js +++ b/app/dom.js @@ -1,12 +1,29 @@ -/** - * @typedef {Object} BaseElementOptions - * @property {Partial} [styles] - * @property {string} [id] - * @property {string[]} [classes] - * @property {string} [textContent] - * @property {HTMLElement[]} [children] - * @property {Record} [attributes] - */ +// dom.js +import { House } from "models"; + +export class DomOptions { + attributes; + children; + classes; + id; + styles; + + /** + * @param {Object} [options] + * @param {Partial} [options.styles] + * @param {string|null} [options.id] + * @param {string[]} [options.classes] + * @param {HTMLElement[]} [options.children] + * @param {Record} [options.attributes] + */ + constructor({ id = "", styles = {}, classes = [], children = [], attributes = {} } = {}) { + this.attributes = attributes; + this.children = children; + this.classes = classes; + this.id = id; + this.styles = styles; + } +} /** * Toast notification types @@ -18,249 +35,149 @@ export const ToastType = { warning: "warning", }; -/** - * DOM element creation class – every creator applies its own options. - * @class - */ export class Dom { /** * Create a `
` - * @param {BaseElementOptions} [options={}] + * @param {DomOptions} options * @returns {HTMLDivElement} */ - static div(options = {}) { - const { - styles = {}, - id = "", - classes = [], - textContent = "", - children = [], - attributes = {}, - } = options; - + static div(options) { const div = document.createElement("div"); - Object.assign(div.style, styles); - if (id) div.id = id; - for (const cls of classes) div.classList.add(cls); - if (textContent) div.textContent = textContent; - for (const [k, v] of Object.entries(attributes)) div.setAttribute(k, v); - Dom.appendChildren(div, children); + Object.assign(div.style, options.styles); + if (options.id) div.id = options.id; + for (const cls of options.classes) div.classList.add(cls); + for (const [k, v] of Object.entries(options.attributes)) div.setAttribute(k, v); + if (options.children) div.append(...options.children); return div; } /** * Create a `` - * @param {BaseElementOptions} [options={}] + * @param {string} text + * @param {DomOptions} options * @returns {HTMLSpanElement} */ - static span(options = {}) { - const { - styles = {}, - id = "", - classes = [], - textContent = "", - children = [], - attributes = {}, - } = options; - + static span(text, options = new DomOptions()) { const span = document.createElement("span"); - Object.assign(span.style, styles); - if (id) span.id = id; - for (const cls of classes) span.classList.add(cls); - if (textContent) span.textContent = textContent; - for (const [k, v] of Object.entries(attributes)) span.setAttribute(k, v); - Dom.appendChildren(span, children); + Object.assign(span.style, options.styles); + if (options.id) span.id = options.id; + for (const cls of options.classes) span.classList.add(cls); + span.textContent = text; + for (const [k, v] of Object.entries(options.attributes)) span.setAttribute(k, v); + if (options.children) span.append(...options.children); return span; } /** * Create a `