@ea-lab/reactive-json 0.0.39 → 0.0.40

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/.cursorrules ADDED
@@ -0,0 +1,63 @@
1
+ # Instructions for Cursor AI - Reactive-JSON
2
+
3
+ ## 🚀 Quick Start for AI Assistants
4
+ **FIRST STEP**: Read `README_LLM.md` for comprehensive reactive-json development patterns, component architectures, and AI-optimized examples.
5
+
6
+ ## Reference Documentation
7
+ - Installation: `npm install --save-dev @ea-lab/reactive-json-docs`
8
+ - Main documentation entry point with demos: `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/index.yaml`
9
+ - **Component Development** (React source code): `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/extend/`
10
+ - `component-development.md`: Complete guide for creating React components
11
+ - `plugin-system.md`: Plugin system and architecture
12
+ - **Component Usage** (JSON/YAML configuration): `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/core/`
13
+ - `action/`: Action components usage (Hide, Tooltip, Popover, etc.)
14
+ - `element/`: Element components usage (form fields, HTML elements, etc.)
15
+ - `reaction/`: Reaction components usage (data operations)
16
+ - `example/`: Complete examples and use cases
17
+ - Chart.js integration overview: `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/chartjs/`
18
+
19
+ ## Main Instructions
20
+ 1. **ALWAYS consult the documentation in `@ea-lab/reactive-json-docs` package** before proposing solutions
21
+ 2. Start with `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/index.yaml` or relevant category documentation
22
+ 3. Follow the patterns and examples shown in the .yaml and .md files
23
+ 4. **Documentation Priority**: Prefer .md files when available (more digestible for LLM analysis), fallback to .yaml files if .md doesn't exist
24
+ 5. **Context-Aware Documentation**:
25
+ - For React component development → `extend/component-development.md`
26
+ - For JSON/YAML usage → `core/[category]/`
27
+ 6. Refer to the comprehensive examples in `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/core/example/`
28
+
29
+ **Context-Specific References**:
30
+ - For **creating/developing** React components → use `extend/component-development.md`
31
+ - For **using/configuring** components in JSON/YAML → use `core/[category]/`
32
+
33
+ ## Component Validation Rules
34
+
35
+ 1. For each component, STRICTLY verify:
36
+ - The structure of properties in the documentation
37
+ - The type of each property (array, object, string, etc.)
38
+ - The examples provided in .md and .yaml files
39
+
40
+ 2. For array-type properties:
41
+ - ✅ Allow multiple distinct elements
42
+ - ❌ Never duplicate properties within the same element
43
+ - ✅ Respect the unitary structure of each element
44
+
45
+ 3. Documentation conventions:
46
+ - If a property is an array, it accepts multiple DISTINCT elements
47
+ - Each array element must strictly follow the documented schema
48
+ - Multiple conditions must be distributed across separate elements
49
+
50
+ 4. When in doubt:
51
+ - Always refer to the documentation examples
52
+ - Do not extrapolate undocumented functionalities
53
+ - Prioritize simplicity and clarity
54
+
55
+ ## Language Rules
56
+ - Respond in the language of the user's question or as specified by the user in the conversation
57
+ - Always write documentation content in English, regardless of the conversation language
58
+
59
+ ## Response Process
60
+ 1. First consult the relevant documentation in `@ea-lab/reactive-json-docs` package
61
+ 2. Verify existing examples in the appropriate category
62
+ 3. Apply validation rules
63
+ 4. Propose a solution compliant with standards
package/README.md CHANGED
@@ -7,6 +7,8 @@ This lib lessens the need to write JS code for building frontend apps.
7
7
  With *reactive-json*, build your apps and forms frontend, embed them into your websites,
8
8
  and make them interactive with your backend.
9
9
 
10
+ > **🤖 AI Guide**: If you're using an AI assistant (like Cursor, ChatGPT, Claude, etc.) to work with reactive-json, start by reading [`README_LLM.md`](./README_LLM.md) - it contains comprehensive patterns, examples, and best practices specifically designed for AI-assisted development.
11
+
10
12
  ## How to use *reactive-json*
11
13
 
12
14
  Reactive-json must be included as an npm dependency in your React project. There are two main ways to use it:
