@ea-lab/reactive-json-docs 0.4.0 → 0.5.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/package.json +2 -2
- package/public/rjbuild/docs/advanced-concepts/index.md +1 -0
- package/public/rjbuild/docs/advanced-concepts/index.yaml +1 -0
- package/public/rjbuild/docs/advanced-concepts/plugins/component-development.md +1 -1
- package/public/rjbuild/docs/advanced-concepts/plugins/component-development.yaml +1 -1
- package/public/rjbuild/docs/core/action/Hide.md +1 -1
- package/public/rjbuild/docs/core/action/Hide.yaml +10 -10
- package/public/rjbuild/docs/core/action/ReactOnEvent.md +12 -12
- package/public/rjbuild/docs/core/action/ReactOnEvent.yaml +61 -101
- package/public/rjbuild/docs/core/action/Redirect.md +10 -2
- package/public/rjbuild/docs/core/action/Redirect.yaml +18 -51
- package/public/rjbuild/docs/core/action/VisuallyHide.yaml +10 -12
- package/public/rjbuild/docs/core/action/index.md +19 -204
- package/public/rjbuild/docs/core/action/index.yaml +19 -264
- package/public/rjbuild/docs/core/element/form/DateField.md +1 -1
- package/public/rjbuild/docs/core/element/form/DateField.yaml +4 -4
- package/public/rjbuild/docs/core/element/form/SelectField.yaml +2 -2
- package/public/rjbuild/docs/core/example/website.yaml +10 -10
- package/public/rjbuild/docs/core/reaction/index.md +17 -229
- package/public/rjbuild/docs/core/reaction/index.yaml +14 -242
- package/public/rjbuild/docs/core/reaction/setData.md +1 -1
- package/public/rjbuild/docs/core/reaction/setData.yaml +1 -1
- package/public/rjbuild/docs/docs-components/index.md +0 -2
- package/public/rjbuild/docs/docs-components/index.yaml +0 -2
- package/public/rjbuild/docs/getting-started/actions.md +294 -0
- package/public/rjbuild/docs/getting-started/actions.yaml +403 -0
- package/public/rjbuild/docs/getting-started/index.md +30 -6
- package/public/rjbuild/docs/getting-started/index.yaml +20 -6
- package/public/rjbuild/docs/getting-started/reactions.md +301 -0
- package/public/rjbuild/docs/getting-started/reactions.yaml +300 -0
- package/public/rjbuild/docs/getting-started/rjbuild-structure.md +10 -4
- package/public/rjbuild/docs/getting-started/rjbuild-structure.yaml +10 -4
- package/public/rjbuild/docs/getting-started/{template.md → template-contexts-data-binding.md} +16 -12
- package/public/rjbuild/docs/getting-started/{template.yaml → template-contexts-data-binding.yaml} +28 -14
- /package/public/rjbuild/docs/{core/reaction → advanced-concepts}/forward-update.md +0 -0
- /package/public/rjbuild/docs/{core/reaction → advanced-concepts}/forward-update.yaml +0 -0
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Reactive-JSON Getting Started Guide
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## Topics
|
|
6
|
+
|
|
7
|
+
- **[RjBuild structure](rjbuild-structure.md)**:
|
|
8
|
+
- **[Template system](template-contexts-data-binding.md)**:
|
|
9
|
+
- **[Actions](actions.md)**: Make the UI reflect the state of the app.
|
|
10
|
+
- **[Reactions](reactions.md)**: Bring interactivity to your app, such as performing HTTP requests, edit the app state on events…
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
3
27
|
## Introduction
|
|
4
28
|
|
|
5
29
|
Reactive-JSON is a powerful library that allows you to create interactive user interfaces using only JSON/YAML configurations. No need to write complex JavaScript code - simply define your interface and its behavior declaratively.
|
|
@@ -53,7 +77,7 @@ data:
|
|
|
53
77
|
isAdmin: true
|
|
54
78
|
```
|
|
55
79
|
|
|
56
|
-
> 💡 **Advanced navigation:** For complex hierarchical data access, see the [Template System documentation](/docs/getting-started/template) which covers `~>key` and `~~>key` notations.
|
|
80
|
+
> 💡 **Advanced navigation:** For complex hierarchical data access, see the [Template System documentation](/docs/getting-started/template-contexts-data-binding) which covers `~>key` and `~~>key` notations.
|
|
57
81
|
|
|
58
82
|
### Basic Elements
|
|
59
83
|
|
|
@@ -152,8 +176,8 @@ data:
|
|
|
152
176
|
|
|
153
177
|
## Next Steps
|
|
154
178
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
179
|
+
Now that you have an overview of Reactive-JSON, continue with the getting started guide to master the fundamentals:
|
|
180
|
+
|
|
181
|
+
**[RjBuild Structure](./rjbuild-structure)** - Learn about the core structure of Reactive-JSON configurations and how data, templates, and views work together.
|
|
182
|
+
|
|
183
|
+
This systematic approach will give you a solid foundation for building interactive applications with Reactive-JSON.
|
|
@@ -5,6 +5,20 @@ renderView:
|
|
|
5
5
|
|
|
6
6
|
> Dev note: This page needs to be rewritten.
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
## Topics
|
|
10
|
+
|
|
11
|
+
- **[RjBuild structure](rjbuild-structure)**:
|
|
12
|
+
- **[Template, contexts, and data binding](template-contexts-data-binding)**:
|
|
13
|
+
- **[Actions](actions)**: Make the UI reflect the state of the app.
|
|
14
|
+
- **[Reactions](reactions)**: Bring interactivity to your app, such as performing HTTP requests, edit the app state on events…
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
8
22
|
## Introduction
|
|
9
23
|
|
|
10
24
|
Reactive-JSON is a powerful library that allows you to create interactive user interfaces using only JSON/YAML configurations. No need to write complex JavaScript code - simply define your interface and its behavior declaratively.
|
|
@@ -41,7 +55,7 @@ renderView:
|
|
|
41
55
|
- `~.` : Local context (relative to current template)
|
|
42
56
|
- `~~.` : Global context (access to global data)
|
|
43
57
|
|
|
44
|
-
> 💡 **Advanced navigation:** For complex hierarchical data access, see the [Template System documentation](/docs/getting-started/template) which covers `~>key` and `~~>key` notations.
|
|
58
|
+
> 💡 **Advanced navigation:** For complex hierarchical data access, see the [Template System documentation](/docs/getting-started/template-contexts-data-binding) which covers `~>key` and `~~>key` notations.
|
|
45
59
|
|
|
46
60
|
- type: RjBuildDescriber
|
|
47
61
|
title: "Template System Example"
|
|
@@ -219,8 +233,8 @@ renderView:
|
|
|
219
233
|
content: |
|
|
220
234
|
## Next Steps
|
|
221
235
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
236
|
+
Now that you have an overview of Reactive-JSON, continue with the getting started guide to master the fundamentals:
|
|
237
|
+
|
|
238
|
+
**[RjBuild Structure](./rjbuild-structure)** - Learn about the core structure of Reactive-JSON configurations and how data, templates, and views work together.
|
|
239
|
+
|
|
240
|
+
This systematic approach will give you a solid foundation for building interactive applications with Reactive-JSON.
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# Reactions System
|
|
2
|
+
|
|
3
|
+
Reactions are a fundamental part of Reactive-JSON's interactivity system. They allow you to respond to user events and perform operations like data updates, network requests, and browser interactions - all through JSON configuration. In the RjBuild, reactions are defined under the `actions` key, just like regular actions, but are distinguished by the presence of the `on` property.
|
|
4
|
+
|
|
5
|
+
Reactions execute in response to user events (click, change, etc.) to modify application state and trigger behaviors. They differ from [actions](./actions.md), which continuously adapt the UI based on the current data state; reactions are event-driven while actions are state-driven.
|
|
6
|
+
|
|
7
|
+
## Basic Syntax
|
|
8
|
+
|
|
9
|
+
Reactions are defined as part of the `actions` array on any element. Each reaction has the following core properties:
|
|
10
|
+
|
|
11
|
+
- `what`: The name of the reaction to execute.
|
|
12
|
+
- `on`: The event that triggers the reaction.
|
|
13
|
+
- `when` (optional): Reactions also support optional conditions to control when the reaction should execute. See the [Actions conditional operators documentation](./actions.md#conditional-operators) for detailed information about available condition types.
|
|
14
|
+
|
|
15
|
+
Beyond these core properties, reactions include reaction-specific properties that vary depending on the reaction type. For example, a `setData` reaction requires `path` and `value` properties, while a `fetchData` reaction needs a `url` property and optional `method` configuration.
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
renderView:
|
|
19
|
+
- type: button
|
|
20
|
+
content: "Save Text"
|
|
21
|
+
actions:
|
|
22
|
+
- what: setData # Reaction type
|
|
23
|
+
on: click # Triggering event
|
|
24
|
+
path: ~.saved_text # Reaction-specific property
|
|
25
|
+
value: ~.user_input # Reaction-specific property
|
|
26
|
+
when: ~.user_input # Optional condition
|
|
27
|
+
isNotEmpty: # Condition value
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Basic Reaction Demonstration
|
|
31
|
+
|
|
32
|
+
This example demonstrates how to set data when a button is clicked.
|
|
33
|
+
|
|
34
|
+
On the *Save Text* button, we define a `setData` reaction that will set the text field value in the `saved_text` data location when the button is clicked, but only if the text field is not empty.
|
|
35
|
+
|
|
36
|
+
```yaml
|
|
37
|
+
renderView:
|
|
38
|
+
- type: TextField
|
|
39
|
+
label: "Enter some text:"
|
|
40
|
+
dataLocation: ~.user_input
|
|
41
|
+
placeholder: "Type something..."
|
|
42
|
+
|
|
43
|
+
- type: button
|
|
44
|
+
content: "Save Text"
|
|
45
|
+
actions:
|
|
46
|
+
- what: setData # Reaction type
|
|
47
|
+
on: click # Triggering event
|
|
48
|
+
path: ~.saved_text # Reaction-specific property
|
|
49
|
+
value: ~.user_input # Reaction-specific property
|
|
50
|
+
when: ~.user_input # Optional condition
|
|
51
|
+
isNotEmpty: # Condition value
|
|
52
|
+
|
|
53
|
+
- type: div
|
|
54
|
+
content: ["Saved text: ", ~.saved_text]
|
|
55
|
+
actions:
|
|
56
|
+
- what: hide # Action (no 'on' property)
|
|
57
|
+
when: ~.saved_text # Condition
|
|
58
|
+
isEmpty:
|
|
59
|
+
|
|
60
|
+
data:
|
|
61
|
+
user_input: ""
|
|
62
|
+
saved_text: ""
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Reaction Types
|
|
66
|
+
|
|
67
|
+
Reactive-JSON provides several built-in reactions:
|
|
68
|
+
|
|
69
|
+
### Data Management
|
|
70
|
+
- **setData**: Sets data at the specified path.
|
|
71
|
+
- **addData**: Adds new data to the specified path.
|
|
72
|
+
- **removeData**: Removes data from the specified path.
|
|
73
|
+
- **moveData**: Moves data from one path to another.
|
|
74
|
+
|
|
75
|
+
### Network Operations
|
|
76
|
+
- **fetchData**: Fetches data from a URL using GET requests.
|
|
77
|
+
- **submitData**: Submits data to a server endpoint using POST/PUT/DELETE.
|
|
78
|
+
|
|
79
|
+
### Browser Operations
|
|
80
|
+
- **setClipboardData**: Copies data to the clipboard.
|
|
81
|
+
- **redirectNow**: Performs an immediate redirect.
|
|
82
|
+
- **triggerEvent**: Triggers a custom event.
|
|
83
|
+
- **postMessage**: Sends a message to another window/frame.
|
|
84
|
+
|
|
85
|
+
For detailed documentation of each reaction, including properties and examples, see their respective documentation pages.
|
|
86
|
+
|
|
87
|
+
## Event Types
|
|
88
|
+
|
|
89
|
+
The `on` property accepts standard browser events. These events are the same as those used in standard web development, and their availability depends on the HTML element type. For example, a `change` event will only work on form elements like `input`, `select`, or `textarea`, while a `click` event works on any element.
|
|
90
|
+
|
|
91
|
+
This example demonstrates the different event types supported by reactions:
|
|
92
|
+
|
|
93
|
+
```yaml
|
|
94
|
+
renderView:
|
|
95
|
+
- type: div
|
|
96
|
+
content: ["Last event type: ", ~.last_event_type]
|
|
97
|
+
attributes:
|
|
98
|
+
style:
|
|
99
|
+
padding: "10px"
|
|
100
|
+
border: "1px solid var(--bs-border-color, #dee2e6)"
|
|
101
|
+
borderRadius: "4px"
|
|
102
|
+
marginBottom: "10px"
|
|
103
|
+
fontWeight: "bold"
|
|
104
|
+
|
|
105
|
+
- type: TextField
|
|
106
|
+
label: "Interactive text field:"
|
|
107
|
+
dataLocation: ~.user_input
|
|
108
|
+
placeholder: "Click, type, or hover..."
|
|
109
|
+
actions:
|
|
110
|
+
- what: setData
|
|
111
|
+
on: click
|
|
112
|
+
path: ~.last_event_type
|
|
113
|
+
value: "click"
|
|
114
|
+
- what: setData
|
|
115
|
+
on: change
|
|
116
|
+
path: ~.last_event_type
|
|
117
|
+
value: "change"
|
|
118
|
+
- what: setData
|
|
119
|
+
on: mouseOver
|
|
120
|
+
path: ~.last_event_type
|
|
121
|
+
value: "mouseOver"
|
|
122
|
+
|
|
123
|
+
data:
|
|
124
|
+
last_event_type: "none"
|
|
125
|
+
user_input: ""
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Common event types:
|
|
129
|
+
- `click`: Mouse click (works on any element).
|
|
130
|
+
- `change`: Form input change (works on form elements only).
|
|
131
|
+
- `mouseOver`: Mouse hover (works on any element).
|
|
132
|
+
- `submit`: Form submission (works on form elements only).
|
|
133
|
+
- `keyDown`/`keyUp`: Keyboard events (works on focusable elements).
|
|
134
|
+
|
|
135
|
+
> **Note**: Event names must respect standard React/DOM event naming conventions (camelCase).
|
|
136
|
+
|
|
137
|
+
## Advanced Features
|
|
138
|
+
|
|
139
|
+
### Conditional Logic
|
|
140
|
+
Reactions support the same conditional operators as actions:
|
|
141
|
+
- `when` + `is`/`isNot`: Value equality checks.
|
|
142
|
+
- `when` + `isEmpty`: Empty value tests.
|
|
143
|
+
- `when` + `contains`/`containsNot`: Content search.
|
|
144
|
+
- `when` + `>`, `<`, `>=`, `<=`: Numeric/date comparisons.
|
|
145
|
+
- `andConditions`/`orConditions`: Complex condition logic.
|
|
146
|
+
|
|
147
|
+
### Event Control
|
|
148
|
+
Use `stopPropagation: true` to:
|
|
149
|
+
1. Prevent event bubbling to parent elements.
|
|
150
|
+
2. Stop execution of subsequent actions for the same event.
|
|
151
|
+
|
|
152
|
+
### Execution Order
|
|
153
|
+
- Multiple reactions on the same event execute in the order they are defined.
|
|
154
|
+
- Reactions with unmet conditions are skipped.
|
|
155
|
+
- Actions (without `on` property) are evaluated separately from reactions.
|
|
156
|
+
|
|
157
|
+
## Technical Details
|
|
158
|
+
|
|
159
|
+
- Reactions are triggered by DOM events.
|
|
160
|
+
- Multiple reactions can be defined for the same event.
|
|
161
|
+
- Reactions are executed in the order they appear in the YAML.
|
|
162
|
+
- Reactions can be chained together by modifying data that other reactions depend on.
|
|
163
|
+
- Conditional reactions only execute when their conditions evaluate to true.
|
|
164
|
+
- The `stopPropagation` property affects both event bubbling and subsequent action execution.
|
|
165
|
+
|
|
166
|
+
## Limitations
|
|
167
|
+
|
|
168
|
+
- Event availability depends on the HTML element type (e.g., `change` only works on form elements).
|
|
169
|
+
- Network operations require proper CORS configuration.
|
|
170
|
+
- Browser operations require appropriate permissions.
|
|
171
|
+
- No built-in error handling beyond console logging for network operations.
|
|
172
|
+
- Only one network request (fetch/submit) can be active at a time.
|
|
173
|
+
- URLs in network operations must be static strings (dynamic URLs not supported).
|
|
174
|
+
|
|
175
|
+
## Best Practices
|
|
176
|
+
|
|
177
|
+
1. **Use descriptive conditions**: Make your conditional logic clear and readable.
|
|
178
|
+
2. **Handle empty states**: Always consider what happens when data is empty or undefined.
|
|
179
|
+
3. **Order matters**: Place more specific conditions before general ones.
|
|
180
|
+
4. **Use stopPropagation wisely**: Only use it when you specifically need to prevent event bubbling or stop action execution.
|
|
181
|
+
5. **Test network operations**: Ensure your API endpoints return the expected format.
|
|
182
|
+
6. **Provide user feedback**: Use visual indicators during loading states.
|
|
183
|
+
|
|
184
|
+
## Complete Examples
|
|
185
|
+
|
|
186
|
+
### Data Input and Submission
|
|
187
|
+
```yaml
|
|
188
|
+
renderView:
|
|
189
|
+
- type: TextField
|
|
190
|
+
label: "Username"
|
|
191
|
+
placeholder: "Enter your username"
|
|
192
|
+
dataLocation: ~.form_data.username
|
|
193
|
+
- type: TextField
|
|
194
|
+
label: "Email"
|
|
195
|
+
placeholder: "Enter your email"
|
|
196
|
+
inputType: "email"
|
|
197
|
+
dataLocation: ~.form_data.email
|
|
198
|
+
- type: button
|
|
199
|
+
content: Submit
|
|
200
|
+
actions:
|
|
201
|
+
- what: submitData
|
|
202
|
+
on: click
|
|
203
|
+
url: "/api/submit"
|
|
204
|
+
data:
|
|
205
|
+
username: ~.form_data.username
|
|
206
|
+
email: ~.form_data.email
|
|
207
|
+
when: ~.form_data.username
|
|
208
|
+
isNotEmpty:
|
|
209
|
+
|
|
210
|
+
data:
|
|
211
|
+
form_data:
|
|
212
|
+
username: ""
|
|
213
|
+
email: ""
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Conditional Reactions Example
|
|
217
|
+
```yaml
|
|
218
|
+
renderView:
|
|
219
|
+
- type: button
|
|
220
|
+
content: "Toggle State"
|
|
221
|
+
actions:
|
|
222
|
+
- what: setData
|
|
223
|
+
on: click
|
|
224
|
+
path: ~.button_state
|
|
225
|
+
value: "on"
|
|
226
|
+
when: ~.button_state
|
|
227
|
+
is: "off"
|
|
228
|
+
stopPropagation: true
|
|
229
|
+
- what: setData
|
|
230
|
+
on: click
|
|
231
|
+
path: ~.button_state
|
|
232
|
+
value: "off"
|
|
233
|
+
when: ~.button_state
|
|
234
|
+
is: "on"
|
|
235
|
+
stopPropagation: true
|
|
236
|
+
- type: div
|
|
237
|
+
content: ["Button state: ", ~.button_state]
|
|
238
|
+
- type: div
|
|
239
|
+
content: "Button has been clicked!"
|
|
240
|
+
actions:
|
|
241
|
+
- what: hide
|
|
242
|
+
when: ~.button_state
|
|
243
|
+
is: "off"
|
|
244
|
+
|
|
245
|
+
data:
|
|
246
|
+
button_state: "off"
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Complex Conditional Logic
|
|
250
|
+
```yaml
|
|
251
|
+
renderView:
|
|
252
|
+
- type: TextField
|
|
253
|
+
label: "Enter a number:"
|
|
254
|
+
dataLocation: ~.user_input
|
|
255
|
+
inputType: "number"
|
|
256
|
+
- type: button
|
|
257
|
+
content: "Process Number"
|
|
258
|
+
actions:
|
|
259
|
+
- what: setData
|
|
260
|
+
on: click
|
|
261
|
+
path: ~.result
|
|
262
|
+
value: "Number is valid and positive!"
|
|
263
|
+
andConditions:
|
|
264
|
+
- when: ~.user_input
|
|
265
|
+
isNotEmpty:
|
|
266
|
+
- when: ~.user_input
|
|
267
|
+
">": 0
|
|
268
|
+
- what: setData
|
|
269
|
+
on: click
|
|
270
|
+
path: ~.result
|
|
271
|
+
value: "Number must be positive!"
|
|
272
|
+
when: ~.user_input
|
|
273
|
+
"<=": 0
|
|
274
|
+
- what: setData
|
|
275
|
+
on: click
|
|
276
|
+
path: ~.result
|
|
277
|
+
value: "Please enter a number!"
|
|
278
|
+
when: ~.user_input
|
|
279
|
+
isEmpty: true
|
|
280
|
+
- type: div
|
|
281
|
+
content: ["Result: ", ~.result]
|
|
282
|
+
actions:
|
|
283
|
+
- what: hide
|
|
284
|
+
when: ~.result
|
|
285
|
+
isEmpty: true
|
|
286
|
+
|
|
287
|
+
data:
|
|
288
|
+
user_input: null
|
|
289
|
+
result: null
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Next Steps
|
|
293
|
+
|
|
294
|
+
Congratulations! You've mastered the fundamentals of Reactive-JSON. You now understand how to structure RjBuilds, use templates, and create interactive applications with actions and reactions.
|
|
295
|
+
|
|
296
|
+
Ready to take your skills further? Explore the **[Advanced Concepts](../advanced-concepts/index.md)** to learn about data mapping, custom plugins, and performance optimization techniques.
|
|
297
|
+
|
|
298
|
+
## Related Documentation
|
|
299
|
+
|
|
300
|
+
- **[Actions System](./actions.md)**: Review state-driven UI adaptation.
|
|
301
|
+
- **[Template System](./template-contexts-data-binding.md)**: Revisit data binding patterns.
|