@ea-lab/reactive-json-docs 0.1.3 → 0.1.5
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/package.json +3 -3
- package/public/rjbuild/docs/core/element/html/SyntaxHighlighter.yaml +293 -0
- package/public/rjbuild/docs/docs-components/SyntaxHighlighter.md +154 -0
- package/public/rjbuild/docs/docs-components/SyntaxHighlighter.yaml +167 -0
- package/public/rjbuild/docs/docs-components/index.md +28 -0
- package/public/rjbuild/docs/docs-components/index.yaml +35 -0
- package/public/rjbuild/docs/extend/component-development-guide-llm.md +383 -0
- package/public/rjbuild/docs/extend/component-development.md +193 -0
- package/public/rjbuild/docs/extend/component-development.yaml +215 -0
- package/public/rjbuild/docs/extend/index.md +20 -0
- package/public/rjbuild/docs/extend/index.yaml +29 -0
- package/public/rjbuild/docs/extend/plugin-system.md +142 -0
- package/public/rjbuild/docs/extend/plugin-system.yaml +147 -0
- package/public/rjbuild/docs/index.yaml +60 -6
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
# System Prompt: Reactive-JSON Component Creation Guide
|
|
2
|
+
|
|
3
|
+
## Overview & Mission
|
|
4
|
+
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.
|
|
5
|
+
|
|
6
|
+
**Core Principle**: Always consult the documentation in `public/rjbuild/docs/` before proposing solutions, following existing patterns and examples.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Understanding Reactive-JSON
|
|
11
|
+
|
|
12
|
+
### What is Reactive-JSON?
|
|
13
|
+
- **HTML Builder**: Creates HTML with minimal JavaScript code using JSON/YAML
|
|
14
|
+
- **JSON/YAML Processing**: Processes configurations to generate HTML
|
|
15
|
+
- **Extensible**: Can be extended with custom React components and plugins
|
|
16
|
+
- **React Library**: Developed by EA Lab for building websites with declarative configurations
|
|
17
|
+
|
|
18
|
+
### RjBuild Structure
|
|
19
|
+
Every Reactive-JSON configuration follows this structure:
|
|
20
|
+
|
|
21
|
+
```yaml
|
|
22
|
+
renderView: # Basic structure - what to render
|
|
23
|
+
templates: # Reusable structural elements
|
|
24
|
+
data: # Data used by renderView and templates
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Component Architecture Patterns
|
|
30
|
+
|
|
31
|
+
### 1. Basic Element Component Structure
|
|
32
|
+
|
|
33
|
+
```jsx
|
|
34
|
+
import {ActionDependant} from "@ea-lab/reactive-json/dist/engine";
|
|
35
|
+
import {GlobalDataContext} from "@ea-lab/reactive-json/dist/engine";
|
|
36
|
+
import {TemplateContext} from "@ea-lab/reactive-json/dist/engine";
|
|
37
|
+
import {evaluateTemplateValue} from "@ea-lab/reactive-json/dist/engine";
|
|
38
|
+
import {useContext} from "react";
|
|
39
|
+
|
|
40
|
+
export const ComponentName = ({props}) => {
|
|
41
|
+
const globalDataContext = useContext(GlobalDataContext);
|
|
42
|
+
const templateContext = useContext(TemplateContext);
|
|
43
|
+
|
|
44
|
+
// Evaluate dynamic values
|
|
45
|
+
const evaluatedValue = evaluateTemplateValue({
|
|
46
|
+
valueToEvaluate: props.content,
|
|
47
|
+
globalDataContext,
|
|
48
|
+
templateContext
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<ActionDependant {...props}>
|
|
53
|
+
{/* Component content */}
|
|
54
|
+
</ActionDependant>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 2. Form Element Component Structure
|
|
60
|
+
|
|
61
|
+
```jsx
|
|
62
|
+
import {useContext} from 'react';
|
|
63
|
+
import {GlobalDataContext} from "@ea-lab/reactive-json/dist/engine";
|
|
64
|
+
import {ActionDependant} from "@ea-lab/reactive-json/dist/engine";
|
|
65
|
+
import {TemplateContext} from "@ea-lab/reactive-json/dist/engine";
|
|
66
|
+
import {evaluateTemplateValue, useEvaluatedAttributes} from "@ea-lab/reactive-json/dist/engine";
|
|
67
|
+
import {propsDataLocationToPathAndValue} from "@ea-lab/reactive-json/dist/engine";
|
|
68
|
+
|
|
69
|
+
export const FormComponentName = ({props, datafield, path}) => {
|
|
70
|
+
const globalDataContext = useContext(GlobalDataContext);
|
|
71
|
+
const templateContext = useContext(TemplateContext);
|
|
72
|
+
|
|
73
|
+
const attributes = useEvaluatedAttributes(props.attributes);
|
|
74
|
+
|
|
75
|
+
const {formData, formDataPath} = propsDataLocationToPathAndValue({
|
|
76
|
+
currentPath: path,
|
|
77
|
+
datafield: datafield,
|
|
78
|
+
dataLocation: props.dataLocation,
|
|
79
|
+
defaultValue: props.defaultFieldValue,
|
|
80
|
+
globalDataContext,
|
|
81
|
+
templateContext,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const onChange = (e) => {
|
|
85
|
+
globalDataContext.updateData(e.currentTarget.value, formDataPath);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<ActionDependant {...props}>
|
|
90
|
+
{/* Form component content */}
|
|
91
|
+
</ActionDependant>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 3. Component with View (Nested Content)
|
|
97
|
+
|
|
98
|
+
```jsx
|
|
99
|
+
import {View} from "@ea-lab/reactive-json/dist/engine";
|
|
100
|
+
import {useEvaluatedAttributes} from "@ea-lab/reactive-json/dist/engine";
|
|
101
|
+
import {ActionDependant} from "@ea-lab/reactive-json/dist/engine";
|
|
102
|
+
|
|
103
|
+
export const WrapperComponent = ({props, path, currentData, datafield}) => {
|
|
104
|
+
const attributes = useEvaluatedAttributes(props.attributes);
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<ActionDependant {...props}>
|
|
108
|
+
<SomeWrapper {...attributes}>
|
|
109
|
+
{props?.content && (
|
|
110
|
+
<View
|
|
111
|
+
props={props.content}
|
|
112
|
+
path={path + ".content"}
|
|
113
|
+
currentData={currentData?.["content"]}
|
|
114
|
+
datafield={"content"}
|
|
115
|
+
/>
|
|
116
|
+
)}
|
|
117
|
+
</SomeWrapper>
|
|
118
|
+
</ActionDependant>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 4. Generic Bootstrap Wrapper
|
|
124
|
+
|
|
125
|
+
```jsx
|
|
126
|
+
import {ActionDependant} from "@ea-lab/reactive-json/dist/engine";
|
|
127
|
+
import {View} from "@ea-lab/reactive-json/dist/engine";
|
|
128
|
+
import {useEvaluatedAttributes} from "@ea-lab/reactive-json/dist/engine";
|
|
129
|
+
|
|
130
|
+
export function BootstrapElement({props, currentData, path, bsComponent}) {
|
|
131
|
+
const attributes = useEvaluatedAttributes(props.attributes);
|
|
132
|
+
|
|
133
|
+
if (!bsComponent) return null;
|
|
134
|
+
|
|
135
|
+
const BsElement = bsComponent;
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<ActionDependant {...props}>
|
|
139
|
+
<BsElement {...attributes}>
|
|
140
|
+
{props.content && (
|
|
141
|
+
<View
|
|
142
|
+
currentData={currentData.content ?? undefined}
|
|
143
|
+
datafield={"content"}
|
|
144
|
+
path={path + ".content"}
|
|
145
|
+
props={props.content}
|
|
146
|
+
/>
|
|
147
|
+
)}
|
|
148
|
+
</BsElement>
|
|
149
|
+
</ActionDependant>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 5. Action Component Structure
|
|
155
|
+
|
|
156
|
+
```jsx
|
|
157
|
+
import {useContext, useEffect} from "react";
|
|
158
|
+
import {EventDispatcherContext} from "@ea-lab/reactive-json/dist/engine";
|
|
159
|
+
import {GlobalDataContext} from "@ea-lab/reactive-json/dist/engine";
|
|
160
|
+
import {TemplateContext} from "@ea-lab/reactive-json/dist/engine";
|
|
161
|
+
import {evaluateTemplateValue} from "@ea-lab/reactive-json/dist/engine";
|
|
162
|
+
|
|
163
|
+
export const ActionComponentName = (props) => {
|
|
164
|
+
const eventDispatcherContext = useContext(EventDispatcherContext);
|
|
165
|
+
const globalDataContext = useContext(GlobalDataContext);
|
|
166
|
+
const templateContext = useContext(TemplateContext);
|
|
167
|
+
|
|
168
|
+
const actionProps = props?.actionProps ?? undefined;
|
|
169
|
+
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
// Action logic here
|
|
172
|
+
}, [eventDispatcherContext, globalDataContext, actionProps, templateContext]);
|
|
173
|
+
|
|
174
|
+
return <>{props.children}</>;
|
|
175
|
+
};
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Key APIs & Contexts
|
|
181
|
+
|
|
182
|
+
### Essential Contexts
|
|
183
|
+
- **GlobalDataContext**: Contains root data and `updateData` callback
|
|
184
|
+
- **TemplateContext**: Contains current template data
|
|
185
|
+
|
|
186
|
+
Other specialized contexts are available.
|
|
187
|
+
- **EventDispatcherContext**: Centralized event handling system, mostly used by the reaction system.
|
|
188
|
+
- **PaginationContext**: Used by components that integrate pagination, such as Switch.
|
|
189
|
+
|
|
190
|
+
### Key Functions
|
|
191
|
+
- **evaluateTemplateValue()**: Evaluates template patterns (`~.value`, `~~.value`, `~>.value`)
|
|
192
|
+
- **useEvaluatedAttributes()**: Hook to evaluate dynamic attributes
|
|
193
|
+
- **propsDataLocationToPathAndValue()**: Form-specific data location handling
|
|
194
|
+
|
|
195
|
+
### Core Components
|
|
196
|
+
- **ActionDependant**: Enables action system support (wrap your component content)
|
|
197
|
+
- **View**: Renders RjBuild content or any displayable value
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Component Creation Rules
|
|
202
|
+
|
|
203
|
+
### 1. Import Path Conventions
|
|
204
|
+
|
|
205
|
+
**Consumer application** (package imports - **RECOMMENDED**):
|
|
206
|
+
```jsx
|
|
207
|
+
import {ActionDependant} from "@ea-lab/reactive-json/dist/engine";
|
|
208
|
+
import {GlobalDataContext} from "@ea-lab/reactive-json/dist/engine";
|
|
209
|
+
import {View} from "@ea-lab/reactive-json/dist/engine";
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**Inside reactive-json library** (relative paths - **INTERNAL COMPONENTS ONLY**):
|
|
213
|
+
```jsx
|
|
214
|
+
// ⚠️ WARNING: Use this ONLY for component development
|
|
215
|
+
// inside the reactive-json package itself
|
|
216
|
+
import {ActionDependant} from "../../../engine/Actions.jsx";
|
|
217
|
+
import {GlobalDataContext} from "../../../engine/GlobalDataContext.jsx";
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
> **Important Note**: The relative path syntax (`../../../engine/`) is reserved for developing internal components within the reactive-json package. For all other use cases, use package imports with `@ea-lab/reactive-json/dist/engine`.
|
|
221
|
+
|
|
222
|
+
### 2. Component Signature Standards
|
|
223
|
+
✅ **Correct**:
|
|
224
|
+
```jsx
|
|
225
|
+
export const Component = ({props}) => {
|
|
226
|
+
// Use props.customValue
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
❌ **Avoid**:
|
|
231
|
+
```jsx
|
|
232
|
+
export const Component = ({props, customValue}) => {
|
|
233
|
+
// Don't add non-standard properties
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### 3. Error Handling
|
|
238
|
+
- Components should fail silently when misconfigured
|
|
239
|
+
- Return `null` for invalid configurations
|
|
240
|
+
- Don't crash the application
|
|
241
|
+
|
|
242
|
+
### 4. Feature Implementation Priority
|
|
243
|
+
1. **Essential features**: Core functionality
|
|
244
|
+
2. **Requested features**: When explicitly asked
|
|
245
|
+
3. **Optional features**: Keep minimal complexity
|
|
246
|
+
|
|
247
|
+
### 5. Default Behavior
|
|
248
|
+
- Provide sensible defaults
|
|
249
|
+
- Allow overriding via YAML/JSON configuration
|
|
250
|
+
- Keep React components simple
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## Integration & Activation
|
|
255
|
+
|
|
256
|
+
### Making Components Available
|
|
257
|
+
```jsx
|
|
258
|
+
import {ReactiveJsonRoot, mergeComponentCollections} from "@ea-lab/reactive-json";
|
|
259
|
+
|
|
260
|
+
const customPlugins = {
|
|
261
|
+
element: {
|
|
262
|
+
MyCustomComponent,
|
|
263
|
+
AnotherComponent,
|
|
264
|
+
},
|
|
265
|
+
action: {
|
|
266
|
+
MyAction,
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
export const CustomRoot = (props) => {
|
|
271
|
+
const plugins = mergeComponentCollections([customPlugins]);
|
|
272
|
+
return <ReactiveJsonRoot {...props} plugins={plugins} />;
|
|
273
|
+
};
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Plugin Structure
|
|
277
|
+
```js
|
|
278
|
+
{
|
|
279
|
+
action: { /* Action components */ },
|
|
280
|
+
element: { /* Element components */ },
|
|
281
|
+
hook: { /* React hooks */ },
|
|
282
|
+
reaction: { /* Reaction functions */ },
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Best Practices
|
|
289
|
+
|
|
290
|
+
### 1. Code Organization
|
|
291
|
+
- Order imports alphabetically by path
|
|
292
|
+
- Order object properties alphabetically
|
|
293
|
+
- Use JSX for reactive-json library components
|
|
294
|
+
- Export components via `index.js`: `export * from "./ComponentName.jsx";`
|
|
295
|
+
|
|
296
|
+
### 2. Dynamic Values
|
|
297
|
+
- Use `evaluateTemplateValue()` for single values
|
|
298
|
+
- Use `evaluateTemplateValueCollection()` for arrays/objects
|
|
299
|
+
- Always evaluate user-provided content
|
|
300
|
+
|
|
301
|
+
### 3. Attributes & Actions
|
|
302
|
+
- Include attribute support via `useEvaluatedAttributes()`
|
|
303
|
+
- Wrap content with `<ActionDependant {...props}>`
|
|
304
|
+
- Support actions unless explicitly told not to
|
|
305
|
+
|
|
306
|
+
### 4. CSS & Styling
|
|
307
|
+
- Use CSS modules for component-specific styles (`Component.module.css`)
|
|
308
|
+
- For external libraries, mention CSS import requirements
|
|
309
|
+
- Prefer minimal styling approach
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## Component Development Workflow
|
|
314
|
+
|
|
315
|
+
### Step 1: Analyze Requirements
|
|
316
|
+
- Determine component type (element, action, form, wrapper)
|
|
317
|
+
- Identify dynamic vs static features
|
|
318
|
+
- Check if existing patterns apply
|
|
319
|
+
|
|
320
|
+
### Step 2: Choose Architecture
|
|
321
|
+
- Select appropriate component structure pattern
|
|
322
|
+
- Determine signature requirements (`props` only vs additional params)
|
|
323
|
+
- Plan data flow and contexts needed
|
|
324
|
+
|
|
325
|
+
### Step 3: Implement Core Logic
|
|
326
|
+
- Start with minimal working version
|
|
327
|
+
- Add essential features first
|
|
328
|
+
- Implement error handling
|
|
329
|
+
|
|
330
|
+
### Step 4: Add Reactive-JSON Integration
|
|
331
|
+
- Include ActionDependant wrapper
|
|
332
|
+
- Support attributes evaluation
|
|
333
|
+
- Handle template value evaluation
|
|
334
|
+
|
|
335
|
+
### Step 5: Create Usage Example
|
|
336
|
+
- Provide YAML/JSON example
|
|
337
|
+
- Show typical use cases
|
|
338
|
+
- Include integration instructions if needed
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## Template Patterns Reference
|
|
343
|
+
|
|
344
|
+
### Data Access Patterns
|
|
345
|
+
```yaml
|
|
346
|
+
data:
|
|
347
|
+
global_value: "Hello"
|
|
348
|
+
template_data:
|
|
349
|
+
nested_value: "World"
|
|
350
|
+
|
|
351
|
+
renderView:
|
|
352
|
+
- content: ~~.global_value # From root data
|
|
353
|
+
- content: ~.nested_value # From current template
|
|
354
|
+
- content: ~>.nested_value # Search up hierarchy
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### Common RjBuild Patterns
|
|
358
|
+
```yaml
|
|
359
|
+
# Basic component
|
|
360
|
+
- type: ComponentName
|
|
361
|
+
content: "Static content"
|
|
362
|
+
attributes:
|
|
363
|
+
class: "css-class"
|
|
364
|
+
style:
|
|
365
|
+
backgroundColor: yellow
|
|
366
|
+
|
|
367
|
+
# With template data
|
|
368
|
+
- type: ComponentName
|
|
369
|
+
content: ~.dynamic_content
|
|
370
|
+
customProp: ~~.global_value
|
|
371
|
+
|
|
372
|
+
# With actions
|
|
373
|
+
- type: ComponentName
|
|
374
|
+
content: "Conditional content"
|
|
375
|
+
actions:
|
|
376
|
+
- what: hide
|
|
377
|
+
when: ~.condition
|
|
378
|
+
is: true
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
---
|
|
382
|
+
|
|
383
|
+
**Remember**: Always prioritize simplicity, follow existing patterns, and make components fail gracefully. When in doubt, check the documentation in `public/rjbuild/docs/` first.
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# Component Development Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Creating custom components for Reactive-JSON involves building React components that follow specific patterns and integrate with the library's context system. This guide covers the essential patterns, APIs, and best practices for component development.
|
|
6
|
+
|
|
7
|
+
## Core Concepts
|
|
8
|
+
|
|
9
|
+
### Component Architecture
|
|
10
|
+
Reactive-JSON components follow these key principles:
|
|
11
|
+
- **Context Integration**: Use React contexts for data access and manipulation
|
|
12
|
+
- **Template Evaluation**: Support dynamic values through template patterns
|
|
13
|
+
- **Action/reaction Support**: Enable the action system through proper wrapping
|
|
14
|
+
- **Consistent Props**: Follow standard property patterns for consistency
|
|
15
|
+
|
|
16
|
+
### Essential Contexts
|
|
17
|
+
All components have access to these React contexts:
|
|
18
|
+
- **GlobalDataContext**: Contains root data and `updateData` callback
|
|
19
|
+
- **TemplateContext**: Contains current template data for evaluation
|
|
20
|
+
|
|
21
|
+
Other specialized contexts are available.
|
|
22
|
+
- **EventDispatcherContext**: Centralized event handling system, mostly used by the [reaction system](/docs/core/reaction/index).
|
|
23
|
+
- **PaginationContext**: Used by components that integrate pagination, such as [Switch](/docs/core/element/special/Switch).
|
|
24
|
+
|
|
25
|
+
## Basic Element Component
|
|
26
|
+
|
|
27
|
+
This example shows the structure of a basic element component that displays content and supports the action system.
|
|
28
|
+
|
|
29
|
+
```jsx
|
|
30
|
+
import { ActionDependant } from "@ea-lab/reactive-json/dist/engine";
|
|
31
|
+
import { GlobalDataContext } from "@ea-lab/reactive-json/dist/engine";
|
|
32
|
+
import { TemplateContext } from "@ea-lab/reactive-json/dist/engine";
|
|
33
|
+
import { evaluateTemplateValue } from "@ea-lab/reactive-json/dist/engine";
|
|
34
|
+
import { useContext } from "react";
|
|
35
|
+
|
|
36
|
+
export const MyComponent = ({ props }) => {
|
|
37
|
+
const globalDataContext = useContext(GlobalDataContext);
|
|
38
|
+
const templateContext = useContext(TemplateContext);
|
|
39
|
+
|
|
40
|
+
// Evaluate dynamic values
|
|
41
|
+
const evaluatedContent = evaluateTemplateValue({
|
|
42
|
+
valueToEvaluate: props.content,
|
|
43
|
+
globalDataContext,
|
|
44
|
+
templateContext
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<ActionDependant {...props}>
|
|
49
|
+
<div className="my-component">
|
|
50
|
+
{evaluatedContent}
|
|
51
|
+
</div>
|
|
52
|
+
</ActionDependant>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Form Component Pattern
|
|
58
|
+
|
|
59
|
+
Form components handle user input and provide two-way data binding with the global data context.
|
|
60
|
+
|
|
61
|
+
```jsx
|
|
62
|
+
import { useContext } from 'react';
|
|
63
|
+
import { GlobalDataContext } from "@ea-lab/reactive-json/dist/engine";
|
|
64
|
+
import { ActionDependant } from "@ea-lab/reactive-json/dist/engine";
|
|
65
|
+
import { TemplateContext } from "@ea-lab/reactive-json/dist/engine";
|
|
66
|
+
import { useEvaluatedAttributes } from "@ea-lab/reactive-json/dist/engine";
|
|
67
|
+
import { propsDataLocationToPathAndValue } from "@ea-lab/reactive-json/dist/engine";
|
|
68
|
+
|
|
69
|
+
export const MyFormField = ({ props, datafield, path }) => {
|
|
70
|
+
const globalDataContext = useContext(GlobalDataContext);
|
|
71
|
+
const templateContext = useContext(TemplateContext);
|
|
72
|
+
|
|
73
|
+
const attributes = useEvaluatedAttributes(props.attributes);
|
|
74
|
+
|
|
75
|
+
const { formData, formDataPath } = propsDataLocationToPathAndValue({
|
|
76
|
+
currentPath: path,
|
|
77
|
+
datafield: datafield,
|
|
78
|
+
dataLocation: props.dataLocation,
|
|
79
|
+
defaultValue: props.defaultFieldValue,
|
|
80
|
+
globalDataContext,
|
|
81
|
+
templateContext,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const onChange = (e) => {
|
|
85
|
+
globalDataContext.updateData(e.currentTarget.value, formDataPath);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<ActionDependant {...props}>
|
|
90
|
+
<input
|
|
91
|
+
type="text"
|
|
92
|
+
value={formData || ''}
|
|
93
|
+
onChange={onChange}
|
|
94
|
+
{...attributes}
|
|
95
|
+
/>
|
|
96
|
+
</ActionDependant>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Component with Nested Content
|
|
102
|
+
|
|
103
|
+
Components that render nested RjBuild content use the View component to process child elements.
|
|
104
|
+
|
|
105
|
+
```jsx
|
|
106
|
+
import { View } from "@ea-lab/reactive-json/dist/engine";
|
|
107
|
+
import { useEvaluatedAttributes } from "@ea-lab/reactive-json/dist/engine";
|
|
108
|
+
import { ActionDependant } from "@ea-lab/reactive-json/dist/engine";
|
|
109
|
+
|
|
110
|
+
export const MyWrapper = ({ props, path, currentData, datafield }) => {
|
|
111
|
+
const attributes = useEvaluatedAttributes(props.attributes);
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<ActionDependant {...props}>
|
|
115
|
+
<div className="my-wrapper" {...attributes}>
|
|
116
|
+
{props?.content && (
|
|
117
|
+
<View
|
|
118
|
+
props={props.content}
|
|
119
|
+
path={path + ".content"}
|
|
120
|
+
currentData={currentData?.["content"]}
|
|
121
|
+
datafield={"content"}
|
|
122
|
+
/>
|
|
123
|
+
)}
|
|
124
|
+
</div>
|
|
125
|
+
</ActionDependant>
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Key APIs and Utilities
|
|
131
|
+
|
|
132
|
+
### Template Evaluation
|
|
133
|
+
- **evaluateTemplateValue()**: Evaluates template patterns like `~.value`, `~~.value`, `~>.value`
|
|
134
|
+
- **evaluateTemplateValueCollection()**: Evaluates collections and arrays with template patterns, supports multiple elements
|
|
135
|
+
- **useEvaluatedAttributes()**: Hook to evaluate dynamic attributes object
|
|
136
|
+
|
|
137
|
+
### Data Management
|
|
138
|
+
- **propsDataLocationToPathAndValue()**: Handles form data location and path resolution
|
|
139
|
+
- **GlobalDataContext.updateData()**: Updates data at specified path
|
|
140
|
+
|
|
141
|
+
### Component Integration
|
|
142
|
+
- **ActionDependant**: Wrapper that enables action system support
|
|
143
|
+
- **View**: Renders RjBuild content or any displayable value
|
|
144
|
+
|
|
145
|
+
## Action Component Pattern
|
|
146
|
+
|
|
147
|
+
Action components perform side effects and don't render visible content. They wrap their children and react to events or data changes. The conditional system (`when`, `is`, etc.) is handled by Actions.jsx, not by the action component itself.
|
|
148
|
+
|
|
149
|
+
```jsx
|
|
150
|
+
import { useContext, useEffect } from "react";
|
|
151
|
+
import { EventDispatcherContext } from "@ea-lab/reactive-json/dist/engine";
|
|
152
|
+
import { GlobalDataContext } from "@ea-lab/reactive-json/dist/engine";
|
|
153
|
+
import { TemplateContext } from "@ea-lab/reactive-json/dist/engine";
|
|
154
|
+
import { evaluateTemplateValue } from "@ea-lab/reactive-json/dist/engine";
|
|
155
|
+
|
|
156
|
+
export const MyAction = (props) => {
|
|
157
|
+
const eventDispatcherContext = useContext(EventDispatcherContext);
|
|
158
|
+
const globalDataContext = useContext(GlobalDataContext);
|
|
159
|
+
const templateContext = useContext(TemplateContext);
|
|
160
|
+
|
|
161
|
+
const actionProps = props?.actionProps ?? undefined;
|
|
162
|
+
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
// Action logic - this runs when Actions.jsx determines conditions are met
|
|
165
|
+
// No need to check conditions here, Actions.jsx handles that
|
|
166
|
+
if (actionProps?.targetElement) {
|
|
167
|
+
// Perform the action on the target element
|
|
168
|
+
actionProps.targetElement.style.display = 'none';
|
|
169
|
+
}
|
|
170
|
+
}, [actionProps, eventDispatcherContext, globalDataContext, templateContext]);
|
|
171
|
+
|
|
172
|
+
return <>{props.children}</>;
|
|
173
|
+
};
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Best Practices
|
|
177
|
+
|
|
178
|
+
### Component Guidelines
|
|
179
|
+
1. **Always wrap content with ActionDependant** to enable action system
|
|
180
|
+
2. **Use provided contexts** for data access and manipulation
|
|
181
|
+
3. **Evaluate template values** using provided utilities
|
|
182
|
+
4. **Handle attributes properly** using useEvaluatedAttributes
|
|
183
|
+
5. **Follow naming conventions** for consistency
|
|
184
|
+
|
|
185
|
+
### Performance Considerations
|
|
186
|
+
- Use React hooks efficiently to avoid unnecessary re-renders
|
|
187
|
+
- Memoize expensive computations when appropriate
|
|
188
|
+
- Leverage the EventDispatcherContext for optimal event handling
|
|
189
|
+
|
|
190
|
+
### Integration Requirements
|
|
191
|
+
- Components must accept props in the standard format
|
|
192
|
+
- Form components should implement proper data binding
|
|
193
|
+
- Action components should not interfere with normal rendering
|