arche 0.2.5 → 0.3.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/CHANGELOG.md +13 -1
- package/es.js +51 -3
- package/index.js +52 -3
- package/index.mjs +51 -3
- package/package.json +1 -1
- package/test.js +55 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
## v0.
|
|
1
|
+
## v0.3.0
|
|
2
|
+
* styled option enables the css parameter
|
|
3
|
+
|
|
4
|
+
## v0.2.5
|
|
5
|
+
* mjs export
|
|
6
|
+
|
|
7
|
+
## v0.2.2
|
|
8
|
+
* React Context Support
|
|
9
|
+
|
|
10
|
+
## v0.2.0
|
|
11
|
+
* Element shorthands
|
|
12
|
+
|
|
13
|
+
## v0.1.0
|
|
2
14
|
* First release with proof of concept at [rubico.land](https://rubico.land/)
|
package/es.js
CHANGED
|
@@ -114,7 +114,9 @@ const creatorCreateElement = function (creator, type, props, children) {
|
|
|
114
114
|
* Pre: (props, children?)|children)=>element,
|
|
115
115
|
* }
|
|
116
116
|
*
|
|
117
|
-
* Arche(creator
|
|
117
|
+
* Arche(creator, options {
|
|
118
|
+
* styled?: Styled,
|
|
119
|
+
* }) -> rootElement
|
|
118
120
|
* ```
|
|
119
121
|
*
|
|
120
122
|
* @description
|
|
@@ -184,23 +186,69 @@ const creatorCreateElement = function (creator, type, props, children) {
|
|
|
184
186
|
* ```
|
|
185
187
|
*/
|
|
186
188
|
|
|
187
|
-
const Arche = function (creator) {
|
|
188
|
-
const
|
|
189
|
+
const Arche = function (creator, options = {}) {
|
|
190
|
+
const { styled } = options
|
|
191
|
+
|
|
192
|
+
const originalRootElement = type => function creatingElement(arg0, arg1) {
|
|
189
193
|
if (isArray(arg0)) {
|
|
190
194
|
return creatorCreateElement(creator, type, {}, arg0)
|
|
191
195
|
}
|
|
196
|
+
|
|
192
197
|
if (typeof arg0 == 'string') {
|
|
193
198
|
return creatorCreateElement(creator, type, {}, [arg0])
|
|
194
199
|
}
|
|
200
|
+
|
|
195
201
|
if (isArray(arg1)) {
|
|
196
202
|
return creatorCreateElement(creator, type, arg0, arg1)
|
|
197
203
|
}
|
|
204
|
+
|
|
198
205
|
if (arg1 == null) {
|
|
199
206
|
return creatorCreateElement(creator, type, arg0, [])
|
|
200
207
|
}
|
|
208
|
+
|
|
201
209
|
return creatorCreateElement(creator, type, arg0, [arg1])
|
|
202
210
|
}
|
|
203
211
|
|
|
212
|
+
const styledRootElement = type => function creatingStyledElement(arg0, arg1) {
|
|
213
|
+
if (isArray(arg0)) {
|
|
214
|
+
return creatorCreateElement(creator, type, {}, arg0)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (typeof arg0 == 'string') {
|
|
218
|
+
return creatorCreateElement(creator, type, {}, [arg0])
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (isArray(arg1)) {
|
|
222
|
+
if (arg0.css == null) {
|
|
223
|
+
return creatorCreateElement(creator, type, arg0, arg1)
|
|
224
|
+
}
|
|
225
|
+
const { css, ...props } = arg0
|
|
226
|
+
return creatorCreateElement(creator, styled[type](css), props, arg1)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (arg1 == null) {
|
|
230
|
+
if (arg0.css == null) {
|
|
231
|
+
return creatorCreateElement(creator, type, arg0, [])
|
|
232
|
+
}
|
|
233
|
+
const { css, ...props } = arg0
|
|
234
|
+
return creatorCreateElement(creator, styled[type](css), props, [])
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (arg0.css == null) {
|
|
238
|
+
return creatorCreateElement(creator, type, arg0, [arg1])
|
|
239
|
+
}
|
|
240
|
+
const { css, ...props } = arg0
|
|
241
|
+
return creatorCreateElement(creator, styled[type](css), props, [arg1])
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const rootElement = (
|
|
245
|
+
styled == null
|
|
246
|
+
? originalRootElement
|
|
247
|
+
: type => typeof type == 'string'
|
|
248
|
+
? styledRootElement(type)
|
|
249
|
+
: originalRootElement(type)
|
|
250
|
+
)
|
|
251
|
+
|
|
204
252
|
rootElement.A = rootElement('a')
|
|
205
253
|
rootElement.P = rootElement('p')
|
|
206
254
|
rootElement.B = rootElement('b')
|
package/index.js
CHANGED
|
@@ -120,7 +120,9 @@ const creatorCreateElement = function (creator, type, props, children) {
|
|
|
120
120
|
* Pre: (props, children?)|children)=>element,
|
|
121
121
|
* }
|
|
122
122
|
*
|
|
123
|
-
* Arche(creator
|
|
123
|
+
* Arche(creator, options {
|
|
124
|
+
* styled?: Styled,
|
|
125
|
+
* }) -> rootElement
|
|
124
126
|
* ```
|
|
125
127
|
*
|
|
126
128
|
* @description
|
|
@@ -190,23 +192,69 @@ const creatorCreateElement = function (creator, type, props, children) {
|
|
|
190
192
|
* ```
|
|
191
193
|
*/
|
|
192
194
|
|
|
193
|
-
const Arche = function (creator) {
|
|
194
|
-
const
|
|
195
|
+
const Arche = function (creator, options = {}) {
|
|
196
|
+
const { styled } = options
|
|
197
|
+
|
|
198
|
+
const originalRootElement = type => function creatingElement(arg0, arg1) {
|
|
195
199
|
if (isArray(arg0)) {
|
|
196
200
|
return creatorCreateElement(creator, type, {}, arg0)
|
|
197
201
|
}
|
|
202
|
+
|
|
198
203
|
if (typeof arg0 == 'string') {
|
|
199
204
|
return creatorCreateElement(creator, type, {}, [arg0])
|
|
200
205
|
}
|
|
206
|
+
|
|
201
207
|
if (isArray(arg1)) {
|
|
202
208
|
return creatorCreateElement(creator, type, arg0, arg1)
|
|
203
209
|
}
|
|
210
|
+
|
|
204
211
|
if (arg1 == null) {
|
|
205
212
|
return creatorCreateElement(creator, type, arg0, [])
|
|
206
213
|
}
|
|
214
|
+
|
|
207
215
|
return creatorCreateElement(creator, type, arg0, [arg1])
|
|
208
216
|
}
|
|
209
217
|
|
|
218
|
+
const styledRootElement = type => function creatingStyledElement(arg0, arg1) {
|
|
219
|
+
if (isArray(arg0)) {
|
|
220
|
+
return creatorCreateElement(creator, type, {}, arg0)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (typeof arg0 == 'string') {
|
|
224
|
+
return creatorCreateElement(creator, type, {}, [arg0])
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (isArray(arg1)) {
|
|
228
|
+
if (arg0.css == null) {
|
|
229
|
+
return creatorCreateElement(creator, type, arg0, arg1)
|
|
230
|
+
}
|
|
231
|
+
const { css, ...props } = arg0
|
|
232
|
+
return creatorCreateElement(creator, styled[type](css), props, arg1)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (arg1 == null) {
|
|
236
|
+
if (arg0.css == null) {
|
|
237
|
+
return creatorCreateElement(creator, type, arg0, [])
|
|
238
|
+
}
|
|
239
|
+
const { css, ...props } = arg0
|
|
240
|
+
return creatorCreateElement(creator, styled[type](css), props, [])
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (arg0.css == null) {
|
|
244
|
+
return creatorCreateElement(creator, type, arg0, [arg1])
|
|
245
|
+
}
|
|
246
|
+
const { css, ...props } = arg0
|
|
247
|
+
return creatorCreateElement(creator, styled[type](css), props, [arg1])
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const rootElement = (
|
|
251
|
+
styled == null
|
|
252
|
+
? originalRootElement
|
|
253
|
+
: type => typeof type == 'string'
|
|
254
|
+
? styledRootElement(type)
|
|
255
|
+
: originalRootElement(type)
|
|
256
|
+
)
|
|
257
|
+
|
|
210
258
|
rootElement.A = rootElement('a')
|
|
211
259
|
rootElement.P = rootElement('p')
|
|
212
260
|
rootElement.B = rootElement('b')
|
|
@@ -253,5 +301,6 @@ const Arche = function (creator) {
|
|
|
253
301
|
|
|
254
302
|
return rootElement
|
|
255
303
|
}
|
|
304
|
+
|
|
256
305
|
return Arche
|
|
257
306
|
}())))
|
package/index.mjs
CHANGED
|
@@ -114,7 +114,9 @@ const creatorCreateElement = function (creator, type, props, children) {
|
|
|
114
114
|
* Pre: (props, children?)|children)=>element,
|
|
115
115
|
* }
|
|
116
116
|
*
|
|
117
|
-
* Arche(creator
|
|
117
|
+
* Arche(creator, options {
|
|
118
|
+
* styled?: Styled,
|
|
119
|
+
* }) -> rootElement
|
|
118
120
|
* ```
|
|
119
121
|
*
|
|
120
122
|
* @description
|
|
@@ -184,23 +186,69 @@ const creatorCreateElement = function (creator, type, props, children) {
|
|
|
184
186
|
* ```
|
|
185
187
|
*/
|
|
186
188
|
|
|
187
|
-
const Arche = function (creator) {
|
|
188
|
-
const
|
|
189
|
+
const Arche = function (creator, options = {}) {
|
|
190
|
+
const { styled } = options
|
|
191
|
+
|
|
192
|
+
const originalRootElement = type => function creatingElement(arg0, arg1) {
|
|
189
193
|
if (isArray(arg0)) {
|
|
190
194
|
return creatorCreateElement(creator, type, {}, arg0)
|
|
191
195
|
}
|
|
196
|
+
|
|
192
197
|
if (typeof arg0 == 'string') {
|
|
193
198
|
return creatorCreateElement(creator, type, {}, [arg0])
|
|
194
199
|
}
|
|
200
|
+
|
|
195
201
|
if (isArray(arg1)) {
|
|
196
202
|
return creatorCreateElement(creator, type, arg0, arg1)
|
|
197
203
|
}
|
|
204
|
+
|
|
198
205
|
if (arg1 == null) {
|
|
199
206
|
return creatorCreateElement(creator, type, arg0, [])
|
|
200
207
|
}
|
|
208
|
+
|
|
201
209
|
return creatorCreateElement(creator, type, arg0, [arg1])
|
|
202
210
|
}
|
|
203
211
|
|
|
212
|
+
const styledRootElement = type => function creatingStyledElement(arg0, arg1) {
|
|
213
|
+
if (isArray(arg0)) {
|
|
214
|
+
return creatorCreateElement(creator, type, {}, arg0)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (typeof arg0 == 'string') {
|
|
218
|
+
return creatorCreateElement(creator, type, {}, [arg0])
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (isArray(arg1)) {
|
|
222
|
+
if (arg0.css == null) {
|
|
223
|
+
return creatorCreateElement(creator, type, arg0, arg1)
|
|
224
|
+
}
|
|
225
|
+
const { css, ...props } = arg0
|
|
226
|
+
return creatorCreateElement(creator, styled[type](css), props, arg1)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (arg1 == null) {
|
|
230
|
+
if (arg0.css == null) {
|
|
231
|
+
return creatorCreateElement(creator, type, arg0, [])
|
|
232
|
+
}
|
|
233
|
+
const { css, ...props } = arg0
|
|
234
|
+
return creatorCreateElement(creator, styled[type](css), props, [])
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (arg0.css == null) {
|
|
238
|
+
return creatorCreateElement(creator, type, arg0, [arg1])
|
|
239
|
+
}
|
|
240
|
+
const { css, ...props } = arg0
|
|
241
|
+
return creatorCreateElement(creator, styled[type](css), props, [arg1])
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const rootElement = (
|
|
245
|
+
styled == null
|
|
246
|
+
? originalRootElement
|
|
247
|
+
: type => typeof type == 'string'
|
|
248
|
+
? styledRootElement(type)
|
|
249
|
+
: originalRootElement(type)
|
|
250
|
+
)
|
|
251
|
+
|
|
204
252
|
rootElement.A = rootElement('a')
|
|
205
253
|
rootElement.P = rootElement('p')
|
|
206
254
|
rootElement.B = rootElement('b')
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -34,7 +34,7 @@ describe('Arche', () => {
|
|
|
34
34
|
Article('yo'),
|
|
35
35
|
]),
|
|
36
36
|
])
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
assert.strictEqual(
|
|
39
39
|
JSON.stringify(el),
|
|
40
40
|
'{"type":"div","children":[{"type":"h1","children":[{"type":"text","text":"header"}],"style":{}},{"type":"p","children":[{"type":"text","text":"description"}],"style":{"color":"grey"}},{"type":"span","children":[],"style":{},"id":"hey","excluded":null},{"type":"div","children":[{"type":"article","children":[{"type":"text","text":"yo"}],"style":{}}],"style":{},"id":"nested"}],"style":{}}')
|
|
@@ -59,10 +59,63 @@ describe('Arche', () => {
|
|
|
59
59
|
Article('yo'),
|
|
60
60
|
]),
|
|
61
61
|
])
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
assert.strictEqual(
|
|
64
64
|
JSON.stringify(el),
|
|
65
65
|
'["div",{},[["h1",{},["header"]],["p",{"style":{"color":"grey"}},["description"]],["span",{"id":"hey","excluded":null},[]],["div",{"id":"nested"},[["article",{},["yo"]]]]]]')
|
|
66
66
|
})
|
|
67
67
|
})
|
|
68
|
+
|
|
69
|
+
describe('styled 3-ary creator.createElement', () => {
|
|
70
|
+
const mockReact = {
|
|
71
|
+
createElement(type, props, ...children) {
|
|
72
|
+
return [type, props || {}, children || []]
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const identity = value => value
|
|
77
|
+
|
|
78
|
+
const styled = {
|
|
79
|
+
h1: identity,
|
|
80
|
+
h2: identity,
|
|
81
|
+
div: identity,
|
|
82
|
+
p: identity,
|
|
83
|
+
b: identity,
|
|
84
|
+
span: identity,
|
|
85
|
+
article: identity,
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const rootElement = Arche(mockReact, { styled })
|
|
89
|
+
const { Div, H1, P, Span, Article } = rootElement
|
|
90
|
+
|
|
91
|
+
it('tree structure 1', () => {
|
|
92
|
+
const el = Div([
|
|
93
|
+
H1({ css: 'h2' }, 'header'), // should swap with h2
|
|
94
|
+
P({ style: { color: 'grey' } }, 'description'),
|
|
95
|
+
Span({ id: 'hey', excluded: null }),
|
|
96
|
+
Div({ id: 'nested' }, [
|
|
97
|
+
Article('yo'),
|
|
98
|
+
]),
|
|
99
|
+
])
|
|
100
|
+
|
|
101
|
+
assert.strictEqual(
|
|
102
|
+
JSON.stringify(el),
|
|
103
|
+
'["div",{},[["h2",{},["header"]],["p",{"style":{"color":"grey"}},["description"]],["span",{"id":"hey","excluded":null},[]],["div",{"id":"nested"},[["article",{},["yo"]]]]]]')
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('tree structure 2', () => {
|
|
107
|
+
const el = Div([
|
|
108
|
+
H1('header'),
|
|
109
|
+
P({ css: 'h3', style: { color: 'grey' } }, 'description'),
|
|
110
|
+
Span({ css: 'b', id: 'hey', excluded: null }),
|
|
111
|
+
Div({ css: 'article', id: 'nested' }, [
|
|
112
|
+
Article('yo'),
|
|
113
|
+
]),
|
|
114
|
+
])
|
|
115
|
+
|
|
116
|
+
assert.strictEqual(
|
|
117
|
+
JSON.stringify(el),
|
|
118
|
+
'["div",{},[["h1",{},["header"]],["h3",{"style":{"color":"grey"}},["description"]],["b",{"id":"hey","excluded":null},[]],["article",{"id":"nested"},[["article",{},["yo"]]]]]]')
|
|
119
|
+
})
|
|
120
|
+
})
|
|
68
121
|
})
|