@snupo/jmc 1.0.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/coverage/base.css +224 -0
- package/coverage/base.ts.html +172 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/coverage-final.json +7 -0
- package/coverage/favicon.png +0 -0
- package/coverage/h.ts.html +490 -0
- package/coverage/index.html +191 -0
- package/coverage/index.ts.html +97 -0
- package/coverage/jmc.ts.html +562 -0
- package/coverage/jsx.ts.html +2446 -0
- package/coverage/lib.ts.html +157 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/dist/app.js +65602 -0
- package/dist/magic-string.es-hwNd2_8t.js +1012 -0
- package/dist/rolldown-runtime-C_rDcCAf.js +43 -0
- package/dist/src/base.d.ts +7 -0
- package/dist/src/base.d.ts.map +1 -0
- package/dist/src/base.js +23 -0
- package/dist/src/base.js.map +1 -0
- package/dist/src/h.d.ts +65 -0
- package/dist/src/h.d.ts.map +1 -0
- package/dist/src/h.js +21 -0
- package/dist/src/h.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/jmc.d.ts +5 -0
- package/dist/src/jmc.d.ts.map +1 -0
- package/dist/src/jmc.js +123 -0
- package/dist/src/jmc.js.map +1 -0
- package/dist/src/jsx.d.ts +697 -0
- package/dist/src/jsx.d.ts.map +1 -0
- package/dist/src/jsx.js +21 -0
- package/dist/src/jsx.js.map +1 -0
- package/dist/src/lib.d.ts +21 -0
- package/dist/src/lib.d.ts.map +1 -0
- package/dist/src/lib.js +19 -0
- package/dist/src/lib.js.map +1 -0
- package/package.json +29 -0
- package/src/base.ts +27 -0
- package/src/h.ts +118 -0
- package/src/index.ts +5 -0
- package/src/jmc.ts +139 -0
- package/src/jsx.ts +787 -0
- package/src/lib.ts +25 -0
- package/tests/classcomponent.test.tsx +170 -0
- package/tests/functioncomponent.test.tsx +41 -0
- package/tests/h.test.tsx +312 -0
- package/tests/jmc.test.tsx +329 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +42 -0
- package/tsdown.config.ts +5 -0
- package/vite.config.mts +31 -0
- package/vitest.config.mts +34 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { jsx, jsxf, patch, HElement, JMXComp, Expr, H, updateview, HtmlHTMLAttributes, IntrinsicElementAttributes, updateviewuc, HClassComponent } from '../src/index'
|
|
2
|
+
import { describe, expect, beforeEach, it } from 'vitest'
|
|
3
|
+
import { Window } from 'happy-dom'
|
|
4
|
+
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
const window = new Window({url: "http://localhost/"})
|
|
7
|
+
window.document.documentElement.innerHTML = `<html><body></body></html>`
|
|
8
|
+
// @ts-expect-error assigning globals
|
|
9
|
+
globalThis.window = window
|
|
10
|
+
// @ts-expect-error assigning globals
|
|
11
|
+
globalThis.document = window.document
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
describe('JMX dom tests', () => {
|
|
15
|
+
|
|
16
|
+
it('HTag 1', () => {
|
|
17
|
+
|
|
18
|
+
var h: HElement = <body>hase</body>
|
|
19
|
+
|
|
20
|
+
patch(document.body, h)
|
|
21
|
+
expect(document.body.outerHTML).toBe("<body>hase</body>")
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('HTag 1 thunked', () => {
|
|
25
|
+
|
|
26
|
+
var h: HElement = <body>hase</body>
|
|
27
|
+
|
|
28
|
+
patch(document.body, h)
|
|
29
|
+
expect(document.body.outerHTML).toBe("<body>hase</body>")
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('HTag 2', () => {
|
|
33
|
+
|
|
34
|
+
let h = <body class="cc">hase{42}{true}{false}</body>
|
|
35
|
+
|
|
36
|
+
patch(document.body, h)
|
|
37
|
+
expect(document.body.className).toBe("cc")
|
|
38
|
+
expect(document.body.innerHTML).toBe("hase42truefalse")
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('HFunction', () => {
|
|
42
|
+
|
|
43
|
+
let F = ({ x }: { x: number }) => <div class={"classo" + x * 3}>{x * 2}</div>
|
|
44
|
+
let a = <body><F x={7} /></body>
|
|
45
|
+
|
|
46
|
+
patch(document.body, a)
|
|
47
|
+
expect(document.body.outerHTML).toBe('<body><div class="classo21">14</div></body>')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('clear styles after update', () => {
|
|
51
|
+
|
|
52
|
+
patch(document.body, <body><div class="hase">div</div></body>)
|
|
53
|
+
expect(document.body.innerHTML).toBe('<div class="hase">div</div>')
|
|
54
|
+
|
|
55
|
+
patch(document.querySelector("div")!, <div>snuff</div>)
|
|
56
|
+
expect(document.body.innerHTML).toBe('<div>snuff</div>')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('fragments', () => {
|
|
60
|
+
|
|
61
|
+
let F = <>
|
|
62
|
+
<b>1</b>
|
|
63
|
+
<b>2</b>
|
|
64
|
+
<b>3</b>
|
|
65
|
+
</>
|
|
66
|
+
|
|
67
|
+
patch(document.body, <body><F /></body>)
|
|
68
|
+
expect(document.body.innerHTML).toBe('<b>1</b><b>2</b><b>3</b>')
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('fragment thunked', () => {
|
|
72
|
+
|
|
73
|
+
let F = () => <>
|
|
74
|
+
<b>1</b>
|
|
75
|
+
<b>2</b>
|
|
76
|
+
<b>3</b>
|
|
77
|
+
</>
|
|
78
|
+
|
|
79
|
+
patch(document.body, <body><F /></body>)
|
|
80
|
+
expect(document.body.innerHTML).toBe('<b>1</b><b>2</b><b>3</b>')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('fragments many', () => {
|
|
84
|
+
|
|
85
|
+
let F = <>
|
|
86
|
+
<b>1</b>
|
|
87
|
+
<b>2</b>
|
|
88
|
+
<b>3</b>
|
|
89
|
+
</>
|
|
90
|
+
|
|
91
|
+
patch(document.body, <body><F /><F /></body>)
|
|
92
|
+
expect(document.body.innerHTML).toBe('<b>1</b><b>2</b><b>3</b><b>1</b><b>2</b><b>3</b>')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('element as object', () => {
|
|
96
|
+
|
|
97
|
+
let D = <div />
|
|
98
|
+
|
|
99
|
+
patch(document.body, <body><D /></body>)
|
|
100
|
+
expect(document.body.innerHTML).toBe('<div></div>')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('element as thunked object', () => {
|
|
104
|
+
|
|
105
|
+
let D = () => <div />
|
|
106
|
+
|
|
107
|
+
patch(document.body, <body><D /></body>)
|
|
108
|
+
expect(document.body.innerHTML).toBe('<div></div>')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('class component is constructed', () => {
|
|
112
|
+
|
|
113
|
+
class C extends JMXComp {
|
|
114
|
+
view() {
|
|
115
|
+
return 'bunny component'
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
patch(document.body, <body><C /></body>)
|
|
120
|
+
expect(document.body.innerHTML).toBe('bunny component')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('class component h is attached', () => {
|
|
124
|
+
class C extends JMXComp {
|
|
125
|
+
view() {
|
|
126
|
+
return <div />
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
patch(document.body, <body><C /></body>)
|
|
131
|
+
expect(document.querySelector("div")?.h).toBeDefined()
|
|
132
|
+
expect(document.body.innerHTML).toBe("<div></div>")
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
it('class component instance h.i is attached', () => {
|
|
136
|
+
class C extends JMXComp {
|
|
137
|
+
view() {
|
|
138
|
+
return <div />
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
patch(document.body, <body><C /></body>)
|
|
143
|
+
let h = document.querySelector("div")?.h as HClassComponent
|
|
144
|
+
expect(h.i).toBeDefined()
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('fragments in context', () => {
|
|
148
|
+
|
|
149
|
+
let F = <>
|
|
150
|
+
<b>1</b>
|
|
151
|
+
</>
|
|
152
|
+
|
|
153
|
+
let A = <div>
|
|
154
|
+
<F />
|
|
155
|
+
<article></article>
|
|
156
|
+
<aside></aside>
|
|
157
|
+
</div>
|
|
158
|
+
|
|
159
|
+
patch(document.body, <body><A /></body>)
|
|
160
|
+
expect(document.body.innerHTML).toBe('<div><b>1</b><article></article><aside></aside></div>')
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
it('fragments in context2', () => {
|
|
164
|
+
|
|
165
|
+
let F = () => <>
|
|
166
|
+
<b>1</b>
|
|
167
|
+
</>
|
|
168
|
+
|
|
169
|
+
let A = <div>
|
|
170
|
+
<F />
|
|
171
|
+
<article></article>
|
|
172
|
+
<aside></aside>
|
|
173
|
+
</div>
|
|
174
|
+
|
|
175
|
+
patch(document.body, <body><A /></body>)
|
|
176
|
+
expect(document.body.innerHTML).toBe('<div><b>1</b><article></article><aside></aside></div>')
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('patch class component', () => {
|
|
180
|
+
class C extends JMXComp {
|
|
181
|
+
view() {
|
|
182
|
+
return <aside>hase war da</aside>
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
document.body.innerHTML = "<div />"
|
|
187
|
+
patch(document.body.querySelector("div"), <C />)
|
|
188
|
+
expect(document.body.innerHTML).toBe("<aside>hase war da</aside>")
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
it('svg autonamespace', () => {
|
|
192
|
+
|
|
193
|
+
let h = <div>
|
|
194
|
+
<circle id="c1" />
|
|
195
|
+
<svg xmlns="http://www.w3.org/2000/svg">
|
|
196
|
+
<circle id="c2" />
|
|
197
|
+
</svg>
|
|
198
|
+
</div>
|
|
199
|
+
|
|
200
|
+
patch(document.body, h)
|
|
201
|
+
let svg = document.querySelector("svg")
|
|
202
|
+
expect(svg).toBeInstanceOf(SVGElement)
|
|
203
|
+
expect(svg?.namespaceURI).toBe("http://www.w3.org/2000/svg")
|
|
204
|
+
|
|
205
|
+
expect(document.getElementById("c1")?.namespaceURI).toBe("http://www.w3.org/1999/xhtml")
|
|
206
|
+
expect(document.getElementById("c2")?.namespaceURI).toBe("http://www.w3.org/2000/svg")
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
it('Expression', () => {
|
|
210
|
+
|
|
211
|
+
let F = () => <div><b>bunny</b></div>
|
|
212
|
+
let H = () => <body>hase</body>
|
|
213
|
+
|
|
214
|
+
patch(document.body, <H />)
|
|
215
|
+
expect(document.body.outerHTML).toBe("<body>hase</body>")
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
it('Expression is updated', () => {
|
|
219
|
+
|
|
220
|
+
let m = { name: 'bugs' }
|
|
221
|
+
let F: Expr<H> = () => <body>{m.name}</body>
|
|
222
|
+
|
|
223
|
+
patch(document.body, <F />)
|
|
224
|
+
expect(document.body.outerHTML).toBe("<body>bugs</body>")
|
|
225
|
+
|
|
226
|
+
m.name = 'bunny'
|
|
227
|
+
updateview()
|
|
228
|
+
expect(document.body.outerHTML).toBe("<body>bunny</body>")
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
it('patchelementonly does not expand the whole subtree', () => {
|
|
232
|
+
|
|
233
|
+
let m = {
|
|
234
|
+
sidepanel: false,
|
|
235
|
+
longlist: [1, 2, 3]
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
let B = ({ x }: { x: number }) => {
|
|
239
|
+
return <b>{x}</b>
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
let Side = <side>
|
|
243
|
+
{m.longlist.map(x => <B x={x} />)}
|
|
244
|
+
</side>
|
|
245
|
+
|
|
246
|
+
let App = () => <body>
|
|
247
|
+
<Side />
|
|
248
|
+
</body>
|
|
249
|
+
|
|
250
|
+
patch(document.body, <App />)
|
|
251
|
+
expect(document.body.outerHTML).toBe("<body><side><b>1</b><b>2</b><b>3</b></side></body>")
|
|
252
|
+
|
|
253
|
+
console.log("updating")
|
|
254
|
+
m.sidepanel = true
|
|
255
|
+
|
|
256
|
+
updateviewuc({ patchElementOnly: true }, "body")
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
it('patchelementonly does not expand the whole subtree 2', () => {
|
|
260
|
+
|
|
261
|
+
let m = {
|
|
262
|
+
sidepanel: false,
|
|
263
|
+
longlist: [1, 2, 3]
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
let B = ({ x }: { x: number }) => {
|
|
267
|
+
return <b>{x}</b>
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
let Side = () => <side>
|
|
271
|
+
{m.longlist.map(x => <B x={x} />)}
|
|
272
|
+
</side>
|
|
273
|
+
|
|
274
|
+
let App = () => <body>
|
|
275
|
+
<Side />
|
|
276
|
+
</body>
|
|
277
|
+
|
|
278
|
+
console.log("patch initial")
|
|
279
|
+
patch(document.body, <App />)
|
|
280
|
+
expect(document.body.outerHTML).toBe("<body><side><b>1</b><b>2</b><b>3</b></side></body>")
|
|
281
|
+
|
|
282
|
+
console.log("updating")
|
|
283
|
+
m.sidepanel = true
|
|
284
|
+
|
|
285
|
+
updateviewuc({ patchElementOnly: true }, "body")
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
it('patchelementonly does not expand the whole subtree 3', () => {
|
|
289
|
+
|
|
290
|
+
let m = {
|
|
291
|
+
sidepanel: false,
|
|
292
|
+
longlist: [1, 2, 3]
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
let B = ({ x }: { x: number }) => {
|
|
296
|
+
return <i><b>{x}</b></i>
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
let I = ({ x }: { x: number }) => {
|
|
300
|
+
return <i><B x={x} /></i>
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let Side = <side>
|
|
304
|
+
<B x={1} />
|
|
305
|
+
<B x={2} />
|
|
306
|
+
<B x={4} />
|
|
307
|
+
</side>
|
|
308
|
+
|
|
309
|
+
let App = () => <body>
|
|
310
|
+
<Side />
|
|
311
|
+
</body>
|
|
312
|
+
|
|
313
|
+
patch(document.body, <App />)
|
|
314
|
+
expect(document.body.outerHTML).toBe("<body><side><i><b>1</b></i><i><b>2</b></i><i><b>4</b></i></side></body>")
|
|
315
|
+
|
|
316
|
+
console.log("updating")
|
|
317
|
+
m.sidepanel = true
|
|
318
|
+
updateviewuc({ patchElementOnly: true }, "body")
|
|
319
|
+
expect(document.body.outerHTML).toBe("<body><side><i><b>1</b></i><i><b>2</b></i><i><b>4</b></i></side></body>")
|
|
320
|
+
})
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
declare global {
|
|
324
|
+
namespace JSX {
|
|
325
|
+
interface IntrinsicElements extends IntrinsicElementAttributes {
|
|
326
|
+
side: HtmlHTMLAttributes
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNEXT",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
|
|
6
|
+
"jsx": "react",
|
|
7
|
+
"jsxFactory": "jsx",
|
|
8
|
+
"jsxFragmentFactory": "jsxf",
|
|
9
|
+
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"declarationMap": true,
|
|
12
|
+
|
|
13
|
+
"sourceMap": true,
|
|
14
|
+
"inlineSources": true,
|
|
15
|
+
|
|
16
|
+
"outDir": "dist",
|
|
17
|
+
|
|
18
|
+
"removeComments": false,
|
|
19
|
+
|
|
20
|
+
"strict": true,
|
|
21
|
+
"noImplicitAny": true,
|
|
22
|
+
"strictNullChecks": true,
|
|
23
|
+
|
|
24
|
+
"moduleResolution": "bundler",
|
|
25
|
+
|
|
26
|
+
"esModuleInterop": true,
|
|
27
|
+
|
|
28
|
+
"experimentalDecorators": true,
|
|
29
|
+
|
|
30
|
+
"skipLibCheck": true,
|
|
31
|
+
"forceConsistentCasingInFileNames": true,
|
|
32
|
+
|
|
33
|
+
"preserveConstEnums": false
|
|
34
|
+
},
|
|
35
|
+
// "include": [
|
|
36
|
+
// "src"
|
|
37
|
+
// ],
|
|
38
|
+
"exclude": [
|
|
39
|
+
"node_modules",
|
|
40
|
+
"dist"
|
|
41
|
+
]
|
|
42
|
+
}
|
package/tsdown.config.ts
ADDED
package/vite.config.mts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
|
|
3
|
+
// vite.config.js
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
oxc: {
|
|
6
|
+
jsx: {
|
|
7
|
+
development: false,
|
|
8
|
+
runtime: "classic",
|
|
9
|
+
pragma: "jsx",
|
|
10
|
+
pragmaFrag: "jsxf",
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
plugins: [
|
|
14
|
+
{
|
|
15
|
+
name: "strip-pure",
|
|
16
|
+
transform: (code: string) => code.replace(/\/\*\s*@__PURE__\s*\*\/\s*/g, "")
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
// build: {
|
|
20
|
+
// minify: false,
|
|
21
|
+
// modulePreload: false,
|
|
22
|
+
// rolldownOptions: {
|
|
23
|
+
// platform: 'browser',
|
|
24
|
+
// output: {
|
|
25
|
+
// format: 'es',
|
|
26
|
+
// entryFileNames: 'app.js',
|
|
27
|
+
// assetFileNames: '[name].[ext]',
|
|
28
|
+
// }
|
|
29
|
+
// }
|
|
30
|
+
// }
|
|
31
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
oxc: {
|
|
5
|
+
jsx: {
|
|
6
|
+
development: false,
|
|
7
|
+
runtime: "classic",
|
|
8
|
+
pragma: "jsx",
|
|
9
|
+
pragmaFrag: "jsxf",
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
plugins: [
|
|
13
|
+
{
|
|
14
|
+
name: "strip-pure",
|
|
15
|
+
transform: (code: string) => code.replace(/\/\*\s*@__PURE__\s*\*\/\s*/g, "")
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
test: {
|
|
19
|
+
include: ['./tests/*.test.{js,ts,tsx}'],
|
|
20
|
+
coverage: {
|
|
21
|
+
provider: 'v8',
|
|
22
|
+
reporter: ['text', 'json', 'html'],
|
|
23
|
+
// include: ['**/*.{ts,tsx}']
|
|
24
|
+
},
|
|
25
|
+
environment: 'happy-dom',
|
|
26
|
+
snapshotFormat: {
|
|
27
|
+
printBasicPrototype: false,
|
|
28
|
+
escapeString: false,
|
|
29
|
+
},
|
|
30
|
+
diff: {
|
|
31
|
+
printBasicPrototype: false,
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
})
|