1
1
import React , { createElement } from 'react' ;
2
- import { View , Text , Button } from 'react-native' ;
2
+ import { View , Text , Button , txtInput , StyleSheet } from 'react-native' ;
3
3
4
4
let textNode = 1 ,
5
5
elementNode = 2 ,
@@ -12,84 +12,92 @@ let styleData = 1,
12
12
attributeData = 4 ,
13
13
keyData = 7 ;
14
14
15
- export function createElementNode ( tag ) {
16
- return function ( nodeData ) {
17
- return function ( potentialChildren ) {
18
- let children = potentialChildren ,
19
- text = undefined ;
20
-
21
- if ( potentialChildren . length === 1 && potentialChildren [ 0 ] . nodeType == textNode ) {
22
- children = undefined ;
23
- text = potentialChildren [ 0 ] . text ;
24
- }
25
-
26
- return {
27
- nodeType : elementNode ,
28
- node : undefined ,
29
- tag : tag ,
30
- nodeData : fromNodeData ( nodeData ) ,
31
- children : children ,
32
- text : text
33
- } ;
34
- } ;
35
- } ;
36
- }
37
15
38
16
export function createViewNode ( nodeData ) {
39
17
return function ( children ) {
40
18
let props = fromNodeData ( nodeData )
41
19
42
- return createElement ( View , undefined , ...children ) ;
20
+ return createElement ( View , props , ...children ) ;
43
21
} ;
44
22
}
45
23
46
24
export function createButtonNode ( nodeData ) {
47
- return function ( text ) {
25
+ return function ( children ) {
48
26
let props = fromNodeData ( nodeData )
49
27
50
- return createElement ( Button , { title : text , ...props } ) ;
28
+ return createElement ( Button , { title : children [ 0 ] , ...props } ) ;
51
29
}
52
30
}
53
31
54
- export function createDatalessElementNode ( tag ) {
55
- return function ( potentialChildren ) {
56
- let children = potentialChildren ,
57
- text = undefined ;
32
+ let initialHrStyle = {
33
+ borderBottomColor : 'black' ,
34
+ borderBottomWidth : StyleSheet . hairlineWidth ,
35
+ } ;
58
36
59
- if ( potentialChildren . length === 1 && potentialChildren [ 0 ] . nodeType == textNode ) {
60
- children = undefined ;
61
- text = potentialChildren [ 0 ] . text ;
62
- }
37
+ export function createHrNode ( nodeData ) {
38
+ let props = fromNodeData ( nodeData ) ;
63
39
64
- return {
65
- nodeType : elementNode ,
66
- node : undefined ,
67
- tag : tag ,
68
- nodeData : { } ,
69
- children : children ,
70
- text : text
71
- } ;
72
- } ;
40
+ if ( props . style === undefined )
41
+ props . style = { ...initialHrStyle } ;
42
+ else {
43
+ props . style = { ...initialHrStyle , ...props . style } ;
44
+ }
45
+
46
+ return createViewNode ( nodeData ) ( undefined ) ;
73
47
}
74
48
75
- export function createSingleElementNode ( tag ) {
76
- return function ( nodeData ) {
77
- return {
78
- nodeType : elementNode ,
79
- node : undefined ,
80
- tag : tag ,
81
- nodeData : fromNodeData ( nodeData )
82
- } ;
83
- } ;
49
+ export function createBrNode ( nodeData ) {
50
+ let txt = text ( '\n' ) ;
51
+ txt . props = fromNodeData ( nodeData ) ;
52
+
53
+ return txt ;
84
54
}
85
55
86
- export function createEmptyElement ( tag ) {
87
- return {
88
- nodeType : tag . trim ( ) . toLowerCase ( ) === 'svg' ? svgNode : elementNode ,
89
- node : undefined ,
90
- tag : tag ,
91
- nodeData : { }
92
- } ;
56
+ export function createInputNode ( nodeData ) {
57
+ return createElement ( txtInput , fromNodeData ( nodeData ) ) ;
58
+ }
59
+
60
+ export function createANode ( nodeData ) {
61
+ return function ( children ) {
62
+ let props = fromNodeData ( nodeData ) ,
63
+ propedChildren = [ ] ;
64
+
65
+ for ( let c of children ) {
66
+ let txt = text ( c ) ;
67
+ txt . props = props ;
68
+
69
+ propedChildren . push ( txt ) ;
70
+ }
71
+
72
+ return createViewNode ( undefined ) ( propedChildren ) ;
73
+ }
74
+ }
75
+
76
+ let initialBStyle = {
77
+ fontWeight : 'bold'
78
+ } ;
79
+
80
+ export function createBNode ( nodeData ) {
81
+ return function ( children ) {
82
+ let props = fromNodeData ( nodeData ) ;
83
+
84
+ if ( props . style === undefined )
85
+ props . style = { ...initialBStyle } ;
86
+ else {
87
+ props . style = { ...initialBStyle , ...props . style } ;
88
+ }
89
+
90
+ let propedChildren = [ ] ;
91
+
92
+ for ( let c of children ) {
93
+ let txt = text ( c ) ;
94
+ txt . props = props ;
95
+
96
+ propedChildren . push ( txt ) ;
97
+ }
98
+
99
+ return createViewNode ( undefined ) ( propedChildren ) ;
100
+ }
93
101
}
94
102
95
103
export function text ( value ) {
0 commit comments