solarite 0.5.2 → 0.7.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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Solarite-debug.js +4847 -3878
  3. package/dist/Solarite.js +4583 -3626
  4. package/dist/Solarite.min.js +2 -4
  5. package/package.json +19 -6
  6. package/readme.md +58 -11
  7. package/src/Globals.js +54 -72
  8. package/src/HtmlParser.js +90 -90
  9. package/src/MultiValueMap.js +57 -105
  10. package/src/NodeGroup.js +624 -470
  11. package/src/Path.js +224 -211
  12. package/src/PathToAttribValue.js +401 -261
  13. package/src/PathToAttribs.js +113 -80
  14. package/src/PathToComment.js +7 -7
  15. package/src/PathToComponent.js +183 -188
  16. package/src/PathToEvent.js +76 -64
  17. package/src/PathToKey.js +19 -0
  18. package/src/PathToNodes.js +1053 -566
  19. package/src/RootNodeGroup.js +120 -8
  20. package/src/Shell.js +570 -348
  21. package/src/Solarite.d.ts +134 -113
  22. package/src/Solarite.js +243 -286
  23. package/src/Template.js +195 -274
  24. package/src/Util.js +353 -351
  25. package/src/assert.js +10 -10
  26. package/src/assignAttributes.js +63 -0
  27. package/src/delve.js +55 -43
  28. package/src/h.js +220 -138
  29. package/src/jsx-dev-runtime.d.ts +1 -0
  30. package/src/jsx-dev-runtime.js +5 -0
  31. package/src/jsx-runtime.d.ts +21 -0
  32. package/src/jsx-runtime.js +84 -0
  33. package/src/jsx.js +194 -0
  34. package/src/toEl.js +77 -82
  35. package/dist/udomdiff-license.txt +0 -18
  36. package/src/getArg.js +0 -137
  37. package/src/hash.js +0 -89
  38. package/src/udomdiff.js +0 -176
  39. package/src/unused/FastLookupArray.js +0 -54
  40. package/src/unused/Hashes.js +0 -339
  41. package/src/unused/InUse.test.js +0 -92
  42. package/src/unused/InUseMap.js +0 -98
  43. package/src/unused/LinkedList.js +0 -117
  44. package/src/unused/LinkedList.test.js +0 -115
  45. package/src/unused/Misc.js +0 -13
  46. package/src/unused/Perf.js +0 -47
  47. package/src/unused/TrackedArray.js +0 -54
  48. package/src/unused/WeakArray.js +0 -33
  49. package/src/watch.js +0 -543
