ilha 0.9.0 → 0.9.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.
- package/README.md +77 -0
- package/dist/index.js +2121 -5
- package/dist/jsx-dev-runtime.js +3 -1
- package/dist/jsx-runtime.js +162 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -766,6 +766,83 @@ const styles = css`
|
|
|
766
766
|
|
|
767
767
|
---
|
|
768
768
|
|
|
769
|
+
## JSX Runtime
|
|
770
|
+
|
|
771
|
+
Prefer JSX over the `html` tag? `ilha` ships a JSX runtime (`ilha/jsx-runtime`) that produces the same XSS-safe output — JSX expressions evaluate to the same `RawHtml` values the `html` tag returns, so the two syntaxes are interchangeable and can be mixed freely.
|
|
772
|
+
|
|
773
|
+
### Setup
|
|
774
|
+
|
|
775
|
+
Enable the automatic JSX transform in `tsconfig.json` (works with TypeScript, Bun, Vite, esbuild, etc.):
|
|
776
|
+
|
|
777
|
+
```jsonc
|
|
778
|
+
{
|
|
779
|
+
"compilerOptions": {
|
|
780
|
+
"jsx": "react-jsx",
|
|
781
|
+
"jsxImportSource": "ilha",
|
|
782
|
+
},
|
|
783
|
+
}
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
### Usage
|
|
787
|
+
|
|
788
|
+
```tsx
|
|
789
|
+
import ilha from "ilha";
|
|
790
|
+
|
|
791
|
+
const Counter = ilha
|
|
792
|
+
.state("count", 0)
|
|
793
|
+
.on("button@click", ({ state }) => state.count(state.count() + 1))
|
|
794
|
+
.render(({ state }) => (
|
|
795
|
+
<div>
|
|
796
|
+
<p>Count: {state.count}</p>
|
|
797
|
+
<button>Increment</button>
|
|
798
|
+
</div>
|
|
799
|
+
));
|
|
800
|
+
```
|
|
801
|
+
|
|
802
|
+
Interpolated children follow the same rules as the `html` tag — strings are escaped, signal accessors are auto-called, islands become hydration slots, arrays are flattened. Use `raw()` to opt out of escaping, and `<></>` (Fragment) to group siblings without a wrapper element.
|
|
803
|
+
|
|
804
|
+
### Attributes
|
|
805
|
+
|
|
806
|
+
| Feature | Behaviour |
|
|
807
|
+
| --------------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
808
|
+
| `class` / `className` | Accepts a string, an array (`["a", cond && "b"]`), or an object (`{ active: isActive }`) |
|
|
809
|
+
| `htmlFor` | Alias for `for` |
|
|
810
|
+
| `style` | Accepts a string or an object (`{ backgroundColor: "teal" }` → `background-color:teal`) |
|
|
811
|
+
| Boolean attributes | `true` renders the bare attribute, `false`/`null`/`undefined` omit it |
|
|
812
|
+
| `bind:*` | Two-way bindings, same as in `html` templates — pass a signal accessor: `<input bind:value={state.name} />` |
|
|
813
|
+
| `key` | Keys a child island for reorder-safe rendering (same as `.key()`). Keys must be non-empty and must not contain `:` |
|
|
814
|
+
|
|
815
|
+
For safety, `on*` attributes (e.g. `onclick`) and `srcdoc` are stripped — attach event listeners with `.on()` instead — and URL attributes (`href`, `src`, `action`, …) with unsafe schemes like `javascript:` are dropped.
|
|
816
|
+
|
|
817
|
+
### Islands as components
|
|
818
|
+
|
|
819
|
+
Islands are plain functions, so they compose as JSX components — props and keys work as you'd expect:
|
|
820
|
+
|
|
821
|
+
```tsx
|
|
822
|
+
const Badge = ilha
|
|
823
|
+
.input<{ label: string }>()
|
|
824
|
+
.render(({ input }) => <span class="badge">{input.label}</span>);
|
|
825
|
+
|
|
826
|
+
const Card = ilha.render(() => (
|
|
827
|
+
<div class="card">
|
|
828
|
+
<Badge label="New" />
|
|
829
|
+
<p>Card content</p>
|
|
830
|
+
</div>
|
|
831
|
+
));
|
|
832
|
+
|
|
833
|
+
const List = ilha.render(() => (
|
|
834
|
+
<ul>
|
|
835
|
+
{items.map((item) => (
|
|
836
|
+
<li>
|
|
837
|
+
<Item key={item.id} name={item.name} />
|
|
838
|
+
</li>
|
|
839
|
+
))}
|
|
840
|
+
</ul>
|
|
841
|
+
));
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
---
|
|
845
|
+
|
|
769
846
|
## SSR + Hydration
|
|
770
847
|
|
|
771
848
|
The recommended SSR + hydration pattern uses `.hydratable()` on the server and `ilha.mount()` on the client.
|