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.
Files changed (113) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/README.md +18 -10
  3. package/apprun.d.ts +67 -23
  4. package/dist/apprun-code.js +1 -1
  5. package/dist/apprun-code.js.map +1 -1
  6. package/dist/apprun-dev-tools.js +1 -1
  7. package/dist/apprun-dev-tools.js.map +1 -1
  8. package/dist/apprun-html.esm.js +7 -7
  9. package/dist/apprun-html.esm.js.map +1 -1
  10. package/dist/apprun-html.js +1 -1
  11. package/dist/apprun-html.js.map +1 -1
  12. package/dist/apprun-play.js +1 -1
  13. package/dist/apprun-play.js.map +1 -1
  14. package/dist/apprun.esm.js +1 -1
  15. package/dist/apprun.esm.js.map +1 -1
  16. package/dist/apprun.js +1 -1
  17. package/dist/apprun.js.map +1 -1
  18. package/esm/add-components.js +7 -7
  19. package/esm/add-components.js.map +1 -1
  20. package/esm/app.js +81 -32
  21. package/esm/app.js.map +1 -1
  22. package/esm/apprun-code.js +8 -2
  23. package/esm/apprun-code.js.map +1 -1
  24. package/esm/apprun-html.js +14 -9
  25. package/esm/apprun-html.js.map +1 -1
  26. package/esm/apprun-play.js +7 -1
  27. package/esm/apprun-play.js.map +1 -1
  28. package/esm/apprun.js +38 -19
  29. package/esm/apprun.js.map +1 -1
  30. package/esm/component.js +90 -37
  31. package/esm/component.js.map +1 -1
  32. package/esm/directive.js +1 -1
  33. package/esm/directive.js.map +1 -1
  34. package/esm/router.js +73 -19
  35. package/esm/router.js.map +1 -1
  36. package/esm/types.js +2 -1
  37. package/esm/types.js.map +1 -1
  38. package/esm/vdom-my.js +52 -52
  39. package/esm/vdom-my.js.map +1 -1
  40. package/esm/vdom-to-html.js +8 -1
  41. package/esm/vdom-to-html.js.map +1 -1
  42. package/esm/vdom.js +3 -3
  43. package/esm/vdom.js.map +1 -1
  44. package/esm/version.js +1 -1
  45. package/esm/version.js.map +1 -1
  46. package/esm/web-component.js +23 -6
  47. package/esm/web-component.js.map +1 -1
  48. package/jsx-runtime.js +1 -1
  49. package/jsx-runtime.js.map +1 -1
  50. package/package.json +62 -2
  51. package/.clinerules +0 -1
  52. package/.travis.yml +0 -10
  53. package/BACKERS.md +0 -8
  54. package/CNAME +0 -1
  55. package/WHATSNEW.md +0 -367
  56. package/ai/apprun-html.prompt.md +0 -290
  57. package/ai/apprun.prompt.md +0 -602
  58. package/apprun-book.jpg +0 -0
  59. package/dist/apprun-dev-tools-tests.js +0 -1
  60. package/dist/apprun-dev-tools.js.LICENSE.txt +0 -1
  61. package/dist/apprun-play-html.esm.js +0 -34
  62. package/dist/apprun-play-html.esm.js.map +0 -1
  63. package/error.log +0 -0
  64. package/esm/apprun-play-html.js +0 -210
  65. package/esm/apprun-play-html.js.map +0 -1
  66. package/esm/shadow.js +0 -8
  67. package/esm/shadow.js.map +0 -1
  68. package/esm/vdom-html.js +0 -22
  69. package/esm/vdom-html.js.map +0 -1
  70. package/esm/vdom-my-new.js +0 -327
  71. package/esm/vdom-my-new.js.map +0 -1
  72. package/esm/vdom-patch.js +0 -103
  73. package/esm/vdom-patch.js.map +0 -1
  74. package/index.html +0 -87
  75. package/jest.config.js +0 -57
  76. package/jest.setup.js +0 -73
  77. package/logo.png +0 -0
  78. package/react.js +0 -13
  79. package/rollup.config.js +0 -62
  80. package/src/add-components.ts +0 -103
  81. package/src/app.ts +0 -173
  82. package/src/apprun-code.tsx +0 -177
  83. package/src/apprun-dev-tools-tests.tsx +0 -101
  84. package/src/apprun-dev-tools.tsx +0 -307
  85. package/src/apprun-html.ts +0 -25
  86. package/src/apprun-play.tsx +0 -249
  87. package/src/apprun.ts +0 -238
  88. package/src/component.ts +0 -388
  89. package/src/createState.ts +0 -11
  90. package/src/decorator.ts +0 -98
  91. package/src/directive.ts +0 -303
  92. package/src/global.d.ts +0 -22
  93. package/src/router.ts +0 -311
  94. package/src/shadow.tsx +0 -8
  95. package/src/tsconfig.json +0 -16
  96. package/src/type-utils.ts +0 -130
  97. package/src/types.ts +0 -151
  98. package/src/vdom-html.ts_ +0 -20
  99. package/src/vdom-lit-html.ts +0 -67
  100. package/src/vdom-my-new.ts +0 -311
  101. package/src/vdom-my-prop-attr.ts +0 -241
  102. package/src/vdom-my.ts +0 -286
  103. package/src/vdom-patch.ts +0 -108
  104. package/src/vdom-to-html.tsx +0 -49
  105. package/src/vdom.ts +0 -28
  106. package/src/version.ts +0 -16
  107. package/src/web-component.ts +0 -154
  108. package/tsconfig.jest.json +0 -49
  109. package/tsconfig.json +0 -16
  110. package/tslint.json +0 -114
  111. package/typescriptreact.json +0 -87
  112. package/viewEngine.js +0 -54
  113. package/webpack.config.cjs +0 -41
@@ -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
-