arche 0.3.11 → 1.0.1
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 +134 -188
- package/es.js +268 -128
- package/index.js +268 -128
- package/index.mjs +268 -128
- package/package.json +1 -1
- package/test.html +28 -10
- package/test.js +130 -4
- package/test-lib.html +0 -87
package/.eslintrc.js
CHANGED
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
## Steps to release
|
|
4
|
+
|
|
5
|
+
1. Bump the repo version
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm version patch|minor|major
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
2. Copy everything in the scope starting with 'use strict' in `index.js` to `es.js` and `index.mjs`
|
|
12
|
+
|
|
13
|
+
3. Manually update the code versions and year
|
|
14
|
+
|
|
15
|
+
4. Commit the changes
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
git commit -m "distribute"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
5. Publish the new version
|
|
22
|
+
```
|
|
23
|
+
npm publish
|
|
24
|
+
```
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,56 +1,112 @@
|
|
|
1
1
|
# Arche
|
|
2
2
|

|
|
3
|
-
> Arche (/ˈɑːrki/; Ancient Greek: ἀρχή) is a Greek word with primary senses "beginning", "origin" or "source of action" (ἐξ' ἀρχῆς: from the beginning, οr ἐξ' ἀρχῆς λόγος: the original argument), and later "first principle" or "element".
|
|
3
|
+
> Arche (/ˈɑːrki/; Ancient Greek: ἀρχή) is a Greek word with primary senses "beginning", "origin" or "source of action" (ἐξ' ἀρχῆς: from the beginning, οr ἐξ' ἀρχῆς λόγος: the original argument), and later "first principle" or "element".
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
[](https://codecov.io/gh/richytong/arche)
|
|
7
|
+
[](https://www.npmjs.com/package/arche)
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
Simplified DOM interface / React in pure JavaScript.
|
|
9
10
|
|
|
10
11
|
```javascript [playground]
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
{
|
|
13
|
+
const DocumentElement = Arche(document)
|
|
14
|
+
const { Div, H1, P } = DocumentElement
|
|
15
|
+
|
|
16
|
+
const myElement = Div({ id: 'my-element' }, [
|
|
17
|
+
H1('DOM Example'),
|
|
18
|
+
P('paragraph'),
|
|
19
|
+
P('lorem ipsum'),
|
|
20
|
+
])
|
|
13
21
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
H1
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
document.getElementById('dom-container').appendChild(myElement)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
{
|
|
26
|
+
const ReactElement = Arche(React)
|
|
27
|
+
const { Div, H1, P, Button, Img } = ReactElement
|
|
28
|
+
|
|
29
|
+
const UserCard = ReactElement(({
|
|
30
|
+
firstName, lastName, age,
|
|
31
|
+
}) => Div([
|
|
32
|
+
H1(`${firstName} ${lastName}`),
|
|
33
|
+
Img({ src: 'https://placehold.co/300x300', alt: 'placeholder' }),
|
|
34
|
+
P({ style: { color: 'lightgrey' } }, `age: ${age}`),
|
|
35
|
+
]))
|
|
36
|
+
|
|
37
|
+
ReactDOM.render(
|
|
38
|
+
UserCard({ firstName: 'React', lastName: 'ExampleUser', age: 32 }),
|
|
39
|
+
document.getElementById('react-root')
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
with `npm`
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm i arche
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
with browser script, sets `window.Arche`
|
|
52
|
+
|
|
53
|
+
```html
|
|
54
|
+
<script src="https://unpkg.com/arche"></script>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
with [ES Modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
|
|
58
|
+
```javascript
|
|
59
|
+
import Arche from 'https://unpkg.com/arche/es.js'
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Set `DocumentElement` globally for a better developer experience.
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
// global.js
|
|
66
|
+
const DocumentElement = Arche()
|
|
67
|
+
|
|
68
|
+
window.DocumentElement = DocumentElement
|
|
69
|
+
|
|
70
|
+
for (const elementName in DocumentElement) {
|
|
71
|
+
window[elementName] = DocumentElement[elementName]
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// set missing elements
|
|
75
|
+
window.Aside = DocumentElement('aside')
|
|
76
|
+
window.Svg = DocumentElement('svg')
|
|
77
|
+
window.Path = DocumentElement('path')
|
|
30
78
|
```
|
|
31
79
|
|
|
32
|
-
|
|
80
|
+
## Using React
|
|
81
|
+
To use Arche with [React](https://react.dev/), simply provide the React library.
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
const ReactElement = Arche(React)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Create dynamic components with props.
|
|
88
|
+
|
|
33
89
|
```javascript [playground]
|
|
34
90
|
const ReactElement = Arche(React)
|
|
91
|
+
|
|
35
92
|
const { Div, H1, P, Button, Img } = ReactElement
|
|
36
93
|
|
|
37
94
|
const UserCard = ReactElement(({
|
|
38
95
|
firstName, lastName, age,
|
|
39
96
|
}) => Div([
|
|
40
97
|
H1(`${firstName} ${lastName}`),
|
|
41
|
-
Img({ src: 'https://
|
|
98
|
+
Img({ src: 'https://placehold.co/300x300', alt: 'placeholder' }),
|
|
42
99
|
P({ style: { color: 'lightgrey' } }, `age: ${age}`),
|
|
43
100
|
]))
|
|
44
101
|
|
|
45
|
-
render(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// <p style="color: lightgrey">age: 32</p>
|
|
50
|
-
// </div>
|
|
102
|
+
ReactDOM.render(
|
|
103
|
+
UserCard({ firstName: 'Example', lastName: 'Name', age: 32 }),
|
|
104
|
+
document.getElementById('react-root')
|
|
105
|
+
)
|
|
51
106
|
```
|
|
52
107
|
|
|
53
|
-
Complete interoperability with React hooks (converted from [this example](https://reactjs.org/docs/hooks-intro.html))
|
|
108
|
+
Complete interoperability with React hooks (converted from [this example](https://reactjs.org/docs/hooks-intro.html)).
|
|
109
|
+
|
|
54
110
|
```javascript [playground]
|
|
55
111
|
const ReactElement = Arche(React)
|
|
56
112
|
const { Div, P, Button } = ReactElement
|
|
@@ -69,35 +125,13 @@ const Example = ReactElement(() => {
|
|
|
69
125
|
])
|
|
70
126
|
})
|
|
71
127
|
|
|
72
|
-
render(Example())
|
|
73
|
-
// <div>
|
|
74
|
-
// <p>You clicked {count} times</p>
|
|
75
|
-
// <button onclick="setCount(count + 1)">Click me</button>
|
|
76
|
-
// </div>
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Installation
|
|
80
|
-
with `npm`
|
|
81
|
-
```bash
|
|
82
|
-
npm i arche
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
browser script, global `Arche`
|
|
86
|
-
```html
|
|
87
|
-
<script src="https://unpkg.com/arche"></script>
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
browser module
|
|
91
|
-
```javascript
|
|
92
|
-
import Arche from 'https://unpkg.com/arche/es.js'
|
|
128
|
+
ReactDOM.render(Example(), document.getElementById('react-root'))
|
|
93
129
|
```
|
|
94
130
|
|
|
95
|
-
|
|
96
|
-
Set Arche elements globally for a better developer experience.
|
|
131
|
+
Set `ReactElement` globally for a better developer experience.
|
|
97
132
|
|
|
98
133
|
```javascript
|
|
99
134
|
// global.js
|
|
100
|
-
|
|
101
135
|
const ReactElement = Arche(React)
|
|
102
136
|
|
|
103
137
|
window.ReactElement = ReactElement
|
|
@@ -106,146 +140,12 @@ for (const elementName in ReactElement) {
|
|
|
106
140
|
window[elementName] = ReactElement[elementName]
|
|
107
141
|
}
|
|
108
142
|
|
|
109
|
-
//
|
|
110
|
-
// create the ones you need like so
|
|
143
|
+
// set missing elements
|
|
111
144
|
window.Aside = ReactElement('aside')
|
|
112
145
|
window.Svg = ReactElement('svg')
|
|
113
146
|
window.Path = ReactElement('path')
|
|
114
147
|
```
|
|
115
148
|
|
|
116
|
-
## Syntax
|
|
117
|
-
```coffeescript [specscript]
|
|
118
|
-
Arche() -> DocumentElement
|
|
119
|
-
Arche(document Document) -> DocumentElement
|
|
120
|
-
|
|
121
|
-
DocumentElement(elementType string) -> Element
|
|
122
|
-
DocumentElement(elementType string, props object, text string) -> Element
|
|
123
|
-
|
|
124
|
-
Arche(React {
|
|
125
|
-
createElement: (
|
|
126
|
-
elementType string,
|
|
127
|
-
props? object,
|
|
128
|
-
children? string|Array<React.Element|string>
|
|
129
|
-
)=>ReactElement
|
|
130
|
-
}) -> ReactElement
|
|
131
|
-
|
|
132
|
-
ReactElement(elementType string, props object, text string) -> React.Element
|
|
133
|
-
|
|
134
|
-
ReactElement(
|
|
135
|
-
elementType string,
|
|
136
|
-
props object,
|
|
137
|
-
children Array<React.Element|string>
|
|
138
|
-
) -> React.Element
|
|
139
|
-
|
|
140
|
-
ReactElement(elementType string) -> TypedReactElement function
|
|
141
|
-
|
|
142
|
-
TypedReactElement(props object, text string) -> React.Element
|
|
143
|
-
TypedReactElement(text string)-> React.Element
|
|
144
|
-
TypedReactElement(children Array<React.Element|string>)-> React.Element
|
|
145
|
-
|
|
146
|
-
ReactElement.A -> TypedReactElement
|
|
147
|
-
ReactElement.P -> TypedReactElement
|
|
148
|
-
ReactElement.B -> TypedReactElement
|
|
149
|
-
ReactElement.Q -> TypedReactElement
|
|
150
|
-
ReactElement.I -> TypedReactElement
|
|
151
|
-
ReactElement.Ul -> TypedReactElement
|
|
152
|
-
ReactElement.Ol -> TypedReactElement
|
|
153
|
-
ReactElement.Li -> TypedReactElement
|
|
154
|
-
ReactElement.H1 -> TypedReactElement
|
|
155
|
-
ReactElement.H2 -> TypedReactElement
|
|
156
|
-
ReactElement.H3 -> TypedReactElement
|
|
157
|
-
ReactElement.H4 -> TypedReactElement
|
|
158
|
-
ReactElement.H5 -> TypedReactElement
|
|
159
|
-
ReactElement.H6 -> TypedReactElement
|
|
160
|
-
ReactElement.Hr -> TypedReactElement
|
|
161
|
-
ReactElement.Br -> TypedReactElement
|
|
162
|
-
ReactElement.Script -> TypedReactElement
|
|
163
|
-
ReactElement.Html -> TypedReactElement
|
|
164
|
-
ReactElement.Body -> TypedReactElement
|
|
165
|
-
ReactElement.Nav -> TypedReactElement
|
|
166
|
-
ReactElement.Section -> TypedReactElement
|
|
167
|
-
ReactElement.Article -> TypedReactElement
|
|
168
|
-
ReactElement.Footer -> TypedReactElement
|
|
169
|
-
ReactElement.Span -> TypedReactElement
|
|
170
|
-
ReactElement.Div -> TypedReactElement
|
|
171
|
-
ReactElement.Img -> TypedReactElement
|
|
172
|
-
ReactElement.Video -> TypedReactElement
|
|
173
|
-
ReactElement.Form -> TypedReactElement
|
|
174
|
-
ReactElement.Fieldset -> TypedReactElement
|
|
175
|
-
ReactElement.Input -> TypedReactElement
|
|
176
|
-
ReactElement.Label -> TypedReactElement
|
|
177
|
-
ReactElement.Textarea -> TypedReactElement
|
|
178
|
-
ReactElement.Select -> TypedReactElement
|
|
179
|
-
ReactElement.Option -> TypedReactElement
|
|
180
|
-
ReactElement.Button -> TypedReactElement
|
|
181
|
-
ReactElement.Iframe -> TypedReactElement
|
|
182
|
-
ReactElement.Blockquote -> TypedReactElement
|
|
183
|
-
ReactElement.Code -> TypedReactElement
|
|
184
|
-
ReactElement.Pre -> TypedReactElement
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
## Using styled
|
|
188
|
-
Arche accepts a `styled` option from css-in-js libraries like [Styled Components](https://styled-components.com/) to enable a `css` prop on the base elements. This does not apply to composite components (those created with `ReactElement(props => {...})` syntax)
|
|
189
|
-
|
|
190
|
-
```javascript
|
|
191
|
-
// global.js
|
|
192
|
-
const ReactElement = Arche(React, { styled })
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
Elements can now specify a `css` prop to use css-in-js.
|
|
196
|
-
|
|
197
|
-
```javascript
|
|
198
|
-
// MyComponent.js
|
|
199
|
-
const MyComponent = ReactElement(props => {
|
|
200
|
-
return Div({
|
|
201
|
-
css: `
|
|
202
|
-
width: 500px;
|
|
203
|
-
background-color: pink;
|
|
204
|
-
`,
|
|
205
|
-
})
|
|
206
|
-
})
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
## Syntax with styled
|
|
210
|
-
```coffeescript [specscript]
|
|
211
|
-
strings Array<string>
|
|
212
|
-
values Array<any>
|
|
213
|
-
tagFunctionArgs Array<strings, ...values>
|
|
214
|
-
|
|
215
|
-
type Styled = {
|
|
216
|
-
h1: (...tagFunctionArgs)=>React.Element,
|
|
217
|
-
h2: (...tagFunctionArgs)=>React.Element,
|
|
218
|
-
h3: (...tagFunctionArgs)=>React.Element,
|
|
219
|
-
h4: (...tagFunctionArgs)=>React.Element,
|
|
220
|
-
h5: (...tagFunctionArgs)=>React.Element,
|
|
221
|
-
div: (...tagFunctionArgs)=>React.Element,
|
|
222
|
-
button: (...tagFunctionArgs)=>React.Element,
|
|
223
|
-
a: (...tagFunctionArgs)=>React.Element,
|
|
224
|
-
p: (...tagFunctionArgs)=>React.Element,
|
|
225
|
-
span: (...tagFunctionArgs)=>React.Element,
|
|
226
|
-
img: (...tagFunctionArgs)=>React.Element,
|
|
227
|
-
ul: (...tagFunctionArgs)=>React.Element,
|
|
228
|
-
ol: (...tagFunctionArgs)=>React.Element,
|
|
229
|
-
li: (...tagFunctionArgs)=>React.Element,
|
|
230
|
-
form: (...tagFunctionArgs)=>React.Element,
|
|
231
|
-
article: (...tagFunctionArgs)=>React.Element,
|
|
232
|
-
main: (...tagFunctionArgs)=>React.Element,
|
|
233
|
-
section: (...tagFunctionArgs)=>React.Element,
|
|
234
|
-
nav: (...tagFunctionArgs)=>React.Element,
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
Arche(React {
|
|
238
|
-
createElement: (
|
|
239
|
-
elementType string,
|
|
240
|
-
props? object,
|
|
241
|
-
children? string|Array<React.Element|string>,
|
|
242
|
-
)=>ReactElement
|
|
243
|
-
}, options {
|
|
244
|
-
styled: Styled,
|
|
245
|
-
styledMemoizationCap?: number
|
|
246
|
-
}) -> ReactElement
|
|
247
|
-
```
|
|
248
|
-
|
|
249
149
|
## Using React Context
|
|
250
150
|
To use React Context with Arche, wrap `YourContext.Provider` with `ReactElement` and supply `value` as a prop, specifying children in the next argument.
|
|
251
151
|
|
|
@@ -276,3 +176,49 @@ const ArticleWrapper = ReactElement(() => {
|
|
|
276
176
|
}, [ThemeSwitcher(), Article()])
|
|
277
177
|
})
|
|
278
178
|
```
|
|
179
|
+
|
|
180
|
+
## Using styled
|
|
181
|
+
Arche accepts a `styled` option from css-in-js libraries like [Styled Components](https://styled-components.com/) to enable a `css` prop on `ReactElement` and `TypedReactElement`.
|
|
182
|
+
|
|
183
|
+
```javascript
|
|
184
|
+
const ReactElement = Arche(React, { styled })
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Elements can now specify a `css` prop to use css-in-js.
|
|
188
|
+
|
|
189
|
+
```javascript [playground]
|
|
190
|
+
const ReactElement = Arche(React, { styled })
|
|
191
|
+
const { Div, H1, P } = ReactElement
|
|
192
|
+
|
|
193
|
+
const MyComponent = ReactElement(() => {
|
|
194
|
+
return Div({
|
|
195
|
+
css: `
|
|
196
|
+
height: 500px;
|
|
197
|
+
width: 100%;
|
|
198
|
+
background-color: pink;
|
|
199
|
+
`,
|
|
200
|
+
}, [
|
|
201
|
+
H1('Styled Example'),
|
|
202
|
+
P('Text'),
|
|
203
|
+
])
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
ReactDOM.render(MyComponent(), document.getElementById('react-root'))
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
# Contributing
|
|
210
|
+
Your feedback and contributions are welcome. If you have a suggestion, please raise an issue. Prior to that, please search through the issues first in case your suggestion has been made already. If you decide to work on an issue, please create a pull request.
|
|
211
|
+
|
|
212
|
+
Pull requests should provide some basic context and link the relevant issue. If you are interested in contributing, the [help wanted](https://github.com/richytong/arche/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) tag is a good place to start.
|
|
213
|
+
|
|
214
|
+
For more information please see [CONTRIBUTING.md](https://github.com/richytong/arche/blob/master/CONTRIBUTING.md)
|
|
215
|
+
|
|
216
|
+
# License
|
|
217
|
+
Arche is [MIT Licensed](https://github.com/a-synchronous/rubico/blob/master/LICENSE).
|
|
218
|
+
|
|
219
|
+
# Support
|
|
220
|
+
* minimum Node.js version: 14
|
|
221
|
+
* minimum Chrome version: 63
|
|
222
|
+
* minimum Firefox version: 57
|
|
223
|
+
* minimum Edge version: 79
|
|
224
|
+
* minimum Safari version: 11.1
|