@arcmantle/lit-jsx 1.0.2 → 1.0.3
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 +28 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ A powerful JSX compiler and Vite plugin that transforms JSX into native Lit temp
|
|
|
4
4
|
|
|
5
5
|
## 🚀 Features
|
|
6
6
|
|
|
7
|
-
jsx
|
|
7
|
+
lit-jsx brings the familiar JSX syntax to the Lit ecosystem while maintaining the performance and capabilities that make Lit exceptional.
|
|
8
8
|
|
|
9
9
|
```tsx
|
|
10
10
|
// Write familiar JSX
|
|
@@ -53,11 +53,11 @@ html`
|
|
|
53
53
|
## 📦 Installation
|
|
54
54
|
|
|
55
55
|
```bash
|
|
56
|
-
npm install jsx
|
|
56
|
+
npm install @arcmantle/lit-jsx
|
|
57
57
|
# or
|
|
58
|
-
pnpm add jsx
|
|
58
|
+
pnpm add @arcmantle/lit-jsx
|
|
59
59
|
# or
|
|
60
|
-
yarn add jsx
|
|
60
|
+
yarn add @arcmantle/lit-jsx
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
## ⚡ Quick Start
|
|
@@ -66,7 +66,7 @@ yarn add jsx-lit
|
|
|
66
66
|
|
|
67
67
|
```typescript
|
|
68
68
|
// vite.config.ts
|
|
69
|
-
import { litJsx } from 'jsx
|
|
69
|
+
import { litJsx } from '@arcmantle/lit-jsx/vite-jsx-preserve';
|
|
70
70
|
import { defineConfig } from 'vite';
|
|
71
71
|
|
|
72
72
|
export default defineConfig({
|
|
@@ -80,7 +80,7 @@ export default defineConfig({
|
|
|
80
80
|
{
|
|
81
81
|
"compilerOptions": {
|
|
82
82
|
"jsx": "preserve",
|
|
83
|
-
"jsxImportSource": "jsx
|
|
83
|
+
"jsxImportSource": "lit-jsx"
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
```
|
|
@@ -89,13 +89,13 @@ export default defineConfig({
|
|
|
89
89
|
|
|
90
90
|
```tsx
|
|
91
91
|
import { LitElement } from 'lit';
|
|
92
|
-
import { For, Show, Choose } from 'jsx
|
|
92
|
+
import { For, Show, Choose } from '@arcmantle/lit-jsx';
|
|
93
93
|
|
|
94
94
|
export class MyComponent extends LitElement {
|
|
95
95
|
render() {
|
|
96
96
|
return (
|
|
97
97
|
<div>
|
|
98
|
-
<h1>Hello jsx
|
|
98
|
+
<h1>Hello lit-jsx!</h1>
|
|
99
99
|
<p>JSX compiled to Lit templates with utility components</p>
|
|
100
100
|
|
|
101
101
|
<Show when={this.items.length > 0}>
|
|
@@ -115,7 +115,7 @@ export class MyComponent extends LitElement {
|
|
|
115
115
|
|
|
116
116
|
### Attribute Binding Control
|
|
117
117
|
|
|
118
|
-
jsx
|
|
118
|
+
lit-jsx provides precise control over how values are bound to elements:
|
|
119
119
|
|
|
120
120
|
#### Default Behavior (Attribute Binding)
|
|
121
121
|
|
|
@@ -194,7 +194,7 @@ jsx-lit provides precise control over how values are bound to elements:
|
|
|
194
194
|
|
|
195
195
|
### Function Components
|
|
196
196
|
|
|
197
|
-
jsx
|
|
197
|
+
lit-jsx fully supports function components that return JSX:
|
|
198
198
|
|
|
199
199
|
```tsx
|
|
200
200
|
const Button = ({ label, variant = 'primary', disabled, onClick, children }) => (
|
|
@@ -228,7 +228,7 @@ Function components:
|
|
|
228
228
|
Use `toJSX()` for type-safe custom element components:
|
|
229
229
|
|
|
230
230
|
```tsx
|
|
231
|
-
import { toJSX } from 'jsx
|
|
231
|
+
import { toJSX } from '@arcmantle/lit-jsx';
|
|
232
232
|
import { LitElement } from 'lit';
|
|
233
233
|
|
|
234
234
|
export class MyButton extends LitElement {
|
|
@@ -252,7 +252,7 @@ export class MyButton extends LitElement {
|
|
|
252
252
|
For custom elements with generic types, you can create type-safe JSX components using explicit type casting:
|
|
253
253
|
|
|
254
254
|
```tsx
|
|
255
|
-
import { toJSX } from 'jsx
|
|
255
|
+
import { toJSX } from '@arcmantle/lit-jsx';
|
|
256
256
|
import { LitElement } from 'lit';
|
|
257
257
|
|
|
258
258
|
class DataList<T> extends LitElement {
|
|
@@ -287,14 +287,14 @@ class DataList<T> extends LitElement {
|
|
|
287
287
|
/>
|
|
288
288
|
```
|
|
289
289
|
|
|
290
|
-
**Note**: The current generic syntax requires explicit type casting due to TypeScript's limitations in forwarding generic parameters through static properties. If TypeScript gains the ability to forward generics in this context in the future, jsx
|
|
290
|
+
**Note**: The current generic syntax requires explicit type casting due to TypeScript's limitations in forwarding generic parameters through static properties. If TypeScript gains the ability to forward generics in this context in the future, lit-jsx will implement a more seamless syntax.
|
|
291
291
|
|
|
292
292
|
### Dynamic Tag Names
|
|
293
293
|
|
|
294
|
-
jsx
|
|
294
|
+
lit-jsx supports dynamic element types with the `.tag` property pattern:
|
|
295
295
|
|
|
296
296
|
```tsx
|
|
297
|
-
import { toTag } from 'jsx
|
|
297
|
+
import { toTag } from '@arcmantle/lit-jsx';
|
|
298
298
|
|
|
299
299
|
function ActionElement({ href, children }) {
|
|
300
300
|
const Tag = toTag(href ? 'a' : 'button');
|
|
@@ -311,14 +311,14 @@ function ActionElement({ href, children }) {
|
|
|
311
311
|
|
|
312
312
|
### Library Components
|
|
313
313
|
|
|
314
|
-
jsx
|
|
314
|
+
lit-jsx provides utility components that enhance common patterns and integrate seamlessly with Lit directives:
|
|
315
315
|
|
|
316
316
|
#### For Component - Declarative List Rendering
|
|
317
317
|
|
|
318
318
|
The `For` component provides a declarative way to render lists with optional keys and separators:
|
|
319
319
|
|
|
320
320
|
```tsx
|
|
321
|
-
import { For } from 'jsx
|
|
321
|
+
import { For } from '@arcmantle/lit-jsx';
|
|
322
322
|
|
|
323
323
|
// Basic list rendering
|
|
324
324
|
<For each={users}>
|
|
@@ -357,7 +357,7 @@ The `For` component automatically uses lit-html's optimized directives:
|
|
|
357
357
|
The `Show` component provides type-safe conditional rendering with optional fallback:
|
|
358
358
|
|
|
359
359
|
```tsx
|
|
360
|
-
import { Show } from 'jsx
|
|
360
|
+
import { Show } from '@arcmantle/lit-jsx';
|
|
361
361
|
|
|
362
362
|
// Simple conditional rendering
|
|
363
363
|
<Show when={user}>
|
|
@@ -402,7 +402,7 @@ The `Show` component uses lit-html's `when` directive internally and provides st
|
|
|
402
402
|
The `Choose` component enables clean switch-like conditional rendering with multiple condition-output pairs:
|
|
403
403
|
|
|
404
404
|
```tsx
|
|
405
|
-
import { Choose } from 'jsx
|
|
405
|
+
import { Choose } from '@arcmantle/lit-jsx';
|
|
406
406
|
|
|
407
407
|
// Multiple conditions based on a value
|
|
408
408
|
<Choose value={status}>
|
|
@@ -465,7 +465,7 @@ The `Choose` component evaluates conditions in order and renders the first match
|
|
|
465
465
|
These components work seamlessly together for complex rendering scenarios:
|
|
466
466
|
|
|
467
467
|
```tsx
|
|
468
|
-
import { For, Show, Choose } from 'jsx
|
|
468
|
+
import { For, Show, Choose } from '@arcmantle/lit-jsx';
|
|
469
469
|
|
|
470
470
|
@customElement('user-dashboard')
|
|
471
471
|
export class UserDashboard extends LitElement {
|
|
@@ -548,7 +548,7 @@ export class UserDashboard extends LitElement {
|
|
|
548
548
|
|
|
549
549
|
### Lit Directives Integration
|
|
550
550
|
|
|
551
|
-
jsx
|
|
551
|
+
lit-jsx works seamlessly with all Lit directives:
|
|
552
552
|
|
|
553
553
|
```tsx
|
|
554
554
|
import { when } from 'lit-html/directives/when.js';
|
|
@@ -650,7 +650,7 @@ export class TodoList extends LitElement {
|
|
|
650
650
|
### Vite Plugin Options
|
|
651
651
|
|
|
652
652
|
```typescript
|
|
653
|
-
import { litJsx } from 'jsx
|
|
653
|
+
import { litJsx } from '@arcmantle/lit-jsx/vite-jsx-preserve';
|
|
654
654
|
|
|
655
655
|
export default defineConfig({
|
|
656
656
|
plugins: [
|
|
@@ -670,7 +670,7 @@ export default defineConfig({
|
|
|
670
670
|
|
|
671
671
|
## 🚀 Template Types
|
|
672
672
|
|
|
673
|
-
jsx
|
|
673
|
+
lit-jsx automatically detects and uses the appropriate template type:
|
|
674
674
|
|
|
675
675
|
- **HTML templates**: `html\`...\`` for regular HTML elements
|
|
676
676
|
- **SVG templates**: `svg\`...\`` for SVG elements
|
|
@@ -727,7 +727,7 @@ jsx-lit automatically detects and uses the appropriate template type:
|
|
|
727
727
|
|
|
728
728
|
## 🔗 Ecosystem Integration
|
|
729
729
|
|
|
730
|
-
jsx
|
|
730
|
+
lit-jsx is designed to work seamlessly with the entire Lit ecosystem:
|
|
731
731
|
|
|
732
732
|
- **Lit Elements**: Full compatibility with LitElement and reactive properties
|
|
733
733
|
- **Lit Directives**: All official and community directives work out of the box
|
|
@@ -739,13 +739,13 @@ jsx-lit is designed to work seamlessly with the entire Lit ecosystem:
|
|
|
739
739
|
|
|
740
740
|
### From React JSX
|
|
741
741
|
|
|
742
|
-
jsx
|
|
742
|
+
lit-jsx syntax is very similar to React, with a few key differences:
|
|
743
743
|
|
|
744
744
|
```tsx
|
|
745
745
|
// React
|
|
746
746
|
<button onClick={handler} className="btn" />
|
|
747
747
|
|
|
748
|
-
// jsx
|
|
748
|
+
// lit-jsx
|
|
749
749
|
<button on-click={handler} class="btn" />
|
|
750
750
|
```
|
|
751
751
|
|
|
@@ -755,13 +755,13 @@ jsx-lit syntax is very similar to React, with a few key differences:
|
|
|
755
755
|
// Lit html
|
|
756
756
|
html`<div class=${classMap(classes)}>${content}</div>`
|
|
757
757
|
|
|
758
|
-
// jsx
|
|
758
|
+
// lit-jsx
|
|
759
759
|
<div classList={classes}>{content}</div>
|
|
760
760
|
```
|
|
761
761
|
|
|
762
762
|
## 🤝 Contributing
|
|
763
763
|
|
|
764
|
-
jsx
|
|
764
|
+
lit-jsx is part of the larger Weave project. Contributions are welcome!
|
|
765
765
|
|
|
766
766
|
## 📄 License
|
|
767
767
|
|