Skip to content

Commit 91190ee

Browse files
committed
Merge branch 'release/v0.17.1'
2 parents 93fb60d + c39cd63 commit 91190ee

File tree

10 files changed

+36
-13
lines changed

10 files changed

+36
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "zeed-dom",
33
"type": "module",
4-
"version": "0.17.0",
4+
"version": "0.17.1",
55
"description": "🌱 Lightweight offline DOM",
66
"author": {
77
"name": "Dirk Holtwick",

src/html.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export function markup(
153153

154154
export function html(
155155
tag: string | ((props: any) => VDocumentFragment | VElement),
156-
attrs?: Record<string, unknown> | null,
156+
attrs?: Record<string, unknown> | unknown[] | null,
157157
...children: unknown[]
158158
): string {
159159
const parsed = hArgumentParser(tag, attrs, ...children)

src/serialize-markdown.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ function serialize(node: VNode | VElement, context: SerializeContext = {
5353
count: 0,
5454
}): string {
5555
if (node.nodeType === VNode.DOCUMENT_FRAGMENT_NODE) {
56-
return (node.children || []).map(c => serialize(c, { ...context })).join('')
56+
return (node.childNodes || []).map(c => serialize(c, { ...context })).join('')
5757
}
5858
else if (isVElement(node)) {
5959
const tag: string = node.tagName.toLowerCase()
60-
const handleChildren = (ctx?: Partial<SerializeContext>): string => (node.children || []).map(c => serialize(c, { ...context, ...ctx })).join('')
60+
const handleChildren = (ctx?: Partial<SerializeContext>): string => (node.childNodes || []).map(c => serialize(c, { ...context, ...ctx })).join('')
6161
const fn = rules[tag]
6262
if (fn)
6363
return fn(node as VElement, handleChildren, context)

src/serialize-plaintext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ function serialize(node: VNode | VElement, context: SerializeContext = {
1313
count: 0,
1414
}): string {
1515
if (node.nodeType === VNode.DOCUMENT_FRAGMENT_NODE) {
16-
return node.children.map(c => serialize(c, { ...context })).join('')
16+
return node.childNodes.map(c => serialize(c, { ...context })).join('')
1717
}
1818

1919
else if (isVElement(node)) {
2020
const tag: string = node.tagName.toLowerCase()
2121

22-
const handleChildren = (ctx?: Partial<SerializeContext>): string => node.children.map(c => serialize(c, { ...context, ...ctx })).join('')
22+
const handleChildren = (ctx?: Partial<SerializeContext>): string => node.childNodes.map(c => serialize(c, { ...context, ...ctx })).join('')
2323

2424
const rules: Record<string, () => string> = {
2525
br: () => `${handleChildren()}\n`,

src/serialize-safehtml.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ function serialize(node: VNode, context: SerializeContext = {
3131
count: 0,
3232
}): string {
3333
if (node.nodeType === VNode.DOCUMENT_FRAGMENT_NODE) {
34-
return (node.children || []).map(c => serialize(c, { ...context })).join('')
34+
return (node.childNodes || []).map(c => serialize(c, { ...context })).join('')
3535
}
3636
else if (isVElement(node)) {
3737
const tag: string = node.tagName?.toLowerCase()
38-
const handleChildren = (ctx?: Partial<SerializeContext>): string => (node.children || []).map(c => serialize(c, { ...context, ...ctx })).join('')
38+
const handleChildren = (ctx?: Partial<SerializeContext>): string => (node.childNodes || []).map(c => serialize(c, { ...context, ...ctx })).join('')
3939
const fn = baseRules[tag]
4040
if (fn)
4141
return fn(node, handleChildren)

src/utils.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('utils', () => {
1212

1313
const body = removeBodyContainer(doc)
1414
expect(body.render()).toMatchInlineSnapshot(
15-
`"<title>Hello Title</title>Hello world"`,
15+
`"<title>Hello Title</title>"`,
1616
)
1717
})
1818
})

src/vcss.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,18 @@ describe('css', () => {
351351
expect(matchSelector('div', <div />)).toBe(true)
352352
})
353353

354+
it('should not throw on descendant selector with attribute and iframe', () => {
355+
const element = (
356+
<div data-youtube-video>
357+
<iframe src="https://www.youtube.com/watch?v=cqHqLQgVCgY" />
358+
</div>
359+
)
360+
// Should not throw, should return true for Fiframe
361+
expect(matchSelector('div[data-youtube-video] iframe', element.querySelector('iframe'))).toBe(true)
362+
// Should return true for div
363+
expect(matchSelector('div[data-youtube-video]', element)).toBe(true)
364+
})
365+
354366
// it('should be single fail', () => {
355367
// let element = <h1>...</h1>
356368
// expect(matchSelector('[id]', element)).toBe(false)

src/vdom.spec.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,4 +724,10 @@ describe('vdom', () => {
724724
// div.remove()
725725
// div.replaceWith('x')
726726
// })
727+
728+
it('should include only elements in children', () => {
729+
const el: VElement = parseHTML('<div> <p>Hello</p> </div>').firstChild
730+
expect(el.childNodes).toHaveLength(3)
731+
expect(el.children).toHaveLength(1)
732+
})
727733
})

src/vdom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class VNode {
187187
}
188188

189189
get children() {
190-
return this._childNodes || []
190+
return (this._childNodes || []).filter<any>(isVElement)
191191
}
192192

193193
get firstChild() {

src/xml.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import type { VDocumentFragment, VElement } from './vdom'
12
import { hArgumentParser } from './h'
23
import { markup } from './html'
34
import './jsx-runtime'
45

5-
export function xml(itag: string, iattrs?: object, ...ichildren: any[]) {
6-
const { tag, attrs, children } = hArgumentParser(itag, iattrs, ichildren)
7-
return markup(true, tag, attrs, children)
6+
export function xml(
7+
itag: string | ((props: any) => VElement | VDocumentFragment),
8+
iattrs?: Record<string, unknown> | unknown[] | null,
9+
...ichildren: any[]
10+
) {
11+
const { tag, attrs, children } = hArgumentParser(itag, iattrs, ...ichildren)
12+
return markup(true, tag as string, attrs, children)
813
}
914

1015
// export const xmlVDOM = markup.bind(null, true)

0 commit comments

Comments
 (0)