hyper-dom-expressions 0.40.2 → 0.41.0-next.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.
@@ -1,15 +1,3 @@
1
- const $ELEMENT = Symbol("hyper-element");
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
1
  // Inspired by https://github.com/hyperhype/hyperscript
14
2
  function createHyperScript(r) {
15
3
  function h() {
@@ -18,17 +6,6 @@ function createHyperScript(r) {
18
6
  classes = [],
19
7
  multiExpression = false;
20
8
 
21
- while (Array.isArray(args[0])) args = args[0];
22
- if (args[0][$ELEMENT]) args.unshift(h.Fragment);
23
- typeof args[0] === "string" && detectMultiExpression(args);
24
- const ret = () => {
25
- while (args.length) item(args.shift());
26
- if (e instanceof Element && classes.length) e.classList.add(...classes);
27
- return e;
28
- };
29
- ret[$ELEMENT] = true;
30
- return ret;
31
-
32
9
  function item(l) {
33
10
  const type = typeof l;
34
11
  if (l == null) ;else
@@ -53,10 +30,10 @@ function createHyperScript(r) {
53
30
  const d = Object.getOwnPropertyDescriptors(l);
54
31
  for (const k in d) {
55
32
  if (k === "class" && classes.length !== 0) {
56
- const fixedClasses = classes.join(" "),
57
- value = typeof d["class"].value === "function" ?
58
- () => fixedClasses + " " + d["class"].value() :
59
- fixedClasses + " " + l["class"];
33
+ const value =
34
+ typeof d["class"].value === "function" ?
35
+ () => [...classes, d["class"].value()] :
36
+ [...classes, l["class"]];
60
37
  Object.defineProperty(l, "class", { ...d[k], value });
61
38
  classes = [];
62
39
  }
@@ -83,26 +60,22 @@ function createHyperScript(r) {
83
60
  }
84
61
  const d = Object.getOwnPropertyDescriptors(props);
85
62
  for (const k in d) {
86
- if (Array.isArray(d[k].value)) {
87
- const list = d[k].value;
88
- props[k] = () => {
89
- for (let i = 0; i < list.length; i++) {
90
- while (list[i][$ELEMENT]) list[i] = list[i]();
91
- }
92
- return list;
93
- };
94
- r.dynamicProperty(props, k);
95
- } else if (typeof d[k].value === "function" && !d[k].value.length)
96
- r.dynamicProperty(props, k);
63
+ if (typeof d[k].value === "function" && !d[k].value.length) r.dynamicProperty(props, k);
97
64
  }
98
65
  e = r.createComponent(l, props);
99
66
  args = [];
100
67
  } else {
101
- while (l[$ELEMENT]) l = l();
102
68
  r.insert(e, l, multiExpression ? null : undefined);
103
69
  }
104
70
  }
105
71
  }
72
+
73
+ if (args.length === 1 && Array.isArray(args[0])) return args[0];
74
+ typeof args[0] === "string" && detectMultiExpression(args);
75
+ while (args.length) item(args.shift());
76
+ if (e instanceof Element && classes.length) e.classList.add(...classes);
77
+ return e;
78
+
106
79
  function parseClass(string) {
107
80
  // Our minimal parser doesn’t understand escaping CSS special
108
81
  // characters like `#`. Don’t use them. More reading:
@@ -1,17 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const $ELEMENT = Symbol("hyper-element");
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
3
  // Inspired by https://github.com/hyperhype/hyperscript
16
4
  function createHyperScript(r) {
17
5
  function h() {
@@ -20,17 +8,6 @@ function createHyperScript(r) {
20
8
  classes = [],
21
9
  multiExpression = false;
22
10
 
23
- while (Array.isArray(args[0])) args = args[0];
24
- if (args[0][$ELEMENT]) args.unshift(h.Fragment);
25
- typeof args[0] === "string" && detectMultiExpression(args);
26
- const ret = () => {
27
- while (args.length) item(args.shift());
28
- if (e instanceof Element && classes.length) e.classList.add(...classes);
29
- return e;
30
- };
31
- ret[$ELEMENT] = true;
32
- return ret;
33
-
34
11
  function item(l) {
35
12
  const type = typeof l;
36
13
  if (l == null) ;else
@@ -55,10 +32,10 @@ function createHyperScript(r) {
55
32
  const d = Object.getOwnPropertyDescriptors(l);
56
33
  for (const k in d) {
57
34
  if (k === "class" && classes.length !== 0) {
58
- const fixedClasses = classes.join(" "),
59
- value = typeof d["class"].value === "function" ?
60
- () => fixedClasses + " " + d["class"].value() :
61
- fixedClasses + " " + l["class"];
35
+ const value =
36
+ typeof d["class"].value === "function" ?
37
+ () => [...classes, d["class"].value()] :
38
+ [...classes, l["class"]];
62
39
  Object.defineProperty(l, "class", { ...d[k], value });
63
40
  classes = [];
64
41
  }
@@ -85,26 +62,22 @@ function createHyperScript(r) {
85
62
  }
86
63
  const d = Object.getOwnPropertyDescriptors(props);
87
64
  for (const k in d) {
88
- if (Array.isArray(d[k].value)) {
89
- const list = d[k].value;
90
- props[k] = () => {
91
- for (let i = 0; i < list.length; i++) {
92
- while (list[i][$ELEMENT]) list[i] = list[i]();
93
- }
94
- return list;
95
- };
96
- r.dynamicProperty(props, k);
97
- } else if (typeof d[k].value === "function" && !d[k].value.length)
98
- r.dynamicProperty(props, k);
65
+ if (typeof d[k].value === "function" && !d[k].value.length) r.dynamicProperty(props, k);
99
66
  }
100
67
  e = r.createComponent(l, props);
101
68
  args = [];
102
69
  } else {
103
- while (l[$ELEMENT]) l = l();
104
70
  r.insert(e, l, multiExpression ? null : undefined);
105
71
  }
106
72
  }
107
73
  }
74
+
75
+ if (args.length === 1 && Array.isArray(args[0])) return args[0];
76
+ typeof args[0] === "string" && detectMultiExpression(args);
77
+ while (args.length) item(args.shift());
78
+ if (e instanceof Element && classes.length) e.classList.add(...classes);
79
+ return e;
80
+
108
81
  function parseClass(string) {
109
82
  // Our minimal parser doesn’t understand escaping CSS special
110
83
  // characters like `#`. Don’t use them. More reading:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hyper-dom-expressions",
3
3
  "description": "A Fine-Grained Rendering Runtime API using HyperScript",
4
- "version": "0.40.2",
4
+ "version": "0.41.0-next.0",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -19,7 +19,7 @@
19
19
  "prepare": "pnpm run build"
20
20
  },
21
21
  "devDependencies": {
22
- "dom-expressions": "^0.40.2"
22
+ "dom-expressions": "^0.41.0-next.0"
23
23
  },
24
- "gitHead": "2c44b1854b7b2863a506ee32517e6f962804609e"
24
+ "gitHead": "59823cd3108ee6d17058b90d1ef92b9d9ad103d7"
25
25
  }
package/types/index.d.ts CHANGED
@@ -11,10 +11,10 @@ type ExpandableNode = Node & {
11
11
  [key: string]: any;
12
12
  };
13
13
  export type HyperScript = {
14
- (...args: any[]): () => ExpandableNode | ExpandableNode[];
14
+ (...args: any[]): ExpandableNode | ExpandableNode[];
15
15
  Fragment: (props: {
16
- children: (() => ExpandableNode) | (() => ExpandableNode)[];
17
- }) => ExpandableNode[];
16
+ children: ExpandableNode | ExpandableNode[];
17
+ }) => ExpandableNode | ExpandableNode[];
18
18
  };
19
19
  export declare function createHyperScript(r: Runtime): HyperScript;
20
20
  export {};
@@ -1,38 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var babel = require('@rollup/plugin-babel');
6
- var nodeResolve = require('@rollup/plugin-node-resolve');
7
-
8
- const plugins = [
9
- nodeResolve({
10
- extensions: [".js", ".ts"]
11
- }),
12
- babel({
13
- extensions: [".js", ".ts"],
14
- babelHelpers: "bundled",
15
- presets: ["@babel/preset-typescript"],
16
- exclude: "node_modules/**",
17
- babelrc: false,
18
- configFile: false,
19
- retainLines: true
20
- })
21
- ];
22
-
23
- var rollup_config = {
24
- input: "src/index.ts",
25
- output: [
26
- {
27
- file: "lib/hyper-dom-expressions.js",
28
- format: "cjs"
29
- },
30
- {
31
- file: "dist/hyper-dom-expressions.js",
32
- format: "es"
33
- }
34
- ],
35
- plugins
36
- };
37
-
38
- exports.default = rollup_config;