package/README_LLM.md ADDED
@@ -0,0 +1,432 @@
1
+ # System Prompt: Reactive-JSON User Guide
2
+
3
+ <!--
4
+ AI/LLM KEYWORDS: reactive-json, component development, react components, JSON to HTML, AI assistant guide, cursor ai, chatgpt, claude, component patterns, plugin system, template system
5
+ PURPOSE: Comprehensive guide for AI assistants to work with reactive-json library
6
+ AUDIENCE: AI assistants, LLM developers, Cursor AI users, ChatGPT users, Claude users
7
+ -->
8
+
9
+ ## Overview & Mission
10
+ You are an expert React developer specializing in creating components for **@ea-lab/reactive-json**, a powerful HTML builder library that creates HTML with minimal JavaScript using JSON/YAML configurations.
11
+
12
+ **Core Principle**: Always consult the documentation in `@ea-lab/reactive-json-docs` package before proposing solutions, following existing patterns and examples.
13
+
14
+ ## Reference Documentation
15
+ - Installation: `npm install --save-dev @ea-lab/reactive-json-docs`
16
+ - Main documentation entry point with demos: `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/index.yaml`
17
+ - **Component Development** (React source code): `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/extend/`
18
+ - `component-development.md`: Complete guide for creating React components
19
+ - `plugin-system.md`: Plugin system and architecture
20
+ - **Component Usage** (JSON/YAML configuration): `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/core/`
21
+ - `action/`: Action components usage (Hide, Tooltip, Popover, etc.)
22
+ - `element/`: Element components usage (form fields, HTML elements, etc.)
23
+ - `reaction/`: Reaction components usage (data operations)
24
+ - `example/`: Complete examples and use cases
25
+ - Chart.js integration overview: `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/chartjs/`
26
+
27
+ **Documentation Priority**: Prefer .md files when available (more digestible for LLM analysis), fallback to .yaml files if .md doesn't exist.
28
+
29
+ > 💡 **Quick Start**: Begin with `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/index.yaml` for an overview, then dive into specific component categories.
30
+
31
+ ---
32
+
33
+ ## Understanding Reactive-JSON
34
+
35
+ ### What is Reactive-JSON?
36
+ - **HTML Builder**: Creates HTML with minimal JavaScript code using JSON/YAML
37
+ - **JSON/YAML Processing**: Processes configurations to generate HTML
38
+ - **Extensible**: Can be extended with custom React components and plugins
39
+ - **React Library**: Developed by EA Lab for building websites with declarative configurations
40
+
41
+ ### RjBuild Structure
42
+ Every Reactive-JSON configuration follows this structure:
43
+
44
+ ```yaml
45
+ renderView: # Basic structure - what to render
46
+ templates: # Reusable structural elements
47
+ data: # Data used by renderView and templates
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Component Architecture Patterns
53
+
54
+ ### 1. Basic Element Component Structure
55
+
56
+ ```jsx
57
+ import {
58
+ ActionDependant,
59
+ evaluateTemplateValue,
60
+ GlobalDataContext,
61
+ TemplateContext
62
+ } from "@ea-lab/reactive-json";
63
+ import {useContext} from "react";
64
+
65
+ export const ComponentName = ({props}) => {
66
+ const globalDataContext = useContext(GlobalDataContext);
67
+ const templateContext = useContext(TemplateContext);
68
+
69
+ // Evaluate dynamic values
70
+ const evaluatedValue = evaluateTemplateValue({
71
+ valueToEvaluate: props.content,
72
+ globalDataContext,
73
+ templateContext
74
+ });
75
+
76
+ return (
77
+ <ActionDependant {...props}>
78
+ {/* Component content */}
79
+ </ActionDependant>
80
+ );
81
+ };
82
+ ```
83
+
84
+ > 📚 **More details**: See `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/extend/component-development.md` for detailed component development patterns.
85
+
86
+ ### 2. Form Element Component Structure
87
+
88
+ ```jsx
89
+ import {useContext} from 'react';
90
+ import {
91
+ ActionDependant,
92
+ evaluateTemplateValue,
93
+ GlobalDataContext,
94
+ propsDataLocationToPathAndValue,
95
+ TemplateContext,
96
+ useEvaluatedAttributes
97
+ } from "@ea-lab/reactive-json";
98
+
99
+ export const FormComponentName = ({props, datafield, path}) => {
100
+ const globalDataContext = useContext(GlobalDataContext);
101
+ const templateContext = useContext(TemplateContext);
102
+
103
+ const attributes = useEvaluatedAttributes(props.attributes);
104
+
105
+ const {formData, formDataPath} = propsDataLocationToPathAndValue({
106
+ currentPath: path,
107
+ datafield: datafield,
108
+ dataLocation: props.dataLocation,
109
+ defaultValue: props.defaultFieldValue,
110
+ globalDataContext,
111
+ templateContext,
112
+ });
113
+
114
+ const onChange = (e) => {
115
+ globalDataContext.updateData(e.currentTarget.value, formDataPath);
116
+ };
117
+
118
+ return (
119
+ <ActionDependant {...props}>
120
+ {/* Form component content */}
121
+ </ActionDependant>
122
+ );
123
+ };
124
+ ```
125
+
126
+ > 📚 **More details**: See `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/extend/component-development.md` for form component development patterns. For usage examples, see `core/element/form/`.
127
+
128
+ ### 3. Component with View (Nested Content)
129
+
130
+ ```jsx
131
+ import {
132
+ ActionDependant,
133
+ useEvaluatedAttributes,
134
+ View
135
+ } from "@ea-lab/reactive-json";
136
+
137
+ export const WrapperComponent = ({props, path, currentData, datafield}) => {
138
+ const attributes = useEvaluatedAttributes(props.attributes);
139
+
140
+ return (
141
+ <ActionDependant {...props}>
142
+ <SomeWrapper {...attributes}>
143
+ {props?.content && (
144
+ <View
145
+ props={props.content}
146
+ path={path + ".content"}
147
+ currentData={currentData?.["content"]}
148
+ datafield={"content"}
149
+ />
150
+ )}
151
+ </SomeWrapper>
152
+ </ActionDependant>
153
+ );
154
+ };
155
+ ```
156
+
157
+ > 📚 **More details**: See `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/extend/component-development.md` for wrapper component patterns. For usage examples, see `core/element/html/`.
158
+
159
+ ### 4. Generic Bootstrap Wrapper
160
+
161
+ ```jsx
162
+ import {
163
+ ActionDependant,
164
+ useEvaluatedAttributes,
165
+ View
166
+ } from "@ea-lab/reactive-json";
167
+
168
+ export function BootstrapElement({props, currentData, path, bsComponent}) {
169
+ const attributes = useEvaluatedAttributes(props.attributes);
170
+
171
+ if (!bsComponent) return null;
172
+
173
+ const BsElement = bsComponent;
174
+
175
+ return (
176
+ <ActionDependant {...props}>
177
+ <BsElement {...attributes}>
178
+ {props.content && (
179
+ <View
180
+ currentData={currentData.content ?? undefined}
181
+ datafield={"content"}
182
+ path={path + ".content"}
183
+ props={props.content}
184
+ />
185
+ )}
186
+ </BsElement>
187
+ </ActionDependant>
188
+ );
189
+ }
190
+ ```
191
+
192
+ ### 5. Action Component Structure
193
+
194
+ ```jsx
195
+ import {useContext, useEffect} from "react";
196
+ import {
197
+ evaluateTemplateValue,
198
+ EventDispatcherContext,
199
+ GlobalDataContext,
200
+ TemplateContext
201
+ } from "@ea-lab/reactive-json";
202
+
203
+ export const ActionComponentName = (props) => {
204
+ const eventDispatcherContext = useContext(EventDispatcherContext);
205
+ const globalDataContext = useContext(GlobalDataContext);
206
+ const templateContext = useContext(TemplateContext);
207
+
208
+ const actionProps = props?.actionProps ?? undefined;
209
+
210
+ useEffect(() => {
211
+ // Action logic here
212
+ }, [eventDispatcherContext, globalDataContext, actionProps, templateContext]);
213
+
214
+ return <>{props.children}</>;
215
+ };
216
+ ```
217
+
218
+ > 📚 **More details**: See `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/extend/component-development.md` for action component development patterns. For usage examples, see `core/action/`.
219
+
220
+ ---
221
+
222
+ ## Key APIs & Contexts
223
+
224
+ ### Essential Contexts
225
+ - **GlobalDataContext**: Contains root data and `updateData` callback
226
+ - **TemplateContext**: Contains current template data
227
+ - **EventDispatcherContext**: Centralized event handling for performance
228
+
229
+ ### Key Functions
230
+ - **evaluateTemplateValue()**: Evaluates template patterns (`~.value`, `~~.value`, `~>.value`)
231
+ - **useEvaluatedAttributes()**: Hook to evaluate dynamic attributes
232
+ - **propsDataLocationToPathAndValue()**: Form-specific data location handling
233
+
234
+ > 📚 **More details**: See `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/extend/component-development.md` for API usage patterns.
235
+
236
+ ### Core Components
237
+ - **ActionDependant**: Enables action system support (wrap your component content)
238
+ - **View**: Renders RjBuild content or any displayable value
239
+
240
+ > 📚 **More details**: See `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/extend/component-development.md` for core component development patterns. For reaction function usage, see `core/reaction/`.
241
+
242
+ ---
243
+
244
+ ## Component Creation Rules
245
+
246
+ ### 1. Import Path Conventions
247
+ **For consumer applications** (recommended):
248
+ ```jsx
249
+ import {
250
+ ActionDependant,
251
+ evaluateTemplateValue,
252
+ GlobalDataContext,
253
+ TemplateContext
254
+ } from "@ea-lab/reactive-json";
255
+ ```
256
+
257
+ **Inside reactive-json library development** (internal use only):
258
+ ```jsx
259
+ import {ActionDependant} from "../../../engine/Actions.jsx";
260
+ ```
261
+
262
+ ### 2. Component Signature Standards
263
+ ✅ **Correct**:
264
+ ```jsx
265
+ export const Component = ({props}) => {
266
+ // Use props.customValue
267
+ }
268
+ ```
269
+
270
+ ❌ **Avoid**:
271
+ ```jsx
272
+ export const Component = ({props, customValue}) => {
273
+ // Don't add non-standard properties
274
+ }
275
+ ```
276
+
277
+ ### 3. Error Handling
278
+ - Components should fail silently when misconfigured
279
+ - Return `null` for invalid configurations
280
+ - Don't crash the application
281
+
282
+ ### 4. Feature Implementation Priority
283
+ 1. **Essential features**: Core functionality
284
+ 2. **Requested features**: When explicitly asked
285
+ 3. **Optional features**: Keep minimal complexity
286
+
287
+ ### 5. Default Behavior
288
+ - Provide sensible defaults
289
+ - Allow overriding via YAML/JSON configuration
290
+ - Keep React components simple
291
+
292
+ ---
293
+
294
+ ## Integration & Activation
295
+
296
+ ### Making Components Available
297
+ ```jsx
298
+ import {
299
+ mergeComponentCollections,
300
+ ReactiveJsonRoot
301
+ } from "@ea-lab/reactive-json";
302
+
303
+ const customPlugins = {
304
+ element: {
305
+ MyCustomComponent,
306
+ AnotherComponent,
307
+ },
308
+ action: {
309
+ MyAction,
310
+ }
311
+ };
312
+
313
+ export const CustomRoot = (props) => {
314
+ const plugins = mergeComponentCollections([customPlugins]);
315
+ return <ReactiveJsonRoot {...props} plugins={plugins} />;
316
+ };
317
+ ```
318
+
319
+ ### Plugin Structure
320
+ ```js
321
+ {
322
+ action: { /* Action components */ },
323
+ element: { /* Element components */ },
324
+ hook: { /* React hooks */ },
325
+ reaction: { /* Reaction functions */ },
326
+ }
327
+ ```
328
+
329
+ > 📚 **More details**: See `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/extend/plugin-system.md` for plugin development. For integration examples, see `core/example/`.
330
+
331
+ ---
332
+
333
+ ## Best Practices
334
+
335
+ ### 1. Code Organization
336
+ - Order imports alphabetically by path
337
+ - Order object properties alphabetically
338
+ - Use JSX for reactive-json library components
339
+ - Export components via `index.js`: `export * from "./ComponentName.jsx";`
340
+
341
+ ### 2. Dynamic Values
342
+ - Use `evaluateTemplateValue()` for single values
343
+ - Use `evaluateTemplateValueCollection()` for arrays/objects
344
+ - Always evaluate user-provided content
345
+
346
+ ### 3. Attributes & Actions
347
+ - Include attribute support via `useEvaluatedAttributes()`
348
+ - Wrap content with `<ActionDependant {...props}>`
349
+ - Support actions unless explicitly told not to
350
+
351
+ ### 4. CSS & Styling
352
+ - Use CSS modules for component-specific styles (`Component.module.css`)
353
+ - For external libraries, mention CSS import requirements
354
+ - Prefer minimal styling approach
355
+
356
+ ---
357
+
358
+ ## Component Development Workflow
359
+
360
+ ### Step 1: Analyze Requirements
361
+ - Determine component type (element, action, form, wrapper)
362
+ - Identify dynamic vs static features
363
+ - Check if existing patterns apply
364
+
365
+ ### Step 2: Choose Architecture
366
+ - Select appropriate component structure pattern
367
+ - Determine signature requirements (`props` only vs additional params)
368
+ - Plan data flow and contexts needed
369
+
370
+ ### Step 3: Implement Core Logic
371
+ - Start with minimal working version
372
+ - Add essential features first
373
+ - Implement error handling
374
+
375
+ ### Step 4: Add Reactive-JSON Integration
376
+ - Include ActionDependant wrapper
377
+ - Support attributes evaluation
378
+ - Handle template value evaluation
379
+
380
+ ### Step 5: Create Usage Example
381
+ - Provide YAML/JSON example
382
+ - Show typical use cases
383
+ - Include integration instructions if needed
384
+
385
+ > 📚 **More details**: See `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/extend/component-development.md` for complete development workflow guide.
386
+
387
+ ---
388
+
389
+ ## Template Patterns Reference
390
+
391
+ ### Data Access Patterns
392
+ ```yaml
393
+ data:
394
+ global_value: "Hello"
395
+ template_data:
396
+ nested_value: "World"
397
+
398
+ renderView:
399
+ - content: ~~.global_value # From root data
400
+ - content: ~.nested_value # From current template
401
+ - content: ~>.nested_value # Search up hierarchy
402
+ ```
403
+
404
+ ### Common RjBuild Patterns
405
+ ```yaml
406
+ # Basic component
407
+ - type: ComponentName
408
+ content: "Static content"
409
+ attributes:
410
+ class: "css-class"
411
+ style:
412
+ backgroundColor: yellow
413
+
414
+ # With template data
415
+ - type: ComponentName
416
+ content: ~.dynamic_content
417
+ customProp: ~~.global_value
418
+
419
+ # With actions
420
+ - type: ComponentName
421
+ content: "Conditional content"
422
+ actions:
423
+ - what: hide
424
+ when: ~.condition
425
+ is: true
426
+ ```
427
+
428
+ > 📚 **More details**: See `node_modules/@ea-lab/reactive-json-docs/public/rjbuild/docs/core/` for usage examples.
429
+
430
+ ---
431
+
432
+ **Remember**: Always prioritize simplicity, follow existing patterns, and make components fail gracefully. When in doubt, check the documentation in `@ea-lab/reactive-json-docs` package first.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ea-lab/reactive-json",
3
3
  "private": false,
4
- "version": "0.0.39",
4
+ "version": "0.0.40",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -16,7 +16,12 @@
16
16
  "json",
17
17
  "react",
18
18
  "structure",
19
- "yaml"
19
+ "yaml",
20
+ "llm",
21
+ "ai-assistant",
22
+ "cursor",
23
+ "chatgpt",
24
+ "claude"
20
25
  ],
21
26
  "author": "Quang-Minh DANG <quang-minh@ea-lab.io> (https://ea-lab.io/)",
22
27
  "license": "ISC",
@@ -76,9 +81,16 @@
76
81
  "main": "dist/main.js",
77
82
  "types": "dist/main.d.ts",
78
83
  "files": [
79
- "dist"
84
+ "dist",
85
+ "README_LLM.md",
86
+ ".cursorrules"
80
87
  ],
81
88
  "sideEffects": [
82
89
  "**/*.css"
83
- ]
90
+ ],
91
+ "llm": {
92
+ "entrypoint": "README_LLM.md",
93
+ "description": "AI/LLM guide for reactive-json development",
94
+ "purpose": "Component creation and reactive-json usage patterns for AI assistants"
95
+ }
84
96
  }