Skip to content

Commit c9c7dca

Browse files
committed
Added for Function-Component in JDOM-Template
1 parent 36284c5 commit c9c7dca

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# JDOM `3.0.1`
1+
# JDOM `3.0.2`
22
## A wrapper for query selector and html elements + templating & reactivity framework
33

44
## Install
@@ -9,12 +9,12 @@ npm install jdomjs
99

1010
### Module
1111
```js
12-
import { $, $n, $c, $r, $h, JDOM } from 'https://cdn.jsdelivr.net/npm/jdomjs@3.0.1/index.js'
12+
import { $, $n, $c, $r, $h, JDOM } from 'https://cdn.jsdelivr.net/npm/jdomjs@3.0.2/index.js'
1313
```
1414

1515
### HTML import
1616
```js
17-
<script src="https://cdn.jsdelivr.net/npm/jdom@3.0.1/dist/jdom.js"></script>
17+
<script src="https://cdn.jsdelivr.net/npm/jdom@3.0.2/dist/jdom.js"></script>
1818
```
1919

2020
## DOM-Modfier Usage
@@ -164,6 +164,17 @@ html`
164164
name: ${name} <br>
165165
<input :bind=${name}>
166166
`
167+
168+
// Function components
169+
function UserLayout({ exampleProp, $slot }) {
170+
return html`<div class="user-profile">
171+
${$slot}
172+
</div>`
173+
}
174+
175+
html`<${UserLayout} exampleProp="test">
176+
Profile
177+
</${UserLayout}>`
167178
```
168179

169180
# Reactivity (JDOM-Hooks)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jdomjs",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"description": "A wrapper for query selector and html elements",
55
"main": "index.js",
66

src/template/JDOMTemplateParser.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,39 @@ export default class JDOMTemplateParser {
8787

8888

8989
if (value === '>') {
90-
if (this.autoCloseTags.includes(tag.tag.toLowerCase())) {
90+
if (typeof tag.tag === 'string' && this.autoCloseTags.includes(tag.tag.toLowerCase())) {
9191
this.next()
9292
break
9393
}
9494
opened = true
9595
}
9696
} else if (closingTag) {
97-
const next = `</${tag.tag}`
97+
const next = `</`
9898

9999
// TODO: Check why -1 is needed
100100
if (this.nextIs(next, -1)) {
101-
this.next(next.length - 1)
102-
this.skipEmpty()
103-
// Skipping >
104-
this.next()
101+
let isEnding = false
102+
// typeof tag.tag === 'string'
103+
const afterClosingSlash = this.get(this.index + 1)
104+
if (afterClosingSlash.type === 'value') {
105+
if (typeof afterClosingSlash.value === 'function' && afterClosingSlash.value === tag.tag) {
106+
isEnding = true
107+
tag.attributes.slot = tag.body
108+
this.next()
109+
}
110+
} else {
111+
if (!this.nextIs(tag.tag)) {
112+
isEnding = true
113+
this.next(tag.tag.length)
114+
}
115+
}
116+
117+
if (isEnding) {
118+
this.next(next.length - 1)
119+
this.skipEmpty()
120+
// Skipping >
121+
this.next()
122+
}
105123

106124
break
107125
}

src/template/TemplateDOMAdapter.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export default class TemplateDOMAdapter {
1212

1313
if (typeof conf.tag === 'function') {
1414
const elAttribs = {}
15+
16+
if (conf.body.length > 0) {
17+
elAttribs.$slot = (new TemplateDOMAdapter(conf.body)).create(svg)
18+
}
19+
1520
for (const [key, value] of conf.attributes) {
1621
if (key === ':bind') {
1722
elAttribs.value = value
@@ -24,6 +29,7 @@ export default class TemplateDOMAdapter {
2429

2530
return this.createFromValue({value: newEl})
2631
}
32+
2733
if (conf.tag.toLowerCase() === '!doctype')
2834
return null
2935

0 commit comments

Comments
 (0)