apprun 3.38.0 → 6.0.0-rc.0
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/CHANGELOG.md +12 -1
- package/README.md +18 -10
- package/apprun.d.ts +67 -23
- package/dist/apprun-code.js +1 -1
- package/dist/apprun-code.js.map +1 -1
- package/dist/apprun-dev-tools.js +1 -1
- package/dist/apprun-dev-tools.js.map +1 -1
- package/dist/apprun-html.esm.js +7 -7
- package/dist/apprun-html.esm.js.map +1 -1
- package/dist/apprun-html.js +1 -1
- package/dist/apprun-html.js.map +1 -1
- package/dist/apprun-play.js +1 -1
- package/dist/apprun-play.js.map +1 -1
- package/dist/apprun.esm.js +1 -1
- package/dist/apprun.esm.js.map +1 -1
- package/dist/apprun.js +1 -1
- package/dist/apprun.js.map +1 -1
- package/esm/add-components.js +7 -7
- package/esm/add-components.js.map +1 -1
- package/esm/app.js +81 -32
- package/esm/app.js.map +1 -1
- package/esm/apprun-code.js +8 -2
- package/esm/apprun-code.js.map +1 -1
- package/esm/apprun-html.js +14 -9
- package/esm/apprun-html.js.map +1 -1
- package/esm/apprun-play.js +7 -1
- package/esm/apprun-play.js.map +1 -1
- package/esm/apprun.js +38 -19
- package/esm/apprun.js.map +1 -1
- package/esm/component.js +90 -37
- package/esm/component.js.map +1 -1
- package/esm/directive.js +1 -1
- package/esm/directive.js.map +1 -1
- package/esm/router.js +73 -19
- package/esm/router.js.map +1 -1
- package/esm/types.js +2 -1
- package/esm/types.js.map +1 -1
- package/esm/vdom-my.js +52 -52
- package/esm/vdom-my.js.map +1 -1
- package/esm/vdom-to-html.js +8 -1
- package/esm/vdom-to-html.js.map +1 -1
- package/esm/vdom.js +3 -3
- package/esm/vdom.js.map +1 -1
- package/esm/version.js +1 -1
- package/esm/version.js.map +1 -1
- package/esm/web-component.js +23 -6
- package/esm/web-component.js.map +1 -1
- package/jsx-runtime.js +1 -1
- package/jsx-runtime.js.map +1 -1
- package/package.json +62 -2
- package/.clinerules +0 -1
- package/.travis.yml +0 -10
- package/BACKERS.md +0 -8
- package/CNAME +0 -1
- package/WHATSNEW.md +0 -367
- package/ai/apprun-html.prompt.md +0 -290
- package/ai/apprun.prompt.md +0 -602
- package/apprun-book.jpg +0 -0
- package/dist/apprun-dev-tools-tests.js +0 -1
- package/dist/apprun-dev-tools.js.LICENSE.txt +0 -1
- package/dist/apprun-play-html.esm.js +0 -34
- package/dist/apprun-play-html.esm.js.map +0 -1
- package/error.log +0 -0
- package/esm/apprun-play-html.js +0 -210
- package/esm/apprun-play-html.js.map +0 -1
- package/esm/shadow.js +0 -8
- package/esm/shadow.js.map +0 -1
- package/esm/vdom-html.js +0 -22
- package/esm/vdom-html.js.map +0 -1
- package/esm/vdom-my-new.js +0 -327
- package/esm/vdom-my-new.js.map +0 -1
- package/esm/vdom-patch.js +0 -103
- package/esm/vdom-patch.js.map +0 -1
- package/index.html +0 -87
- package/jest.config.js +0 -57
- package/jest.setup.js +0 -73
- package/logo.png +0 -0
- package/react.js +0 -13
- package/rollup.config.js +0 -62
- package/src/add-components.ts +0 -103
- package/src/app.ts +0 -173
- package/src/apprun-code.tsx +0 -177
- package/src/apprun-dev-tools-tests.tsx +0 -101
- package/src/apprun-dev-tools.tsx +0 -307
- package/src/apprun-html.ts +0 -25
- package/src/apprun-play.tsx +0 -249
- package/src/apprun.ts +0 -238
- package/src/component.ts +0 -388
- package/src/createState.ts +0 -11
- package/src/decorator.ts +0 -98
- package/src/directive.ts +0 -303
- package/src/global.d.ts +0 -22
- package/src/router.ts +0 -311
- package/src/shadow.tsx +0 -8
- package/src/tsconfig.json +0 -16
- package/src/type-utils.ts +0 -130
- package/src/types.ts +0 -151
- package/src/vdom-html.ts_ +0 -20
- package/src/vdom-lit-html.ts +0 -67
- package/src/vdom-my-new.ts +0 -311
- package/src/vdom-my-prop-attr.ts +0 -241
- package/src/vdom-my.ts +0 -286
- package/src/vdom-patch.ts +0 -108
- package/src/vdom-to-html.tsx +0 -49
- package/src/vdom.ts +0 -28
- package/src/version.ts +0 -16
- package/src/web-component.ts +0 -154
- package/tsconfig.jest.json +0 -49
- package/tsconfig.json +0 -16
- package/tslint.json +0 -114
- package/typescriptreact.json +0 -87
- package/viewEngine.js +0 -54
- package/webpack.config.cjs +0 -41
package/ai/apprun-html.prompt.md
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
mode: agent
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# AppRun Component Creation Rules
|
|
6
|
-
|
|
7
|
-
When creating AppRun components, follow these guidelines for consistent, maintainable code.
|
|
8
|
-
|
|
9
|
-
## Core Component Architecture
|
|
10
|
-
- **HTML templates**: Always use `html` tagged literals for UI rendering
|
|
11
|
-
- **State management**: Handle state through event handlers that return new state objects
|
|
12
|
-
- **Event handling**: Use `event-name` syntax in templates with handlers `(state, param) => newState`
|
|
13
|
-
- **Local events**: Use `run()` for component-local events (no registration needed)
|
|
14
|
-
- **Immutable updates**: Always return new state objects, never mutate existing state
|
|
15
|
-
|
|
16
|
-
## Component Creation Patterns
|
|
17
|
-
|
|
18
|
-
### 1. Functional Components (Pure UI Components)
|
|
19
|
-
**When to use**: For reusable UI pieces that don't manage their own state.
|
|
20
|
-
|
|
21
|
-
```js
|
|
22
|
-
// Create pure function components that take props and return HTML
|
|
23
|
-
export const AgentModal = (agent, onClose) => {
|
|
24
|
-
return html`
|
|
25
|
-
<div class="modal-overlay" @click=${run(onClose, false)}>
|
|
26
|
-
<div class="modal-content" @click=${(e) => e.stopPropagation()}>
|
|
27
|
-
<!-- Use conditional rendering for dynamic content -->
|
|
28
|
-
${agent.status ? html`<h2>${agent.name}</h2>` : html`
|
|
29
|
-
<input value="${agent.name || ''}" @input=${(e) => agent.name = e.target.value}>
|
|
30
|
-
`}
|
|
31
|
-
</div>
|
|
32
|
-
</div>
|
|
33
|
-
`;
|
|
34
|
-
};
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
**Rules for functional components**:
|
|
38
|
-
- Export as pure functions
|
|
39
|
-
- Accept props as parameters
|
|
40
|
-
- Return HTML template literals
|
|
41
|
-
- Handle events through callback props
|
|
42
|
-
- No internal state management
|
|
43
|
-
|
|
44
|
-
### 2. Stateful Page Components (Full Components)
|
|
45
|
-
**When to use**: For main application views that manage state and handle complex interactions.
|
|
46
|
-
|
|
47
|
-
**Step 1: Create async state initialization**
|
|
48
|
-
```js
|
|
49
|
-
// Always use async state function for API calls and data loading
|
|
50
|
-
const state = async () => {
|
|
51
|
-
const data = await api.getData();
|
|
52
|
-
return {
|
|
53
|
-
...initialState,
|
|
54
|
-
data,
|
|
55
|
-
loading: false
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
**Step 2: Define event handlers as separate functions**
|
|
61
|
-
```js
|
|
62
|
-
// Create specific handlers for each user interaction
|
|
63
|
-
const selectWorld = async (state, worldName) => {
|
|
64
|
-
if (worldName === state.worldName) return state;
|
|
65
|
-
const agents = await api.getAgents(worldName);
|
|
66
|
-
return ({ ...state, worldName, agents });
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const openModal = (state, item = null) => {
|
|
70
|
-
return ({
|
|
71
|
-
...state,
|
|
72
|
-
editingItem: item || { name: 'New Item' },
|
|
73
|
-
showModal: true
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
**Step 3: Create view function with proper rendering patterns**
|
|
79
|
-
```js
|
|
80
|
-
// View function should be pure - only render, never mutate
|
|
81
|
-
const view = (state) => {
|
|
82
|
-
return html`
|
|
83
|
-
<div class="container">
|
|
84
|
-
${state.items.map(item => html`
|
|
85
|
-
<div class="item" @click=${run(openModal, item)}>
|
|
86
|
-
${item.name}
|
|
87
|
-
</div>
|
|
88
|
-
`)}
|
|
89
|
-
${state.showModal ? ModalComponent(state.editingItem, closeModal) : ''}
|
|
90
|
-
</div>
|
|
91
|
-
`;
|
|
92
|
-
};
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
**Step 4: Define minimal update object for routing**
|
|
96
|
-
```js
|
|
97
|
-
// Keep update object minimal - most events handled by run()
|
|
98
|
-
const update = {
|
|
99
|
-
'/,#': state => state,
|
|
100
|
-
// Only add global events or routing here
|
|
101
|
-
};
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
**Step 5: Export Component instance**
|
|
105
|
-
```js
|
|
106
|
-
// Create and export component instance without class syntax
|
|
107
|
-
// enable global events with {global_event: true}
|
|
108
|
-
export default new Component(state, view, update, {global_event: true});
|
|
109
|
-
|
|
110
|
-
// Mount to DOM element
|
|
111
|
-
component.start('#main'); // For visible components
|
|
112
|
-
component.mount('#modal'); // For modal/hidden components
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
## Event Handling Best Practices
|
|
116
|
-
|
|
117
|
-
### Using run() for Local Events
|
|
118
|
-
**✅ Correct patterns**:
|
|
119
|
-
```js
|
|
120
|
-
// Simple event with parameter
|
|
121
|
-
@click=${run(selectWorld, world.name)}
|
|
122
|
-
|
|
123
|
-
// Event with callback function
|
|
124
|
-
@click=${run(closeModal, false)}
|
|
125
|
-
|
|
126
|
-
// Global event
|
|
127
|
-
@input=${run('updateModalAgentName')}
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
**❌ Common mistakes to avoid**:
|
|
131
|
-
```js
|
|
132
|
-
// DON'T wrap run() in arrow function - prevents re-rendering
|
|
133
|
-
@click=${() => run(selectWorld, world.name)}
|
|
134
|
-
|
|
135
|
-
// DON'T manually pass event in arrow function
|
|
136
|
-
@click=${(e) => run(updateName, e)}
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### Event Handler Function Rules
|
|
140
|
-
```js
|
|
141
|
-
// Event handlers automatically receive event as last parameter
|
|
142
|
-
const updateModalAgentName = (state, eventParam) => {
|
|
143
|
-
const name = eventParam.target.value;
|
|
144
|
-
return ({...state, agentName: name });
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
// Handle event.stopPropagation() in handler when needed
|
|
148
|
-
const openAgentModal = (state, agent, e) => {
|
|
149
|
-
e.stopPropagation();
|
|
150
|
-
return ({...state, editingAgent: agent, showModal: true });
|
|
151
|
-
};
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
## Template Rendering Guidelines
|
|
156
|
-
|
|
157
|
-
### Conditional Rendering Patterns
|
|
158
|
-
```js
|
|
159
|
-
// Simple boolean conditions
|
|
160
|
-
${state.loading ? html`<div>Loading...</div>` : ''}
|
|
161
|
-
|
|
162
|
-
// Complex conditional with nested HTML blocks
|
|
163
|
-
${agent.status ? html`
|
|
164
|
-
<h2>${agent.name}</h2>
|
|
165
|
-
<p>Status: Active</p>
|
|
166
|
-
` : html`
|
|
167
|
-
<input value="${agent.name || ''}" @input=${run(updateName)}>
|
|
168
|
-
<button @click=${run(saveAgent)}>Save</button>
|
|
169
|
-
`}
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### List Rendering with map()
|
|
173
|
-
```js
|
|
174
|
-
// Basic list rendering
|
|
175
|
-
${state.items.map(item => html`
|
|
176
|
-
<div class="${item.active ? 'active' : ''}">${item.name}</div>
|
|
177
|
-
`)}
|
|
178
|
-
|
|
179
|
-
// Complex list items with events
|
|
180
|
-
${state.agents.map(agent => html`
|
|
181
|
-
<div class="agent-card" @click=${run(selectAgent, agent.id)}>
|
|
182
|
-
<h3>${agent.name}</h3>
|
|
183
|
-
<button @click=${run(editAgent, agent)}
|
|
184
|
-
@click=${(e) => e.stopPropagation()}>
|
|
185
|
-
Edit
|
|
186
|
-
</button>
|
|
187
|
-
</div>
|
|
188
|
-
`)}
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### Component Composition
|
|
192
|
-
```js
|
|
193
|
-
// Pass data and callbacks to child components
|
|
194
|
-
${state.showModal ? AgentModal(state.editingAgent, closeModal) : ''}
|
|
195
|
-
|
|
196
|
-
// Conditional component rendering with fallbacks
|
|
197
|
-
${state.currentView === 'list'
|
|
198
|
-
? AgentList(state.agents, selectAgent)
|
|
199
|
-
: AgentDetail(state.selectedAgent, goBack)
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
## State Management Rules
|
|
204
|
-
|
|
205
|
-
### Immutable State Updates
|
|
206
|
-
```js
|
|
207
|
-
// ✅ Always spread existing state for updates
|
|
208
|
-
return ({ ...state, newProperty: value });
|
|
209
|
-
|
|
210
|
-
// ✅ Update nested objects immutably
|
|
211
|
-
return ({
|
|
212
|
-
...state,
|
|
213
|
-
user: { ...state.user, name: newName },
|
|
214
|
-
items: [...state.items, newItem]
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
// ❌ Never mutate state directly
|
|
218
|
-
state.newProperty = value; // Wrong!
|
|
219
|
-
state.items.push(newItem); // Wrong!
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
### Async State Updates
|
|
223
|
-
```js
|
|
224
|
-
// Standard async handler
|
|
225
|
-
const handler = async (state, param) => {
|
|
226
|
-
try {
|
|
227
|
-
const data = await api.call(param);
|
|
228
|
-
return ({ ...state, data, loading: false });
|
|
229
|
-
} catch (error) {
|
|
230
|
-
return ({ ...state, error: error.message, loading: false });
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
// Generator for progressive updates
|
|
235
|
-
const handler = async function* (state, param) {
|
|
236
|
-
yield ({ ...state, loading: true });
|
|
237
|
-
try {
|
|
238
|
-
const data = await api.call(param);
|
|
239
|
-
yield ({ ...state, data, loading: false });
|
|
240
|
-
} catch (error) {
|
|
241
|
-
yield ({ ...state, error: error.message, loading: false });
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### Error Handling in Components
|
|
247
|
-
```js
|
|
248
|
-
// Always handle errors in async operations
|
|
249
|
-
const saveData = async (state, data) => {
|
|
250
|
-
try {
|
|
251
|
-
await api.saveData(data);
|
|
252
|
-
return ({ ...state, showModal: false, saved: true });
|
|
253
|
-
} catch (error) {
|
|
254
|
-
return ({ ...state, error: `Save failed: ${error.message}` });
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
## Component Creation Checklist
|
|
260
|
-
|
|
261
|
-
When creating any AppRun component, ensure you follow these rules:
|
|
262
|
-
|
|
263
|
-
### Essential Requirements
|
|
264
|
-
- ✅ **Event handlers must return new state** - No return = no re-render
|
|
265
|
-
- ✅ **View functions are pure** - Only render, never mutate state
|
|
266
|
-
- ✅ **Use `run()` for local events** - No registration needed in update object
|
|
267
|
-
- ✅ **Use `app.run()` for global events** - Cross-component communication
|
|
268
|
-
- ✅ **Immutable state updates** - Always spread existing state `{...state, newProp}`
|
|
269
|
-
- ✅ **HTML template literals** - Use `html` tagged templates for all UI
|
|
270
|
-
- ✅ **Conditional rendering** - Use ternary operators and template conditionals
|
|
271
|
-
|
|
272
|
-
### Component Structure Guidelines
|
|
273
|
-
- ✅ **Functional components**: Export pure functions that take props and return HTML
|
|
274
|
-
- ✅ **Stateful components**: Use async state, separate handlers, Component instance
|
|
275
|
-
- ✅ **Error boundaries**: Always handle async errors in try/catch blocks
|
|
276
|
-
- ✅ **Component composition**: Pass data and callbacks to child components
|
|
277
|
-
- ✅ **Event delegation**: Use event.stopPropagation() when needed in handlers
|
|
278
|
-
|
|
279
|
-
### File Organization
|
|
280
|
-
- ✅ **One component per file** - Keep components focused and reusable
|
|
281
|
-
- ✅ **Named exports for functions** - `export const ComponentName = (...) => html`
|
|
282
|
-
- ✅ **Default export for pages** - `export default new Component(...)`
|
|
283
|
-
- ✅ **Import dependencies** - Use static imports, omit `.js`/`.ts` extensions
|
|
284
|
-
|
|
285
|
-
### Performance Considerations
|
|
286
|
-
- ✅ **Minimal update object** - Only include routing and global events
|
|
287
|
-
- ✅ **Efficient rendering** - Use conditional rendering to avoid unnecessary DOM updates
|
|
288
|
-
- ✅ **State normalization** - Keep state flat when possible for easier updates
|
|
289
|
-
- ✅ **Event handler optimization** - Define handlers outside render when possible
|
|
290
|
-
|