@solidjs/html 2.0.0-rc.11 → 2.0.0-rc.14

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
@@ -92,14 +92,17 @@ html`<div id=${() => props.id}>${() => firstName() + lastName()}</div>`
92
92
 
93
93
  2. Events on components require explicit event in the arguments
94
94
 
95
- Solid's Tagged Template Literals automatically wraps functions passed to props of components with no arguments in getters so you need to provide one to prevent this. The same applies to render props like in the `<For>` component.
95
+ Solid's Tagged Template Literals automatically wrap functions with no arguments passed to props of components in getters, so you need to declare an argument to prevent this. That covers every prop, `onXxx` handlers and `ref` included; the same applies to render props like in the `<For>` component.
96
96
 
97
97
  ```js
98
- // good
99
- html`<${Button} onClick=${(e) => console.log("Hi")} />`;
98
+ // good: passed as a function
99
+ html`<${Button} onClick=${e => console.log("Hi")} />`;
100
100
 
101
- // bad
101
+ // bad: a getter, so `props.onClick` runs `console.log` and reads its result
102
102
  html`<${Button} onClick=${() => console.log("Hi")} />`;
103
+
104
+ // getter: `props.on` reads `key()`
105
+ html`<${Loading} on=${() => key()}>...<//>`;
103
106
  ```
104
107
 
105
108
  4. All refs are callback form
@@ -119,4 +122,13 @@ html`
119
122
  <div>1</div>
120
123
  <div>2</div>
121
124
  `
125
+ ```
126
+
127
+ 6. Only `onXxx` names are event handlers
128
+
129
+ On elements, camelCase `onXxx` names (`on` followed by an uppercase letter) are event handlers and are passed through as functions, as is `ref`. A lowercase `onclick` is a plain attribute, and a zero-argument function passed to it becomes a getter like any other attribute.
130
+
131
+ ```js
132
+ html`<button onClick=${() => save()} />`; // event handler
133
+ html`<button onclick=${() => code()} />`; // reactive `onclick` attribute
122
134
  ```
package/dist/html.js CHANGED
@@ -86,7 +86,7 @@ const tokenize = (strings, rawTextElements) => {
86
86
  if (isWhitespace(code)) {
87
87
  cursor++;
88
88
  } else if (code === 62) {
89
- if (rawTextElements.has(lastTagName) && tokens[tokens.length - 2]?.type !== SLASH_TOKEN) {
89
+ if (rawTextElements.has(lastTagName) && tokens[tokens.length - 1]?.type !== SLASH_TOKEN && tokens[tokens.length - 2]?.type !== SLASH_TOKEN) {
90
90
  state = STATE_RAW_TEXT;
91
91
  } else {
92
92
  state = STATE_TEXT;
@@ -501,7 +501,7 @@ function createHtml() {
501
501
  own[prop.name] = prop.value;
502
502
  break;
503
503
  case EXPRESSION_PROP:
504
- applyGetter(own, prop.name, values[prop.value]);
504
+ applyGetter(own, prop.name, values[prop.value], node.type === COMPONENT_NODE);
505
505
  break;
506
506
  case SPREAD_PROP:
507
507
  const spreadValue = values[prop.value];
@@ -522,8 +522,8 @@ function createHtml() {
522
522
  sources.push(own);
523
523
  return mergeProps(...sources);
524
524
  };
525
- const applyGetter = (props, name, value) => {
526
- if (typeof value === "function" && value.length === 0 && name !== "ref" && !name.startsWith("on")) {
525
+ const applyGetter = (props, name, value, component) => {
526
+ if (typeof value === "function" && value.length === 0 && (component || name !== "ref" && !/^on[A-Z]/.test(name))) {
527
527
  Object.defineProperty(props, name, {
528
528
  get() {
529
529
  return value();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@solidjs/html",
3
3
  "description": "Tagged-template-literal templating for Solid — write components with no build step.",
4
- "version": "2.0.0-rc.11",
4
+ "version": "2.0.0-rc.14",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -42,7 +42,7 @@
42
42
  "test": "vitest run"
43
43
  },
44
44
  "peerDependencies": {
45
- "@solidjs/web": "^2.0.0-rc.11"
45
+ "@solidjs/web": "^2.0.0-rc.14"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@solidjs/web": "workspace:*",