arche 0.3.11 → 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/test.js CHANGED
@@ -12,10 +12,10 @@ describe('Arche', () => {
12
12
  new TypeError('creator not defined'),
13
13
  )
14
14
 
15
- globalThis.document = { createElement() {} }
15
+ const document = { createElement() {} }
16
16
 
17
- const E1 = Arche()
18
- assert.equal(E1.creator, globalThis.document)
17
+ const E1 = Arche(document)
18
+ assert.equal(E1.creator, document)
19
19
  })
20
20
 
21
21
  const mockEventListeners = new Map()
@@ -61,7 +61,7 @@ describe('Arche', () => {
61
61
  }
62
62
 
63
63
  const el = Div([
64
- H1('header'),
64
+ MockElement('h1', {}, 'header'),
65
65
  P({ style: { color: 'grey' } }, 'description'),
66
66
  Span({ id: 'hey', excluded: null }),
67
67
  Div({ id: 'nested' }, [
@@ -173,4 +173,130 @@ describe('Arche', () => {
173
173
  '["div",{},[["h1",{},["header"]],["h3",{"style":{"color":"grey"}},["description"]],["b",{"id":"hey","excluded":null},[]],["article",{"id":"nested"},[["article",{},["yo"]]]],["span",{},[]]]]')
174
174
  })
175
175
  })
176
+
177
+ it('Typed elements', async () => {
178
+ const mockReact = {
179
+ createElement(type, props, ...children) {
180
+ return [type, props || {}, children || []]
181
+ },
182
+ }
183
+ const MockReactElement = Arche(mockReact)
184
+
185
+ assert.equal(typeof MockReactElement.A, 'function')
186
+ assert.equal(MockReactElement.A()[0],'a')
187
+ assert.equal(typeof MockReactElement.P, 'function')
188
+ assert.equal(MockReactElement.P()[0],'p')
189
+ assert.equal(typeof MockReactElement.B, 'function')
190
+ assert.equal(MockReactElement.B()[0],'b')
191
+ assert.equal(typeof MockReactElement.Q, 'function')
192
+ assert.equal(MockReactElement.Q()[0],'q')
193
+ assert.equal(typeof MockReactElement.I, 'function')
194
+ assert.equal(MockReactElement.I()[0],'i')
195
+ assert.equal(typeof MockReactElement.S, 'function')
196
+ assert.equal(MockReactElement.S()[0],'s')
197
+ assert.equal(typeof MockReactElement.U, 'function')
198
+ assert.equal(MockReactElement.U()[0],'u')
199
+ assert.equal(typeof MockReactElement.Ul, 'function')
200
+ assert.equal(MockReactElement.Ul()[0],'ul')
201
+ assert.equal(typeof MockReactElement.Ol, 'function')
202
+ assert.equal(MockReactElement.Ol()[0],'ol')
203
+ assert.equal(typeof MockReactElement.Li, 'function')
204
+ assert.equal(MockReactElement.Li()[0],'li')
205
+
206
+ assert.equal(typeof MockReactElement.H1, 'function')
207
+ assert.equal(MockReactElement.H1()[0],'h1')
208
+ assert.equal(typeof MockReactElement.H2, 'function')
209
+ assert.equal(MockReactElement.H2()[0],'h2')
210
+ assert.equal(typeof MockReactElement.H3, 'function')
211
+ assert.equal(MockReactElement.H3()[0],'h3')
212
+ assert.equal(typeof MockReactElement.H4, 'function')
213
+ assert.equal(MockReactElement.H4()[0],'h4')
214
+ assert.equal(typeof MockReactElement.H5, 'function')
215
+ assert.equal(MockReactElement.H5()[0],'h5')
216
+ assert.equal(typeof MockReactElement.H6, 'function')
217
+ assert.equal(MockReactElement.H6()[0],'h6')
218
+ assert.equal(typeof MockReactElement.Hr, 'function')
219
+ assert.equal(MockReactElement.Hr()[0],'hr')
220
+ assert.equal(typeof MockReactElement.Br, 'function')
221
+ assert.equal(MockReactElement.Br()[0],'br')
222
+
223
+ assert.equal(typeof MockReactElement.Script, 'function')
224
+ assert.equal(MockReactElement.Script()[0],'script')
225
+ assert.equal(typeof MockReactElement.Style, 'function')
226
+ assert.equal(MockReactElement.Style()[0],'style')
227
+
228
+ assert.equal(typeof MockReactElement.Html, 'function')
229
+ assert.equal(MockReactElement.Html()[0],'html')
230
+ assert.equal(typeof MockReactElement.Main, 'function')
231
+ assert.equal(MockReactElement.Main()[0],'main')
232
+ assert.equal(typeof MockReactElement.Body, 'function')
233
+ assert.equal(MockReactElement.Body()[0],'body')
234
+ assert.equal(typeof MockReactElement.Header, 'function')
235
+ assert.equal(MockReactElement.Header()[0],'header')
236
+ assert.equal(typeof MockReactElement.Nav, 'function')
237
+ assert.equal(MockReactElement.Nav()[0],'nav')
238
+ assert.equal(typeof MockReactElement.Section, 'function')
239
+ assert.equal(MockReactElement.Section()[0],'section')
240
+ assert.equal(typeof MockReactElement.Article, 'function')
241
+ assert.equal(MockReactElement.Article()[0],'article')
242
+ assert.equal(typeof MockReactElement.Footer, 'function')
243
+ assert.equal(MockReactElement.Footer()[0],'footer')
244
+ assert.equal(typeof MockReactElement.Span, 'function')
245
+ assert.equal(MockReactElement.Span()[0],'span')
246
+ assert.equal(typeof MockReactElement.Div, 'function')
247
+ assert.equal(MockReactElement.Div()[0],'div')
248
+ assert.equal(typeof MockReactElement.Img, 'function')
249
+ assert.equal(MockReactElement.Img()[0],'img')
250
+ assert.equal(typeof MockReactElement.Video, 'function')
251
+ assert.equal(MockReactElement.Video()[0],'video')
252
+ assert.equal(typeof MockReactElement.Picture, 'function')
253
+ assert.equal(MockReactElement.Picture()[0],'picture')
254
+ assert.equal(typeof MockReactElement.Source, 'function')
255
+ assert.equal(MockReactElement.Source()[0],'source')
256
+
257
+ assert.equal(typeof MockReactElement.Form, 'function')
258
+ assert.equal(MockReactElement.Form()[0],'form')
259
+ assert.equal(typeof MockReactElement.Fieldset, 'function')
260
+ assert.equal(MockReactElement.Fieldset()[0],'fieldset')
261
+ assert.equal(typeof MockReactElement.Input, 'function')
262
+ assert.equal(MockReactElement.Input()[0],'input')
263
+ assert.equal(typeof MockReactElement.Label, 'function')
264
+ assert.equal(MockReactElement.Label()[0],'label')
265
+ assert.equal(typeof MockReactElement.Textarea, 'function')
266
+ assert.equal(MockReactElement.Textarea()[0],'textarea')
267
+ assert.equal(typeof MockReactElement.Select, 'function')
268
+ assert.equal(MockReactElement.Select()[0],'select')
269
+ assert.equal(typeof MockReactElement.Option, 'function')
270
+ assert.equal(MockReactElement.Option()[0],'option')
271
+
272
+ assert.equal(typeof MockReactElement.Button, 'function')
273
+ assert.equal(MockReactElement.Button()[0],'button')
274
+ assert.equal(typeof MockReactElement.Iframe, 'function')
275
+ assert.equal(MockReactElement.Iframe()[0],'iframe')
276
+ assert.equal(typeof MockReactElement.Blockquote, 'function')
277
+ assert.equal(MockReactElement.Blockquote()[0],'blockquote')
278
+ assert.equal(typeof MockReactElement.Code, 'function')
279
+ assert.equal(MockReactElement.Code()[0],'code')
280
+ assert.equal(typeof MockReactElement.Pre, 'function')
281
+ assert.equal(MockReactElement.Pre()[0],'pre')
282
+
283
+ assert.equal(typeof MockReactElement.Polygon, 'function')
284
+ assert.equal(MockReactElement.Polygon()[0],'polygon')
285
+ assert.equal(typeof MockReactElement.Svg, 'function')
286
+ assert.equal(MockReactElement.Svg()[0],'svg')
287
+ assert.equal(typeof MockReactElement.Path, 'function')
288
+ assert.equal(MockReactElement.Path()[0],'path')
289
+ assert.equal(typeof MockReactElement.Rect, 'function')
290
+ assert.equal(MockReactElement.Rect()[0],'rect')
291
+ assert.equal(typeof MockReactElement.Mask, 'function')
292
+ assert.equal(MockReactElement.Mask()[0],'mask')
293
+
294
+ assert.equal(typeof MockReactElement.Dl, 'function')
295
+ assert.equal(MockReactElement.Dl()[0],'dl')
296
+ assert.equal(typeof MockReactElement.Dt, 'function')
297
+ assert.equal(MockReactElement.Dt()[0],'dt')
298
+ assert.equal(typeof MockReactElement.Dd, 'function')
299
+ assert.equal(MockReactElement.Dd()[0],'dd')
300
+ })
301
+
176
302
  })
