fusee-framework 1.6.0 → 1.7.0
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.
- package/README.md +29 -13
- package/app/benchmark/benchmark.js +633 -0
- package/app/benchmark/index.html +102 -0
- package/app/benchmark/styles.css +249 -0
- package/app/components/Counter.js +17 -7
- package/app/components/CounterSection.js +3 -4
- package/app/main.js +29 -62
- package/app/main.ts +72 -63
- package/app/pages/404.js +16 -0
- package/app/pages/[...all].js +35 -0
- package/app/pages/[...all].ts +35 -0
- package/app/pages/_layout.js +26 -0
- package/app/pages/_layout.ts +26 -0
- package/app/pages/about.js +23 -0
- package/app/pages/about.ts +29 -0
- package/app/pages/composables.js +158 -0
- package/app/pages/composables.ts +158 -0
- package/app/pages/dynamic.js +40 -0
- package/app/pages/dynamic.ts +40 -0
- package/app/pages/index.js +117 -0
- package/app/pages/index.ts +78 -0
- package/app/pages/login.ts +21 -0
- package/app/pages/objects/[id].js +56 -0
- package/app/pages/objects/[id].ts +56 -0
- package/app/pages/posts/[category]/[slug].js +56 -0
- package/app/pages/posts/[category]/[slug].ts +56 -0
- package/app/pages/router-example.js +56 -0
- package/app/pages/router-example.ts +56 -0
- package/app/pages/test-for.js +65 -0
- package/app/pages/test-for.ts +80 -0
- package/app/pages/users/[id].js +24 -0
- package/app/pages/users/[id].ts +46 -0
- package/app/pages/users/index.js +22 -0
- package/app/pages/users/index.ts +29 -0
- package/app/pages/users.js +43 -0
- package/app/pages/users.ts +78 -0
- package/app/routes/About.js +1 -1
- package/app/routes/About.ts +1 -1
- package/app/routes/AuthRoutes.ts +41 -0
- package/app/routes/Home.js +9 -0
- package/app/routes/NotFound.js +16 -0
- package/app/routes/NotFound.ts +16 -0
- package/app/routes/RouterExample.js +56 -0
- package/app/routes/RouterExample.ts +56 -0
- package/app/routes/WildcardDemo.js +35 -0
- package/app/routes/WildcardDemo.ts +35 -0
- package/auto-imports.d.ts +1 -0
- package/bin/create-fusee-linux +0 -0
- package/bin/create-fusee-mac-arm64 +0 -0
- package/bin/create-fusee-mac-intel +0 -0
- package/bin/create-fusee-win.exe +0 -0
- package/bin/create-fusee.exe +0 -0
- package/bin/index.js +38 -0
- package/create-fusee-go/cmd/generate.go +72 -0
- package/create-fusee-go/cmd/init.go +38 -0
- package/create-fusee-go/cmd/root.go +121 -0
- package/create-fusee-go/go.mod +10 -0
- package/create-fusee-go/go.sum +10 -0
- package/create-fusee-go/internal/assets/assets.go +78 -0
- package/create-fusee-go/internal/assets/embed/framework/auto-import-preset.js +9 -0
- package/create-fusee-go/internal/assets/embed/framework/core/compiler.js +253 -0
- package/create-fusee-go/internal/assets/embed/framework/core/component.js +266 -0
- package/create-fusee-go/internal/assets/embed/framework/core/composable.js +27 -0
- package/create-fusee-go/internal/assets/embed/framework/core/directives.js +875 -0
- package/create-fusee-go/internal/assets/embed/framework/core/evaluator.js +153 -0
- package/create-fusee-go/internal/assets/embed/framework/core/event-delegation.js +191 -0
- package/create-fusee-go/internal/assets/embed/framework/core/signal.js +412 -0
- package/create-fusee-go/internal/assets/embed/framework/core/store.js +81 -0
- package/create-fusee-go/internal/assets/embed/framework/index.d.ts +3 -0
- package/create-fusee-go/internal/assets/embed/framework/index.js +10 -0
- package/create-fusee-go/internal/assets/embed/framework/router/file-router.js +177 -0
- package/create-fusee-go/internal/assets/embed/framework/router/router.js +462 -0
- package/create-fusee-go/internal/assets/embed/framework/types/compiler.d.ts +15 -0
- package/create-fusee-go/internal/assets/embed/framework/types/component.d.ts +88 -0
- package/create-fusee-go/internal/assets/embed/framework/types/composable.d.ts +14 -0
- package/create-fusee-go/internal/assets/embed/framework/types/directives.d.ts +55 -0
- package/create-fusee-go/internal/assets/embed/framework/types/evaluator.d.ts +13 -0
- package/create-fusee-go/internal/assets/embed/framework/types/event-delegation.d.ts +32 -0
- package/create-fusee-go/internal/assets/embed/framework/types/index.d.ts +22 -0
- package/create-fusee-go/internal/assets/embed/framework/types/router.d.ts +32 -0
- package/create-fusee-go/internal/assets/embed/framework/types/signal.d.ts +79 -0
- package/create-fusee-go/internal/assets/embed/framework/types/store.d.ts +8 -0
- package/create-fusee-go/internal/assets/templates/Counter.tmpl +26 -0
- package/create-fusee-go/internal/assets/templates/component.tmpl +11 -0
- package/create-fusee-go/internal/assets/templates/components/Loading.tmpl +24 -0
- package/create-fusee-go/internal/assets/templates/index.html.tmpl +15 -0
- package/create-fusee-go/internal/assets/templates/main.tmpl +14 -0
- package/create-fusee-go/internal/assets/templates/package.json.tmpl +14 -0
- package/create-fusee-go/internal/assets/templates/page.tmpl +12 -0
- package/create-fusee-go/internal/assets/templates/pages/about.tmpl +20 -0
- package/create-fusee-go/internal/assets/templates/pages/index.tmpl +22 -0
- package/create-fusee-go/internal/assets/templates/pages/layout.tmpl +18 -0
- package/create-fusee-go/internal/assets/templates/tsconfig.json.tmpl +14 -0
- package/create-fusee-go/internal/assets/templates/vite.config.js.tmpl +18 -0
- package/create-fusee-go/main.go +7 -0
- package/framework/auto-import-preset.js +1 -1
- package/framework/core/compiler.js +252 -249
- package/framework/core/component.js +265 -260
- package/framework/core/directives.js +875 -786
- package/framework/core/evaluator.js +153 -70
- package/framework/core/event-delegation.js +33 -14
- package/framework/core/signal.js +412 -403
- package/framework/index.js +10 -11
- package/framework/router/file-router.js +177 -0
- package/framework/router/router.js +462 -80
- package/framework/types/event-delegation.d.ts +0 -58
- package/framework/types/router.d.ts +32 -15
- package/framework/types/signal.d.ts +1 -0
- package/index.html +638 -626
- package/package.json +5 -3
- package/tsconfig.json +1 -0
- /package/{framework → create-fusee-go/internal/assets/embed/framework}/bin/create-fusee.js +0 -0
|
@@ -1,250 +1,253 @@
|
|
|
1
|
-
import { effect, batch } from './signal.js'
|
|
2
|
-
import { processDirectives } from './directives.js'
|
|
3
|
-
import { parseSlots } from './component.js'
|
|
4
|
-
import {
|
|
5
|
-
evaluateExpression,
|
|
6
|
-
parseInterpolation,
|
|
7
|
-
sanitizeAttr,
|
|
8
|
-
MUSTACHE_RE
|
|
9
|
-
} from './evaluator.js'
|
|
10
|
-
|
|
11
|
-
export function mountTemplate(template, container, context, components) {
|
|
12
|
-
const effects = []
|
|
13
|
-
let processed = template.replace(/(<[a-zA-Z0-9-]+\s[^>]*?)\s:([a-zA-Z][a-zA-Z0-9-]*)=/g, '$1 data-bind-$2=')
|
|
14
|
-
|
|
15
|
-
for (const name of Object.keys(components)) {
|
|
16
|
-
const reWithSlot = new RegExp(
|
|
17
|
-
`\\{\\{\\s*${name}(\\s[^}]*?|\\s*)\\}\\}([\\s\\S]*?)\\{\\{\\s*\\/${name}\\s*\\}\\}`,
|
|
18
|
-
'g'
|
|
19
|
-
)
|
|
20
|
-
const reNoSlot = new RegExp(`\\{\\{\\s*${name}(\\s+.*?|\\s*)\\}\\}`, 'g')
|
|
21
|
-
|
|
22
|
-
processed = processed.replace(reWithSlot, (match, propsStr, slotContent) => {
|
|
23
|
-
const attrs = parseComponentAttrs(propsStr || '')
|
|
24
|
-
const encodedSlot = encodeURIComponent(slotContent.trim())
|
|
25
|
-
return `<div data-component="${name}"${attrs} data-slot="${encodedSlot}"></div>`
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
processed = processed.replace(reNoSlot, (match, propsStr) => {
|
|
29
|
-
const attrs = parseComponentAttrs(propsStr || '')
|
|
30
|
-
return `<div data-component="${name}"${attrs}></div>`
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
container.innerHTML = processed
|
|
35
|
-
compileNode(container, context, components, effects)
|
|
36
|
-
|
|
37
|
-
return { effects }
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function parseComponentAttrs(propsStr) {
|
|
41
|
-
let attrs = ''
|
|
42
|
-
if (!propsStr || !propsStr.trim()) return attrs
|
|
43
|
-
|
|
44
|
-
const attrRegex = /(@?:?[a-zA-Z0-9-]+)="([^"]*)"/g
|
|
45
|
-
let attrMatch
|
|
46
|
-
while ((attrMatch = attrRegex.exec(propsStr)) !== null) {
|
|
47
|
-
const attrName = attrMatch[1]
|
|
48
|
-
const attrValue = attrMatch[2]
|
|
49
|
-
|
|
50
|
-
if (attrName.startsWith('@')) {
|
|
51
|
-
attrs += ` data-on-${attrName.slice(1).toLowerCase()}="${attrValue}"`
|
|
52
|
-
} else if (attrName.startsWith(':')) {
|
|
53
|
-
attrs += ` data-bind-prop-${attrName.slice(1).toLowerCase()}="${attrValue}"`
|
|
54
|
-
} else {
|
|
55
|
-
attrs += ` data-prop-${attrName.toLowerCase()}="${attrValue}"`
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return attrs
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function compileNode(node, context, components, effects) {
|
|
62
|
-
if (node.nodeType === 1 && node.hasAttribute('f-once')) {
|
|
63
|
-
node.removeAttribute('f-once')
|
|
64
|
-
const temporaryEffects = []
|
|
65
|
-
|
|
66
|
-
processDirectives(node, context, components, temporaryEffects)
|
|
67
|
-
processBindingAttrs(node, context, temporaryEffects)
|
|
68
|
-
processMustaches(node, context, temporaryEffects)
|
|
69
|
-
bindComponents(node, components, context, temporaryEffects)
|
|
70
|
-
|
|
71
|
-
let child = node.firstChild
|
|
72
|
-
while (child) {
|
|
73
|
-
compileOnce(child, context, components, temporaryEffects)
|
|
74
|
-
child = child.nextSibling
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
for (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
fragment.appendChild(
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
el.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
1
|
+
import { effect, batch } from './signal.js'
|
|
2
|
+
import { processDirectives } from './directives.js'
|
|
3
|
+
import { parseSlots } from './component.js'
|
|
4
|
+
import {
|
|
5
|
+
evaluateExpression,
|
|
6
|
+
parseInterpolation,
|
|
7
|
+
sanitizeAttr,
|
|
8
|
+
MUSTACHE_RE
|
|
9
|
+
} from './evaluator.js'
|
|
10
|
+
|
|
11
|
+
export function mountTemplate(template, container, context, components) {
|
|
12
|
+
const effects = []
|
|
13
|
+
let processed = template.replace(/(<[a-zA-Z0-9-]+\s[^>]*?)\s:([a-zA-Z][a-zA-Z0-9-]*)=/g, '$1 data-bind-$2=')
|
|
14
|
+
|
|
15
|
+
for (const name of Object.keys(components)) {
|
|
16
|
+
const reWithSlot = new RegExp(
|
|
17
|
+
`\\{\\{\\s*${name}(\\s[^}]*?|\\s*)\\}\\}([\\s\\S]*?)\\{\\{\\s*\\/${name}\\s*\\}\\}`,
|
|
18
|
+
'g'
|
|
19
|
+
)
|
|
20
|
+
const reNoSlot = new RegExp(`\\{\\{\\s*${name}(\\s+.*?|\\s*)\\}\\}`, 'g')
|
|
21
|
+
|
|
22
|
+
processed = processed.replace(reWithSlot, (match, propsStr, slotContent) => {
|
|
23
|
+
const attrs = parseComponentAttrs(propsStr || '')
|
|
24
|
+
const encodedSlot = encodeURIComponent(slotContent.trim())
|
|
25
|
+
return `<div data-component="${name}"${attrs} data-slot="${encodedSlot}"></div>`
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
processed = processed.replace(reNoSlot, (match, propsStr) => {
|
|
29
|
+
const attrs = parseComponentAttrs(propsStr || '')
|
|
30
|
+
return `<div data-component="${name}"${attrs}></div>`
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
container.innerHTML = processed
|
|
35
|
+
compileNode(container, context, components, effects)
|
|
36
|
+
|
|
37
|
+
return { effects }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function parseComponentAttrs(propsStr) {
|
|
41
|
+
let attrs = ''
|
|
42
|
+
if (!propsStr || !propsStr.trim()) return attrs
|
|
43
|
+
|
|
44
|
+
const attrRegex = /(@?:?[a-zA-Z0-9-]+)="([^"]*)"/g
|
|
45
|
+
let attrMatch
|
|
46
|
+
while ((attrMatch = attrRegex.exec(propsStr)) !== null) {
|
|
47
|
+
const attrName = attrMatch[1]
|
|
48
|
+
const attrValue = attrMatch[2]
|
|
49
|
+
|
|
50
|
+
if (attrName.startsWith('@')) {
|
|
51
|
+
attrs += ` data-on-${attrName.slice(1).toLowerCase()}="${attrValue}"`
|
|
52
|
+
} else if (attrName.startsWith(':')) {
|
|
53
|
+
attrs += ` data-bind-prop-${attrName.slice(1).toLowerCase()}="${attrValue}"`
|
|
54
|
+
} else {
|
|
55
|
+
attrs += ` data-prop-${attrName.toLowerCase()}="${attrValue}"`
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return attrs
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function compileNode(node, context, components, effects) {
|
|
62
|
+
if (node.nodeType === 1 && node.hasAttribute('f-once')) {
|
|
63
|
+
node.removeAttribute('f-once')
|
|
64
|
+
const temporaryEffects = []
|
|
65
|
+
|
|
66
|
+
processDirectives(node, context, components, temporaryEffects)
|
|
67
|
+
processBindingAttrs(node, context, temporaryEffects)
|
|
68
|
+
processMustaches(node, context, temporaryEffects)
|
|
69
|
+
bindComponents(node, components, context, temporaryEffects)
|
|
70
|
+
|
|
71
|
+
let child = node.firstChild
|
|
72
|
+
while (child) {
|
|
73
|
+
compileOnce(child, context, components, temporaryEffects)
|
|
74
|
+
child = child.nextSibling
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
for (let i = temporaryEffects.length - 1; i >= 0; i--) {
|
|
78
|
+
const cleanup = temporaryEffects[i]
|
|
79
|
+
if (typeof cleanup === 'function') cleanup()
|
|
80
|
+
}
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (node.nodeType === 1) {
|
|
85
|
+
if (processDirectives(node, context, components, effects)) return
|
|
86
|
+
processBindingAttrs(node, context, effects)
|
|
87
|
+
bindComponents(node, components, context, effects)
|
|
88
|
+
} else if (node.nodeType === 3) {
|
|
89
|
+
processMustaches(node, context, effects)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let child = node.firstChild
|
|
93
|
+
while (child) {
|
|
94
|
+
compileNode(child, context, components, effects)
|
|
95
|
+
child = child.nextSibling
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function compileOnce(node, context, components, effects) {
|
|
100
|
+
if (node.nodeType === 1) {
|
|
101
|
+
if (processDirectives(node, context, components, effects)) return
|
|
102
|
+
processBindingAttrs(node, context, effects)
|
|
103
|
+
bindComponents(node, components, context, effects)
|
|
104
|
+
} else if (node.nodeType === 3) {
|
|
105
|
+
processMustaches(node, context, effects)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let child = node.firstChild
|
|
109
|
+
while (child) {
|
|
110
|
+
compileOnce(child, context, components, effects)
|
|
111
|
+
child = child.nextSibling
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function processMustaches(node, context, effects) {
|
|
116
|
+
if (node.nodeType !== 3) return
|
|
117
|
+
const text = node.textContent
|
|
118
|
+
if (!MUSTACHE_RE.test(text)) return
|
|
119
|
+
|
|
120
|
+
const parts = parseInterpolation(text)
|
|
121
|
+
const fragment = document.createDocumentFragment()
|
|
122
|
+
|
|
123
|
+
for (const part of parts) {
|
|
124
|
+
if (part.type === 'static') {
|
|
125
|
+
fragment.appendChild(document.createTextNode(part.value))
|
|
126
|
+
} else {
|
|
127
|
+
const reactiveNode = document.createTextNode('')
|
|
128
|
+
fragment.appendChild(reactiveNode)
|
|
129
|
+
const key = part.key
|
|
130
|
+
const e = effect(() => {
|
|
131
|
+
const resolved = evaluateExpression(key, context)
|
|
132
|
+
reactiveNode.textContent = String(resolved ?? '')
|
|
133
|
+
})
|
|
134
|
+
effects.push(e)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
node.parentNode.replaceChild(fragment, node)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function processBindingAttrs(el, context, effects) {
|
|
141
|
+
if (el.nodeType !== 1) return
|
|
142
|
+
for (const attr of [...el.attributes]) {
|
|
143
|
+
if (attr.name.startsWith('data-bind-') && !attr.name.startsWith('data-bind-prop-')) {
|
|
144
|
+
const realAttr = attr.name.slice(10)
|
|
145
|
+
const expr = attr.value
|
|
146
|
+
el.removeAttribute(attr.name)
|
|
147
|
+
|
|
148
|
+
const e = effect(() => {
|
|
149
|
+
let resolved = evaluateExpression(expr, context)
|
|
150
|
+
if (realAttr === 'class') {
|
|
151
|
+
if (!el._staticClass) el._staticClass = el.getAttribute('class') || ''
|
|
152
|
+
let dynamicClass = ''
|
|
153
|
+
if (Array.isArray(resolved)) dynamicClass = resolved.filter(Boolean).join(' ')
|
|
154
|
+
else if (resolved !== null && typeof resolved === 'object') {
|
|
155
|
+
dynamicClass = Object.entries(resolved).filter(([_, v]) => !!v).map(([k]) => k).join(' ')
|
|
156
|
+
} else dynamicClass = String(resolved ?? '')
|
|
157
|
+
el.className = (el._staticClass + ' ' + dynamicClass).trim()
|
|
158
|
+
} else if (realAttr === 'style') {
|
|
159
|
+
if (resolved !== null && typeof resolved === 'object') {
|
|
160
|
+
for (const k in resolved) el.style[k] = resolved[k]
|
|
161
|
+
} else el.style.cssText = String(resolved ?? '')
|
|
162
|
+
} else {
|
|
163
|
+
if (typeof resolved === 'boolean') {
|
|
164
|
+
resolved ? el.setAttribute(realAttr, '') : el.removeAttribute(realAttr)
|
|
165
|
+
} else el.setAttribute(realAttr, sanitizeAttr(realAttr, String(resolved)))
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
effects.push(e)
|
|
169
|
+
continue
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (MUSTACHE_RE.test(attr.value)) {
|
|
173
|
+
const attrName = attr.name
|
|
174
|
+
const parts = parseInterpolation(attr.value)
|
|
175
|
+
el.removeAttribute(attrName)
|
|
176
|
+
const e = effect(() => {
|
|
177
|
+
let result = ''
|
|
178
|
+
for (const part of parts) {
|
|
179
|
+
result += part.type === 'static' ? part.value : String(evaluateExpression(part.key, context) ?? '')
|
|
180
|
+
}
|
|
181
|
+
el.setAttribute(attrName, sanitizeAttr(attrName, result))
|
|
182
|
+
})
|
|
183
|
+
effects.push(e)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function bindComponents(el, components, context, effects) {
|
|
189
|
+
if (el.nodeType !== 1) return
|
|
190
|
+
const name = el.getAttribute('data-component')
|
|
191
|
+
if (!name) return
|
|
192
|
+
|
|
193
|
+
el.removeAttribute('data-component')
|
|
194
|
+
|
|
195
|
+
const ComponentFn = components[name]
|
|
196
|
+
if (!ComponentFn) return
|
|
197
|
+
|
|
198
|
+
const props = {}
|
|
199
|
+
const listeners = {}
|
|
200
|
+
|
|
201
|
+
for (const attr of [...el.attributes]) {
|
|
202
|
+
const attrName = attr.name.toLowerCase()
|
|
203
|
+
|
|
204
|
+
if (attrName.startsWith('data-prop-')) {
|
|
205
|
+
props[attrName.slice(10)] = attr.value
|
|
206
|
+
|
|
207
|
+
} else if (attrName.startsWith('data-bind-prop-')) {
|
|
208
|
+
const propName = attrName.slice(15)
|
|
209
|
+
const expression = attr.value.trim()
|
|
210
|
+
|
|
211
|
+
if (expression in context) {
|
|
212
|
+
Object.defineProperty(props, propName, {
|
|
213
|
+
get() {
|
|
214
|
+
const val = context[expression]
|
|
215
|
+
return typeof val === 'function' && val.isSignal ? val() : val
|
|
216
|
+
},
|
|
217
|
+
enumerable: true,
|
|
218
|
+
configurable: true
|
|
219
|
+
})
|
|
220
|
+
} else {
|
|
221
|
+
Object.defineProperty(props, propName, {
|
|
222
|
+
get() { return evaluateExpression(expression, context) },
|
|
223
|
+
enumerable: true,
|
|
224
|
+
configurable: true
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
} else if (attrName.startsWith('data-on-')) {
|
|
229
|
+
const eventName = attrName.slice(8)
|
|
230
|
+
const handlerExpr = attr.value.trim()
|
|
231
|
+
|
|
232
|
+
listeners[eventName] = (...args) => {
|
|
233
|
+
const handler = context[handlerExpr]
|
|
234
|
+
if (typeof handler === 'function') {
|
|
235
|
+
handler(...args)
|
|
236
|
+
} else {
|
|
237
|
+
evaluateExpression(handlerExpr, context)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const rawSlot = el.getAttribute('data-slot')
|
|
244
|
+
const slots = rawSlot ? parseSlots(decodeURIComponent(rawSlot)) : {}
|
|
245
|
+
el.removeAttribute('data-slot')
|
|
246
|
+
|
|
247
|
+
const childComponent = ComponentFn(props, { listeners, slots, parent: context._instance })
|
|
248
|
+
childComponent.render(el)
|
|
249
|
+
|
|
250
|
+
if (effects) {
|
|
251
|
+
effects.push(() => childComponent.unmount())
|
|
252
|
+
}
|
|
250
253
|
}
|