jails-js 6.5.0 → 6.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -151,29 +151,35 @@ const setTemplates = ( clone, components ) => {
151
151
  }
152
152
 
153
153
  const removeTemplateTagsRecursively = (node) => {
154
- const walker = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT, {
155
- acceptNode: el => el.tagName === 'TEMPLATE' ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
156
- })
157
154
 
158
- const templatesToRemove = []
155
+ // Get all <template> elements within the node
156
+ const templates = node.querySelectorAll('template')
157
+
158
+ templates.forEach((template) => {
159
159
 
160
- while (walker.nextNode()) {
161
- const tpl = walker.currentNode
162
- if (!tpl.hasAttribute('html-if') && !tpl.hasAttribute('html-inner')) {
163
- templatesToRemove.push(tpl)
160
+ if( template.getAttribute('html-if') || template.getAttribute('html-inner') ) {
161
+ return
164
162
  }
165
- }
166
163
 
167
- for (const template of templatesToRemove) {
164
+ // Process any nested <template> tags within this <template> first
165
+ removeTemplateTagsRecursively(template.content)
166
+
167
+ // Get the parent of the <template> tag
168
168
  const parent = template.parentNode
169
- if (!parent) continue
170
169
 
171
- const frag = document.createDocumentFragment()
172
- frag.append(...template.content.childNodes)
173
- parent.replaceChild(frag, template)
174
- }
170
+ if (parent) {
171
+ // Move all child nodes from the <template>'s content to its parent
172
+ const content = template.content
173
+ while (content.firstChild) {
174
+ parent.insertBefore(content.firstChild, template)
175
+ }
176
+ // Remove the <template> tag itself
177
+ parent.removeChild(template)
178
+ }
179
+ })
175
180
  }
176
181
 
182
+
177
183
  const wrap = (open, node, close) => {
178
184
  node.parentNode?.insertBefore(open, node)
179
185
  node.parentNode?.insertBefore(close, node.nextSibling)
package/types.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ declare module 'jails-js/html' {
2
+ export function html(strings: TemplateStringsArray, ...values: any[]): string;
3
+ export function attributes(strings: TemplateStringsArray, ...values: any[]): string;
4
+ }
5
+
1
6
  type EventCallback = ( Event: Event, data?:any ) => void
2
7
 
3
8
  export declare const templateConfig: (options: any) => void;
@@ -41,11 +46,6 @@ export type Component = {
41
46
 
42
47
  dataset( key: string ) : any
43
48
 
44
- attr( target?: HTMLElement ) : {
45
- change : ( attribute: string, callback: Function ) => void
46
- disconnect : ( callback: Function ) => void
47
- }
48
-
49
49
  }
50
50
 
51
51
  export type Model = {