@@ -1,65 +1,77 @@
1
- import assert from "./assert.js";
2
- import PathToAttribValue from "./PathToAttribValue.js";
3
-
4
- // TODO: Merge this into PathToAttribValue?
5
- export default class PathToEvent extends PathToAttribValue {
6
-
7
- constructor(nodeBefore, nodeMarker, attrName=null, attrValue=null) {
8
- super(null, nodeMarker, attrName, attrValue);
9
- }
10
-
11
- /**
12
- * Handle attributes for event binding, such as:
13
- * onclick=${(e, el) => this.doSomething(el, 'meow')}
14
- * oninput=${[this.doSomething, 'meow']}
15
- * onclick=${[this, 'doSomething', 'meow']}
16
- *
17
- * @param exprs {Expr[]} Only the first is used.*/
18
- apply(exprs) {
19
- //#IFDEV
20
- assert(Array.isArray(exprs));
21
- //#ENDIF
22
-
23
- // Tested by Solariate.events.classicWithExpr
24
- // We have expressions within a string attribute value that's not a Solarite event. E.g.
25
- // <div onclick="alert(${1});"
26
- if (this.attrValue?.length > 1) {
27
- super.apply(exprs);
28
- return;
29
- }
30
-
31
- // Don't bind events to component placeholders.
32
- // PathToComponent will do the binding later when it instantiates the component.
33
- if (this.isComponentAttrib && this.nodeMarker.tagName.endsWith('-SOLARITE-PLACEHOLDER'))
34
- return;
35
-
36
- let expr = exprs[0];
37
- let root = this.parentNg.rootNg.root
38
-
39
- /*#IFDEV*/
40
- assert(root?.nodeType === 1);
41
- /*#ENDIF*/
42
-
43
- let node = this.nodeMarker;
44
-
45
- let eventName = this.attrName.slice(2); // remove "on-" prefix.
46
- let func;
47
- let args = [];
48
-
49
- // Convert array to function.
50
- // oninput=${[this.doSomething, 'meow']}
51
- if (Array.isArray(expr) && typeof expr[0] === 'function') {
52
- func = expr[0];
53
- args = expr.slice(1);
54
- }
55
- else if (typeof expr === 'function')
56
- func = expr;
57
- else
58
- throw new Error(`Invalid event binding: <${node.tagName.toLowerCase()} ${this.attrName}=\${${JSON.stringify(expr)}}>`);
59
-
60
- this.bindEvent(node, root, eventName, eventName, func, args);
61
- }
62
-
63
-
64
-
1
+ import assert from "./assert.js";
2
+ import PathToAttribValue from "./PathToAttribValue.js";
3
+
4
+ // TODO: Merge this into PathToAttribValue?
5
+ export default class PathToEvent extends PathToAttribValue {
6
+
7
+ /** @type {string} The attrName without the "on" prefix. */
8
+ eventName;
9
+
10
+ constructor(nodeBefore, nodeMarker, attrName=null, attrValue=null) {
11
+ super(null, nodeMarker, attrName, attrValue);
12
+ this.eventName = attrName ? attrName.slice(2) : null;
13
+ }
14
+
15
+ /**
16
+ * Handle attributes for event binding, such as:
17
+ * onclick=${(e, el) => this.doSomething(el, 'meow')}
18
+ * oninput=${[this.doSomething, 'meow']}
19
+ * onclick=${[this, 'doSomething', 'meow']}
20
+ *
21
+ * @param exprs {Expr[]} Only the first is used.*/
22
+ apply(exprs) {
23
+ //#IFDEV
24
+ assert(Array.isArray(exprs));
25
+ //#ENDIF
26
+
27
+ // Tested by Solariate.events.classicWithExpr
28
+ // We have expressions within a string attribute value that's not a Solarite event. E.g.
29
+ // <div onclick="alert(${1});"
30
+ if (this.attrValue?.length > 1) {
31
+ super.apply(exprs);
32
+ return;
33
+ }
34
+
35
+ this.applySingle(exprs[0]);
36
+ }
37
+
38
+ /**
39
+ * @param expr {Expr} */
40
+ applySingle(expr) {
41
+ // Expressions within a string attribute value that's not a Solarite event.
42
+ if (this.attrValue?.length > 1)
43
+ return super.apply([expr]);
44
+
45
+ // Don't bind events to component placeholders.
46
+ // PathToComponent will do the binding later when it instantiates the component.
47
+ if (this.isComponentAttrib && this.nodeMarker.tagName.endsWith('-SOLARITE-PLACEHOLDER'))
48
+ return;
49
+
50
+ let root = this.parentNg.rootNg.root
51
+
52
+ /*#IFDEV*/
53
+ assert(root?.nodeType === 1);
54
+ /*#ENDIF*/
55
+
56
+ let node = this.nodeMarker;
57
+
58
+ let eventName = this.eventName;
59
+ let func;
60
+
61
+ // Array form: oninput=${[this.doSomething, 'meow']}
62
+ // The whole array is passed to bindEvent so no args array has to be allocated here.
63
+ if (Array.isArray(expr) && typeof expr[0] === 'function')
64
+ func = expr[0];
65
+ else if (typeof expr === 'function') {
66
+ func = expr;
67
+ expr = null;
68
+ }
69
+ else
70
+ throw new Error(`Invalid event binding: <${node.tagName.toLowerCase()} ${this.attrName}=\${${JSON.stringify(expr)}}>`);
71
+
72
+ this.bindEvent(node, root, eventName, eventName, func, expr);
73
+ }
74
+
75
+
76
+
65
77
  }
@@ -0,0 +1,19 @@
1
+ import Path from "./Path.js";
2
+
3
+ /**
4
+ * Consumes the key=${expr} expression of a keyed template.
5
+ * Writes the value to its NodeGroup's key field and never touches the DOM.
6
+ * Created by Shell when it strips a key attribute; PathToNodes.applyKeyed()
7
+ * matches NodeGroups to new templates by this key. */
8
+ export default class PathToKey extends Path {
9
+
10
+ /**
11
+ * @param exprs {Expr[]} Only the first is used. */
12
+ apply(exprs) {
13
+ this.parentNg.key = exprs[0];
14
+ }
15
+
16
+ applySingle(expr) {
17
+ this.parentNg.key = expr;
18
+ }
19
+ }