arche 0.3.2 → 0.3.5

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/README.md CHANGED
@@ -96,27 +96,57 @@ import Arche from 'https://unpkg.com/arche/es.js'
96
96
  ```coffeescript [specscript]
97
97
  Arche(React {
98
98
  createElement: (type, props?, children?)=>ReactElement,
99
+ }, options? {
100
+ styled?: {
101
+ div: function,
102
+ p: funcion,
103
+ span: function,
104
+ // etc
105
+ },
106
+ styledMemoizationCap?: number, // defaults to 1000
99
107
  }) -> ReactElement
100
108
  ```
101
109
 
102
110
  # Usage
111
+ Set Arche elements globally for a great developer experience.
103
112
  ```javascript
113
+ // global.js
114
+
104
115
  const ReactElement = Arche(React)
105
116
 
106
- const {
107
- A, P, B, Q, I, Ul, Ol, Li,
108
- H1, H2, H3, H4, H5, H6, Hr, Br,
109
- Script, Html, Body, Nav, Section, Article, Footer, Span, Div, Img, Video,
110
- Form, Fieldset, Input, Label, Textarea, Select, Option,
111
- Button, Iframe, Blockquote, Code, Pre,
112
- } = ReactElement
117
+ window.ReactElement = ReactElement
118
+
119
+ for (const elementName in ReactElement) {
120
+ window[elementName] = ReactElement[elementName]
121
+ }
122
+
123
+ // Arche for now does not export every element
124
+ // create the ones you need like so
125
+ window.Aside = ReactElement('aside')
126
+ window.Svg = ReactElement('svg')
127
+ window.Path = ReactElement('path')
113
128
  ```
114
129
 
115
- Don't see an element you need? Just create it!
116
- ```javascript [playground]
117
- const ReactElement = Arche(React)
130
+ ## Using styled
131
+ 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)
118
132
 
119
- const Aside = ReactElement('aside')
133
+ ```javascript
134
+ // global.js
135
+ const ReactElement = Arche(React, { styled })
136
+ ```
137
+
138
+ Elements can now specify a `css` prop to use css-in-js.
139
+
140
+ ```javascript
141
+ // MyComponent.js
142
+ const MyComponent = ReactElement(props => {
143
+ return Div({
144
+ css: `
145
+ width: 500px;
146
+ background-color: pink;
147
+ `,
148
+ })
149
+ })
120
150
  ```
121
151
 
122
152
  ## Using React Context
package/es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Arche v0.3.2
2
+ * Arche v0.3.5
3
3
  * https://github.com/richytong/arche
4
4
  * (c) 2020-2023 Richard Tong
5
5
  * Arche may be freely distributed under the MIT license.
@@ -264,7 +264,7 @@ const Arche = function (creator, options = {}) {
264
264
  }
265
265
 
266
266
  if (isArray(arg1)) {
267
- if (arg0.css == null) {
267
+ if (arg0 == null || arg0.css == null) {
268
268
  return creatorCreateElement(creator, type, arg0, arg1)
269
269
  }
270
270
  const { css, ...props } = arg0
@@ -272,14 +272,14 @@ const Arche = function (creator, options = {}) {
272
272
  }
273
273
 
274
274
  if (arg1 == null) {
275
- if (arg0.css == null) {
275
+ if (arg0 == null || arg0.css == null) {
276
276
  return creatorCreateElement(creator, type, arg0, [])
277
277
  }
278
278
  const { css, ...props } = arg0
279
279
  return creatorCreateElement(creator, styledComponent([css]), props, [])
280
280
  }
281
281
 
282
- if (arg0.css == null) {
282
+ if (arg0 == null || arg0.css == null) {
283
283
  return creatorCreateElement(creator, type, arg0, [arg1])
284
284
  }
285
285
  const { css, ...props } = arg0
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Arche v0.3.2
2
+ * Arche v0.3.5
3
3
  * https://github.com/richytong/arche
4
4
  * (c) 2020-2023 Richard Tong
5
5
  * Arche may be freely distributed under the MIT license.
@@ -270,7 +270,7 @@ const Arche = function (creator, options = {}) {
270
270
  }
271
271
 
272
272
  if (isArray(arg1)) {
273
- if (arg0.css == null) {
273
+ if (arg0 == null || arg0.css == null) {
274
274
  return creatorCreateElement(creator, type, arg0, arg1)
275
275
  }
276
276
  const { css, ...props } = arg0
@@ -278,14 +278,14 @@ const Arche = function (creator, options = {}) {
278
278
  }
279
279
 
280
280
  if (arg1 == null) {
281
- if (arg0.css == null) {
281
+ if (arg0 == null || arg0.css == null) {
282
282
  return creatorCreateElement(creator, type, arg0, [])
283
283
  }
284
284
  const { css, ...props } = arg0
285
285
  return creatorCreateElement(creator, styledComponent([css]), props, [])
286
286
  }
287
287
 
288
- if (arg0.css == null) {
288
+ if (arg0 == null || arg0.css == null) {
289
289
  return creatorCreateElement(creator, type, arg0, [arg1])
290
290
  }
291
291
  const { css, ...props } = arg0
package/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Arche v0.3.2
2
+ * Arche v0.3.5
3
3
  * https://github.com/richytong/arche
4
4
  * (c) 2020-2023 Richard Tong
5
5
  * Arche may be freely distributed under the MIT license.
@@ -264,7 +264,7 @@ const Arche = function (creator, options = {}) {
264
264
  }
265
265
 
266
266
  if (isArray(arg1)) {
267
- if (arg0.css == null) {
267
+ if (arg0 == null || arg0.css == null) {
268
268
  return creatorCreateElement(creator, type, arg0, arg1)
269
269
  }
270
270
  const { css, ...props } = arg0
@@ -272,14 +272,14 @@ const Arche = function (creator, options = {}) {
272
272
  }
273
273
 
274
274
  if (arg1 == null) {
275
- if (arg0.css == null) {
275
+ if (arg0 == null || arg0.css == null) {
276
276
  return creatorCreateElement(creator, type, arg0, [])
277
277
  }
278
278
  const { css, ...props } = arg0
279
279
  return creatorCreateElement(creator, styledComponent([css]), props, [])
280
280
  }
281
281
 
282
- if (arg0.css == null) {
282
+ if (arg0 == null || arg0.css == null) {
283
283
  return creatorCreateElement(creator, type, arg0, [arg1])
284
284
  }
285
285
  const { css, ...props } = arg0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arche",
3
- "version": "0.3.2",
3
+ "version": "0.3.5",
4
4
  "description": "HTML as JavaScript",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",
package/test.js CHANGED
@@ -117,11 +117,12 @@ describe('Arche', () => {
117
117
  Div({ css: 'article', id: 'nested' }, [
118
118
  Article('yo'),
119
119
  ]),
120
+ Span(),
120
121
  ])
121
122
 
122
123
  assert.strictEqual(
123
124
  JSON.stringify(el),
124
- '["div",{},[["h1",{},["header"]],["h3",{"style":{"color":"grey"}},["description"]],["b",{"id":"hey","excluded":null},[]],["article",{"id":"nested"},[["article",{},["yo"]]]]]]')
125
+ '["div",{},[["h1",{},["header"]],["h3",{"style":{"color":"grey"}},["description"]],["b",{"id":"hey","excluded":null},[]],["article",{"id":"nested"},[["article",{},["yo"]]]],["span",{},[]]]]')
125
126
  })
126
127
  })
127
128
  })