package/test-lib.html DELETED
@@ -1,87 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>test</title>
6
- <script src="https://unpkg.com/react@16.13.1/umd/react.production.min.js" crossorigin></script>
7
- <script src="https://unpkg.com/react-dom@16.13.1/umd/react-dom.production.min.js" crossorigin></script>
8
- <script src="/index.js"></script>
9
- </head>
10
- <body>
11
- <div id="example"></div>
12
- <div id="user-card"></div>
13
- <div id="dom-example">
14
- </div>
15
- </body>
16
- <script>
17
- function isElement(obj) {
18
- try {
19
- return obj instanceof HTMLElement;
20
- } catch (error) {
21
- return (typeof obj == 'object') &&
22
- (obj.nodeType == 1) && (typeof obj.style == 'object') &&
23
- (typeof obj.ownerDocument == 'object')
24
- }
25
- }
26
-
27
- const Lib = {
28
- createElement(type, props, ...children) {
29
- const el = document.createElement(type)
30
-
31
- for (const key in props) {
32
- if (key == 'class') {
33
- el.className = props[key]
34
- } else {
35
- el[key] = props[key]
36
- }
37
- }
38
-
39
- if (typeof children == 'string') {
40
- el.appendChild(document.createTextNode(children))
41
- } else if (Array.isArray(children)) {
42
- for (const child of children) {
43
- if (typeof child == 'string') {
44
- el.appendChild(document.createTextNode(child))
45
- } else if (isElement(child)) {
46
- el.appendChild(child)
47
- } else {
48
- console.error(child)
49
- const error = new Error(`invalid child ${children}`)
50
- error.child = child
51
- throw error
52
- }
53
- }
54
- } else if (isElement(children)) {
55
- el.appendChild(children)
56
- } else {
57
- console.error(children)
58
- const error = new Error(`invalid children ${children}`)
59
- error.children = children
60
- throw error
61
- }
62
-
63
- return el
64
- },
65
- }
66
-
67
- const LibElement = Arche(Lib)
68
-
69
- const Div = LibElement('div')
70
- const H1 = LibElement('h1')
71
- const P = LibElement('p')
72
- const Span = LibElement('span')
73
-
74
- const component1 = Div({
75
- id: 'component-1',
76
- class: 'a',
77
- }, [
78
- H1('Component 1'),
79
- P('test'),
80
- ])
81
-
82
- console.log('component1', component1)
83
-
84
- document.getElementById('dom-example').appendChild(component1)
85
-
86
- </script>
87
- </html>