Allow loading/saving app.config from plugins and support custom folder/filename formats from app.config

This commit is contained in:
Olivia Godone-Maresca
2023-03-29 20:56:24 -04:00
parent e5a47ac964
commit 7e53eb658c
4 changed files with 315 additions and 43 deletions

View File

@ -683,14 +683,16 @@ class ServiceContainer {
* @param {string} tag
* @param {object} attributes
* @param {string | Array<string>} classes
* @param {string | HTMLElement | Array<string | HTMLElement>}
* @param {string | Node | Array<string | Node>}
* @returns {HTMLElement}
*/
function createElement(tagName, attributes, classes, textOrElements) {
const element = document.createElement(tagName)
if (attributes) {
Object.entries(attributes).forEach(([key, value]) => {
element.setAttribute(key, value)
if (value !== undefined && value !== null) {
element.setAttribute(key, value)
}
});
}
if (classes) {
@ -699,7 +701,7 @@ function createElement(tagName, attributes, classes, textOrElements) {
if (textOrElements) {
const children = Array.isArray(textOrElements) ? textOrElements : [textOrElements]
children.forEach(textOrElem => {
if (textOrElem instanceof HTMLElement) {
if (textOrElem instanceof Node) {
element.appendChild(textOrElem)
} else {
element.appendChild(document.createTextNode(textOrElem))
@ -708,3 +710,21 @@ function createElement(tagName, attributes, classes, textOrElements) {
}
return element
}
/**
* Add a listener for arrays
* @param {keyof Array} method
* @param {(args) => {}} callback
*/
Array.prototype.addEventListener = function(method, callback) {
console.log(`Array.addEventListener(${method})`)
const originalFunction = this[method]
if (originalFunction) {
this[method] = function() {
console.log(`Array.${method}()`, arguments)
originalFunction.apply(this, arguments)
callback.apply(this, arguments)
}
}
}