literaljs 8.0.0 → 8.0.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 (2) hide show
  1. package/README.md +38 -18
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -21,24 +21,33 @@ npm install literaljs
21
21
  ```
22
22
 
23
23
  ```js
24
+ /** @jsx h */
24
25
  import { h, component, App } from 'literaljs';
25
26
 
26
27
  const Hello = component({
27
28
  name: 'Hello',
28
29
  state: { count: 0 },
29
30
  render() {
30
- return h('div', {}, [
31
- h('p', {}, `Count: ${this.getState().count}`),
32
- h('button', {
33
- events: { click: () => this.setState({ count: this.getState().count + 1 }) }
34
- }, 'Increment')
35
- ]);
31
+ const { count } = this.getState();
32
+ return (
33
+ <div>
34
+ <p>Count: {count}</p>
35
+ <button events={{ click: () => this.setState({ count: count + 1 }) }}>
36
+ Increment
37
+ </button>
38
+ </div>
39
+ );
36
40
  }
37
41
  });
38
42
 
39
43
  new App(Hello, {}).mount('app');
40
44
  ```
41
45
 
46
+ > **JSX setup**: Configure your build tool to use `h` as the JSX pragma. Babel example:
47
+ > ```json
48
+ > { "plugins": [["@babel/plugin-transform-react-jsx", { "pragma": "h" }]] }
49
+ > ```
50
+
42
51
  ### CDN (UMD)
43
52
 
44
53
  ```html
@@ -55,7 +64,7 @@ new App(Hello, {}).mount('app');
55
64
 
56
65
  | Export | Purpose |
57
66
  |--------|---------|
58
- | `h(tag, attrs, ...children)` | Create VNode (JSX/Hyperscript/Object syntax) |
67
+ | `h(tag, attrs, ...children)` | Create VNode (Hyperscript/Object syntax, or JSX pragma) |
59
68
  | `component(config)` | Define a component with state, methods, lifecycle |
60
69
  | `new App(rootComponent, initialStore)` | Create an app instance |
61
70
  | `app.mount(domId)` | Mount to a DOM element |
@@ -124,7 +133,7 @@ Build target: Chrome 90+, Firefox 90+, Safari 14+ (ES2018). No `Object.assign` p
124
133
  - **Fast** — Keyed diffing, WeakMap event delegation, render memoization
125
134
  - **Simple** — Plain functions + structured components. No classes, no hooks, no magic.
126
135
  - **Virtual DOM** — Diffed updates only on state change
127
- - **Flexible Syntax** — JSX, Hyperscript (`h()`), or Object syntax
136
+ - **Flexible Syntax** — JSX (with `h` pragma), Hyperscript, or Object syntax
128
137
  - **Lifecycle Methods** — `mounted`, `updated`, `unmounted`
129
138
  - **Global + Component State** — Built-in store; no Redux needed
130
139
  - **Event Delegation** — Most events delegated to root for performance
@@ -135,6 +144,9 @@ Build target: Chrome 90+, Firefox 90+, Safari 14+ (ES2018). No `Object.assign` p
135
144
  ## Component API
136
145
 
137
146
  ```js
147
+ /** @jsx h */
148
+ import { h, component, App } from 'literaljs';
149
+
138
150
  const MyComponent = component({
139
151
  name: 'MyComponent', // Required, for debugging
140
152
  state: { count: 0 }, // Initial component state
@@ -148,23 +160,28 @@ const MyComponent = component({
148
160
  unmounted() { console.log('unmounted'); },
149
161
  render() {
150
162
  const { count } = this.getState();
151
- return h('div', {}, [
152
- h('p', {}, `Count: ${count}`),
153
- h('button', { events: { click: () => this.increment() } }, 'Add')
154
- ]);
163
+ return (
164
+ <div>
165
+ <p>Count: {count}</p>
166
+ <button events={{ click: () => this.increment() }}>Add</button>
167
+ </div>
168
+ );
155
169
  }
156
170
  });
171
+
172
+ new App(MyComponent, {}).mount('app');
157
173
  ```
158
174
 
159
175
  ### Props
160
176
 
161
177
  ```js
178
+ /** @jsx h */
162
179
  // Parent passes props
163
- h(MyComponent, { key: 'unique', title: 'Hello' })
180
+ <MyComponent key="unique" title="Hello" />
164
181
 
165
182
  // Child accesses via this.props
166
183
  render() {
167
- return h('h1', {}, this.props.title);
184
+ return <h1>{this.props.title}</h1>;
168
185
  }
169
186
  ```
170
187
 
@@ -173,9 +190,12 @@ render() {
173
190
  Use `key` for list items to enable DOM identity preservation:
174
191
 
175
192
  ```js
176
- h('ul', {}, items.map(item =>
177
- h('li', { key: item.id }, item.name)
178
- ));
193
+ /** @jsx h */
194
+ <ul>
195
+ {items.map(item => (
196
+ <li key={item.id}>{item.name}</li>
197
+ ))}
198
+ </ul>
179
199
  ```
180
200
 
181
201
  ---
@@ -198,7 +218,7 @@ this.setStore({ theme: 'dark' }); // Update global store
198
218
  // Access in render
199
219
  render() {
200
220
  const theme = this.getStore().theme;
201
- return h('div', { class: theme }, ...);
221
+ return <div class={theme}>...</div>;
202
222
  }
203
223
  ```
204
224
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "literaljs",
3
- "version": "8.0.0",
3
+ "version": "8.0.1",
4
4
  "description": "A small JavaScript library for building reactive user interfaces.",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.m.js",