@ea-lab/reactive-json-docs 0.1.2
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/README-npm.md +49 -0
- package/README.md +86 -0
- package/package.json +79 -0
- package/public/rjbuild/component-doc/chartjs/components.yaml +252 -0
- package/public/rjbuild/component-doc/chartjs/overview.yaml +51 -0
- package/public/rjbuild/component-doc/core/action/HashChangeListener.md +90 -0
- package/public/rjbuild/component-doc/core/action/HashChangeListener.yaml +124 -0
- package/public/rjbuild/component-doc/core/action/Hide.md +22 -0
- package/public/rjbuild/component-doc/core/action/Hide.yaml +60 -0
- package/public/rjbuild/component-doc/core/action/MessageListener.md +93 -0
- package/public/rjbuild/component-doc/core/action/MessageListener.yaml +153 -0
- package/public/rjbuild/component-doc/core/action/Popover.md +26 -0
- package/public/rjbuild/component-doc/core/action/Popover.yaml +100 -0
- package/public/rjbuild/component-doc/core/action/ReactOnEvent.md +81 -0
- package/public/rjbuild/component-doc/core/action/ReactOnEvent.yaml +133 -0
- package/public/rjbuild/component-doc/core/action/Redirect.md +20 -0
- package/public/rjbuild/component-doc/core/action/Redirect.yaml +68 -0
- package/public/rjbuild/component-doc/core/action/Tooltip.md +22 -0
- package/public/rjbuild/component-doc/core/action/Tooltip.yaml +90 -0
- package/public/rjbuild/component-doc/core/action/VisuallyHide.md +21 -0
- package/public/rjbuild/component-doc/core/action/VisuallyHide.yaml +62 -0
- package/public/rjbuild/component-doc/core/action/index.md +214 -0
- package/public/rjbuild/component-doc/core/action/index.yaml +278 -0
- package/public/rjbuild/component-doc/core/element/form/CheckBoxField.md +276 -0
- package/public/rjbuild/component-doc/core/element/form/CheckBoxField.yaml +338 -0
- package/public/rjbuild/component-doc/core/element/form/DateField.md +189 -0
- package/public/rjbuild/component-doc/core/element/form/DateField.yaml +264 -0
- package/public/rjbuild/component-doc/core/element/form/NumberField.md +136 -0
- package/public/rjbuild/component-doc/core/element/form/NumberField.yaml +103 -0
- package/public/rjbuild/component-doc/core/element/form/SelectField.md +304 -0
- package/public/rjbuild/component-doc/core/element/form/SelectField.yaml +360 -0
- package/public/rjbuild/component-doc/core/element/form/TextAreaField.md +134 -0
- package/public/rjbuild/component-doc/core/element/form/TextAreaField.yaml +146 -0
- package/public/rjbuild/component-doc/core/element/form/TextField.md +129 -0
- package/public/rjbuild/component-doc/core/element/form/TextField.yaml +147 -0
- package/public/rjbuild/component-doc/core/element/form/formElementsCommon.md +106 -0
- package/public/rjbuild/component-doc/core/element/form/index.md +50 -0
- package/public/rjbuild/component-doc/core/element/form/index.yaml +96 -0
- package/public/rjbuild/component-doc/core/element/html/AccordionItem.yaml +47 -0
- package/public/rjbuild/component-doc/core/element/html/FolderSortableTree.yaml +81 -0
- package/public/rjbuild/component-doc/core/element/html/FormatNumeral.yaml +58 -0
- package/public/rjbuild/component-doc/core/element/html/Html.yaml +67 -0
- package/public/rjbuild/component-doc/core/element/html/LabelFromValue.yaml +54 -0
- package/public/rjbuild/component-doc/core/element/html/Modal.yaml +93 -0
- package/public/rjbuild/component-doc/core/element/html/PreformattedMarkup.yaml +37 -0
- package/public/rjbuild/component-doc/core/element/html/SortableTreeItemCollapseButton.yaml +92 -0
- package/public/rjbuild/component-doc/core/element/html/Tabs.yaml +57 -0
- package/public/rjbuild/component-doc/core/element/special/BootstrapElement.md +17 -0
- package/public/rjbuild/component-doc/core/element/special/BootstrapElement.yaml +18 -0
- package/public/rjbuild/component-doc/core/element/special/Count.md +37 -0
- package/public/rjbuild/component-doc/core/element/special/Count.yaml +325 -0
- package/public/rjbuild/component-doc/core/element/special/DataFilter.md +149 -0
- package/public/rjbuild/component-doc/core/element/special/DataFilter.yaml +315 -0
- package/public/rjbuild/component-doc/core/element/special/DelayedActions.md +51 -0
- package/public/rjbuild/component-doc/core/element/special/DelayedActions.yaml +55 -0
- package/public/rjbuild/component-doc/core/element/special/PageControls.md +126 -0
- package/public/rjbuild/component-doc/core/element/special/PageControls.yaml +133 -0
- package/public/rjbuild/component-doc/core/element/special/Phantom.md +31 -0
- package/public/rjbuild/component-doc/core/element/special/Phantom.yaml +34 -0
- package/public/rjbuild/component-doc/core/element/special/ReactiveJsonSubroot.md +27 -0
- package/public/rjbuild/component-doc/core/element/special/ReactiveJsonSubroot.yaml +51 -0
- package/public/rjbuild/component-doc/core/element/special/Switch.md +262 -0
- package/public/rjbuild/component-doc/core/element/special/Switch.yaml +348 -0
- package/public/rjbuild/component-doc/core/example/accordion.md +96 -0
- package/public/rjbuild/component-doc/core/example/accordion.yaml +64 -0
- package/public/rjbuild/component-doc/core/example/dynamic-content.md +197 -0
- package/public/rjbuild/component-doc/core/example/dynamic-content.yaml +237 -0
- package/public/rjbuild/component-doc/core/example/html.md +66 -0
- package/public/rjbuild/component-doc/core/example/html.yaml +83 -0
- package/public/rjbuild/component-doc/core/example/website.yaml +1663 -0
- package/public/rjbuild/component-doc/core/reaction/addData.md +96 -0
- package/public/rjbuild/component-doc/core/reaction/addData.yaml +133 -0
- package/public/rjbuild/component-doc/core/reaction/fetchData.md +60 -0
- package/public/rjbuild/component-doc/core/reaction/fetchData.yaml +156 -0
- package/public/rjbuild/component-doc/core/reaction/index.md +236 -0
- package/public/rjbuild/component-doc/core/reaction/index.yaml +254 -0
- package/public/rjbuild/component-doc/core/reaction/moveData.md +68 -0
- package/public/rjbuild/component-doc/core/reaction/moveData.yaml +71 -0
- package/public/rjbuild/component-doc/core/reaction/postMessage.md +63 -0
- package/public/rjbuild/component-doc/core/reaction/postMessage.yaml +68 -0
- package/public/rjbuild/component-doc/core/reaction/redirectNow.md +37 -0
- package/public/rjbuild/component-doc/core/reaction/redirectNow.yaml +37 -0
- package/public/rjbuild/component-doc/core/reaction/removeData.md +78 -0
- package/public/rjbuild/component-doc/core/reaction/removeData.yaml +56 -0
- package/public/rjbuild/component-doc/core/reaction/setClipboardData.md +44 -0
- package/public/rjbuild/component-doc/core/reaction/setClipboardData.yaml +41 -0
- package/public/rjbuild/component-doc/core/reaction/setData.md +93 -0
- package/public/rjbuild/component-doc/core/reaction/setData.yaml +85 -0
- package/public/rjbuild/component-doc/core/reaction/submitData.md +138 -0
- package/public/rjbuild/component-doc/core/reaction/submitData.yaml +141 -0
- package/public/rjbuild/component-doc/core/reaction/triggerEvent.md +59 -0
- package/public/rjbuild/component-doc/core/reaction/triggerEvent.yaml +59 -0
- package/public/rjbuild/component-doc/index.yaml +13 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# addData
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
`addData` is a reaction that allows adding data at a specified path in the application's data context. It's particularly useful for appending new items to arrays or adding new properties to objects.
|
|
6
|
+
|
|
7
|
+
## Properties
|
|
8
|
+
- `path` (string, required): The location where the data should be added (using template path syntax with `~` or `~~`). If the path does not exist, it will be created automatically.
|
|
9
|
+
- `value` (any, optional): The data to add. Can be any valid JSON value (string, number, object, array).
|
|
10
|
+
|
|
11
|
+
## Behavior
|
|
12
|
+
- If the path doesn't exist, it will be created automatically
|
|
13
|
+
- For arrays, the value is appended to the end
|
|
14
|
+
- For objects, the value must be an object with a single key
|
|
15
|
+
- The operation is atomic and synchronous
|
|
16
|
+
|
|
17
|
+
## Data Management
|
|
18
|
+
The value is evaluated using the template system before being added.
|
|
19
|
+
|
|
20
|
+
### Adding to Arrays
|
|
21
|
+
If the target path is an array, the value is appended to the end of the array. The value can be a string, number, object, or array.
|
|
22
|
+
|
|
23
|
+
### Adding to Objects
|
|
24
|
+
If the target path is an object, the value must be an object with a single key. The key will be used as the new property name, and the value as its value.
|
|
25
|
+
|
|
26
|
+
Example:
|
|
27
|
+
```yaml
|
|
28
|
+
actions:
|
|
29
|
+
- what: addData
|
|
30
|
+
on: click
|
|
31
|
+
path: ~.user
|
|
32
|
+
value:
|
|
33
|
+
role: "admin" # Adds a new property 'role' to the user object
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Complete Examples
|
|
37
|
+
|
|
38
|
+
### Adding to an Array
|
|
39
|
+
```yaml
|
|
40
|
+
renderView:
|
|
41
|
+
- type: button
|
|
42
|
+
content: Add Item
|
|
43
|
+
actions:
|
|
44
|
+
- what: addData
|
|
45
|
+
on: click
|
|
46
|
+
path: ~.items
|
|
47
|
+
value: "New Item"
|
|
48
|
+
|
|
49
|
+
data:
|
|
50
|
+
items: ["Item 1", "Item 2"]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Adding to an Object
|
|
54
|
+
```yaml
|
|
55
|
+
renderView:
|
|
56
|
+
- type: button
|
|
57
|
+
content: Add Property
|
|
58
|
+
actions:
|
|
59
|
+
- what: addData
|
|
60
|
+
on: click
|
|
61
|
+
path: ~.user
|
|
62
|
+
value:
|
|
63
|
+
role: "admin"
|
|
64
|
+
|
|
65
|
+
data:
|
|
66
|
+
user:
|
|
67
|
+
name: "John"
|
|
68
|
+
email: "john@example.com"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Adding with Dynamic Values
|
|
72
|
+
```yaml
|
|
73
|
+
renderView:
|
|
74
|
+
- type: TextField
|
|
75
|
+
label: "New Item"
|
|
76
|
+
dataLocation: ~.new_item
|
|
77
|
+
- type: button
|
|
78
|
+
content: Add
|
|
79
|
+
actions:
|
|
80
|
+
- what: addData
|
|
81
|
+
on: click
|
|
82
|
+
path: ~.items
|
|
83
|
+
value: ~.new_item
|
|
84
|
+
when: ~.new_item
|
|
85
|
+
isEmpty: not
|
|
86
|
+
|
|
87
|
+
data:
|
|
88
|
+
items: []
|
|
89
|
+
new_item: ""
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Limitations
|
|
93
|
+
- Cannot add data to non-object/non-array paths
|
|
94
|
+
- The path must be valid according to the template system rules
|
|
95
|
+
- The value must be serializable
|
|
96
|
+
- For objects, the value must be an object with a single key
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
renderView:
|
|
2
|
+
- type: Markdown
|
|
3
|
+
content: |
|
|
4
|
+
# addData
|
|
5
|
+
|
|
6
|
+
`addData` is a reaction that allows adding data at a specified path in the application's data context. It's particularly useful for appending new items to arrays or adding new properties to objects.
|
|
7
|
+
|
|
8
|
+
## Properties
|
|
9
|
+
- `path` (string, required): The location where the data should be added (using template path syntax with `~` or `~~`). If the path does not exist, it will be created automatically.
|
|
10
|
+
- `value` (any, optional): The data to add. Can be any valid JSON value (string, number, object, array).
|
|
11
|
+
|
|
12
|
+
## Behavior
|
|
13
|
+
- If the path doesn't exist, it will be created automatically
|
|
14
|
+
- For arrays, the value is appended to the end
|
|
15
|
+
- For objects, the value must be an object with a single key
|
|
16
|
+
- The operation is atomic and synchronous
|
|
17
|
+
|
|
18
|
+
## Data Management
|
|
19
|
+
The value is evaluated using the template system before being added.
|
|
20
|
+
|
|
21
|
+
### Adding to Arrays
|
|
22
|
+
If the target path is an array, the value is appended to the end of the array. The value can be a string, number, object, or array.
|
|
23
|
+
|
|
24
|
+
### Adding to Objects
|
|
25
|
+
If the target path is an object, the value must be an object with a single key. The key will be used as the new property name, and the value as its value.
|
|
26
|
+
|
|
27
|
+
Example:
|
|
28
|
+
```yaml
|
|
29
|
+
actions:
|
|
30
|
+
- what: addData
|
|
31
|
+
on: click
|
|
32
|
+
path: ~.user
|
|
33
|
+
value:
|
|
34
|
+
role: "admin" # Adds a new property 'role' to the user object
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Complete Examples
|
|
38
|
+
|
|
39
|
+
### Adding to an Array
|
|
40
|
+
```yaml
|
|
41
|
+
renderView:
|
|
42
|
+
- type: button
|
|
43
|
+
content: Add Item
|
|
44
|
+
actions:
|
|
45
|
+
- what: addData
|
|
46
|
+
on: click
|
|
47
|
+
path: ~.items
|
|
48
|
+
value: "New Item"
|
|
49
|
+
|
|
50
|
+
data:
|
|
51
|
+
items: ["Item 1", "Item 2"]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Adding to an Object
|
|
55
|
+
```yaml
|
|
56
|
+
renderView:
|
|
57
|
+
- type: button
|
|
58
|
+
content: Add Property
|
|
59
|
+
actions:
|
|
60
|
+
- what: addData
|
|
61
|
+
on: click
|
|
62
|
+
path: ~.user
|
|
63
|
+
value:
|
|
64
|
+
role: "admin"
|
|
65
|
+
|
|
66
|
+
data:
|
|
67
|
+
user:
|
|
68
|
+
name: "John"
|
|
69
|
+
email: "john@example.com"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Adding with Dynamic Values
|
|
73
|
+
```yaml
|
|
74
|
+
renderView:
|
|
75
|
+
- type: TextField
|
|
76
|
+
label: "New Item"
|
|
77
|
+
dataLocation: ~.new_item
|
|
78
|
+
- type: button
|
|
79
|
+
content: Add
|
|
80
|
+
actions:
|
|
81
|
+
- what: addData
|
|
82
|
+
on: click
|
|
83
|
+
path: ~.items
|
|
84
|
+
value: ~.new_item
|
|
85
|
+
when: ~.new_item
|
|
86
|
+
isEmpty: not
|
|
87
|
+
|
|
88
|
+
data:
|
|
89
|
+
items: []
|
|
90
|
+
new_item: ""
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- type: RjBuildDescriber
|
|
94
|
+
title: "Interactive Example: Add User to Array"
|
|
95
|
+
description:
|
|
96
|
+
- type: Markdown
|
|
97
|
+
content: |
|
|
98
|
+
The button below adds a new user (with empty name and email) to the `users` array. Each user is displayed with a form using the `Switch` component and the `user_form` template.
|
|
99
|
+
toDescribe:
|
|
100
|
+
renderView:
|
|
101
|
+
- type: button
|
|
102
|
+
content: Add user
|
|
103
|
+
actions:
|
|
104
|
+
- what: addData
|
|
105
|
+
on: click
|
|
106
|
+
path: ~.users
|
|
107
|
+
value:
|
|
108
|
+
name: ""
|
|
109
|
+
email: ""
|
|
110
|
+
- type: Switch
|
|
111
|
+
content: ~.users
|
|
112
|
+
singleOption:
|
|
113
|
+
load: user_form
|
|
114
|
+
templates:
|
|
115
|
+
user_form:
|
|
116
|
+
- type: TextField
|
|
117
|
+
label: Name
|
|
118
|
+
dataLocation: ~.name
|
|
119
|
+
- type: TextField
|
|
120
|
+
label: Email
|
|
121
|
+
dataLocation: ~.email
|
|
122
|
+
data:
|
|
123
|
+
users:
|
|
124
|
+
- name: "John"
|
|
125
|
+
email: "john@example.com"
|
|
126
|
+
- type: Markdown
|
|
127
|
+
content: |
|
|
128
|
+
## Limitations
|
|
129
|
+
|
|
130
|
+
- Cannot add data to non-object/non-array paths
|
|
131
|
+
- The path must be valid according to the template system rules
|
|
132
|
+
- The value must be serializable
|
|
133
|
+
- For objects, the value must be an object with a single key
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Reactive-JSON fetchData Documentation
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
`fetchData` is a reaction that allows making HTTP GET requests to a server. It operates in two distinct modes, depending on the value of `refreshAppOnResponse`.
|
|
5
|
+
|
|
6
|
+
## Properties
|
|
7
|
+
- `url` (string, required): The URL to call (must be a static string, dynamic URLs are not supported)
|
|
8
|
+
- `refreshAppOnResponse` (boolean, optional): If true (default), the response must be a valid rjbuild and will replace the application state. If false, the response is ignored (webhook mode).
|
|
9
|
+
|
|
10
|
+
## Behavior
|
|
11
|
+
- Only GET requests are supported
|
|
12
|
+
- Only one request can be active at a time
|
|
13
|
+
- The URL is evaluated via the template system before sending, but must resolve to a static string
|
|
14
|
+
- If `refreshAppOnResponse` is true, the response must be a valid rjbuild and will replace the application state
|
|
15
|
+
- If `refreshAppOnResponse` is false, the response is ignored (webhook mode)
|
|
16
|
+
- Errors are only logged to the console
|
|
17
|
+
- The triggering element is visually disabled during the request
|
|
18
|
+
|
|
19
|
+
## Examples
|
|
20
|
+
|
|
21
|
+
### Data Loading (with Refresh)
|
|
22
|
+
```yaml
|
|
23
|
+
renderView:
|
|
24
|
+
- type: button
|
|
25
|
+
content: Load Data
|
|
26
|
+
actions:
|
|
27
|
+
- what: fetchData
|
|
28
|
+
on: click
|
|
29
|
+
url: "/api/users"
|
|
30
|
+
refreshAppOnResponse: true # Response will replace the application state
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Simple Call (Webhook Style)
|
|
34
|
+
```yaml
|
|
35
|
+
renderView:
|
|
36
|
+
- type: button
|
|
37
|
+
content: Notify Server
|
|
38
|
+
actions:
|
|
39
|
+
- what: fetchData
|
|
40
|
+
on: click
|
|
41
|
+
url: "/api/notify"
|
|
42
|
+
refreshAppOnResponse: false # Response is ignored, like a webhook
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Use Cases with refreshAppOnResponse: false
|
|
46
|
+
1. Server notifications
|
|
47
|
+
2. Webhooks
|
|
48
|
+
3. API pinging
|
|
49
|
+
4. Triggering server-side actions without waiting for response
|
|
50
|
+
|
|
51
|
+
## Limitations
|
|
52
|
+
- Only one request can be active at a time
|
|
53
|
+
- Only GET requests are supported
|
|
54
|
+
- Response must be a valid rjbuild **only** if refreshAppOnResponse is true
|
|
55
|
+
- No built-in error handling beyond console logging
|
|
56
|
+
- No support for request cancellation
|
|
57
|
+
- No support for timeouts
|
|
58
|
+
- **No support for dynamic URLs** - URLs must be static strings
|
|
59
|
+
- No support for query parameters in URL templates
|
|
60
|
+
- No support for complex URL routing or path generation
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
renderView:
|
|
2
|
+
- type: Markdown
|
|
3
|
+
content: |
|
|
4
|
+
# fetchData
|
|
5
|
+
|
|
6
|
+
fetchData is a reaction that allows making HTTP GET requests to a server. It operates in two distinct modes:
|
|
7
|
+
|
|
8
|
+
The behavior depends on `refreshAppOnResponse`:
|
|
9
|
+
- If `true` (default): Response must be a valid rjbuild (with renderView/templates/data) as it will be used to re-render the application
|
|
10
|
+
- If `false`: Response is completely ignored - useful for webhook-like calls or server notifications
|
|
11
|
+
|
|
12
|
+
**Important**: Dynamic URLs are not supported. URLs must be static strings.
|
|
13
|
+
|
|
14
|
+
## Properties
|
|
15
|
+
- `url` (string, required): The URL to call (must be a static string, dynamic URLs are not supported)
|
|
16
|
+
- `refreshAppOnResponse` (boolean, optional): If true (default), the response must be a valid rjbuild and will replace the application state. If false, the response is ignored (webhook mode).
|
|
17
|
+
|
|
18
|
+
## Behavior
|
|
19
|
+
- Only GET requests are supported
|
|
20
|
+
- Only one request can be active at a time
|
|
21
|
+
- The URL is evaluated via the template system before sending, but must resolve to a static string
|
|
22
|
+
- If `refreshAppOnResponse` is true, the response must be a valid rjbuild and will replace the application state
|
|
23
|
+
- If `refreshAppOnResponse` is false, the response is ignored (webhook mode)
|
|
24
|
+
- Errors are only logged to the console
|
|
25
|
+
- The triggering element is visually disabled during the request
|
|
26
|
+
|
|
27
|
+
- type: RjBuildDescriber
|
|
28
|
+
title: Basic Structure
|
|
29
|
+
description:
|
|
30
|
+
- type: Markdown
|
|
31
|
+
content: |
|
|
32
|
+
The basic structure of a fetchData reaction requires a URL and can include the refreshAppOnResponse option.
|
|
33
|
+
|
|
34
|
+
The URL can be a template value that resolves to a static string.
|
|
35
|
+
toDescribe:
|
|
36
|
+
renderView:
|
|
37
|
+
- type: button
|
|
38
|
+
content: Basic Example
|
|
39
|
+
actions:
|
|
40
|
+
- what: fetchData
|
|
41
|
+
on: click
|
|
42
|
+
url: "/mockup-api/fetchData/example.json"
|
|
43
|
+
refreshAppOnResponse: true # Response will replace the application state
|
|
44
|
+
- type: div
|
|
45
|
+
content:
|
|
46
|
+
- "URL: "
|
|
47
|
+
- "/mockup-api/fetchData/example.json"
|
|
48
|
+
- type: div
|
|
49
|
+
content:
|
|
50
|
+
- "Fetch status: "
|
|
51
|
+
- ~.fetch_status
|
|
52
|
+
data:
|
|
53
|
+
fetch_status: "Waiting for click"
|
|
54
|
+
|
|
55
|
+
- type: RjBuildDescriber
|
|
56
|
+
title: Webhook Mode
|
|
57
|
+
description:
|
|
58
|
+
- type: Markdown
|
|
59
|
+
content: |
|
|
60
|
+
With `refreshAppOnResponse: false`, fetchData behaves like a webhook:
|
|
61
|
+
- Response is completely ignored
|
|
62
|
+
- Only the HTTP call is made
|
|
63
|
+
- Useful for:
|
|
64
|
+
* Server notifications
|
|
65
|
+
* Triggering server-side actions
|
|
66
|
+
* API pinging
|
|
67
|
+
* Sending webhooks
|
|
68
|
+
toDescribe:
|
|
69
|
+
renderView:
|
|
70
|
+
- type: button
|
|
71
|
+
content: Notify Server
|
|
72
|
+
actions:
|
|
73
|
+
- what: fetchData
|
|
74
|
+
on: click
|
|
75
|
+
url: "/mockup-api/fetchData/status.json"
|
|
76
|
+
refreshAppOnResponse: false # Response is ignored, like a webhook
|
|
77
|
+
- type: div
|
|
78
|
+
content:
|
|
79
|
+
- "Last call: "
|
|
80
|
+
- ~.last_status
|
|
81
|
+
data:
|
|
82
|
+
last_status: "Not made"
|
|
83
|
+
|
|
84
|
+
- type: RjBuildDescriber
|
|
85
|
+
title: Error Handling
|
|
86
|
+
description:
|
|
87
|
+
- type: Markdown
|
|
88
|
+
content: |
|
|
89
|
+
Errors are logged to the console but don't trigger a reload.
|
|
90
|
+
|
|
91
|
+
The triggering element is visually disabled during the request.
|
|
92
|
+
|
|
93
|
+
**Limitation**: No built-in error handling beyond console logging.
|
|
94
|
+
toDescribe:
|
|
95
|
+
renderView:
|
|
96
|
+
- type: button
|
|
97
|
+
content: Test Error
|
|
98
|
+
actions:
|
|
99
|
+
- what: fetchData
|
|
100
|
+
on: click
|
|
101
|
+
url: "/mockup-api/fetchData/error.json"
|
|
102
|
+
- type: div
|
|
103
|
+
content:
|
|
104
|
+
- "Status: "
|
|
105
|
+
- ~.error_state
|
|
106
|
+
data:
|
|
107
|
+
error_state: "Pending"
|
|
108
|
+
|
|
109
|
+
- type: Markdown
|
|
110
|
+
content: |
|
|
111
|
+
## Limitations
|
|
112
|
+
|
|
113
|
+
- Only one request can be active at a time
|
|
114
|
+
- Only GET requests are supported
|
|
115
|
+
- Response must be a valid rjbuild **only** if refreshAppOnResponse is true
|
|
116
|
+
- No built-in error handling beyond console logging
|
|
117
|
+
- No support for request cancellation
|
|
118
|
+
- No support for timeouts
|
|
119
|
+
- **No support for dynamic URLs** - URLs must be static strings
|
|
120
|
+
- No support for query parameters in URL templates
|
|
121
|
+
- No support for complex URL routing or path generation
|
|
122
|
+
|
|
123
|
+
- type: Markdown
|
|
124
|
+
content: |
|
|
125
|
+
## Styling Fetching State (CSS)
|
|
126
|
+
You can visually disable form controls during a fetchData request using CSS. The system is the same as for submitData:
|
|
127
|
+
|
|
128
|
+
### 1. Target only the fetching control (button, input, etc.)
|
|
129
|
+
The element that triggered the fetch receives `data-is-submitting="true"` during the request:
|
|
130
|
+
|
|
131
|
+
```css
|
|
132
|
+
input[data-is-submitting="true"],
|
|
133
|
+
button[data-is-submitting="true"],
|
|
134
|
+
select[data-is-submitting="true"],
|
|
135
|
+
textarea[data-is-submitting="true"] {
|
|
136
|
+
opacity: 0.5;
|
|
137
|
+
pointer-events: none;
|
|
138
|
+
cursor: not-allowed;
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### 2. Target all controls globally during fetch
|
|
143
|
+
While a fetch is in progress, the `<body>` receives `data-html-builder-is-submitting="true"`. You can use this to disable all form controls:
|
|
144
|
+
|
|
145
|
+
```css
|
|
146
|
+
body[data-html-builder-is-submitting="true"] input,
|
|
147
|
+
body[data-html-builder-is-submitting="true"] button,
|
|
148
|
+
body[data-html-builder-is-submitting="true"] select,
|
|
149
|
+
body[data-html-builder-is-submitting="true"] textarea {
|
|
150
|
+
opacity: 0.5;
|
|
151
|
+
pointer-events: none;
|
|
152
|
+
cursor: not-allowed;
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Choose the approach that best fits your UX needs.
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# Reactive-JSON Reactions System Documentation
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
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. In the RjBuild, reactions are defined under the `actions` key, just like regular actions, but are distinguished by the presence of the `on` property.
|
|
6
|
+
|
|
7
|
+
### Basic Structure
|
|
8
|
+
```yaml
|
|
9
|
+
renderView:
|
|
10
|
+
- type: button
|
|
11
|
+
content: Click me
|
|
12
|
+
actions:
|
|
13
|
+
- what: setData # Reaction type
|
|
14
|
+
on: click # Event that triggers the reaction
|
|
15
|
+
path: ~.my_state # Where to store the data
|
|
16
|
+
value: "on" # Value to set
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 1. Basic Reactions
|
|
20
|
+
|
|
21
|
+
### 1.1 Data Management
|
|
22
|
+
- `addData` : Adds new data to the specified path
|
|
23
|
+
- `setData` : Sets data at the specified path
|
|
24
|
+
- `removeData` : Removes data from the specified path
|
|
25
|
+
- `moveData` : Moves data from one path to another
|
|
26
|
+
|
|
27
|
+
### 1.2 Network Operations
|
|
28
|
+
- `fetchData` : Fetches data from a URL
|
|
29
|
+
- `submitData` : Submits data to a server endpoint
|
|
30
|
+
|
|
31
|
+
### 1.3 Browser Operations
|
|
32
|
+
- `setClipboardData` : Copies data to the clipboard
|
|
33
|
+
- `redirectNow` : Performs an immediate redirect
|
|
34
|
+
- `triggerEvent` : Triggers a custom event
|
|
35
|
+
- `postMessage` : Sends a message to another window/frame
|
|
36
|
+
|
|
37
|
+
## 2. Reaction Structure
|
|
38
|
+
Each reaction is defined by:
|
|
39
|
+
- `what` : The name of the reaction to execute
|
|
40
|
+
- `on` : The event that triggers the reaction
|
|
41
|
+
- Reaction-specific options (vary by reaction type)
|
|
42
|
+
- **Optional conditions** : Reactions support the same conditional system as actions
|
|
43
|
+
|
|
44
|
+
### 2.1 Conditional Reactions
|
|
45
|
+
Just like actions, reactions can be made conditional using various comparison operators:
|
|
46
|
+
|
|
47
|
+
- `when` + `is` / `isNot` : Value equality checks
|
|
48
|
+
- `when` + `isEmpty` : Empty value tests
|
|
49
|
+
- `when` + `contains` / `containsNot` : Content search
|
|
50
|
+
- `when` + `>`, `<`, `>=`, `<=` : Numeric/date comparisons
|
|
51
|
+
- `andConditions` / `orConditions` : Complex condition logic
|
|
52
|
+
|
|
53
|
+
For example:
|
|
54
|
+
```yaml
|
|
55
|
+
actions:
|
|
56
|
+
- what: setData # Reaction name
|
|
57
|
+
on: click # Triggering event
|
|
58
|
+
path: ~.user.profile # Reaction-specific option
|
|
59
|
+
value: ~.form_data # Reaction-specific option
|
|
60
|
+
when: ~.is_editing # Condition - only execute if editing
|
|
61
|
+
is: true # Condition value
|
|
62
|
+
- what: submitData # Reaction name
|
|
63
|
+
on: submit # Triggering event
|
|
64
|
+
url: "/api/endpoint" # Reaction-specific option
|
|
65
|
+
method: "POST" # Reaction-specific option
|
|
66
|
+
data: ~.form_data # Reaction-specific option
|
|
67
|
+
when: ~.form_data # Condition - only submit if form has data
|
|
68
|
+
isEmpty: "not" # Condition check
|
|
69
|
+
- what: setData # Multiple conditions example
|
|
70
|
+
on: click
|
|
71
|
+
path: ~.result
|
|
72
|
+
value: "success"
|
|
73
|
+
andConditions: # All conditions must be true
|
|
74
|
+
- when: ~.user.role
|
|
75
|
+
is: "admin"
|
|
76
|
+
- when: ~.feature_enabled
|
|
77
|
+
is: true
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## 3. Event Types
|
|
81
|
+
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.
|
|
82
|
+
|
|
83
|
+
Common event types:
|
|
84
|
+
- `click` : Mouse click (works on any element)
|
|
85
|
+
- `change` : Form input change (works on form elements only)
|
|
86
|
+
- `submit` : Form submission (works on form elements only)
|
|
87
|
+
- `keydown` : Keyboard key press (works on elements that can receive focus)
|
|
88
|
+
- `keyup` : Keyboard key release (works on elements that can receive focus)
|
|
89
|
+
|
|
90
|
+
## 4. Event Control
|
|
91
|
+
The `stopPropagation` property can be used to control event bubbling and subsequent actions:
|
|
92
|
+
```yaml
|
|
93
|
+
actions:
|
|
94
|
+
- what: setData
|
|
95
|
+
on: click
|
|
96
|
+
path: ~.state
|
|
97
|
+
value: "on"
|
|
98
|
+
stopPropagation: true # Prevents event bubbling AND stops execution of subsequent actions
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
When `stopPropagation` is set to `true`, it:
|
|
102
|
+
1. Prevents the event from bubbling up to parent elements
|
|
103
|
+
2. Stops the execution of any subsequent actions defined for the same event
|
|
104
|
+
|
|
105
|
+
This is particularly useful when you want to ensure that only the first matching action is executed, even if multiple actions are defined for the same event.
|
|
106
|
+
|
|
107
|
+
## 5. Technical Details
|
|
108
|
+
- Reactions are triggered by events
|
|
109
|
+
- Multiple reactions can be defined for the same event
|
|
110
|
+
- Reactions are executed in order
|
|
111
|
+
- Reactions can be chained together
|
|
112
|
+
- **Reactions support all the same conditional operators as actions**: `when`, `is`, `isNot`, `isEmpty`, `contains`, `>`, `<`, `>=`, `<=`, `andConditions`, `orConditions`
|
|
113
|
+
- Conditional reactions only execute when their conditions evaluate to true
|
|
114
|
+
- The execution order of multiple reactions on the same event is guaranteed to match their order in the YAML
|
|
115
|
+
- If a reaction's conditions are not met, it is skipped and the next reaction is evaluated
|
|
116
|
+
|
|
117
|
+
## 6. Limitations
|
|
118
|
+
- Reactions cannot modify external state
|
|
119
|
+
- Network operations must be properly configured
|
|
120
|
+
- Browser operations require appropriate permissions
|
|
121
|
+
|
|
122
|
+
## 7. Complete Examples
|
|
123
|
+
|
|
124
|
+
### 7.1 Data Input and Submission
|
|
125
|
+
```yaml
|
|
126
|
+
renderView:
|
|
127
|
+
- type: TextField
|
|
128
|
+
label: "Username"
|
|
129
|
+
placeholder: "Enter your username"
|
|
130
|
+
dataLocation: ~.form_data.username
|
|
131
|
+
- type: TextField
|
|
132
|
+
label: "Email"
|
|
133
|
+
placeholder: "Enter your email"
|
|
134
|
+
inputType: "email"
|
|
135
|
+
dataLocation: ~.form_data.email
|
|
136
|
+
- type: button
|
|
137
|
+
content: Submit
|
|
138
|
+
actions:
|
|
139
|
+
- what: submitData
|
|
140
|
+
on: click
|
|
141
|
+
url: "/api/submit"
|
|
142
|
+
data:
|
|
143
|
+
username: ~.form_data.username
|
|
144
|
+
email: ~.form_data.email
|
|
145
|
+
when: ~.form_data.username
|
|
146
|
+
isEmpty: not
|
|
147
|
+
|
|
148
|
+
data:
|
|
149
|
+
form_data:
|
|
150
|
+
username: ""
|
|
151
|
+
email: ""
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 7.2 Conditional Reactions Example
|
|
155
|
+
```yaml
|
|
156
|
+
renderView:
|
|
157
|
+
- type: button
|
|
158
|
+
content: "Toggle State"
|
|
159
|
+
actions:
|
|
160
|
+
- what: setData
|
|
161
|
+
on: click
|
|
162
|
+
path: ~.button_state
|
|
163
|
+
value: "on"
|
|
164
|
+
when: ~.button_state
|
|
165
|
+
is: "off"
|
|
166
|
+
stopPropagation: true
|
|
167
|
+
- what: setData
|
|
168
|
+
on: click
|
|
169
|
+
path: ~.button_state
|
|
170
|
+
value: "off"
|
|
171
|
+
when: ~.button_state
|
|
172
|
+
is: "on"
|
|
173
|
+
stopPropagation: true
|
|
174
|
+
- type: div
|
|
175
|
+
content: ["Button state: ", ~.button_state]
|
|
176
|
+
- type: div
|
|
177
|
+
content: "Button has been clicked!"
|
|
178
|
+
actions:
|
|
179
|
+
- what: hide
|
|
180
|
+
when: ~.button_state
|
|
181
|
+
is: "off"
|
|
182
|
+
|
|
183
|
+
data:
|
|
184
|
+
button_state: "off"
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 7.3 Complex Conditional Logic
|
|
188
|
+
```yaml
|
|
189
|
+
renderView:
|
|
190
|
+
- type: TextField
|
|
191
|
+
label: "Enter a number:"
|
|
192
|
+
dataLocation: ~.user_input
|
|
193
|
+
inputType: "number"
|
|
194
|
+
- type: button
|
|
195
|
+
content: "Process Number"
|
|
196
|
+
actions:
|
|
197
|
+
- what: setData
|
|
198
|
+
on: click
|
|
199
|
+
path: ~.result
|
|
200
|
+
value: "Number is valid and positive!"
|
|
201
|
+
andConditions:
|
|
202
|
+
- when: ~.user_input
|
|
203
|
+
isEmpty: "not"
|
|
204
|
+
- when: ~.user_input
|
|
205
|
+
">": 0
|
|
206
|
+
- what: setData
|
|
207
|
+
on: click
|
|
208
|
+
path: ~.result
|
|
209
|
+
value: "Number must be positive!"
|
|
210
|
+
when: ~.user_input
|
|
211
|
+
"<=": 0
|
|
212
|
+
- what: setData
|
|
213
|
+
on: click
|
|
214
|
+
path: ~.result
|
|
215
|
+
value: "Please enter a number!"
|
|
216
|
+
when: ~.user_input
|
|
217
|
+
isEmpty: true
|
|
218
|
+
- type: div
|
|
219
|
+
content: ["Result: ", ~.result]
|
|
220
|
+
actions:
|
|
221
|
+
- what: hide
|
|
222
|
+
when: ~.result
|
|
223
|
+
isEmpty: true
|
|
224
|
+
|
|
225
|
+
data:
|
|
226
|
+
user_input: null
|
|
227
|
+
result: null
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Conclusion
|
|
231
|
+
|
|
232
|
+
You now have a good understanding of reactions in Reactive-JSON. We've seen how they allow you to respond to user events and perform various operations like data updates and network requests.
|
|
233
|
+
|
|
234
|
+
To create complete interactive interfaces, you should combine reactions with actions. Actions handle the conditional behavior of elements, while reactions handle user interactions and data updates.
|
|
235
|
+
|
|
236
|
+
For more information about actions and conditional behavior, check out the [Actions Documentation](../action/index.md).
|