@solidjs/h 2.0.0-experimental.4 → 2.0.0-experimental.6

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/dist/h.cjs CHANGED
@@ -2,23 +2,12 @@
2
2
 
3
3
  var web = require('@solidjs/web');
4
4
 
5
- const $ELEMENT = Symbol("hyper-element");
6
5
  function createHyperScript(r) {
7
6
  function h() {
8
7
  let args = [].slice.call(arguments),
9
8
  e,
10
9
  classes = [],
11
10
  multiExpression = false;
12
- while (Array.isArray(args[0])) args = args[0];
13
- if (args[0][$ELEMENT]) args.unshift(h.Fragment);
14
- typeof args[0] === "string" && detectMultiExpression(args);
15
- const ret = () => {
16
- while (args.length) item(args.shift());
17
- if (e instanceof Element && classes.length) e.classList.add(...classes);
18
- return e;
19
- };
20
- ret[$ELEMENT] = true;
21
- return ret;
22
11
  function item(l) {
23
12
  const type = typeof l;
24
13
  if (l == null) ;else if ("string" === type) {
@@ -34,8 +23,7 @@ function createHyperScript(r) {
34
23
  const d = Object.getOwnPropertyDescriptors(l);
35
24
  for (const k in d) {
36
25
  if (k === "class" && classes.length !== 0) {
37
- const fixedClasses = classes.join(" "),
38
- value = typeof d["class"].value === "function" ? () => fixedClasses + " " + d["class"].value() : fixedClasses + " " + l["class"];
26
+ const value = typeof d["class"].value === "function" ? () => [...classes, d["class"].value()] : [...classes, l["class"]];
39
27
  Object.defineProperty(l, "class", {
40
28
  ...d[k],
41
29
  value
@@ -59,25 +47,20 @@ function createHyperScript(r) {
59
47
  }
60
48
  const d = Object.getOwnPropertyDescriptors(props);
61
49
  for (const k in d) {
62
- if (Array.isArray(d[k].value)) {
63
- const list = d[k].value;
64
- props[k] = () => {
65
- for (let i = 0; i < list.length; i++) {
66
- while (list[i][$ELEMENT]) list[i] = list[i]();
67
- }
68
- return list;
69
- };
70
- r.dynamicProperty(props, k);
71
- } else if (typeof d[k].value === "function" && !d[k].value.length) r.dynamicProperty(props, k);
50
+ if (typeof d[k].value === "function" && !d[k].value.length) r.dynamicProperty(props, k);
72
51
  }
73
52
  e = r.createComponent(l, props);
74
53
  args = [];
75
54
  } else {
76
- while (l[$ELEMENT]) l = l();
77
55
  r.insert(e, l, multiExpression ? null : undefined);
78
56
  }
79
57
  }
80
58
  }
59
+ if (args.length === 1 && Array.isArray(args[0])) return args[0];
60
+ typeof args[0] === "string" && detectMultiExpression(args);
61
+ while (args.length) item(args.shift());
62
+ if (e instanceof Element && classes.length) e.classList.add(...classes);
63
+ return e;
81
64
  function parseClass(string) {
82
65
  const m = string.split(/([\.#]?[^\s#.]+)/);
83
66
  if (/^\.|#/.test(m[1])) e = document.createElement("div");
package/dist/h.js CHANGED
@@ -1,43 +1,16 @@
1
- import {
2
- spread,
3
- assign,
4
- insert,
5
- createComponent,
6
- dynamicProperty,
7
- SVGElements
8
- } from "@solidjs/web";
1
+ import { spread, assign, insert, createComponent, dynamicProperty, SVGElements } from '@solidjs/web';
9
2
 
10
- const $ELEMENT = Symbol("hyper-element");
11
3
  function createHyperScript(r) {
12
4
  function h() {
13
5
  let args = [].slice.call(arguments),
14
6
  e,
15
7
  classes = [],
16
8
  multiExpression = false;
17
- while (Array.isArray(args[0])) args = args[0];
18
- if (args[0][$ELEMENT]) args.unshift(h.Fragment);
19
- typeof args[0] === "string" && detectMultiExpression(args);
20
- const ret = () => {
21
- while (args.length) item(args.shift());
22
- if (e instanceof Element && classes.length) e.classList.add(...classes);
23
- return e;
24
- };
25
- ret[$ELEMENT] = true;
26
- return ret;
27
9
  function item(l) {
28
10
  const type = typeof l;
29
- if (l == null);
30
- else if ("string" === type) {
31
- if (!e) parseClass(l);
32
- else e.appendChild(document.createTextNode(l));
33
- } else if (
34
- "number" === type ||
35
- "boolean" === type ||
36
- "bigint" === type ||
37
- "symbol" === type ||
38
- l instanceof Date ||
39
- l instanceof RegExp
40
- ) {
11
+ if (l == null) ;else if ("string" === type) {
12
+ if (!e) parseClass(l);else e.appendChild(document.createTextNode(l));
13
+ } else if ("number" === type || "boolean" === type || "bigint" === type || "symbol" === type || l instanceof Date || l instanceof RegExp) {
41
14
  e.appendChild(document.createTextNode(l.toString()));
42
15
  } else if (Array.isArray(l)) {
43
16
  for (let i = 0; i < l.length; i++) item(l[i]);
@@ -48,11 +21,7 @@ function createHyperScript(r) {
48
21
  const d = Object.getOwnPropertyDescriptors(l);
49
22
  for (const k in d) {
50
23
  if (k === "class" && classes.length !== 0) {
51
- const fixedClasses = classes.join(" "),
52
- value =
53
- typeof d["class"].value === "function"
54
- ? () => fixedClasses + " " + d["class"].value()
55
- : fixedClasses + " " + l["class"];
24
+ const value = typeof d["class"].value === "function" ? () => [...classes, d["class"].value()] : [...classes, l["class"]];
56
25
  Object.defineProperty(l, "class", {
57
26
  ...d[k],
58
27
  value
@@ -64,44 +33,32 @@ function createHyperScript(r) {
64
33
  dynamic = true;
65
34
  } else if (d[k].get) dynamic = true;
66
35
  }
67
- dynamic
68
- ? r.spread(e, l, e instanceof SVGElement, !!args.length)
69
- : r.assign(e, l, e instanceof SVGElement, !!args.length);
36
+ dynamic ? r.spread(e, l, e instanceof SVGElement, !!args.length) : r.assign(e, l, e instanceof SVGElement, !!args.length);
70
37
  } else if ("function" === type) {
71
38
  if (!e) {
72
39
  let props,
73
40
  next = args[0];
74
- if (
75
- next == null ||
76
- (typeof next === "object" && !Array.isArray(next) && !(next instanceof Element))
77
- )
78
- props = args.shift();
41
+ if (next == null || typeof next === "object" && !Array.isArray(next) && !(next instanceof Element)) props = args.shift();
79
42
  props || (props = {});
80
43
  if (args.length) {
81
44
  props.children = args.length > 1 ? args : args[0];
82
45
  }
83
46
  const d = Object.getOwnPropertyDescriptors(props);
84
47
  for (const k in d) {
85
- if (Array.isArray(d[k].value)) {
86
- const list = d[k].value;
87
- props[k] = () => {
88
- for (let i = 0; i < list.length; i++) {
89
- while (list[i][$ELEMENT]) list[i] = list[i]();
90
- }
91
- return list;
92
- };
93
- r.dynamicProperty(props, k);
94
- } else if (typeof d[k].value === "function" && !d[k].value.length)
95
- r.dynamicProperty(props, k);
48
+ if (typeof d[k].value === "function" && !d[k].value.length) r.dynamicProperty(props, k);
96
49
  }
97
50
  e = r.createComponent(l, props);
98
51
  args = [];
99
52
  } else {
100
- while (l[$ELEMENT]) l = l();
101
53
  r.insert(e, l, multiExpression ? null : undefined);
102
54
  }
103
55
  }
104
56
  }
57
+ if (args.length === 1 && Array.isArray(args[0])) return args[0];
58
+ typeof args[0] === "string" && detectMultiExpression(args);
59
+ while (args.length) item(args.shift());
60
+ if (e instanceof Element && classes.length) e.classList.add(...classes);
61
+ return e;
105
62
  function parseClass(string) {
106
63
  const m = string.split(/([\.#]?[^\s#.]+)/);
107
64
  if (/^\.|#/.test(m[1])) e = document.createElement("div");
@@ -109,12 +66,7 @@ function createHyperScript(r) {
109
66
  const v = m[i],
110
67
  s = v.substring(1, v.length);
111
68
  if (!v) continue;
112
- if (!e)
113
- e = r.SVGElements.has(v)
114
- ? document.createElementNS("http://www.w3.org/2000/svg", v)
115
- : document.createElement(v);
116
- else if (v[0] === ".") classes.push(s);
117
- else if (v[0] === "#") e.setAttribute("id", s);
69
+ if (!e) e = r.SVGElements.has(v) ? document.createElementNS("http://www.w3.org/2000/svg", v) : document.createElement(v);else if (v[0] === ".") classes.push(s);else if (v[0] === "#") e.setAttribute("id", s);
118
70
  }
119
71
  }
120
72
  function detectMultiExpression(list) {
@@ -1,4 +1,4 @@
1
- import h from "@solidjs/h";
1
+ import h from '@solidjs/h';
2
2
 
3
3
  function Fragment(props) {
4
4
  return props.children;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@solidjs/h",
3
3
  "description": "A standard (less-optimal) JSX factory for Solid",
4
- "version": "2.0.0-experimental.4",
4
+ "version": "2.0.0-experimental.6",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -46,10 +46,10 @@
46
46
  "./types/*": "./types/*"
47
47
  },
48
48
  "peerDependencies": {
49
- "@solidjs/web": "^2.0.0-experimental.4"
49
+ "@solidjs/web": "^2.0.0-experimental.6"
50
50
  },
51
51
  "devDependencies": {
52
- "@solidjs/web": "2.0.0-experimental.4"
52
+ "@solidjs/web": "2.0.0-experimental.6"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "npm-run-all -nl build:*",