diff --git a/development/issues/open/233.html b/development/issues/open/233.html index e854dfb918e8483d8f15090d417584cb231fa9b6..8238afb6036c77a7543d4a25a81e7bd223ae5d9a 100644 --- a/development/issues/open/233.html +++ b/development/issues/open/233.html @@ -118,6 +118,50 @@ </monster-tree-menu> + </monster-panel> + + <monster-panel id="inner3" data-monster-option-heightadjustment="5" + slot="end"> + <monster-tree-menu + data-monster-option-mapping-idtemplate="id" + data-monster-option-mapping-parentkey="parent_id" + data-monster-option-mapping-labeltemplate="${title}" + data-monster-option-mapping-valuetemplate="${path:url | tostring}" + data-monster-option-mapping-icontemplate="${path:icon | default:default}" + data-monster-option-datasource-selector="#menu-rest" + value="" + > + + <svg xmlns="http://www.w3.org/2000/svg" style="display: none;"> + <symbol id="box" viewBox="0 0 16 16"> + <path d="M6 9a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3A.5.5 0 0 1 6 9M3.854 4.146a.5.5 0 1 0-.708.708L4.793 6.5 3.146 8.146a.5.5 0 1 0 .708.708l2-2a.5.5 0 0 0 0-.708z"/> + <path d="M2 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2zm12 1a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1z"/> + </symbol> + + <symbol id="default" viewBox="0 0 16 16"> + <path d="M11 2a3 3 0 0 1 3 3v6a3 3 0 0 1-3 3H5a3 3 0 0 1-3-3V5a3 3 0 0 1 3-3zM5 1a4 4 0 0 0-4 4v6a4 4 0 0 0 4 4h6a4 4 0 0 0 4-4V5a4 4 0 0 0-4-4z"/> + </symbol> + + + <symbol id="balloon" viewBox="0 0 16 16"> + <path d="M8 9.984C10.403 9.506 12 7.48 12 5a4 4 0 0 0-8 0c0 2.48 1.597 4.506 4 4.984M13 5c0 2.837-1.789 5.227-4.52 5.901l.244.487a.25.25 0 1 1-.448.224l-.008-.017c.008.11.02.202.037.29.054.27.161.488.419 1.003.288.578.235 1.15.076 1.629-.157.469-.422.867-.588 1.115l-.004.007a.25.25 0 1 1-.416-.278c.168-.252.4-.6.533-1.003.133-.396.163-.824-.049-1.246l-.013-.028c-.24-.48-.38-.758-.448-1.102a3 3 0 0 1-.052-.45l-.04.08a.25.25 0 1 1-.447-.224l.244-.487C4.789 10.227 3 7.837 3 5a5 5 0 0 1 10 0m-6.938-.495a2 2 0 0 1 1.443-1.443C7.773 2.994 8 2.776 8 2.5s-.226-.504-.498-.459a3 3 0 0 0-2.46 2.461c-.046.272.182.498.458.498s.494-.227.562-.495"/> + </symbol> + + <symbol id="cart" viewBox="0 0 16 16"> + <path d="M8 1a2.5 2.5 0 0 1 2.5 2.5V4h-5v-.5A2.5 2.5 0 0 1 8 1m3.5 3v-.5a3.5 3.5 0 1 0-7 0V4H1v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V4zM2 5h12v9a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1z"/> + </symbol> + + <symbol id="box2" viewBox="0 0 16 16"> + <path d="M8 7.982C9.664 6.309 13.825 9.236 8 13 2.175 9.236 6.336 6.31 8 7.982"/> + <path d="M3.75 0a1 1 0 0 0-.8.4L.1 4.2a.5.5 0 0 0-.1.3V15a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1V4.5a.5.5 0 0 0-.1-.3L13.05.4a1 1 0 0 0-.8-.4zm0 1H7.5v3h-6zM8.5 4V1h3.75l2.25 3zM15 5v10H1V5z"/> + </symbol> + + + </svg> + + + </monster-tree-menu> + </monster-panel> </monster-split-panel> </monster-panel> diff --git a/development/issues/open/233.mjs b/development/issues/open/233.mjs index 04bca3a9c1b4494617a3d9a9eabec2ba76373355..5f64595aba2e4f1f377b1f709571c0fec18249e7 100644 --- a/development/issues/open/233.mjs +++ b/development/issues/open/233.mjs @@ -21,10 +21,11 @@ setTimeout(() => { const obj = document.querySelector("monster-tree-menu"); obj.selectEntry("/alvine/?cmd=9130") - setTimeout(() => { - //obj.selectEntry("/ebay") - obj.selectEntry("/alvine/?cmd=8157") - }, 1000) + // setTimeout(() => { + // //obj.selectEntry("/ebay") + // console.log(obj) + // obj.selectEntry("/alvine/?cmd=9201") + // }, 5000) }, 1000) diff --git a/source/components/tree-menu/tree-menu.mjs b/source/components/tree-menu/tree-menu.mjs index 6b91af5d6921a0626dd3952d1195c986580aefa6..ea022d0079ba36beba9a8df835f24d4ede4909fa 100644 --- a/source/components/tree-menu/tree-menu.mjs +++ b/source/components/tree-menu/tree-menu.mjs @@ -217,6 +217,7 @@ class TreeMenu extends CustomElement { * @param value */ selectEntry(value) { + this.shadowRoot .querySelectorAll("[data-monster-role=entry]") .forEach((entry) => { @@ -241,6 +242,7 @@ class TreeMenu extends CustomElement { let intend = parseInt(currentNode.getAttribute(ATTRIBUTE_INTEND)); if (intend > 0) { + const refSet = new Set() let ref = currentNode.previousElementSibling; while (ref && ref.hasAttribute(ATTRIBUTE_INTEND)) { const i = parseInt(ref.getAttribute(ATTRIBUTE_INTEND)); @@ -252,6 +254,11 @@ class TreeMenu extends CustomElement { if (i < intend) { if (ref.getAttribute("data-monster-state") !== "open") { ref.click(); + + //console.log(ref.getAttribute("data-monster-state") ) + + //refSet.add(ref) + //console.log(ref) } if (i === 0) { @@ -261,6 +268,13 @@ class TreeMenu extends CustomElement { } ref = ref.previousElementSibling; } + + // if (refSet.size > 0) { + // console.log(refSet) + // refSet.forEach((ref) => { + // ref.click(); + // }) + // } } } } @@ -311,7 +325,10 @@ function initEventHandler() { return; } this[preventChangeSymbol] = true; - importEntries.call(this); + setTimeout(() => { + importEntries.call(this); + },10) + }), ); }); @@ -500,7 +517,10 @@ function importEntries() { } } - this.setOption("entries", options); + setTimeout(() => { + this.setOption("entries", options); + },5) + return this; } diff --git a/source/data/pathfinder.mjs b/source/data/pathfinder.mjs index dbadb68c358e642ccfe2464f398157f80313dcdf..98bf041949520130a94d2a0548d9f5fe863796ef 100644 --- a/source/data/pathfinder.mjs +++ b/source/data/pathfinder.mjs @@ -12,22 +12,22 @@ * SPDX-License-Identifier: AGPL-3.0 */ -import { Base } from "../types/base.mjs"; +import {Base} from "../types/base.mjs"; import { - isArray, - isInteger, - isObject, - isPrimitive, - isString, + isArray, + isInteger, + isObject, + isPrimitive, + isString, } from "../types/is.mjs"; -import { Stack } from "../types/stack.mjs"; +import {Stack} from "../types/stack.mjs"; import { - validateInteger, - validateBoolean, - validateString, + validateInteger, + validateBoolean, + validateString, } from "../types/validate.mjs"; -export { Pathfinder, DELIMITER, WILDCARD }; +export {Pathfinder, DELIMITER, WILDCARD}; /** * path separator @@ -89,101 +89,102 @@ const WILDCARD = "*"; * @memberOf Monster.Data */ class Pathfinder extends Base { - /** - * Creates a new instance of the constructor. - * - * @param {object} object - The object parameter for the constructor. - * - * @throws {Error} Throws an error if the provided object parameter is a simple type. - */ - constructor(object) { - super(); - - if (isPrimitive(object)) { - throw new Error("the parameter must not be a simple type"); - } - - this.object = object; - this.wildCard = WILDCARD; - } - - /** - * set wildcard - * - * @param {string} wildcard - * @return {Pathfinder} - * @since 1.7.0 - */ - setWildCard(wildcard) { - validateString(wildcard); - this.wildCard = wildcard; - return this; - } - - /** - * - * @param {string|array} path - * @since 1.4.0 - * @returns {*} - * @throws {TypeError} unsupported type - * @throws {Error} the journey is not at its end - * @throws {TypeError} value is not a string - * @throws {TypeError} value is not an integer - * @throws {Error} unsupported action for this data type - */ - getVia(path) { - return getValueViaPath.call(this, this.object, path); - } - - /** - * - * @param {string|array} path - * @param {*} value - * @returns {Pathfinder} - * @since 1.4.0 - * @throws {TypeError} unsupported type - * @throws {TypeError} value is not a string - * @throws {TypeError} value is not an integer - * @throws {Error} unsupported action for this data type - */ - setVia(path, value) { - setValueViaPath.call(this, this.object, path, value); - return this; - } - - /** - * Delete Via Path - * - * @param {string|array} path - * @returns {Pathfinder} - * @since 1.6.0 - * @throws {TypeError} unsupported type - * @throws {TypeError} value is not a string - * @throws {TypeError} value is not an integer - * @throws {Error} unsupported action for this data type - */ - deleteVia(path) { - deleteValueViaPath.call(this, this.object, path); - return this; - } - - /** - * - * @param {string|array} path - * @return {bool} - * @throws {TypeError} unsupported type - * @throws {TypeError} value is not a string - * @throws {TypeError} value is not an integer - * @since 1.4.0 - */ - exists(path) { - try { - getValueViaPath.call(this, this.object, path, true); - return true; - } catch (e) {} - - return false; - } + /** + * Creates a new instance of the constructor. + * + * @param {object} object - The object parameter for the constructor. + * + * @throws {Error} Throws an error if the provided object parameter is a simple type. + */ + constructor(object) { + super(); + + if (isPrimitive(object)) { + throw new Error("the parameter must not be a simple type"); + } + + this.object = object; + this.wildCard = WILDCARD; + } + + /** + * set wildcard + * + * @param {string} wildcard + * @return {Pathfinder} + * @since 1.7.0 + */ + setWildCard(wildcard) { + validateString(wildcard); + this.wildCard = wildcard; + return this; + } + + /** + * + * @param {string|array} path + * @since 1.4.0 + * @returns {*} + * @throws {TypeError} unsupported type + * @throws {Error} the journey is not at its end + * @throws {TypeError} value is not a string + * @throws {TypeError} value is not an integer + * @throws {Error} unsupported action for this data type + */ + getVia(path) { + return getValueViaPath.call(this, this.object, path); + } + + /** + * + * @param {string|array} path + * @param {*} value + * @returns {Pathfinder} + * @since 1.4.0 + * @throws {TypeError} unsupported type + * @throws {TypeError} value is not a string + * @throws {TypeError} value is not an integer + * @throws {Error} unsupported action for this data type + */ + setVia(path, value) { + setValueViaPath.call(this, this.object, path, value); + return this; + } + + /** + * Delete Via Path + * + * @param {string|array} path + * @returns {Pathfinder} + * @since 1.6.0 + * @throws {TypeError} unsupported type + * @throws {TypeError} value is not a string + * @throws {TypeError} value is not an integer + * @throws {Error} unsupported action for this data type + */ + deleteVia(path) { + deleteValueViaPath.call(this, this.object, path); + return this; + } + + /** + * + * @param {string|array} path + * @return {bool} + * @throws {TypeError} unsupported type + * @throws {TypeError} value is not a string + * @throws {TypeError} value is not an integer + * @since 1.4.0 + */ + exists(path) { + try { + getValueViaPath.call(this, this.object, path, true); + return true; + } catch (e) { + } + + return false; + } } /** @@ -198,106 +199,105 @@ class Pathfinder extends Base { * @private */ function iterate(subject, path, check) { - if (check === undefined) { - check = false; - } - validateBoolean(check); - - const result = new Map(); - - if (isArray(path)) { - path = path.join(DELIMITER); - } - - if (isObject(subject) || isArray(subject)) { - for (const [key, value] of Object.entries(subject)) { - result.set(key, getValueViaPath.call(this, value, path, check)); - } - } else { - const key = path.split(DELIMITER).shift(); - result.set(key, getValueViaPath.call(this, subject, path, check)); - } - - return result; + if (check === undefined) { + check = false; + } + validateBoolean(check); + + const result = new Map(); + + if (isArray(path)) { + path = path.join(DELIMITER); + } + + if (isObject(subject) || isArray(subject)) { + for (const [key, value] of Object.entries(subject)) { + result.set(key, getValueViaPath.call(this, value, path, check)); + } + } else { + const key = path.split(DELIMITER).shift(); + result.set(key, getValueViaPath.call(this, subject, path, check)); + } + + return result; } /** * - * @param {*} subject - * @param [string|array} path - * @param [boolean} check - * @returns {*} + * @param subject + * @param path + * @param check + * @returns {V|*|Map} * @throws {TypeError} unsupported type * @throws {Error} the journey is not at its end * @throws {Error} unsupported action for this data type - * @private */ function getValueViaPath(subject, path, check) { - if (check === undefined) { - check = false; - } - validateBoolean(check); - - if (!(isArray(path) || isString(path))) { - throw new Error("type error: path must be a string or an array"); - } - - let parts; - if (isString(path)) { - if (path === "") { - return subject; - } - - parts = path.split(DELIMITER); - } - - let current = parts.shift(); - - if (current === this.wildCard) { - return iterate.call(this, subject, parts.join(DELIMITER), check); - } - - if (isObject(subject) || isArray(subject)) { - let anchor; - if (subject instanceof Map || subject instanceof WeakMap) { - anchor = subject.get(current); - } else if (subject instanceof Set || subject instanceof WeakSet) { - current = parseInt(current); - validateInteger(current); - anchor = [...subject]?.[current]; - } else if (typeof WeakRef === "function" && subject instanceof WeakRef) { - throw Error("unsupported action for this data type"); - } else if (isArray(subject)) { - current = parseInt(current); - validateInteger(current); - anchor = subject?.[current]; - } else { - anchor = subject?.[current]; - } - - if (isObject(anchor) || isArray(anchor)) { - return getValueViaPath.call(this, anchor, parts.join(DELIMITER), check); - } - - if (parts.length > 0) { - throw Error(`the journey is not at its end (${parts.join(DELIMITER)})`); - } - - if (check === true) { - const descriptor = Object.getOwnPropertyDescriptor( - Object.getPrototypeOf(subject), - current, - ); - - if (!subject.hasOwnProperty(current) && descriptor === undefined) { - throw Error("unknown value"); - } - } - - return anchor; - } - - throw TypeError(`unsupported type ${typeof subject}`); + if (check === undefined) { + check = false; + } + validateBoolean(check); + + if (!(isArray(path) || isString(path))) { + throw new Error("type error: a path must be a string or an array in getValueViaPath"); + } + + let parts; + if (isString(path)) { + if (path === "") { + return subject; + } + + parts = path.split(DELIMITER); + } + + let current = parts.shift(); + + if (current === this.wildCard) { + return iterate.call(this, subject, parts.join(DELIMITER), check); + } + + if (isObject(subject) || isArray(subject)) { + let anchor; + if (subject instanceof Map || subject instanceof WeakMap) { + anchor = subject.get(current); + } else if (subject instanceof Set || subject instanceof WeakSet) { + current = parseInt(current); + validateInteger(current); + anchor = [...subject]?.[current]; + } else if (typeof WeakRef === "function" && subject instanceof WeakRef) { + throw Error("unsupported action for this data type (WeakRef)"); + } else if (isArray(subject)) { + current = parseInt(current); + validateInteger(current); + anchor = subject?.[current]; + } else { + anchor = subject?.[current]; + } + + if (isObject(anchor) || isArray(anchor)) { + return getValueViaPath.call(this, anchor, parts.join(DELIMITER), check); + } + + if (parts.length > 0) { + throw Error(`the journey is not at its end (${parts.join(DELIMITER)})`); + } + + if (check === true) { + const descriptor = Object.getOwnPropertyDescriptor( + Object.getPrototypeOf(subject), + current, + ); + + if (!subject.hasOwnProperty(current) && descriptor === undefined) { + throw Error("unknown value " + current); + } + } + + return anchor; + } + + throw TypeError(`unsupported type ${typeof subject} for path ${path}`); } /** @@ -313,72 +313,73 @@ function getValueViaPath(subject, path, check) { * @private */ function setValueViaPath(subject, path, value) { - if (!(isArray(path) || isString(path))) { - throw new Error("type error: path must be a string or an array"); - } - - let parts; - if (isArray(path)) { - if (path.length === 0) { - return subject; - } - - parts = path; - } else { - parts = path.split(DELIMITER); - } - - let last = parts.pop(); - const subpath = parts.join(DELIMITER); - - const stack = new Stack(); - let current = subpath; - while (true) { - try { - getValueViaPath.call(this, subject, current, true); - break; - } catch (e) {} - - stack.push(current); - parts.pop(); - current = parts.join(DELIMITER); - - if (current === "") break; - } - - while (!stack.isEmpty()) { - current = stack.pop(); - let obj = {}; - - if (!stack.isEmpty()) { - const n = stack.peek().split(DELIMITER).pop(); - if (isInteger(parseInt(n))) { - obj = []; - } - } - - setValueViaPath.call(this, subject, current, obj); - } - - const anchor = getValueViaPath.call(this, subject, subpath); - - if (!(isObject(subject) || isArray(subject))) { - throw TypeError(`unsupported type: ${typeof subject}`); - } - - if (anchor instanceof Map || anchor instanceof WeakMap) { - anchor.set(last, value); - } else if (anchor instanceof Set || anchor instanceof WeakSet) { - anchor.append(value); - } else if (typeof WeakRef === "function" && anchor instanceof WeakRef) { - throw Error("unsupported action for this data type"); - } else if (isArray(anchor)) { - last = parseInt(last); - validateInteger(last); - assignProperty(anchor, last, value); - } else { - assignProperty(anchor, last, value); - } + if (!(isArray(path) || isString(path))) { + throw new Error("type error: a path must be a string or an array"); + } + + let parts; + if (isArray(path)) { + if (path.length === 0) { + return; + } + + parts = path; + } else { + parts = path.split(DELIMITER); + } + + let last = parts.pop(); + const subpath = parts.join(DELIMITER); + + const stack = new Stack(); + let current = subpath; + while (true) { + try { + getValueViaPath.call(this, subject, current, true); + break; + } catch (e) { + } + + stack.push(current); + parts.pop(); + current = parts.join(DELIMITER); + + if (current === "") break; + } + + while (!stack.isEmpty()) { + current = stack.pop(); + let obj = {}; + + if (!stack.isEmpty()) { + const n = stack.peek().split(DELIMITER).pop(); + if (isInteger(parseInt(n))) { + obj = []; + } + } + + setValueViaPath.call(this, subject, current, obj); + } + + const anchor = getValueViaPath.call(this, subject, subpath); + + if (!(isObject(subject) || isArray(subject))) { + throw TypeError(`unsupported type: ${typeof subject} in setValueViaPath`); + } + + if (anchor instanceof Map || anchor instanceof WeakMap) { + anchor.set(last, value); + } else if (anchor instanceof Set || anchor instanceof WeakSet) { + anchor.append(value); + } else if (typeof WeakRef === "function" && anchor instanceof WeakRef) { + throw Error("unsupported action for this data type in setValueViaPath"); + } else if (isArray(anchor)) { + last = parseInt(last); + validateInteger(last); + assignProperty(anchor, "" + last, value); + } else { + assignProperty(anchor, last, value); + } } /** @@ -388,16 +389,16 @@ function setValueViaPath(subject, path, value) { * @param {*} value */ function assignProperty(object, key, value) { - if (!object.hasOwnProperty(key)) { - object[key] = value; - return; - } + if (!object.hasOwnProperty(key)) { + object[key] = value; + return; + } - if (value === undefined) { - delete object[key]; - } + if (value === undefined) { + delete object[key]; + } - object[key] = value; + object[key] = value; } /** @@ -414,40 +415,40 @@ function assignProperty(object, key, value) { * @private */ function deleteValueViaPath(subject, path) { - if (!(isArray(path) || isString(path))) { - throw new Error("type error: path must be a string or an array"); - } - - let parts; - if (isArray(path)) { - if (path.length === 0) { - return subject; - } - - parts = path; - } else { - parts = path.split(DELIMITER); - } - - let last = parts.pop(); - const subpath = parts.join(DELIMITER); - - const anchor = getValueViaPath.call(this, subject, subpath); - - if (anchor instanceof Map) { - anchor.delete(last); - } else if ( - anchor instanceof Set || - anchor instanceof WeakMap || - anchor instanceof WeakSet || - (typeof WeakRef === "function" && anchor instanceof WeakRef) - ) { - throw Error("unsupported action for this data type"); - } else if (isArray(anchor)) { - last = parseInt(last); - validateInteger(last); - delete anchor[last]; - } else { - delete anchor[last]; - } + if (!(isArray(path) || isString(path))) { + throw new Error("type error: a path must be a string or an array in deleteValueViaPath"); + } + + let parts; + if (isArray(path)) { + if (path.length === 0) { + return; + } + + parts = path; + } else { + parts = path.split(DELIMITER); + } + + let last = parts.pop(); + const subPath = parts.join(DELIMITER); + + const anchor = getValueViaPath.call(this, subject, subPath); + + if (anchor instanceof Map) { + anchor.delete(last); + } else if ( + anchor instanceof Set || + anchor instanceof WeakMap || + anchor instanceof WeakSet || + (typeof WeakRef === "function" && anchor instanceof WeakRef) + ) { + throw Error("unsupported action for this data type in deleteValueViaPath"); + } else if (isArray(anchor)) { + last = parseInt(last); + validateInteger(last); + delete anchor[last]; + } else { + delete anchor[last]; + } } diff --git a/source/dom/updater.mjs b/source/dom/updater.mjs index 92c77b5d998324a1e924b91d18bfa73c12b4244f..790ce09a9406f7da1f532fc7df65a1ed6752b99a 100644 --- a/source/dom/updater.mjs +++ b/source/dom/updater.mjs @@ -221,7 +221,7 @@ class Updater extends Base { * If you have passed a ProxyObserver in the constructor, you will get the object that the ProxyObserver manages here. * However, if you passed a simple object, here you will get a proxy for that object. * - * For changes the ProxyObserver must be used. + * For changes, the ProxyObserver must be used. * * @since 1.8.0 * @return {Proxy} @@ -534,7 +534,7 @@ function insertElement(change) { const available = new Set(); - for (const [i, obj] of Object.entries(value)) { + for (const [i, ] of Object.entries(value)) { const ref = refPrefix + i; const currentPath = `${dataPath}.${i}`; diff --git a/test/cases/data/pathfinder.mjs b/test/cases/data/pathfinder.mjs index c3ccc0d043483e5a36c58327e898a820cc2e4a9b..d97d95ba45454430848ea578f2f215db4aca073e 100644 --- a/test/cases/data/pathfinder.mjs +++ b/test/cases/data/pathfinder.mjs @@ -69,11 +69,12 @@ describe('Pathfinder', function () { it('.setVia(' + a + ') should result in ' + b, function () { + let r = pf.getVia(a); let i = convertMapResult(r); expect(JSON.stringify(i)).is.equal(b); - }); + }); });