From e7d02fc16d4b814c44752a49bca5e7854fed719f Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Fri, 11 Aug 2023 19:26:23 +0530 Subject: feat: adds support for specifying element type --- src/index.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index 2d6e9b8..7e73cf5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -91,18 +91,17 @@ const manageElement = async ($element: Element) => { const childrenIds = getChildrenIds($element) if (childrenIds.length > 0) { + const LAYER_CLASS = 'cssx-layer' const $childrenRoot = - $element.querySelector(':scope > .cssx-layer') ?? - Object.assign(document.createElement('div'), { - className: 'cssx-layer', - }) + $element.querySelector(`:scope > .${LAYER_CLASS}`) ?? + Object.assign(document.createElement('div'), { className: LAYER_CLASS }) $element.appendChild($childrenRoot) - for (const id of childrenIds) { - // TODO: Allow adding node types other than div + for (const childId of childrenIds) { + const [tag, id] = childId.split('#') const $child = $childrenRoot.querySelector(`:scope > #${id}`) ?? - Object.assign(document.createElement('div'), { id }) + Object.assign(document.createElement(tag || 'div'), { id }) $childrenRoot.appendChild($child) await manageElement($child) } -- cgit v1.3.1