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/.eslintrc.js +1 -4
- package/CONTRIBUTING.md +24 -0
- package/LICENSE +1 -1
- package/README.md +307 -114
- package/es.js +2 -2
- package/index.js +264 -128
- package/index.mjs +2 -2
- package/package.json +1 -1
- package/test.html +28 -10
- package/test.js +130 -4
- package/test-lib.html +0 -87
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Arche
|
|
2
|
+
* Arche v1.0.0
|
|
3
3
|
* https://github.com/richytong/arche
|
|
4
|
-
* (c)
|
|
4
|
+
* (c) 2026 Richard Tong
|
|
5
5
|
* Arche may be freely distributed under the MIT license.
|
|
6
6
|
*/
|
|
7
7
|
|
|
@@ -18,13 +18,11 @@ const isArray = Array.isArray
|
|
|
18
18
|
*
|
|
19
19
|
* @synopsis
|
|
20
20
|
* ```coffeescript [specscript]
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* var element Element,
|
|
21
|
+
* elementSetAttribute(
|
|
22
|
+
* element Element,
|
|
24
23
|
* key string,
|
|
25
|
-
* value string|number|
|
|
26
|
-
*
|
|
27
|
-
* elementSetAttribute(element, key, value) -> element
|
|
24
|
+
* value string|number|object
|
|
25
|
+
* ) -> element
|
|
28
26
|
* ```
|
|
29
27
|
*/
|
|
30
28
|
const elementSetAttribute = function (element, key, value) {
|
|
@@ -97,7 +95,7 @@ const memoizeCappedWithResolver = function (func, cap, resolver) {
|
|
|
97
95
|
* elementType string,
|
|
98
96
|
* props? object,
|
|
99
97
|
* children? Array<creator.Element>
|
|
100
|
-
* )=>creator.Element
|
|
98
|
+
* )=>(creatorElement creator.Element)
|
|
101
99
|
* }
|
|
102
100
|
*
|
|
103
101
|
* creatorCreateElement(
|
|
@@ -105,7 +103,7 @@ const memoizeCappedWithResolver = function (func, cap, resolver) {
|
|
|
105
103
|
* elementType string|function,
|
|
106
104
|
* propsOrTextOrChildren object|string|Array,
|
|
107
105
|
* textOrChildren string|Array,
|
|
108
|
-
* ) -> creator.Element
|
|
106
|
+
* ) -> creatorElement creator.Element
|
|
109
107
|
* ```
|
|
110
108
|
*/
|
|
111
109
|
function creatorCreateElement(
|
|
@@ -150,13 +148,12 @@ function creatorCreateElement(
|
|
|
150
148
|
* elementType string,
|
|
151
149
|
* props? object,
|
|
152
150
|
* children? Array<creator.Element>
|
|
153
|
-
* )=>creator.Element
|
|
151
|
+
* )=>(creatorElement creator.Element)
|
|
154
152
|
* },
|
|
155
153
|
* elementType string,
|
|
156
154
|
* propsOrTextOrChildren object|string|Array,
|
|
157
155
|
* textOrChildren string|Array,
|
|
158
|
-
* )
|
|
159
|
-
* -> creator.Element
|
|
156
|
+
* ) -> creatorElement creator.Element
|
|
160
157
|
* ```
|
|
161
158
|
*/
|
|
162
159
|
function CreatorElement(
|
|
@@ -220,15 +217,15 @@ function CreatorElement(
|
|
|
220
217
|
* elementType string,
|
|
221
218
|
* props? object,
|
|
222
219
|
* children? Array<creator.Element>
|
|
223
|
-
* )=>creator.Element
|
|
220
|
+
* )=>(creatorElement creator.Element)
|
|
224
221
|
* }
|
|
225
222
|
*
|
|
226
|
-
* __CreatorElement(creator elementType string) -> _Element
|
|
223
|
+
* __CreatorElement(creator elementType string) -> _Element
|
|
227
224
|
*
|
|
228
225
|
* _Element(
|
|
229
226
|
* propsOrTextOrChildren object|string|Array,
|
|
230
227
|
* textOrChildren string|Array,
|
|
231
|
-
* ) -> creator.Element
|
|
228
|
+
* ) -> creatorElement creator.Element
|
|
232
229
|
* ```
|
|
233
230
|
*/
|
|
234
231
|
function __CreatorElement(creator, elementType) {
|
|
@@ -254,10 +251,11 @@ function __CreatorElement(creator, elementType) {
|
|
|
254
251
|
* elementType string,
|
|
255
252
|
* props? object,
|
|
256
253
|
* children? Array<creator.Element>
|
|
257
|
-
* )=>creator.Element
|
|
254
|
+
* )=>(creatorElement creator.Element)
|
|
258
255
|
* }
|
|
259
256
|
*
|
|
260
|
-
* _CreatorElement(creator) -> _Element
|
|
257
|
+
* _CreatorElement(creator) -> _Element
|
|
258
|
+
* _Element(...args) -> creatorElement creator.Element
|
|
261
259
|
* ```
|
|
262
260
|
*/
|
|
263
261
|
function _CreatorElement(creator) {
|
|
@@ -279,7 +277,7 @@ function _CreatorElement(creator) {
|
|
|
279
277
|
* elementType string,
|
|
280
278
|
* props? object,
|
|
281
279
|
* children? Array<creator.Element>
|
|
282
|
-
* )=>creator.Element
|
|
280
|
+
* )=>(creatorElement creator.Element)
|
|
283
281
|
* }
|
|
284
282
|
*
|
|
285
283
|
* $__StyledCreatorElement(
|
|
@@ -288,14 +286,14 @@ function _CreatorElement(creator) {
|
|
|
288
286
|
* styled Styled,
|
|
289
287
|
* styledMemoizationCap number,
|
|
290
288
|
* }
|
|
291
|
-
* ) -> _StyledCreatorElement
|
|
289
|
+
* ) -> _StyledCreatorElement
|
|
292
290
|
*
|
|
293
|
-
* _StyledCreatorElement(elementType string) -> _StyledElement
|
|
291
|
+
* _StyledCreatorElement(elementType string) -> _StyledElement
|
|
294
292
|
*
|
|
295
293
|
* _StyledElement(
|
|
296
294
|
* propsOrTextOrChildren object|string|Array,
|
|
297
295
|
* textOrChildren string|Array,
|
|
298
|
-
* ) -> creator.Element
|
|
296
|
+
* ) -> creatorElement creator.Element
|
|
299
297
|
* ```
|
|
300
298
|
*/
|
|
301
299
|
function $__StyledCreatorElement(creator, options) {
|
|
@@ -387,7 +385,7 @@ function $__StyledCreatorElement(creator, options) {
|
|
|
387
385
|
* elementType string,
|
|
388
386
|
* props? object,
|
|
389
387
|
* children? Array<creator.Element>
|
|
390
|
-
* )=>creator.Element
|
|
388
|
+
* )=>(creatorElement creator.Element)
|
|
391
389
|
* }
|
|
392
390
|
*
|
|
393
391
|
* __assignElementNames(CreatorElement creator.Element) -> ()
|
|
@@ -399,6 +397,8 @@ function __assignElementNames(CreatorElement) {
|
|
|
399
397
|
CreatorElement.B = CreatorElement('b')
|
|
400
398
|
CreatorElement.Q = CreatorElement('q')
|
|
401
399
|
CreatorElement.I = CreatorElement('i')
|
|
400
|
+
CreatorElement.S = CreatorElement('s')
|
|
401
|
+
CreatorElement.U = CreatorElement('u')
|
|
402
402
|
CreatorElement.Ul = CreatorElement('ul')
|
|
403
403
|
CreatorElement.Ol = CreatorElement('ol')
|
|
404
404
|
CreatorElement.Li = CreatorElement('li')
|
|
@@ -413,8 +413,12 @@ function __assignElementNames(CreatorElement) {
|
|
|
413
413
|
CreatorElement.Br = CreatorElement('br')
|
|
414
414
|
|
|
415
415
|
CreatorElement.Script = CreatorElement('script')
|
|
416
|
+
CreatorElement.Style = CreatorElement('style')
|
|
417
|
+
|
|
416
418
|
CreatorElement.Html = CreatorElement('html')
|
|
419
|
+
CreatorElement.Main = CreatorElement('main')
|
|
417
420
|
CreatorElement.Body = CreatorElement('body')
|
|
421
|
+
CreatorElement.Header = CreatorElement('header')
|
|
418
422
|
CreatorElement.Nav = CreatorElement('nav')
|
|
419
423
|
CreatorElement.Section = CreatorElement('section')
|
|
420
424
|
CreatorElement.Article = CreatorElement('article')
|
|
@@ -423,6 +427,8 @@ function __assignElementNames(CreatorElement) {
|
|
|
423
427
|
CreatorElement.Div = CreatorElement('div')
|
|
424
428
|
CreatorElement.Img = CreatorElement('img')
|
|
425
429
|
CreatorElement.Video = CreatorElement('video')
|
|
430
|
+
CreatorElement.Picture = CreatorElement('picture')
|
|
431
|
+
CreatorElement.Source = CreatorElement('source')
|
|
426
432
|
|
|
427
433
|
CreatorElement.Form = CreatorElement('form')
|
|
428
434
|
CreatorElement.Fieldset = CreatorElement('fieldset')
|
|
@@ -437,133 +443,263 @@ function __assignElementNames(CreatorElement) {
|
|
|
437
443
|
CreatorElement.Blockquote = CreatorElement('blockquote')
|
|
438
444
|
CreatorElement.Code = CreatorElement('code')
|
|
439
445
|
CreatorElement.Pre = CreatorElement('pre')
|
|
446
|
+
|
|
447
|
+
CreatorElement.Polygon = CreatorElement('polygon')
|
|
448
|
+
CreatorElement.Svg = CreatorElement('svg')
|
|
449
|
+
CreatorElement.Path = CreatorElement('path')
|
|
450
|
+
CreatorElement.Rect = CreatorElement('rect')
|
|
451
|
+
CreatorElement.Mask = CreatorElement('mask')
|
|
452
|
+
|
|
453
|
+
CreatorElement.Dl = CreatorElement('dl')
|
|
454
|
+
CreatorElement.Dt = CreatorElement('dt')
|
|
455
|
+
CreatorElement.Dd = CreatorElement('dd')
|
|
456
|
+
|
|
440
457
|
}
|
|
441
458
|
|
|
442
459
|
/**
|
|
443
|
-
* @name
|
|
460
|
+
* @name DocumentElement
|
|
444
461
|
*
|
|
445
|
-
* @
|
|
462
|
+
* @docs
|
|
446
463
|
* ```coffeescript [specscript]
|
|
447
|
-
*
|
|
464
|
+
* type DocumentElementChildren = string|Array<string|Element>
|
|
448
465
|
*
|
|
449
|
-
* type
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
* element Element
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
466
|
+
* type TypedDocumentElement =
|
|
467
|
+
* (props object, children DocumentElementChildren)=>(element Element)
|
|
468
|
+
* |(children DocumentElementChildren)=>(element Element)
|
|
469
|
+
* |(props object)=>(element Element)
|
|
470
|
+
*
|
|
471
|
+
* DocumentElement(elementType string) -> TypedDocumentElement
|
|
472
|
+
* ```
|
|
473
|
+
*
|
|
474
|
+
* The `DocumentElement` constructor returned from `Arche(document)`. Constructs a `TypedDocumentElement` constructor.
|
|
475
|
+
*
|
|
476
|
+
* Arguments:
|
|
477
|
+
* * `elementType` - the name of the HTML element that the `TypedDocumentElement` constructor will represent.
|
|
478
|
+
*
|
|
479
|
+
* Return:
|
|
480
|
+
* * `TypedDocumentElement` - a DOM element constructor.
|
|
481
|
+
*
|
|
482
|
+
* ```javascript
|
|
483
|
+
* const DocumentElement = Arche(document)
|
|
484
|
+
*
|
|
485
|
+
* const H1 = DocumentElement('h1') // H1 is a DOM element constructor
|
|
486
|
+
* ```
|
|
487
|
+
*/
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* @name DocumentElement.{ELEMENT_NAME}
|
|
491
|
+
*
|
|
492
|
+
* @docs
|
|
493
|
+
* ```coffeescript [specscript]
|
|
494
|
+
* type DocumentElementChildren = string|Array<string|Element>
|
|
495
|
+
*
|
|
496
|
+
* type TypedDocumentElement =
|
|
497
|
+
* (props object, children DocumentElementChildren)=>(element Element)
|
|
498
|
+
* |(children DocumentElementChildren)=>(element Element)
|
|
499
|
+
* |(props object)=>(element Element)
|
|
500
|
+
*
|
|
501
|
+
* type DocumentElement = (elementType string)=>TypedDocumentElement
|
|
502
|
+
*
|
|
503
|
+
* DocumentElement.{ELEMENT_NAME} -> TypedDocumentElement
|
|
504
|
+
* ```
|
|
505
|
+
*
|
|
506
|
+
* The DocumentElement.{ELEMENT_NAME} constructor.
|
|
507
|
+
*
|
|
508
|
+
* Arguments:
|
|
509
|
+
* * `props` - an object of element properties. These are equivalent to [html attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes).
|
|
510
|
+
* * `children` - a string or array of strings and/or [elements](https://developer.mozilla.org/en-US/docs/Web/API/Element). Represents nesting elements in HTML.
|
|
511
|
+
*
|
|
512
|
+
* Return:
|
|
513
|
+
* * `element` - [`Element`](https://developer.mozilla.org/en-US/docs/Web/API/Element) - a basic [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model) element.
|
|
514
|
+
*
|
|
515
|
+
* ```javascript
|
|
516
|
+
* const DocumentElement = Arche(document)
|
|
517
|
+
* const my{ELEMENT_NAME} = DocumentElement.{ELEMENT_NAME}({CHILDREN})
|
|
518
|
+
* document.getElementById('#container').appendChild(my{ELEMENT_NAME})
|
|
519
|
+
* ```
|
|
520
|
+
*/
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* @name ReactElement
|
|
524
|
+
*
|
|
525
|
+
* @docs
|
|
526
|
+
* ```coffeescript [specscript]
|
|
527
|
+
* type React = {
|
|
528
|
+
* Element: {
|
|
529
|
+
* $$typeof: Symbol,
|
|
530
|
+
* props: Object,
|
|
531
|
+
* type: any,
|
|
532
|
+
* },
|
|
533
|
+
* createElement: (
|
|
534
|
+
* elementType string,
|
|
535
|
+
* props object,
|
|
536
|
+
* children string|Array<React.Element|string>
|
|
537
|
+
*
|
|
538
|
+
* )=>(reactElement React.Element),
|
|
487
539
|
* }
|
|
488
540
|
*
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
541
|
+
* type ReactElementChildren = string|Array<React.Element>
|
|
542
|
+
*
|
|
543
|
+
* type TypedReactElement =
|
|
544
|
+
* (props object, children ReactElementChildren)=>(reactElement React.Element)
|
|
545
|
+
* |(children ReactElementChildren)=>(reactElement React.Element)
|
|
546
|
+
* |(props object)=>(reactElement React.Element)
|
|
547
|
+
*
|
|
548
|
+
* type ReactElement =
|
|
549
|
+
* ReactFunctionComponent=>(reactElement React.Element)
|
|
550
|
+
* |(elementType string)=>TypedReactElement
|
|
551
|
+
*
|
|
552
|
+
* ReactElement(fn ReactFunctionComponent) -> reactElement React.Element
|
|
553
|
+
* ReactElement(elementType string) -> TypedReactElement
|
|
493
554
|
* ```
|
|
494
555
|
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
556
|
+
* The `ReactElement` constructor returned from `Arche(React)`. Constructs a `TypedReactElement` constructor.
|
|
557
|
+
*
|
|
558
|
+
* Arguments:
|
|
559
|
+
* * `elementType` - the name of the HTML element that the `TypedReactElement` constructor will represent.
|
|
497
560
|
*
|
|
498
|
-
*
|
|
561
|
+
* Return:
|
|
562
|
+
* * `TypedReactElement` - a React element constructor.
|
|
499
563
|
*
|
|
500
|
-
* ```javascript
|
|
564
|
+
* ```javascript
|
|
501
565
|
* const ReactElement = Arche(React)
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
* const { Div, H1, P } = ReactElement
|
|
505
|
-
* // some common building blocks are provided on ReactElement
|
|
506
|
-
* // as property functions.
|
|
507
|
-
*
|
|
508
|
-
* const myElement = Div([
|
|
509
|
-
* H1('I am a heading'),
|
|
510
|
-
* P('heyo'),
|
|
511
|
-
* P('lorem ipsum'),
|
|
512
|
-
* ])
|
|
513
|
-
*
|
|
514
|
-
* console.log(myElement)
|
|
515
|
-
* // {
|
|
516
|
-
* // $$typeof: Symbol(react.element),
|
|
517
|
-
* // type: 'div',
|
|
518
|
-
* // props: {
|
|
519
|
-
* // children: [
|
|
520
|
-
* // { $$typeof: Symbol(react.element), type: 'h1', props: { children: 'I am a heading' } },
|
|
521
|
-
* // { $$typeof: Symbol(react.element), type: 'p', props: { children: 'heyo' } },
|
|
522
|
-
* // { $$typeof: Symbol(react.element), type: 'p', props: { children: 'heyo' } },
|
|
523
|
-
* // ],
|
|
524
|
-
* // },
|
|
525
|
-
* // }
|
|
566
|
+
*
|
|
567
|
+
* const H1 = ReactElement('h1') // H1 is a React element constructor
|
|
526
568
|
* ```
|
|
569
|
+
*/
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* @name ReactElement.{ELEMENT_NAME}
|
|
527
573
|
*
|
|
528
|
-
*
|
|
529
|
-
* ```
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
574
|
+
* @docs
|
|
575
|
+
* ```coffeescript [specscript]
|
|
576
|
+
* type React = {
|
|
577
|
+
* Element: {
|
|
578
|
+
* $$typeof: Symbol,
|
|
579
|
+
* props: Object,
|
|
580
|
+
* type: any,
|
|
581
|
+
* },
|
|
582
|
+
* createElement: (
|
|
583
|
+
* elementType string,
|
|
584
|
+
* props object,
|
|
585
|
+
* children string|Array<React.Element|string>
|
|
586
|
+
*
|
|
587
|
+
* )=>(reactElement React.Element),
|
|
588
|
+
* }
|
|
589
|
+
*
|
|
590
|
+
* type ReactElementChildren = string|Array<React.Element>
|
|
591
|
+
*
|
|
592
|
+
* type TypedReactElement =
|
|
593
|
+
* (props object, children ReactElementChildren)=>(reactElement React.Element)
|
|
594
|
+
* |(children ReactElementChildren)=>(reactElement React.Element)
|
|
595
|
+
* |(props object)=>(reactElement React.Element)
|
|
596
|
+
*
|
|
597
|
+
* type ReactElement =
|
|
598
|
+
* ReactFunctionComponent=>(reactElement React.Element)
|
|
599
|
+
* |(elementType string)=>TypedReactElement
|
|
600
|
+
*
|
|
601
|
+
* ReactElement.{ELEMENT_NAME} -> TypedReactElement
|
|
539
602
|
* ```
|
|
540
603
|
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
604
|
+
* The ReactElement.{ELEMENT_NAME} constructor.
|
|
605
|
+
*
|
|
606
|
+
* Arguments:
|
|
607
|
+
* * `props` - an object of React element properties. These are equivalent to [React props](https://react.dev/learn/passing-props-to-a-component).
|
|
608
|
+
* * `children` - a string or array of strings and/or React elements. Represents nesting elements in HTML.
|
|
609
|
+
*
|
|
610
|
+
* Return:
|
|
611
|
+
* * `reactElement` - a basic React element, `reactElement` is recognized by React and used to render the final React application.
|
|
612
|
+
*
|
|
613
|
+
* ```javascript
|
|
543
614
|
* const ReactElement = Arche(React)
|
|
544
|
-
* const {
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
* const Example = ReactElement(() => {
|
|
548
|
-
* const [count, setCount] = useState(0)
|
|
549
|
-
*
|
|
550
|
-
* return Div([
|
|
551
|
-
* P(`You clicked ${count} times`),
|
|
552
|
-
* Button({
|
|
553
|
-
* onClick() {
|
|
554
|
-
* setCount(count + 1)
|
|
555
|
-
* },
|
|
556
|
-
* }, 'Click me'),
|
|
557
|
-
* ])
|
|
558
|
-
* })
|
|
615
|
+
* const myReact{ELEMENT_NAME} = ReactElement.{ELEMENT_NAME}({CHILDREN})
|
|
616
|
+
* ReactDOM.render(myReact{ELEMENT_NAME}, document.getElementById('react-root'))
|
|
559
617
|
* ```
|
|
560
618
|
*/
|
|
561
619
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
620
|
+
/**
|
|
621
|
+
* @name Arche
|
|
622
|
+
*
|
|
623
|
+
* @constructor
|
|
624
|
+
*
|
|
625
|
+
* @docs
|
|
626
|
+
* ```coffeescript [specscript]
|
|
627
|
+
* type DocumentElementChildren = string|Array<string|Element>
|
|
628
|
+
*
|
|
629
|
+
* type TypedDocumentElement =
|
|
630
|
+
* (props object, children DocumentElementChildren)=>(element Element)
|
|
631
|
+
* |(children DocumentElementChildren)=>(element Element)
|
|
632
|
+
* |(props object)=>(element Element)
|
|
633
|
+
*
|
|
634
|
+
* type DocumentElement = (elementType string)=>TypedDocumentElement
|
|
635
|
+
*
|
|
636
|
+
* type React = {
|
|
637
|
+
* Element: {
|
|
638
|
+
* $$typeof: Symbol,
|
|
639
|
+
* props: Object,
|
|
640
|
+
* type: any,
|
|
641
|
+
* },
|
|
642
|
+
* createElement: (
|
|
643
|
+
* elementType string,
|
|
644
|
+
* props object,
|
|
645
|
+
* children string|Array<React.Element|string>
|
|
646
|
+
* )=>(reactElement React.Element),
|
|
647
|
+
* }
|
|
648
|
+
*
|
|
649
|
+
* type ReactElementChildren = string|Array<React.Element>
|
|
650
|
+
*
|
|
651
|
+
* type TypedReactElement =
|
|
652
|
+
* (props object, children ReactElementChildren)=>(reactElement React.Element)
|
|
653
|
+
* |(children ReactElementChildren)=>(reactElement React.Element)
|
|
654
|
+
* |(props object)=>(reactElement React.Element)
|
|
655
|
+
*
|
|
656
|
+
* type ReactFunctionComponent =
|
|
657
|
+
* ({ ...props Object, children ReactElementChildren })=>(reactElement React.Element)
|
|
658
|
+
*
|
|
659
|
+
* type ReactElement =
|
|
660
|
+
* ReactFunctionComponent=>(reactElement React.Element)
|
|
661
|
+
* |(elementType string)=>TypedReactElement
|
|
662
|
+
*
|
|
663
|
+
* type StyledComponent = ([css string])=>React.Element
|
|
664
|
+
*
|
|
665
|
+
* type styled = Object<[elementName string]: StyledComponent>
|
|
666
|
+
*
|
|
667
|
+
* Arche(document Document) -> DocumentElement
|
|
668
|
+
* Arche(React) -> ReactElement
|
|
669
|
+
* Arche(React, options { styled }) -> ReactElement
|
|
670
|
+
* ```
|
|
671
|
+
*
|
|
672
|
+
* The Arche class. Simplified DOM interface / React in pure JavaScript.
|
|
673
|
+
*
|
|
674
|
+
* Arguments:
|
|
675
|
+
* * `document` - [`Document`](https://developer.mozilla.org/en-US/docs/Web/API/Document) - represents any web page loaded in the browser.
|
|
676
|
+
* * `React` - the [`React`](https://react.dev/) library.
|
|
677
|
+
* * `options`
|
|
678
|
+
* * `styled` - the [styled-components](https://styled-components.com/) library.
|
|
679
|
+
*
|
|
680
|
+
* Return:
|
|
681
|
+
* * `DocumentElement` - a simplified interface for the [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model)
|
|
682
|
+
* * `ReactElement` - a pure JavaScript interface for React.
|
|
683
|
+
*
|
|
684
|
+
* ```javascript
|
|
685
|
+
* {
|
|
686
|
+
* const DocumentElement = Arche(document)
|
|
687
|
+
* const H1 = DocumentElement('h1')
|
|
688
|
+
* const myH1Element = H1('Title')
|
|
689
|
+
* document.getElementById('#container').appendChild(myH1Element)
|
|
690
|
+
* }
|
|
691
|
+
*
|
|
692
|
+
* {
|
|
693
|
+
* const ReactElement = Arche(React)
|
|
694
|
+
* const H1 = ReactElement('he')
|
|
695
|
+
* const myH1ReactElement = H1('Title')
|
|
696
|
+
* ReactDOM.render(myH1ReactElement, document.getElementById('react-root'))
|
|
697
|
+
* }
|
|
698
|
+
* ```
|
|
699
|
+
*
|
|
700
|
+
*/
|
|
566
701
|
|
|
702
|
+
const Arche = function (creator, options = {}) {
|
|
567
703
|
if (creator == null) {
|
|
568
704
|
throw new TypeError('creator not defined')
|
|
569
705
|
}
|
package/index.mjs
CHANGED
package/package.json
CHANGED
package/test.html
CHANGED
|
@@ -13,15 +13,14 @@
|
|
|
13
13
|
|
|
14
14
|
<script>
|
|
15
15
|
const ReactElement = Arche(React)
|
|
16
|
-
const { Div, H1, P, Button, Img } = ReactElement
|
|
17
16
|
const { useState } = React
|
|
18
17
|
|
|
19
18
|
const ReactCounter = ReactElement(() => {
|
|
20
19
|
const [count, setCount] = useState(0)
|
|
21
|
-
return Div([
|
|
22
|
-
P('Success! - React Counter'),
|
|
23
|
-
P(`You clicked ${count} times`),
|
|
24
|
-
Button({
|
|
20
|
+
return ReactElement.Div([
|
|
21
|
+
ReactElement.P('Success! - React Counter'),
|
|
22
|
+
ReactElement.P(`You clicked ${count} times`),
|
|
23
|
+
ReactElement.Button({
|
|
25
24
|
onClick() {
|
|
26
25
|
setCount(count + 1)
|
|
27
26
|
},
|
|
@@ -37,13 +36,17 @@ ReactDOM.render(ReactCounter(), document.getElementById('react-counter'))
|
|
|
37
36
|
<script>
|
|
38
37
|
const UserCard = ReactElement(({
|
|
39
38
|
firstName, lastName, age,
|
|
40
|
-
}) => Div({ style: { border: '1px solid lightgrey' } }, [
|
|
41
|
-
P('Success! - React User Card'),
|
|
42
|
-
H1(`${firstName} ${lastName}`),
|
|
43
|
-
Img({ src: 'https://placehold.co/300', alt: 'placeholder' }),
|
|
44
|
-
P({ style: { color: 'lightgrey' } }, `age: ${age}`),
|
|
39
|
+
}) => ReactElement.Div({ style: { border: '1px solid lightgrey' } }, [
|
|
40
|
+
ReactElement.P('Success! - React User Card'),
|
|
41
|
+
ReactElement.H1(`${firstName} ${lastName}`),
|
|
42
|
+
ReactElement.Img({ src: 'https://placehold.co/300', alt: 'placeholder' }),
|
|
43
|
+
ReactElement.P({ style: { color: 'lightgrey' } }, `age: ${age}`),
|
|
45
44
|
]))
|
|
46
45
|
|
|
46
|
+
console.log(
|
|
47
|
+
UserCard({ firstName: 'George', lastName: 'Henry', age: 32 }),
|
|
48
|
+
)
|
|
49
|
+
|
|
47
50
|
ReactDOM.render(
|
|
48
51
|
UserCard({ firstName: 'George', lastName: 'Henry', age: 32 }),
|
|
49
52
|
document.getElementById('user-card')
|
|
@@ -97,6 +100,21 @@ ReactDOM.render(
|
|
|
97
100
|
console.log(styled)
|
|
98
101
|
</script>
|
|
99
102
|
|
|
103
|
+
<div id="my-container"></div>
|
|
104
|
+
|
|
105
|
+
<script>
|
|
106
|
+
const DocumentElement = Arche()
|
|
107
|
+
|
|
108
|
+
const myElement = DocumentElement.Div({ id: 'my-element' }, [
|
|
109
|
+
DocumentElement.P('Success! - Docs container example'),
|
|
110
|
+
DocumentElement.H1('I am a heading'),
|
|
111
|
+
DocumentElement.P('paragraph'),
|
|
112
|
+
DocumentElement.P('lorem ipsum'),
|
|
113
|
+
])
|
|
114
|
+
|
|
115
|
+
document.getElementById('my-container').appendChild(myElement)
|
|
116
|
+
</script>
|
|
117
|
+
|
|
100
118
|
</body>
|
|
101
119
|
<script>
|
|
102
120
|
</script>
|